Search in sources :

Example 31 with Download

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

the class StatusItem method refresh.

@Override
public void refresh(TableCell cell) {
    DownloadManager dm = (DownloadManager) cell.getDataSource();
    if (dm == null) {
        return;
    }
    Integer sort_order = sort_orders.get(getTableID());
    if (sort_order == null) {
        sort_order = sort_orders.get("other");
    }
    int state = dm.getState();
    String tooltip;
    if (state == DownloadManager.STATE_QUEUED && Utils.getUserMode() == 0) {
        tooltip = MessageText.getString("ManagerItem.queued.tooltip");
    } else {
        tooltip = null;
    }
    if (state != DownloadManager.STATE_STOPPED && state != DownloadManager.STATE_ERROR && dm.isDownloadComplete(false)) {
        SeedingRank sr = dm.getSeedingRank();
        String[] status = sr.getStatus(true);
        tooltip = tooltip == null ? status[0] : (tooltip + "\n\n" + status[0]);
        if (status[1] != null) {
            tooltip += "\n\n" + status[1];
        }
    }
    long sort_value;
    String text;
    if (showTrackerErrors && dm.isUnauthorisedOnTracker() && state != DownloadManager.STATE_ERROR) {
        text = dm.getTrackerStatus();
        sort_value = 1100;
    } else {
        text = DisplayFormatters.formatDownloadStatus(dm);
        boolean forced = dm.isForceStart() && (state == DownloadManager.STATE_DOWNLOADING || state == DownloadManager.STATE_SEEDING);
        if (sort_order == 1) {
            if (forced) {
                sort_value = 1000;
            } else {
                switch(state) {
                    case DownloadManager.STATE_SEEDING:
                        {
                            sort_value = 900;
                            break;
                        }
                    case DownloadManager.STATE_DOWNLOADING:
                        {
                            sort_value = 800;
                            break;
                        }
                    case DownloadManager.STATE_QUEUED:
                        {
                            if (dm.getSubState() == DownloadManager.STATE_SEEDING) {
                                // light seeding
                                sort_value = 750;
                            } else {
                                sort_value = 700;
                            }
                            break;
                        }
                    case DownloadManager.STATE_STOPPED:
                        {
                            if (dm.isPaused()) {
                                sort_value = 600;
                            } else {
                                sort_value = 500;
                            }
                            break;
                        }
                    default:
                        {
                            sort_value = 0;
                        }
                }
            }
        } else if (sort_order == 2) {
            PEPeerManager pm = dm.getPeerManager();
            boolean super_seeding = pm != null && pm.isSuperSeedMode();
            if (forced) {
                sort_value = 800;
            } else if (dm.isPaused()) {
                sort_value = 600;
            } else if (super_seeding) {
                sort_value = 825;
            } else {
                switch(state) {
                    case DownloadManager.STATE_WAITING:
                        {
                            sort_value = 100;
                            break;
                        }
                    case DownloadManager.STATE_INITIALIZING:
                        {
                            sort_value = 100;
                            break;
                        }
                    case DownloadManager.STATE_INITIALIZED:
                        {
                            sort_value = 100;
                            break;
                        }
                    case DownloadManager.STATE_ALLOCATING:
                        {
                            sort_value = 200;
                            break;
                        }
                    case DownloadManager.STATE_CHECKING:
                        {
                            sort_value = 900;
                            break;
                        }
                    case DownloadManager.STATE_READY:
                        {
                            sort_value = 300;
                            break;
                        }
                    case DownloadManager.STATE_DOWNLOADING:
                        {
                            sort_value = 400;
                            break;
                        }
                    case DownloadManager.STATE_FINISHING:
                        {
                            sort_value = 400;
                            break;
                        }
                    case DownloadManager.STATE_SEEDING:
                        {
                            DiskManager diskManager = dm.getDiskManager();
                            if (diskManager != null && diskManager.getCompleteRecheckStatus() != -1) {
                                sort_value = 900;
                            } else {
                                sort_value = 850;
                            }
                            break;
                        }
                    case DownloadManager.STATE_STOPPING:
                        {
                            sort_value = 500;
                            break;
                        }
                    case DownloadManager.STATE_STOPPED:
                        {
                            sort_value = 500;
                            break;
                        }
                    case DownloadManager.STATE_QUEUED:
                        {
                            if (dm.getSubState() == DownloadManager.STATE_SEEDING) {
                                sort_value = 810;
                            } else {
                                sort_value = 700;
                            }
                            break;
                        }
                    case DownloadManager.STATE_ERROR:
                        {
                            sort_value = 1000;
                            break;
                        }
                    default:
                        {
                            sort_value = 999;
                            break;
                        }
                }
            }
        } else {
            // not used
            sort_value = 0;
        }
    }
    if (tooltip != null) {
        tooltip = text + "\n\n" + tooltip;
    }
    if (sort_order == 1) {
        // priority based - mix in actual state and priority
        sort_value += state;
        sort_value <<= 32;
        if (dm.isDownloadComplete(false)) {
            Download dl = PluginCoreUtils.wrap(dm);
            if (dl != null) {
                sort_value += dl.getSeedingRank().getRank();
            }
        } else {
            sort_value -= dm.getPosition();
        }
    }
    boolean update;
    if (sort_order == 0) {
        update = cell.setSortValue(text);
    } else {
        update = cell.setSortValue(sort_value);
        if (!update) {
            if (!cell.getText().equals(text)) {
                update = true;
            }
        }
    }
    if (update || !cell.isValid()) {
        cell.setText(text);
        cell.setToolTip(tooltip);
        boolean clickable = false;
        if (cell instanceof TableCellSWT) {
            int cursor_id;
            if (!text.contains("http://")) {
                dm.setUserData(CLICK_KEY, null);
                cursor_id = SWT.CURSOR_ARROW;
            } else {
                dm.setUserData(CLICK_KEY, text);
                cursor_id = SWT.CURSOR_HAND;
                clickable = true;
            }
            ((TableCellSWT) cell).setCursorID(cursor_id);
        }
        if (!changeCellFG && !changeRowFG) {
            // clickable, make it blue whatever
            cell.setForeground(clickable ? BLUE : null);
            return;
        }
        TableRow row = cell.getTableRow();
        if (row != null) {
            Color color = null;
            if (state == DownloadManager.STATE_SEEDING) {
                color = Colors.blues[Colors.BLUES_MIDDARK];
            } else if (state == DownloadManager.STATE_ERROR) {
                color = Colors.colorError;
            } else {
                color = null;
            }
            if (changeRowFG) {
                if (row instanceof TableRowSWT) {
                    ((TableRowSWT) row).requestForegroundColor(color_requester, overall_change_fg ? color : null);
                }
            // row.setForeground( overall_change_fg?Utils.colorToIntArray(color):null);
            } else if (changeCellFG) {
                cell.setForeground(Utils.colorToIntArray(color));
            }
            if (clickable) {
                cell.setForeground(Utils.colorToIntArray(Colors.blue));
            }
        }
    } else {
        String old_tt = (String) cell.getToolTip();
        if (old_tt != tooltip) {
            if (old_tt == null || tooltip == null || !old_tt.equals(tooltip)) {
                cell.setToolTip(tooltip);
            }
        }
    }
}
Also used : TableRowSWT(com.biglybt.ui.swt.views.table.TableRowSWT) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) Color(org.eclipse.swt.graphics.Color) DiskManager(com.biglybt.core.disk.DiskManager) DownloadManager(com.biglybt.core.download.DownloadManager) SeedingRank(com.biglybt.pif.download.Download.SeedingRank) PEPeerManager(com.biglybt.core.peer.PEPeerManager) Download(com.biglybt.pif.download.Download)

Example 32 with Download

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

the class SeedToPeerRatioItem method refresh.

@Override
public void refresh(TableCell cell) {
    float ratio = -1;
    DownloadManager dm = (DownloadManager) cell.getDataSource();
    Download download = null;
    if (cell instanceof TableCellCore && dm != null) {
        TableRowCore row = ((TableCellCore) cell).getTableRowCore();
        if (row != null) {
            download = (Download) row.getDataSource(false);
        }
    }
    if (dm != null && download != null) {
        DownloadScrapeResult response = download.getAggregatedScrapeResult();
        int seeds;
        int peers;
        if (response.getResponseType() == DownloadScrapeResult.RT_SUCCESS) {
            seeds = Math.max(dm.getNbSeeds(), response.getSeedCount());
            int trackerPeerCount = response.getNonSeedCount();
            peers = dm.getNbPeers();
            if (peers == 0 || trackerPeerCount > peers) {
                if (trackerPeerCount <= 0) {
                // peers = dm.getActivationCount(); crap info
                } else {
                    peers = trackerPeerCount;
                }
            }
        } else {
            seeds = dm.getNbSeeds();
            peers = dm.getNbPeers();
        }
        if (peers < 0 || seeds < 0) {
            ratio = 0;
        } else {
            if (peers == 0) {
                if (seeds == 0) {
                    ratio = 0;
                } else {
                    ratio = Float.POSITIVE_INFINITY;
                }
            } else {
                ratio = (float) seeds / peers;
            }
        }
    }
    if (!cell.setSortValue(ratio) && cell.isValid()) {
        return;
    }
    if (ratio == -1) {
        cell.setText("");
    } else if (ratio == 0) {
        cell.setText("??");
    } else {
        cell.setText(DisplayFormatters.formatDecimal(ratio, 3));
    }
}
Also used : TableRowCore(com.biglybt.ui.common.table.TableRowCore) TableCellCore(com.biglybt.ui.common.table.TableCellCore) DownloadManager(com.biglybt.core.download.DownloadManager) Download(com.biglybt.pif.download.Download) DownloadScrapeResult(com.biglybt.pif.download.DownloadScrapeResult)

Example 33 with Download

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

the class ManagerUtils method moveToArchive.

public static void moveToArchive(final List<Download> downloads, ArchiveCallback _run_when_complete) {
    final ArchiveCallback run_when_complete = _run_when_complete == null ? new ArchiveCallback() : _run_when_complete;
    Utils.getOffOfSWTThread(new AERunnable() {

        @Override
        public void runSupport() {
            try {
                String title = MessageText.getString("archive.info.title");
                String text = MessageText.getString("archive.info.text");
                MessageBoxShell prompter = new MessageBoxShell(title, text, new String[] { MessageText.getString("Button.ok") }, 0);
                String remember_id = "managerutils.archive.info";
                prompter.setRemember(remember_id, true, MessageText.getString("MessageBoxWindow.nomoreprompting"));
                prompter.setAutoCloseInMS(0);
                prompter.open(null);
                prompter.waitUntilClosed();
                for (Download dm : downloads) {
                    try {
                        DownloadStub stub = dm.stubbify();
                        run_when_complete.success(dm, stub);
                    } catch (DownloadRemovalVetoException e) {
                        run_when_complete.failed(dm, e);
                        if (!e.isSilent()) {
                            UIFunctionsManager.getUIFunctions().forceNotify(UIFunctions.STATUSICON_ERROR, MessageText.getString("globalmanager.download.remove.veto"), e.getMessage(), dm.getName(), new Object[] { dm }, -1);
                        }
                    } catch (Throwable e) {
                        run_when_complete.failed(dm, e);
                        Debug.out(e);
                    }
                }
            } finally {
                run_when_complete.completed();
            }
        }
    });
}
Also used : DownloadStub(com.biglybt.pif.download.DownloadStub) DownloadRemovalVetoException(com.biglybt.pif.download.DownloadRemovalVetoException) GlobalManagerDownloadRemovalVetoException(com.biglybt.core.global.GlobalManagerDownloadRemovalVetoException) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) Download(com.biglybt.pif.download.Download)

Example 34 with Download

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

the class SubscriptionManagerUI method createSubsColumns.

private void createSubsColumns(TableManager table_manager) {
    final TableCellRefreshListener subs_refresh_listener = new TableCellRefreshListener() {

        @Override
        public void refresh(TableCell _cell) {
            TableCellSWT cell = (TableCellSWT) _cell;
            SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
            Download dl = (Download) cell.getDataSource();
            if (dl == null) {
                return;
            }
            Torrent torrent = dl.getTorrent();
            if (torrent != null) {
                Subscription[] subs = subs_man.getKnownSubscriptions(torrent.getHash());
                int num_subscribed = 0;
                int num_unsubscribed = 0;
                for (int i = 0; i < subs.length; i++) {
                    if (subs[i].isSubscribed()) {
                        num_subscribed++;
                    } else {
                        num_unsubscribed++;
                    }
                }
                Graphic graphic;
                String tooltip;
                int height = cell.getHeight();
                int sort_order = 0;
                if (subs.length == 0) {
                    graphic = null;
                    tooltip = null;
                } else {
                    if (num_subscribed == subs.length) {
                        graphic = height >= 22 ? icon_rss_all_add_big : icon_rss_all_add_small;
                        tooltip = MessageText.getString("subscript.all.subscribed");
                    } else if (num_subscribed > 0) {
                        graphic = height >= 22 ? icon_rss_some_add_big : icon_rss_some_add_small;
                        tooltip = MessageText.getString("subscript.some.subscribed");
                        sort_order = 10000;
                    } else {
                        graphic = height >= 22 ? icon_rss_big : icon_rss_small;
                        tooltip = MessageText.getString("subscript.none.subscribed");
                        sort_order = 1000000;
                    }
                }
                sort_order += 1000 * num_unsubscribed + num_subscribed;
                cell.setMarginHeight(0);
                cell.setGraphic(graphic);
                cell.setToolTip(tooltip);
                cell.setSortValue(sort_order);
                cell.setCursorID(graphic == null ? SWT.CURSOR_ARROW : SWT.CURSOR_HAND);
            } else {
                cell.setCursorID(SWT.CURSOR_ARROW);
                cell.setSortValue(0);
            }
        }
    };
    final TableCellMouseListener subs_mouse_listener = new TableCellMouseListener() {

        @Override
        public void cellMouseTrigger(TableCellMouseEvent event) {
            if (event.eventType == TableCellMouseEvent.EVENT_MOUSEDOWN) {
                TableCell cell = event.cell;
                Download dl = (Download) cell.getDataSource();
                Torrent torrent = dl.getTorrent();
                if (torrent != null) {
                    SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
                    Subscription[] subs = subs_man.getKnownSubscriptions(torrent.getHash());
                    if (subs.length > 0) {
                        event.skipCoreFunctionality = true;
                        new SubscriptionWizard(PluginCoreUtils.unwrap(dl));
                        COConfigurationManager.setParameter("subscriptions.wizard.shown", true);
                        refreshTitles(mdiEntryOverview);
                    // new SubscriptionListWindow(PluginCoreUtils.unwrap(dl),true);
                    }
                }
            }
        }
    };
    columnCreationSubs = new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn result) {
            result.setAlignment(TableColumn.ALIGN_CENTER);
            result.setPosition(TableColumn.POSITION_LAST);
            result.setWidth(32);
            result.setRefreshInterval(TableColumn.INTERVAL_INVALID_ONLY);
            result.setType(TableColumn.TYPE_GRAPHIC);
            result.addCellRefreshListener(subs_refresh_listener);
            result.addCellMouseListener(subs_mouse_listener);
            result.setIconReference("image.subscription.column", true);
            synchronized (columns) {
                columns.add(result);
            }
        }
    };
    table_manager.registerColumn(Download.class, "azsubs.ui.column.subs", columnCreationSubs);
    final TableCellRefreshListener link_refresh_listener = new TableCellRefreshListener() {

        @Override
        public void refresh(TableCell _cell) {
            TableCellSWT cell = (TableCellSWT) _cell;
            SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
            Download dl = (Download) cell.getDataSource();
            if (dl == null) {
                return;
            }
            String str = "";
            Torrent torrent = dl.getTorrent();
            if (torrent != null) {
                byte[] hash = torrent.getHash();
                Subscription[] subs = subs_man.getKnownSubscriptions(hash);
                for (int i = 0; i < subs.length; i++) {
                    Subscription sub = subs[i];
                    if (sub.hasAssociation(hash)) {
                        str += (str.length() == 0 ? "" : "; ") + sub.getName();
                    }
                }
            }
            cell.setCursorID(str.length() > 0 ? SWT.CURSOR_HAND : SWT.CURSOR_ARROW);
            cell.setText(str);
        }
    };
    final TableCellMouseListener link_mouse_listener = new TableCellMouseListener() {

        @Override
        public void cellMouseTrigger(TableCellMouseEvent event) {
            if (event.eventType == TableCellMouseEvent.EVENT_MOUSEDOWN) {
                TableCell cell = event.cell;
                Download dl = (Download) cell.getDataSource();
                Torrent torrent = dl.getTorrent();
                SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
                if (torrent != null) {
                    byte[] hash = torrent.getHash();
                    Subscription[] subs = subs_man.getKnownSubscriptions(hash);
                    for (int i = 0; i < subs.length; i++) {
                        Subscription sub = subs[i];
                        if (sub.hasAssociation(hash)) {
                            showSubscriptionMDI(sub);
                            break;
                        }
                    }
                }
            }
        }
    };
    columnCreationSubsLink = new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn result) {
            result.setAlignment(TableColumn.ALIGN_LEAD);
            result.setPosition(TableColumn.POSITION_INVISIBLE);
            result.setWidth(85);
            result.setRefreshInterval(TableColumn.INTERVAL_INVALID_ONLY);
            result.setType(TableColumn.TYPE_TEXT_ONLY);
            result.addCellRefreshListener(link_refresh_listener);
            result.addCellMouseListener(link_mouse_listener);
            result.setMinimumRequiredUserMode(Parameter.MODE_INTERMEDIATE);
            synchronized (columns) {
                columns.add(result);
            }
        }
    };
    table_manager.registerColumn(Download.class, "azsubs.ui.column.subs_link", columnCreationSubsLink);
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) Download(com.biglybt.pif.download.Download)

Example 35 with Download

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

the class TabbedMDI method popoutEntry.

public boolean popoutEntry(MdiEntry _entry, boolean onTop) {
    TabbedEntry target = (TabbedEntry) _entry;
    SkinnedDialog skinnedDialog = new SkinnedDialog("skin3_dlg_sidebar_popout", "shell", onTop ? UIFunctionsManagerSWT.getUIFunctionsSWT().getMainShell() : null, SWT.RESIZE | SWT.MAX | SWT.DIALOG_TRIM);
    SWTSkin skin = skinnedDialog.getSkin();
    SWTSkinObjectContainer cont = target.buildStandAlone((SWTSkinObjectContainer) skin.getSkinObject("content-area"));
    if (cont != null) {
        String ds_str = "";
        Object ds = target.getDatasourceCore();
        DownloadManager dm = DataSourceUtils.getDM(ds);
        if (dm != null) {
            ds_str = dm.getDisplayName();
        }
        skinnedDialog.setTitle(target.getTitle() + (ds_str.length() == 0 ? "" : (" - " + ds_str)));
        String metrics_id;
        if (target.getDatasource() instanceof Download) {
            metrics_id = MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS;
        } else {
            metrics_id = target.getId();
        }
        skinnedDialog.open("mdi.popout:" + metrics_id, true);
        return (true);
    } else {
        skinnedDialog.close();
        return (false);
    }
}
Also used : SkinnedDialog(com.biglybt.ui.swt.views.skin.SkinnedDialog) DownloadManager(com.biglybt.core.download.DownloadManager) 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