Search in sources :

Example 46 with GlobalManager

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

the class SB_Transfers method recountUnopened.

void recountUnopened() {
    if (!CoreFactory.isCoreRunning()) {
        return;
    }
    GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
    List<?> dms = gm.getDownloadManagers();
    statsNoLowNoise.numUnOpened = 0;
    for (Iterator<?> iter = dms.iterator(); iter.hasNext(); ) {
        DownloadManager dm = (DownloadManager) iter.next();
        if (!PlatformTorrentUtils.getHasBeenOpened(dm) && dm.getAssumedComplete()) {
            statsNoLowNoise.numUnOpened++;
        }
    }
    statsWithLowNoise.numUnOpened = statsNoLowNoise.numUnOpened;
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 47 with GlobalManager

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

the class SB_Transfers method setupViewTitleWithCore.

protected void setupViewTitleWithCore(Core _core) {
    synchronized (SB_Transfers.class) {
        if (!first) {
            return;
        }
        first = false;
        core = _core;
        coreCreateTime = core.getCreateTime();
    }
    categoryListener = new CategoryListener() {

        @Override
        public void downloadManagerRemoved(Category cat, DownloadManager removed) {
            RefreshCategorySideBar(cat);
        }

        @Override
        public void downloadManagerAdded(Category cat, DownloadManager manager) {
            RefreshCategorySideBar(cat);
        }
    };
    paramCatInSidebarListener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            if (Utils.isAZ2UI()) {
                return;
            }
            Category[] categories = CategoryManager.getCategories();
            if (categories.length == 0) {
                return;
            }
            boolean catInSidebar = COConfigurationManager.getBooleanParameter("Library.CatInSideBar");
            if (catInSidebar) {
                if (categoryManagerListener != null) {
                    return;
                }
                categoryManagerListener = new CategoryManagerListener() {

                    @Override
                    public void categoryRemoved(Category category) {
                        removeCategory(category);
                    }

                    @Override
                    public void categoryChanged(Category category) {
                        RefreshCategorySideBar(category);
                    }

                    @Override
                    public void categoryAdded(Category category) {
                        Category[] categories = CategoryManager.getCategories();
                        if (categories.length == 3) {
                            for (Category cat : categories) {
                                setupCategory(cat);
                            }
                        } else {
                            setupCategory(category);
                        }
                    }
                };
                CategoryManager.addCategoryManagerListener(categoryManagerListener);
                if (categories.length > 2) {
                    for (Category category : categories) {
                        category.addCategoryListener(categoryListener);
                        setupCategory(category);
                    }
                }
            } else {
                if (categoryManagerListener != null) {
                    CategoryManager.removeCategoryManagerListener(categoryManagerListener);
                    categoryManagerListener = null;
                }
                for (Category category : categories) {
                    category.removeCategoryListener(categoryListener);
                    removeCategory(category);
                }
            }
        }
    };
    COConfigurationManager.addAndFireParameterListener("Library.CatInSideBar", paramCatInSidebarListener);
    tagListener = new TagListener() {

        @Override
        public void taggableAdded(Tag tag, Taggable tagged) {
            refreshTagSideBar(tag);
        }

        @Override
        public void taggableSync(Tag tag) {
            refreshTagSideBar(tag);
        }

        @Override
        public void taggableRemoved(Tag tag, Taggable tagged) {
            refreshTagSideBar(tag);
        }
    };
    paramTagsInSidebarListener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            boolean tagInSidebar = COConfigurationManager.getBooleanParameter("Library.TagInSideBar");
            if (tagInSidebar) {
                addTagManagerListeners();
            } else {
                removeTagManagerListeners(true);
            }
        }
    };
    COConfigurationManager.addAndFireParameterListener("Library.TagInSideBar", paramTagsInSidebarListener);
    final GlobalManager gm = core.getGlobalManager();
    dmListener = new DownloadManagerAdapter() {

        @Override
        public void stateChanged(DownloadManager dm, int state) {
            stateChanged(dm, state, statsNoLowNoise);
            stateChanged(dm, state, statsWithLowNoise);
        }

        public void stateChanged(DownloadManager dm, int state, stats stats) {
            if (!stats.includeLowNoise && PlatformTorrentUtils.isAdvancedViewOnly(dm)) {
                return;
            }
            synchronized (statsLock) {
                updateDMCounts(dm);
                boolean complete = dm.getAssumedComplete();
                Boolean wasErrorStateB = (Boolean) dm.getUserData("wasErrorState");
                boolean wasErrorState = wasErrorStateB != null && wasErrorStateB.booleanValue();
                boolean isErrorState = state == DownloadManager.STATE_ERROR;
                if (isErrorState != wasErrorState) {
                    int rel = isErrorState ? 1 : -1;
                    if (complete) {
                        stats.numErrorComplete += rel;
                    } else {
                        stats.numErrorInComplete += rel;
                    }
                    updateErrorTooltip(gm, stats);
                    dm.setUserData("wasErrorState", Boolean.valueOf(isErrorState));
                }
                refreshAllLibraries();
            }
        }

        @Override
        public void completionChanged(DownloadManager dm, boolean completed) {
            completionChanged(dm, completed, statsNoLowNoise);
            completionChanged(dm, completed, statsWithLowNoise);
        }

        public void completionChanged(DownloadManager dm, boolean completed, stats stats) {
            if (!stats.includeLowNoise && PlatformTorrentUtils.isAdvancedViewOnly(dm)) {
                return;
            }
            synchronized (statsLock) {
                int dm_state = updateDMCounts(dm);
                if (completed) {
                    stats.numComplete++;
                    stats.numIncomplete--;
                    if (dm_state == DownloadManager.STATE_ERROR) {
                        stats.numErrorComplete++;
                        stats.numErrorInComplete--;
                    }
                    if (dm_state == DownloadManager.STATE_STOPPED) {
                        statsNoLowNoise.numStoppedIncomplete--;
                    }
                } else {
                    stats.numComplete--;
                    stats.numIncomplete++;
                    if (dm_state == DownloadManager.STATE_ERROR) {
                        stats.numErrorComplete--;
                        stats.numErrorInComplete++;
                    }
                    if (dm_state == DownloadManager.STATE_STOPPED) {
                        statsNoLowNoise.numStoppedIncomplete++;
                    }
                }
                recountUnopened();
                updateErrorTooltip(gm, stats);
                refreshAllLibraries();
            }
        }
    };
    gmListener = new GlobalManagerAdapter() {

        @Override
        public void downloadManagerRemoved(DownloadManager dm) {
            downloadManagerRemoved(dm, statsNoLowNoise);
            downloadManagerRemoved(dm, statsWithLowNoise);
        }

        public void downloadManagerRemoved(DownloadManager dm, stats stats) {
            if (!stats.includeLowNoise && PlatformTorrentUtils.isAdvancedViewOnly(dm)) {
                return;
            }
            synchronized (statsLock) {
                recountUnopened();
                if (dm.getAssumedComplete()) {
                    stats.numComplete--;
                    Boolean wasDownloadingB = (Boolean) dm.getUserData("wasDownloading");
                    if (wasDownloadingB != null && wasDownloadingB.booleanValue()) {
                        stats.numDownloading--;
                    }
                } else {
                    stats.numIncomplete--;
                    Boolean wasSeedingB = (Boolean) dm.getUserData("wasSeeding");
                    if (wasSeedingB != null && wasSeedingB.booleanValue()) {
                        stats.numSeeding--;
                    }
                }
                Boolean wasStoppedB = (Boolean) dm.getUserData("wasStopped");
                boolean wasStopped = wasStoppedB != null && wasStoppedB.booleanValue();
                if (wasStopped) {
                    if (!dm.getAssumedComplete()) {
                        stats.numStoppedIncomplete--;
                    }
                }
                Boolean wasQueuedB = (Boolean) dm.getUserData("wasQueued");
                boolean wasQueued = wasQueuedB != null && wasQueuedB.booleanValue();
                if (wasQueued) {
                    stats.numQueued--;
                }
                refreshAllLibraries();
            }
            dm.removeListener(dmListener);
        }

        @Override
        public void downloadManagerAdded(DownloadManager dm) {
            dm.addListener(dmListener, false);
            synchronized (statsLock) {
                recountUnopened();
                downloadManagerAdded(dm, statsNoLowNoise);
                downloadManagerAdded(dm, statsWithLowNoise);
                refreshAllLibraries();
            }
        }

        public void downloadManagerAdded(DownloadManager dm, stats stats) {
            if (!stats.includeLowNoise && PlatformTorrentUtils.isAdvancedViewOnly(dm)) {
                return;
            }
            boolean assumed_complete = dm.getAssumedComplete();
            synchronized (statsLock) {
                if (dm.isPersistent() && dm.getTorrent() != null && !assumed_complete) {
                    // ignore borked torrents as their create time is inaccurate
                    stats.newestIncompleteDownloadTime = Math.max(stats.newestIncompleteDownloadTime, dm.getCreationTime());
                }
                int dm_state = dm.getState();
                if (assumed_complete) {
                    stats.numComplete++;
                    if (dm_state == DownloadManager.STATE_SEEDING) {
                        stats.numSeeding++;
                    }
                } else {
                    stats.numIncomplete++;
                    if (dm_state == DownloadManager.STATE_DOWNLOADING) {
                        dm.setUserData("wasDownloading", Boolean.TRUE);
                        stats.numDownloading++;
                    } else {
                        dm.setUserData("wasDownloading", Boolean.FALSE);
                    }
                }
            }
        }
    };
    gm.addListener(gmListener, false);
    resetStats(gm, dmListener, statsWithLowNoise, statsNoLowNoise);
    refreshAllLibraries();
    timerEventPeriodic = SimpleTimer.addPeriodicEvent("header:refresh", 60 * 1000, new TimerEventPerformer() {

        @Override
        public void perform(TimerEvent event) {
            stats withNoise = new stats();
            stats noNoise = new stats();
            noNoise.includeLowNoise = false;
            withNoise.includeLowNoise = true;
            synchronized (statsLock) {
                resetStats(gm, null, withNoise, noNoise);
                boolean fixed = false;
                if (!withNoise.sameAs(statsWithLowNoise)) {
                    statsWithLowNoise.copyFrom(withNoise);
                    fixed = true;
                }
                if (!noNoise.sameAs(statsNoLowNoise)) {
                    statsNoLowNoise.copyFrom(noNoise);
                    fixed = true;
                }
                if (fixed) {
                    updateErrorTooltip(gm, statsWithLowNoise);
                    updateErrorTooltip(gm, statsNoLowNoise);
                    refreshAllLibraries();
                }
            }
        }
    });
}
Also used : Category(com.biglybt.core.category.Category) CategoryManagerListener(com.biglybt.core.category.CategoryManagerListener) DownloadManager(com.biglybt.core.download.DownloadManager) DownloadManagerAdapter(com.biglybt.core.download.impl.DownloadManagerAdapter) GlobalManager(com.biglybt.core.global.GlobalManager) GlobalManagerAdapter(com.biglybt.core.global.GlobalManagerAdapter) ParameterListener(com.biglybt.core.config.ParameterListener) CategoryListener(com.biglybt.core.category.CategoryListener)

Example 48 with GlobalManager

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

the class SB_Transfers method addMenuUnwatched.

private void addMenuUnwatched(String id) {
    PluginInterface pi = PluginInitializer.getDefaultInterface();
    UIManager uim = pi.getUIManager();
    MenuManager menuManager = uim.getMenuManager();
    MenuItem menuItem = menuManager.addMenuItem("sidebar." + id, "v3.activity.button.watchall");
    menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    menuItem.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            CoreWaiterSWT.waitForCore(TriggerInThread.ANY_THREAD, new CoreRunningListener() {

                @Override
                public void coreRunning(Core core) {
                    GlobalManager gm = core.getGlobalManager();
                    List<?> downloadManagers = gm.getDownloadManagers();
                    for (Iterator<?> iter = downloadManagers.iterator(); iter.hasNext(); ) {
                        DownloadManager dm = (DownloadManager) iter.next();
                        if (!PlatformTorrentUtils.getHasBeenOpened(dm) && dm.getAssumedComplete()) {
                            PlatformTorrentUtils.setHasBeenOpened(dm, true);
                        }
                    }
                }
            });
        }
    });
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) UIManager(com.biglybt.pif.ui.UIManager) MenuItem(com.biglybt.pif.ui.menus.MenuItem) DownloadManager(com.biglybt.core.download.DownloadManager) GlobalManager(com.biglybt.core.global.GlobalManager) MenuManager(com.biglybt.pif.ui.menus.MenuManager) CoreRunningListener(com.biglybt.core.CoreRunningListener) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) Core(com.biglybt.core.Core)

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