Search in sources :

Example 1 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class SBC_TagDiscovery method startScan.

private void startScan() {
    try {
        mon_scansRemaining.enter();
        if (scansRemaining > 0) {
            return;
        }
    } finally {
        mon_scansRemaining.exit();
    }
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(Core core) {
            GlobalManager gm = core.getGlobalManager();
            try {
                try {
                    mon_scansRemaining.enter();
                    scansRemaining = 0;
                } finally {
                    mon_scansRemaining.exit();
                }
                RelatedContentManager rcm = RelatedContentManager.getSingleton();
                List<DownloadManager> dms = gm.getDownloadManagers();
                for (final DownloadManager dm : dms) {
                    if (tv == null) {
                        return;
                    }
                    TOTorrent torrent = dm.getTorrent();
                    if (torrent == null) {
                        continue;
                    }
                    try {
                        final byte[] hash = torrent.getHash();
                        try {
                            mon_scansRemaining.enter();
                            scansRemaining++;
                            if (vitalityImage != null && scansRemaining == 1) {
                                vitalityImage.setVisible(true);
                            }
                            if (soTitle != null) {
                                soTitle.setText(MessageText.getString("tag.discovery.view.heading") + " : Scanning " + scansRemaining);
                            }
                        } finally {
                            mon_scansRemaining.exit();
                        }
                        try {
                            rcm.lookupAttributes(hash, dm.getDownloadState().getNetworks(), new RelatedAttributeLookupListener() {

                                @Override
                                public void tagFound(String tag, String network) {
                                    if (DEBUG) {
                                        System.out.println("Tag Search: Found Tag " + tag + " for " + dm.getDisplayName());
                                    }
                                    if (tv == null) {
                                        return;
                                    }
                                    String key = Base32.encode(hash) + tag;
                                    TagManager tm = TagManagerFactory.getTagManager();
                                    TagType tt_manual = tm.getTagType(TagType.TT_DOWNLOAD_MANUAL);
                                    List<Tag> existingDMTags = tt_manual.getTagsForTaggable(dm);
                                    for (Tag existingTag : existingDMTags) {
                                        if (existingTag.getTagName(true).equalsIgnoreCase(tag)) {
                                            return;
                                        }
                                    }
                                    synchronized (mapTagDiscoveries) {
                                        if (!mapTagDiscoveries.containsKey(key)) {
                                            TagDiscovery tagDiscovery = new TagDiscovery(tag, network, dm.getDisplayName(), hash);
                                            mapTagDiscoveries.put(key, tagDiscovery);
                                            ViewTitleInfoManager.refreshTitleInfo(SBC_TagDiscovery.this);
                                            tv.addDataSource(tagDiscovery);
                                        }
                                    }
                                }

                                @Override
                                public void lookupStart() {
                                    if (DEBUG) {
                                        System.out.println("Tag Search: Start" + " for " + dm.getDisplayName());
                                    }
                                }

                                @Override
                                public void lookupFailed(ContentException error) {
                                    if (DEBUG) {
                                        System.out.println("Tag Search: Failed " + error.getMessage() + " for " + dm.getDisplayName());
                                    }
                                }

                                @Override
                                public void lookupComplete() {
                                    decreaseScansRemaining();
                                    if (DEBUG) {
                                        System.out.println("Tag Search: Complete" + " for " + dm.getDisplayName());
                                    }
                                }
                            });
                        } catch (Throwable e) {
                            // can get here if the scan never gets kicked off (dht unavailable for network etc)
                            decreaseScansRemaining();
                        }
                    } catch (TOTorrentException e) {
                        e.printStackTrace();
                    }
                }
            } catch (ContentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
}
Also used : RelatedContentManager(com.biglybt.core.content.RelatedContentManager) ContentException(com.biglybt.core.content.ContentException) RelatedAttributeLookupListener(com.biglybt.core.content.RelatedAttributeLookupListener) DownloadManager(com.biglybt.core.download.DownloadManager) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) GlobalManager(com.biglybt.core.global.GlobalManager) TOTorrent(com.biglybt.core.torrent.TOTorrent) CoreRunningListener(com.biglybt.core.CoreRunningListener) List(java.util.List) Core(com.biglybt.core.Core)

Example 2 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class SB_Transfers method dispose.

public void dispose() {
    if (categoryListener != null) {
        Category[] categories = CategoryManager.getCategories();
        if (categories.length >= 0) {
            for (Category cat : categories) {
                cat.removeCategoryListener(categoryListener);
            }
        }
        CategoryManager.removeCategoryManagerListener(categoryManagerListener);
    }
    if (tagManagerListener != null) {
        removeTagManagerListeners(false);
    }
    if (hasBeenOpenedListener != null) {
        PlatformTorrentUtils.removeHasBeenOpenedListener(hasBeenOpenedListener);
    }
    refresh_limiter = null;
    if (dmListener != null || gmListener != null) {
        if (core != null) {
            GlobalManager gm = core.getGlobalManager();
            if (gm != null) {
                if (gmListener != null) {
                    gm.removeListener(gmListener);
                }
                if (dmListener != null) {
                    List<DownloadManager> dms = gm.getDownloadManagers();
                    for (DownloadManager dm : dms) {
                        dm.removeListener(dmListener);
                    }
                }
            }
        }
        gmListener = null;
        dmListener = null;
    }
    if (timerEventPeriodic != null) {
        timerEventPeriodic.cancel();
        timerEventPeriodic = null;
    }
    // should already be empty if everyone removed their listeners..
    listeners.clear();
    COConfigurationManager.removeParameterListener("MyTorrentsView.showuptime", configListenerShow);
    COConfigurationManager.removeParameterListener("MyTorrentsView.showrates", configListenerShow);
    if (timerEventShowUptime != null) {
        timerEventShowUptime.cancel();
        timerEventShowUptime = null;
    }
    COConfigurationManager.removeParameterListener("Library.TagInSideBar", paramTagsInSidebarListener);
    COConfigurationManager.removeParameterListener("Library.CatInSideBar", paramCatInSidebarListener);
}
Also used : Category(com.biglybt.core.category.Category) GlobalManager(com.biglybt.core.global.GlobalManager) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 3 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class SB_Transfers method setupCategory.

private void setupCategory(final Category category) {
    MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
    if (mdi == null) {
        return;
    }
    String name = category.getName();
    String id = "Cat." + Base32.encode(name.getBytes());
    if (category.getType() != Category.TYPE_USER) {
        name = "{" + name + "}";
    }
    ViewTitleInfo viewTitleInfo = new ViewTitleInfo() {

        @Override
        public Object getTitleInfoProperty(int propertyID) {
            if (propertyID == TITLE_INDICATOR_TEXT) {
                if (statsNoLowNoise.numIncomplete > 0) {
                    List<?> dms = category.getDownloadManagers(null);
                    if (dms != null) {
                        return "" + dms.size();
                    }
                }
            }
            return null;
        }
    };
    MdiEntry entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, id, "library", name, viewTitleInfo, category, false, null);
    if (entry != null) {
        entry.setImageLeftID("image.sidebar.library");
        entry.addListener(new MdiEntryDropListener() {

            @Override
            public boolean mdiEntryDrop(MdiEntry entry, Object payload) {
                if (!(payload instanceof String)) {
                    return false;
                }
                String dropped = (String) payload;
                String[] split = Constants.PAT_SPLIT_SLASH_N.split(dropped);
                if (split.length > 1) {
                    String type = split[0];
                    if (type.startsWith("DownloadManager")) {
                        GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
                        for (int i = 1; i < split.length; i++) {
                            String hash = split[i];
                            try {
                                DownloadManager dm = gm.getDownloadManager(new HashWrapper(Base32.decode(hash)));
                                if (dm != null) {
                                    TorrentUtil.assignToCategory(new Object[] { dm }, category);
                                }
                            } catch (Throwable t) {
                            }
                        }
                    }
                }
                return true;
            }
        });
    }
    if (entry instanceof SideBarEntrySWT) {
        final SideBarEntrySWT entrySWT = (SideBarEntrySWT) entry;
        entrySWT.addListener(new MdiSWTMenuHackListener() {

            @Override
            public void menuWillBeShown(MdiEntry entry, Menu menuTree) {
                CategoryUIUtils.createMenuItems(menuTree, category);
            }
        });
    }
}
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) Menu(org.eclipse.swt.widgets.Menu) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)

Example 4 with GlobalManager

use of com.biglybt.core.global.GlobalManager 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 5 with GlobalManager

use of com.biglybt.core.global.GlobalManager 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)

Aggregations

GlobalManager (com.biglybt.core.global.GlobalManager)48 DownloadManager (com.biglybt.core.download.DownloadManager)33 Core (com.biglybt.core.Core)10 TOTorrent (com.biglybt.core.torrent.TOTorrent)10 List (java.util.List)7 CoreRunningListener (com.biglybt.core.CoreRunningListener)6 File (java.io.File)6 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)5 UIFunctions (com.biglybt.ui.UIFunctions)5 GlobalManagerStats (com.biglybt.core.global.GlobalManagerStats)4 PEPeerManager (com.biglybt.core.peer.PEPeerManager)4 HashWrapper (com.biglybt.core.util.HashWrapper)4 PluginInterface (com.biglybt.pif.PluginInterface)4 Menu (org.eclipse.swt.widgets.Menu)4 DiskManagerFileInfoSet (com.biglybt.core.disk.DiskManagerFileInfoSet)3 DownloadManagerInitialisationAdapter (com.biglybt.core.download.DownloadManagerInitialisationAdapter)3 PEPeer (com.biglybt.core.peer.PEPeer)3 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)3 PluginException (com.biglybt.pif.PluginException)3 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)3