Search in sources :

Example 6 with PluginManager

use of com.biglybt.pif.PluginManager in project BiglyBT by BiglySoftware.

the class PlayUtils method getMediaServerContentURL.

public static URL getMediaServerContentURL(DiskManagerFileInfo file) {
    // TorrentListViewsUtils.debugDCAD("enter - getMediaServerContentURL");
    PluginManager pm = CoreFactory.getSingleton().getPluginManager();
    PluginInterface pi = pm.getPluginInterfaceByID("azupnpav", false);
    if (pi == null) {
        Logger.log(new LogEvent(LogIDs.UI3, "Media server plugin not found"));
        return null;
    }
    if (!pi.getPluginState().isOperational()) {
        Logger.log(new LogEvent(LogIDs.UI3, "Media server plugin not operational"));
        return null;
    }
    try {
        if (hasQuickTime == null) {
            UIFunctions uif = UIFunctionsManager.getUIFunctions();
            if (uif != null) {
                hasQuickTime = uif.isProgramInstalled(".qtl", "Quicktime");
                try {
                    pi.getIPC().invoke("setQuickTimeAvailable", new Object[] { hasQuickTime });
                } catch (Throwable e) {
                    Logger.log(new LogEvent(LogIDs.UI3, LogEvent.LT_WARNING, "IPC to media server plugin failed", e));
                }
            }
        }
        boolean use_peek = tls_non_block_indicator.get()[0] > 0;
        Object url;
        if (use_peek && pi.getIPC().canInvoke("peekContentURL", new Object[] { file })) {
            url = pi.getIPC().invoke("peekContentURL", new Object[] { file });
        } else {
            url = pi.getIPC().invoke("getContentURL", new Object[] { file });
        }
        if (url instanceof String) {
            return new URL((String) url);
        }
    } catch (Throwable e) {
        Logger.log(new LogEvent(LogIDs.UI3, LogEvent.LT_WARNING, "IPC to media server plugin failed", e));
    }
    return null;
}
Also used : PluginManager(com.biglybt.pif.PluginManager) LogEvent(com.biglybt.core.logging.LogEvent) UIFunctions(com.biglybt.ui.UIFunctions) PluginInterface(com.biglybt.pif.PluginInterface) URL(java.net.URL)

Example 7 with PluginManager

use of com.biglybt.pif.PluginManager in project BiglyBT by BiglySoftware.

the class Utils method handlePluginLaunch.

private static void handlePluginLaunch(String eb_choice, String net_type, boolean use_plugins, final String sFileOriginal, final String sFileModified, final boolean sync, final boolean force_url, final boolean force_anon) {
    PluginManager pm = CoreFactory.getSingleton().getPluginManager();
    if (net_type == AENetworkClassifier.AT_I2P) {
        if (pm.getPluginInterfaceByID("azneti2phelper") == null) {
            boolean try_it;
            synchronized (pending_ext_urls) {
                try_it = !i2p_install_active_for_url;
                i2p_install_active_for_url = true;
            }
            if (try_it) {
                ext_url_dispatcher.dispatch(new AERunnable() {

                    @Override
                    public void runSupport() {
                        boolean installing = false;
                        try {
                            final boolean[] install_outcome = { false };
                            installing = I2PHelpers.installI2PHelper("azneti2phelper.install", install_outcome, new Runnable() {

                                @Override
                                public void run() {
                                    try {
                                        if (install_outcome[0]) {
                                            Utils.launch(sFileOriginal, sync, force_url, force_anon);
                                        }
                                    } finally {
                                        synchronized (pending_ext_urls) {
                                            i2p_install_active_for_url = false;
                                        }
                                    }
                                }
                            });
                        } finally {
                            if (!installing) {
                                synchronized (pending_ext_urls) {
                                    i2p_install_active_for_url = false;
                                }
                            }
                        }
                    }
                });
            } else {
                Debug.out("I2P installation already active");
            }
            return;
        }
    }
    java.util.List<PluginInterface> pis = pm.getPluginsWithMethod("launchURL", new Class[] { URL.class, boolean.class, Runnable.class });
    boolean found = false;
    for (final PluginInterface pi : pis) {
        String id = "plugin:" + pi.getPluginID();
        if (eb_choice.equals("plugin") || id.equals(eb_choice)) {
            found = true;
            synchronized (pending_ext_urls) {
                if (pending_ext_urls.contains(sFileModified)) {
                    Debug.outNoStack("Already queued browser request for '" + sFileModified + "' - ignoring");
                    return;
                }
                pending_ext_urls.add(sFileModified);
            }
            AERunnable launch = new AERunnable() {

                @Override
                public void runSupport() {
                    try {
                        final AESemaphore sem = new AESemaphore("wait");
                        pi.getIPC().invoke("launchURL", new Object[] { new URL(sFileModified), false, new Runnable() {

                            @Override
                            public void run() {
                                sem.release();
                            }
                        } });
                        if (!sem.reserve(30 * 1000)) {
                        // can happen when user is prompted to accept the launch or not and is
                        // slow in replying
                        // Debug.out( "Timeout waiting for external url launch" );
                        }
                    } catch (Throwable e) {
                        Debug.out(e);
                    } finally {
                        synchronized (pending_ext_urls) {
                            pending_ext_urls.remove(sFileModified);
                        }
                    }
                }
            };
            if (sync) {
                launch.runSupport();
            } else {
                ext_url_dispatcher.dispatch(launch);
            }
        }
    }
    if (!found) {
        if (net_type != AENetworkClassifier.AT_PUBLIC && use_plugins) {
            boolean try_it;
            synchronized (pending_ext_urls) {
                try_it = !browser_install_active_for_url;
                browser_install_active_for_url = true;
            }
            if (try_it) {
                ext_url_dispatcher.dispatch(new AERunnable() {

                    @Override
                    public void runSupport() {
                        boolean installing = false;
                        try {
                            final boolean[] install_outcome = { false };
                            installing = installTorBrowser("aznettorbrowser.install", install_outcome, new Runnable() {

                                @Override
                                public void run() {
                                    try {
                                        if (install_outcome[0]) {
                                            Utils.launch(sFileOriginal, sync, force_url, force_anon);
                                        }
                                    } finally {
                                        synchronized (pending_ext_urls) {
                                            browser_install_active_for_url = false;
                                        }
                                    }
                                }
                            });
                        } catch (Throwable e) {
                            Debug.out(e);
                        } finally {
                            if (!installing) {
                                synchronized (pending_ext_urls) {
                                    browser_install_active_for_url = false;
                                }
                            }
                        }
                    }
                });
            } else {
                Debug.out("Browser installation already active");
            }
            return;
        }
    }
    if (!found && !eb_choice.equals("plugin")) {
        Debug.out("Failed to find external URL launcher plugin with id '" + eb_choice + "'");
    }
    return;
}
Also used : PluginManager(com.biglybt.pif.PluginManager) java.util(java.util) com.biglybt.core.util(com.biglybt.core.util) SWTRunnable(com.biglybt.ui.swt.utils.SWTRunnable) PluginInterface(com.biglybt.pif.PluginInterface) URL(java.net.URL)

Example 8 with PluginManager

use of com.biglybt.pif.PluginManager in project BiglyBT by BiglySoftware.

the class DeviceManagerUI method setupHeader.

private void setupHeader(MultipleDocumentInterface mdi, final MdiEntry entryHeader) {
    addDefaultDropListener(entryHeader);
    /* and away you go!
		SideBarVitalityImage addDevice = entryHeader.addVitalityImage("image.sidebar.subs.add");

		addDevice.setToolTip("Add Device");

		addDevice.addListener(
			new SideBarVitalityImageListener()
			{
				public void
				sbVitalityImage_clicked(
					int x, int y)
				{
					addNewDevice();
					//new DevicesWizard( DeviceManagerUI.this );
				}
			});
		*/
    // Rollup spinner/warning/info
    entryHeader.setViewTitleInfo(new ViewTitleInfo() {

        private int last_indicator = 0;

        MdiEntryVitalityImage spinner = entryHeader.addVitalityImage(SPINNER_IMAGE_ID);

        MdiEntryVitalityImage warning = entryHeader.addVitalityImage(ALERT_IMAGE_ID);

        MdiEntryVitalityImage info = entryHeader.addVitalityImage(INFO_IMAGE_ID);

        {
            hideIcon(spinner);
            hideIcon(warning);
            hideIcon(info);
        }

        @Override
        public Object getTitleInfoProperty(int propertyID) {
            boolean expanded = entryHeader.isExpanded();
            if (propertyID == TITLE_INDICATOR_TEXT) {
                spinner.setVisible(!expanded && device_manager.isBusy(Device.DT_UNKNOWN));
                if (!expanded) {
                    Device[] devices = device_manager.getDevices();
                    last_indicator = 0;
                    String all_errors = "";
                    String all_infos = "";
                    for (Device device : devices) {
                        String error = device.getError();
                        if (error != null) {
                            all_errors += (all_errors.length() == 0 ? "" : "; ") + error;
                        }
                        String info = device.getInfo();
                        if (info != null) {
                            all_infos += (all_infos.length() == 0 ? "" : "; ") + info;
                        }
                        if (device instanceof DeviceMediaRenderer) {
                            if (SHOW_RENDERER_VITALITY) {
                                DeviceMediaRenderer renderer = (DeviceMediaRenderer) device;
                                last_indicator += renderer.getCopyToDevicePending() + renderer.getCopyToFolderPending();
                            }
                        }
                    }
                    if (all_errors.length() > 0) {
                        hideIcon(info);
                        showIcon(warning, all_errors);
                    } else {
                        hideIcon(warning);
                        if (all_infos.length() > 0) {
                            showIcon(info, all_infos);
                        } else {
                            hideIcon(info);
                        }
                    }
                    if (last_indicator > 0) {
                        return (String.valueOf(last_indicator));
                    }
                } else {
                    hideIcon(warning);
                    hideIcon(info);
                }
            } else if (propertyID == TITLE_INDICATOR_COLOR) {
            /*
					if ( last_indicator > 0 ){

						if ( SHOW_VITALITY ){

							return( to_copy_indicator_colors );
						}
					}
					*/
            } else if (propertyID == TITLE_INDICATOR_TEXT_TOOLTIP) {
                return (getHeaderToolTip());
            }
            return null;
        }
    });
    // /////// Turn On
    if (!DISABLED_TRANSCODING) {
        deviceManagerListener = new DeviceManagerListener() {

            @Override
            public void deviceRemoved(Device device) {
            }

            @Override
            public void deviceManagerLoaded() {
                device_manager.removeListener(this);
                if (entryHeader == null || entryHeader.isDisposed()) {
                    return;
                }
                PluginManager pm = CoreFactory.getSingleton().getPluginManager();
                PluginInterface pi;
                pi = pm.getPluginInterfaceByID("vuzexcode");
                if (device_manager.getTranscodeManager().getProviders().length == 0 || pi == null) {
                    // provider plugin not installed yet
                    final MdiEntryVitalityImage turnon = entryHeader.addVitalityImage("image.sidebar.turnon");
                    if (turnon != null) {
                        turnon.addListener(new MdiEntryVitalityImageListener() {

                            @Override
                            public void mdiEntryVitalityImage_clicked(int x, int y) {
                                DevicesFTUX.ensureInstalled(null);
                            }
                        });
                        transcodeManagerListener = new TranscodeManagerListener() {

                            @Override
                            public void providerAdded(TranscodeProvider provider) {
                                // only triggers when vuzexcode is avail
                                turnon.setVisible(false);
                            }

                            @Override
                            public void providerUpdated(TranscodeProvider provider) {
                            }

                            @Override
                            public void providerRemoved(TranscodeProvider provider) {
                            }
                        };
                        device_manager.getTranscodeManager().addListener(transcodeManagerListener);
                    }
                }
            }

            @Override
            public void deviceChanged(Device device) {
            }

            @Override
            public void deviceAttentionRequest(Device device) {
            }

            @Override
            public void deviceAdded(Device device) {
            }
        };
        device_manager.addListener(deviceManagerListener);
    }
    entryHeader.addListener(new MdiCloseListener() {

        @Override
        public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
            if (device_manager != null) {
                device_manager.removeListener(deviceManagerListener);
                if (transcodeManagerListener != null) {
                    device_manager.getTranscodeManager().removeListener(transcodeManagerListener);
                }
            }
        }
    });
    // /////// Menu
    MenuManager menu_manager = ui_manager.getMenuManager();
    createOverallMenu(menu_manager, "sidebar." + SideBar.SIDEBAR_HEADER_DEVICES);
    createOverallMenu(menu_manager, "sidebar." + SideBar.SIDEBAR_SECTION_DEVICES);
}
Also used : UPnPDevice(com.biglybt.net.upnp.UPnPDevice) UnassociatedDevice(com.biglybt.core.devices.DeviceManager.UnassociatedDevice) UPnPRootDevice(com.biglybt.net.upnp.UPnPRootDevice) PluginInterface(com.biglybt.pif.PluginInterface) Point(org.eclipse.swt.graphics.Point) PluginManager(com.biglybt.pif.PluginManager) MenuManager(com.biglybt.pif.ui.menus.MenuManager) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)

Example 9 with PluginManager

use of com.biglybt.pif.PluginManager 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();
                }
            }
        });
    }
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) UIManager(com.biglybt.pif.ui.UIManager) DownloadManager(com.biglybt.core.download.DownloadManager) PluginManager(com.biglybt.pif.PluginManager) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) MenuManager(com.biglybt.pif.ui.menus.MenuManager) PluginUISWTSkinObject(com.biglybt.ui.swt.pif.PluginUISWTSkinObject) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) SkinnedDialog(com.biglybt.ui.swt.views.skin.SkinnedDialog) Download(com.biglybt.pif.download.Download)

Example 10 with PluginManager

use of com.biglybt.pif.PluginManager in project BiglyBT by BiglySoftware.

the class MyTorrentsView method createTableView.

protected TableViewSWT<DownloadManager> createTableView(Class<?> forDataSourceType, String tableID, TableColumnCore[] basicItems) {
    int tableExtraStyle = COConfigurationManager.getIntParameter("MyTorrentsView.table.style");
    TableViewSWT<DownloadManager> table = TableViewFactory.createTableViewSWT(forDataSourceType, tableID, getPropertiesPrefix(), basicItems, "#", tableExtraStyle | SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.CASCADE);
    // config??
    boolean enable_tab_views = !Utils.isAZ2UI() && supportsTabs && COConfigurationManager.getBooleanParameter("Library.ShowTabsInTorrentView");
    List<String> restrictTo = new ArrayList<>();
    restrictTo.addAll(Arrays.asList(GeneralView.MSGID_PREFIX, TrackerView.MSGID_PREFIX, PeersView.MSGID_PREFIX, PeersGraphicView.MSGID_PREFIX, PiecesView.MSGID_PREFIX, DownloadActivityView.MSGID_PREFIX, PieceInfoView.MSGID_PREFIX, FilesView.MSGID_PREFIX, TaggingView.MSGID_PREFIX, PrivacyView.MSGID_PREFIX));
    // sub-tab hacks
    restrictTo.add("azbuddy.ui.menu.chat");
    PluginManager pm = CoreFactory.getSingleton().getPluginManager();
    PluginInterface pi = pm.getPluginInterfaceByID("aercm", true);
    if (pi != null) {
        String pluginInfo = pi.getPluginconfig().getPluginStringParameter("plugin.info", "");
        if (pluginInfo.equals("e")) {
            restrictTo.add("rcm.subview.torrentdetails.name");
        }
    }
    pi = pm.getPluginInterfaceByID("3dview", true);
    if (pi != null) {
        restrictTo.add("view3d.subtab.name");
    }
    if (Logger.isEnabled()) {
        restrictTo.add(LoggerView.MSGID_PREFIX);
    }
    table.setEnableTabViews(enable_tab_views, false, restrictTo.toArray(new String[0]));
    UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
    if (uiFunctions != null) {
        UISWTInstance pluginUI = uiFunctions.getUISWTInstance();
        registerPluginViews(pluginUI);
    }
    return (table);
}
Also used : PluginManager(com.biglybt.pif.PluginManager) PluginInterface(com.biglybt.pif.PluginInterface) UISWTInstance(com.biglybt.ui.swt.pif.UISWTInstance) DownloadManager(com.biglybt.core.download.DownloadManager)

Aggregations

PluginInterface (com.biglybt.pif.PluginInterface)12 PluginManager (com.biglybt.pif.PluginManager)12 MenuManager (com.biglybt.pif.ui.menus.MenuManager)3 URL (java.net.URL)3 DownloadManager (com.biglybt.core.download.DownloadManager)2 PluginException (com.biglybt.pif.PluginException)2 InstallablePlugin (com.biglybt.pif.installer.InstallablePlugin)2 UIManager (com.biglybt.pif.ui.UIManager)2 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)2 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)2 Update (com.biglybt.pif.update.Update)2 UpdateCheckInstance (com.biglybt.pif.update.UpdateCheckInstance)2 UpdateCheckInstanceListener (com.biglybt.pif.update.UpdateCheckInstanceListener)2 UpdateManager (com.biglybt.pif.update.UpdateManager)2 PluginUISWTSkinObject (com.biglybt.ui.swt.pif.PluginUISWTSkinObject)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 UnassociatedDevice (com.biglybt.core.devices.DeviceManager.UnassociatedDevice)1 DHT (com.biglybt.core.dht.DHT)1 DHTTransportStats (com.biglybt.core.dht.transport.DHTTransportStats)1