use of com.biglybt.core.category.Category in project BiglyBT by BiglySoftware.
the class TorrentUtil method addCategorySubMenu.
protected static void addCategorySubMenu(final DownloadManager[] dms, Menu menuCategory) {
MenuItem[] items = menuCategory.getItems();
int i;
for (i = 0; i < items.length; i++) {
items[i].dispose();
}
Category[] categories = CategoryManager.getCategories();
Arrays.sort(categories);
// Ensure that there is at least one user category available.
boolean allow_category_selection = categories.length > 0;
if (allow_category_selection) {
boolean user_category_found = false;
for (i = 0; i < categories.length; i++) {
if (categories[i].getType() == Category.TYPE_USER) {
user_category_found = true;
break;
}
}
// It may be the categories array just contains "uncategorised".
allow_category_selection = user_category_found;
}
if (allow_category_selection) {
final Category catUncat = CategoryManager.getCategory(Category.TYPE_UNCATEGORIZED);
if (catUncat != null) {
final MenuItem itemCategory = new MenuItem(menuCategory, SWT.PUSH);
Messages.setLanguageText(itemCategory, catUncat.getName());
itemCategory.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
dm.getDownloadState().setCategory(catUncat);
}
});
new MenuItem(menuCategory, SWT.SEPARATOR);
}
for (i = 0; i < categories.length; i++) {
final Category category = categories[i];
if (category.getType() == Category.TYPE_USER) {
final MenuItem itemCategory = new MenuItem(menuCategory, SWT.PUSH);
itemCategory.setText(category.getName());
itemCategory.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
dm.getDownloadState().setCategory(category);
}
});
}
}
new MenuItem(menuCategory, SWT.SEPARATOR);
}
final MenuItem itemAddCategory = new MenuItem(menuCategory, SWT.PUSH);
Messages.setLanguageText(itemAddCategory, "MyTorrentsView.menu.setCategory.add");
itemAddCategory.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager[] dms) {
CategoryUIUtils.showCreateCategoryDialog(new TagReturner() {
@Override
public void returnedTags(Tag[] tags) {
if (tags.length == 1 && tags[0] instanceof Category) {
assignToCategory(dms, (Category) tags[0]);
}
}
});
}
});
}
use of com.biglybt.core.category.Category in project BiglyBT by BiglySoftware.
the class GlobalManagerImpl method addDownloadManager.
protected DownloadManager addDownloadManager(DownloadManager download_manager, boolean save, boolean notifyListeners) {
if (!isStopping) {
// make sure we have existing ones loaded so that existing check works
loadExistingTorrentsNow(false);
try {
managers_mon.enter();
int existing_index = managers_cow.indexOf(download_manager);
if (existing_index != -1) {
DownloadManager existing = managers_cow.get(existing_index);
download_manager.destroy(true);
return (existing);
}
DownloadManagerStats dm_stats = download_manager.getStats();
HashWrapper hashwrapper = null;
try {
TOTorrent torrent = download_manager.getTorrent();
if (torrent != null) {
hashwrapper = torrent.getHashWrapper();
}
} catch (Exception e1) {
}
Map save_download_state = (Map) saved_download_manager_state.remove(hashwrapper);
long saved_data_bytes_downloaded = 0;
long saved_data_bytes_uploaded = 0;
long saved_discarded = 0;
long saved_hashfails = 0;
long saved_SecondsDownloading = 0;
long saved_SecondsOnlySeeding = 0;
if (save_download_state != null) {
int maxDL = save_download_state.get("maxdl") == null ? 0 : ((Long) save_download_state.get("maxdl")).intValue();
int maxUL = save_download_state.get("maxul") == null ? 0 : ((Long) save_download_state.get("maxul")).intValue();
Long lDownloaded = (Long) save_download_state.get("downloaded");
Long lUploaded = (Long) save_download_state.get("uploaded");
Long lCompletedBytes = (Long) save_download_state.get("completedbytes");
Long lDiscarded = (Long) save_download_state.get("discarded");
// old method, number of fails
Long lHashFailsCount = (Long) save_download_state.get("hashfails");
// new method, bytes failed
Long lHashFailsBytes = (Long) save_download_state.get("hashfailbytes");
// migrated to downloadstate in 2403
Long nbUploads = (Long) save_download_state.get("uploads");
if (nbUploads != null) {
// migrate anything other than the default value of 4
int maxUploads = nbUploads.intValue();
if (maxUploads != 4) {
// value if the stored value is non-default and the state one is
if (download_manager.getMaxUploads() == 4) {
download_manager.setMaxUploads(maxUploads);
}
}
}
dm_stats.setDownloadRateLimitBytesPerSecond(maxDL);
dm_stats.setUploadRateLimitBytesPerSecond(maxUL);
if (lCompletedBytes != null) {
dm_stats.setDownloadCompletedBytes(lCompletedBytes.longValue());
}
if (lDiscarded != null) {
saved_discarded = lDiscarded.longValue();
}
if (lHashFailsBytes != null) {
saved_hashfails = lHashFailsBytes.longValue();
} else if (lHashFailsCount != null) {
TOTorrent torrent = download_manager.getTorrent();
if (torrent != null) {
saved_hashfails = lHashFailsCount.longValue() * torrent.getPieceLength();
}
}
Long lPosition = (Long) save_download_state.get("position");
// 2.2.0.1 - category moved to downloadstate - this here for
// migration purposes
String sCategory = null;
if (save_download_state.containsKey("category")) {
try {
sCategory = new String((byte[]) save_download_state.get("category"), Constants.DEFAULT_ENCODING);
} catch (UnsupportedEncodingException e) {
Debug.printStackTrace(e);
}
}
if (sCategory != null) {
Category cat = CategoryManager.getCategory(sCategory);
if (cat != null)
download_manager.getDownloadState().setCategory(cat);
}
download_manager.requestAssumedCompleteMode();
if (lDownloaded != null && lUploaded != null) {
boolean bCompleted = download_manager.isDownloadComplete(false);
long lUploadedValue = lUploaded.longValue();
long lDownloadedValue = lDownloaded.longValue();
if (bCompleted && (lDownloadedValue == 0)) {
// Gudy : I say if the torrent is complete, let's simply set downloaded
// to size in order to see a meaningfull share-ratio
// Gudy : Bypass this horrible hack, and I don't care of first priority seeding...
/*
if (lDownloadedValue != 0 && ((lUploadedValue * 1000) / lDownloadedValue < minQueueingShareRatio) )
lUploadedValue = ( download_manager.getSize()+999) * minQueueingShareRatio / 1000;
*/
// Parg: quite a few users have complained that they want "open-for-seeding" torrents to
// have an infinite share ratio for seeding rules (i.e. so they're not first priority)
int dl_copies = COConfigurationManager.getIntParameter("StartStopManager_iAddForSeedingDLCopyCount");
lDownloadedValue = download_manager.getSize() * dl_copies;
download_manager.getDownloadState().setFlag(DownloadManagerState.FLAG_ONLY_EVER_SEEDED, true);
}
saved_data_bytes_downloaded = lDownloadedValue;
saved_data_bytes_uploaded = lUploadedValue;
}
if (lPosition != null)
download_manager.setPosition(lPosition.intValue());
// no longer needed code
// else if (dm_stats.getDownloadCompleted(false) < 1000)
// dm.setPosition(bCompleted ? numCompleted : numDownloading);
Long lSecondsDLing = (Long) save_download_state.get("secondsDownloading");
if (lSecondsDLing != null) {
saved_SecondsDownloading = lSecondsDLing.longValue();
}
Long lSecondsOnlySeeding = (Long) save_download_state.get("secondsOnlySeeding");
if (lSecondsOnlySeeding != null) {
saved_SecondsOnlySeeding = lSecondsOnlySeeding.longValue();
}
Long already_allocated = (Long) save_download_state.get("allocated");
if (already_allocated != null && already_allocated.intValue() == 1) {
download_manager.setDataAlreadyAllocated(true);
}
Long creation_time = (Long) save_download_state.get("creationTime");
if (creation_time != null) {
long ct = creation_time.longValue();
if (ct < SystemTime.getCurrentTime()) {
download_manager.setCreationTime(ct);
}
}
} else {
if (dm_stats.getDownloadCompleted(false) == 1000) {
int dl_copies = COConfigurationManager.getIntParameter("StartStopManager_iAddForSeedingDLCopyCount");
saved_data_bytes_downloaded = download_manager.getSize() * dl_copies;
}
}
dm_stats.restoreSessionTotals(saved_data_bytes_downloaded, saved_data_bytes_uploaded, saved_discarded, saved_hashfails, saved_SecondsDownloading, saved_SecondsOnlySeeding);
boolean isCompleted = download_manager.isDownloadComplete(false);
if (download_manager.getPosition() == -1) {
int endPosition = 0;
for (int i = 0; i < managers_cow.size(); i++) {
DownloadManager dm = managers_cow.get(i);
boolean dmIsCompleted = dm.isDownloadComplete(false);
if (dmIsCompleted == isCompleted)
endPosition++;
}
download_manager.setPosition(endPosition + 1);
}
// Even though when the DownloadManager was created, onlySeeding was
// most likely set to true for completed torrents (via the Initializer +
// readTorrent), there's a chance that the torrent file didn't have the
// resume data. If it didn't, but we marked it as complete in our
// downloads config file, we should set to onlySeeding
download_manager.requestAssumedCompleteMode();
List<DownloadManager> new_download_managers = new ArrayList<>(managers_cow);
new_download_managers.add(download_manager);
managers_cow = new_download_managers;
TOTorrent torrent = download_manager.getTorrent();
if (torrent != null) {
try {
manager_map.put(new HashWrapper(torrent.getHash()), download_manager);
} catch (TOTorrentException e) {
Debug.printStackTrace(e);
}
}
// flag set, to prevent them being moved.
if (COConfigurationManager.getBooleanParameter("Set Completion Flag For Completed Downloads On Start")) {
// ones yet.
if (download_manager.isDownloadComplete(true)) {
download_manager.getDownloadState().setFlag(DownloadManagerState.FLAG_MOVE_ON_COMPLETION_DONE, true);
}
}
if (notifyListeners) {
listeners_and_event_listeners.dispatch(LDT_MANAGER_ADDED, download_manager);
taggable_life_manager.taggableCreated(download_manager);
if (host_support != null) {
host_support.torrentAdded(download_manager.getTorrentFileName(), download_manager.getTorrent());
}
}
download_manager.addListener(this);
if (save_download_state != null) {
Long lForceStart = (Long) save_download_state.get("forceStart");
if (lForceStart == null) {
Long lStartStopLocked = (Long) save_download_state.get("startStopLocked");
if (lStartStopLocked != null) {
lForceStart = lStartStopLocked;
}
}
if (lForceStart != null) {
if (lForceStart.intValue() == 1) {
download_manager.setForceStart(true);
}
}
}
} finally {
managers_mon.exit();
}
if (save) {
saveDownloads(false);
}
return (download_manager);
} else {
Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "Tried to add a DownloadManager after shutdown of GlobalManager."));
return (null);
}
}
use of com.biglybt.core.category.Category in project BiglyBT by BiglySoftware.
the class DownloadManagerStateImpl method setAttribute.
@Override
public void setAttribute(String name, String value) {
if (name.equals(AT_CATEGORY)) {
if (value == null) {
setCategory(null);
} else {
Category cat = CategoryManager.getCategory(value);
if (cat == null) {
cat = CategoryManager.createCategory(value);
}
setCategory(cat);
}
return;
}
if (name.equals(AT_RELATIVE_SAVE_PATH)) {
if (value.length() > 0) {
File relative_path_file = new File(value);
relative_path_file = DownloadManagerDefaultPaths.normaliseRelativePath(relative_path_file);
value = (relative_path_file == null) ? "" : relative_path_file.getPath();
}
}
setStringAttribute(name, value);
}
use of com.biglybt.core.category.Category in project BiglyBT by BiglySoftware.
the class DownloadManagerStateImpl method setCategory.
@Override
public void setCategory(Category cat) {
if (cat == category) {
return;
}
if (cat != null && cat.getType() != Category.TYPE_USER) {
cat = null;
if (cat == category) {
return;
}
}
Category oldCategory = (category == null) ? CategoryManager.getCategory(Category.TYPE_UNCATEGORIZED) : category;
category = cat;
if (oldCategory != null) {
oldCategory.removeManager(this);
}
DownloadManager dm = getDownloadManager();
if (dm != null && !dm.isDestroyed()) {
if (category != null) {
category.addManager(this);
} else {
CategoryManager.getCategory(Category.TYPE_UNCATEGORIZED).addManager(this);
}
}
if (category != null) {
setStringAttribute(AT_CATEGORY, category.getName());
} else {
setStringAttribute(AT_CATEGORY, null);
}
}
use of com.biglybt.core.category.Category in project BiglyBT by BiglySoftware.
the class SBC_DevicesView method addCategorySubMenu.
private void addCategorySubMenu(Menu menu_category, final TranscodeFile[] files) {
MenuItem[] items = menu_category.getItems();
int i;
for (i = 0; i < items.length; i++) {
items[i].dispose();
}
Category[] categories = CategoryManager.getCategories();
Arrays.sort(categories);
if (categories.length > 0) {
Category catUncat = CategoryManager.getCategory(Category.TYPE_UNCATEGORIZED);
if (catUncat != null) {
final MenuItem itemCategory = new MenuItem(menu_category, SWT.PUSH);
Messages.setLanguageText(itemCategory, catUncat.getName());
itemCategory.setData("Category", catUncat);
itemCategory.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
MenuItem item = (MenuItem) event.widget;
assignSelectedToCategory((Category) item.getData("Category"), files);
}
});
new MenuItem(menu_category, SWT.SEPARATOR);
}
for (i = 0; i < categories.length; i++) {
if (categories[i].getType() == Category.TYPE_USER) {
final MenuItem itemCategory = new MenuItem(menu_category, SWT.PUSH);
itemCategory.setText(categories[i].getName());
itemCategory.setData("Category", categories[i]);
itemCategory.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
MenuItem item = (MenuItem) event.widget;
assignSelectedToCategory((Category) item.getData("Category"), files);
}
});
}
}
new MenuItem(menu_category, SWT.SEPARATOR);
}
final MenuItem itemAddCategory = new MenuItem(menu_category, SWT.PUSH);
Messages.setLanguageText(itemAddCategory, "MyTorrentsView.menu.setCategory.add");
itemAddCategory.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
addCategory(files);
}
});
}
Aggregations