Search in sources :

Example 1 with TagFeatureFileLocation

use of com.biglybt.core.tag.TagFeatureFileLocation in project BiglyBT by BiglySoftware.

the class ColumnTagCopyOnComp method refresh.

@Override
public void refresh(TableCell cell) {
    Tag tag = (Tag) cell.getDataSource();
    if (tag instanceof TagFeatureFileLocation) {
        TagFeatureFileLocation fl = (TagFeatureFileLocation) tag;
        if (fl.supportsTagCopyOnComplete()) {
            File target_file = fl.getTagCopyOnCompleteFolder();
            String target;
            if (target_file == null) {
                target = "";
            } else {
                target = target_file.getAbsolutePath();
            }
            if (!cell.setSortValue(target) && cell.isValid()) {
                return;
            }
            if (!cell.isShown()) {
                return;
            }
            cell.setText(target);
        }
    }
}
Also used : Tag(com.biglybt.core.tag.Tag) TagFeatureFileLocation(com.biglybt.core.tag.TagFeatureFileLocation) File(java.io.File)

Example 2 with TagFeatureFileLocation

use of com.biglybt.core.tag.TagFeatureFileLocation in project BiglyBT by BiglySoftware.

the class DownloadManagerDefaultPaths method getDownloadOrTagMovementInformation.

static MovementInformation getDownloadOrTagMovementInformation(DownloadManager dm, MovementInformation def_mi) {
    boolean move_data = true;
    boolean move_torrent = false;
    File move_to_target = null;
    String context_str = "";
    String mi_str = "";
    DownloadManagerState state = dm.getDownloadState();
    String explicit_target = state.getAttribute(DownloadManagerState.AT_MOVE_ON_COMPLETE_DIR);
    if (explicit_target != null && explicit_target.length() > 0) {
        File move_to = new File(explicit_target);
        if (!move_to.exists()) {
            move_to.mkdirs();
        }
        if (move_to.isDirectory() && move_to.canWrite()) {
            move_to_target = move_to;
            context_str = "Download-specific move-on-complete directory";
            mi_str = "Download-specific Move on Completion";
        } else {
            logInfo("Ignoring invalid download move-to location: " + move_to, dm);
        }
    }
    if (move_to_target == null) {
        List<Tag> dm_tags = TagManagerFactory.getTagManager().getTagsForTaggable(dm);
        if (dm_tags != null) {
            List<Tag> applicable_tags = new ArrayList<>();
            for (Tag tag : dm_tags) {
                if (tag.getTagType().hasTagTypeFeature(TagFeature.TF_FILE_LOCATION)) {
                    TagFeatureFileLocation fl = (TagFeatureFileLocation) tag;
                    if (fl.supportsTagMoveOnComplete()) {
                        File move_to = fl.getTagMoveOnCompleteFolder();
                        if (move_to != null) {
                            if (!move_to.exists()) {
                                move_to.mkdirs();
                            }
                            if (move_to.isDirectory() && move_to.canWrite()) {
                                applicable_tags.add(tag);
                            } else {
                                logInfo("Ignoring invalid tag move-to location: " + move_to, dm);
                            }
                        }
                    }
                }
            }
            if (!applicable_tags.isEmpty()) {
                if (applicable_tags.size() > 1) {
                    Collections.sort(applicable_tags, new Comparator<Tag>() {

                        @Override
                        public int compare(Tag o1, Tag o2) {
                            return (o1.getTagID() - o2.getTagID());
                        }
                    });
                    String str = "";
                    for (Tag tag : applicable_tags) {
                        str += (str.length() == 0 ? "" : ", ") + tag.getTagName(true);
                    }
                    logInfo("Multiple applicable tags found: " + str + " - selecting first", dm);
                }
                Tag tag_target = applicable_tags.get(0);
                TagFeatureFileLocation fl = (TagFeatureFileLocation) tag_target;
                move_to_target = fl.getTagMoveOnCompleteFolder();
                long options = fl.getTagMoveOnCompleteOptions();
                move_data = (options & TagFeatureFileLocation.FL_DATA) != 0;
                move_torrent = (options & TagFeatureFileLocation.FL_TORRENT) != 0;
                context_str = "Tag '" + tag_target.getTagName(true) + "' move-on-complete directory";
                mi_str = "Tag Move on Completion";
            }
        }
    }
    if (move_to_target != null) {
        SourceSpecification source = new SourceSpecification();
        if (def_mi.target.getBoolean("enabled", false)) {
            source.setBoolean("default dir", "Move Only When In Default Save Dir");
            source.setBoolean("default subdir", SUBDIR_PARAM);
        } else {
            source.setBoolean("default dir", false);
        }
        source.setBoolean("incomplete dl", false);
        TargetSpecification dest = new TargetSpecification();
        if (move_data) {
            dest.setBoolean("enabled", true);
            dest.setString("target_raw", move_to_target.getAbsolutePath());
        } else {
            dest.setBoolean("enabled", def_mi.target.getBoolean("enabled", false));
        }
        dest.setContext(context_str);
        if (move_torrent) {
            dest.setBoolean("torrent", true);
            dest.setString("torrent_path_raw", move_to_target.getAbsolutePath());
        } else {
            dest.setBoolean("torrent", "Move Torrent When Done");
            dest.setString("torrent_path", "Move Torrent When Done Directory");
        }
        TransferSpecification trans = new TransferSpecification();
        MovementInformation mi = new MovementInformation(source, dest, trans, mi_str);
        return (mi);
    } else {
        return (def_mi);
    }
}
Also used : DownloadManagerState(com.biglybt.core.download.DownloadManagerState) Tag(com.biglybt.core.tag.Tag) TagFeatureFileLocation(com.biglybt.core.tag.TagFeatureFileLocation) File(java.io.File)

Example 3 with TagFeatureFileLocation

use of com.biglybt.core.tag.TagFeatureFileLocation in project BiglyBT by BiglySoftware.

the class ColumnTagInitialSaveLocation method refresh.

@Override
public void refresh(TableCell cell) {
    Tag tag = (Tag) cell.getDataSource();
    if (tag instanceof TagFeatureFileLocation) {
        TagFeatureFileLocation fl = (TagFeatureFileLocation) tag;
        if (fl.supportsTagInitialSaveFolder()) {
            File target_file = fl.getTagInitialSaveFolder();
            String target;
            if (target_file == null) {
                target = "";
            } else {
                target = target_file.getAbsolutePath();
            }
            if (!cell.setSortValue(target) && cell.isValid()) {
                return;
            }
            if (!cell.isShown()) {
                return;
            }
            cell.setText(target);
        }
    }
}
Also used : Tag(com.biglybt.core.tag.Tag) TagFeatureFileLocation(com.biglybt.core.tag.TagFeatureFileLocation) File(java.io.File)

Example 4 with TagFeatureFileLocation

use of com.biglybt.core.tag.TagFeatureFileLocation in project BiglyBT by BiglySoftware.

the class ColumnTagMoveOnComp method refresh.

@Override
public void refresh(TableCell cell) {
    Tag tag = (Tag) cell.getDataSource();
    if (tag instanceof TagFeatureFileLocation) {
        TagFeatureFileLocation fl = (TagFeatureFileLocation) tag;
        if (fl.supportsTagMoveOnComplete()) {
            File target_file = fl.getTagMoveOnCompleteFolder();
            String target;
            if (target_file == null) {
                target = "";
            } else {
                target = target_file.getAbsolutePath();
            }
            if (!cell.setSortValue(target) && cell.isValid()) {
                return;
            }
            if (!cell.isShown()) {
                return;
            }
            cell.setText(target);
        }
    }
}
Also used : Tag(com.biglybt.core.tag.Tag) TagFeatureFileLocation(com.biglybt.core.tag.TagFeatureFileLocation) File(java.io.File)

Aggregations

Tag (com.biglybt.core.tag.Tag)4 TagFeatureFileLocation (com.biglybt.core.tag.TagFeatureFileLocation)4 File (java.io.File)4 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)1