Search in sources :

Example 6 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class SB_Transfers method setupTag.

public MdiEntry setupTag(final Tag tag) {
    MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
    if (mdi == null) {
        return null;
    }
    synchronized (tag_setup_lock) {
        String id = "Tag." + tag.getTagType().getTagType() + "." + tag.getTagID();
        if (mdi.getEntry(id) != null) {
            return null;
        }
        // find where to locate this in the sidebar
        TreeMap<Tag, String> name_map = new TreeMap<>(TagUIUtils.getTagComparator());
        name_map.put(tag, id);
        for (Tag t : tag.getTagType().getTags()) {
            if (t.isVisible()) {
                String tid = "Tag." + tag.getTagType().getTagType() + "." + t.getTagID();
                if (mdi.getEntry(tid) != null) {
                    name_map.put(t, tid);
                }
            }
        }
        String prev_id = null;
        for (String this_id : name_map.values()) {
            if (this_id == id) {
                break;
            }
            prev_id = this_id;
        }
        if (prev_id == null && name_map.size() > 1) {
            Iterator<String> it = name_map.values().iterator();
            it.next();
            prev_id = "~" + it.next();
        }
        boolean auto = tag.getTagType().isTagTypeAuto();
        ViewTitleInfo viewTitleInfo = new ViewTitleInfo() {

            @Override
            public Object getTitleInfoProperty(int pid) {
                if (pid == TITLE_TEXT) {
                    return (tag.getTagName(true));
                } else if (pid == TITLE_INDICATOR_TEXT) {
                    return (String.valueOf(tag.getTaggedCount()));
                } else if (pid == TITLE_INDICATOR_COLOR) {
                    TagType tag_type = tag.getTagType();
                    int[] def_color = tag_type.getColorDefault();
                    int[] tag_color = tag.getColor();
                    if (tag_color != def_color) {
                        return (tag_color);
                    }
                } else if (pid == TITLE_INDICATOR_TEXT_TOOLTIP) {
                    return (TagUIUtils.getTagTooltip(tag));
                }
                return null;
            }
        };
        MdiEntry entry;
        boolean closable = auto;
        if (tag.getTaggableTypes() == Taggable.TT_DOWNLOAD) {
            closable = true;
            String name = tag.getTagName(true);
            entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, id, "library", name, viewTitleInfo, tag, closable, prev_id);
        } else {
            entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, new PeersGeneralView(tag), id, closable, null, prev_id);
            entry.setViewTitleInfo(viewTitleInfo);
        }
        if (closable) {
            entry.addListener(new MdiCloseListener() {

                @Override
                public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                    if (userClosed && entry.getUserData(AUTO_CLOSE_KEY) == null) {
                        if (COConfigurationManager.getBooleanParameter("Library.TagInSideBar")) {
                            tag.setVisible(false);
                        }
                    }
                }
            });
        }
        if (entry != null) {
            String image_id = tag.getImageID();
            if (image_id != null) {
                entry.setImageLeftID(image_id);
            } else if (tag.getTagType().getTagType() == TagType.TT_PEER_IPSET) {
                entry.setImageLeftID("image.sidebar.tag-red");
            } else if (tag.getTagType().isTagTypePersistent()) {
                entry.setImageLeftID("image.sidebar.tag-green");
            } else {
                entry.setImageLeftID("image.sidebar.tag-blue");
            }
        }
        if (entry instanceof SideBarEntrySWT) {
            final SideBarEntrySWT entrySWT = (SideBarEntrySWT) entry;
            entrySWT.addListener(new MdiSWTMenuHackListener() {

                @Override
                public void menuWillBeShown(MdiEntry entry, Menu menuTree) {
                    TagUIUtils.createSideBarMenuItems(menuTree, tag);
                }
            });
        }
        if (!auto && entry != null) {
            MdiEntryDropListener dl = new MdiEntryDropListener() {

                @Override
                public boolean mdiEntryDrop(MdiEntry entry, Object payload) {
                    if (!(payload instanceof String)) {
                        return false;
                    }
                    boolean[] auto = tag.isTagAuto();
                    if (auto[0] && auto[1]) {
                        return (false);
                    }
                    final String dropped = (String) payload;
                    new AEThread2("Tagger") {

                        @Override
                        public void run() {
                            dropTorrentOnTag(tag, dropped);
                        }
                    }.start();
                    return true;
                }

                private void dropTorrentOnTag(Tag tag, String dropped) {
                    String[] split = Constants.PAT_SPLIT_SLASH_N.split(dropped);
                    if (split.length <= 1) {
                        return;
                    }
                    String type = split[0];
                    if (!type.startsWith("DownloadManager") && !type.startsWith("DiskManagerFileInfo")) {
                        return;
                    }
                    GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
                    List<DownloadManager> listDMs = new ArrayList<>();
                    boolean doAdd = false;
                    for (int i = 1; i < split.length; i++) {
                        String hash = split[i];
                        // for files
                        int sep = hash.indexOf(";");
                        if (sep != -1) {
                            hash = hash.substring(0, sep);
                        }
                        try {
                            DownloadManager dm = gm.getDownloadManager(new HashWrapper(Base32.decode(hash)));
                            if (dm != null) {
                                listDMs.add(dm);
                                if (!doAdd && !tag.hasTaggable(dm)) {
                                    doAdd = true;
                                }
                            }
                        } catch (Throwable t) {
                        }
                        boolean[] auto = tag.isTagAuto();
                        for (DownloadManager dm : listDMs) {
                            if (doAdd) {
                                if (!auto[0]) {
                                    tag.addTaggable(dm);
                                }
                            } else {
                                if (!(auto[0] && auto[1])) {
                                    tag.removeTaggable(dm);
                                }
                            }
                        }
                    }
                }
            };
            boolean[] tag_auto = tag.isTagAuto();
            entry.setUserData(TAG_DATA_KEY, new Object[] { dl, tag_auto });
            if (!(tag_auto[0] && tag_auto[1])) {
                entry.addListener(dl);
            }
        }
        return entry;
    }
}
Also used : SideBarEntrySWT(com.biglybt.ui.swt.views.skin.sidebar.SideBarEntrySWT) MdiSWTMenuHackListener(com.biglybt.ui.swt.mdi.MdiSWTMenuHackListener) DownloadManager(com.biglybt.core.download.DownloadManager) GlobalManager(com.biglybt.core.global.GlobalManager) MultipleDocumentInterfaceSWT(com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT) Menu(org.eclipse.swt.widgets.Menu) PeersGeneralView(com.biglybt.ui.swt.views.PeersGeneralView) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)

Example 7 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class SB_Transfers method updateErrorTooltip.

private void updateErrorTooltip(GlobalManager gm, stats stats) {
    if (stats.numErrorComplete < 0) {
        stats.numErrorComplete = 0;
    }
    if (stats.numErrorInComplete < 0) {
        stats.numErrorInComplete = 0;
    }
    if (stats.numErrorComplete > 0 || stats.numErrorInComplete > 0) {
        String comp_error = null;
        String incomp_error = null;
        List<?> downloads = gm.getDownloadManagers();
        for (int i = 0; i < downloads.size(); i++) {
            DownloadManager download = (DownloadManager) downloads.get(i);
            if (download.getState() == DownloadManager.STATE_ERROR) {
                if (download.getAssumedComplete()) {
                    if (comp_error == null) {
                        comp_error = download.getDisplayName() + ": " + download.getErrorDetails();
                    } else {
                        comp_error += "...";
                    }
                } else {
                    if (incomp_error == null) {
                        incomp_error = download.getDisplayName() + ": " + download.getErrorDetails();
                    } else {
                        incomp_error += "...";
                    }
                }
            }
        }
        stats.errorCompleteTooltip = comp_error;
        stats.errorInCompleteTooltip = incomp_error;
    }
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager)

Example 8 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class ToolBarView method moveTop.

protected boolean moveTop() {
    if (!CoreFactory.isCoreRunning()) {
        return false;
    }
    GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
    DownloadManager[] dms = SelectedContentManager.getDMSFromSelectedContent();
    if (dms != null) {
        gm.moveTop(dms);
    }
    return true;
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 9 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class ToolBarView method setupToolBarItems.

private void setupToolBarItems(boolean uiClassic) {
    ToolBarItem item;
    {
        // always add these items, whether they are shown or not is decided later
        // ==OPEN
        item = createItem(this, "open", "image.toolbar.open", "Button.add.torrent");
        item.setDefaultActivationListener(new UIToolBarActivationListener() {

            @Override
            public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
                if (activationType != ACTIVATIONTYPE_NORMAL) {
                    Boolean result = Utils.execSWTThreadWithBool("open", new AERunnableBoolean() {

                        @Override
                        public boolean runSupport() {
                            Clipboard clipboard = new Clipboard(Display.getDefault());
                            try {
                                String text = (String) clipboard.getContents(TextTransfer.getInstance());
                                if (text != null && text.length() <= 2048) {
                                    if (TorrentOpener.openTorrentsFromClipboard(text)) {
                                        return (true);
                                    }
                                }
                            } finally {
                                clipboard.dispose();
                            }
                            return false;
                        }
                    }, 1000);
                    return (result != null && result);
                }
                UIFunctionsManagerSWT.getUIFunctionsSWT().openTorrentWindow();
                return true;
            }
        });
        item.setAlwaysAvailable(true);
        item.setGroupID("classic");
        tbm.addToolBarItem(item, false);
        // ==SEARCH
        item = createItem(this, "search", "search", "Button.search");
        item.setDefaultActivationListener(new UIToolBarActivationListener() {

            @Override
            public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
                if (activationType != ACTIVATIONTYPE_NORMAL) {
                    return false;
                }
                UIFunctionsManagerSWT.getUIFunctionsSWT().promptForSearch();
                return true;
            }
        });
        item.setAlwaysAvailable(true);
        item.setGroupID("classic");
        tbm.addToolBarItem(item, false);
    }
    if (!uiClassic) {
        // ==play
        item = createItem(this, "play", "image.button.play", "iconBar.play");
        item.setDefaultActivationListener(new UIToolBarActivationListener() {

            @Override
            public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
                if (activationType != ACTIVATIONTYPE_NORMAL) {
                    return false;
                }
                ISelectedContent[] sc = SelectedContentManager.getCurrentlySelectedContent();
                if (sc != null && sc.length > 0) {
                    if (PlayUtils.canStreamDS(sc[0], sc[0].getFileIndex(), true)) {
                        TorrentListViewsUtils.playOrStreamDataSource(sc[0], DLReferals.DL_REFERAL_TOOLBAR, true, false);
                    } else {
                        TorrentListViewsUtils.playOrStreamDataSource(sc[0], DLReferals.DL_REFERAL_TOOLBAR, false, true);
                    }
                }
                return false;
            }
        });
        tbm.addToolBarItem(item, false);
    }
    // ==run
    item = createItem(this, "run", "image.toolbar.run", "iconBar.run");
    item.setDefaultActivationListener(new UIToolBarActivationListener() {

        @Override
        public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
            if (activationType != ACTIVATIONTYPE_NORMAL) {
                return false;
            }
            TableView tv = SelectedContentManager.getCurrentlySelectedTableView();
            Object[] ds;
            if (tv != null) {
                ds = tv.getSelectedDataSources().toArray();
            } else {
                ds = SelectedContentManager.getDMSFromSelectedContent();
            }
            if (ds != null) {
                TorrentUtil.runDataSources(ds);
                return true;
            }
            return false;
        }
    });
    tbm.addToolBarItem(item, false);
    if (uiClassic) {
        // ==TOP
        item = createItem(this, "top", "image.toolbar.top", "iconBar.top");
        item.setDefaultActivationListener(new UIToolBarActivationListener() {

            @Override
            public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
                if (activationType == ACTIVATIONTYPE_NORMAL) {
                    return moveTop();
                }
                return false;
            }
        });
        tbm.addToolBarItem(item, false);
    }
    // ==UP
    item = createItem(this, "up", "image.toolbar.up", "iconBar.up");
    item.setDefaultActivationListener(new UIToolBarActivationListener() {

        @Override
        public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
            if (activationType == ACTIVATIONTYPE_NORMAL) {
                if (!CoreFactory.isCoreRunning()) {
                    return false;
                }
                DownloadManager[] dms = SelectedContentManager.getDMSFromSelectedContent();
                if (dms != null) {
                    Arrays.sort(dms, new Comparator<DownloadManager>() {

                        @Override
                        public int compare(DownloadManager a, DownloadManager b) {
                            return a.getPosition() - b.getPosition();
                        }
                    });
                    GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
                    for (int i = 0; i < dms.length; i++) {
                        DownloadManager dm = dms[i];
                        if (gm.isMoveableUp(dm)) {
                            gm.moveUp(dm);
                        }
                    }
                }
            } else if (activationType == ACTIVATIONTYPE_HELD) {
                return moveTop();
            }
            return false;
        }
    });
    tbm.addToolBarItem(item, false);
    // ==down
    item = createItem(this, "down", "image.toolbar.down", "iconBar.down");
    item.setDefaultActivationListener(new UIToolBarActivationListener() {

        @Override
        public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
            if (activationType == ACTIVATIONTYPE_NORMAL) {
                if (!CoreFactory.isCoreRunning()) {
                    return false;
                }
                GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
                DownloadManager[] dms = SelectedContentManager.getDMSFromSelectedContent();
                if (dms != null) {
                    Arrays.sort(dms, new Comparator<DownloadManager>() {

                        @Override
                        public int compare(DownloadManager a, DownloadManager b) {
                            return b.getPosition() - a.getPosition();
                        }
                    });
                    for (int i = 0; i < dms.length; i++) {
                        DownloadManager dm = dms[i];
                        if (gm.isMoveableDown(dm)) {
                            gm.moveDown(dm);
                        }
                    }
                    return true;
                }
            } else if (activationType == ACTIVATIONTYPE_HELD) {
                return moveBottom();
            }
            return false;
        }
    });
    tbm.addToolBarItem(item, false);
    if (uiClassic) {
        // ==BOTTOM
        item = createItem(this, "bottom", "image.toolbar.bottom", "iconBar.bottom");
        item.setDefaultActivationListener(new UIToolBarActivationListener() {

            @Override
            public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
                if (activationType != ACTIVATIONTYPE_NORMAL) {
                    return false;
                }
                return moveBottom();
            }
        });
        tbm.addToolBarItem(item, false);
    }
    // ==start
    item = createItem(this, "start", "image.toolbar.startstop.start", "iconBar.start");
    item.setDefaultActivationListener(new UIToolBarActivationListener_OffSWT() {

        @Override
        public void toolBarItemActivated_OffSWT(ToolBarItem item, long activationType, Object datasource) {
            ISelectedContent[] selected = SelectedContentManager.getCurrentlySelectedContent();
            TorrentUtil.queueDataSources(selected, true, activationType == ACTIVATIONTYPE_HELD);
        }
    });
    tbm.addToolBarItem(item, false);
    // ==stop
    item = createItem(this, "stop", "image.toolbar.startstop.stop", "iconBar.stop");
    item.setDefaultActivationListener(new UIToolBarActivationListener_OffSWT() {

        @Override
        public void toolBarItemActivated_OffSWT(ToolBarItem item, long activationType, Object datasource) {
            ISelectedContent[] selected = SelectedContentManager.getCurrentlySelectedContent();
            TorrentUtil.stopDataSources(selected, activationType == ACTIVATIONTYPE_HELD);
        }
    });
    tbm.addToolBarItem(item, false);
    // ==startstop
    item = createItem(this, "startstop", "image.toolbar.startstop.start", "iconBar.startstop");
    item.setDefaultActivationListener(new UIToolBarActivationListener_OffSWT() {

        @Override
        public void toolBarItemActivated_OffSWT(ToolBarItem item, long activationType, Object datasource) {
            ISelectedContent[] selected = SelectedContentManager.getCurrentlySelectedContent();
            TorrentUtil.stopOrStartDataSources(selected, activationType == ACTIVATIONTYPE_HELD);
        }
    });
    tbm.addToolBarItem(item, false);
    // ==remove
    item = createItem(this, "remove", "image.toolbar.remove", "iconBar.remove");
    item.setDefaultActivationListener(new UIToolBarActivationListener_OffSWT(UIToolBarActivationListener.ACTIVATIONTYPE_NORMAL) {

        @Override
        public void toolBarItemActivated_OffSWT(ToolBarItem item, long activationType, Object datasource) {
            ISelectedContent[] selected = SelectedContentManager.getCurrentlySelectedContent();
            TorrentUtil.removeDataSources(selected);
        }
    });
    tbm.addToolBarItem(item, false);
    if (COConfigurationManager.getBooleanParameter("Library.EnableSimpleView")) {
        // == mode big
        item = createItem(this, "modeBig", "image.toolbar.table_large", "v3.iconBar.view.big");
        item.setGroupID("views");
        tbm.addToolBarItem(item, false);
        // == mode small
        item = createItem(this, "modeSmall", "image.toolbar.table_normal", "v3.iconBar.view.small");
        item.setGroupID("views");
        tbm.addToolBarItem(item, false);
    }
}
Also used : AERunnableBoolean(com.biglybt.core.util.AERunnableBoolean) DownloadManager(com.biglybt.core.download.DownloadManager) GlobalManager(com.biglybt.core.global.GlobalManager) ToolBarItem(com.biglybt.ui.common.ToolBarItem) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) Clipboard(org.eclipse.swt.dnd.Clipboard) AERunnableBoolean(com.biglybt.core.util.AERunnableBoolean) TableView(com.biglybt.ui.common.table.TableView)

Example 10 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class ToolBarView method _refreshCoreToolBarItems.

public void _refreshCoreToolBarItems() {
    if (DEBUG && !isVisible()) {
        Debug.out("Trying to refresh core toolbar items when toolbar is not visible " + this + getMainSkinObject());
    }
    UIFunctionsSWT uiFunctionsSWT = UIFunctionsManagerSWT.getUIFunctionsSWT();
    MultipleDocumentInterfaceSWT mdi = uiFunctionsSWT != null ? uiFunctionsSWT.getMDISWT() : null;
    if (mdi != null) {
        UIToolBarItem[] allToolBarItems = tbm.getAllToolBarItems();
        MdiEntrySWT entry = mdi.getCurrentEntrySWT();
        Map<String, Long> mapStates = new HashMap<>();
        if (entry != null) {
            UIToolBarEnablerBase[] enablers = entry.getToolbarEnablers();
            for (UIToolBarEnablerBase enabler : enablers) {
                if (enabler instanceof UIPluginViewToolBarListener) {
                    try {
                        ((UIPluginViewToolBarListener) enabler).refreshToolBarItems(mapStates);
                    } catch (Throwable e) {
                        // don't trust them plugins
                        Debug.out(e);
                    }
                }
            }
        }
        ISelectedContent[] currentContent = SelectedContentManager.getCurrentlySelectedContent();
        synchronized (dm_listener_map) {
            Map<DownloadManager, DownloadManagerListener> copy = new IdentityHashMap<>(dm_listener_map);
            for (ISelectedContent content : currentContent) {
                DownloadManager dm = content.getDownloadManager();
                if (dm != null) {
                    copy.remove(dm);
                    if (!dm_listener_map.containsKey(dm)) {
                        DownloadManagerListener l = new DownloadManagerListener() {

                            @Override
                            public void stateChanged(DownloadManager manager, int state) {
                                refreshCoreToolBarItems();
                            }

                            @Override
                            public void downloadComplete(DownloadManager manager) {
                                refreshCoreToolBarItems();
                            }

                            @Override
                            public void completionChanged(DownloadManager manager, boolean bCompleted) {
                                refreshCoreToolBarItems();
                            }

                            @Override
                            public void positionChanged(DownloadManager download, int oldPosition, int newPosition) {
                                refreshCoreToolBarItems();
                            }

                            @Override
                            public void filePriorityChanged(DownloadManager download, DiskManagerFileInfo file) {
                                refreshCoreToolBarItems();
                            }
                        };
                        dm.addListener(l, false);
                        dm_listener_map.put(dm, l);
                    // System.out.println( "Added " + dm.getDisplayName() + " - size=" + dm_listener_map.size());
                    }
                }
            }
            for (Map.Entry<DownloadManager, DownloadManagerListener> e : copy.entrySet()) {
                DownloadManager dm = e.getKey();
                dm.removeListener(e.getValue());
                dm_listener_map.remove(dm);
            // System.out.println( "Removed " + dm.getDisplayName() + " - size=" + dm_listener_map.size());
            }
        }
        boolean has1Selection = currentContent.length == 1;
        boolean can_play = false;
        boolean can_stream = false;
        boolean stream_permitted = false;
        if (has1Selection) {
            if (!(currentContent[0] instanceof ISelectedVuzeFileContent)) {
                can_play = PlayUtils.canPlayDS(currentContent[0], currentContent[0].getFileIndex(), false);
                can_stream = PlayUtils.canStreamDS(currentContent[0], currentContent[0].getFileIndex(), false);
                if (can_stream) {
                    stream_permitted = PlayUtils.isStreamPermitted();
                }
            }
        }
        if (mapStates.containsKey("play")) {
            can_play |= (mapStates.get("play") & UIToolBarItem.STATE_ENABLED) > 0;
        }
        if (mapStates.containsKey("stream")) {
            can_stream |= (mapStates.get("stream") & UIToolBarItem.STATE_ENABLED) > 0;
        }
        mapStates.put("play", can_play | can_stream ? UIToolBarItem.STATE_ENABLED : 0);
        UIToolBarItem pitem = tbm.getToolBarItem("play");
        if (pitem != null) {
            if (can_stream) {
                pitem.setImageID(stream_permitted ? "image.button.stream" : "image.button.pstream");
                pitem.setTextID(stream_permitted ? "iconBar.stream" : "iconBar.pstream");
            } else {
                pitem.setImageID("image.button.play");
                pitem.setTextID("iconBar.play");
            }
        }
        UIToolBarItem ssItem = tbm.getToolBarItem("startstop");
        if (ssItem != null) {
            boolean shouldStopGroup;
            if (currentContent.length == 0 && mapStates.containsKey("start") && (!mapStates.containsKey("stop") || (mapStates.get("stop") & UIToolBarItem.STATE_ENABLED) == 0) && (mapStates.get("start") & UIToolBarItem.STATE_ENABLED) > 0) {
                shouldStopGroup = false;
            } else {
                shouldStopGroup = TorrentUtil.shouldStopGroup(currentContent);
            }
            ssItem.setTextID(shouldStopGroup ? "iconBar.stop" : "iconBar.start");
            ssItem.setImageID("image.toolbar.startstop." + (shouldStopGroup ? "stop" : "start"));
            if (currentContent.length == 0 && !mapStates.containsKey("startstop")) {
                boolean can_stop = mapStates.containsKey("stop") && (mapStates.get("stop") & UIToolBarItem.STATE_ENABLED) > 0;
                boolean can_start = mapStates.containsKey("start") && (mapStates.get("start") & UIToolBarItem.STATE_ENABLED) > 0;
                if (can_start && can_stop) {
                    can_stop = false;
                }
                if (can_start || can_stop) {
                    ssItem.setTextID(can_stop ? "iconBar.stop" : "iconBar.start");
                    ssItem.setImageID("image.toolbar.startstop." + (can_stop ? "stop" : "start"));
                    mapStates.put("startstop", UIToolBarItem.STATE_ENABLED);
                }
            }
        }
        Map<String, Long> fallBackStates = TorrentUtil.calculateToolbarStates(currentContent, null);
        for (String key : fallBackStates.keySet()) {
            if (!mapStates.containsKey(key)) {
                mapStates.put(key, fallBackStates.get(key));
            }
        }
        final String[] TBKEYS = new String[] { "play", "run", "top", "up", "down", "bottom", "start", "stop", "startstop", "remove" };
        for (String key : TBKEYS) {
            if (!mapStates.containsKey(key)) {
                mapStates.put(key, 0L);
            }
        }
        for (int i = 0; i < allToolBarItems.length; i++) {
            UIToolBarItem toolBarItem = allToolBarItems[i];
            Long state = mapStates.get(toolBarItem.getID());
            if (state != null) {
                toolBarItem.setState(state);
            }
        }
    }
}
Also used : DownloadManagerListener(com.biglybt.core.download.DownloadManagerListener) DownloadManager(com.biglybt.core.download.DownloadManager) MultipleDocumentInterfaceSWT(com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT) ISelectedVuzeFileContent(com.biglybt.ui.selectedcontent.ISelectedVuzeFileContent) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) MdiEntrySWT(com.biglybt.ui.swt.mdi.MdiEntrySWT) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener)

Aggregations

DownloadManager (com.biglybt.core.download.DownloadManager)307 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)54 TOTorrent (com.biglybt.core.torrent.TOTorrent)35 GlobalManager (com.biglybt.core.global.GlobalManager)33 PEPeerManager (com.biglybt.core.peer.PEPeerManager)29 File (java.io.File)29 List (java.util.List)21 Core (com.biglybt.core.Core)17 Download (com.biglybt.pif.download.Download)17 Point (org.eclipse.swt.graphics.Point)17 UIFunctions (com.biglybt.ui.UIFunctions)16 Tag (com.biglybt.core.tag.Tag)15 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)14 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)13 ArrayList (java.util.ArrayList)13 DiskManager (com.biglybt.core.disk.DiskManager)12 DownloadManagerStats (com.biglybt.core.download.DownloadManagerStats)12 CoreRunningListener (com.biglybt.core.CoreRunningListener)11 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)11 PEPeer (com.biglybt.core.peer.PEPeer)11