use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.
the class BaseMdiEntry method exportStandAlone.
public Map<String, Object> exportStandAlone() {
Map<String, Object> result = new HashMap<>();
result.put("mdi", (this instanceof SideBarEntrySWT) ? "sidebar" : "tabbed");
String title = null;
ViewTitleInfo vti = getViewTitleInfo();
if (vti != null) {
title = (String) vti.getTitleInfoProperty(ViewTitleInfo.TITLE_TEXT);
}
if (title == null || title.length() == 0) {
title = getFullTitle();
}
result.put("title", title);
result.put("skin_ref", getSkinRef());
result.put("skin_id", skin.getSkinID());
result.put("parent_id", getParentID());
result.put("id", id);
Object data_source = getDatasourceCore();
if (data_source == null) {
data_source = getInitialDataSource();
}
if (data_source != null) {
if (data_source instanceof String) {
result.put("data_source", data_source);
} else if (data_source instanceof Integer) {
List l = new ArrayList();
l.add("i");
l.add(((Integer) data_source).longValue());
result.put("data_source", l);
} else {
result.put("data_source", DataSourceResolver.exportDataSource(data_source));
}
}
result.put("control_type", getControlType());
UISWTViewEventListener listener = getEventListener();
if (listener instanceof UISWTViewCoreEventListenerEx) {
CloneConstructor cc = ((UISWTViewCoreEventListenerEx) listener).getCloneConstructor();
String name = cc.getCloneClass().getName();
Map<String, Object> map = new HashMap<>();
map.put("name", name);
List<Object> params = cc.getParameters();
if (params != null) {
List p_types = new ArrayList<>();
List p_vals = new ArrayList<>();
map.put("p_types", p_types);
map.put("p_vals", p_vals);
for (Object p : params) {
if (p instanceof Boolean) {
p_types.add("bool");
p_vals.add(new Long(((Boolean) p) ? 1 : 0));
} else if (p instanceof Long) {
p_types.add("long");
p_vals.add(p);
} else if (p instanceof String) {
p_types.add("string");
p_vals.add(p);
} else {
Debug.out("Unsupported param type: " + p);
}
}
}
result.put("event_listener", map);
} else if (listener instanceof UISWTViewEventListenerEx) {
com.biglybt.ui.swt.pif.UISWTViewEventListenerEx.CloneConstructor cc = ((UISWTViewEventListenerEx) listener).getCloneConstructor();
PluginInterface pi = cc.getPluginInterface();
Map<String, Object> map = new HashMap<>();
map.put("plugin_id", pi.getPluginID());
map.put("plugin_name", pi.getPluginName());
map.put("ipc_method", cc.getIPCMethod());
List<Object> params = cc.getIPCParameters();
if (params != null) {
List p_types = new ArrayList<>();
List p_vals = new ArrayList<>();
map.put("p_types", p_types);
map.put("p_vals", p_vals);
for (Object p : params) {
if (p instanceof Boolean) {
p_types.add("bool");
p_vals.add(new Long(((Boolean) p) ? 1 : 0));
} else if (p instanceof Long) {
p_types.add("long");
p_vals.add(p);
} else if (p instanceof String) {
p_types.add("string");
p_vals.add(p);
} else {
Debug.out("Unsupported param type: " + p);
}
}
}
result.put("event_listener", map);
}
return (result);
}
use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.
the class TabbedMDI method addMenus.
private void addMenus(TabbedEntry entry, String id) {
PluginManager pm = CoreFactory.getSingleton().getPluginManager();
PluginInterface pi = pm.getDefaultPluginInterface();
UIManager uim = pi.getUIManager();
MenuManager menuManager = uim.getMenuManager();
{
if (!Utils.isAZ2UI()) {
com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem(id + "._end_", "menu.add.to.dashboard");
menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menuItem.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
// pick up the right target - due to the confusion of multiple tab instances registering
// the same menu entries the original registerer may well not be the one that should receive the event,
// rather the one specified in the event is
TabbedEntry target = entry;
if (data instanceof Object[]) {
Object[] odata = (Object[]) data;
if (odata.length == 1 && odata[0] instanceof TabbedEntry) {
target = (TabbedEntry) odata[0];
}
}
menu.setVisible(target.canBuildStandAlone());
}
});
menuItem.addListener(new MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
TabbedEntry target = entry;
if (data instanceof Object[]) {
Object[] odata = (Object[]) data;
if (odata.length == 1 && odata[0] instanceof TabbedEntry) {
target = (TabbedEntry) odata[0];
}
} else if (data instanceof TabbedEntry) {
target = (TabbedEntry) data;
}
MainMDISetup.getSb_dashboard().addItem(target);
}
});
}
}
{
com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem(id + "._end_", "menu.pop.out");
menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {
@Override
public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
TabbedEntry target = entry;
if (data instanceof Object[]) {
Object[] odata = (Object[]) data;
if (odata.length == 1 && odata[0] instanceof TabbedEntry) {
target = (TabbedEntry) odata[0];
}
}
menu.setVisible(target.canBuildStandAlone());
}
});
menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
TabbedEntry target = entry;
if (data instanceof Object[]) {
Object[] odata = (Object[]) data;
if (odata.length == 1 && odata[0] instanceof TabbedEntry) {
target = (TabbedEntry) odata[0];
}
} else if (data instanceof TabbedEntry) {
target = (TabbedEntry) data;
}
SkinnedDialog skinnedDialog = new SkinnedDialog("skin3_dlg_sidebar_popout", "shell", // standalone
null, SWT.RESIZE | SWT.MAX | SWT.DIALOG_TRIM);
SWTSkin skin = skinnedDialog.getSkin();
SWTSkinObjectContainer cont = target.buildStandAlone((SWTSkinObjectContainer) skin.getSkinObject("content-area"));
if (cont != null) {
Object ds = target.getDatasource();
if (ds instanceof Object[]) {
Object[] temp = (Object[]) ds;
if (temp.length > 0) {
ds = temp[0];
}
}
String ds_str = "";
if (ds instanceof Download) {
ds_str = ((Download) ds).getName();
} else if (ds instanceof DownloadManager) {
ds_str = ((DownloadManager) ds).getDisplayName();
}
skinnedDialog.setTitle(target.getTitle() + (ds_str.length() == 0 ? "" : (" - " + ds_str)));
skinnedDialog.open();
} else {
skinnedDialog.close();
}
}
});
}
}
use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.
the class MenuFactory method handleShowChanges.
private static void handleShowChanges() {
final String NL = "\r\n";
StringWriter content = new StringWriter();
content.append("**** Please review the contents of this before submitting it ****" + NL + NL);
content.append("Settings" + NL);
IndentWriter iw = new IndentWriter(new PrintWriter(content));
iw.indent();
try {
COConfigurationManager.dumpConfigChanges(iw);
} finally {
iw.exdent();
iw.close();
}
Core core = CoreFactory.getSingleton();
content.append("Plugins" + NL);
PluginInterface[] plugins = core.getPluginManager().getPlugins();
for (PluginInterface pi : plugins) {
if (pi.getPluginState().isBuiltIn()) {
continue;
}
content.append(" ").append(pi.getPluginName()).append(": ").append(pi.getPluginVersion()).append(NL);
}
java.util.List<DownloadManager> dms = core.getGlobalManager().getDownloadManagers();
content.append("Downloads - ").append(String.valueOf(dms.size())).append(NL);
iw = new IndentWriter(new PrintWriter(content));
iw.indent();
try {
for (DownloadManager dm : dms) {
String hash_str;
try {
byte[] hash = dm.getTorrent().getHash();
hash_str = Base32.encode(hash).substring(0, 16);
} catch (Throwable e) {
hash_str = "<no hash>";
}
iw.println(hash_str + ": " + DisplayFormatters.formatDownloadStatus(dm));
iw.indent();
dm.getDownloadState().dump(iw);
try {
} finally {
iw.exdent();
}
}
} finally {
iw.exdent();
iw.close();
}
content.append("Categories" + NL);
Category[] cats = CategoryManager.getCategories();
iw = new IndentWriter(new PrintWriter(content));
iw.indent();
try {
for (Category cat : cats) {
iw.println(cat.getName());
iw.indent();
try {
cat.dump(iw);
} finally {
iw.exdent();
}
}
} finally {
iw.exdent();
iw.close();
}
content.append("Speed Limits" + NL);
iw = new IndentWriter(new PrintWriter(content));
iw.indent();
try {
SpeedLimitHandler.getSingleton(core).dump(iw);
} finally {
iw.exdent();
iw.close();
}
new TextViewerWindow(MessageText.getString("config.changes.title"), null, content.toString(), false);
}
use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.
the class ManagerUtils method asyncStopDelete.
public static void asyncStopDelete(final DownloadManager dm, final int stateAfterStopped, final boolean bDeleteTorrent, final boolean bDeleteData, final AERunnable deleteFailed) {
TorrentUtils.startTorrentDelete();
final boolean[] endDone = { false };
try {
async.dispatch(new AERunnable() {
@Override
public void runSupport() {
try {
// I would move the FLAG_DO_NOT_DELETE_DATA_ON_REMOVE even deeper
// but I fear what could possibly go wrong.
boolean reallyDeleteData = bDeleteData && !dm.getDownloadState().getFlag(Download.FLAG_DO_NOT_DELETE_DATA_ON_REMOVE);
dm.getGlobalManager().removeDownloadManager(dm, bDeleteTorrent, reallyDeleteData);
} catch (GlobalManagerDownloadRemovalVetoException f) {
try {
PluginInterface pi = CoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface();
ShareManager sm = pi.getShareManager();
Tracker tracker = pi.getTracker();
ShareResource[] shares = sm.getShares();
TOTorrent torrent = dm.getTorrent();
byte[] target_hash = torrent.getHash();
for (ShareResource share : shares) {
int type = share.getType();
byte[] hash;
if (type == ShareResource.ST_DIR) {
hash = ((ShareResourceDir) share).getItem().getTorrent().getHash();
} else if (type == ShareResource.ST_FILE) {
hash = ((ShareResourceFile) share).getItem().getTorrent().getHash();
} else {
hash = null;
}
if (hash != null) {
if (Arrays.equals(target_hash, hash)) {
try {
dm.stopIt(DownloadManager.STATE_STOPPED, false, false);
} catch (Throwable e) {
}
try {
TrackerTorrent tracker_torrent = tracker.getTorrent(PluginCoreUtils.wrap(torrent));
if (tracker_torrent != null) {
tracker_torrent.stop();
}
} catch (Throwable e) {
}
share.delete();
return;
}
}
}
} catch (Throwable e) {
}
if (!f.isSilent()) {
UIFunctionsManager.getUIFunctions().forceNotify(UIFunctions.STATUSICON_WARNING, MessageText.getString("globalmanager.download.remove.veto"), f.getMessage(), null, null, -1);
// Logger.log(new LogAlert(dm, false,
// "{globalmanager.download.remove.veto}", f));
}
if (deleteFailed != null) {
deleteFailed.runSupport();
}
} catch (Exception ex) {
Debug.printStackTrace(ex);
if (deleteFailed != null) {
deleteFailed.runSupport();
}
} finally {
synchronized (endDone) {
if (!endDone[0]) {
TorrentUtils.endTorrentDelete();
endDone[0] = true;
}
}
}
}
});
} catch (Throwable e) {
synchronized (endDone) {
if (!endDone[0]) {
TorrentUtils.endTorrentDelete();
endDone[0] = true;
}
}
Debug.out(e);
}
}
use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.
the class PlatformManagerImpl method getInstaller.
private UpdateInstaller getInstaller(Core core) throws Exception {
// we don't want our update to interfere with the normal update process so
// hang around until it completes
PluginInterface pi = core.getPluginManager().getDefaultPluginInterface();
UpdateManager update_manager = pi.getUpdateManager();
final List<UpdateCheckInstance> l_instances = new ArrayList<>();
update_manager.addListener(new UpdateManagerListener() {
@Override
public void checkInstanceCreated(UpdateCheckInstance instance) {
synchronized (l_instances) {
l_instances.add(instance);
}
}
});
UpdateCheckInstance[] instances = update_manager.getCheckInstances();
l_instances.addAll(Arrays.asList(instances));
long start = SystemTime.getMonotonousTime();
while (true) {
if (SystemTime.getMonotonousTime() - start >= 5 * 60 * 1000) {
break;
}
try {
Thread.sleep(5000);
} catch (Throwable e) {
Debug.out(e);
return (null);
}
if (l_instances.size() > 0) {
boolean all_done = true;
for (UpdateCheckInstance instance : l_instances) {
if (!instance.isCompleteOrCancelled()) {
all_done = false;
break;
}
}
if (all_done) {
break;
}
}
}
if (update_manager.getInstallers().length > 0) {
return (null);
}
UpdateInstaller installer = pi.getUpdateManager().createInstaller();
return (installer);
}
Aggregations