use of com.biglybt.pif.ui.UIManager 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.ui.UIManager in project BiglyBT by BiglySoftware.
the class TorrentOpener method mergeFileIntoTorrentInfo.
/**
* Creates a TorrentInfo from a file. Prompts user if the file is invalid,
* torrent already exists
*
* @param sFileName
* @param sOriginatingLocation
* @return
* @since 5.0.0.1
*/
// TODO: i18n
public static boolean mergeFileIntoTorrentInfo(String sFileName, final String sOriginatingLocation, TorrentOpenOptions torrentOptions) {
TOTorrent torrent = null;
File torrentFile;
boolean bDeleteFileOnCancel = false;
// actually made a copy.
try {
if (sFileName.startsWith("file://localhost/")) {
sFileName = UrlUtils.decode(sFileName.substring(16));
}
final File fOriginal = new File(sFileName);
if (!fOriginal.isFile() || !fOriginal.exists()) {
UIFunctionsManager.getUIFunctions().showErrorMessage("OpenTorrentWindow.mb.openError", fOriginal.toString(), new String[] { UrlUtils.decode(sOriginatingLocation), "Not a File" });
return false;
}
if (fOriginal.length() > TorrentUtils.MAX_TORRENT_FILE_SIZE) {
UIFunctionsManager.getUIFunctions().showErrorMessage("OpenTorrentWindow.mb.openError", fOriginal.toString(), new String[] { UrlUtils.decode(sOriginatingLocation), "Too large to be a torrent" });
return false;
}
torrentFile = TorrentUtils.copyTorrentFileToSaveDir(fOriginal, true);
bDeleteFileOnCancel = !fOriginal.equals(torrentFile);
// TODO if the files are still equal, and it isn't in the save
// dir, we should copy it to a temp file in case something
// re-writes it. No need to copy a torrent coming from the
// downloader though..
} catch (IOException e1) {
// Use torrent in wherever it is and hope for the best
// XXX Should error instead?
Debug.out(e1);
torrentFile = new File(sFileName);
}
VuzeFileHandler vfh = VuzeFileHandler.getSingleton();
VuzeFile vf = vfh.loadVuzeFile(torrentFile);
if (vf != null) {
vfh.handleFiles(new VuzeFile[] { vf }, VuzeFileComponent.COMP_TYPE_NONE);
return false;
}
if (RSSUtils.isRSSFeed(torrentFile)) {
boolean done = false;
try {
URL url = new URL(sOriginatingLocation);
UIManager ui_manager = StaticUtilities.getUIManager(10 * 1000);
if (ui_manager != null) {
String details = MessageText.getString("subscription.request.add.message", new String[] { sOriginatingLocation });
long res = ui_manager.showMessageBox("subscription.request.add.title", "!" + details + "!", UIManagerEvent.MT_YES | UIManagerEvent.MT_NO);
if (res == UIManagerEvent.MT_YES) {
SubscriptionManager sm = PluginInitializer.getDefaultInterface().getUtilities().getSubscriptionManager();
sm.requestSubscription(url);
done = true;
}
}
} catch (Throwable e) {
Debug.out(e);
}
if (done) {
if (bDeleteFileOnCancel) {
torrentFile.delete();
}
return false;
}
}
// Do a quick check to see if it's a torrent
if (!TorrentUtil.isFileTorrent(sOriginatingLocation, torrentFile, torrentFile.getName(), !torrentOptions.getHideErrors())) {
if (bDeleteFileOnCancel) {
torrentFile.delete();
}
return false;
}
// Load up the torrent, see it it's real
try {
torrent = TorrentUtils.readFromFile(torrentFile, false);
} catch (final TOTorrentException e) {
UIFunctionsManager.getUIFunctions().showErrorMessage("OpenTorrentWindow.mb.openError", Debug.getStackTrace(e), new String[] { sOriginatingLocation, e.getMessage() });
if (bDeleteFileOnCancel)
torrentFile.delete();
return false;
}
if (bDeleteFileOnCancel) {
torrentOptions.setDeleteFileOnCancel(bDeleteFileOnCancel);
}
torrentOptions.sFileName = torrentFile.getAbsolutePath();
torrentOptions.setTorrent(torrent);
torrentOptions.sOriginatingLocation = sOriginatingLocation;
return torrentOptions.getTorrent() != null;
}
use of com.biglybt.pif.ui.UIManager in project BiglyBT by BiglySoftware.
the class PlatformManagerImpl method informUpdateRequired.
private boolean informUpdateRequired() {
UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
long res = ui_manager.showMessageBox("update.now.title", "update.now.desc", UIManagerEvent.MT_OK | UIManagerEvent.MT_CANCEL);
return (res == UIManagerEvent.MT_OK);
}
use of com.biglybt.pif.ui.UIManager in project BiglyBT by BiglySoftware.
the class PluginUpdatePlugin method initialize.
@Override
public void initialize(PluginInterface _plugin_interface) {
plugin_interface = _plugin_interface;
plugin_interface.getPluginProperties().setProperty("plugin.version", "1.0");
plugin_interface.getPluginProperties().setProperty("plugin.name", "Plugin Updater");
log = plugin_interface.getLogger().getChannel("Plugin Update");
log.setDiagnostic();
log.setForce(true);
UIManager ui_manager = plugin_interface.getUIManager();
final BasicPluginViewModel model = ui_manager.createBasicPluginViewModel(PLUGIN_RESOURCE_ID);
final PluginConfig plugin_config = plugin_interface.getPluginconfig();
boolean enabled = plugin_config.getPluginBooleanParameter("enable.update", true);
model.setConfigSectionID(PLUGIN_CONFIGSECTION_ID);
model.getStatus().setText(enabled ? "Running" : "Optional checks disabled");
model.getActivity().setVisible(false);
model.getProgress().setVisible(false);
log.addListener(new LoggerChannelListener() {
@Override
public void messageLogged(int type, String message) {
model.getLogArea().appendText(message + "\n");
}
@Override
public void messageLogged(String str, Throwable error) {
model.getLogArea().appendText(error.toString() + "\n");
}
});
BasicPluginConfigModel config = ui_manager.createBasicPluginConfigModel(ConfigSection.SECTION_PLUGINS, PLUGIN_CONFIGSECTION_ID);
config.addBooleanParameter2("enable.update", "Plugin.pluginupdate.enablecheck", true);
plugin_interface.addEventListener(new PluginEventListener() {
@Override
public void handleEvent(PluginEvent ev) {
if (ev.getType() == PluginEvent.PEV_ALL_PLUGINS_INITIALISED) {
plugin_interface.removeEventListener(this);
initComplete(plugin_config);
}
}
});
}
use of com.biglybt.pif.ui.UIManager in project BiglyBT by BiglySoftware.
the class SBC_ChatOverview method preInitialize.
public static void preInitialize() {
UIManager ui_manager = PluginInitializer.getDefaultInterface().getUIManager();
ui_manager.addUIListener(new UIManagerListener() {
@Override
public void UIAttached(UIInstance instance) {
final MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
if (mdi == null) {
return;
}
mdi.registerEntry("Chat_.*", new MdiEntryCreationListener2() {
@Override
public MdiEntry createMDiEntry(MultipleDocumentInterface mdi, String id, Object datasource, Map<?, ?> params) {
ChatInstance chat = null;
if (datasource instanceof ChatInstance) {
chat = (ChatInstance) datasource;
try {
chat = chat.getClone();
} catch (Throwable e) {
chat = null;
Debug.out(e);
}
} else if (id.length() > 7) {
BuddyPluginBeta beta = BuddyPluginUtils.getBetaPlugin();
if (beta != null) {
try {
String[] bits = id.substring(5).split(":");
String network = AENetworkClassifier.internalise(bits[0]);
String key = new String(Base32.decode(bits[1]), "UTF-8");
chat = beta.getChat(network, key);
} catch (Throwable e) {
Debug.out(e);
}
}
}
if (chat != null) {
chat.setAutoNotify(true);
return (createChatMdiEntry(chat));
}
return (null);
}
});
}
@Override
public void UIDetached(UIInstance instance) {
}
});
}
Aggregations