use of com.biglybt.core.tag.TagFeatureProperties.TagProperty in project BiglyBT by BiglySoftware.
the class StartStopRulesDefaultPlugin method reloadConfigParams.
private void reloadConfigParams() {
try {
this_mon.enter();
int iNewRankType = plugin_config.getUnsafeIntParameter("StartStopManager_iRankType");
minSpeedForActiveSeeding = plugin_config.getUnsafeIntParameter("StartStopManager_iMinSpeedForActiveSeeding");
maxStalledSeeding = plugin_config.getUnsafeIntParameter("StartStopManager_iMaxStalledSeeding");
if (maxStalledSeeding <= 0) {
// insanity :)
maxStalledSeeding = 999;
}
stalledSeedingIgnoreZP = plugin_config.getUnsafeBooleanParameter("StartStopManager_bMaxStalledSeedingIgnoreZP");
_maxActive = plugin_config.getUnsafeIntParameter("max active torrents");
_maxActiveWhenSeedingEnabled = plugin_config.getUnsafeBooleanParameter("StartStopManager_bMaxActiveTorrentsWhenSeedingEnabled");
_maxActiveWhenSeeding = plugin_config.getUnsafeIntParameter("StartStopManager_iMaxActiveTorrentsWhenSeeding");
maxConfiguredDownloads = plugin_config.getUnsafeIntParameter("max downloads");
boolean min_eq_max = plugin_config.getUnsafeBooleanParameter("StartStopManager_bMaxMinDLLinked");
if (min_eq_max) {
minDownloads = maxConfiguredDownloads;
} else {
minDownloads = plugin_config.getUnsafeIntParameter("min downloads");
}
bMaxDownloadIgnoreChecking = plugin_config.getUnsafeBooleanParameter("StartStopManager_bMaxDownloadIgnoreChecking");
numPeersAsFullCopy = plugin_config.getUnsafeIntParameter("StartStopManager_iNumPeersAsFullCopy");
iFakeFullCopySeedStart = plugin_config.getUnsafeIntParameter("StartStopManager_iFakeFullCopySeedStart");
bAutoReposition = plugin_config.getUnsafeBooleanParameter("StartStopManager_bAutoReposition");
minTimeAlive = plugin_config.getUnsafeIntParameter("StartStopManager_iMinSeedingTime") * 1000;
bDebugLog = plugin_config.getUnsafeBooleanParameter("StartStopManager_bDebugLog");
bAutoStart0Peers = plugin_config.getUnsafeBooleanParameter("StartStopManager_bAutoStart0Peers");
globalDownloadLimit = plugin_config.getUnsafeIntParameter("Max Download Speed KBs", 0);
globalUploadLimit = plugin_config.getUnsafeIntParameter("Max Upload Speed KBs", 0);
globalUploadWhenSeedingLimit = plugin_config.getUnsafeBooleanParameter("enable.seedingonly.upload.rate") ? plugin_config.getUnsafeIntParameter("Max Upload Speed Seeding KBs", 0) : globalUploadLimit;
bStopOnceBandwidthMet = plugin_config.getUnsafeBooleanParameter("StartStopManager_bStopOnceBandwidthMet");
bStartNoMoreSeedsWhenUpLimitMet = plugin_config.getUnsafeBooleanParameter("StartStopManager_bStartNoMoreSeedsWhenUpLimitMet");
bStartNoMoreSeedsWhenUpLimitMetPercent = plugin_config.getUnsafeBooleanParameter("StartStopManager_bStartNoMoreSeedsWhenUpLimitMetPercent");
bStartNoMoreSeedsWhenUpLimitMetSlack = plugin_config.getUnsafeIntParameter("StartStopManager_bStartNoMoreSeedsWhenUpLimitMetSlack");
boolean move_top = plugin_config.getUnsafeBooleanParameter("StartStopManager_bNewSeedsMoveTop");
plugin_config.setCoreBooleanParameter(PluginConfig.CORE_PARAM_BOOLEAN_NEW_SEEDS_START_AT_TOP, move_top);
if (iNewRankType != iRankType) {
iRankType = iNewRankType;
// shorten recalc for timed rank type, since the calculation is fast and we want to stop on the second
if (iRankType == RANK_TIMED) {
if (recalcSeedingRanksTask == null) {
recalcAllSeedingRanks(false);
recalcSeedingRanksTask = new RecalcSeedingRanksTask();
SimpleTimer.addPeriodicEvent("StartStop:recalcSR", 1000, recalcSeedingRanksTask);
}
} else if (recalcSeedingRanksTask != null) {
recalcSeedingRanksTask.cancel();
recalcSeedingRanksTask = null;
}
}
iDownloadSortType = plugin_config.getUnsafeIntParameter("StartStopManager_Downloading_iSortType", -1);
// migrate from old boolean setting
if (iDownloadSortType == -1) {
boolean bDownloadAutoReposition = plugin_config.getUnsafeBooleanParameter("StartStopManager_Downloading_bAutoReposition");
iDownloadSortType = bDownloadAutoReposition ? DefaultRankCalculator.DOWNLOAD_ORDER_SPEED : DefaultRankCalculator.DOWNLOAD_ORDER_INDEX;
plugin_config.setCoreIntParameter("StartStopManager_Downloading_iSortType", iDownloadSortType);
}
iDownloadTestTimeMillis = plugin_config.getUnsafeIntParameter("StartStopManager_Downloading_iTestTimeSecs") * 1000;
iDownloadReTestMillis = plugin_config.getUnsafeIntParameter("StartStopManager_Downloading_iRetestTimeMins") * 60 * 1000;
bTagFirstPriority = plugin_config.getUnsafeBooleanParameter("StartStopManager_bTagFirstPriority");
if (bTagFirstPriority) {
TagManager tag_manager = TagManagerFactory.getTagManager();
if (tag_manager != null && tag_manager.isEnabled()) {
TagType tt = tag_manager.getTagType(TagType.TT_DOWNLOAD_MANUAL);
if (fp_tag == null) {
fp_tag = tt.getTag("First Priority", true);
if (fp_tag == null) {
try {
fp_tag = tt.createTag("First Priority", true);
} catch (Throwable e) {
Debug.out(e);
}
}
}
Tag not_fp_tag = tt.getTag("Not First Priority", true);
if (not_fp_tag == null) {
try {
not_fp_tag = tt.createTag("Not First Priority", true);
} catch (Throwable e) {
Debug.out(e);
}
}
if (not_fp_tag != null) {
TagProperty constraint = ((TagFeatureProperties) not_fp_tag).getProperty(TagFeatureProperties.PR_CONSTRAINT);
constraint.setStringList(new String[] { "isComplete() && !hasTag( \"First Priority\" )" });
}
}
}
/*
// limit _maxActive and maxDownloads based on TheColonel's specs
// maxActive = max_upload_speed / (slots_per_torrent * min_speed_per_peer)
if (_maxActive > 0) {
int iSlotsPerTorrent = plugin_config.getUnsafeIntParameter("Max Uploads");
// TODO: Track upload speed, storing the max upload speed over a minute
// and use that for "unlimited" setting, or huge settings (like 200)
if (iSlotsPerTorrent > 0) {
int iMinSpeedPerPeer = 3; // for now. TODO: config value
int _maxActiveLimit = iMaxUploadSpeed / (iSlotsPerTorrent * iMinSpeedPerPeer);
if (_maxActive > _maxActiveLimit) {
_maxActive = _maxActiveLimit;
plugin_config.setCoreIntParameter(PluginConfig.CORE_PARAM_INT_MAX_ACTIVE, _maxActive);
}
}
if (maxDownloads > _maxActive) {
maxDownloads = _maxActive;
plugin_config.setCoreIntParameter(PluginConfig.CORE_PARAM_INT_MAX_DOWNLOADS, maxDownloads);
}
}
*/
// force a recalc on all downloads by setting SR to 0, scheduling
// a recalc on next process, and requsting a process cycle
Collection<DefaultRankCalculator> allDownloads = downloadDataMap.values();
DefaultRankCalculator[] dlDataArray = allDownloads.toArray(new DefaultRankCalculator[0]);
for (int i = 0; i < dlDataArray.length; i++) {
dlDataArray[i].getDownloadObject().setSeedingRank(0);
}
try {
ranksToRecalc_mon.enter();
synchronized (downloadDataMap) {
ranksToRecalc.addAll(allDownloads);
}
} finally {
ranksToRecalc_mon.exit();
}
requestProcessCycle(null);
if (bDebugLog) {
log.log(LoggerChannel.LT_INFORMATION, "somethingChanged: config reload");
try {
if (debugMenuItem == null) {
final String DEBUG_MENU_ID = "StartStopRules.menu.viewDebug";
MenuItemListener menuListener = new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
if (!(target instanceof TableRow))
return;
TableRow tr = (TableRow) target;
Object ds = tr.getDataSource();
if (!(ds instanceof Download))
return;
DefaultRankCalculator dlData = downloadDataMap.get(ds);
if (dlData != null) {
if (swt_ui != null)
swt_ui.openDebugWindow(dlData);
else
pi.getUIManager().showTextMessage(null, null, "FP:\n" + dlData.sExplainFP + "\n" + "SR:" + dlData.sExplainSR + "\n" + "TRACE:\n" + dlData.sTrace);
}
}
};
TableManager tm = pi.getUIManager().getTableManager();
debugMenuItem = tm.addContextMenuItem(TableManager.TABLE_MYTORRENTS_COMPLETE, DEBUG_MENU_ID);
debugMenuItem.setHeaderCategory(MenuItem.HEADER_CONTROL);
debugMenuItem.addListener(menuListener);
debugMenuItem = tm.addContextMenuItem(TableManager.TABLE_MYTORRENTS_INCOMPLETE, DEBUG_MENU_ID);
debugMenuItem.setHeaderCategory(MenuItem.HEADER_CONTROL);
debugMenuItem.addListener(menuListener);
}
} catch (Throwable t) {
Debug.printStackTrace(t);
}
}
} finally {
this_mon.exit();
}
}
use of com.biglybt.core.tag.TagFeatureProperties.TagProperty in project BiglyBT by BiglySoftware.
the class TagWithState method exportDetails.
protected void exportDetails(VuzeFile vf, Map map, boolean do_contents) {
exportDetails(map, do_contents);
if (getTagType().hasTagTypeFeature(TagFeature.TF_PROPERTIES)) {
TagFeatureProperties tfp = (TagFeatureProperties) this;
TagProperty prop = tfp.getProperty(TagFeatureProperties.PR_TRACKER_TEMPLATES);
if (prop != null) {
String[] bits = prop.getStringList();
if (bits == null || bits.length == 0) {
return;
}
Map<String, List<List<String>>> templates = TrackersUtil.getInstance().getMultiTrackers();
for (String bit : bits) {
String[] temp = bit.split(":");
String t_name = temp[1];
List<List<String>> template_trackers = templates.get(t_name);
if (template_trackers != null) {
Map tt_map = new HashMap();
tt_map.put("name", t_name);
tt_map.put("template", template_trackers);
vf.addComponent(VuzeFileComponent.COMP_TYPE_TRACKER_TEMPLATE, tt_map);
}
}
}
}
}
use of com.biglybt.core.tag.TagFeatureProperties.TagProperty in project BiglyBT by BiglySoftware.
the class TagUIUtils method setupSideBarMenus.
public static void setupSideBarMenus(final MenuManager menuManager) {
com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem("sidebar." + MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, "ConfigView.section.style.TagInSidebar");
menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_CHECK);
menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
boolean b = COConfigurationManager.getBooleanParameter("Library.TagInSideBar");
COConfigurationManager.setParameter("Library.TagInSideBar", !b);
}
});
menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {
@Override
public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
menu.setData(Boolean.valueOf(COConfigurationManager.getBooleanParameter("Library.TagInSideBar")));
}
});
// tag options
menuItem = menuManager.addMenuItem("sidebar." + MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, "label.tags");
menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {
@Override
public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
menu.removeAllChildItems();
// manual
final TagType manual_tt = TagManagerFactory.getTagManager().getTagType(TagType.TT_DOWNLOAD_MANUAL);
com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem(menu, manual_tt.getTagTypeName(false));
menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {
@Override
public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
menu.removeAllChildItems();
final List<Tag> all_tags = manual_tt.getTags();
List<String> menu_names = new ArrayList<>();
Map<String, Tag> menu_name_map = new IdentityHashMap<>();
boolean all_visible = true;
boolean all_invisible = true;
boolean has_ut = false;
for (Tag t : all_tags) {
String name = t.getTagName(true);
menu_names.add(name);
menu_name_map.put(name, t);
if (t.isVisible()) {
all_invisible = false;
} else {
all_visible = false;
}
TagFeatureProperties props = (TagFeatureProperties) t;
TagProperty prop = props.getProperty(TagFeatureProperties.PR_UNTAGGED);
if (prop != null) {
Boolean b = prop.getBoolean();
if (b != null && b) {
has_ut = true;
}
}
}
com.biglybt.pif.ui.menus.MenuItem showAllItem = menuManager.addMenuItem(menu, "label.show.all");
showAllItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
showAllItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
for (Tag t : all_tags) {
t.setVisible(true);
}
}
});
com.biglybt.pif.ui.menus.MenuItem hideAllItem = menuManager.addMenuItem(menu, "popup.error.hideall");
hideAllItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
hideAllItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
for (Tag t : all_tags) {
t.setVisible(false);
}
}
});
com.biglybt.pif.ui.menus.MenuItem sepItem = menuManager.addMenuItem(menu, "sepm");
sepItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
showAllItem.setEnabled(!all_visible);
hideAllItem.setEnabled(!all_invisible);
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<>();
com.biglybt.pif.ui.menus.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 sub_all_visible = true;
boolean sub_some_visible = false;
for (String name : tag_names) {
Tag tag = menu_name_map.get(name);
if (tag.isVisible()) {
sub_some_visible = true;
} else {
sub_all_visible = false;
}
bucket_tags.add(tag);
}
String mod;
if (sub_all_visible) {
mod = " (*)";
} else if (sub_some_visible) {
mod = " (+)";
} else {
mod = "";
}
parent_menu = menuManager.addMenuItem(menu, "!" + (String) entry[0] + mod + "!");
parent_menu.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
}
for (final Tag tag : bucket_tags) {
com.biglybt.pif.ui.menus.MenuItem m = menuManager.addMenuItem(parent_menu, tag.getTagName(false));
m.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_CHECK);
m.setData(Boolean.valueOf(tag.isVisible()));
m.addListener(new MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
tag.setVisible(!tag.isVisible());
}
});
}
}
if (!has_ut) {
sepItem = menuManager.addMenuItem(menu, "sepu");
sepItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
com.biglybt.pif.ui.menus.MenuItem m = menuManager.addMenuItem(menu, "label.untagged");
m.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
m.addListener(new MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
try {
String tag_name = MessageText.getString("label.untagged");
Tag ut_tag = manual_tt.getTag(tag_name, true);
if (ut_tag == null) {
ut_tag = manual_tt.createTag(tag_name, true);
}
TagFeatureProperties tp = (TagFeatureProperties) ut_tag;
tp.getProperty(TagFeatureProperties.PR_UNTAGGED).setBoolean(true);
} catch (TagException e) {
Debug.out(e);
}
}
});
}
}
});
menuItem = menuManager.addMenuItem(menu, "label.add.tag");
menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
createManualTag(null);
}
});
com.biglybt.pif.ui.menus.MenuItem sepItem = menuManager.addMenuItem(menu, "sep1");
sepItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
// auto
menuItem = menuManager.addMenuItem(menu, "wizard.maketorrent.auto");
menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {
@Override
public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
menu.removeAllChildItems();
// autos
List<TagType> tag_types = TagManagerFactory.getTagManager().getTagTypes();
for (final TagType tag_type : tag_types) {
if (tag_type.getTagType() == TagType.TT_DOWNLOAD_CATEGORY) {
continue;
}
if (!tag_type.isTagTypeAuto()) {
continue;
}
if (tag_type.getTags().size() == 0) {
continue;
}
com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem(menu, tag_type.getTagTypeName(false));
menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {
@Override
public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
menu.removeAllChildItems();
final List<Tag> tags = tag_type.getTags();
com.biglybt.pif.ui.menus.MenuItem showAllItem = menuManager.addMenuItem(menu, "label.show.all");
showAllItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
showAllItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
for (Tag t : tags) {
t.setVisible(true);
}
}
});
com.biglybt.pif.ui.menus.MenuItem hideAllItem = menuManager.addMenuItem(menu, "popup.error.hideall");
hideAllItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
hideAllItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
for (Tag t : tags) {
t.setVisible(false);
}
}
});
boolean all_visible = true;
boolean all_invisible = true;
for (Tag t : tags) {
if (t.isVisible()) {
all_invisible = false;
} else {
all_visible = false;
}
}
showAllItem.setEnabled(!all_visible);
hideAllItem.setEnabled(!all_invisible);
com.biglybt.pif.ui.menus.MenuItem sepItem = menuManager.addMenuItem(menu, "sep2");
sepItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
for (final Tag t : tags) {
com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem(menu, t.getTagName(false));
menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_CHECK);
menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
t.setVisible(menu.isSelected());
}
});
menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {
@Override
public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
menu.setData(t.isVisible());
}
});
}
}
});
}
}
});
sepItem = menuManager.addMenuItem(menu, "sep3");
sepItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
menuItem = menuManager.addMenuItem(menu, "tag.show.stats");
menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
uiFunctions.getMDI().showEntryByID(StatsView.VIEW_ID, "TagStatsView");
}
});
menuItem = menuManager.addMenuItem(menu, "tag.show.overview");
menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TAGS);
}
});
}
});
CoreFactory.addCoreRunningListener(new CoreRunningListener() {
@Override
public void coreRunning(Core core) {
checkTagSharing(true);
}
});
}
use of com.biglybt.core.tag.TagFeatureProperties.TagProperty in project BiglyBT by BiglySoftware.
the class TagSettingsView method swt_initialize.
private void swt_initialize(Composite parent) {
if (cMainComposite == null || cMainComposite.isDisposed()) {
if (parent == null || parent.isDisposed()) {
return;
}
sc = new ScrolledComposite(parent, SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.getVerticalBar().setIncrement(16);
Layout parentLayout = parent.getLayout();
if (parentLayout instanceof GridLayout) {
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
Utils.setLayoutData(sc, gd);
} else if (parentLayout instanceof FormLayout) {
Utils.setLayoutData(sc, Utils.getFilledFormData());
}
cMainComposite = new Composite(sc, SWT.NONE);
sc.setContent(cMainComposite);
} else {
Utils.disposeComposite(cMainComposite, false);
}
if (tags == null) {
params = null;
cMainComposite.setLayout(new FillLayout());
Label label = new Label(cMainComposite, SWT.NONE);
label.setText(MessageText.getString("tag.settings.select.tag"));
} else {
final int numTags = tags.length;
int isTagVisible = -1;
int canBePublic = -1;
int[] tagColor = tags[0].getColor();
boolean tagsAreTagFeatureRateLimit = true;
Set<String> listTagTypes = new HashSet<>();
for (Tag tag : tags) {
TagType tt = tag.getTagType();
String s = tt.getTagTypeName(true);
listTagTypes.add(s);
if (tagsAreTagFeatureRateLimit && !(tag instanceof TagFeatureRateLimit)) {
tagsAreTagFeatureRateLimit = false;
}
isTagVisible = updateIntBoolean(tag.isVisible(), isTagVisible);
canBePublic = updateIntBoolean(tag.canBePublic(), canBePublic);
if (tagColor != null) {
int[] color = tag.getColor();
if (!Arrays.areEqual(tagColor, color)) {
tagColor = null;
}
}
}
String tagTypes = GeneralUtils.stringJoin(listTagTypes, ", ");
params = new Params();
GridData gd;
GridLayout gridLayout;
gridLayout = new GridLayout(1, false);
gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0;
gridLayout.marginHeight = gridLayout.marginWidth = 0;
cMainComposite.setLayout(gridLayout);
Composite cSection1 = new Composite(cMainComposite, SWT.NONE);
gridLayout = new GridLayout(4, false);
gridLayout.marginHeight = 0;
cSection1.setLayout(gridLayout);
gd = new GridData(SWT.FILL, SWT.FILL, true, false);
cSection1.setLayoutData(gd);
Composite cSection2 = new Composite(cMainComposite, SWT.NONE);
gridLayout = new GridLayout(4, false);
cSection2.setLayout(gridLayout);
gd = new GridData(SWT.FILL, SWT.FILL, true, false);
cSection2.setLayoutData(gd);
Label label;
// Field: Tag Type
label = new Label(cSection1, SWT.NONE);
FontUtils.setFontHeight(label, 12, SWT.BOLD);
gd = new GridData();
gd.horizontalSpan = 4;
Utils.setLayoutData(label, gd);
label.setText(tagTypes);
// Field: Name
label = new Label(cSection1, SWT.NONE);
Messages.setLanguageText(label, "MinimizedWindow.name");
gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
Utils.setLayoutData(label, gd);
if (numTags == 1 && !tags[0].getTagType().isTagTypeAuto()) {
Text txtName = new Text(cSection1, SWT.BORDER);
params.cName = txtName;
gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
Utils.setLayoutData(txtName, gd);
txtName.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
try {
String newName = ((Text) e.widget).getText();
if (!tags[0].getTagName(true).equals(newName)) {
tags[0].setTagName(newName);
}
} catch (TagException e1) {
Debug.out(e1);
}
}
});
} else {
label = new Label(cSection1, SWT.WRAP);
gd = Utils.getWrappableLabelGridData(1, GridData.GRAB_HORIZONTAL);
Utils.setLayoutData(label, gd);
params.cName = label;
}
// Field: Color
label = new Label(cSection1, SWT.NONE);
Messages.setLanguageText(label, "label.color");
if (tagColor == null) {
tagColor = new int[] { 0, 0, 0 };
}
params.tagColor = new ColorParameter(cSection1, null, tagColor[0], tagColor[1], tagColor[2]) {
// @see com.biglybt.ui.swt.config.ColorParameter#newColorChosen(org.eclipse.swt.graphics.RGB)
@Override
public void newColorChosen(RGB newColor) {
for (Tag tag : tags) {
tag.setColor(new int[] { newColor.red, newColor.green, newColor.blue });
}
}
};
// Field: Visible
params.viewInSideBar = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
int isTagVisible = -1;
for (Tag tag : tags) {
isTagVisible = updateIntBoolean(tag.isVisible(), isTagVisible);
}
return isTagVisible == 2 ? null : (isTagVisible == 1);
}
@Override
public void setBooleanValue(String key, boolean value) {
for (Tag tag : tags) {
tag.setVisible(value);
}
}
}, cSection2, null, "TagSettings.viewInSideBar");
gd = new GridData();
gd.horizontalSpan = 4;
params.viewInSideBar.setLayoutData(gd);
// Field: Public
if (canBePublic == 1) {
params.isPublic = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
int val = -1;
for (Tag tag : tags) {
val = updateIntBoolean(tag.isPublic(), val);
}
return val == 2 ? null : (val == 1);
}
@Override
public void setBooleanValue(String key, boolean value) {
for (Tag tag : tags) {
tag.setPublic(value);
}
}
}, cSection2, null, "TagAddWindow.public.checkbox");
gd = new GridData();
gd.horizontalSpan = 4;
params.isPublic.setLayoutData(gd);
}
// //////////////////
Group gTransfer = new Group(cMainComposite, SWT.NONE);
gTransfer.setText(MessageText.getString("label.transfer.settings"));
gridLayout = new GridLayout(6, false);
gTransfer.setLayout(gridLayout);
gd = new GridData(SWT.FILL, SWT.NONE, false, false, 4, 1);
gTransfer.setLayoutData(gd);
if (tagsAreTagFeatureRateLimit) {
final TagFeatureRateLimit[] rls = new TagFeatureRateLimit[tags.length];
System.arraycopy(tags, 0, rls, 0, tags.length);
boolean supportsTagDownloadLimit = true;
boolean supportsTagUploadLimit = true;
boolean hasTagUploadPriority = true;
for (TagFeatureRateLimit rl : rls) {
supportsTagDownloadLimit &= rl.supportsTagDownloadLimit();
supportsTagUploadLimit &= rl.supportsTagUploadLimit();
hasTagUploadPriority &= rl.getTagUploadPriority() >= 0;
}
String k_unit = DisplayFormatters.getRateUnitBase10(DisplayFormatters.UNIT_KB).trim();
int cols_used = 0;
// Field: Download Limit
if (supportsTagDownloadLimit) {
gd = new GridData();
label = new Label(gTransfer, SWT.NULL);
Utils.setLayoutData(label, gd);
label.setText(k_unit + " " + MessageText.getString("GeneralView.label.maxdownloadspeed.tooltip"));
gd = new GridData();
// gd.horizontalSpan = 3;
params.maxDownloadSpeed = new GenericIntParameter(new GenericParameterAdapter() {
@Override
public int getIntValue(String key) {
int limit = rls[0].getTagDownloadLimit();
if (numTags > 1) {
for (int i = 1; i < rls.length; i++) {
int nextLimit = rls[i].getTagDownloadLimit();
if (nextLimit != limit) {
return 0;
}
}
}
return limit < 0 ? limit : limit / DisplayFormatters.getKinB();
}
@Override
public int getIntValue(String key, int def) {
return getIntValue(key);
}
@Override
public void setIntValue(String key, int value) {
for (TagFeatureRateLimit rl : rls) {
if (value == -1) {
rl.setTagDownloadLimit(-1);
} else {
rl.setTagDownloadLimit(value * DisplayFormatters.getKinB());
}
}
}
@Override
public boolean resetIntDefault(String key) {
return false;
}
}, gTransfer, null, -1, Integer.MAX_VALUE);
params.maxDownloadSpeed.setLayoutData(gd);
params.maxDownloadSpeed.setZeroHidden(numTags > 1);
cols_used += 2;
}
// Upload Limit
if (supportsTagUploadLimit) {
gd = new GridData();
label = new Label(gTransfer, SWT.NULL);
Utils.setLayoutData(label, gd);
label.setText(k_unit + " " + MessageText.getString("GeneralView.label.maxuploadspeed.tooltip"));
gd = new GridData();
// gd.horizontalSpan = 3;
params.maxUploadSpeed = new GenericIntParameter(new GenericParameterAdapter() {
@Override
public int getIntValue(String key) {
int limit = rls[0].getTagUploadLimit();
if (numTags > 1) {
for (int i = 1; i < rls.length; i++) {
int nextLimit = rls[i].getTagUploadLimit();
if (nextLimit != limit) {
return 0;
}
}
}
return limit < 0 ? limit : limit / DisplayFormatters.getKinB();
}
@Override
public int getIntValue(String key, int def) {
return getIntValue(key);
}
@Override
public void setIntValue(String key, int value) {
for (TagFeatureRateLimit rl : rls) {
if (value == -1) {
rl.setTagUploadLimit(value);
} else {
rl.setTagUploadLimit(value * DisplayFormatters.getKinB());
}
}
}
@Override
public boolean resetIntDefault(String key) {
return false;
}
}, gTransfer, null, -1, Integer.MAX_VALUE);
params.maxUploadSpeed.setLayoutData(gd);
params.maxUploadSpeed.setZeroHidden(numTags > 1);
cols_used += 2;
}
// Field: Upload Priority
if (hasTagUploadPriority) {
params.uploadPriority = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
int value = -1;
for (TagFeatureRateLimit rl : rls) {
value = updateIntBoolean(rl.getTagUploadPriority() > 0, value);
}
return value == 2 ? null : value == 1;
}
@Override
public void setBooleanValue(String key, boolean value) {
for (TagFeatureRateLimit rl : rls) {
rl.setTagUploadPriority(value ? 1 : 0);
}
}
}, gTransfer, null, "cat.upload.priority");
gd = new GridData();
gd.horizontalSpan = 6 - cols_used;
params.uploadPriority.setLayoutData(gd);
}
// Field: Min Share
if (numTags == 1 && rls[0].getTagMinShareRatio() >= 0) {
label = new Label(gTransfer, SWT.NONE);
Messages.setLanguageText(label, "TableColumn.header.min_sr");
gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
Utils.setLayoutData(label, gd);
params.min_sr = new GenericFloatParameter(new GenericParameterAdapter() {
@Override
public float getFloatValue(String key) {
return rls[0].getTagMinShareRatio() / 1000f;
}
@Override
public void setFloatValue(String key, float value) {
rls[0].setTagMinShareRatio((int) (value * 1000));
}
}, gTransfer, null, 0, Float.MAX_VALUE, true, 3);
gd = new GridData();
// gd.horizontalSpan = 3;
gd.widthHint = 75;
params.min_sr.setLayoutData(gd);
}
// Field: Max Share
if (numTags == 1 && rls[0].getTagMaxShareRatio() >= 0) {
label = new Label(gTransfer, SWT.NONE);
Messages.setLanguageText(label, "TableColumn.header.max_sr");
gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
Utils.setLayoutData(label, gd);
params.max_sr = new GenericFloatParameter(new GenericParameterAdapter() {
@Override
public float getFloatValue(String key) {
return rls[0].getTagMaxShareRatio() / 1000f;
}
@Override
public void setFloatValue(String key, float value) {
rls[0].setTagMaxShareRatio((int) (value * 1000));
updateTagSRParams(params);
}
}, gTransfer, null, 0, Float.MAX_VALUE, true, 3);
gd = new GridData();
// gd.horizontalSpan = 3;
gd.widthHint = 75;
params.max_sr.setLayoutData(gd);
// max sr action
String[] ST_ACTION_VALUES = { "" + TagFeatureRateLimit.SR_ACTION_QUEUE, "" + TagFeatureRateLimit.SR_ACTION_PAUSE, "" + TagFeatureRateLimit.SR_ACTION_STOP };
String[] ST_ACTION_LABELS = { MessageText.getString("ConfigView.section.queue"), MessageText.getString("v3.MainWindow.button.pause"), MessageText.getString("v3.MainWindow.button.stop") };
label = new Label(gTransfer, SWT.NONE);
Messages.setLanguageText(label, "label.when.exceeded");
gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
Utils.setLayoutData(label, gd);
params.max_sr_action = new GenericStringListParameter(new GenericParameterAdapter() {
@Override
public String getStringListValue(String key, String def) {
return (getStringListValue(key));
}
@Override
public String getStringListValue(String key) {
return ("" + rls[0].getTagMaxShareRatioAction());
}
@Override
public void setStringListValue(String key, String value) {
rls[0].setTagMaxShareRatioAction(Integer.parseInt(value));
}
}, gTransfer, "max_sr_action", "" + TagFeatureRateLimit.SR_INDIVIDUAL_ACTION_DEFAULT, ST_ACTION_LABELS, ST_ACTION_VALUES);
}
// Field: Max Aggregate Share
if (numTags == 1 && rls[0].getTagAggregateShareRatio() >= 0) {
label = new Label(gTransfer, SWT.NONE);
Messages.setLanguageText(label, "TableColumn.header.max_aggregate_sr");
gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
Utils.setLayoutData(label, gd);
params.max_aggregate_sr = new GenericFloatParameter(new GenericParameterAdapter() {
@Override
public float getFloatValue(String key) {
return rls[0].getTagMaxAggregateShareRatio() / 1000f;
}
@Override
public void setFloatValue(String key, float value) {
rls[0].setTagMaxAggregateShareRatio((int) (value * 1000));
updateTagSRParams(params);
}
}, gTransfer, null, 0, Float.MAX_VALUE, true, 3);
gd = new GridData();
// gd.horizontalSpan = 3;
gd.widthHint = 75;
params.max_aggregate_sr.setLayoutData(gd);
// max sr action
String[] ST_ACTION_VALUES = { "" + TagFeatureRateLimit.SR_ACTION_PAUSE, "" + TagFeatureRateLimit.SR_ACTION_STOP };
String[] ST_ACTION_LABELS = { MessageText.getString("v3.MainWindow.button.pause"), MessageText.getString("v3.MainWindow.button.stop") };
label = new Label(gTransfer, SWT.NONE);
Messages.setLanguageText(label, "label.when.exceeded");
gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
Utils.setLayoutData(label, gd);
params.max_aggregate_sr_action = new GenericStringListParameter(new GenericParameterAdapter() {
@Override
public String getStringListValue(String key, String def) {
return (getStringListValue(key));
}
@Override
public String getStringListValue(String key) {
return ("" + rls[0].getTagMaxAggregateShareRatioAction());
}
@Override
public void setStringListValue(String key, String value) {
rls[0].setTagMaxAggregateShareRatioAction(Integer.parseInt(value));
}
}, gTransfer, "max_aggregate_sr_action", "" + TagFeatureRateLimit.SR_AGGREGATE_ACTION_DEFAULT, ST_ACTION_LABELS, ST_ACTION_VALUES);
// aggregate has priority
label = new Label(gTransfer, SWT.NONE);
Messages.setLanguageText(label, "label.aggregate.has.priority");
gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
Utils.setLayoutData(label, gd);
params.max_aggregate_sr_priority = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return (rls[0].getTagMaxAggregateShareRatioHasPriority());
}
@Override
public void setBooleanValue(String key, boolean value) {
rls[0].setTagMaxAggregateShareRatioHasPriority(value);
}
}, gTransfer, "max_aggregate_sr_priority", TagFeatureRateLimit.AT_RATELIMIT_MAX_AGGREGATE_SR_PRIORITY_DEFAULT);
updateTagSRParams(params);
}
}
if (numTags == 1 && (tags[0] instanceof TagFeatureFileLocation)) {
final TagFeatureFileLocation fl = (TagFeatureFileLocation) tags[0];
if (fl.supportsTagCopyOnComplete() || fl.supportsTagInitialSaveFolder() || fl.supportsTagMoveOnComplete()) {
Group gFiles = new Group(cMainComposite, SWT.NONE);
gFiles.setText(MessageText.getString("label.file.settings"));
gridLayout = new GridLayout(6, false);
gFiles.setLayout(gridLayout);
gd = new GridData(SWT.FILL, SWT.NONE, true, false, 4, 1);
Utils.setLayoutData(gFiles, gd);
if (fl.supportsTagInitialSaveFolder()) {
params.initalSaveFolder = new folderOption(gFiles, "label.init.save.loc") {
@Override
public void setFolder(File folder) {
params.initalSaveData.setEnabled(folder != null);
params.initalSaveTorrent.setEnabled(folder != null);
fl.setTagInitialSaveFolder(folder);
}
@Override
public File getFolder() {
File result = fl.getTagInitialSaveFolder();
params.initalSaveData.setEnabled(result != null);
params.initalSaveTorrent.setEnabled(result != null);
return (result);
}
};
params.initalSaveData = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return ((fl.getTagInitialSaveOptions() & TagFeatureFileLocation.FL_DATA) != 0);
}
@Override
public void setBooleanValue(String key, boolean value) {
long flags = fl.getTagInitialSaveOptions();
if (value) {
flags |= TagFeatureFileLocation.FL_DATA;
} else {
flags &= ~TagFeatureFileLocation.FL_DATA;
}
fl.setTagInitialSaveOptions(flags);
}
}, gFiles, null, "label.move.data");
params.initalSaveTorrent = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return ((fl.getTagInitialSaveOptions() & TagFeatureFileLocation.FL_TORRENT) != 0);
}
@Override
public void setBooleanValue(String key, boolean value) {
long flags = fl.getTagInitialSaveOptions();
if (value) {
flags |= TagFeatureFileLocation.FL_TORRENT;
} else {
flags &= ~TagFeatureFileLocation.FL_TORRENT;
}
fl.setTagInitialSaveOptions(flags);
}
}, gFiles, null, "label.move.torrent");
}
if (fl.supportsTagMoveOnComplete()) {
params.moveOnCompleteFolder = new folderOption(gFiles, "label.move.on.comp") {
@Override
public void setFolder(File folder) {
params.moveOnCompleteData.setEnabled(folder != null);
params.moveOnCompleteTorrent.setEnabled(folder != null);
fl.setTagMoveOnCompleteFolder(folder);
}
@Override
public File getFolder() {
File result = fl.getTagMoveOnCompleteFolder();
params.moveOnCompleteData.setEnabled(result != null);
params.moveOnCompleteTorrent.setEnabled(result != null);
return (result);
}
};
params.moveOnCompleteData = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return ((fl.getTagMoveOnCompleteOptions() & TagFeatureFileLocation.FL_DATA) != 0);
}
@Override
public void setBooleanValue(String key, boolean value) {
long flags = fl.getTagMoveOnCompleteOptions();
if (value) {
flags |= TagFeatureFileLocation.FL_DATA;
} else {
flags &= ~TagFeatureFileLocation.FL_DATA;
}
fl.setTagMoveOnCompleteOptions(flags);
}
}, gFiles, null, "label.move.data");
params.moveOnCompleteTorrent = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return ((fl.getTagMoveOnCompleteOptions() & TagFeatureFileLocation.FL_TORRENT) != 0);
}
@Override
public void setBooleanValue(String key, boolean value) {
long flags = fl.getTagMoveOnCompleteOptions();
if (value) {
flags |= TagFeatureFileLocation.FL_TORRENT;
} else {
flags &= ~TagFeatureFileLocation.FL_TORRENT;
}
fl.setTagMoveOnCompleteOptions(flags);
}
}, gFiles, null, "label.move.torrent");
}
if (fl.supportsTagCopyOnComplete()) {
params.copyOnCompleteFolder = new folderOption(gFiles, "label.copy.on.comp") {
@Override
public void setFolder(File folder) {
params.copyOnCompleteData.setEnabled(folder != null);
params.copyOnCompleteTorrent.setEnabled(folder != null);
fl.setTagCopyOnCompleteFolder(folder);
}
@Override
public File getFolder() {
File result = fl.getTagCopyOnCompleteFolder();
params.copyOnCompleteData.setEnabled(result != null);
params.copyOnCompleteTorrent.setEnabled(result != null);
return (result);
}
};
params.copyOnCompleteData = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return ((fl.getTagCopyOnCompleteOptions() & TagFeatureFileLocation.FL_DATA) != 0);
}
@Override
public void setBooleanValue(String key, boolean value) {
long flags = fl.getTagCopyOnCompleteOptions();
if (value) {
flags |= TagFeatureFileLocation.FL_DATA;
} else {
flags &= ~TagFeatureFileLocation.FL_DATA;
}
fl.setTagCopyOnCompleteOptions(flags);
}
}, gFiles, null, "label.copy.data");
params.copyOnCompleteTorrent = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return ((fl.getTagCopyOnCompleteOptions() & TagFeatureFileLocation.FL_TORRENT) != 0);
}
@Override
public void setBooleanValue(String key, boolean value) {
long flags = fl.getTagCopyOnCompleteOptions();
if (value) {
flags |= TagFeatureFileLocation.FL_TORRENT;
} else {
flags &= ~TagFeatureFileLocation.FL_TORRENT;
}
fl.setTagCopyOnCompleteOptions(flags);
}
}, gFiles, null, "label.copy.torrent");
}
}
}
if (numTags == 1 && tags[0].getTagType().hasTagTypeFeature(TagFeature.TF_PROPERTIES) && (tags[0] instanceof TagFeatureProperties)) {
TagFeatureProperties tfp = (TagFeatureProperties) tags[0];
final TagProperty propConstraint = tfp.getProperty(TagFeatureProperties.PR_CONSTRAINT);
if (propConstraint != null) {
Group gConstraint = new Group(cMainComposite, SWT.NONE);
Messages.setLanguageText(gConstraint, "tag.property.constraint");
int columns = 6;
gridLayout = new GridLayout(columns, false);
gConstraint.setLayout(gridLayout);
gd = new GridData(SWT.FILL, SWT.NONE, true, false, 4, 1);
Utils.setLayoutData(gConstraint, gd);
params.constraints = new Text(gConstraint, SWT.WRAP | SWT.BORDER | SWT.MULTI);
gd = new GridData(SWT.FILL, SWT.NONE, true, false, columns, 1);
gd.heightHint = 40;
Utils.setLayoutData(params.constraints, gd);
params.constraints.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
params.constraints.setData("skipset", 1);
if (btnSaveConstraint != null && !btnSaveConstraint.isDisposed()) {
btnSaveConstraint.setEnabled(true);
btnResetConstraint.setEnabled(true);
}
}
});
params.constraintError = new Label(gConstraint, SWT.NULL);
params.constraintError.setForeground(Colors.colorError);
gd = new GridData(SWT.FILL, SWT.NONE, true, false, columns, 1);
Utils.setLayoutData(params.constraintError, gd);
btnSaveConstraint = new Button(gConstraint, SWT.PUSH);
btnSaveConstraint.setEnabled(false);
btnSaveConstraint.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
String constraint = params.constraints.getText().trim();
String[] old_value = propConstraint.getStringList();
if (constraint.length() == 0) {
propConstraint.setStringList(null);
} else {
String old_options = old_value.length > 1 && old_value[1] != null ? old_value[1] : "";
if (old_options.length() == 0) {
old_options = CM_ADD_REMOVE;
}
propConstraint.setStringList(new String[] { constraint, old_options });
}
if (btnSaveConstraint != null && !btnSaveConstraint.isDisposed()) {
btnSaveConstraint.setEnabled(false);
btnResetConstraint.setEnabled(false);
}
}
});
Messages.setLanguageText(btnSaveConstraint, "Button.save");
btnResetConstraint = new Button(gConstraint, SWT.PUSH);
btnResetConstraint.setEnabled(false);
btnResetConstraint.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
params.constraints.setData("skipset", null);
swt_updateFields();
if (btnSaveConstraint != null && !btnSaveConstraint.isDisposed()) {
btnSaveConstraint.setEnabled(false);
btnResetConstraint.setEnabled(false);
}
}
});
Messages.setLanguageText(btnResetConstraint, "Button.reset");
params.constraintEnabled = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return (propConstraint.isEnabled());
}
@Override
public void setBooleanValue(String key, boolean value) {
propConstraint.setEnabled(value);
}
}, gConstraint, null, "label.enabled");
Label constraintMode = new Label(gConstraint, SWT.NULL);
Messages.setLanguageText(constraintMode, "label.scope");
String[] CM_VALUES = { CM_ADD_REMOVE, CM_ADD_ONLY, CM_REMOVE_ONLY };
String[] CM_LABELS = { MessageText.getString("label.addition.and.removal"), MessageText.getString("label.addition.only"), MessageText.getString("label.removal.only") };
params.constraintMode = new GenericStringListParameter(new GenericParameterAdapter() {
@Override
public String getStringListValue(String key, String def) {
return (getStringListValue(key));
}
@Override
public String getStringListValue(String key) {
String[] list = propConstraint.getStringList();
if (list.length > 1 && list[1] != null) {
return (list[1]);
} else {
return (CM_ADD_REMOVE);
}
}
@Override
public void setStringListValue(String key, String value) {
if (value == null || value.length() == 0) {
value = CM_ADD_REMOVE;
}
String[] list = propConstraint.getStringList();
propConstraint.setStringList(new String[] { list != null && list.length > 0 ? list[0] : "", value });
}
}, gConstraint, "tag_constraint_action_mode", CM_ADD_REMOVE, CM_LABELS, CM_VALUES);
Link lblAboutConstraint = new Link(gConstraint, SWT.WRAP);
Utils.setLayoutData(lblAboutConstraint, Utils.getWrappableLabelGridData(1, GridData.GRAB_HORIZONTAL));
lblAboutConstraint.setText(MessageText.getString("tag.constraints.info"));
lblAboutConstraint.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (event.text != null && (event.text.startsWith("http://") || event.text.startsWith("https://"))) {
Utils.launch(event.text);
}
}
});
}
}
if (numTags == 1 && tags[0].getTagType().hasTagTypeFeature(TagFeature.TF_LIMITS)) {
final TagFeatureLimits tfl = (TagFeatureLimits) tags[0];
if (tfl.getMaximumTaggables() >= 0) {
// ///////////////////////////// limits
Group gLimits = new Group(cMainComposite, SWT.NONE);
gLimits.setText(MessageText.getString("label.limit.settings"));
gridLayout = new GridLayout(6, false);
gLimits.setLayout(gridLayout);
gd = new GridData(SWT.FILL, SWT.NONE, false, false, 4, 1);
gLimits.setLayoutData(gd);
label = new Label(gLimits, SWT.NONE);
Messages.setLanguageText(label, "TableColumn.header.max_taggables");
gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
Utils.setLayoutData(label, gd);
params.tfl_max_taggables = new GenericIntParameter(new GenericParameterAdapter() {
@Override
public int getIntValue(String key) {
return tfl.getMaximumTaggables();
}
@Override
public int getIntValue(String key, int def) {
return getIntValue(key);
}
@Override
public void setIntValue(String key, int value) {
tfl.setMaximumTaggables(value);
}
}, gLimits, null, 0, Integer.MAX_VALUE);
// we really don't want partial values to be set as the consequences may be very
// unwanted if a removal policy is already set...
params.tfl_max_taggables.disableTimedSave();
gd = new GridData();
// gd.horizontalSpan = 3;
gd.widthHint = 50;
params.tfl_max_taggables.setLayoutData(gd);
label = new Label(gLimits, SWT.NONE);
Messages.setLanguageText(label, "label.removal.policy");
params.tfl_removal_policy = new GenericStringListParameter(new GenericParameterAdapter() {
@Override
public String getStringListValue(String key) {
return (String.valueOf(tfl.getRemovalStrategy()));
}
@Override
public String getStringListValue(String key, String def) {
return (getStringListValue(key));
}
@Override
public void setStringListValue(String key, String value) {
tfl.setRemovalStrategy(value == null ? TagFeatureLimits.RS_DEFAULT : Integer.parseInt(value));
}
}, gLimits, null, new String[] { "", MessageText.getString("MyTorrentsView.menu.archive"), MessageText.getString("Button.deleteContent.fromLibrary"), MessageText.getString("Button.deleteContent.fromComputer"), MessageText.getString("label.move.to.old.tag") }, new String[] { "0", "1", "2", "3", "4" });
label = new Label(gLimits, SWT.NONE);
Messages.setLanguageText(label, "label.ordering");
params.tfl_ordering = new GenericStringListParameter(new GenericParameterAdapter() {
@Override
public String getStringListValue(String key) {
return (String.valueOf(tfl.getOrdering()));
}
@Override
public String getStringListValue(String key, String def) {
return (getStringListValue(key));
}
@Override
public void setStringListValue(String key, String value) {
tfl.setOrdering(value == null ? TagFeatureLimits.OP_DEFAULT : Integer.parseInt(value));
}
}, gLimits, null, new String[] { MessageText.getString("label.time.added.to.vuze"), MessageText.getString("label.time.added.to.tag") }, new String[] { "0", "1" });
}
}
if (numTags == 1 && tags[0].getTagType().hasTagTypeFeature(TagFeature.TF_NOTIFICATIONS)) {
final TagFeatureNotifications tfn = (TagFeatureNotifications) tags[0];
// notifications
Group gNotifications = new Group(cMainComposite, SWT.NONE);
gNotifications.setText(MessageText.getString("v3.MainWindow.tab.events"));
gridLayout = new GridLayout(6, false);
gNotifications.setLayout(gridLayout);
gd = new GridData(SWT.FILL, SWT.NONE, false, false, 4, 1);
gNotifications.setLayoutData(gd);
label = new Label(gNotifications, SWT.NONE);
label.setText(MessageText.getString("tag.notification.post") + ":");
params.notification_post_add = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return ((tfn.getPostingNotifications() & TagFeatureNotifications.NOTIFY_ON_ADD) != 0);
}
@Override
public void setBooleanValue(String key, boolean value) {
int flags = tfn.getPostingNotifications();
if (value) {
flags |= TagFeatureNotifications.NOTIFY_ON_ADD;
} else {
flags &= ~TagFeatureNotifications.NOTIFY_ON_ADD;
}
tfn.setPostingNotifications(flags);
}
}, gNotifications, null, "label.on.addition");
params.notification_post_remove = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return ((tfn.getPostingNotifications() & TagFeatureNotifications.NOTIFY_ON_REMOVE) != 0);
}
@Override
public void setBooleanValue(String key, boolean value) {
int flags = tfn.getPostingNotifications();
if (value) {
flags |= TagFeatureNotifications.NOTIFY_ON_REMOVE;
} else {
flags &= ~TagFeatureNotifications.NOTIFY_ON_REMOVE;
}
tfn.setPostingNotifications(flags);
}
}, gNotifications, null, "label.on.removal");
}
swt_updateFields();
}
cMainComposite.layout();
Rectangle r = sc.getClientArea();
sc.setMinSize(cMainComposite.computeSize(r.width, SWT.DEFAULT));
}
use of com.biglybt.core.tag.TagFeatureProperties.TagProperty in project BiglyBT by BiglySoftware.
the class TagSettingsView method swt_updateFields.
private void swt_updateFields() {
if (tags == null || params == null) {
initialize(null);
return;
}
int[] tagColor = tags[0].getColor();
Set<String> listTagNames = new HashSet<>();
for (Tag tag : tags) {
TagType tt = tag.getTagType();
String s = tag.getTagName(true);
listTagNames.add(s);
if (tagColor != null) {
int[] color = tag.getColor();
if (!Arrays.areEqual(tagColor, color)) {
tagColor = null;
}
}
}
String name = GeneralUtils.stringJoin(listTagNames, ", ");
if (params.cName != null && !params.cName.isDisposed()) {
if (params.cName instanceof Text) {
Text txt = (Text) params.cName;
if (!txt.getText().equals(name)) {
txt.setText(name);
}
} else if (params.cName instanceof Label) {
Label lbl = (Label) params.cName;
lbl.setText(name);
}
}
if (params.tagColor != null && tagColor != null) {
params.tagColor.setColor(tagColor[0], tagColor[1], tagColor[2]);
}
if (params.viewInSideBar != null) {
params.viewInSideBar.refresh();
}
if (params.isPublic != null) {
params.isPublic.refresh();
}
if (params.maxDownloadSpeed != null) {
params.maxDownloadSpeed.resetToDefault();
}
if (params.maxUploadSpeed != null) {
params.maxUploadSpeed.resetToDefault();
}
if (params.uploadPriority != null) {
params.uploadPriority.refresh();
}
if (params.min_sr != null) {
params.min_sr.refresh();
}
if (params.max_sr != null) {
params.max_sr.refresh();
}
if (params.initalSaveFolder != null) {
params.initalSaveFolder.update();
}
if (params.moveOnCompleteFolder != null) {
params.moveOnCompleteFolder.update();
}
if (params.copyOnCompleteFolder != null) {
params.copyOnCompleteFolder.update();
}
if (params.constraints != null) {
Tag tag = tags[0];
if (params.constraints.getData("skipset") == null) {
String text = "";
String mode = CM_ADD_REMOVE;
if (tag.getTagType().hasTagTypeFeature(TagFeature.TF_PROPERTIES) && (tag instanceof TagFeatureProperties)) {
TagFeatureProperties tfp = (TagFeatureProperties) tag;
TagProperty propConstraint = tfp.getProperty(TagFeatureProperties.PR_CONSTRAINT);
if (propConstraint != null) {
String[] stringList = propConstraint.getStringList();
// constraint only has one entry
if (stringList.length > 0) {
text = stringList[0];
}
if (stringList.length > 1 && stringList[1] != null) {
mode = stringList[1];
}
}
}
params.constraints.setText(text);
params.constraintMode.setValue(mode);
}
String error = (String) tag.getTransientProperty(Tag.TP_CONSTRAINT_ERROR);
if (error == null) {
params.constraintError.setText("");
} else {
params.constraintError.setText(error.replace('\r', ' ').replace('\n', ' '));
}
}
if (params.tfl_max_taggables != null) {
params.tfl_max_taggables.refresh();
}
}
Aggregations