use of com.biglybt.ui.swt.maketorrent.TrackerEditorListener in project BiglyBT by BiglySoftware.
the class TagUIUtils method createTFProperitesMenuItems.
private static void createTFProperitesMenuItems(Menu menu, Tag tag) {
TagFeatureProperties props = (TagFeatureProperties) tag;
TagProperty[] tps = props.getSupportedProperties();
if (tps.length > 0) {
final Menu props_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
MenuItem props_item = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(props_item, "label.properties");
props_item.setMenu(props_menu);
for (final TagProperty tp : tps) {
if (tp.getType() == TagFeatureProperties.PT_STRING_LIST) {
String tp_name = tp.getName(false);
if (tp_name.equals(TagFeatureProperties.PR_CONSTRAINT)) {
MenuItem const_item = new MenuItem(props_menu, SWT.PUSH);
Messages.setLanguageText(const_item, "label.contraints");
const_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
final String[] old_value = tp.getStringList();
String def_val;
if (old_value != null && old_value.length > 0) {
def_val = old_value[0];
} else {
def_val = "";
}
String msg = MessageText.getString("UpdateConstraint.message");
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("UpdateConstraint.title", "!" + msg + "!");
entryWindow.setPreenteredText(def_val, false);
entryWindow.selectPreenteredText(true);
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver receiver) {
if (!receiver.hasSubmittedInput()) {
return;
}
try {
String text = receiver.getSubmittedInput().trim();
if (text.length() == 0) {
tp.setStringList(null);
} else {
String old_options = old_value.length > 1 ? old_value[1] : "";
tp.setStringList(new String[] { text, old_options });
}
} catch (Throwable e) {
Debug.out(e);
}
}
});
}
});
} else if (tp_name.equals(TagFeatureProperties.PR_TRACKER_TEMPLATES)) {
final TrackersUtil tut = TrackersUtil.getInstance();
List<String> templates = new ArrayList<>(tut.getMultiTrackers().keySet());
String str_merge = MessageText.getString("label.merge");
String str_replace = MessageText.getString("label.replace");
String str_remove = MessageText.getString("Button.remove");
String[] val = tp.getStringList();
String def_str;
final List<String> selected = new ArrayList<>();
if (val == null || val.length == 0) {
def_str = "";
} else {
def_str = "";
for (String v : val) {
String[] bits = v.split(":");
if (bits.length == 2) {
String tn = bits[1];
if (templates.contains(tn)) {
String type = bits[0];
if (type.equals("m")) {
tn += ": " + str_merge;
} else if (type.equals("r")) {
tn += ": " + str_replace;
} else {
tn += ": " + str_remove;
}
selected.add(v);
def_str += (def_str.length() == 0 ? "" : ", ") + tn;
}
}
}
}
Collections.sort(templates);
// deliberately hanging this off the main menu, not properties...
Menu ttemp_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
MenuItem ttemp_item = new MenuItem(menu, SWT.CASCADE);
ttemp_item.setText(MessageText.getString("label.tracker.templates") + (def_str.length() == 0 ? "" : (" (" + def_str + ") ")));
ttemp_item.setMenu(ttemp_menu);
MenuItem new_item = new MenuItem(ttemp_menu, SWT.PUSH);
Messages.setLanguageText(new_item, "wizard.multitracker.new");
new_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
List<List<String>> group = new ArrayList<>();
List<String> tracker = new ArrayList<>();
group.add(tracker);
new MultiTrackerEditor(props_menu.getShell(), null, group, new TrackerEditorListener() {
@Override
public void trackersChanged(String oldName, String newName, List<List<String>> trackers) {
if (trackers != null) {
tut.addMultiTracker(newName, trackers);
}
}
});
}
});
MenuItem reapply_item = new MenuItem(ttemp_menu, SWT.PUSH);
Messages.setLanguageText(reapply_item, "label.reapply");
reapply_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
tp.syncListeners();
}
});
reapply_item.setEnabled(def_str.length() > 0);
if (templates.size() > 0) {
new MenuItem(ttemp_menu, SWT.SEPARATOR);
for (final String template_name : templates) {
Menu t_menu = new Menu(ttemp_menu.getShell(), SWT.DROP_DOWN);
MenuItem t_item = new MenuItem(ttemp_menu, SWT.CASCADE);
t_item.setText(template_name);
t_item.setMenu(t_menu);
boolean r_selected = false;
for (int i = 0; i < 3; i++) {
final MenuItem sel_item = new MenuItem(t_menu, SWT.CHECK);
final String key = (i == 0 ? "m" : (i == 1 ? "r" : "x")) + ":" + template_name;
sel_item.setText(i == 0 ? str_merge : (i == 1 ? str_replace : str_remove));
boolean is_sel = selected.contains(key);
r_selected |= is_sel;
sel_item.setSelection(is_sel);
sel_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (sel_item.getSelection()) {
selected.add(key);
} else {
selected.remove(key);
}
Utils.getOffOfSWTThread(new AERunnable() {
@Override
public void runSupport() {
tp.setStringList(selected.toArray(new String[selected.size()]));
}
});
}
});
}
if (r_selected) {
Utils.setMenuItemImage(t_item, "graytick");
}
new MenuItem(t_menu, SWT.SEPARATOR);
MenuItem edit_item = new MenuItem(t_menu, SWT.PUSH);
Messages.setLanguageText(edit_item, "wizard.multitracker.edit");
edit_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
new MultiTrackerEditor(props_menu.getShell(), template_name, tut.getMultiTrackers().get(template_name), new TrackerEditorListener() {
@Override
public void trackersChanged(String oldName, String newName, List<List<String>> trackers) {
if (oldName != null && !oldName.equals(newName)) {
tut.removeMultiTracker(oldName);
}
tut.addMultiTracker(newName, trackers);
}
});
}
});
MenuItem del_item = new MenuItem(t_menu, SWT.PUSH);
Messages.setLanguageText(del_item, "FileItem.delete");
Utils.setMenuItemImage(del_item, "delete");
del_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
MessageBoxShell mb = new MessageBoxShell(MessageText.getString("message.confirm.delete.title"), MessageText.getString("message.confirm.delete.text", new String[] { template_name }), new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 1);
mb.open(new UserPrompterResultListener() {
@Override
public void prompterClosed(int result) {
if (result == 0) {
tut.removeMultiTracker(template_name);
}
}
});
}
});
}
}
} else {
String[] val = tp.getStringList();
String def_str;
if (val == null || val.length == 0) {
def_str = "";
} else {
def_str = "";
for (String v : val) {
def_str += (def_str.length() == 0 ? "" : ", ") + v;
}
}
MenuItem set_item = new MenuItem(props_menu, SWT.PUSH);
set_item.setText(tp.getName(true) + (def_str.length() == 0 ? "" : (" (" + def_str + ") ")) + "...");
final String f_def_str = def_str;
set_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
String msg = MessageText.getString("UpdateProperty.list.message", new String[] { tp.getName(true) });
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("UpdateProperty.title", "!" + msg + "!");
entryWindow.setPreenteredText(f_def_str, false);
entryWindow.selectPreenteredText(true);
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
if (!entryWindow.hasSubmittedInput()) {
return;
}
try {
String text = entryWindow.getSubmittedInput().trim();
if (text.length() == 0) {
tp.setStringList(null);
} else {
text = text.replace(';', ',');
text = text.replace(' ', ',');
text = text.replaceAll("[,]+", ",");
String[] bits = text.split(",");
List<String> vals = new ArrayList<>();
for (String bit : bits) {
bit = bit.trim();
if (bit.length() > 0) {
vals.add(bit);
}
}
if (vals.size() == 0) {
tp.setStringList(null);
} else {
tp.setStringList(vals.toArray(new String[vals.size()]));
}
}
} catch (Throwable e) {
Debug.out(e);
}
}
});
}
});
}
} else if (tp.getType() == TagFeatureProperties.PT_BOOLEAN) {
final MenuItem set_item = new MenuItem(props_menu, SWT.CHECK);
set_item.setText(tp.getName(true));
Boolean val = tp.getBoolean();
set_item.setSelection(val != null && val);
set_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
tp.setBoolean(set_item.getSelection());
}
});
} else {
Debug.out("Unknown property");
}
}
}
}
use of com.biglybt.ui.swt.maketorrent.TrackerEditorListener in project BiglyBT by BiglySoftware.
the class TorrentUtil method addTrackerTorrentMenu.
protected static void addTrackerTorrentMenu(final Menu menuTracker, final DownloadManager[] dms, boolean changeUrl, boolean manualUpdate, boolean allStopped, final boolean use_open_containing_folder, boolean canMove) {
Shell shell = Utils.findAnyShell();
boolean hasSelection = dms.length > 0;
final MenuItem itemChangeTracker = new MenuItem(menuTracker, SWT.PUSH);
Messages.setLanguageText(itemChangeTracker, "MyTorrentsView.menu.changeTracker");
Utils.setMenuItemImage(itemChangeTracker, "add_tracker");
itemChangeTracker.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager[] dms) {
if (dms.length > 0) {
new TrackerChangerWindow(dms);
}
}
});
itemChangeTracker.setEnabled(changeUrl);
// edit tracker URLs
final MenuItem itemEditTracker = new MenuItem(menuTracker, SWT.PUSH);
Messages.setLanguageText(itemEditTracker, "MyTorrentsView.menu.editTracker");
Utils.setMenuItemImage(itemEditTracker, "edit_trackers");
itemEditTracker.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(final DownloadManager[] dms) {
Map<String, List<DownloadManager>> same_map = new HashMap<>();
for (DownloadManager dm : dms) {
TOTorrent torrent = dm.getTorrent();
if (torrent == null) {
continue;
}
List<List<String>> group = TorrentUtils.announceGroupsToList(torrent);
String str = "";
for (List<String> l : group) {
str += "[[";
for (String s : l) {
str += s + ", ";
}
}
List<DownloadManager> dl = same_map.get(str);
if (dl == null) {
dl = new ArrayList<>();
same_map.put(str, dl);
}
dl.add(dm);
}
for (final List<DownloadManager> set : same_map.values()) {
TOTorrent torrent = set.get(0).getTorrent();
List<List<String>> group = TorrentUtils.announceGroupsToList(torrent);
new MultiTrackerEditor(null, null, group, new TrackerEditorListener() {
@Override
public void trackersChanged(String str, String str2, List<List<String>> group) {
for (DownloadManager dm : set) {
TOTorrent torrent = dm.getTorrent();
TorrentUtils.listToAnnounceGroups(group, torrent);
try {
TorrentUtils.writeToFile(torrent);
} catch (Throwable e) {
Debug.printStackTrace(e);
}
if (dm.getTrackerClient() != null) {
dm.getTrackerClient().resetTrackerUrl(true);
}
}
}
}, true, true);
}
}
});
itemEditTracker.setEnabled(hasSelection);
// edit tracker URLs together
final MenuItem itemEditTrackerMerged = new MenuItem(menuTracker, SWT.PUSH);
Messages.setLanguageText(itemEditTrackerMerged, "MyTorrentsView.menu.editTrackerMerge");
itemEditTrackerMerged.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(final DownloadManager[] dms) {
final List<List<String>> merged_trackers = new ArrayList<>();
Set<String> added = new HashSet<>();
for (DownloadManager dm : dms) {
TOTorrent torrent = dm.getTorrent();
if (torrent == null) {
continue;
}
List<List<String>> group = TorrentUtils.announceGroupsToList(torrent);
for (List<String> set : group) {
List<String> rem = new ArrayList<>();
for (String url_str : set) {
try {
URL url = new URL(url_str);
if (TorrentUtils.isDecentralised(url)) {
continue;
}
if (!added.contains(url_str)) {
added.add(url_str);
rem.add(url_str);
}
} catch (Throwable e) {
}
}
if (rem.size() > 0) {
merged_trackers.add(rem);
}
}
}
new MultiTrackerEditor(null, null, merged_trackers, new TrackerEditorListener() {
@Override
public void trackersChanged(String str, String str2, List<List<String>> group) {
for (DownloadManager dm : dms) {
TOTorrent torrent = dm.getTorrent();
TorrentUtils.listToAnnounceGroups(group, torrent);
try {
TorrentUtils.writeToFile(torrent);
} catch (Throwable e) {
Debug.printStackTrace(e);
}
if (dm.getTrackerClient() != null) {
dm.getTrackerClient().resetTrackerUrl(true);
}
}
}
}, true, true);
}
});
itemEditTrackerMerged.setEnabled(dms.length > 1);
// edit webseeds
final MenuItem itemEditWebSeeds = new MenuItem(menuTracker, SWT.PUSH);
Messages.setLanguageText(itemEditWebSeeds, "MyTorrentsView.menu.editWebSeeds");
itemEditWebSeeds.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(final DownloadManager[] dms) {
final TOTorrent torrent = dms[0].getTorrent();
if (torrent == null) {
return;
}
List getright = getURLList(torrent, "url-list");
List webseeds = getURLList(torrent, "httpseeds");
Map ws = new HashMap();
ws.put("getright", getright);
ws.put("webseeds", webseeds);
ws = BDecoder.decodeStrings(ws);
new WebSeedsEditor(null, ws, new WebSeedsEditorListener() {
@Override
public void webSeedsChanged(String oldName, String newName, Map ws) {
try {
// String -> byte[]
ws = BDecoder.decode(BEncoder.encode(ws));
List getright = (List) ws.get("getright");
if (getright == null || getright.size() == 0) {
torrent.removeAdditionalProperty("url-list");
} else {
torrent.setAdditionalListProperty("url-list", getright);
}
List webseeds = (List) ws.get("webseeds");
if (webseeds == null || webseeds.size() == 0) {
torrent.removeAdditionalProperty("httpseeds");
} else {
torrent.setAdditionalListProperty("httpseeds", webseeds);
}
PluginInterface pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByClass(ExternalSeedPlugin.class);
if (pi != null) {
ExternalSeedPlugin ext_seed_plugin = (ExternalSeedPlugin) pi.getPlugin();
ext_seed_plugin.downloadChanged(PluginCoreUtils.wrap(dms[0]));
}
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
}, true);
}
protected List getURLList(TOTorrent torrent, String key) {
Object obj = torrent.getAdditionalProperty(key);
if (obj instanceof byte[]) {
List l = new ArrayList();
l.add(obj);
return (l);
} else if (obj instanceof List) {
return ((List) obj);
} else {
return (new ArrayList());
}
}
});
itemEditWebSeeds.setEnabled(dms.length == 1);
// manual update
final MenuItem itemManualUpdate = new MenuItem(menuTracker, SWT.PUSH);
Messages.setLanguageText(itemManualUpdate, // $NON-NLS-1$
"GeneralView.label.trackerurlupdate");
// itemManualUpdate.setImage(ImageRepository.getImage("edit_trackers"));
itemManualUpdate.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
dm.requestTrackerAnnounce(false);
}
});
itemManualUpdate.setEnabled(manualUpdate);
boolean scrape_enabled = COConfigurationManager.getBooleanParameter("Tracker Client Scrape Enable");
boolean scrape_stopped = COConfigurationManager.getBooleanParameter("Tracker Client Scrape Stopped Enable");
boolean manualScrape = (!scrape_enabled) || ((!scrape_stopped) && allStopped);
final MenuItem itemManualScrape = new MenuItem(menuTracker, SWT.PUSH);
Messages.setLanguageText(itemManualScrape, "GeneralView.label.trackerscrapeupdate");
// itemManualUpdate.setImage(ImageRepository.getImage("edit_trackers"));
itemManualScrape.addListener(SWT.Selection, new ListenerDMTask(dms, true, true) {
@Override
public void run(DownloadManager dm) {
dm.requestTrackerScrape(true);
}
});
itemManualScrape.setEnabled(manualScrape);
// download link
final MenuItem itemTorrentDL = new MenuItem(menuTracker, SWT.PUSH);
Messages.setLanguageText(itemTorrentDL, "MyTorrentsView.menu.torrent.dl");
itemTorrentDL.addListener(SWT.Selection, new ListenerDMTask(dms, false) {
@Override
public void run(DownloadManager dm) {
String content;
TOTorrent torrent = dm.getTorrent();
String link = null;
if (torrent == null) {
content = "Torrent not available";
} else {
link = TorrentUtils.getObtainedFrom(torrent);
if (link != null) {
try {
new URL(link);
} catch (Throwable e) {
link = null;
}
}
if (link != null) {
if (link.toLowerCase().startsWith("magnet:")) {
link = UrlUtils.getMagnetURI(dm);
content = "Torrent's magnet link:\r\n\r\n\t" + link;
} else {
content = "Torrent was obtained from\r\n\r\n\t" + link;
}
} else {
if (TorrentUtils.isReallyPrivate(torrent)) {
content = "Origin of torrent unknown and it is private so a magnet URI can't be used - sorry!";
} else {
link = UrlUtils.getMagnetURI(dm);
content = "Origin unavailable but magnet URI may work:\r\n\r\n\t" + link;
}
}
}
if (link != null) {
ClipboardCopy.copyToClipBoard(link);
content += "\r\n\r\nLink copied to clipboard";
}
final TextViewerWindow viewer = new TextViewerWindow(MessageText.getString("MyTorrentsView.menu.torrent.dl") + ": " + dm.getDisplayName(), null, content, false);
}
});
itemTorrentDL.setEnabled(dms.length == 1);
// move torrent
final MenuItem itemFileMoveTorrent = new MenuItem(menuTracker, SWT.PUSH);
Messages.setLanguageText(itemFileMoveTorrent, "MyTorrentsView.menu.movetorrent");
itemFileMoveTorrent.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager[] dms) {
TorrentUtil.moveTorrentFile(shell, dms);
}
});
itemFileMoveTorrent.setEnabled(canMove);
// switch torrent
final MenuItem itemTorrentSwitch = new MenuItem(menuTracker, SWT.PUSH);
Messages.setLanguageText(itemTorrentSwitch, "MyTorrentsView.menu.torrent.switch");
itemTorrentSwitch.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
final TOTorrent torrent = dms[0].getTorrent();
if (torrent == null) {
return;
}
try {
byte[] existing_hash = torrent.getHash();
FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
dialog.setText(MessageText.getString("dialog.select.torrent.file"));
dialog.setFilterExtensions(new String[] { "*.torrent" });
dialog.setFilterNames(new String[] { "*.torrent" });
String path = dialog.open();
if (path == null) {
return;
}
File file = new File(path);
byte[] replacement_hash = TOTorrentFactory.deserialiseFromBEncodedFile(file).getHash();
if (!Arrays.equals(existing_hash, replacement_hash)) {
throw (new Exception("Hash mismatch: old=" + ByteFormatter.encodeString(existing_hash) + ", new=" + ByteFormatter.encodeString(replacement_hash)));
}
dms[0].setTorrentFileName(file.getAbsolutePath());
} catch (Throwable e) {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setText(MessageText.getString("MyTorrentsView.menu.torrent.switch.fail"));
mb.setMessage(MessageText.getString("MyTorrentsView.menu.torrent.switch.fail.text", new String[] { Debug.getNestedExceptionMessage(e) }));
mb.open();
}
}
});
itemTorrentSwitch.setEnabled(dms.length == 1 && dms[0].isPersistent());
// set source
final MenuItem itemTorrentSource = new MenuItem(menuTracker, SWT.PUSH);
Messages.setLanguageText(itemTorrentSource, "MyTorrentsView.menu.torrent.set.source");
itemTorrentSource.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
final TOTorrent torrent = dms[0].getTorrent();
if (torrent == null) {
return;
}
String msg_key_prefix = "MyTorrentsView.menu.edit_source.";
SimpleTextEntryWindow text_entry = new SimpleTextEntryWindow();
text_entry.setParentShell(shell);
text_entry.setTitle(msg_key_prefix + "title");
text_entry.setMessage(msg_key_prefix + "message");
text_entry.setPreenteredText(TorrentUtils.getObtainedFrom(torrent), false);
text_entry.setWidthHint(500);
text_entry.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver text_entry) {
if (text_entry.hasSubmittedInput()) {
TorrentUtils.setObtainedFrom(torrent, text_entry.getSubmittedInput());
try {
TorrentUtils.writeToFile(torrent);
} catch (Throwable e) {
}
}
}
});
}
});
itemTorrentSource.setEnabled(dms.length == 1);
// set thumbnail
final MenuItem itemTorrentThumb = new MenuItem(menuTracker, SWT.PUSH);
Messages.setLanguageText(itemTorrentThumb, "MyTorrentsView.menu.torrent.set.thumb");
itemTorrentThumb.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
FileDialog fDialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
fDialog.setText(MessageText.getString("MainWindow.dialog.choose.thumb"));
String path = fDialog.open();
if (path == null)
return;
File file = new File(path);
try {
byte[] thumbnail = FileUtil.readFileAsByteArray(file);
String name = file.getName();
int pos = name.lastIndexOf(".");
String ext;
if (pos != -1) {
ext = name.substring(pos + 1);
} else {
ext = "";
}
String type = HTTPUtils.guessContentTypeFromFileType(ext);
for (DownloadManager dm : dms) {
try {
TOTorrent torrent = dm.getTorrent();
PlatformTorrentUtils.setContentThumbnail(torrent, thumbnail, type);
} catch (Throwable e) {
}
}
} catch (Throwable e) {
Debug.out(e);
}
}
});
itemTorrentThumb.setEnabled(hasSelection);
// explore torrent file
final MenuItem itemTorrentExplore = new MenuItem(menuTracker, SWT.PUSH);
Messages.setLanguageText(itemTorrentExplore, "MyTorrentsView.menu." + (use_open_containing_folder ? "open_parent_folder" : "explore"));
itemTorrentExplore.addListener(SWT.Selection, new ListenerDMTask(dms, false) {
@Override
public void run(DownloadManager dm) {
ManagerUtils.open(new File(dm.getTorrentFileName()), use_open_containing_folder);
}
});
}
use of com.biglybt.ui.swt.maketorrent.TrackerEditorListener in project BiglyBT by BiglySoftware.
the class ScrapeInfoView method initialize.
private void initialize(Composite parent) {
cParent = parent;
Label label;
GridData gridData;
final Display display = parent.getDisplay();
if (cScrapeInfoView == null || cScrapeInfoView.isDisposed()) {
cScrapeInfoView = new Composite(parent, SWT.NONE);
}
gridData = new GridData(GridData.FILL_BOTH);
cScrapeInfoView.setLayoutData(gridData);
GridLayout layoutInfo = new GridLayout();
layoutInfo.numColumns = 4;
cScrapeInfoView.setLayout(layoutInfo);
label = new Label(cScrapeInfoView, SWT.LEFT);
// $NON-NLS-1$
Messages.setLanguageText(label, "GeneralView.label.trackerurl");
label.setCursor(display.getSystemCursor(SWT.CURSOR_HAND));
label.setForeground(Colors.blue);
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent arg0) {
String announce = trackerUrlValue.getText();
if (announce != null && announce.length() != 0) {
new Clipboard(display).setContents(new Object[] { announce }, new Transfer[] { TextTransfer.getInstance() });
}
}
@Override
public void mouseDown(MouseEvent arg0) {
String announce = trackerUrlValue.getText();
if (announce != null && announce.length() != 0) {
new Clipboard(display).setContents(new Object[] { announce }, new Transfer[] { TextTransfer.getInstance() });
}
}
});
menuTracker = new Menu(parent.getShell(), SWT.POP_UP);
itemSelect = new MenuItem(menuTracker, SWT.CASCADE);
Messages.setLanguageText(itemSelect, "GeneralView.menu.selectTracker");
MenuItem itemEdit = new MenuItem(menuTracker, SWT.NULL);
Messages.setLanguageText(itemEdit, "MyTorrentsView.menu.editTracker");
cScrapeInfoView.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
menuTracker.dispose();
}
});
itemEdit.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
final TOTorrent torrent = manager.getTorrent();
if (torrent == null) {
return;
}
List<List<String>> group = TorrentUtils.announceGroupsToList(torrent);
new MultiTrackerEditor(null, null, group, new TrackerEditorListener() {
@Override
public void trackersChanged(String str, String str2, List<List<String>> _group) {
TorrentUtils.listToAnnounceGroups(_group, torrent);
try {
TorrentUtils.writeToFile(torrent);
} catch (Throwable e2) {
Debug.printStackTrace(e2);
}
TRTrackerAnnouncer tc = manager.getTrackerClient();
if (tc != null) {
tc.resetTrackerUrl(true);
}
}
}, true, true);
}
});
TOTorrent torrent = manager == null ? null : manager.getTorrent();
itemEdit.setEnabled(torrent != null && !TorrentUtils.isReallyPrivate(torrent));
final Listener menuListener = new Listener() {
@Override
public void handleEvent(Event e) {
if (e.widget instanceof MenuItem) {
String text = ((MenuItem) e.widget).getText();
TOTorrent torrent = manager.getTorrent();
TorrentUtils.announceGroupsSetFirst(torrent, text);
try {
TorrentUtils.writeToFile(torrent);
} catch (TOTorrentException f) {
Debug.printStackTrace(f);
}
TRTrackerAnnouncer tc = manager.getTrackerClient();
if (tc != null) {
tc.resetTrackerUrl(false);
}
}
}
};
menuTracker.addListener(SWT.Show, new Listener() {
@Override
public void handleEvent(Event e) {
Menu menuSelect = itemSelect.getMenu();
if (menuSelect != null && !menuSelect.isDisposed()) {
menuSelect.dispose();
}
if (manager == null || cScrapeInfoView == null || cScrapeInfoView.isDisposed()) {
return;
}
List<List<String>> groups = TorrentUtils.announceGroupsToList(manager.getTorrent());
menuSelect = new Menu(cScrapeInfoView.getShell(), SWT.DROP_DOWN);
itemSelect.setMenu(menuSelect);
for (List<String> trackers : groups) {
MenuItem menuItem = new MenuItem(menuSelect, SWT.CASCADE);
Messages.setLanguageText(menuItem, "wizard.multitracker.group");
Menu menu = new Menu(cScrapeInfoView.getShell(), SWT.DROP_DOWN);
menuItem.setMenu(menu);
for (String url : trackers) {
MenuItem menuItemTracker = new MenuItem(menu, SWT.CASCADE);
menuItemTracker.setText(url);
menuItemTracker.addListener(SWT.Selection, menuListener);
}
}
}
});
trackerUrlValue = new BufferedTruncatedLabel(cScrapeInfoView, SWT.LEFT, 70);
trackerUrlValue.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent event) {
if (event.button == 3 || (event.button == 1 && event.stateMask == SWT.CONTROL)) {
menuTracker.setVisible(true);
} else if (event.button == 1) {
String url = trackerUrlValue.getText();
if (url.startsWith("http://") || url.startsWith("https://")) {
int pos = -1;
if ((pos = url.indexOf("/announce")) != -1) {
url = url.substring(0, pos + 1);
}
Utils.launch(url);
}
}
}
});
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
trackerUrlValue.setLayoutData(gridData);
// //////////////////////
label = new Label(cScrapeInfoView, SWT.LEFT);
Messages.setLanguageText(label, "GeneralView.label.tracker");
tracker_status = new BufferedTruncatedLabel(cScrapeInfoView, SWT.LEFT, 150);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
tracker_status.setLayoutData(gridData);
label = new Label(cScrapeInfoView, SWT.LEFT);
Messages.setLanguageText(label, "GeneralView.label.updatein");
trackerUpdateIn = new BufferedLabel(cScrapeInfoView, SWT.LEFT);
gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
trackerUpdateIn.setLayoutData(gridData);
updateButton = new Button(cScrapeInfoView, SWT.PUSH);
Messages.setLanguageText(updateButton, "GeneralView.label.trackerurlupdate");
updateButton.setLayoutData(new GridData());
updateButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
new AEThread2("SIV:async") {
@Override
public void run() {
if (manager.getTrackerClient() != null) {
manager.requestTrackerAnnounce(false);
} else {
manager.requestTrackerScrape(true);
}
}
}.start();
}
});
cScrapeInfoView.layout(true);
}
use of com.biglybt.ui.swt.maketorrent.TrackerEditorListener in project BiglyBT by BiglySoftware.
the class TrackerView method fillMenu.
@Override
public void fillMenu(String sColumnName, Menu menu) {
final Object[] sources = tv.getSelectedDataSources().toArray();
boolean found_tracker = false;
boolean found_dht_tracker = false;
boolean update_ok = false;
boolean delete_ok = false;
for (Object o : sources) {
TrackerPeerSource ps = (TrackerPeerSource) o;
if (ps.getType() == TrackerPeerSource.TP_TRACKER) {
found_tracker = true;
}
if (ps.getType() == TrackerPeerSource.TP_DHT) {
found_dht_tracker = true;
}
int state = ps.getStatus();
if ((state == TrackerPeerSource.ST_ONLINE || state == TrackerPeerSource.ST_QUEUED || state == TrackerPeerSource.ST_ERROR) && !ps.isUpdating() && ps.canManuallyUpdate()) {
update_ok = true;
}
if (ps.canDelete()) {
delete_ok = true;
}
}
boolean needs_sep = false;
if (found_tracker || found_dht_tracker) {
final MenuItem update_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(update_item, "GeneralView.label.trackerurlupdate");
update_item.setEnabled(update_ok);
update_item.addListener(SWT.Selection, new TableSelectedRowsListener(tv) {
@Override
public void run(TableRowCore row) {
for (Object o : sources) {
TrackerPeerSource ps = (TrackerPeerSource) o;
if (ps.canManuallyUpdate()) {
ps.manualUpdate();
}
}
}
});
if (found_tracker) {
final MenuItem edit_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(edit_item, "MyTorrentsView.menu.editTracker");
edit_item.addListener(SWT.Selection, new TableSelectedRowsListener(tv) {
@Override
public boolean run(TableRowCore[] rows) {
final TOTorrent torrent = manager.getTorrent();
if (torrent != null) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
List<List<String>> group = TorrentUtils.announceGroupsToList(torrent);
new MultiTrackerEditor(null, null, group, new TrackerEditorListener() {
@Override
public void trackersChanged(String str, String str2, List<List<String>> _group) {
TorrentUtils.listToAnnounceGroups(_group, torrent);
try {
TorrentUtils.writeToFile(torrent);
} catch (Throwable e2) {
Debug.printStackTrace(e2);
}
TRTrackerAnnouncer tc = manager.getTrackerClient();
if (tc != null) {
tc.resetTrackerUrl(true);
}
}
}, true, true);
}
});
}
return (true);
}
});
TOTorrent torrent = manager.getTorrent();
edit_item.setEnabled(torrent != null && !TorrentUtils.isReallyPrivate(torrent));
}
needs_sep = true;
}
if (delete_ok) {
final MenuItem delete_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(delete_item, "Button.remove");
Utils.setMenuItemImage(delete_item, "delete");
delete_item.addListener(SWT.Selection, new TableSelectedRowsListener(tv) {
@Override
public void run(TableRowCore row) {
for (Object o : sources) {
TrackerPeerSource ps = (TrackerPeerSource) o;
if (ps.canDelete()) {
ps.delete();
}
}
}
});
needs_sep = true;
}
if (needs_sep) {
new MenuItem(menu, SWT.SEPARATOR);
}
}
Aggregations