use of com.biglybt.core.category.Category 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.category.Category in project BiglyBT by BiglySoftware.
the class CategoryItem method refresh.
@Override
public void refresh(TableCell cell) {
TRHostTorrent tr_torrent = (TRHostTorrent) cell.getDataSource();
if (tr_torrent == null) {
cell.setText("");
} else {
TOTorrent torrent = tr_torrent.getTorrent();
if (gm == null) {
if (CoreFactory.isCoreRunning()) {
return;
}
gm = CoreFactory.getSingleton().getGlobalManager();
}
DownloadManager dm = gm.getDownloadManager(torrent);
String cat_str = null;
if (dm != null) {
Category cat = dm.getDownloadState().getCategory();
if (cat != null) {
cat_str = cat.getName();
}
} else {
// pick up specific torrent category, bit 'o' a hack tis
cat_str = TorrentUtils.getPluginStringProperty(torrent, "azcoreplugins.category");
}
cell.setText(cat_str == null ? "" : cat_str);
}
}
use of com.biglybt.core.category.Category in project BiglyBT by BiglySoftware.
the class TranscodeManagerImpl method updateStatus.
protected void updateStatus(int tick_count) {
if (queue != null) {
queue.updateStatus(tick_count);
if (!hooked_categories) {
hooked_categories = true;
CategoryManager.addCategoryManagerListener(new CategoryManagerListener() {
@Override
public void categoryAdded(Category category) {
}
@Override
public void categoryRemoved(Category category) {
}
@Override
public void categoryChanged(Category category) {
checkCategories();
}
});
checkCategories();
}
if (!hooked_tags) {
hooked_tags = true;
TagManagerFactory.getTagManager().addTagFeatureListener(TagFeature.TF_XCODE, new TagFeatureListener() {
@Override
public void tagFeatureChanged(Tag tag, int feature) {
checkTags();
}
});
checkTags();
}
}
}
use of com.biglybt.core.category.Category in project BiglyBT by BiglySoftware.
the class TranscodeManagerImpl method checkCategories.
void checkCategories() {
Category[] cats = CategoryManager.getCategories();
Map<Category, Object[]> active_map = new HashMap<>();
for (Category cat : cats) {
String target = cat.getStringAttribute(Category.AT_AUTO_TRANSCODE_TARGET);
if (target != null) {
String device_id = null;
if (target.endsWith("/blank")) {
device_id = target.substring(0, target.length() - 6);
}
DeviceMediaRenderer target_dmr = null;
TranscodeProfile target_profile = null;
for (DeviceImpl device : device_manager.getDevices()) {
if (!(device instanceof DeviceMediaRenderer)) {
continue;
}
DeviceMediaRenderer dmr = (DeviceMediaRenderer) device;
if (device_id != null) {
if (device.getID().equals(device_id)) {
target_dmr = dmr;
target_profile = device.getBlankProfile();
break;
}
} else {
TranscodeProfile[] profs = device.getTranscodeProfiles();
for (TranscodeProfile prof : profs) {
if (prof.getUID().equals(target)) {
target_dmr = dmr;
target_profile = prof;
break;
}
}
}
}
if (target_dmr != null) {
active_map.put(cat, new Object[] { target_dmr, target_profile });
}
}
}
Map<Category, Object[]> to_process = new HashMap<>();
synchronized (category_map) {
if (category_listener == null) {
category_listener = new CategoryListener() {
@Override
public void downloadManagerAdded(Category cat, DownloadManager manager) {
Object[] details;
synchronized (category_map) {
details = category_map.get(cat);
}
if (details != null) {
processCategory(cat, details, manager);
}
}
@Override
public void downloadManagerRemoved(Category cat, DownloadManager removed) {
}
};
}
Iterator<Category> it = category_map.keySet().iterator();
while (it.hasNext()) {
Category c = it.next();
if (!active_map.containsKey(c)) {
c.removeCategoryListener(category_listener);
it.remove();
}
}
for (final Category c : active_map.keySet()) {
if (!category_map.containsKey(c)) {
to_process.put(c, active_map.get(c));
c.addCategoryListener(category_listener);
category_map.put(c, active_map.get(c));
if (c.getType() == Category.TYPE_UNCATEGORIZED) {
if (category_dl_listener == null) {
// new downloads don't get a category-change event fired when added
// we also want to delay things a bit to allow other components
// to set an initial category. there's no hurry anyways
category_dl_listener = new GlobalManagerAdapter() {
@Override
public void downloadManagerAdded(final DownloadManager dm) {
new DelayedEvent("TM:cat-check", 10 * 1000, new AERunnable() {
@Override
public void runSupport() {
Category dm_c = dm.getDownloadState().getCategory();
if (dm_c == null || dm_c == c) {
// still uncategorised
Object[] details;
synchronized (category_map) {
details = category_map.get(c);
}
if (details != null) {
processCategory(c, details, dm);
}
}
}
});
}
@Override
public void downloadManagerRemoved(DownloadManager dm) {
}
};
core.getGlobalManager().addListener(category_dl_listener, false);
}
}
}
}
}
if (to_process.size() > 0) {
List<DownloadManager> downloads = core.getGlobalManager().getDownloadManagers();
for (Map.Entry<Category, Object[]> entry : to_process.entrySet()) {
Category c = entry.getKey();
Object[] details = entry.getValue();
List<DownloadManager> list = c.getDownloadManagers(downloads);
for (DownloadManager dm : list) {
processCategory(c, details, dm);
}
}
}
}
use of com.biglybt.core.category.Category in project BiglyBT by BiglySoftware.
the class CategoryImpl method addManager.
@Override
public void addManager(DownloadManagerState manager_state) {
Category manager_cat = manager_state.getCategory();
if ((type != Category.TYPE_UNCATEGORIZED && manager_cat != this) || (type == Category.TYPE_UNCATEGORIZED && manager_cat != null)) {
manager_state.setCategory(this);
// we will be called again by CategoryManager.categoryChange
return;
}
DownloadManager manager = manager_state.getDownloadManager();
// can be null if called during downloadmanagerstate construction
if (manager == null) {
return;
}
addTaggable(manager);
if (!managers.contains(manager)) {
if (type == Category.TYPE_USER) {
managers.add(manager);
}
manager.addRateLimiter(upload_limiter, true);
manager.addRateLimiter(download_limiter, false);
int pri = getIntAttribute(AT_UPLOAD_PRIORITY, -1);
if (pri > 0) {
if (manager.getDownloadState() != null) {
manager.updateAutoUploadPriority(UPLOAD_PRIORITY_KEY, true);
}
}
category_listeners.dispatch(LDT_CATEGORY_DMADDED, manager);
}
}
Aggregations