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;
}
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();
}
}
}
});
}
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);
}
}
}
});
}
});
}
Aggregations