Search in sources :

Example 76 with Download

use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.

the class BuddyPlugin method initialize.

@Override
public void initialize(final PluginInterface _plugin_interface) {
    plugin_interface = _plugin_interface;
    ta_category = plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_CATEGORY);
    logger = plugin_interface.getLogger().getChannel("Friends");
    logger.setDiagnostic();
    plugin_networks = new BuddyPluginNetwork[] { new BuddyPluginNetwork(plugin_interface, this, AENetworkClassifier.AT_PUBLIC), new BuddyPluginNetwork(plugin_interface, this, AENetworkClassifier.AT_I2P) };
    final LocaleUtilities lu = plugin_interface.getUtilities().getLocaleUtilities();
    Properties l10n_constants = new Properties();
    l10n_constants.put("azbuddy.classic.link.url", Wiki.FRIENDS);
    l10n_constants.put("azbuddy.dchat.link.url", Wiki.DECENTRALIZED_CHAT);
    l10n_constants.put("azbuddy.profile.info.url", Wiki.FRIENDS_PUBLIC_PROFILE);
    lu.integrateLocalisedMessageBundle(l10n_constants);
    lu.addListener(new LocaleListener() {

        @Override
        public void localeChanged(Locale l) {
            updateLocale(lu);
        }
    });
    updateLocale(lu);
    BasicPluginConfigModel config = plugin_interface.getUIManager().createBasicPluginConfigModel("Views.plugins." + VIEW_ID + ".title");
    // enabled
    classic_enabled_param = config.addBooleanParameter2("azbuddy.enabled", "azbuddy.enabled", false);
    ParameterTabFolder network_tab = config.createTabFolder();
    ParameterGroup network_anon_item = null;
    for (int i = 0; i < 2; i++) {
        boolean is_pub_tab = i == 0;
        String suffix = is_pub_tab ? "" : ".anon";
        // nickname
        StringParameter nick_param = config.addStringParameter2("azbuddy.nickname" + suffix, "azbuddy.nickname", "");
        nick_param.setGenerateIntermediateEvents(false);
        nick_param.addListener(new ParameterListener() {

            @Override
            public void parameterChanged(Parameter param) {
                updateNickName(is_pub_tab, nick_param.getValue());
            }
        });
        // online status
        String[] os_values = STATUS_VALUES;
        String[] os_labels = STATUS_STRINGS;
        StringListParameter os_param = config.addStringListParameter2("azbuddy.online_status" + suffix, "azbuddy.online_status", os_values, os_labels, os_values[0]);
        os_param.addListener(new ParameterListener() {

            @Override
            public void parameterChanged(Parameter param) {
                updateOnlineStatus(is_pub_tab, Integer.parseInt(os_param.getValue()));
            }
        });
        // If we add this then use proper message texts in the STATUS_STRINGS
        os_param.setVisible(SUPPORT_ONLINE_STATUS);
        StringParameter profile_param = config.addStringParameter2("azbuddy.profile.info" + suffix, "", "");
        profile_param.setLabelText("<a href=\"" + MessageText.getString("azbuddy.profile.info.url") + "\">" + MessageText.getString("azbuddy.profile.info") + "</a>");
        profile_param.setMultiLine(5);
        profile_param.setGenerateIntermediateEvents(false);
        profile_param.addListener(new ParameterListener() {

            @Override
            public void parameterChanged(Parameter param) {
                updateProfiles();
            }
        });
        ParameterGroup profile_group = config.createGroup(is_pub_tab ? "azbuddy.public.profile" : "azbuddy.anon.profile", new Parameter[] { profile_param });
        ParameterGroup network_item = config.createGroup(is_pub_tab ? "label.public" : "label.anon", new Parameter[] { nick_param, os_param, profile_group });
        if (is_pub_tab) {
            nick_name_public_param = nick_param;
            online_status_public_param = os_param;
            profile_public_param = profile_param;
        } else {
            nick_name_anon_param = nick_param;
            online_status_anon_param = os_param;
            profile_anon_param = profile_param;
            network_anon_item = network_item;
        }
        network_tab.addTab(network_item);
    }
    updateProfiles();
    // protocol speed
    final IntParameter protocol_speed = config.addIntParameter2("azbuddy.protocolspeed", "azbuddy.protocolspeed", 32);
    protocol_speed.setMinimumRequiredUserMode(Parameter.MODE_ADVANCED);
    ConnectionManager cman = plugin_interface.getConnectionManager();
    int inbound_limit = protocol_speed.getValue() * 1024;
    inbound_limiter = cman.createRateLimiter("buddy_up", inbound_limit);
    outbound_limiter = cman.createRateLimiter("buddy_down", 0);
    protocol_speed.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            inbound_limiter.setRateLimitBytesPerSecond(protocol_speed.getValue() * 1024);
        }
    });
    // chat notifications
    enable_chat_notifications = config.addBooleanParameter2("azbuddy.enable_chat_notif", "azbuddy.enable_chat_notif", true);
    // default published tags or cats
    cat_pub = config.addStringParameter2("azbuddy.enable_cat_pub", "azbuddy.enable_cat_pub", "");
    cat_pub.setGenerateIntermediateEvents(false);
    setPublicTagsOrCategories(cat_pub.getValue(), false);
    final BooleanParameter tracker_enable = config.addBooleanParameter2("azbuddy.tracker.enabled", "azbuddy.tracker.enabled", true);
    final BooleanParameter tracker_so_enable = config.addBooleanParameter2("azbuddy.tracker.seeding.only.enabled", "azbuddy.tracker.seeding.only.enabled", false);
    // nasty hack but the existing text has a \t prefix that causes UI weirdness but I don't want to change it and
    // end up with missing translations...
    tracker_so_enable.setLabelText(MessageText.getString("azbuddy.tracker.seeding.only.enabled").trim());
    tracker_so_enable.setIndent(1, true);
    final BooleanParameter buddies_lan_local = config.addBooleanParameter2("azbuddy.tracker.con.lan.local", "azbuddy.tracker.con.lan.local", true);
    buddies_lan_local.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            lan_local_peers = buddies_lan_local.getValue();
        }
    });
    lan_local_peers = buddies_lan_local.getValue();
    final BooleanParameter buddies_fp_enable = config.addBooleanParameter2("azbuddy.tracker.fp.enable", "azbuddy.tracker.fp.enable", true);
    buddies_fp_enable.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            fp_enable = buddies_fp_enable.getValue();
        }
    });
    fp_enable = buddies_fp_enable.getValue();
    cat_pub.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            setPublicTagsOrCategories(cat_pub.getValue(), false);
        }
    });
    config.createGroup("label.friends", new Parameter[] { classic_enabled_param, network_tab, protocol_speed, enable_chat_notifications, cat_pub, tracker_enable, tracker_so_enable, buddies_lan_local, buddies_fp_enable });
    // decentralised stuff
    beta_enabled_param = config.addBooleanParameter2("azbuddy.dchat.decentralized.enabled", "azbuddy.dchat.decentralized.enabled", true);
    config.createGroup("azbuddy.dchat.decentralized", new Parameter[] { beta_enabled_param });
    config.addLabelParameter2("azbuddy.dchat.more.settings");
    // config end
    beta_plugin = new BuddyPluginBeta(plugin_interface, this, beta_enabled_param);
    for (String table_id : TableManager.TABLE_MYTORRENTS_ALL) {
        TableContextMenuItem menu_item = plugin_interface.getUIManager().getTableManager().addContextMenuItem(table_id, "azbuddy.contextmenu");
        menu_item.setStyle(TableContextMenuItem.STYLE_MENU);
        menu_item.setHeaderCategory(MenuItem.HEADER_SOCIAL);
        MenuItemFillListener menu_fill_listener = new MenuItemFillListener() {

            @Override
            public void menuWillBeShown(MenuItem menu, Object _target) {
                menu.removeAllChildItems();
                if (!(isClassicEnabled() && isAvailable())) {
                    menu.setEnabled(false);
                    return;
                }
                final List<Torrent> torrents = new ArrayList<>();
                if (_target instanceof TableRow) {
                    addDownload(torrents, (TableRow) _target);
                } else {
                    TableRow[] rows = (TableRow[]) _target;
                    for (TableRow row : rows) {
                        addDownload(torrents, row);
                    }
                }
                if (torrents.size() == 0) {
                    menu.setEnabled(false);
                } else {
                    List<BuddyPluginBuddy> buddies = getBuddies();
                    for (int i = 0; i < buddies.size(); i++) {
                        final BuddyPluginBuddy buddy = (BuddyPluginBuddy) buddies.get(i);
                        boolean online = buddy.isOnline(true);
                        TableContextMenuItem item = plugin_interface.getUIManager().getTableManager().addContextMenuItem(menu_item, "!" + (buddy.getName() + (buddy.isPublicNetwork() ? "" : (" (" + MessageText.getString("label.anon.medium") + ")"))) + (online ? "" : (" - " + MessageText.getString("label.disconnected"))) + "!");
                        item.addMultiListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                for (Torrent torrent : torrents) {
                                    buddy.getPluginNetwork().getAZ2Handler().sendAZ2Torrent(torrent, buddy);
                                }
                            }
                        });
                        item.setEnabled(online);
                    }
                    menu.setEnabled(true);
                }
            }

            protected void addDownload(List<Torrent> torrents, TableRow row) {
                Object obj = row.getDataSource();
                Download download;
                if (obj instanceof Download) {
                    download = (Download) obj;
                } else {
                    DiskManagerFileInfo file = (DiskManagerFileInfo) obj;
                    try {
                        download = file.getDownload();
                    } catch (DownloadException e) {
                        Debug.printStackTrace(e);
                        return;
                    }
                }
                Torrent torrent = download.getTorrent();
                if (torrent != null && !TorrentUtils.isReallyPrivate(PluginCoreUtils.unwrap(torrent))) {
                    torrents.add(torrent);
                }
            }
        };
        menu_item.addFillListener(menu_fill_listener);
    }
    buddy_tracker = new BuddyPluginTracker(this, tracker_enable, tracker_so_enable);
    plugin_interface.getUIManager().addUIListener(new UIManagerListener() {

        @Override
        public void UIAttached(final UIInstance instance) {
            if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
                try {
                    synchronized (swt_ui_waiters) {
                        swt_ui = (BuddyPluginViewInterface) Class.forName("com.biglybt.plugin.net.buddy.swt.BuddyPluginView").getConstructor(new Class[] { BuddyPlugin.class, UIInstance.class }).newInstance(new Object[] { BuddyPlugin.this, instance });
                        for (Runnable r : swt_ui_waiters) {
                            try {
                                r.run();
                            } catch (Throwable e) {
                                Debug.out(e);
                            }
                        }
                        swt_ui_waiters.clear();
                    }
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
            setupDisablePrompt(instance);
        }

        @Override
        public void UIDetached(UIInstance instance) {
            if (instance.getUIType().equals(UIInstance.UIT_SWT) && swt_ui != null) {
                swt_ui.destroy();
                swt_ui = null;
            }
        }
    });
    final ParameterGroup f_network_anon_item = network_anon_item;
    ParameterListener enabled_listener = new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            boolean classic_enabled = classic_enabled_param.getValue();
            nick_name_public_param.setEnabled(classic_enabled);
            online_status_public_param.setEnabled(classic_enabled);
            nick_name_anon_param.setEnabled(classic_enabled);
            online_status_anon_param.setEnabled(classic_enabled);
            protocol_speed.setEnabled(classic_enabled);
            enable_chat_notifications.setEnabled(classic_enabled);
            cat_pub.setEnabled(classic_enabled);
            tracker_enable.setEnabled(classic_enabled);
            tracker_so_enable.setEnabled(classic_enabled && tracker_enable.getValue());
            buddies_lan_local.setEnabled(classic_enabled);
            buddies_fp_enable.setEnabled(classic_enabled);
            network_tab.setEnabled(classic_enabled);
            f_network_anon_item.setEnabled(classic_enabled && I2PHelpers.isI2PInstalled());
            if (param != null) {
                for (BuddyPluginNetwork pn : plugin_networks) {
                    pn.setClassicEnabledInternal(classic_enabled);
                }
                fireEnabledStateChanged();
            }
        }
    };
    classic_enabled_param.addListener(enabled_listener);
    beta_enabled_param.addListener(enabled_listener);
    tracker_enable.addListener(enabled_listener);
    for (BuddyPluginNetwork pn : plugin_networks) {
        pn.loadConfig();
        pn.registerMessageHandler();
    }
    plugin_interface.addListener(new PluginListener() {

        @Override
        public void initializationComplete() {
            enabled_listener.parameterChanged(null);
            final DelayedTask dt = plugin_interface.getUtilities().createDelayedTask(new Runnable() {

                @Override
                public void run() {
                    new AEThread2("BuddyPlugin:init", true) {

                        @Override
                        public void run() {
                            startup();
                            beta_plugin.startup();
                            initialization_complete.set(true);
                        }
                    }.start();
                }
            });
            dt.queue();
        }

        @Override
        public void closedownInitiated() {
        // meh, moved this to core listener below as we need to closedown before
        // i2p plugin so connections aren't torn down before we can tidily close
        }

        @Override
        public void closedownComplete() {
        }
    });
    CoreFactory.getSingleton().addLifecycleListener(new CoreLifecycleAdapter() {

        @Override
        public boolean syncInvokeRequired() {
            return (true);
        }

        @Override
        public void stopping(Core core) {
            for (BuddyPluginNetwork pn : plugin_networks) {
                pn.saveConfig(true);
                pn.closedown();
            }
            beta_plugin.closedown();
        }
    });
}
Also used : Locale(java.util.Locale) Torrent(com.biglybt.pif.torrent.Torrent) CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) LocaleUtilities(com.biglybt.pif.utils.LocaleUtilities) ArrayList(java.util.ArrayList) Properties(java.util.Properties) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) PluginListener(com.biglybt.pif.PluginListener) ConnectionManager(com.biglybt.pif.network.ConnectionManager) DownloadException(com.biglybt.pif.download.DownloadException) DelayedTask(com.biglybt.pif.utils.DelayedTask) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) CopyOnWriteList(com.biglybt.core.util.CopyOnWriteList) List(java.util.List) ArrayList(java.util.ArrayList) BuddyPluginTracker(com.biglybt.plugin.net.buddy.tracker.BuddyPluginTracker) LocaleListener(com.biglybt.pif.utils.LocaleListener) Download(com.biglybt.pif.download.Download) UIInstance(com.biglybt.pif.ui.UIInstance) ParameterTabFolder(com.biglybt.pif.ui.config.ParameterTabFolder) Core(com.biglybt.core.Core) StringParameter(com.biglybt.pif.ui.config.StringParameter) DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) BooleanParameter(com.biglybt.pif.ui.config.BooleanParameter) AEThread2(com.biglybt.core.util.AEThread2) StringListParameter(com.biglybt.pif.ui.config.StringListParameter) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) ParameterGroup(com.biglybt.pif.ui.config.ParameterGroup) TableRow(com.biglybt.pif.ui.tables.TableRow) ParameterListener(com.biglybt.pif.ui.config.ParameterListener) BooleanParameter(com.biglybt.pif.ui.config.BooleanParameter) StringParameter(com.biglybt.pif.ui.config.StringParameter) Parameter(com.biglybt.pif.ui.config.Parameter) StringListParameter(com.biglybt.pif.ui.config.StringListParameter) IntParameter(com.biglybt.pif.ui.config.IntParameter) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel) IntParameter(com.biglybt.pif.ui.config.IntParameter)

Example 77 with Download

use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.

the class BuddyPlugin method getRSS.

public FeedDetails getRSS(BuddyPluginBuddy buddy, String tag_or_category, String if_mod) throws BuddyPluginException {
    if (!buddy.isLocalRSSTagOrCategoryAuthorised(tag_or_category)) {
        throw (new BuddyPluginException("Unauthorised tag/category '" + tag_or_category + "'"));
    }
    buddy.localRSSTagOrCategoryRead(tag_or_category);
    Download[] downloads = plugin_interface.getDownloadManager().getDownloads();
    List<Download> selected_dls = new ArrayList<>();
    long fingerprint = 0;
    for (int i = 0; i < downloads.length; i++) {
        Download download = downloads[i];
        Torrent torrent = download.getTorrent();
        if (torrent == null) {
            continue;
        }
        boolean match = tag_or_category.equalsIgnoreCase("all");
        if (!match) {
            String dl_cat = download.getAttribute(ta_category);
            match = dl_cat != null && dl_cat.equals(tag_or_category);
        }
        if (!match) {
            try {
                List<Tag> tags = TagManagerFactory.getTagManager().getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL, PluginCoreUtils.unwrap(download));
                for (Tag tag : tags) {
                    if (tag.getTagName(true).equals(tag_or_category)) {
                        match = true;
                        break;
                    }
                }
            } catch (Throwable e) {
            }
        }
        if (match) {
            if (!TorrentUtils.isReallyPrivate(PluginCoreUtils.unwrap(torrent))) {
                selected_dls.add(download);
                byte[] hash = torrent.getHash();
                int num = (hash[0] << 24) & 0xff000000 | (hash[1] << 16) & 0x00ff0000 | (hash[2] << 8) & 0x0000ff00 | hash[3] & 0x000000ff;
                fingerprint += num;
            }
        }
    }
    PluginConfig pc = plugin_interface.getPluginconfig();
    String feed_finger_key = "feed_finger.category." + tag_or_category;
    String feed_date_key = "feed_date.category." + tag_or_category;
    long existing_fingerprint = pc.getPluginLongParameter(feed_finger_key, 0);
    long feed_date = pc.getPluginLongParameter(feed_date_key, 0);
    long now = SystemTime.getCurrentTime();
    if (existing_fingerprint == fingerprint) {
        if (selected_dls.size() > 0) {
            if (now < feed_date || now - feed_date > FEED_UPDATE_MIN_MILLIS) {
                feed_date = now;
                pc.setPluginParameter(feed_date_key, feed_date);
            }
        }
    } else {
        pc.setPluginParameter(feed_finger_key, fingerprint);
        if (now <= feed_date) {
            feed_date++;
        } else {
            feed_date = now;
        }
        pc.setPluginParameter(feed_date_key, feed_date);
    }
    String last_modified = TimeFormatter.getHTTPDate(feed_date);
    if (if_mod != null && if_mod.equals(last_modified)) {
        return (new FeedDetails(new byte[0], last_modified));
    }
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
        pw.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        pw.println("<rss version=\"2.0\" xmlns:vuze=\"http://www.vuze.com\">");
        pw.println("<channel>");
        pw.println("<title>" + escape(tag_or_category) + "</title>");
        Collections.sort(selected_dls, new Comparator<Download>() {

            @Override
            public int compare(Download d1, Download d2) {
                long added1 = getAddedTime(d1) / 1000;
                long added2 = getAddedTime(d2) / 1000;
                return ((int) (added2 - added1));
            }
        });
        pw.println("<pubDate>" + last_modified + "</pubDate>");
        for (int i = 0; i < selected_dls.size(); i++) {
            Download download = (Download) selected_dls.get(i);
            DownloadManager core_download = PluginCoreUtils.unwrap(download);
            Torrent torrent = download.getTorrent();
            String hash_str = Base32.encode(torrent.getHash());
            pw.println("<item>");
            pw.println("<title>" + escape(download.getName()) + "</title>");
            pw.println("<guid>" + hash_str + "</guid>");
            long added = core_download.getDownloadState().getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME);
            pw.println("<pubDate>" + TimeFormatter.getHTTPDate(added) + "</pubDate>");
            pw.println("<vuze:size>" + torrent.getSize() + "</vuze:size>");
            pw.println("<vuze:assethash>" + hash_str + "</vuze:assethash>");
            String url = "azplug:?id=azbuddy&name=Friends&arg=";
            String arg = "pk=" + buddy.getPluginNetwork().getPublicKey() + "&cat=" + tag_or_category + "&hash=" + Base32.encode(torrent.getHash());
            url += URLEncoder.encode(arg, "UTF-8");
            pw.println("<vuze:downloadurl>" + escape(url) + "</vuze:downloadurl>");
            DownloadScrapeResult scrape = download.getLastScrapeResult();
            if (scrape != null && scrape.getResponseType() == DownloadScrapeResult.RT_SUCCESS) {
                pw.println("<vuze:seeds>" + scrape.getSeedCount() + "</vuze:seeds>");
                pw.println("<vuze:peers>" + scrape.getNonSeedCount() + "</vuze:peers>");
            }
            pw.println("</item>");
        }
        pw.println("</channel>");
        pw.println("</rss>");
        pw.flush();
        return (new FeedDetails(os.toByteArray(), last_modified));
    } catch (IOException e) {
        throw (new BuddyPluginException("", e));
    }
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) DownloadManager(com.biglybt.core.download.DownloadManager) PluginConfig(com.biglybt.pif.PluginConfig) OutputStreamWriter(java.io.OutputStreamWriter) Tag(com.biglybt.core.tag.Tag) Download(com.biglybt.pif.download.Download) DownloadScrapeResult(com.biglybt.pif.download.DownloadScrapeResult) PrintWriter(java.io.PrintWriter)

Example 78 with Download

use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.

the class ExternalSeedPlugin method addPeers.

protected void addPeers(final Download download, List _peers) {
    final List peers = new ArrayList();
    peers.addAll(_peers);
    if (peers.size() > 0) {
        boolean add_listener = false;
        try {
            download_mon.enter();
            List existing_peers = (List) download_map.get(download);
            if (existing_peers == null) {
                add_listener = true;
                existing_peers = new ArrayList();
                download_map.put(download, existing_peers);
            }
            Iterator it = peers.iterator();
            while (it.hasNext()) {
                ExternalSeedPeer peer = (ExternalSeedPeer) it.next();
                boolean skip = false;
                for (int j = 0; j < existing_peers.size(); j++) {
                    ExternalSeedPeer existing_peer = (ExternalSeedPeer) existing_peers.get(j);
                    if (existing_peer.sameAs(peer)) {
                        skip = true;
                        break;
                    }
                }
                if (skip) {
                    it.remove();
                } else {
                    log(download.getName() + " found seed " + peer.getName());
                    existing_peers.add(peer);
                }
            }
            setStatus("Running: Downloads with external seeds = " + download_map.size());
        } finally {
            download_mon.exit();
        }
        if (add_listener) {
            download.addPeerListener(new DownloadPeerListener() {

                @Override
                public void peerManagerAdded(Download download, PeerManager peer_manager) {
                    List existing_peers = getPeers();
                    if (existing_peers == null) {
                        return;
                    }
                    for (int i = 0; i < existing_peers.size(); i++) {
                        ExternalSeedPeer peer = (ExternalSeedPeer) existing_peers.get(i);
                        peer.setManager(peer_manager);
                    }
                }

                @Override
                public void peerManagerRemoved(Download download, PeerManager peer_manager) {
                    List existing_peers = getPeers();
                    if (existing_peers == null) {
                        return;
                    }
                    for (int i = 0; i < existing_peers.size(); i++) {
                        ExternalSeedPeer peer = (ExternalSeedPeer) existing_peers.get(i);
                        peer.setManager(null);
                    }
                }

                protected List getPeers() {
                    List existing_peers = null;
                    try {
                        download_mon.enter();
                        List temp = (List) download_map.get(download);
                        if (temp != null) {
                            existing_peers = new ArrayList(temp.size());
                            existing_peers.addAll(temp);
                        }
                    } finally {
                        download_mon.exit();
                    }
                    return (existing_peers);
                }
            });
        } else {
            // fix up newly added peers to current peer manager
            PeerManager existing_pm = download.getPeerManager();
            if (existing_pm != null) {
                for (int i = 0; i < peers.size(); i++) {
                    ExternalSeedPeer peer = (ExternalSeedPeer) peers.get(i);
                    if (peer.getManager() == null) {
                        peer.setManager(existing_pm);
                    }
                }
            }
        }
    }
}
Also used : PeerManager(com.biglybt.pif.peers.PeerManager) DownloadPeerListener(com.biglybt.pif.download.DownloadPeerListener) Download(com.biglybt.pif.download.Download)

Example 79 with Download

use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.

the class SeedingRankColumnListener method refresh.

@Override
public void refresh(TableCell cell) {
    Download dl = (Download) cell.getDataSource();
    if (dl == null)
        return;
    DefaultRankCalculator dlData;
    Object o = cell.getSortValue();
    if (o instanceof DefaultRankCalculator)
        dlData = (DefaultRankCalculator) o;
    else {
        dlData = StartStopRulesDefaultPlugin.getRankCalculator(dl);
    }
    if (dlData == null) {
        cell.setSortValue(-1);
        return;
    }
    Sorter comp = (Sorter) dlData.getUserData(KEY);
    if (comp == null) {
        comp = new Sorter(dlData);
        dlData.setUserData(KEY, comp);
    }
    cell.setSortValue(comp);
    SeedingRank sr = dl.getSeedingRank();
    String[] status = sr.getStatus(false);
    cell.setText(status[0]);
    /* 
 		int state = dlData.getState();

		if ( state == Download.ST_STOPPED || state == Download.ST_ERROR ){
			
			cell.setText( "" );
			
		}else{
						
			cell.setText(status[0]);
		}
		*/
    cell.setToolTip(status[1]);
}
Also used : SeedingRank(com.biglybt.pif.download.Download.SeedingRank) Download(com.biglybt.pif.download.Download)

Example 80 with Download

use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.

the class DownloadManagerMoveHandler method recalculatePath.

public static SaveLocationChange recalculatePath(DownloadManager dm) {
    Download download = PluginCoreUtils.wrap(dm);
    SaveLocationChange result = null;
    if (canGoToCompleteDir(dm)) {
        result = CURRENT_HANDLER.onCompletion(download, true, false);
    }
    if (result == null) {
        result = CURRENT_HANDLER.onInitialization(download, true, false);
    }
    return result;
}
Also used : Download(com.biglybt.pif.download.Download) SaveLocationChange(com.biglybt.pif.download.savelocation.SaveLocationChange)

Aggregations

Download (com.biglybt.pif.download.Download)80 DownloadManager (com.biglybt.core.download.DownloadManager)22 Torrent (com.biglybt.pif.torrent.Torrent)17 DiskManagerFileInfo (com.biglybt.pif.disk.DiskManagerFileInfo)12 File (java.io.File)12 TOTorrent (com.biglybt.core.torrent.TOTorrent)11 PluginInterface (com.biglybt.pif.PluginInterface)11 URL (java.net.URL)10 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)8 PEPeerManager (com.biglybt.core.peer.PEPeerManager)8 List (java.util.List)7 Tag (com.biglybt.core.tag.Tag)6 MenuItem (com.biglybt.pif.ui.menus.MenuItem)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 DownloadException (com.biglybt.pif.download.DownloadException)5 DiskManager (com.biglybt.core.disk.DiskManager)4 DownloadManager (com.biglybt.pif.download.DownloadManager)4 DownloadScrapeResult (com.biglybt.pif.download.DownloadScrapeResult)4 Peer (com.biglybt.pif.peers.Peer)4