Search in sources :

Example 76 with PluginInterface

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

the class ExternalStimulusHandler method initialise.

protected static void initialise(Core core) {
    PluginInterface pi = core.getPluginManager().getPluginInterfaceByClass(MagnetPlugin.class);
    if (pi != null) {
        MagnetPlugin temp = (MagnetPlugin) pi.getPlugin();
        List to_add;
        synchronized (ExternalStimulusHandler.class) {
            magnet_plugin = temp;
            to_add = pending_listeners;
            pending_listeners = null;
        }
        if (to_add != null) {
            for (int i = 0; i < to_add.size(); i++) {
                addListener((ExternalStimulusListener) to_add.get(i));
            }
        }
    } else {
        Debug.out("Failed to resolve magnet plugin");
    }
    // Debug.outNoStack( "ExternalStimulus debug" );
    addListener(new ExternalStimulusListener() {

        @Override
        public boolean receive(String name, Map values) {
            return (name.equals("ExternalStimulus.test"));
        }

        @Override
        public int query(String name, Map values) {
            return (Integer.MIN_VALUE);
        }
    });
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) List(java.util.List) ArrayList(java.util.ArrayList) MagnetPlugin(com.biglybt.plugin.magnet.MagnetPlugin) Map(java.util.Map) HashMap(java.util.HashMap)

Example 77 with PluginInterface

use of com.biglybt.pif.PluginInterface 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 78 with PluginInterface

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

the class DeviceInternetView method initialize.

public void initialize(Composite parent) {
    PluginInterface pi = device_manager_ui.getPluginInterface().getPluginManager().getPluginInterfaceByClass(NetStatusPlugin.class);
    plugin = (NetStatusPlugin) pi.getPlugin();
    main = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginTop = 4;
    layout.marginBottom = 4;
    layout.marginHeight = 4;
    layout.marginWidth = 4;
    main.setLayout(layout);
    GridData grid_data = new GridData(GridData.FILL_BOTH);
    main.setLayoutData(grid_data);
    Label info_lab = new Label(main, SWT.NONE);
    Messages.setLanguageText(info_lab, "label.test.internet");
    // control
    Composite control = new Composite(main, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 3;
    layout.marginHeight = 4;
    layout.marginWidth = 4;
    control.setLayout(layout);
    grid_data = new GridData(GridData.FILL_HORIZONTAL);
    grid_data.horizontalSpan = 1;
    control.setLayoutData(grid_data);
    // start
    start_button = new Button(control, SWT.PUSH);
    Messages.setLanguageText(start_button, "ConfigView.section.start");
    start_button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            start_button.setEnabled(false);
            cancel_button.setEnabled(true);
            startTest();
        }
    });
    // cancel
    cancel_button = new Button(control, SWT.PUSH);
    Messages.setLanguageText(cancel_button, "UpdateWindow.cancel");
    cancel_button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            cancel_button.setEnabled(false);
            cancelTest();
        }
    });
    cancel_button.setEnabled(false);
    // log area
    log = new StyledText(main, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    grid_data = new GridData(GridData.FILL_BOTH);
    grid_data.horizontalSpan = 1;
    grid_data.horizontalIndent = 4;
    log.setLayoutData(grid_data);
    log.setIndent(4);
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) PluginInterface(com.biglybt.pif.PluginInterface) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 79 with PluginInterface

use of com.biglybt.pif.PluginInterface 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 80 with PluginInterface

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

the class BaseMDI method fillMenu.

public void fillMenu(Menu menu, final MdiEntry entry, String menuID) {
    com.biglybt.pif.ui.menus.MenuItem[] menu_items;
    menu_items = MenuItemManager.getInstance().getAllAsArray(menuID);
    MenuBuildUtils.addPluginMenuItems(menu_items, menu, false, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Object[] { entry }));
    if (entry != null) {
        menu_items = MenuItemManager.getInstance().getAllAsArray(getMenuIdPrefix() + entry.getId());
        if (menu_items.length == 0) {
            if (entry instanceof UISWTView) {
                PluginInterface pi = ((UISWTView) entry).getPluginInterface();
                if (pi != null) {
                    final List<String> relevant_sections = new ArrayList<>();
                    List<ConfigSectionHolder> sections = ConfigSectionRepository.getInstance().getHolderList();
                    for (ConfigSectionHolder cs : sections) {
                        if (pi == cs.getPluginInterface()) {
                            relevant_sections.add(cs.configSectionGetName());
                        }
                    }
                    if (relevant_sections.size() > 0) {
                        MenuItem mi = pi.getUIManager().getMenuManager().addMenuItem(getMenuIdPrefix() + entry.getId(), "MainWindow.menu.view.configuration");
                        mi.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                        mi.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif != null) {
                                    for (String s : relevant_sections) {
                                        uif.getMDI().showEntryByID(SIDEBAR_SECTION_CONFIG, s);
                                    }
                                }
                            }
                        });
                        menu_items = MenuItemManager.getInstance().getAllAsArray(getMenuIdPrefix() + entry.getId());
                    }
                }
            }
        }
        MenuBuildUtils.addPluginMenuItems(menu_items, menu, false, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Object[] { entry }));
        MdiSWTMenuHackListener[] menuHackListeners = getMenuHackListeners();
        for (MdiSWTMenuHackListener l : menuHackListeners) {
            try {
                l.menuWillBeShown(entry, menu);
            } catch (Exception e) {
                Debug.out(e);
            }
        }
        if (currentEntry instanceof SideBarEntrySWT) {
            menuHackListeners = ((SideBarEntrySWT) entry).getMenuHackListeners();
            for (MdiSWTMenuHackListener l : menuHackListeners) {
                try {
                    l.menuWillBeShown(entry, menu);
                } catch (Exception e) {
                    Debug.out(e);
                }
            }
        }
    }
    menu_items = MenuItemManager.getInstance().getAllAsArray(menuID + "._end_");
    if (menu_items.length > 0) {
        MenuBuildUtils.addPluginMenuItems(menu_items, menu, false, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Object[] { entry }));
    }
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) SideBarEntrySWT(com.biglybt.ui.swt.views.skin.sidebar.SideBarEntrySWT) ConfigSectionHolder(com.biglybt.pifimpl.local.ui.config.ConfigSectionHolder) MenuItem(com.biglybt.pif.ui.menus.MenuItem) UISWTView(com.biglybt.ui.swt.pif.UISWTView) UIFunctions(com.biglybt.ui.UIFunctions) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) MenuBuildUtils(com.biglybt.ui.swt.MenuBuildUtils)

Aggregations

PluginInterface (com.biglybt.pif.PluginInterface)120 URL (java.net.URL)15 IPCInterface (com.biglybt.pif.ipc.IPCInterface)14 UIManager (com.biglybt.pif.ui.UIManager)13 PluginManager (com.biglybt.pif.PluginManager)12 HashMap (java.util.HashMap)12 List (java.util.List)12 Download (com.biglybt.pif.download.Download)10 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)10 File (java.io.File)10 Map (java.util.Map)10 DownloadManager (com.biglybt.core.download.DownloadManager)9 UIFunctions (com.biglybt.ui.UIFunctions)9 ArrayList (java.util.ArrayList)9 PluginException (com.biglybt.pif.PluginException)8 MenuItem (com.biglybt.pif.ui.menus.MenuItem)8 MenuManager (com.biglybt.pif.ui.menus.MenuManager)8 DHTPlugin (com.biglybt.plugin.dht.DHTPlugin)8 DHT (com.biglybt.core.dht.DHT)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7