use of com.biglybt.pif.PluginInterface 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.PluginInterface in project BiglyBT by BiglySoftware.
the class BaseMdiEntry method importStandAlone.
public static SWTSkinObjectContainer importStandAlone(SWTSkinObjectContainer soParent, Map<String, Object> map, Runnable callback) {
String mdi_type = (String) map.get("mdi");
String skin_ref = (String) map.get("skin_ref");
String skin_id = (String) map.get("skin_id");
SWTSkin skin = SWTSkinFactory.lookupSkin(skin_id);
String parent_id = (String) map.get("parent_id");
String id = (String) map.get("id");
Object data_source = map.get("data_source");
if (data_source != null) {
if (data_source instanceof Map) {
Map<String, Object> ds_map = (Map<String, Object>) data_source;
if (ds_map != null) {
ds_map = new HashMap<String, Object>(ds_map);
ds_map.put("callback", callback);
}
data_source = ds_map == null ? null : DataSourceResolver.importDataSource(ds_map);
} else if (data_source instanceof List) {
List l = (List) data_source;
String type = (String) l.get(0);
Long value = (Long) l.get(1);
if (type.equals("i")) {
data_source = value.intValue();
}
}
}
int control_type = ((Number) map.get("control_type")).intValue();
Map<String, Object> el_map = (Map<String, Object>) map.get("event_listener");
UISWTViewEventListener event_listener = null;
if (el_map != null) {
try {
String class_name = (String) el_map.get("name");
if (class_name != null) {
Class<? extends UISWTViewCoreEventListenerEx> cla = (Class<? extends UISWTViewCoreEventListenerEx>) Class.forName(class_name);
List p_types = (List) el_map.get("p_types");
List p_vals = (List) el_map.get("p_vals");
if (p_types != null && !p_types.isEmpty()) {
List<Class> types = new ArrayList<>();
List<Object> args = new ArrayList<>();
for (int i = 0; i < p_types.size(); i++) {
String type = (String) p_types.get(i);
Object val = p_vals.get(i);
if (type.equals("bool")) {
types.add(boolean.class);
args.add(((Long) val) != 0);
} else if (type.equals("long")) {
types.add(long.class);
args.add((Long) val);
} else if (type.equals("string")) {
types.add(String.class);
args.add((String) val);
} else {
Debug.out("Unsupported type: " + type);
}
}
event_listener = cla.getConstructor(types.toArray(new Class<?>[types.size()])).newInstance(args.toArray(new Object[args.size()]));
} else {
event_listener = cla.newInstance();
}
} else {
String plugin_id = (String) el_map.get("plugin_id");
PluginInterface pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByID(plugin_id);
if (pi != null) {
String ipc_method = (String) el_map.get("ipc_method");
List p_types = (List) el_map.get("p_types");
List p_vals = (List) el_map.get("p_vals");
List<Object> args = new ArrayList<>();
if (p_types != null && !p_types.isEmpty()) {
List<Class> types = new ArrayList<>();
for (int i = 0; i < p_types.size(); i++) {
String type = (String) p_types.get(i);
Object val = p_vals.get(i);
if (type.equals("bool")) {
types.add(boolean.class);
args.add(((Long) val) != 0);
} else if (type.equals("long")) {
types.add(long.class);
args.add((Long) val);
} else if (type.equals("string")) {
types.add(String.class);
args.add((String) val);
} else {
Debug.out("Unsupported type: " + type);
}
}
}
event_listener = (UISWTViewEventListener) pi.getIPC().invoke(ipc_method, args.toArray(new Object[args.size()]));
} else {
boolean try_install = false;
synchronized (installing_pids) {
if (!installing_pids.contains(plugin_id)) {
installing_pids.add(plugin_id);
try_install = true;
}
}
if (try_install) {
boolean went_async = false;
try {
UIFunctions uif = UIFunctionsManager.getUIFunctions();
String plugin_name = (String) el_map.get("plugin_name");
String remember_id = "basemdi.import.view.install." + plugin_id;
String title = MessageText.getString("plugin.required");
String text = MessageText.getString("plugin.required.info", new String[] { plugin_name });
UIFunctionsUserPrompter prompter = uif.getUserPrompter(title, text, new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 0);
if (remember_id != null) {
prompter.setRemember(remember_id, false, MessageText.getString("MessageBoxWindow.nomoreprompting"));
}
prompter.setAutoCloseInMS(0);
prompter.open(null);
boolean install = prompter.waitUntilClosed() == 0;
if (install) {
went_async = true;
uif.installPlugin(plugin_id, "plugin.generic.install", new UIFunctions.actionListener() {
@Override
public void actionComplete(Object result) {
try {
if (callback != null) {
if (result instanceof Boolean) {
if ((Boolean) result) {
callback.run();
}
}
}
} finally {
synchronized (installing_pids) {
installing_pids.remove(plugin_id);
}
}
}
});
}
} finally {
if (!went_async) {
synchronized (installing_pids) {
installing_pids.remove(plugin_id);
}
}
}
}
}
}
} catch (Throwable e) {
Debug.out(e);
}
}
if (mdi_type.equals("sidebar")) {
return (SideBarEntrySWT.buildStandAlone(soParent, skin_ref, skin, parent_id, id, data_source, control_type, null, event_listener, true));
} else {
return (TabbedEntry.buildStandAlone(soParent, skin_ref, skin, parent_id, id, data_source, control_type, null, event_listener, true));
}
}
use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.
the class SearchHandler method handleSearch.
public static void handleSearch(String sSearchText, boolean toSubscribe) {
if (!toSubscribe) {
try {
if (COConfigurationManager.getBooleanParameter("rcm.overall.enabled", true) && COConfigurationManager.getBooleanParameter("Plugin.aercm.rcm.search.enable", false) && COConfigurationManager.getBooleanParameter("search.showRCMView") && CoreFactory.isCoreRunning()) {
final PluginInterface pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByID("aercm");
if (pi != null && pi.getPluginState().isOperational() && pi.getIPC().canInvoke("lookupByExpression", new Object[] { "" })) {
pi.getIPC().invoke("lookupByExpression", new Object[] { sSearchText });
}
}
} catch (Throwable e) {
Debug.out(e);
}
}
SearchResultsTabArea.SearchQuery sq = new SearchResultsTabArea.SearchQuery(sSearchText, toSubscribe);
MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
String id = MultipleDocumentInterface.SIDEBAR_SECTION_SEARCH + "." + Integer.toHexString(sSearchText.hashCode()) + (toSubscribe ? ".s" : "");
MdiEntry existingEntry = mdi.getEntry(id);
if (existingEntry != null && existingEntry.isAdded()) {
SearchResultsTabArea searchClass = (SearchResultsTabArea) SkinViewManager.getByClass(SearchResultsTabArea.class);
if (searchClass != null) {
searchClass.anotherSearch(sSearchText, toSubscribe);
}
existingEntry.setDatasource(sq);
mdi.showEntry(existingEntry);
return;
}
final MdiEntry entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_DISCOVERY, id, "main.area.searchresultstab", sSearchText, null, sq, true, MultipleDocumentInterface.SIDEBAR_POS_FIRST);
if (entry != null) {
entry.setImageLeftID("image.sidebar.search");
entry.setDatasource(sq);
entry.setViewTitleInfo(new ViewTitleInfoImplementation());
}
mdi.showEntryByID(id);
}
use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.
the class PrivacyView method initialize.
private void initialize() {
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);
}
GridLayout layout = new GridLayout(1, false);
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
cMainComposite.setLayout(layout);
GridData gd;
// overview
Composite overview_comp = new Composite(cMainComposite, SWT.NULL);
overview_comp.setLayout(new GridLayout(3, false));
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(overview_comp, gd);
Label label = new Label(overview_comp, SWT.NULL);
label.setText(MessageText.getString("privacy.view.intro"));
LinkLabel link = new LinkLabel(overview_comp, "label.read.more", MessageText.getString("privacy.view.wiki.url"));
// slider component
Composite slider_comp = new Composite(cMainComposite, SWT.NULL);
layout = new GridLayout(3, false);
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
// layout.marginWidth = 0;
slider_comp.setLayout(layout);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(slider_comp, gd);
label = new Label(slider_comp, SWT.NULL);
label.setText(MessageText.getString("privacy.view.level") + ":");
Composite slider2_comp = new Composite(slider_comp, SWT.NULL);
slider2_comp.setLayout(new GridLayout(6, true));
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(slider2_comp, gd);
label = new Label(slider2_comp, SWT.NULL);
label.setText(MessageText.getString("privacy.view.public.only"));
label = new Label(slider2_comp, SWT.NULL);
label.setText(MessageText.getString("privacy.view.public.anon"));
label.setAlignment(SWT.CENTER);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
Utils.setLayoutData(label, gd);
label = new Label(slider2_comp, SWT.NULL);
label.setText(MessageText.getString("privacy.view.anon.only"));
label.setAlignment(SWT.CENTER);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
Utils.setLayoutData(label, gd);
label = new Label(slider2_comp, SWT.NULL);
label.setText(MessageText.getString("label.invalid"));
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment = SWT.END;
Utils.setLayoutData(label, gd);
privacy_scale = new Scale(slider2_comp, SWT.HORIZONTAL);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 6;
Utils.setLayoutData(privacy_scale, gd);
privacy_scale.setMinimum(0);
privacy_scale.setMaximum(30);
final boolean[] slider_mouse_down = { false };
privacy_scale.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
int pos = privacy_scale.getSelection();
int level = ((pos + 5) / 10);
if (level * 10 != pos) {
privacy_scale.setSelection(level * 10);
}
setPrivacyLevel(level);
slider_mouse_down[0] = false;
}
@Override
public void mouseDown(MouseEvent e) {
slider_mouse_down[0] = true;
}
});
privacy_scale.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (!slider_mouse_down[0]) {
int pos = privacy_scale.getSelection();
int level = ((pos + 5) / 10);
setPrivacyLevel(level);
}
}
});
// network selection
Composite network_comp = new Composite(slider_comp, SWT.NULL);
gd = new GridData();
Utils.setLayoutData(network_comp, gd);
network_buttons = new Button[AENetworkClassifier.AT_NETWORKS.length];
network_comp.setLayout(new GridLayout(1, false));
label = new Label(network_comp, SWT.NULL);
label.setText(MessageText.getString("ConfigView.section.connection.group.networks") + ":");
for (int i = 0; i < network_buttons.length; i++) {
final String nn = AENetworkClassifier.AT_NETWORKS[i];
String msg_text = "ConfigView.section.connection.networks." + nn;
Button button = new Button(network_comp, SWT.CHECK);
Messages.setLanguageText(button, msg_text);
network_buttons[i] = button;
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean selected = ((Button) e.widget).getSelection();
if (current_dm != null) {
current_dm.getDownloadState().setNetworkEnabled(nn, selected);
}
}
});
GridData gridData = new GridData();
Utils.setLayoutData(button, gridData);
}
label = new Label(slider_comp, SWT.NULL);
final Composite tracker_webseed_comp = new Composite(slider_comp, SWT.NULL);
layout = new GridLayout(2, true);
layout.marginTop = layout.marginBottom = layout.marginLeft = layout.marginRight = 1;
tracker_webseed_comp.setLayout(layout);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
Utils.setLayoutData(tracker_webseed_comp, gd);
tracker_webseed_comp.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
Rectangle client_area = tracker_webseed_comp.getClientArea();
Rectangle rect = new Rectangle(0, 0, client_area.width - 1, client_area.height - 1);
e.gc.setAlpha(50);
e.gc.drawRectangle(rect);
}
});
// Tracker Info
Composite tracker_comp = new Composite(tracker_webseed_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(tracker_comp, gd);
tracker_comp.setLayout(new GridLayout(2, false));
label = new Label(tracker_comp, SWT.NULL);
label.setText(MessageText.getString("label.trackers") + ":");
tracker_info = new BufferedLabel(tracker_comp, SWT.DOUBLE_BUFFERED);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(tracker_info, gd);
// Webseed Info
Composite webseed_comp = new Composite(tracker_webseed_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(webseed_comp, gd);
webseed_comp.setLayout(new GridLayout(2, false));
label = new Label(webseed_comp, SWT.NULL);
label.setText(MessageText.getString("label.webseeds") + ":");
webseed_info = new BufferedLabel(webseed_comp, SWT.DOUBLE_BUFFERED);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(webseed_info, gd);
// Peer Info
// label = new Label( slider_comp, SWT.NULL );
Composite peer_comp = new Composite(tracker_webseed_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(peer_comp, gd);
peer_comp.setLayout(new GridLayout(2, false));
label = new Label(peer_comp, SWT.NULL);
label.setText(MessageText.getString("TableColumn.header.peers") + ":");
peer_info = new BufferedLabel(peer_comp, SWT.DOUBLE_BUFFERED);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(peer_info, gd);
// I2P install state
Group i2p_group = new Group(cMainComposite, SWT.NULL);
i2p_group.setText("I2P");
// Composite i2p_group = new Composite( cMainComposite, SWT.NULL );
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(i2p_group, gd);
i2p_group.setLayout(new GridLayout(4, false));
label = new Label(i2p_group, SWT.NULL);
label.setText(MessageText.getString("privacy.view.lookup.info"));
gd = new GridData();
gd.horizontalSpan = 2;
Utils.setLayoutData(label, gd);
label = new Label(i2p_group, SWT.NULL);
label.setText(MessageText.getString("label.lookup.status") + ":");
i2p_result_summary = new BufferedLabel(i2p_group, SWT.DOUBLE_BUFFERED);
gd = new GridData(GridData.FILL_HORIZONTAL);
// gd.horizontalIndent = 4;
Utils.setLayoutData(i2p_result_summary, gd);
Composite i2p_button_comp = new Composite(i2p_group, SWT.NULL);
i2p_button_comp.setLayout(new GridLayout(2, false));
gd = new GridData(GridData.FILL_VERTICAL);
Utils.setLayoutData(i2p_button_comp, gd);
label = new Label(i2p_button_comp, SWT.NULL);
label.setText(MessageText.getString("GeneralView.section.availability"));
i2p_install_button = new Button(i2p_button_comp, SWT.PUSH);
i2p_install_button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
final boolean[] result = { false };
I2PHelpers.installI2PHelper(null, result, new Runnable() {
@Override
public void run() {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
updateI2PState();
}
});
}
});
}
});
// I2P peer lookup
i2p_lookup_comp = new Composite(i2p_group, SWT.BORDER);
gd = new GridData();
gd.widthHint = 300;
gd.heightHint = 150;
Utils.setLayoutData(i2p_lookup_comp, gd);
i2p_lookup_comp.setBackground(Colors.white);
// i2p results
i2p_result_list = new Text(i2p_group, SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL | SWT.WRAP | SWT.NO_FOCUS);
gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 2;
Utils.setLayoutData(i2p_result_list, gd);
i2p_result_list.setEditable(false);
// i2p lookup button
label = new Label(i2p_button_comp, SWT.NULL);
label.setText(MessageText.getString("button.lookup.peers"));
i2p_lookup_button = new Button(i2p_button_comp, SWT.PUSH);
i2p_lookup_button.setText(MessageText.getString("button.search.dht"));
i2p_lookup_button.addSelectionListener(new SelectionAdapter() {
private int search_count;
@Override
public void widgetSelected(SelectionEvent event) {
Utils.disposeComposite(i2p_lookup_comp, false);
i2p_result_summary.setText("");
i2p_result_list.setText("");
PluginInterface i2p_pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByID("azneti2phelper", true);
if (i2p_pi != null) {
IPCInterface ipc = i2p_pi.getIPC();
Map<String, Object> options = new HashMap<>();
options.put("server_id", "Scraper");
options.put("server_id_transient", true);
options.put("ui_composite", i2p_lookup_comp);
final byte[] hash = (byte[]) i2p_lookup_button.getData("hash");
search_count++;
final int search_id = search_count;
IPCInterface callback = new IPCInterface() {
@Override
public Object invoke(String methodName, final Object[] params) throws IPCException {
if (search_id != search_count) {
return (null);
}
if (methodName.equals("statusUpdate")) {
final int status = (Integer) params[0];
if (status != TrackerPeerSource.ST_INITIALISING && status != TrackerPeerSource.ST_UPDATING) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (i2p_lookup_button.isDisposed() || hash != i2p_lookup_button.getData("hash")) {
return;
}
i2p_lookup_button.setEnabled(true);
if (i2p_result_list.getText().length() == 0 && status != TrackerPeerSource.ST_UNAVAILABLE) {
i2p_result_summary.setText(MessageText.getString("label.no.peers.found"));
}
}
});
}
if (params.length == 4) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (i2p_result_summary.isDisposed() || hash != i2p_lookup_button.getData("hash")) {
return;
}
int seeds = (Integer) params[1];
int leechers = (Integer) params[2];
int peers = (Integer) params[3];
i2p_result_summary.setText(MessageText.getString("privacy.view.lookup.msg", new String[] { String.valueOf(seeds), String.valueOf(leechers), String.valueOf(peers) }));
}
});
}
} else if (methodName.equals("msgUpdate")) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (i2p_result_summary.isDisposed() || hash != i2p_lookup_button.getData("hash")) {
return;
}
String msg = (String) params[0];
i2p_result_summary.setText(msg);
}
});
} else if (methodName.equals("peerFound")) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (i2p_result_list.isDisposed() || hash != i2p_lookup_button.getData("hash")) {
return;
}
String host = (String) params[0];
int peer_type = (Integer) params[1];
i2p_result_list.append(host + "\r\n");
}
});
}
return (null);
}
@Override
public boolean canInvoke(String methodName, Object[] params) {
return (true);
}
};
i2p_lookup_button.setEnabled(false);
i2p_result_summary.setText(MessageText.getString("label.searching"));
try {
ipc.invoke("lookupTorrent", new Object[] { "", hash, options, callback });
} catch (Throwable e) {
i2p_lookup_button.setEnabled(true);
e.printStackTrace();
}
}
}
});
Label i2p_options_info = new Label(i2p_button_comp, SWT.WRAP);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
gd.widthHint = 150;
Utils.setLayoutData(i2p_options_info, gd);
i2p_options_info.setText(MessageText.getString("privacy.view.check.bw.info"));
if (!COConfigurationManager.getBooleanParameter("privacy.view.check.bw.clicked", false)) {
FontData fontData = i2p_options_info.getFont().getFontData()[0];
final Font bold_font = new Font(i2p_options_info.getDisplay(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
i2p_options_info.setFont(bold_font);
i2p_options_info.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
bold_font.dispose();
}
});
}
i2p_options_link = new Label(i2p_button_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
Utils.setLayoutData(i2p_options_link, gd);
i2p_options_link.setText(MessageText.getString("privacy.view.check.bw"));
i2p_options_link.setCursor(i2p_options_link.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
i2p_options_link.setForeground(Colors.blue);
i2p_options_link.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent arg0) {
openOptions();
}
@Override
public void mouseUp(MouseEvent arg0) {
openOptions();
}
private void openOptions() {
COConfigurationManager.setParameter("privacy.view.check.bw.clicked", true);
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (uif != null) {
uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, "azi2phelper.name");
}
}
});
updateI2PState();
Utils.makeButtonsEqualWidth(Arrays.asList(new Button[] { i2p_install_button, i2p_lookup_button }));
label = new Label(i2p_button_comp, SWT.NULL);
gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 2;
Utils.setLayoutData(label, gd);
Group bottom_comp = new Group(cMainComposite, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(bottom_comp, gd);
bottom_comp.setLayout(new GridLayout(2, false));
// Torrent Info
label = new Label(bottom_comp, SWT.NULL);
label.setText(MessageText.getString("authenticator.torrent") + ":");
Composite torrent_comp = new Composite(bottom_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(torrent_comp, gd);
torrent_comp.setLayout(removeMarginsAndSpacing(new GridLayout(2, false)));
torrent_info = new BufferedLabel(torrent_comp, SWT.DOUBLE_BUFFERED);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(torrent_info, gd);
// source selection
label = new Label(bottom_comp, SWT.NULL);
label.setText(MessageText.getString("ConfigView.section.connection.group.peersources") + ":");
Composite sources_comp = new Composite(bottom_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(sources_comp, gd);
source_buttons = new Button[PEPeerSource.PS_SOURCES.length];
sources_comp.setLayout(removeMargins(new GridLayout(source_buttons.length + 1, false)));
for (int i = 0; i < source_buttons.length; i++) {
final String src = PEPeerSource.PS_SOURCES[i];
String msg_text = "ConfigView.section.connection.peersource." + src;
Button button = new Button(sources_comp, SWT.CHECK);
Messages.setLanguageText(button, msg_text);
source_buttons[i] = button;
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean selected = ((Button) e.widget).getSelection();
if (current_dm != null) {
current_dm.getDownloadState().setPeerSourceEnabled(src, selected);
}
}
});
GridData gridData = new GridData();
Utils.setLayoutData(button, gridData);
}
// IP Filter
label = new Label(bottom_comp, SWT.NULL);
label.setText(MessageText.getString("label.ip.filter") + ":");
Composite ipfilter_comp = new Composite(bottom_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(ipfilter_comp, gd);
ipfilter_comp.setLayout(removeMargins(new GridLayout(2, false)));
ipfilter_enabled = new Button(ipfilter_comp, SWT.CHECK);
ipfilter_enabled.setText(MessageText.getString("label.enabled"));
ipfilter_enabled.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
current_dm.getDownloadState().setFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER, !ipfilter_enabled.getSelection());
}
});
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(ipfilter_enabled, gd);
// VPN Info
label = new Label(bottom_comp, SWT.NULL);
label.setText(MessageText.getString("label.vpn.status") + ":");
Composite vpn_comp = new Composite(bottom_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(vpn_comp, gd);
vpn_comp.setLayout(removeMargins(new GridLayout(2, false)));
vpn_info = new BufferedLabel(vpn_comp, SWT.DOUBLE_BUFFERED);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(vpn_info, gd);
// SOCKS Info
label = new Label(bottom_comp, SWT.NULL);
label.setText(MessageText.getString("label.socks.status") + ":");
Composite socks_comp = new Composite(bottom_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(socks_comp, gd);
socks_comp.setLayout(removeMargins(new GridLayout(10, false)));
label = new Label(socks_comp, SWT.NULL);
label.setText(MessageText.getString("label.proxy") + ":");
socks_state = new BufferedLabel(socks_comp, SWT.DOUBLE_BUFFERED);
gd = new GridData();
gd.widthHint = 120;
Utils.setLayoutData(socks_state, gd);
// current details
label = new Label(socks_comp, SWT.NULL);
label.setText(MessageText.getString("PeersView.state") + ":");
socks_current = new BufferedLabel(socks_comp, SWT.DOUBLE_BUFFERED);
gd = new GridData();
gd.widthHint = 120;
Utils.setLayoutData(socks_current, gd);
// fail details
label = new Label(socks_comp, SWT.NULL);
label.setText(MessageText.getString("label.fails") + ":");
socks_fails = new BufferedLabel(socks_comp, SWT.DOUBLE_BUFFERED);
gd = new GridData();
gd.widthHint = 120;
Utils.setLayoutData(socks_fails, gd);
// more info
label = new Label(socks_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING;
socks_more = new Label(socks_comp, SWT.NULL);
socks_more.setText(MessageText.getString("label.more") + "...");
Utils.setLayoutData(socks_more, gd);
socks_more.setCursor(socks_more.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
socks_more.setForeground(Colors.blue);
socks_more.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent arg0) {
showSOCKSInfo();
}
@Override
public void mouseUp(MouseEvent arg0) {
showSOCKSInfo();
}
});
// the rest
sc.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
Rectangle r = sc.getClientArea();
Point size = cMainComposite.computeSize(r.width, SWT.DEFAULT);
sc.setMinSize(size);
}
});
swt_updateFields(null, current_dm);
updatePeersEtc(current_dm);
updateVPNSocks();
Rectangle r = sc.getClientArea();
Point size = cMainComposite.computeSize(r.width, SWT.DEFAULT);
sc.setMinSize(size);
Utils.relayout(cMainComposite);
}
use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.
the class MySharesView method startStopSelectedShares.
private void startStopSelectedShares(boolean do_stop) {
List items = getSelectedItems();
if (items.size() == 0) {
return;
}
PluginInterface pi = PluginInitializer.getDefaultInterface();
com.biglybt.pif.download.DownloadManager dm = pi.getDownloadManager();
Tracker tracker = pi.getTracker();
for (int i = 0; i < items.size(); i++) {
ShareItem item = (ShareItem) items.get(i);
try {
Torrent t = item.getTorrent();
TrackerTorrent tracker_torrent = tracker.getTorrent(t);
Download download = dm.getDownload(t);
if (tracker_torrent == null || download == null) {
continue;
}
int dl_state = download.getState();
if (dl_state == Download.ST_ERROR) {
} else if (dl_state != Download.ST_STOPPED) {
if (do_stop) {
try {
download.stop();
} catch (Throwable e) {
}
try {
tracker_torrent.stop();
} catch (Throwable e) {
}
}
} else {
if (!do_stop) {
try {
download.restart();
} catch (Throwable e) {
}
try {
tracker_torrent.start();
} catch (Throwable e) {
}
}
}
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
}
Aggregations