use of com.biglybt.pif.ui.UIInputReceiverListener in project BiglyBT by BiglySoftware.
the class BuddyPluginViewBetaChat method buildStatus.
private void buildStatus(Composite main_component, Composite component) {
boolean public_chat = !chat.isPrivateChat();
final Label menu_drop = new Label(component, SWT.NULL);
Messages.setLanguageTooltip(menu_drop, "TagSettingsView.title");
FontData fontData = menu_drop.getFont().getFontData()[0];
Display display = menu_drop.getDisplay();
italic_font = new Font(display, new FontData(fontData.getName(), fontData.getHeight(), SWT.ITALIC));
bold_font = new Font(display, new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
big_font = new Font(display, new FontData(fontData.getName(), (int) (fontData.getHeight() * 1.5), SWT.BOLD));
small_font = new Font(display, new FontData(fontData.getName(), (int) (fontData.getHeight() * 0.5), SWT.BOLD));
ftux_dark_bg = new Color(display, 183, 200, 212);
ftux_dark_fg = new Color(display, 0, 81, 134);
ftux_light_bg = new Color(display, 236, 242, 246);
component.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent arg0) {
Font[] fonts = { italic_font, bold_font, big_font, small_font };
for (Font f : fonts) {
if (f != null) {
f.dispose();
}
}
Color[] colours = { ftux_dark_bg, ftux_dark_fg, ftux_light_bg };
for (Color c : colours) {
if (c != null) {
c.dispose();
}
}
if (drop_targets != null) {
for (DropTarget dt : drop_targets) {
dt.dispose();
}
}
closed();
}
});
status = new BufferedLabel(component, SWT.LEFT | SWT.DOUBLE_BUFFERED);
GridData grid_data = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(status, grid_data);
status.setText(MessageText.getString("PeersView.state.pending"));
Image image = ImageLoader.getInstance().getImage("cog_down");
menu_drop.setImage(image);
grid_data = new GridData();
grid_data.widthHint = image.getBounds().width;
grid_data.heightHint = image.getBounds().height;
Utils.setLayoutData(menu_drop, grid_data);
menu_drop.setCursor(menu_drop.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
Control status_control = status.getControl();
final Menu status_menu = new Menu(status_control);
status.getControl().setMenu(status_menu);
menu_drop.setMenu(status_menu);
menu_drop.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent event) {
try {
Point p = status_menu.getDisplay().map(menu_drop, null, event.x, event.y);
status_menu.setLocation(p);
status_menu.setVisible(true);
} catch (Throwable e) {
Debug.out(e);
}
}
});
if (public_chat) {
Menu status_clip_menu = new Menu(component.getShell(), SWT.DROP_DOWN);
MenuItem status_clip_item = new MenuItem(status_menu, SWT.CASCADE);
status_clip_item.setMenu(status_clip_menu);
status_clip_item.setText(MessageText.getString("label.copy.to.clipboard"));
MenuItem status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.key"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard(chat.getKey());
}
});
status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.url"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard(chat.getURL());
}
});
status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.copy.rss.url"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard("azplug:?id=azbuddy&arg=" + UrlUtils.encode(chat.getURL() + "&format=rss"));
}
});
status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.pk"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard(Base32.encode(chat.getPublicKey()));
}
});
status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.export"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard(chat.export());
}
});
if (!chat.isManaged()) {
Menu status_channel_menu = new Menu(component.getShell(), SWT.DROP_DOWN);
MenuItem status_channel_item = new MenuItem(status_menu, SWT.CASCADE);
status_channel_item.setMenu(status_channel_menu);
status_channel_item.setText(MessageText.getString("azbuddy.dchat.rchans"));
// Managed channel
status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.rchans.managed"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
try {
ChatInstance inst = chat.getManagedChannel();
BuddyPluginViewBetaChat.createChatWindow(view, plugin, inst);
} catch (Throwable e) {
Debug.out(e);
}
}
});
// RO channel
status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.rchans.ro"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
try {
ChatInstance inst = chat.getReadOnlyChannel();
createChatWindow(view, plugin, inst);
} catch (Throwable e) {
Debug.out(e);
}
}
});
// Random sub-channel
status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.rchans.rand"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
try {
byte[] rand = new byte[20];
RandomUtils.nextSecureBytes(rand);
ChatInstance inst = beta.getChat(chat.getNetwork(), chat.getKey() + " {" + Base32.encode(rand) + "}");
createChatWindow(view, plugin, inst);
} catch (Throwable e) {
Debug.out(e);
}
}
});
if (beta.isI2PAvailable()) {
status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
status_mi.setText(MessageText.getString(chat.getNetwork() == AENetworkClassifier.AT_I2P ? "azbuddy.dchat.rchans.pub" : "azbuddy.dchat.rchans.anon"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
try {
ChatInstance inst = beta.getChat(chat.getNetwork() == AENetworkClassifier.AT_I2P ? AENetworkClassifier.AT_PUBLIC : AENetworkClassifier.AT_I2P, chat.getKey());
createChatWindow(view, plugin, inst);
} catch (Throwable e) {
Debug.out(e);
}
}
});
}
}
final MenuItem fave_mi = new MenuItem(status_menu, SWT.CHECK);
fave_mi.setText(MessageText.getString("label.fave"));
fave_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setFavourite(fave_mi.getSelection());
}
});
final MenuItem sis_mi = new MenuItem(status_menu, SWT.PUSH);
sis_mi.setText(MessageText.getString(Utils.isAZ2UI() ? "label.show.in.tab" : "label.show.in.sidebar"));
sis_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
BuddyPluginUI.openChat(chat.getNetwork(), chat.getKey());
}
});
addFriendsMenu(status_menu);
// advanced
final Menu advanced_menu = new Menu(status_menu.getShell(), SWT.DROP_DOWN);
MenuItem advanced_menu_item = new MenuItem(status_menu, SWT.CASCADE);
advanced_menu_item.setMenu(advanced_menu);
advanced_menu_item.setText(MessageText.getString("MyTorrentsView.menu.advancedmenu"));
// rename
final MenuItem rename_mi = new MenuItem(advanced_menu, SWT.PUSH);
rename_mi.setText(MessageText.getString("MyTorrentsView.menu.rename"));
rename_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String name = chat.getDisplayName();
if (name == null) {
name = chat.getName();
}
UISWTInputReceiver entry = new SimpleTextEntryWindow();
entry.setPreenteredText(name, false);
entry.maintainWhitespace(false);
entry.allowEmptyInput(false);
entry.setLocalisedTitle(MessageText.getString("label.rename", new String[] { name }));
entry.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entry) {
if (!entry.hasSubmittedInput()) {
return;
}
String input = entry.getSubmittedInput().trim();
if (input.length() > 0) {
try {
chat.setDisplayName(input);
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
}
});
}
});
// view type
final Menu vt_menu = new Menu(status_menu.getShell(), SWT.DROP_DOWN);
MenuItem vt_menu_item = new MenuItem(advanced_menu, SWT.CASCADE);
vt_menu_item.setMenu(vt_menu);
vt_menu_item.setText(MessageText.getString("menu.view.options"));
SelectionAdapter listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int vt = -1;
for (MenuItem mi : vt_menu.getItems()) {
if (mi.getSelection()) {
vt = (Integer) mi.getData();
}
}
if (vt != -1) {
chat.setViewType(vt);
buildSupport(main_component);
main_component.layout(true, true);
}
}
};
MenuItem vt_mi = new MenuItem(vt_menu, SWT.RADIO);
vt_mi.setText(MessageText.getString("label.full"));
vt_mi.setData(BuddyPluginBeta.VIEW_TYPE_DEFAULT);
vt_mi.addSelectionListener(listener);
vt_mi = new MenuItem(vt_menu, SWT.RADIO);
vt_mi.setText(MessageText.getString("ConfigView.section.sharing"));
vt_mi.setData(BuddyPluginBeta.VIEW_TYPE_SHARING);
if (chat.isReadOnly()) {
vt_mi.setEnabled(false);
}
vt_mi.addSelectionListener(listener);
vt_menu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
int vt = chat.getViewType();
for (MenuItem mi : vt_menu.getItems()) {
mi.setSelection(vt == (Integer) mi.getData());
}
}
});
// persist messages
final MenuItem persist_mi = new MenuItem(advanced_menu, SWT.CHECK);
persist_mi.setText(MessageText.getString("azbuddy.dchat.save.messages"));
persist_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setSaveMessages(persist_mi.getSelection());
}
});
final MenuItem log_mi = new MenuItem(advanced_menu, SWT.CHECK);
log_mi.setText(MessageText.getString("azbuddy.dchat.log.messages"));
log_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setLogMessages(log_mi.getSelection());
}
});
final MenuItem automute_mi = new MenuItem(advanced_menu, SWT.CHECK);
automute_mi.setText(MessageText.getString("azbuddy.dchat.auto.mute"));
automute_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setAutoMute(automute_mi.getSelection());
}
});
final MenuItem postnotifications_mi = new MenuItem(advanced_menu, SWT.CHECK);
postnotifications_mi.setText(MessageText.getString("azbuddy.dchat.post.to.notifcations"));
postnotifications_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setEnableNotificationsPost(postnotifications_mi.getSelection());
}
});
final MenuItem disableindicators_mi = new MenuItem(advanced_menu, SWT.CHECK);
disableindicators_mi.setText(MessageText.getString("azbuddy.dchat.disable.msg.indicators"));
disableindicators_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setDisableNewMsgIndications(disableindicators_mi.getSelection());
}
});
// setup menu
status_menu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
fave_mi.setSelection(chat.isFavourite());
persist_mi.setSelection(chat.getSaveMessages());
log_mi.setSelection(chat.getLogMessages());
automute_mi.setSelection(chat.getAutoMute());
postnotifications_mi.setSelection(chat.getEnableNotificationsPost());
boolean disable_indications = chat.getDisableNewMsgIndications();
disableindicators_mi.setSelection(disable_indications);
postnotifications_mi.setEnabled(!disable_indications);
}
});
} else {
final Menu status_priv_menu = new Menu(component.getShell(), SWT.DROP_DOWN);
MenuItem status_priv_item = new MenuItem(status_menu, SWT.CASCADE);
status_priv_item.setMenu(status_priv_menu);
status_priv_item.setText(MessageText.getString("label.private.chat"));
SelectionAdapter listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
beta.setPrivateChatState((Integer) ((MenuItem) e.widget).getData());
}
};
MenuItem status_mi = new MenuItem(status_priv_menu, SWT.RADIO);
status_mi.setText(MessageText.getString("label.enabled"));
status_mi.setData(BuddyPluginBeta.PRIVATE_CHAT_ENABLED);
status_mi.addSelectionListener(listener);
status_mi = new MenuItem(status_priv_menu, SWT.RADIO);
status_mi.setText(MessageText.getString("label.pinned.only"));
status_mi.setData(BuddyPluginBeta.PRIVATE_CHAT_PINNED_ONLY);
status_mi.addSelectionListener(listener);
status_mi = new MenuItem(status_priv_menu, SWT.RADIO);
status_mi.setText(MessageText.getString("label.disabled"));
status_mi.setData(BuddyPluginBeta.PRIVATE_CHAT_DISABLED);
status_mi.addSelectionListener(listener);
status_priv_menu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
int pc_state = beta.getPrivateChatState();
for (MenuItem mi : status_priv_menu.getItems()) {
mi.setSelection(pc_state == (Integer) mi.getData());
}
}
});
addFriendsMenu(status_menu);
final MenuItem keep_alive_mi = new MenuItem(status_menu, SWT.CHECK);
keep_alive_mi.setText(MessageText.getString("label.keep.alive"));
status_menu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
keep_alive_mi.setSelection(chat.getUserData("AC:KeepAlive") != null);
}
});
keep_alive_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ChatInstance clone = (ChatInstance) chat.getUserData("AC:KeepAlive");
if (clone != null) {
clone.destroy();
clone = null;
} else {
try {
clone = chat.getClone();
} catch (Throwable f) {
}
}
chat.setUserData("AC:KeepAlive", clone);
}
});
final MenuItem sis_mi = new MenuItem(status_menu, SWT.PUSH);
sis_mi.setText(MessageText.getString("label.show.in.sidebar"));
sis_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
BuddyPluginUI.openChat(chat.getNetwork(), chat.getKey());
}
});
}
}
use of com.biglybt.pif.ui.UIInputReceiverListener in project BiglyBT by BiglySoftware.
the class UIFunctionsImpl method promptForSearch.
@Override
public void promptForSearch() {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("Button.search", "search.dialog.text");
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver receiver) {
if (receiver.hasSubmittedInput()) {
doSearch(receiver.getSubmittedInput());
}
}
});
}
use of com.biglybt.pif.ui.UIInputReceiverListener 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.pif.ui.UIInputReceiverListener in project BiglyBT by BiglySoftware.
the class TorrentUtil method promptUserForComment.
public static void promptUserForComment(final DownloadManager[] dms) {
if (dms.length == 0) {
return;
}
DownloadManager dm = dms[0];
// Create dialog box.
String suggested = dm.getDownloadState().getUserComment();
String msg_key_prefix = "MyTorrentsView.menu.edit_comment.enter.";
SimpleTextEntryWindow text_entry = new SimpleTextEntryWindow();
text_entry.setTitle(msg_key_prefix + "title");
text_entry.setMessage(msg_key_prefix + "message");
text_entry.setPreenteredText(suggested, false);
text_entry.setMultiLine(true);
text_entry.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver text_entry) {
if (text_entry.hasSubmittedInput()) {
String value = text_entry.getSubmittedInput();
final String value_to_set = (value.length() == 0) ? null : value;
ListenerDMTask task = new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
dm.getDownloadState().setUserComment(value_to_set);
}
};
task.go();
}
}
});
}
use of com.biglybt.pif.ui.UIInputReceiverListener in project BiglyBT by BiglySoftware.
the class MenuFactory method addSpeedLimitsToMenu.
public static MenuItem addSpeedLimitsToMenu(final Menu menuParent) {
MenuItem speedLimitsMenuItem = createTopLevelMenuItem(menuParent, MENU_ID_SPEED_LIMITS);
MenuBuildUtils.addMaintenanceListenerForMenu(speedLimitsMenuItem.getMenu(), new MenuBuildUtils.MenuBuilder() {
@Override
public void buildMenu(Menu menu, MenuEvent menuEvent) {
if (CoreFactory.isCoreRunning()) {
Core core = CoreFactory.getSingleton();
final SpeedLimitHandler slh = SpeedLimitHandler.getSingleton(core);
MenuItem viewCurrentItem = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(viewCurrentItem, "MainWindow.menu.speed_limits.view_current");
viewCurrentItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
showText("MainWindow.menu.speed_limits.info.title", "MainWindow.menu.speed_limits.info.curr", slh.getCurrent());
}
});
java.util.List<String> profiles = slh.getProfileNames();
Menu profiles_menu = new Menu(Utils.findAnyShell(), SWT.DROP_DOWN);
MenuItem profiles_item = new MenuItem(menu, SWT.CASCADE);
profiles_item.setMenu(profiles_menu);
Messages.setLanguageText(profiles_item, "MainWindow.menu.speed_limits.profiles");
if (profiles.size() == 0) {
profiles_item.setEnabled(false);
} else {
for (final String p : profiles) {
Menu profile_menu = new Menu(Utils.findAnyShell(), SWT.DROP_DOWN);
MenuItem profile_item = new MenuItem(profiles_menu, SWT.CASCADE);
profile_item.setMenu(profile_menu);
profile_item.setText(p);
MenuItem loadItem = new MenuItem(profile_menu, SWT.PUSH);
Messages.setLanguageText(loadItem, "MainWindow.menu.speed_limits.load");
loadItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
showText("MainWindow.menu.speed_limits.info.title", MessageText.getString("MainWindow.menu.speed_limits.info.prof", new String[] { p }), slh.loadProfile(p));
}
});
MenuItem viewItem = new MenuItem(profile_menu, SWT.PUSH);
Messages.setLanguageText(viewItem, "MainWindow.menu.speed_limits.view");
viewItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
showText("MainWindow.menu.speed_limits.info.title", MessageText.getString("MainWindow.menu.speed_limits.info.prof", new String[] { p }), slh.getProfile(p));
}
});
addSeparatorMenuItem(profile_menu);
MenuItem deleteItem = new MenuItem(profile_menu, SWT.PUSH);
Messages.setLanguageText(deleteItem, "MainWindow.menu.speed_limits.delete");
deleteItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
slh.deleteProfile(p);
}
});
}
}
MenuItem saveItem = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(saveItem, "MainWindow.menu.speed_limits.save_current");
saveItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
UISWTInputReceiver entry = new SimpleTextEntryWindow();
entry.allowEmptyInput(false);
entry.setLocalisedTitle(MessageText.getString("MainWindow.menu.speed_limits.profile"));
entry.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entry) {
if (!entry.hasSubmittedInput()) {
return;
}
String input = entry.getSubmittedInput().trim();
if (input.length() > 0) {
showText("MainWindow.menu.speed_limits.info.title", MessageText.getString("MainWindow.menu.speed_limits.info.prof", new String[] { input }), slh.saveProfile(input));
}
}
});
}
});
addSeparatorMenuItem(menu);
MenuItem resetItem = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(resetItem, "MainWindow.menu.speed_limits.reset");
resetItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
showText("MainWindow.menu.speed_limits.info.title", "MainWindow.menu.speed_limits.info.curr", slh.reset());
}
});
addSeparatorMenuItem(menu);
MenuItem scheduleItem = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(scheduleItem, "MainWindow.menu.speed_limits.schedule");
scheduleItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
Utils.execSWTThreadLater(1, new Runnable() {
@Override
public void run() {
java.util.List<String> lines = slh.getSchedule();
StringBuilder text = new StringBuilder(80 * lines.size());
for (String s : lines) {
if (text.length() > 0) {
text.append("\n");
}
text.append(s);
}
final TextViewerWindow viewer = new TextViewerWindow("MainWindow.menu.speed_limits.schedule.title", "MainWindow.menu.speed_limits.schedule.msg", text.toString(), false);
viewer.setEditable(true);
viewer.addListener(new TextViewerWindow.TextViewerWindowListener() {
@Override
public void closed() {
if (viewer.getOKPressed()) {
String text = viewer.getText();
String[] lines = text.split("\n");
java.util.List<String> updated_lines = new ArrayList<>(Arrays.asList(lines));
java.util.List<String> result = slh.setSchedule(updated_lines);
if (result != null && result.size() > 0) {
showText("MainWindow.menu.speed_limits.schedule.title", "MainWindow.menu.speed_limits.schedule.err", result);
}
}
}
});
}
});
}
});
addSeparatorMenuItem(menu);
MenuItem helpItem = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(helpItem, "MainWindow.menu.speed_limits.wiki");
helpItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
Utils.launch(MessageText.getString("MainWindow.menu.speed_limits.wiki.url"));
}
});
}
}
});
return (speedLimitsMenuItem);
}
Aggregations