Search in sources :

Example 1 with Tag

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

the class TagColorsItem method cellPaint.

@Override
public void cellPaint(GC gc, TableCellSWT cell) {
    DownloadManager dm = (DownloadManager) cell.getDataSource();
    List<Color> colors = new ArrayList<>();
    if (dm != null) {
        List<Tag> tags = tag_manager.getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL, dm);
        for (Tag tag : tags) {
            int[] rgb = tag.getColor();
            if (rgb != null && rgb.length == 3) {
                colors.add(ColorCache.getColor(gc.getDevice(), rgb));
            }
        }
    }
    int num_colors = colors.size();
    if (num_colors > 0) {
        Rectangle bounds = cell.getBounds();
        bounds.x += 1;
        bounds.y += 1;
        bounds.width -= 1;
        bounds.height -= 1;
        if (num_colors == 1) {
            gc.setBackground(colors.get(0));
            gc.fillRectangle(bounds);
        } else {
            int width = bounds.width;
            int chunk = width / num_colors;
            if (chunk == 0) {
                chunk = 1;
            }
            bounds.width = chunk;
            for (int i = 0; i < num_colors; i++) {
                if (i == num_colors - 1) {
                    int rem = width - (chunk * (num_colors - 1));
                    if (rem > 0) {
                        bounds.width = rem;
                    }
                }
                gc.setBackground(colors.get(i));
                gc.fillRectangle(bounds);
                bounds.x += chunk;
            }
        }
    }
}
Also used : Color(org.eclipse.swt.graphics.Color) ArrayList(java.util.ArrayList) Rectangle(org.eclipse.swt.graphics.Rectangle) Tag(com.biglybt.core.tag.Tag) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 2 with Tag

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

the class TagButtonsUI method updateFields.

public boolean updateFields(List<Taggable> taggables) {
    List<Control> layoutChanges = new ArrayList<>();
    for (Button button : buttons) {
        Tag tag = (Tag) button.getData("Tag");
        if (tag == null) {
            continue;
        }
        String name = tag.getTagName(true);
        if (!button.getText().equals(name)) {
            button.setText(name);
            layoutChanges.add(button);
        }
        updateButtonState(tag, button, taggables);
        button.getParent().redraw();
    }
    if (layoutChanges.size() > 0) {
        cMainComposite.layout(layoutChanges.toArray(new Control[0]));
        return true;
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) Tag(com.biglybt.core.tag.Tag)

Example 3 with Tag

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

the class TorrentFolderWatcher method importAddedFiles.

void importAddedFiles() {
    Core core = CoreFactory.getSingleton();
    try {
        this_mon.enter();
        if (!running) {
            return;
        }
        GlobalManager global_manager = _global_manager;
        if (global_manager == null || !core.isStarted()) {
            return;
        }
        com.biglybt.pif.download.DownloadManager plugin_dm = core.getPluginManager().getDefaultPluginInterface().getDownloadManager();
        boolean save_torrents_default = COConfigurationManager.getBooleanParameter("Save Torrent Files");
        String torrent_save_path = COConfigurationManager.getStringParameter("General_sDefaultTorrent_Directory");
        int start_state = COConfigurationManager.getBooleanParameter("Start Watched Torrents Stopped") ? DownloadManager.STATE_STOPPED : DownloadManager.STATE_QUEUED;
        int num_folders = COConfigurationManager.getIntParameter("Watch Torrent Folder Path Count", 1);
        List<File> folders = new ArrayList<>();
        List<String> tags = new ArrayList<>();
        for (int i = 0; i < num_folders; i++) {
            String folder_path = COConfigurationManager.getStringParameter("Watch Torrent Folder Path" + (i == 0 ? "" : (" " + i)));
            File folder = null;
            if (folder_path != null && folder_path.length() > 0) {
                folder = new File(folder_path);
                if (!folder.isDirectory()) {
                    if (!folder.exists()) {
                        FileUtil.mkdirs(folder);
                    }
                    if (!folder.isDirectory()) {
                        if (Logger.isEnabled())
                            Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "[Watch Torrent Folder Path] " + "does not exist or " + "is not a dir"));
                        folder = null;
                    }
                }
            }
            if (folder != null) {
                folders.add(folder);
                String tag = COConfigurationManager.getStringParameter("Watch Torrent Folder Tag" + (i == 0 ? "" : (" " + i)), null);
                if (tag != null && tag.trim().length() == 0) {
                    tag = null;
                }
                tags.add(tag);
            }
        }
        if (folders.isEmpty()) {
            if (Logger.isEnabled())
                Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "[Watch Torrent Folder Path] not configured"));
            return;
        }
        String data_save_path = COConfigurationManager.getStringParameter("Default save path");
        File f = null;
        if (data_save_path != null && data_save_path.length() > 0) {
            f = new File(data_save_path);
            // Path is not an existing directory.
            if (!f.isDirectory()) {
                if (!f.exists()) {
                    FileUtil.mkdirs(f);
                }
                // If path is still not a directory, abort.
                if (!f.isDirectory()) {
                    if (Logger.isEnabled()) {
                        Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "[Default save path] does not exist or is not a dir"));
                    }
                    Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_ERROR, "[Default save path] does not exist or is not a dir"));
                    return;
                }
            }
        }
        // If we get here, and this is true, then data_save_path isn't valid.
        if (f == null) {
            if (Logger.isEnabled()) {
                Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "[Default save path] needs to be set for auto-.torrent-import to work"));
            }
            Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_ERROR, "[Default save path] needs to be set for auto-.torrent-import to work"));
        }
        for (int i = 0; i < to_delete.size(); i++) {
            TOTorrent torrent = (TOTorrent) to_delete.get(i);
            try {
                TorrentUtils.delete(torrent);
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
        }
        to_delete.clear();
        for (int folder_index = 0; folder_index < folders.size(); folder_index++) {
            File folder = folders.get(folder_index);
            final String tag_name = tags.get(folder_index);
            // if we are saving torrents to the same location as we import them from
            // then we can't assume that its safe to delete the torrent after import!
            boolean save_torrents = save_torrents_default;
            if (torrent_save_path.length() == 0 || new File(torrent_save_path).getAbsolutePath().equals(folder.getAbsolutePath()) || !new File(torrent_save_path).isDirectory()) {
                save_torrents = false;
            }
            String[] currentFileList = folder.list(filename_filter);
            if (currentFileList == null) {
                Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "There was a problem trying to get a listing of torrents from " + folder));
            } else {
                for (int i = 0; i < currentFileList.length; i++) {
                    if (!running) {
                        return;
                    }
                    File file = new File(folder, currentFileList[i]);
                    if (file.getName().toLowerCase(Locale.US).endsWith(".magnet")) {
                        handleMagnet(file);
                    } else {
                        try {
                            TOTorrent torrent = TorrentUtils.readFromFile(file, false);
                            if (global_manager.getDownloadManager(torrent) != null) {
                                if (Logger.isEnabled())
                                    Logger.log(new LogEvent(LOGID, file.getAbsolutePath() + " is already being downloaded"));
                            // we can't touch the torrent file as it is (probably)
                            // being used for the download
                            } else if (plugin_dm.lookupDownloadStub(torrent.getHash()) != null) {
                                if (Logger.isEnabled())
                                    Logger.log(new LogEvent(LOGID, file.getAbsolutePath() + " is an archived download"));
                                if (!save_torrents) {
                                    File imported = new File(folder, file.getName() + ".imported");
                                    TorrentUtils.move(file, imported);
                                } else {
                                    to_delete.add(torrent);
                                }
                            } else {
                                final DownloadManagerInitialisationAdapter dmia = new DownloadManagerInitialisationAdapter() {

                                    @Override
                                    public int getActions() {
                                        return (ACT_ASSIGNS_TAGS);
                                    }

                                    @Override
                                    public void initialised(DownloadManager dm, boolean for_seeding) {
                                        if (tag_name != null) {
                                            TagManager tm = TagManagerFactory.getTagManager();
                                            TagType tt = tm.getTagType(TagType.TT_DOWNLOAD_MANUAL);
                                            Tag tag = tt.getTag(tag_name, true);
                                            try {
                                                if (tag == null) {
                                                    tag = tt.createTag(tag_name, true);
                                                }
                                                tag.addTaggable(dm);
                                            } catch (Throwable e) {
                                                Debug.out(e);
                                            }
                                        }
                                    }
                                };
                                byte[] hash = null;
                                try {
                                    hash = torrent.getHash();
                                } catch (Exception e) {
                                }
                                if (!save_torrents) {
                                    File imported = new File(folder, file.getName() + ".imported");
                                    TorrentUtils.move(file, imported);
                                    global_manager.addDownloadManager(imported.getAbsolutePath(), hash, data_save_path, start_state, true, false, dmia);
                                } else {
                                    global_manager.addDownloadManager(file.getAbsolutePath(), hash, data_save_path, start_state, true, false, dmia);
                                    // add torrent for deletion, since there will be a
                                    // saved copy elsewhere
                                    to_delete.add(torrent);
                                }
                                if (Logger.isEnabled())
                                    Logger.log(new LogEvent(LOGID, "Auto-imported " + file.getAbsolutePath()));
                            }
                        } catch (Throwable e) {
                            Debug.out("Failed to auto-import torrent file '" + file.getAbsolutePath() + "' - " + Debug.getNestedExceptionMessage(e));
                            Debug.printStackTrace(e);
                        }
                    }
                }
            }
        }
    } finally {
        this_mon.exit();
    }
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) ArrayList(java.util.ArrayList) DownloadManagerInitialisationAdapter(com.biglybt.core.download.DownloadManagerInitialisationAdapter) DownloadManager(com.biglybt.core.download.DownloadManager) LogAlert(com.biglybt.core.logging.LogAlert) TagType(com.biglybt.core.tag.TagType) TagManager(com.biglybt.core.tag.TagManager) GlobalManager(com.biglybt.core.global.GlobalManager) TOTorrent(com.biglybt.core.torrent.TOTorrent) Tag(com.biglybt.core.tag.Tag) File(java.io.File) Core(com.biglybt.core.Core)

Example 4 with Tag

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

the class SubscriptionManagerImpl method prepareDownload.

protected void prepareDownload(Download download, Subscription[] subscriptions, SubscriptionResult[] results) {
    try {
        if (subscriptions.length > 0) {
            // deal with first only for cat/tag/nets as will always be just one when called from downloadAdded
            Subscription subs = subscriptions[0];
            if (results != null && results.length > 0) {
                try {
                    SubscriptionResult result = results[0];
                    Map<Integer, Object> props = result.toPropertyMap();
                    Long leechers = (Long) props.get(SearchResult.PR_LEECHER_COUNT);
                    Long seeds = (Long) props.get(SearchResult.PR_SEED_COUNT);
                    if (leechers != null && seeds != null && leechers >= 0 && seeds >= 0) {
                        com.biglybt.core.download.DownloadManager core_dm = PluginCoreUtils.unwrap(download);
                        DownloadManagerState state = core_dm.getDownloadState();
                        long cache = ((seeds & 0x00ffffffL) << 32) | (leechers & 0x00ffffffL);
                        state.setLongAttribute(DownloadManagerState.AT_SCRAPE_CACHE_SOURCE, 1);
                        state.setLongAttribute(DownloadManagerState.AT_SCRAPE_CACHE, cache);
                    }
                } catch (Throwable e) {
                }
            }
            String category = subs.getCategory();
            if (category != null) {
                String existing = download.getAttribute(ta_category);
                if (existing == null) {
                    download.setAttribute(ta_category, category);
                }
            }
            long tag_id = subs.getTagID();
            if (tag_id >= 0) {
                Tag tag = TagManagerFactory.getTagManager().lookupTagByUID(tag_id);
                if (tag != null) {
                    com.biglybt.core.download.DownloadManager core_dm = PluginCoreUtils.unwrap(download);
                    if (!tag.hasTaggable(core_dm)) {
                        tag.addTaggable(core_dm);
                    }
                }
            }
            String[] nets = subs.getHistory().getDownloadNetworks();
            if (nets != null) {
                com.biglybt.core.download.DownloadManager core_dm = PluginCoreUtils.unwrap(download);
                DownloadManagerState state = core_dm.getDownloadState();
                state.setNetworks(nets);
                // ensure that other cide (e.g. the open-torrent stuff) doesn't over-write this
                state.setFlag(DownloadManagerState.FLAG_INITIAL_NETWORKS_SET, true);
            }
        }
    } catch (Throwable e) {
        log("Failed to prepare association", e);
    }
}
Also used : DownloadManagerState(com.biglybt.core.download.DownloadManagerState) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) com.biglybt.pif.download(com.biglybt.pif.download) Tag(com.biglybt.core.tag.Tag)

Example 5 with Tag

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

the class ColumnTagAggregateSR method refresh.

@Override
public void refresh(TableCell cell) {
    Tag tag = (Tag) cell.getDataSource();
    if (tag instanceof TagFeatureRateLimit) {
        TagFeatureRateLimit rl = (TagFeatureRateLimit) tag;
        int sr = rl.getTagAggregateShareRatio();
        if (sr >= 0) {
            if (!cell.setSortValue(sr) && cell.isValid()) {
                return;
            }
            if (!cell.isShown()) {
                return;
            }
            cell.setText(sr == 0 ? "" : String.valueOf(sr / 1000.0f));
        }
    }
}
Also used : TagFeatureRateLimit(com.biglybt.core.tag.TagFeatureRateLimit) Tag(com.biglybt.core.tag.Tag)

Aggregations

Tag (com.biglybt.core.tag.Tag)55 DownloadManager (com.biglybt.core.download.DownloadManager)15 TagFeatureRateLimit (com.biglybt.core.tag.TagFeatureRateLimit)12 File (java.io.File)9 TagManager (com.biglybt.core.tag.TagManager)8 TagType (com.biglybt.core.tag.TagType)8 ArrayList (java.util.ArrayList)8 List (java.util.List)5 Core (com.biglybt.core.Core)4 CoreRunningListener (com.biglybt.core.CoreRunningListener)4 PEPeerManager (com.biglybt.core.peer.PEPeerManager)4 TagFeatureFileLocation (com.biglybt.core.tag.TagFeatureFileLocation)4 Point (org.eclipse.swt.graphics.Point)4 Category (com.biglybt.core.category.Category)3 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)3 DownloadManagerInitialisationAdapter (com.biglybt.core.download.DownloadManagerInitialisationAdapter)3 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)3 TOTorrent (com.biglybt.core.torrent.TOTorrent)3 Download (com.biglybt.pif.download.Download)3 GlobalManager (com.biglybt.core.global.GlobalManager)2