Search in sources :

Example 21 with DiskManagerFileInfo

use of com.biglybt.pif.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.

the class DeviceManagerUI method addDownload.

protected static void addDownload(TranscodeTarget target, TranscodeProfile profile, int transcode_requirement, Download download) {
    // we could use the primary file
    // int index = DownloadManagerEnhancer.getSingleton().getEnhancedDownload(hash).getPrimaryFile().getIndex();
    // DiskManagerFileInfo dm_file = plugin_interface.getShortCuts().getDownload(hash).getDiskManagerFileInfo()[index];
    // but lets just grab all files
    DiskManagerFileInfo[] dm_files = download.getDiskManagerFileInfo();
    int num_added = 0;
    for (DiskManagerFileInfo dm_file : dm_files) {
        if (num_added > MAX_FILES_FOR_MULTI_XCODE) {
            break;
        }
        if (dm_files.length == 1 || dm_file.getLength() >= MIN_FILE_SIZE_FOR_XCODE) {
            addFile(target, profile, transcode_requirement, dm_file);
            num_added++;
        }
    }
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) Point(org.eclipse.swt.graphics.Point)

Example 22 with DiskManagerFileInfo

use of com.biglybt.pif.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.

the class StartStopRulesDefaultPlugin method getMaxActive.

protected int getMaxActive() {
    if (!_maxActiveWhenSeedingEnabled)
        return (_maxActive);
    if (download_manager.isSeedingOnly()) {
        if (_maxActiveWhenSeeding <= _maxActive)
            return (_maxActiveWhenSeeding);
        // danger here if we are in a position where allowing more to start when seeding
        // allows a non-seeding download to start (looping occurs)
        Download[] downloads = download_manager.getDownloads();
        boolean danger = false;
        for (int i = 0; i < downloads.length && !danger; i++) {
            Download download = downloads[i];
            int state = download.getState();
            if (state == Download.ST_DOWNLOADING || state == Download.ST_SEEDING || state == Download.ST_STOPPED || state == Download.ST_STOPPING || state == Download.ST_ERROR) {
            // not interesting, they can't potentially cause trouble
            } else {
                // look for incomplete files
                DiskManagerFileInfo[] files = download.getDiskManagerFileInfo();
                for (int j = 0; j < files.length; j++) {
                    DiskManagerFileInfo file = files[j];
                    if ((!file.isSkipped()) && file.getDownloaded() != file.getLength()) {
                        danger = true;
                        break;
                    }
                }
            }
        }
        if (!danger)
            return (_maxActiveWhenSeeding);
    }
    return (_maxActive);
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo)

Example 23 with DiskManagerFileInfo

use of com.biglybt.pif.disk.DiskManagerFileInfo 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);
    az2_handler = new BuddyPluginAZ2(this);
    sec_man = plugin_interface.getUtilities().getSecurityManager();
    logger = plugin_interface.getLogger().getChannel("Friends");
    logger.setDiagnostic();
    final LocaleUtilities lu = plugin_interface.getUtilities().getLocaleUtilities();
    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);
    // nickname
    nick_name_param = config.addStringParameter2("azbuddy.nickname", "azbuddy.nickname", "");
    nick_name_param.setGenerateIntermediateEvents(false);
    nick_name_param.addListener(new ParameterListener() {

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

        @Override
        public void parameterChanged(Parameter param) {
            int status = Integer.parseInt(online_status_param.getValue());
            updateOnlineStatus(status);
        }
    });
    // If we add this then use proper message texts in the STATUS_STRINGS
    online_status_param.setVisible(SUPPORT_ONLINE_STATUS);
    // 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);
    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();
    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, nick_name_param, online_status_param, protocol_speed, enable_chat_notifications, cat_pub, tracker_enable, tracker_so_enable, buddies_lan_local });
    // 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 end
    beta_plugin = new BuddyPluginBeta(plugin_interface, this, beta_enabled_param);
    final TableContextMenuItem menu_item_itorrents = plugin_interface.getUIManager().getTableManager().addContextMenuItem(TableManager.TABLE_MYTORRENTS_INCOMPLETE, "azbuddy.contextmenu");
    final TableContextMenuItem menu_item_ctorrents = plugin_interface.getUIManager().getTableManager().addContextMenuItem(TableManager.TABLE_MYTORRENTS_COMPLETE, "azbuddy.contextmenu");
    menu_item_itorrents.setStyle(TableContextMenuItem.STYLE_MENU);
    menu_item_itorrents.setHeaderCategory(MenuItem.HEADER_SOCIAL);
    menu_item_ctorrents.setStyle(TableContextMenuItem.STYLE_MENU);
    menu_item_ctorrents.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();
                boolean incomplete = ((TableContextMenuItem) menu).getTableID() == TableManager.TABLE_MYTORRENTS_INCOMPLETE;
                TableContextMenuItem parent = incomplete ? menu_item_itorrents : menu_item_ctorrents;
                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(parent, "!" + buddy.getName() + (online ? "" : (" - " + MessageText.getString("label.disconnected"))) + "!");
                    item.addMultiListener(new MenuItemListener() {

                        @Override
                        public void selected(MenuItem menu, Object target) {
                            for (Torrent torrent : torrents) {
                                az2_handler.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_itorrents.addFillListener(menu_fill_listener);
    menu_item_ctorrents.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, String.class }).newInstance(new Object[] { BuddyPlugin.this, instance, VIEW_ID });
                        for (Runnable r : swt_ui_waiters) {
                            try {
                                r.run();
                            } catch (Throwable e) {
                                Debug.out(e);
                            }
                        }
                        swt_ui_waiters.clear();
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
            setupDisablePrompt(instance);
        }

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

        @Override
        public void parameterChanged(Parameter param) {
            boolean classic_enabled = classic_enabled_param.getValue();
            nick_name_param.setEnabled(classic_enabled);
            online_status_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(tracker_enable.getValue());
            if (param != null) {
                setClassicEnabledInternal(classic_enabled);
                fireEnabledStateChanged();
            }
        }
    };
    enabled_listener.parameterChanged(null);
    classic_enabled_param.addListener(enabled_listener);
    beta_enabled_param.addListener(enabled_listener);
    tracker_enable.addListener(enabled_listener);
    loadConfig();
    registerMessageHandler();
    plugin_interface.addListener(new PluginListener() {

        @Override
        public void initializationComplete() {
            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() {
            saveConfig(true);
            closedown();
            beta_plugin.closedown();
        }

        @Override
        public void closedownComplete() {
        }
    });
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) PluginListener(com.biglybt.pif.PluginListener) ConnectionManager(com.biglybt.pif.network.ConnectionManager) DownloadException(com.biglybt.pif.download.DownloadException) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) BuddyPluginTracker(com.biglybt.plugin.net.buddy.tracker.BuddyPluginTracker) Download(com.biglybt.pif.download.Download) UIInstance(com.biglybt.pif.ui.UIInstance) DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) TableRow(com.biglybt.pif.ui.tables.TableRow) ParameterListener(com.biglybt.pif.ui.config.ParameterListener) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Aggregations

DiskManagerFileInfo (com.biglybt.pif.disk.DiskManagerFileInfo)23 Download (com.biglybt.pif.download.Download)11 DownloadException (com.biglybt.pif.download.DownloadException)5 IPCInterface (com.biglybt.pif.ipc.IPCInterface)5 Torrent (com.biglybt.pif.torrent.Torrent)3 Point (org.eclipse.swt.graphics.Point)3 ContentFile (com.biglybt.core.content.ContentFile)2 TranscodeFile (com.biglybt.core.devices.TranscodeFile)2 TranscodeJob (com.biglybt.core.devices.TranscodeJob)2 DownloadManager (com.biglybt.core.download.DownloadManager)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 MenuItem (com.biglybt.pif.ui.menus.MenuItem)2 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)2 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)2 TableContextMenuItem (com.biglybt.pif.ui.tables.TableContextMenuItem)2 TableRow (com.biglybt.pif.ui.tables.TableRow)2 ISelectedContent (com.biglybt.ui.selectedcontent.ISelectedContent)2 File (java.io.File)2 URL (java.net.URL)2 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)1