use of com.biglybt.core.download.DownloadManager 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();
}
}
});
}
use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.
the class SBC_TorrentDetailsView method initialize.
private void initialize(Composite composite) {
Composite main_area = new Composite(composite, SWT.NULL);
main_area.setLayout(new FormLayout());
// Color bg_color = ColorCache.getColor(composite.getDisplay(), "#c0cbd4");
UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
this.parent = composite;
if (tabbedMDI == null) {
tabbedMDI = uiFunctions.createTabbedMDI(main_area, "detailsview");
} else {
System.out.println("ManagerView::initialize : folder isn't null !!!");
}
if (composite.getLayout() instanceof FormLayout) {
main_area.setLayoutData(Utils.getFilledFormData());
} else if (composite.getLayout() instanceof GridLayout) {
main_area.setLayoutData(new GridData(GridData.FILL_BOTH));
}
composite.layout();
// Call plugin listeners
if (uiFunctions != null) {
UISWTInstance pluginUI = uiFunctions.getUISWTInstance();
if (pluginUI != null) {
MyTorrentsView.registerPluginViews(pluginUI);
for (String id : new String[] { UISWTInstance.VIEW_MYTORRENTS, UISWTInstance.VIEW_TORRENT_DETAILS }) {
UISWTViewEventListenerWrapper[] pluginViews = pluginUI.getViewListeners(id);
for (UISWTViewEventListenerWrapper l : pluginViews) {
if (id == UISWTInstance.VIEW_MYTORRENTS && l.getViewID() == PieceInfoView.MSGID_PREFIX) {
// Simple hack to exlude PieceInfoView tab as it's already within Pieces View
continue;
}
if (l != null) {
try {
tabbedMDI.createEntryFromEventListener(null, UISWTInstance.VIEW_TORRENT_DETAILS, l, l.getViewID(), false, manager, null);
} catch (Throwable e) {
Debug.out(e);
}
}
}
}
}
}
SelectedContentManager.addCurrentlySelectedContentListener(this);
tabbedMDI.addListener(new MdiSWTMenuHackListener() {
@Override
public void menuWillBeShown(MdiEntry entry, Menu menuTree) {
menuTree.setData("downloads", new DownloadManager[] { manager });
menuTree.setData("is_detailed_view", true);
MenuFactory.buildTorrentMenu(menuTree);
}
});
if (dataSource instanceof Object[] && ((Object[]) dataSource)[0] instanceof PEPeer) {
tabbedMDI.showEntryByID(PeersView.MSGID_PREFIX);
} else {
MdiEntry[] entries = tabbedMDI.getEntries();
if (entries.length > 0) {
tabbedMDI.showEntry(entries[0]);
}
}
}
use of com.biglybt.core.download.DownloadManager 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);
}
use of com.biglybt.core.download.DownloadManager 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);
}
});
}
}
use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.
the class SB_Transfers method resetStats.
private void resetStats(GlobalManager gm, DownloadManagerListener listener, stats statsWithLowNoise, stats statsNoLowNoise) {
List<DownloadManager> downloadManagers = gm.getDownloadManagers();
for (Iterator<DownloadManager> iter = downloadManagers.iterator(); iter.hasNext(); ) {
DownloadManager dm = iter.next();
boolean lowNoise = PlatformTorrentUtils.isAdvancedViewOnly(dm);
boolean assumed_complete = dm.getAssumedComplete();
if (dm.isPersistent() && dm.getTorrent() != null && !assumed_complete) {
// ignore borked torrents as their create time is inaccurate
long createTime = dm.getCreationTime();
statsWithLowNoise.newestIncompleteDownloadTime = Math.max(statsWithLowNoise.newestIncompleteDownloadTime, createTime);
if (!lowNoise) {
statsNoLowNoise.newestIncompleteDownloadTime = Math.max(statsNoLowNoise.newestIncompleteDownloadTime, createTime);
}
}
if (listener != null) {
dm.addListener(listener, false);
}
int dm_state = dm.getState();
if (dm_state == DownloadManager.STATE_STOPPED) {
dm.setUserData("wasStopped", Boolean.TRUE);
if (!dm.getAssumedComplete()) {
statsWithLowNoise.numStoppedIncomplete++;
}
if (!lowNoise) {
if (!dm.getAssumedComplete()) {
statsNoLowNoise.numStoppedIncomplete++;
}
}
} else {
dm.setUserData("wasStopped", Boolean.FALSE);
}
if (dm_state == DownloadManager.STATE_QUEUED) {
dm.setUserData("wasQueued", Boolean.TRUE);
statsWithLowNoise.numQueued++;
if (!lowNoise) {
statsNoLowNoise.numQueued++;
}
} else {
dm.setUserData("wasQueued", Boolean.FALSE);
}
if (dm.getAssumedComplete()) {
statsWithLowNoise.numComplete++;
if (!lowNoise) {
statsNoLowNoise.numComplete++;
}
if (dm_state == DownloadManager.STATE_SEEDING) {
dm.setUserData("wasSeeding", Boolean.TRUE);
statsWithLowNoise.numSeeding++;
if (!lowNoise) {
statsNoLowNoise.numSeeding++;
}
} else {
dm.setUserData("wasSeeding", Boolean.FALSE);
}
} else {
statsWithLowNoise.numIncomplete++;
if (!lowNoise) {
statsNoLowNoise.numIncomplete++;
}
if (dm_state == DownloadManager.STATE_DOWNLOADING) {
statsWithLowNoise.numDownloading++;
if (!lowNoise) {
statsNoLowNoise.numDownloading++;
}
}
}
if (!PlatformTorrentUtils.getHasBeenOpened(dm) && dm.getAssumedComplete()) {
statsNoLowNoise.numUnOpened++;
}
}
statsWithLowNoise.numUnOpened = statsNoLowNoise.numUnOpened;
}
Aggregations