use of com.biglybt.core.tag.TagManager in project BiglyBT by BiglySoftware.
the class DeviceManagerUI method addTagSubMenu.
private static void addTagSubMenu(MenuManager menu_manager, MenuItem menu, final DeviceMediaRenderer device) {
menu.removeAllChildItems();
TagManager tm = TagManagerFactory.getTagManager();
List<Tag> tags = tm.getTagType(TagType.TT_DOWNLOAD_MANUAL).getTags();
tags = TagUIUtils.sortTags(tags);
long tag_id = device.getAutoShareToTagID();
Tag assigned_tag = tm.lookupTagByUID(tag_id);
MenuItem m = menu_manager.addMenuItem(menu, "label.no.tag");
m.setStyle(MenuItem.STYLE_RADIO);
m.setData(Boolean.valueOf(assigned_tag == null));
m.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
device.setAutoShareToTagID(-1);
}
});
m = menu_manager.addMenuItem(menu, "sep1");
m.setStyle(MenuItem.STYLE_SEPARATOR);
List<String> menu_names = new ArrayList<>();
Map<String, Tag> menu_name_map = new IdentityHashMap<>();
for (Tag t : tags) {
if (!t.isTagAuto()[0]) {
String name = t.getTagName(true);
menu_names.add(name);
menu_name_map.put(name, t);
}
}
List<Object> menu_structure = MenuBuildUtils.splitLongMenuListIntoHierarchy(menu_names, TagUIUtils.MAX_TOP_LEVEL_TAGS_IN_MENU);
for (Object obj : menu_structure) {
List<Tag> bucket_tags = new ArrayList<>();
MenuItem parent_menu;
if (obj instanceof String) {
parent_menu = menu;
bucket_tags.add(menu_name_map.get((String) obj));
} else {
Object[] entry = (Object[]) obj;
List<String> tag_names = (List<String>) entry[1];
boolean has_selected = false;
for (String name : tag_names) {
Tag tag = menu_name_map.get(name);
bucket_tags.add(tag);
if (assigned_tag == tag) {
has_selected = true;
}
}
parent_menu = menu_manager.addMenuItem(menu, "!" + (String) entry[0] + (has_selected ? " (*)" : "") + "!");
parent_menu.setStyle(MenuItem.STYLE_MENU);
}
for (final Tag tag : bucket_tags) {
m = menu_manager.addMenuItem(parent_menu, tag.getTagName(false));
m.setStyle(MenuItem.STYLE_RADIO);
m.setData(Boolean.valueOf(assigned_tag == tag));
m.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
device.setAutoShareToTagID(tag.getTagUID());
}
});
}
}
m = menu_manager.addMenuItem(menu, "sep2");
m.setStyle(MenuItem.STYLE_SEPARATOR);
m = menu_manager.addMenuItem(menu, "label.add.tag");
m.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
TagUIUtils.createManualTag(new UIFunctions.TagReturner() {
@Override
public void returnedTags(Tag[] tags) {
if (tags != null) {
for (Tag new_tag : tags) {
device.setAutoShareToTagID(new_tag.getTagUID());
}
}
}
});
}
});
}
use of com.biglybt.core.tag.TagManager in project BiglyBT by BiglySoftware.
the class SBC_DevicesView method addTagsSubMenu.
private void addTagsSubMenu(Menu menu_tags, final TranscodeFile[] files) {
MenuItem[] items = menu_tags.getItems();
for (int i = 0; i < items.length; i++) {
items[i].dispose();
}
TagManager tm = TagManagerFactory.getTagManager();
List<Tag> all_tags = tm.getTagType(TagType.TT_DOWNLOAD_MANUAL).getTags();
all_tags = TagUIUtils.sortTags(all_tags);
if (all_tags.size() > 0) {
Set<String> shared_tags = null;
boolean some_tags_assigned = false;
for (TranscodeFile file : files) {
Set<String> file_tags = new HashSet<>();
file_tags.addAll(Arrays.asList(file.getTags(true)));
if (file_tags.size() > 0) {
some_tags_assigned = true;
}
if (shared_tags == null) {
shared_tags = file_tags;
} else {
if (shared_tags.size() != file_tags.size()) {
shared_tags.clear();
break;
} else {
if (!shared_tags.equals(file_tags)) {
shared_tags.clear();
break;
}
}
}
}
if (some_tags_assigned) {
final MenuItem mi_no_tag = new MenuItem(menu_tags, SWT.PUSH);
mi_no_tag.setText(MessageText.getString("label.no.tag"));
mi_no_tag.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
for (TranscodeFile file : files) {
file.setTags(new String[0]);
}
}
});
new MenuItem(menu_tags, SWT.SEPARATOR);
}
List<String> menu_names = new ArrayList<>();
Map<String, Tag> menu_name_map = new IdentityHashMap<>();
for (Tag t : all_tags) {
if (!t.isTagAuto()[0]) {
String name = t.getTagName(true);
menu_names.add(name);
menu_name_map.put(name, t);
}
}
List<Object> menu_structure = MenuBuildUtils.splitLongMenuListIntoHierarchy(menu_names, TagUIUtils.MAX_TOP_LEVEL_TAGS_IN_MENU);
for (Object obj : menu_structure) {
List<Tag> bucket_tags = new ArrayList<>();
Menu parent_menu;
if (obj instanceof String) {
parent_menu = menu_tags;
bucket_tags.add(menu_name_map.get((String) obj));
} else {
Object[] entry = (Object[]) obj;
List<String> tag_names = (List<String>) entry[1];
boolean sub_all_selected = true;
boolean sub_some_selected = false;
for (String name : tag_names) {
Tag sub_tag = menu_name_map.get(name);
if (shared_tags != null && shared_tags.contains(name)) {
sub_some_selected = true;
} else {
sub_all_selected = false;
}
bucket_tags.add(sub_tag);
}
String mod;
if (sub_all_selected) {
mod = " (*)";
} else if (sub_some_selected) {
mod = " (+)";
} else {
mod = "";
}
Menu menu_bucket = new Menu(menu_tags.getShell(), SWT.DROP_DOWN);
MenuItem bucket_item = new MenuItem(menu_tags, SWT.CASCADE);
bucket_item.setText((String) entry[0] + mod);
bucket_item.setMenu(menu_bucket);
parent_menu = menu_bucket;
}
for (final Tag t : bucket_tags) {
final MenuItem t_i = new MenuItem(parent_menu, SWT.CHECK);
String tag_name = t.getTagName(true);
t_i.setText(tag_name);
boolean selected = shared_tags != null && shared_tags.contains(tag_name);
t_i.setSelection(selected);
t_i.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
boolean selected = t_i.getSelection();
String tag_uid = String.valueOf(t.getTagUID());
for (TranscodeFile file : files) {
Set<String> uids = new TreeSet<>();
uids.addAll(Arrays.asList(file.getTags(false)));
boolean update = false;
if (selected) {
if (!uids.contains(tag_uid)) {
uids.add(tag_uid);
update = true;
}
} else {
if (uids.contains(tag_uid)) {
uids.remove(tag_uid);
update = true;
}
}
if (update) {
file.setTags(uids.toArray(new String[uids.size()]));
}
}
}
});
}
}
}
new MenuItem(menu_tags, SWT.SEPARATOR);
MenuItem item_create = new MenuItem(menu_tags, SWT.PUSH);
Messages.setLanguageText(item_create, "label.add.tag");
item_create.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
TagUIUtilsV3.showCreateTagDialog(new UIFunctions.TagReturner() {
@Override
public void returnedTags(Tag[] tags) {
if (tags != null) {
for (Tag new_tag : tags) {
if (new_tag != null) {
String[] tagUIDs = new String[] { String.valueOf(new_tag.getTagUID()) };
for (TranscodeFile file : files) {
file.setTags(tagUIDs);
}
COConfigurationManager.setParameter("Library.TagInSideBar", true);
}
}
}
}
});
}
});
}
use of com.biglybt.core.tag.TagManager in project BiglyBT by BiglySoftware.
the class ShareHosterPlugin method addDownload.
private Download addDownload(ShareResource resource, final Torrent torrent, File torrent_file, File data_file) throws DownloadException {
Map<String, String> properties = resource.getProperties();
final List<String> networks = new ArrayList<>();
final List<Tag> tags = new ArrayList<>();
boolean force_networks = false;
if (!COConfigurationManager.getBooleanParameter("Sharing Network Selection Global")) {
force_networks = true;
for (String net : AENetworkClassifier.AT_NETWORKS) {
String config_name = "Sharing Network Selection Default." + net;
if (COConfigurationManager.getBooleanParameter(config_name)) {
networks.add(net);
}
}
}
if (properties != null) {
String nets = properties.get(ShareManager.PR_NETWORKS);
if (nets != null) {
force_networks = true;
networks.clear();
String[] bits = nets.split(",");
for (String bit : bits) {
bit = AENetworkClassifier.internalise(bit.trim());
if (bit != null) {
networks.add(bit);
}
}
}
String tags_str = properties.get(ShareManager.PR_TAGS);
if (tags_str != null) {
String[] bits = tags_str.split(",");
TagManager tm = TagManagerFactory.getTagManager();
for (String bit : bits) {
try {
long tag_uid = Long.parseLong(bit.trim());
Tag tag = tm.lookupTagByUID(tag_uid);
if (tag != null) {
tags.add(tag);
}
} catch (Throwable e) {
Debug.out(e);
}
}
}
}
DownloadWillBeAddedListener dwbal = null;
if (networks.size() > 0 || force_networks) {
dwbal = new DownloadWillBeAddedListener() {
@Override
public void initialised(Download download) {
if (Arrays.equals(download.getTorrentHash(), torrent.getHash())) {
PluginCoreUtils.unwrap(download).getDownloadState().setNetworks(networks.toArray(new String[networks.size()]));
}
}
};
download_manager.addDownloadWillBeAddedListener(dwbal);
}
try {
Download download;
if (resource.isPersistent()) {
DownloadStub stub = download_manager.lookupDownloadStub(torrent.getHash());
if (stub != null) {
return (null);
}
try {
torrent.setComplete(data_file);
} catch (Throwable e) {
Debug.out(e);
}
download = download_manager.addDownload(torrent, torrent_file, data_file);
} else {
download = download_manager.addNonPersistentDownload(torrent, torrent_file, data_file);
}
if (tags.size() > 0) {
com.biglybt.core.download.DownloadManager dm = PluginCoreUtils.unwrap(download);
for (Tag tag : tags) {
tag.addTaggable(dm);
}
}
return (download);
} finally {
if (dwbal != null) {
download_manager.removeDownloadWillBeAddedListener(dwbal);
}
}
}
use of com.biglybt.core.tag.TagManager in project BiglyBT by BiglySoftware.
the class ConfigSectionStartShutdown method configSectionCreate.
@Override
public Composite configSectionCreate(final Composite parent) {
GridData gridData;
GridLayout layout;
Label label;
final Composite cDisplay = new Composite(parent, SWT.NULL);
gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
Utils.setLayoutData(cDisplay, gridData);
layout = new GridLayout();
layout.numColumns = 1;
layout.marginWidth = 0;
layout.marginHeight = 0;
cDisplay.setLayout(layout);
final PlatformManager platform = PlatformManagerFactory.getPlatformManager();
int userMode = COConfigurationManager.getIntParameter("User Mode");
// ***** start group
boolean can_ral = platform.hasCapability(PlatformManagerCapabilities.RunAtLogin);
if (can_ral || userMode > 0) {
Group gStartStop = new Group(cDisplay, SWT.NULL);
Messages.setLanguageText(gStartStop, "ConfigView.label.start");
layout = new GridLayout(2, false);
gStartStop.setLayout(layout);
Utils.setLayoutData(gStartStop, new GridData(GridData.FILL_HORIZONTAL));
if (can_ral) {
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter start_on_login = new BooleanParameter(gStartStop, "Start On Login", "ConfigView.label.start.onlogin");
try {
start_on_login.setSelected(platform.getRunAtLogin());
start_on_login.addChangeListener(new ParameterChangeAdapter() {
@Override
public void booleanParameterChanging(Parameter p, boolean toValue) {
try {
platform.setRunAtLogin(toValue);
} catch (Throwable e) {
Debug.out(e);
}
}
});
} catch (Throwable e) {
start_on_login.setEnabled(false);
Debug.out(e);
}
start_on_login.setLayoutData(gridData);
}
if (userMode > 0) {
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter start_in_lr_mode = new BooleanParameter(gStartStop, "Start In Low Resource Mode", "ConfigView.label.start.inlrm");
start_in_lr_mode.setLayoutData(gridData);
Composite lr_comp = new Composite(gStartStop, SWT.NULL);
gridData = new GridData();
gridData.horizontalSpan = 2;
gridData.horizontalIndent = 20;
Utils.setLayoutData(lr_comp, gridData);
layout = new GridLayout(3, false);
lr_comp.setLayout(layout);
BooleanParameter lr_ui = new BooleanParameter(lr_comp, "LRMS UI", "lrms.deactivate.ui");
BooleanParameter lr_udp_net = new BooleanParameter(lr_comp, "LRMS UDP Peers", "lrms.udp.peers");
BooleanParameter lr_dht_sleep = new BooleanParameter(lr_comp, "LRMS DHT Sleep", "lrms.dht.sleep");
// start_in_lr_mode.setAdditionalActionPerformer( new ChangeSelectionActionPerformer( lr_ui ));
// this must always be selected as it is coming out of the deactivated UI mode that enable the others as well
lr_ui.setEnabled(false);
start_in_lr_mode.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(lr_udp_net));
start_in_lr_mode.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(lr_dht_sleep));
}
}
if (platform.hasCapability(PlatformManagerCapabilities.PreventComputerSleep)) {
Group gSleep = new Group(cDisplay, SWT.NULL);
Messages.setLanguageText(gSleep, "ConfigView.label.sleep");
layout = new GridLayout(2, false);
gSleep.setLayout(layout);
Utils.setLayoutData(gSleep, new GridData(GridData.FILL_HORIZONTAL));
gridData = new GridData();
gridData.horizontalSpan = 2;
label = new Label(gSleep, SWT.NULL);
Messages.setLanguageText(label, "ConfigView.label.sleep.info");
Utils.setLayoutData(label, gridData);
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter no_sleep_dl = new BooleanParameter(gSleep, "Prevent Sleep Downloading", "ConfigView.label.sleep.download");
no_sleep_dl.setLayoutData(gridData);
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter no_sleep_se = new BooleanParameter(gSleep, "Prevent Sleep FP Seeding", "ConfigView.label.sleep.fpseed");
no_sleep_se.setLayoutData(gridData);
TagManager tm = TagManagerFactory.getTagManager();
if (tm.isEnabled()) {
List<Tag> tag_list = tm.getTagType(TagType.TT_DOWNLOAD_MANUAL).getTags();
String[] tags = new String[tag_list.size() + 1];
tags[0] = "";
for (int i = 0; i < tag_list.size(); i++) {
tags[i + 1] = tag_list.get(i).getTagName(true);
}
label = new Label(gSleep, SWT.NULL);
Messages.setLanguageText(label, "ConfigView.label.sleep.tag");
new StringListParameter(gSleep, "Prevent Sleep Tag", "", tags, tags);
}
}
if (userMode > 0) {
Group gPR = new Group(cDisplay, SWT.NULL);
Messages.setLanguageText(gPR, "ConfigView.label.pauseresume");
layout = new GridLayout(2, false);
gPR.setLayout(layout);
Utils.setLayoutData(gPR, new GridData(GridData.FILL_HORIZONTAL));
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter pauseOnExit = new BooleanParameter(gPR, "Pause Downloads On Exit", "ConfigView.label.pause.downloads.on.exit");
pauseOnExit.setLayoutData(gridData);
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter resumeOnStart = new BooleanParameter(gPR, "Resume Downloads On Start", "ConfigView.label.resume.downloads.on.start");
resumeOnStart.setLayoutData(gridData);
}
if (userMode >= 0) {
Group gStop = new Group(cDisplay, SWT.NULL);
Messages.setLanguageText(gStop, "ConfigView.label.stop");
layout = new GridLayout(5, false);
gStop.setLayout(layout);
Utils.setLayoutData(gStop, new GridData(GridData.FILL_HORIZONTAL));
// done downloading
addDoneDownloadingOption(gStop, true);
// done seeding
addDoneSeedingOption(gStop, true);
// reset on trigger
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter resetOnTrigger = new BooleanParameter(gStop, "Stop Triggers Auto Reset", "!" + MessageText.getString("ConfigView.label.stop.autoreset", new String[] { MessageText.getString("ConfigView.label.stop.Nothing") }) + "!");
resetOnTrigger.setLayoutData(gridData);
// prompt to allow abort
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter enablePrompt = new BooleanParameter(gStop, "Prompt To Abort Shutdown", "ConfigView.label.prompt.abort");
enablePrompt.setLayoutData(gridData);
}
if (userMode > 0) {
Group gRestart = new Group(cDisplay, SWT.NULL);
Messages.setLanguageText(gRestart, "label.restart");
layout = new GridLayout(2, false);
gRestart.setLayout(layout);
Utils.setLayoutData(gRestart, new GridData(GridData.FILL_HORIZONTAL));
label = new Label(gRestart, SWT.NULL);
Messages.setLanguageText(label, "ConfigView.label.restart.auto");
new IntParameter(gRestart, "Auto Restart When Idle", 0, 100000);
}
if (userMode > 0 && platform.hasCapability(PlatformManagerCapabilities.AccessExplicitVMOptions)) {
Group gJVM = new Group(cDisplay, SWT.NULL);
Messages.setLanguageText(gJVM, "ConfigView.label.jvm");
layout = new GridLayout(2, false);
gJVM.setLayout(layout);
Utils.setLayoutData(gJVM, new GridData(GridData.FILL_HORIZONTAL));
// wiki link
gridData = new GridData();
gridData.horizontalSpan = 2;
LinkLabel link = new LinkLabel(gJVM, gridData, "ConfigView.label.please.visit.here", Constants.URL_WIKI + "w/Java_VM_memory_usage");
// info
label = new Label(gJVM, SWT.NULL);
Messages.setLanguageText(label, "jvm.info");
gridData = new GridData();
gridData.horizontalSpan = 2;
Utils.setLayoutData(label, gridData);
try {
final File option_file = platform.getVMOptionFile();
final Group gJVMOptions = new Group(gJVM, SWT.NULL);
layout = new GridLayout(3, false);
gJVMOptions.setLayout(layout);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
Utils.setLayoutData(gJVMOptions, gridData);
buildOptions(cDisplay, platform, gJVMOptions, false);
// show option file
label = new Label(gJVM, SWT.NULL);
Messages.setLanguageText(label, "jvm.show.file", new String[] { option_file.getAbsolutePath() });
Button show_folder_button = new Button(gJVM, SWT.PUSH);
Messages.setLanguageText(show_folder_button, "MyTorrentsView.menu.explore");
show_folder_button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ManagerUtils.open(option_file);
}
});
label = new Label(gJVM, SWT.NULL);
Messages.setLanguageText(label, "jvm.reset");
Button reset_button = new Button(gJVM, SWT.PUSH);
Messages.setLanguageText(reset_button, "Button.reset");
reset_button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
try {
platform.setExplicitVMOptions(new String[0]);
buildOptions(cDisplay, platform, gJVMOptions, true);
} catch (Throwable e) {
Debug.out(e);
}
}
});
} catch (Throwable e) {
Debug.out(e);
label = new Label(gJVM, SWT.NULL);
Messages.setLanguageText(label, "jvm.error", new String[] { Debug.getNestedExceptionMessage(e) });
gridData = new GridData();
gridData.horizontalSpan = 2;
Utils.setLayoutData(label, gridData);
}
}
return cDisplay;
}
Aggregations