Messages.setLanguageText(itemDelete,
"MyTorrentsView.menu.category.delete");
itemDelete.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
GlobalManager gm = AzureusCoreFactory.getSingleton().getGlobalManager();
List<?> managers = category.getDownloadManagers(gm.getDownloadManagers());
// move to array,since setcategory removed it from the category,
// which would mess up our loop
DownloadManager dms[] = managers.toArray(new DownloadManager[managers.size()]);
for (int i = 0; i < dms.length; i++) {
dms[i].getDownloadState().setCategory(null);
}
CategoryManager.removeCategory(category);
}
});
}
if (category.getType() != Category.TYPE_ALL) {
long maxDownload = COConfigurationManager.getIntParameter(
"Max Download Speed KBs", 0) * 1024;
long maxUpload = COConfigurationManager.getIntParameter(
"Max Upload Speed KBs", 0) * 1024;
int down_speed = category.getDownloadSpeed();
int up_speed = category.getUploadSpeed();
ViewUtils.addSpeedMenu(menu.getShell(), menu, true, true, false,
down_speed == 0, down_speed, down_speed, maxDownload, false,
up_speed == 0, up_speed, up_speed, maxUpload, 1, new SpeedAdapter() {
public void setDownSpeed(int val) {
category.setDownloadSpeed(val);
}
public void setUpSpeed(int val) {
category.setUploadSpeed(val);
}
});
}
GlobalManager gm = AzureusCoreFactory.getSingleton().getGlobalManager();
List<?> managers = category.getDownloadManagers(gm.getDownloadManagers());
final DownloadManager dms[] = managers.toArray(new DownloadManager[managers.size()]);
boolean start = false;
boolean stop = false;
for (int i = 0; i < dms.length; i++) {
DownloadManager dm = dms[i];
stop = stop || ManagerUtils.isStopable(dm);
start = start || ManagerUtils.isStartable(dm);
}
// Queue
final MenuItem itemQueue = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemQueue, "MyTorrentsView.menu.queue");
Utils.setMenuItemImage(itemQueue, "start");
itemQueue.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
GlobalManager gm = AzureusCoreFactory.getSingleton().getGlobalManager();
List<?> managers = category.getDownloadManagers(gm.getDownloadManagers());
Object[] dms = managers.toArray();
TorrentUtil.queueDataSources(dms, true);
}
});
itemQueue.setEnabled(start);
// Stop
final MenuItem itemStop = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemStop, "MyTorrentsView.menu.stop");
Utils.setMenuItemImage(itemStop, "stop");
itemStop.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
GlobalManager gm = AzureusCoreFactory.getSingleton().getGlobalManager();
List<?> managers = category.getDownloadManagers(gm.getDownloadManagers());
Object[] dms = managers.toArray();
TorrentUtil.stopDataSources(dms);
}
});