Search in sources :

Example 46 with Download

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

the class TorrentMenuFancy method buildTorrentCustomMenu_Control.

public void buildTorrentCustomMenu_Control(final Composite cParent, final DownloadManager[] dms) {
    final int userMode = COConfigurationManager.getIntParameter("User Mode");
    boolean start = false;
    boolean stop = false;
    boolean pause = false;
    boolean recheck = false;
    boolean barsOpened = true;
    boolean bChangeDir = hasSelection;
    for (int i = 0; i < dms.length; i++) {
        DownloadManager dm = dms[i];
        if (barsOpened && !DownloadBar.getManager().isOpen(dm)) {
            barsOpened = false;
        }
        stop = stop || ManagerUtils.isStopable(dm);
        start = start || ManagerUtils.isStartable(dm);
        pause = pause || ManagerUtils.isPauseable(dm);
        recheck = recheck || dm.canForceRecheck();
        boolean stopped = ManagerUtils.isStopped(dm);
        int state = dm.getState();
        bChangeDir &= (state == DownloadManager.STATE_ERROR || state == DownloadManager.STATE_STOPPED || state == DownloadManager.STATE_QUEUED);
        /**
         * Only perform a test on disk if:
         *    1) We are currently set to allow the "Change Data Directory" option, and
         *    2) We've only got one item selected - otherwise, we may potentially end up checking massive
         *       amounts of files across multiple torrents before we generate a menu.
         */
        if (bChangeDir && dms.length == 1) {
            bChangeDir = dm.isDataAlreadyAllocated();
            if (bChangeDir && state == DownloadManager.STATE_ERROR) {
                // filesExist is way too slow!
                bChangeDir = !dm.filesExist(true);
            } else {
                DiskManagerFileInfo[] files = dm.getDiskManagerFileInfoSet().getFiles();
                bChangeDir = false;
                for (DiskManagerFileInfo info : files) {
                    if (info.isSkipped()) {
                        continue;
                    }
                    bChangeDir = !info.getFile(true).exists();
                    break;
                }
            }
        }
    }
    Composite cQuickCommands = new Composite(cParent, SWT.NONE);
    // cQuickCommands.setBackground(ColorCache.getRandomColor());
    RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
    rowLayout.justify = true;
    rowLayout.marginLeft = 0;
    rowLayout.marginRight = 0;
    cQuickCommands.setLayout(rowLayout);
    GridData gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    cQuickCommands.setLayoutData(gd);
    // Queue
    createActionButton(dms, cQuickCommands, "MyTorrentsView.menu.queue", "start", start, (ListenerGetOffSWT) event -> TorrentUtil.queueDataSources(dms, false));
    if (TorrentUtil.isForceStartVisible(dms)) {
        boolean forceStart = false;
        boolean forceStartEnabled = false;
        for (int i = 0; i < dms.length; i++) {
            DownloadManager dm = dms[i];
            forceStartEnabled = forceStartEnabled || ManagerUtils.isForceStartable(dm);
            forceStart = forceStart || dm.isForceStart();
        }
        final boolean newForceStart = !forceStart;
        createActionButton(dms, cQuickCommands, "MyTorrentsView.menu.forceStart", "forcestart", forceStartEnabled, !newForceStart, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager dm) {
                if (ManagerUtils.isForceStartable(dm)) {
                    dm.setForceStart(newForceStart);
                }
            }
        });
    }
    // Pause
    if (userMode > 0) {
        createActionButton(dms, cQuickCommands, "v3.MainWindow.button.pause", "pause", pause, (ListenerGetOffSWT) event -> TorrentUtil.pauseDataSources(dms));
    }
    // Stop
    createActionButton(dms, cQuickCommands, "MyTorrentsView.menu.stop", "stop", stop, (ListenerGetOffSWT) event -> TorrentUtil.stopDataSources(dms));
    // Force Recheck
    createActionButton(dms, cQuickCommands, "MyTorrentsView.menu.recheck", "recheck", recheck, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager dm) {
            if (dm.canForceRecheck()) {
                dm.forceRecheck();
            }
        }
    });
    // Delete
    createActionButton(dms, cQuickCommands, "menu.delete.options", "delete", hasSelection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            TorrentUtil.removeDownloads(dms, null, true);
        }
    });
    if (bChangeDir) {
        createRow(cParent, "MyTorrentsView.menu.changeDirectory", null, new Listener() {

            @Override
            public void handleEvent(Event e) {
                TorrentUtil.changeDirSelectedTorrents(dms, parentShell);
            }
        });
    }
    // Open Details
    if (hasSelection) {
        createRow(cParent, "MyTorrentsView.menu.showdetails", "details", new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager dm) {
                UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                if (uiFunctions != null) {
                    uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, dm);
                }
            }
        });
    }
    // Open Bar
    if (hasSelection) {
        FancyRowInfo row = createRow(cParent, "MyTorrentsView.menu.showdownloadbar", "downloadBar", new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager dm) {
                if (DownloadBar.getManager().isOpen(dm)) {
                    DownloadBar.close(dm);
                } else {
                    DownloadBar.open(dm, parentShell);
                }
            }
        });
        row.setSelection(barsOpened);
    }
    if (hasSelection) {
        FancyRowInfo rowSpeedDL = createRow(cParent, "MyTorrentsView.menu.downSpeedLimit", "image.torrentspeed.down", false, new Listener() {

            @Override
            public void handleEvent(Event e) {
                Event event = new Event();
                event.type = SWT.MouseUp;
                event.widget = e.widget;
                event.stateMask = e.stateMask;
                event.button = e.button;
                e.display.post(event);
                Core core = CoreFactory.getSingleton();
                SelectableSpeedMenu.invokeSlider((Control) event.widget, core, dms, false, shell);
                if (e.display.getActiveShell() != shell) {
                    if (!shell.isDisposed()) {
                        shell.dispose();
                    }
                    return;
                }
                FancyRowInfo rowInfo = findRowInfo(event.widget);
                if (rowInfo != null) {
                    updateRowSpeed(rowInfo, false);
                }
            }
        });
        rowSpeedDL.keepMenu = true;
        updateRowSpeed(rowSpeedDL, false);
    }
    if (hasSelection) {
        FancyRowInfo rowSpeedUL = createRow(cParent, "MyTorrentsView.menu.upSpeedLimit", "image.torrentspeed.up", false, new Listener() {

            @Override
            public void handleEvent(Event e) {
                Event event = new Event();
                event.type = SWT.MouseUp;
                event.widget = e.widget;
                event.stateMask = e.stateMask;
                event.button = e.button;
                e.display.post(event);
                Core core = CoreFactory.getSingleton();
                SelectableSpeedMenu.invokeSlider((Control) e.widget, core, dms, true, shell);
                if (e.display.getActiveShell() != shell) {
                    if (!shell.isDisposed()) {
                        shell.dispose();
                    }
                    return;
                }
                FancyRowInfo rowInfo = findRowInfo(event.widget);
                if (rowInfo != null) {
                    updateRowSpeed(rowInfo, true);
                }
            }
        });
        rowSpeedUL.keepMenu = true;
        updateRowSpeed(rowSpeedUL, true);
    }
    if (hasSelection && userMode > 0) {
        createMenuRow(cParent, "MyTorrentsView.menu.tracker", null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu menu) {
                boolean changeUrl = hasSelection;
                boolean manualUpdate = true;
                boolean allStopped = true;
                boolean canMove = true;
                int userMode = COConfigurationManager.getIntParameter("User Mode");
                final boolean use_open_containing_folder = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
                for (DownloadManager dm : dms) {
                    boolean stopped = ManagerUtils.isStopped(dm);
                    allStopped &= stopped;
                    canMove = canMove && dm.canMoveDataFiles();
                    if (userMode < 2) {
                        TRTrackerAnnouncer trackerClient = dm.getTrackerClient();
                        if (trackerClient != null) {
                            boolean update_state = ((SystemTime.getCurrentTime() / 1000 - trackerClient.getLastUpdateTime() >= TRTrackerAnnouncer.REFRESH_MINIMUM_SECS));
                            manualUpdate = manualUpdate & update_state;
                        }
                    }
                }
                TorrentUtil.addTrackerTorrentMenu(menu, dms, changeUrl, manualUpdate, allStopped, use_open_containing_folder, canMove);
            }
        });
    }
    if (hasSelection) {
        Core core = CoreFactory.getSingleton();
        SpeedLimitHandler slh = SpeedLimitHandler.getSingleton(core);
        if (slh.hasAnyProfiles()) {
            createMenuRow(cParent, IMenuConstants.MENU_ID_SPEED_LIMITS, null, new FancyMenuRowInfoListener() {

                @Override
                public void buildMenu(Menu menu) {
                    TorrentUtil.addSpeedLimitsMenu(dms, menu);
                }
            });
        }
    }
    if (userMode > 0 && hasSelection) {
        boolean can_pause_for = false;
        for (int i = 0; i < dms.length; i++) {
            DownloadManager dm = dms[i];
            if (dm.isPaused() || ManagerUtils.isPauseable(dm)) {
                can_pause_for = true;
                break;
            }
        }
        if (can_pause_for) {
            createRow(detailArea, "MainWindow.menu.transfers.pausetransfersfor", null, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    TorrentUtil.pauseDownloadsFor(dms);
                }
            });
        }
    }
    if (userMode > 0 && dms.length > 1) {
        createRow(cParent, "label.options.and.info", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                if (uiFunctions != null) {
                    uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, dms);
                }
            }
        });
    }
    if (userMode > 0) {
        createMenuRow(cParent, "MyTorrentsView.menu.peersource", null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu menu) {
                TorrentUtil.addPeerSourceSubMenu(dms, menu);
            }
        });
    }
    // Sequential download
    {
        boolean allSeq = true;
        boolean AllNonSeq = true;
        for (int j = 0; j < dms.length; j++) {
            DownloadManager dm = dms[j];
            boolean seq = dm.getDownloadState().getFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD);
            if (seq) {
                AllNonSeq = false;
            } else {
                allSeq = false;
            }
        }
        boolean bChecked;
        if (allSeq) {
            bChecked = true;
        } else if (AllNonSeq) {
            bChecked = false;
        } else {
            bChecked = false;
        }
        final boolean newSeq = !bChecked;
        FancyRowInfo row = createRow(cParent, "menu.sequential.download", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager dm) {
                dm.getDownloadState().setFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD, newSeq);
            }
        });
        row.setSelection(bChecked);
    }
    // IP Filter Enable
    if (userMode > 0 && IpFilterManagerFactory.getSingleton().getIPFilter().isEnabled()) {
        boolean allEnabled = true;
        boolean allDisabled = true;
        for (int j = 0; j < dms.length; j++) {
            DownloadManager dm = dms[j];
            boolean filterDisabled = dm.getDownloadState().getFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER);
            if (filterDisabled) {
                allEnabled = false;
            } else {
                allDisabled = false;
            }
        }
        boolean bChecked;
        if (allEnabled) {
            bChecked = true;
        } else if (allDisabled) {
            bChecked = false;
        } else {
            bChecked = false;
        }
        final boolean newDisable = bChecked;
        FancyRowInfo row = createRow(cParent, "MyTorrentsView.menu.ipf_enable", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager dm) {
                dm.getDownloadState().setFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER, newDisable);
            }
        });
        row.setSelection(bChecked);
    }
    if (userMode > 1) {
        createMenuRow(cParent, "MyTorrentsView.menu.networks", null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu menu) {
                TorrentUtil.addNetworksSubMenu(dms, menu);
            }
        });
    }
    // Advanced menu with stuff I don't know where to put
    if (userMode > 0) {
        createMenuRow(cParent, "MyTorrentsView.menu.advancedmenu", null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu menu) {
                boolean allStopped = true;
                boolean allScanSelected = true;
                boolean allScanNotSelected = true;
                boolean fileMove = true;
                boolean allResumeIncomplete = true;
                boolean hasClearableLinks = false;
                boolean hasRevertableFiles = false;
                boolean lrrecheck = false;
                boolean allAllocatable = true;
                boolean allMaskDC = true;
                for (DownloadManager dm : dms) {
                    boolean stopped = ManagerUtils.isStopped(dm);
                    allStopped &= stopped;
                    fileMove = fileMove && dm.canMoveDataFiles();
                    boolean scan = dm.getDownloadState().getFlag(DownloadManagerState.FLAG_SCAN_INCOMPLETE_PIECES);
                    // include DND files in incomplete stat, since a recheck may
                    // find those files have been completed
                    boolean incomplete = !dm.isDownloadComplete(true);
                    allScanSelected = incomplete && allScanSelected && scan;
                    allScanNotSelected = incomplete && allScanNotSelected && !scan;
                    DownloadManagerState dms = dm.getDownloadState();
                    if (dms.isResumeDataComplete()) {
                        allResumeIncomplete = false;
                    }
                    if (stopped && !hasClearableLinks) {
                        if (dm.getDiskManagerFileInfoSet().nbFiles() > 1) {
                            if (dms.getFileLinks().hasLinks()) {
                                hasClearableLinks = true;
                            }
                        }
                    }
                    if (dm.getDownloadState().getFileLinks().size() > 0) {
                        hasRevertableFiles = true;
                    }
                    lrrecheck = lrrecheck || ManagerUtils.canLowResourceRecheck(dm);
                    allAllocatable &= stopped && !dm.isDataAlreadyAllocated() && !dm.isDownloadComplete(false);
                    allMaskDC = allMaskDC && dms.getBooleanAttribute(DownloadManagerState.AT_MASK_DL_COMP);
                }
                boolean fileRescan = allScanSelected || allScanNotSelected;
                final MenuItem itemFileRescan = new MenuItem(menu, SWT.CHECK);
                Messages.setLanguageText(itemFileRescan, "MyTorrentsView.menu.rescanfile");
                itemFileRescan.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager dm) {
                        dm.getDownloadState().setFlag(DownloadManagerState.FLAG_SCAN_INCOMPLETE_PIECES, itemFileRescan.getSelection());
                    }
                });
                itemFileRescan.setSelection(allScanSelected);
                itemFileRescan.setEnabled(fileRescan);
                // low resource recheck
                final MenuItem itemLowResourceRecheck = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(itemLowResourceRecheck, "MyTorrentsView.menu.lowresourcerecheck");
                itemLowResourceRecheck.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager dm) {
                        ManagerUtils.lowResourceRecheck(dm);
                    }
                });
                itemLowResourceRecheck.setEnabled(lrrecheck);
                // revert
                final MenuItem itemRevertFiles = new MenuItem(menu, SWT.PUSH);
                itemRevertFiles.setText(MessageText.getString("MyTorrentsView.menu.revertfiles") + "...");
                itemRevertFiles.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager[] dms) {
                        FilesViewMenuUtil.revertFiles(tv, dms);
                    }
                });
                itemRevertFiles.setEnabled(hasRevertableFiles);
                // view links
                final MenuItem itemViewLinks = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(itemViewLinks, "menu.view.links");
                itemViewLinks.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager[] dms) {
                        ManagerUtils.viewLinks(dms);
                    }
                });
                // clear links
                final MenuItem itemClearLinks = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(itemClearLinks, "FilesView.menu.clear.links");
                itemClearLinks.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager dm) {
                        if (ManagerUtils.isStopped(dm) && dm.getDownloadState().getFileLinks().hasLinks()) {
                            DiskManagerFileInfoSet fis = dm.getDiskManagerFileInfoSet();
                            if (fis.nbFiles() > 1) {
                                DiskManagerFileInfo[] files = fis.getFiles();
                                for (DiskManagerFileInfo file_info : files) {
                                    File file_link = file_info.getFile(true);
                                    File file_nolink = file_info.getFile(false);
                                    if (!file_nolink.getAbsolutePath().equals(file_link.getAbsolutePath())) {
                                        file_info.setLink(null);
                                    }
                                }
                            }
                        }
                    }
                });
                itemClearLinks.setEnabled(hasClearableLinks);
                // allocate
                MenuItem itemFileAlloc = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(itemFileAlloc, "label.allocate");
                itemFileAlloc.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager dm) {
                        dm.getDownloadState().setLongAttribute(DownloadManagerState.AT_FILE_ALLOC_STRATEGY, DownloadManagerState.FAS_ZERO_NEW_STOP);
                        dm.getDownloadState().setFlag(DownloadManagerState.FLAG_DISABLE_STOP_AFTER_ALLOC, false);
                        ManagerUtils.queue(dm, null);
                    }
                });
                itemFileAlloc.setEnabled(allAllocatable);
                // clear allocation
                MenuItem itemFileClearAlloc = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(itemFileClearAlloc, "MyTorrentsView.menu.clear_alloc_data");
                itemFileClearAlloc.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager dm) {
                        dm.setDataAlreadyAllocated(false);
                    }
                });
                itemFileClearAlloc.setEnabled(allStopped);
                // clear resume
                MenuItem itemFileClearResume = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(itemFileClearResume, "MyTorrentsView.menu.clear_resume_data");
                itemFileClearResume.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager dm) {
                        dm.getDownloadState().clearResumeData();
                    }
                });
                itemFileClearResume.setEnabled(allStopped);
                // set resume complete
                MenuItem itemFileSetResumeComplete = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(itemFileSetResumeComplete, "MyTorrentsView.menu.set.resume.complete");
                itemFileSetResumeComplete.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager dm) {
                        TorrentUtils.setResumeDataCompletelyValid(dm.getDownloadState());
                    }
                });
                itemFileSetResumeComplete.setEnabled(allStopped && allResumeIncomplete);
                // mask dl comp
                boolean globalMask = COConfigurationManager.getBooleanParameter(ConfigKeys.Transfer.BCFG_PEERCONTROL_HIDE_PIECE);
                MenuItem itemMaskDLComp = new MenuItem(menu, SWT.CHECK);
                if (dms.length > 0) {
                    itemMaskDLComp.setSelection(globalMask || allMaskDC);
                }
                Messages.setLanguageText(itemMaskDLComp, "ConfigView.label.hap");
                itemMaskDLComp.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager dm) {
                        dm.getDownloadState().setBooleanAttribute(DownloadManagerState.AT_MASK_DL_COMP, itemMaskDLComp.getSelection());
                    }
                });
                itemMaskDLComp.setEnabled(dms.length > 0 && !globalMask);
                if (userMode > 1 && isSeedingView) {
                    boolean canSetSuperSeed = false;
                    boolean superSeedAllYes = true;
                    boolean superSeedAllNo = true;
                    for (DownloadManager dm : dms) {
                        PEPeerManager pm = dm.getPeerManager();
                        if (pm != null) {
                            if (pm.canToggleSuperSeedMode()) {
                                canSetSuperSeed = true;
                            }
                            if (pm.isSuperSeedMode()) {
                                superSeedAllYes = false;
                            } else {
                                superSeedAllNo = false;
                            }
                        } else {
                            superSeedAllYes = false;
                            superSeedAllNo = false;
                        }
                    }
                    final MenuItem itemSuperSeed = new MenuItem(menu, SWT.CHECK);
                    Messages.setLanguageText(itemSuperSeed, "ManagerItem.superseeding");
                    boolean enabled = canSetSuperSeed && (superSeedAllNo || superSeedAllYes);
                    itemSuperSeed.setEnabled(enabled);
                    final boolean selected = superSeedAllNo;
                    if (enabled) {
                        itemSuperSeed.setSelection(selected);
                        itemSuperSeed.addListener(SWT.Selection, new ListenerDMTask(dms) {

                            @Override
                            public void run(DownloadManager dm) {
                                PEPeerManager pm = dm.getPeerManager();
                                if (pm != null) {
                                    if (pm.isSuperSeedMode() == selected && pm.canToggleSuperSeedMode()) {
                                        pm.setSuperSeedMode(!selected);
                                    }
                                }
                            }
                        });
                    }
                }
            }
        });
    }
}
Also used : Graphic(com.biglybt.pif.ui.Graphic) COConfigurationManager(com.biglybt.core.config.COConfigurationManager) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) TableRowCore(com.biglybt.ui.common.table.TableRowCore) UIFunctionsManager(com.biglybt.ui.UIFunctionsManager) Clipboard(org.eclipse.swt.dnd.Clipboard) ShareUtils(com.biglybt.ui.swt.sharing.ShareUtils) GraphicURI(com.biglybt.pif.ui.GraphicURI) FilesViewMenuUtil(com.biglybt.ui.swt.views.FilesViewMenuUtil) IpFilterManagerFactory(com.biglybt.core.ipfilter.IpFilterManagerFactory) TableCellCore(com.biglybt.ui.common.table.TableCellCore) org.eclipse.swt.layout(org.eclipse.swt.layout) org.eclipse.swt.graphics(org.eclipse.swt.graphics) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) MessageText(com.biglybt.core.internat.MessageText) Transfer(org.eclipse.swt.dnd.Transfer) ConfigKeys(com.biglybt.core.config.ConfigKeys) List(java.util.List) com.biglybt.ui.swt.mainwindow(com.biglybt.ui.swt.mainwindow) TagUIUtils(com.biglybt.ui.swt.views.utils.TagUIUtils) SWT(org.eclipse.swt.SWT) UIFunctions(com.biglybt.ui.UIFunctions) java.util(java.util) DiskManagerFileInfoSet(com.biglybt.core.disk.DiskManagerFileInfoSet) MenuManager(com.biglybt.pif.ui.menus.MenuManager) ExportTorrentWizard(com.biglybt.ui.swt.exporttorrent.wizard.ExportTorrentWizard) MenuBuilder(com.biglybt.pif.ui.menus.MenuBuilder) Download(com.biglybt.pif.download.Download) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) TOTorrent(com.biglybt.core.torrent.TOTorrent) PEPeerManager(com.biglybt.core.peer.PEPeerManager) SpeedLimitHandler(com.biglybt.core.speedmanager.SpeedLimitHandler) ManagerUtils(com.biglybt.ui.swt.views.utils.ManagerUtils) DownloadManagerState(com.biglybt.core.download.DownloadManagerState) MenuItemManager(com.biglybt.ui.common.util.MenuItemManager) TextTransfer(org.eclipse.swt.dnd.TextTransfer) MenuItem(com.biglybt.pif.ui.menus.MenuItem) CoreFactory(com.biglybt.core.CoreFactory) PluginCoreUtils(com.biglybt.pifimpl.local.PluginCoreUtils) TableSelectedRowsListener(com.biglybt.ui.swt.views.table.TableSelectedRowsListener) Core(com.biglybt.core.Core) TableColumnSetupWindow(com.biglybt.ui.swt.views.columnsetup.TableColumnSetupWindow) TableStructureEventDispatcher(com.biglybt.ui.common.table.TableStructureEventDispatcher) PlatformTorrentUtils(com.biglybt.core.torrent.PlatformTorrentUtils) org.eclipse.swt.events(org.eclipse.swt.events) TableContextMenuManager(com.biglybt.ui.common.table.impl.TableContextMenuManager) org.eclipse.swt.widgets(org.eclipse.swt.widgets) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) File(java.io.File) DownloadManager(com.biglybt.core.download.DownloadManager) TRTrackerAnnouncer(com.biglybt.core.tracker.client.TRTrackerAnnouncer) com.biglybt.core.util(com.biglybt.core.util) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface) DownloadBar(com.biglybt.ui.swt.minibar.DownloadBar) MenuItemImpl(com.biglybt.pifimpl.local.ui.menus.MenuItemImpl) TableViewSWT(com.biglybt.ui.swt.views.table.TableViewSWT) TRTrackerUtils(com.biglybt.core.tracker.util.TRTrackerUtils) TableSelectedRowsListener(com.biglybt.ui.swt.views.table.TableSelectedRowsListener) SpeedLimitHandler(com.biglybt.core.speedmanager.SpeedLimitHandler) DownloadManager(com.biglybt.core.download.DownloadManager) DownloadManagerState(com.biglybt.core.download.DownloadManagerState) UIFunctions(com.biglybt.ui.UIFunctions) TableRowCore(com.biglybt.ui.common.table.TableRowCore) TableCellCore(com.biglybt.ui.common.table.TableCellCore) Core(com.biglybt.core.Core) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) DiskManagerFileInfoSet(com.biglybt.core.disk.DiskManagerFileInfoSet) MenuItem(com.biglybt.pif.ui.menus.MenuItem) TRTrackerAnnouncer(com.biglybt.core.tracker.client.TRTrackerAnnouncer) PEPeerManager(com.biglybt.core.peer.PEPeerManager) File(java.io.File)

Example 47 with Download

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

the class TorrentMenuFancy method getTarget.

private Object[] getTarget(com.biglybt.pif.ui.menus.MenuItem item) {
    if (MenuManager.MENU_TABLE.equals(item.getMenuID())) {
        TableRowCore[] rows = tv.getSelectedRows();
        List<TableRowCore> result = new ArrayList<TableRowCore>(rows.length);
        for (TableRowCore row : rows) {
            if (row.getDataSource(false) instanceof Download) {
                result.add(row);
            }
        }
        return (result.toArray(new TableRowCore[result.size()]));
    } else {
        Object[] dataSources = tv.getSelectedDataSources(false);
        List<Download> result = new ArrayList<>(dataSources.length);
        for (Object ds : dataSources) {
            if (ds instanceof Download) {
                result.add((Download) ds);
            }
        }
        return (result.toArray(new Download[result.size()]));
    }
}
Also used : TableRowCore(com.biglybt.ui.common.table.TableRowCore) Download(com.biglybt.pif.download.Download)

Example 48 with Download

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

the class MySharesView method refreshToolBarItems.

@Override
public void refreshToolBarItems(Map<String, Long> list) {
    boolean start = false, stop = false, remove = false;
    if (!CoreFactory.isCoreRunning()) {
        return;
    }
    List items = getSelectedItems();
    if (items.size() > 0) {
        PluginInterface pi = PluginInitializer.getDefaultInterface();
        com.biglybt.pif.download.DownloadManager dm = pi.getDownloadManager();
        remove = true;
        for (int i = 0; i < items.size(); i++) {
            ShareItem item = (ShareItem) items.get(i);
            try {
                Torrent t = item.getTorrent();
                Download download = dm.getDownload(t);
                if (download == null) {
                    continue;
                }
                int dl_state = download.getState();
                if (dl_state == Download.ST_ERROR) {
                } else if (dl_state != Download.ST_STOPPED) {
                    stop = true;
                } else {
                    start = true;
                }
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
        }
    }
    list.put("start", start ? UIToolBarItem.STATE_ENABLED : 0);
    list.put("stop", stop ? UIToolBarItem.STATE_ENABLED : 0);
    list.put("remove", remove ? UIToolBarItem.STATE_ENABLED : 0);
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent) TrackerTorrent(com.biglybt.pif.tracker.TrackerTorrent) PluginInterface(com.biglybt.pif.PluginInterface) List(java.util.List) Download(com.biglybt.pif.download.Download)

Example 49 with Download

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

the class RelatedContentManager method checkI2PSearcher.

void checkI2PSearcher(boolean force) {
    synchronized (searchers) {
        if (added_i2p_searcher) {
            return;
        }
        if (!force) {
            DownloadManager dm = plugin_interface.getDownloadManager();
            Download[] downloads = dm.getDownloads();
            boolean found = false;
            for (Download download : downloads) {
                String[] nets = PluginCoreUtils.unwrap(download).getDownloadState().getNetworks();
                if (nets.length == 1 && nets[0] == AENetworkClassifier.AT_I2P) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                return;
            }
        }
        List<DistributedDatabase> ddbs = DDBaseImpl.getDDBs(new String[] { AENetworkClassifier.AT_I2P });
        for (DistributedDatabase ddb : ddbs) {
            if (ddb.getNetwork() == AENetworkClassifier.AT_I2P) {
                DHTPluginInterface i2p_dht = ddb.getDHTPlugin();
                RelatedContentSearcher i2p_searcher = new RelatedContentSearcher(RelatedContentManager.this, transfer_type, i2p_dht, false);
                searchers.add(i2p_searcher);
                added_i2p_searcher = true;
            }
        }
    }
}
Also used : DistributedDatabase(com.biglybt.pif.ddb.DistributedDatabase) DownloadManager(com.biglybt.pif.download.DownloadManager) Download(com.biglybt.pif.download.Download)

Example 50 with Download

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

the class RelatedContentManager method checkAlternativePubs.

void checkAlternativePubs(DownloadInfo to_info, final byte[] map_bytes, final int f_cutoff) {
    Download dl = to_info.getRelatedToDownload();
    if (dl != null) {
        DiskManagerFileInfo[] files = dl.getDiskManagerFileInfo();
        List<Long> sizes = new ArrayList<>();
        for (DiskManagerFileInfo file : files) {
            long size = file.getLength();
            if (size >= FILE_ASSOC_MIN_SIZE) {
                sizes.add(size);
            }
        }
        final DHTPluginInterface dht_plugin = selectDHT(to_info.getNetworksInternal());
        if (dht_plugin != null && sizes.size() > 0) {
            try {
                final String to_hash = ByteFormatter.encodeString(to_info.getHash());
                final long selected_size = sizes.get(new Random().nextInt(sizes.size()));
                final byte[] key_bytes = ("az:rcm:size:assoc:" + selected_size).getBytes("UTF-8");
                int max_hits = 30;
                dht_plugin.get(key_bytes, "Content size rel test: " + to_hash.substring(0, 16), DHTPlugin.FLAG_SINGLE_VALUE, max_hits, 30 * 1000, false, false, new DHTPluginOperationListener() {

                    private boolean diversified;

                    private int hits;

                    private Set<String> entries = new HashSet<>();

                    @Override
                    public void starts(byte[] key) {
                    }

                    @Override
                    public boolean diversified() {
                        diversified = true;
                        return (false);
                    }

                    @Override
                    public void valueRead(DHTPluginContact originator, DHTPluginValue value) {
                        hits++;
                    }

                    @Override
                    public void valueWritten(DHTPluginContact target, DHTPluginValue value) {
                    }

                    @Override
                    public void complete(byte[] key, boolean timeout_occurred) {
                        boolean do_it;
                        if (diversified || hits >= f_cutoff) {
                            do_it = false;
                        } else if (hits <= f_cutoff / 2) {
                            do_it = true;
                        } else {
                            do_it = RandomUtils.nextInt(hits - (f_cutoff / 2) + 1) == 0;
                        }
                        if (do_it) {
                            try {
                                dht_plugin.put(key_bytes, "Content size rel: " + selected_size + " -> " + to_hash.substring(0, 16), map_bytes, DHTPlugin.FLAG_ANON, new DHTPluginOperationListener() {

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

                                    @Override
                                    public void starts(byte[] key) {
                                    }

                                    @Override
                                    public void valueRead(DHTPluginContact originator, DHTPluginValue value) {
                                    }

                                    @Override
                                    public void valueWritten(DHTPluginContact target, DHTPluginValue value) {
                                    }

                                    @Override
                                    public void complete(byte[] key, boolean timeout_occurred) {
                                    }
                                });
                            } catch (Throwable e) {
                                Debug.printStackTrace(e);
                            }
                        }
                    }
                });
            } catch (Throwable e) {
                Debug.out(e);
            }
        }
    }
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) Download(com.biglybt.pif.download.Download)

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