Search in sources :

Example 1 with Parameter

use of com.biglybt.pif.ui.config.Parameter in project BiglyBT by BiglySoftware.

the class ConfigSectionPlugins method initPluginSubSections.

public void initPluginSubSections() {
    // Create subsections for plugins that used the PluginConfigModel object
    // =====================================================================
    TreeItem treePlugins = configView.findTreeItem(ConfigSection.SECTION_PLUGINS);
    ParameterRepository repository = ParameterRepository.getInstance();
    String[] names = repository.getNames();
    Arrays.sort(names);
    for (int i = 0; i < names.length; i++) {
        String pluginName = names[i];
        Parameter[] parameters = repository.getParameterBlock(pluginName);
        // Note: 2070's plugin documentation for PluginInterface.addConfigUIParameters
        // said to pass <"ConfigView.plugins." + displayName>.  This was
        // never implemented in 2070.  2070 read the key <displayName> without
        // the prefix.
        // 
        // 2071+ uses <sSectionPrefix ("ConfigView.section.plugins.") + pluginName>
        // and falls back to <displayName>.  Since
        // <"ConfigView.plugins." + displayName> was never implemented in the
        // first place, a check for it has not been created
        boolean bUsePrefix = MessageText.keyExists(ConfigView.sSectionPrefix + "plugins." + pluginName);
        Composite pluginGroup = configView.createConfigSection(treePlugins, pluginName, -2, bUsePrefix);
        GridLayout pluginLayout = new GridLayout();
        pluginLayout.numColumns = 3;
        pluginGroup.setLayout(pluginLayout);
        Map parameterToPluginParameter = new HashMap();
        // Add all parameters
        for (int j = 0; j < parameters.length; j++) {
            Parameter parameter = parameters[j];
            parameterToPluginParameter.put(parameter, new PluginParameter(pluginGroup, parameter));
        }
        // Check for dependencies
        for (int j = 0; j < parameters.length; j++) {
            Parameter parameter = parameters[j];
            if (parameter instanceof BooleanParameterImpl) {
                List parametersToEnable = ((BooleanParameterImpl) parameter).getEnabledOnSelectionParameters();
                List controlsToEnable = new ArrayList();
                Iterator iter = parametersToEnable.iterator();
                while (iter.hasNext()) {
                    Parameter parameterToEnable = (Parameter) iter.next();
                    PluginParameter pp = (PluginParameter) parameterToPluginParameter.get(parameterToEnable);
                    Control[] controls = pp.getControls();
                    Collections.addAll(controlsToEnable, controls);
                }
                List parametersToDisable = ((BooleanParameterImpl) parameter).getDisabledOnSelectionParameters();
                List controlsToDisable = new ArrayList();
                iter = parametersToDisable.iterator();
                while (iter.hasNext()) {
                    Parameter parameterToDisable = (Parameter) iter.next();
                    PluginParameter pp = (PluginParameter) parameterToPluginParameter.get(parameterToDisable);
                    Control[] controls = pp.getControls();
                    Collections.addAll(controlsToDisable, controls);
                }
                Control[] ce = new Control[controlsToEnable.size()];
                Control[] cd = new Control[controlsToDisable.size()];
                if (ce.length + cd.length > 0) {
                    IAdditionalActionPerformer ap = new DualChangeSelectionActionPerformer((Control[]) controlsToEnable.toArray(ce), (Control[]) controlsToDisable.toArray(cd));
                    PluginParameter pp = (PluginParameter) parameterToPluginParameter.get(parameter);
                    pp.setAdditionalActionPerfomer(ap);
                }
            }
        }
    }
}
Also used : IAdditionalActionPerformer(com.biglybt.ui.swt.config.IAdditionalActionPerformer) ParameterRepository(com.biglybt.pifimpl.local.ui.config.ParameterRepository) GridLayout(org.eclipse.swt.layout.GridLayout) DualChangeSelectionActionPerformer(com.biglybt.ui.swt.config.DualChangeSelectionActionPerformer) PluginParameter(com.biglybt.ui.swt.config.plugins.PluginParameter) Parameter(com.biglybt.pif.ui.config.Parameter) List(java.util.List) PluginParameter(com.biglybt.ui.swt.config.plugins.PluginParameter) BooleanParameterImpl(com.biglybt.pifimpl.local.ui.config.BooleanParameterImpl)

Example 2 with Parameter

use of com.biglybt.pif.ui.config.Parameter in project BiglyBT by BiglySoftware.

the class MagnetPlugin method initialize.

@Override
public void initialize(PluginInterface _plugin_interface) {
    plugin_interface = _plugin_interface;
    MagnetURIHandler uri_handler = MagnetURIHandler.getSingleton();
    final LocaleUtilities lu = plugin_interface.getUtilities().getLocaleUtilities();
    lu.addListener(new LocaleListener() {

        @Override
        public void localeChanged(Locale l) {
            updateLocale(lu);
        }
    });
    updateLocale(lu);
    BasicPluginConfigModel config = plugin_interface.getUIManager().createBasicPluginConfigModel(ConfigSection.SECTION_PLUGINS, PLUGIN_CONFIGSECTION_ID);
    config.addInfoParameter2("MagnetPlugin.current.port", String.valueOf(uri_handler.getPort()));
    secondary_lookup = config.addBooleanParameter2("MagnetPlugin.use.lookup.service", "MagnetPlugin.use.lookup.service", true);
    md_lookup = config.addBooleanParameter2("MagnetPlugin.use.md.download", "MagnetPlugin.use.md.download", true);
    md_lookup_delay = config.addIntParameter2("MagnetPlugin.use.md.download.delay", "MagnetPlugin.use.md.download.delay", MD_LOOKUP_DELAY_SECS_DEFAULT);
    md_lookup.addEnabledOnSelection(md_lookup_delay);
    timeout_param = config.addIntParameter2("MagnetPlugin.timeout.secs", "MagnetPlugin.timeout.secs", PLUGIN_DOWNLOAD_TIMEOUT_SECS_DEFAULT);
    sources_param = config.addStringListParameter2("MagnetPlugin.add.sources", "MagnetPlugin.add.sources", SOURCE_VALUES, SOURCE_STRINGS, SOURCE_VALUES[1]);
    sources_extra_param = config.addIntParameter2("MagnetPlugin.add.sources.extra", "MagnetPlugin.add.sources.extra", 0);
    magnet_recovery = config.addBooleanParameter2("MagnetPlugin.recover.magnets", "MagnetPlugin.recover.magnets", true);
    Parameter[] nps = new Parameter[AENetworkClassifier.AT_NETWORKS.length];
    for (int i = 0; i < nps.length; i++) {
        String nn = AENetworkClassifier.AT_NETWORKS[i];
        String config_name = "Network Selection Default." + nn;
        String msg_text = "ConfigView.section.connection.networks." + nn;
        final BooleanParameter param = config.addBooleanParameter2(config_name, msg_text, COConfigurationManager.getBooleanParameter(config_name));
        COConfigurationManager.addParameterListener(config_name, new com.biglybt.core.config.ParameterListener() {

            @Override
            public void parameterChanged(String name) {
                param.setDefaultValue(COConfigurationManager.getBooleanParameter(name));
            }
        });
        nps[i] = param;
        net_params.put(nn, param);
    }
    config.createGroup("label.default.nets", nps);
    MenuItemListener listener = new MenuItemListener() {

        @Override
        public void selected(MenuItem _menu, Object _target) {
            TableRow[] rows = (TableRow[]) _target;
            String cb_all_data = "";
            for (TableRow row : rows) {
                Torrent torrent;
                String name;
                Object ds = row.getDataSource();
                Download download = null;
                ShareResource share = null;
                if (ds instanceof ShareResourceFile) {
                    ShareResourceFile sf = (ShareResourceFile) ds;
                    try {
                        torrent = sf.getItem().getTorrent();
                    } catch (ShareException e) {
                        continue;
                    }
                    name = sf.getName();
                    share = sf;
                } else if (ds instanceof ShareResourceDir) {
                    ShareResourceDir sd = (ShareResourceDir) ds;
                    try {
                        torrent = sd.getItem().getTorrent();
                    } catch (ShareException e) {
                        continue;
                    }
                    name = sd.getName();
                    share = sd;
                } else if (ds instanceof Download) {
                    download = (Download) ds;
                    torrent = download.getTorrent();
                    name = download.getName();
                } else {
                    continue;
                }
                boolean is_share = false;
                Set<String> networks = new HashSet<>();
                if (share != null) {
                    is_share = true;
                    Map<String, String> properties = share.getProperties();
                    if (properties != null) {
                        String nets = properties.get(ShareManager.PR_NETWORKS);
                        if (nets != null) {
                            String[] bits = nets.split(",");
                            for (String bit : bits) {
                                bit = AENetworkClassifier.internalise(bit.trim());
                                if (bit != null) {
                                    networks.add(bit);
                                }
                            }
                        }
                    }
                }
                if (download != null) {
                    TorrentAttribute ta = plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_NETWORKS);
                    String[] nets = download.getListAttribute(ta);
                    networks.addAll(Arrays.asList(nets));
                    try {
                        byte[] hash = download.getTorrentHash();
                        if (plugin_interface.getShareManager().lookupShare(hash) != null) {
                            is_share = true;
                        }
                    } catch (Throwable e) {
                    }
                }
                String cb_data = download == null ? UrlUtils.getMagnetURI(name, torrent) : UrlUtils.getMagnetURI(download);
                if (download != null) {
                    List<Tag> tags = TagManagerFactory.getTagManager().getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL, PluginCoreUtils.unwrap(download));
                    for (Tag tag : tags) {
                        if (tag.isPublic()) {
                            cb_data += "&tag=" + UrlUtils.encode(tag.getTagName(true));
                        }
                    }
                }
                String sources = sources_param.getValue();
                boolean add_sources = sources.equals("2") || (sources.equals("1") && is_share);
                if (add_sources) {
                    if (networks.isEmpty()) {
                        for (String net : AENetworkClassifier.AT_NETWORKS) {
                            if (isNetworkEnabled(net)) {
                                networks.add(net);
                            }
                        }
                    }
                    if (networks.contains(AENetworkClassifier.AT_PUBLIC) && !cb_data.contains("xsource=")) {
                        InetAddress ip = NetworkAdmin.getSingleton().getDefaultPublicAddress();
                        InetAddress ip_v6 = NetworkAdmin.getSingleton().getDefaultPublicAddressV6();
                        int port = TCPNetworkManager.getSingleton().getTCPListeningPortNumber();
                        if (ip != null && port > 0) {
                            cb_data += "&xsource=" + UrlUtils.encode(ip.getHostAddress() + ":" + port);
                        }
                        if (ip_v6 != null && port > 0) {
                            cb_data += "&xsource=" + UrlUtils.encode(ip_v6.getHostAddress() + ":" + port);
                        }
                        int extra = sources_extra_param.getValue();
                        if (extra > 0) {
                            if (download == null) {
                                if (torrent != null) {
                                    download = plugin_interface.getDownloadManager().getDownload(torrent);
                                }
                            }
                            if (download != null) {
                                Set<String> added = new HashSet<>();
                                DownloadManager dm = PluginCoreUtils.unwrap(download);
                                PEPeerManager pm = dm.getPeerManager();
                                if (pm != null) {
                                    List<PEPeer> peers = pm.getPeers();
                                    for (PEPeer peer : peers) {
                                        String peer_ip = peer.getIp();
                                        if (AENetworkClassifier.categoriseAddress(peer_ip) == AENetworkClassifier.AT_PUBLIC) {
                                            int peer_port = peer.getTCPListenPort();
                                            if (peer_port > 0) {
                                                cb_data += "&xsource=" + UrlUtils.encode(peer_ip + ":" + peer_port);
                                                added.add(peer_ip);
                                                extra--;
                                                if (extra == 0) {
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                                if (extra > 0) {
                                    Map response_cache = dm.getDownloadState().getTrackerResponseCache();
                                    if (response_cache != null) {
                                        List<TRTrackerAnnouncerResponsePeer> peers = TRTrackerAnnouncerFactory.getCachedPeers(response_cache);
                                        for (TRTrackerAnnouncerResponsePeer peer : peers) {
                                            String peer_ip = peer.getAddress();
                                            if (AENetworkClassifier.categoriseAddress(peer_ip) == AENetworkClassifier.AT_PUBLIC) {
                                                if (!added.contains(peer_ip)) {
                                                    int peer_port = peer.getPort();
                                                    if (peer_port > 0) {
                                                        cb_data += "&xsource=" + UrlUtils.encode(peer_ip + ":" + peer_port);
                                                        added.add(peer_ip);
                                                        extra--;
                                                        if (extra == 0) {
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                // removed this as well - nothing wrong with allowing magnet copy
                // for private torrents - they still can't be tracked if you don't
                // have permission
                /*if ( torrent.isPrivate()){

							cb_data = getMessageText( "private_torrent" );

						}else if ( torrent.isDecentralised()){
						*/
                // ok
                /* relaxed this as we allow such torrents to be downloaded via magnet links
							 * (as opposed to tracked in the DHT)

						}else if ( torrent.isDecentralisedBackupEnabled()){

							TorrentAttribute ta_peer_sources 	= plugin_interface.getTorrentManager().getAttribute( TorrentAttribute.TA_PEER_SOURCES );

							String[]	sources = download.getListAttribute( ta_peer_sources );

							boolean	ok = false;

							for (int i=0;i<sources.length;i++){

								if ( sources[i].equalsIgnoreCase( "DHT")){

									ok	= true;

									break;
								}
							}

							if ( !ok ){

								cb_data = getMessageText( "decentral_disabled" );
							}
						}else{

							cb_data = getMessageText( "decentral_backup_disabled" );
							*/
                // }
                // System.out.println( "MagnetPlugin: export = " + url );
                cb_all_data += (cb_all_data.length() == 0 ? "" : "\n") + cb_data;
            }
            try {
                plugin_interface.getUIManager().copyToClipBoard(cb_all_data);
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    };
    List<TableContextMenuItem> menus = new ArrayList<>();
    for (String table : TableManager.TABLE_MYTORRENTS_ALL) {
        TableContextMenuItem menu = plugin_interface.getUIManager().getTableManager().addContextMenuItem(table, "MagnetPlugin.contextmenu.exporturi");
        menu.addMultiListener(listener);
        menu.setHeaderCategory(MenuItem.HEADER_SOCIAL);
        menus.add(menu);
    }
    uri_handler.addListener(new MagnetURIHandlerListener() {

        @Override
        public byte[] badge() {
            InputStream is = getClass().getClassLoader().getResourceAsStream("com/biglybt/plugin/magnet/Magnet.gif");
            if (is == null) {
                return (null);
            }
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                try {
                    byte[] buffer = new byte[8192];
                    while (true) {
                        int len = is.read(buffer);
                        if (len <= 0) {
                            break;
                        }
                        baos.write(buffer, 0, len);
                    }
                } finally {
                    is.close();
                }
                return (baos.toByteArray());
            } catch (Throwable e) {
                Debug.printStackTrace(e);
                return (null);
            }
        }

        @Override
        public byte[] download(MagnetURIHandlerProgressListener muh_listener, byte[] hash, String args, InetSocketAddress[] sources, long timeout) throws MagnetURIHandlerException {
            try {
                Download dl = plugin_interface.getDownloadManager().getDownload(hash);
                if (dl != null) {
                    Torrent torrent = dl.getTorrent();
                    if (torrent != null) {
                        byte[] torrent_data = torrent.writeToBEncodedData();
                        torrent_data = addTrackersAndWebSeedsEtc(torrent_data, args, new HashSet<String>());
                        return (torrent_data);
                    }
                }
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
            return (recoverableDownload(muh_listener, hash, args, sources, timeout, false));
        }

        @Override
        public boolean download(URL url) throws MagnetURIHandlerException {
            try {
                plugin_interface.getDownloadManager().addDownload(url, false);
                return (true);
            } catch (DownloadException e) {
                throw (new MagnetURIHandlerException("Operation failed", e));
            }
        }

        @Override
        public boolean set(String name, Map values) {
            List l = listeners.getList();
            for (int i = 0; i < l.size(); i++) {
                if (((MagnetPluginListener) l.get(i)).set(name, values)) {
                    return (true);
                }
            }
            return (false);
        }

        @Override
        public int get(String name, Map values) {
            List l = listeners.getList();
            for (int i = 0; i < l.size(); i++) {
                int res = ((MagnetPluginListener) l.get(i)).get(name, values);
                if (res != Integer.MIN_VALUE) {
                    return (res);
                }
            }
            return (Integer.MIN_VALUE);
        }
    });
    plugin_interface.getUIManager().addUIListener(new UIManagerListener() {

        @Override
        public void UIAttached(UIInstance instance) {
            if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
                try {
                    Class.forName("com.biglybt.plugin.magnet.swt.MagnetPluginUISWT").getConstructor(new Class[] { UIInstance.class, TableContextMenuItem[].class }).newInstance(new Object[] { instance, menus.toArray(new TableContextMenuItem[menus.size()]) });
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public void UIDetached(UIInstance instance) {
        }
    });
    final List<Download> to_delete = new ArrayList<>();
    Download[] downloads = plugin_interface.getDownloadManager().getDownloads();
    for (Download download : downloads) {
        if (download.getFlag(Download.FLAG_METADATA_DOWNLOAD)) {
            to_delete.add(download);
        }
    }
    final AESemaphore delete_done = new AESemaphore("delete waiter");
    if (to_delete.size() > 0) {
        AEThread2 t = new AEThread2("MagnetPlugin:delmds", true) {

            @Override
            public void run() {
                try {
                    for (Download download : to_delete) {
                        try {
                            download.stop();
                        } catch (Throwable e) {
                        }
                        try {
                            download.remove(true, true);
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                } finally {
                    delete_done.release();
                }
            }
        };
        t.start();
    } else {
        delete_done.release();
    }
    plugin_interface.addListener(new PluginListener() {

        @Override
        public void initializationComplete() {
            // make sure DDB is initialised as we need it to register its
            // transfer types
            AEThread2 t = new AEThread2("MagnetPlugin:init", true) {

                @Override
                public void run() {
                    delete_done.reserve();
                    recoverDownloads();
                    plugin_interface.getDistributedDatabase();
                }
            };
            t.start();
        }

        @Override
        public void closedownInitiated() {
        }

        @Override
        public void closedownComplete() {
        }
    });
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent) TOTorrent(com.biglybt.core.torrent.TOTorrent) PEPeer(com.biglybt.core.peer.PEPeer) ShareResourceDir(com.biglybt.pif.sharing.ShareResourceDir) InetSocketAddress(java.net.InetSocketAddress) LocaleUtilities(com.biglybt.pif.utils.LocaleUtilities) DownloadManager(com.biglybt.core.download.DownloadManager) DownloadException(com.biglybt.pif.download.DownloadException) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UIInstance(com.biglybt.pif.ui.UIInstance) MagnetURIHandler(com.biglybt.net.magneturi.MagnetURIHandler) TableRow(com.biglybt.pif.ui.tables.TableRow) PEPeerManager(com.biglybt.core.peer.PEPeerManager) InetAddress(java.net.InetAddress) ShareResourceFile(com.biglybt.pif.sharing.ShareResourceFile) MagnetURIHandlerProgressListener(com.biglybt.net.magneturi.MagnetURIHandlerProgressListener) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) URL(java.net.URL) PluginListener(com.biglybt.pif.PluginListener) ShareException(com.biglybt.pif.sharing.ShareException) LocaleListener(com.biglybt.pif.utils.LocaleListener) Download(com.biglybt.pif.download.Download) ShareResource(com.biglybt.pif.sharing.ShareResource) InputStream(java.io.InputStream) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BooleanParameter(com.biglybt.pif.ui.config.BooleanParameter) TorrentAttribute(com.biglybt.pif.torrent.TorrentAttribute) BooleanParameter(com.biglybt.pif.ui.config.BooleanParameter) Parameter(com.biglybt.pif.ui.config.Parameter) StringListParameter(com.biglybt.pif.ui.config.StringListParameter) IntParameter(com.biglybt.pif.ui.config.IntParameter) TRTrackerAnnouncerResponsePeer(com.biglybt.core.tracker.client.TRTrackerAnnouncerResponsePeer) Tag(com.biglybt.core.tag.Tag) MagnetURIHandlerListener(com.biglybt.net.magneturi.MagnetURIHandlerListener) MagnetURIHandlerException(com.biglybt.net.magneturi.MagnetURIHandlerException) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Example 3 with Parameter

use of com.biglybt.pif.ui.config.Parameter in project BiglyBT by BiglySoftware.

the class ParameterRepository method addPlugin.

public void addPlugin(Parameter[] parameters, String displayName) {
    params.put(displayName, parameters);
    // set the defaults
    ConfigurationDefaults def = ConfigurationDefaults.getInstance();
    if (def == null)
        return;
    for (int i = 0; i < parameters.length; i++) {
        Parameter parameter = parameters[i];
        if (!(parameter instanceof ParameterImpl))
            continue;
        String sKey = ((ParameterImpl) parameter).getKey();
        if (parameter instanceof StringParameterImpl) {
            def.addParameter(sKey, ((StringParameterImpl) parameter).getDefaultValue());
        } else if (parameter instanceof IntParameterImpl) {
            def.addParameter(sKey, ((IntParameterImpl) parameter).getDefaultValue());
        } else if (parameter instanceof BooleanParameterImpl) {
            def.addParameter(sKey, ((BooleanParameterImpl) parameter).getDefaultValue());
        } else if (parameter instanceof FileParameter) {
            def.addParameter(sKey, ((FileParameter) parameter).getDefaultValue());
        } else if (parameter instanceof DirectoryParameterImpl) {
            def.addParameter(sKey, ((DirectoryParameterImpl) parameter).getDefaultValue());
        } else if (parameter instanceof IntsParameter) {
            def.addParameter(sKey, ((IntsParameter) parameter).getDefaultValue());
        } else if (parameter instanceof StringListParameterImpl) {
            def.addParameter(sKey, ((StringListParameterImpl) parameter).getDefaultValue());
        } else if (parameter instanceof ColorParameter) {
            def.addParameter(sKey + ".red", ((ColorParameter) parameter).getDefaultRed());
            def.addParameter(sKey + ".green", ((ColorParameter) parameter).getDefaultGreen());
            def.addParameter(sKey + ".blue", ((ColorParameter) parameter).getDefaultBlue());
        }
    }
}
Also used : ConfigurationDefaults(com.biglybt.core.config.impl.ConfigurationDefaults) Parameter(com.biglybt.pif.ui.config.Parameter)

Example 4 with Parameter

use of com.biglybt.pif.ui.config.Parameter in project BiglyBT by BiglySoftware.

the class PMSWTImpl method initialise.

@Override
public void initialise(final PluginInterface pi, final BooleanParameter icon_enable) {
    final NetworkAdmin na = NetworkAdmin.getSingleton();
    na.addPropertyChangeListener(new NetworkAdminPropertyChangeListener() {

        @Override
        public void propertyChanged(String property) {
            if (property == NetworkAdmin.PR_NETWORK_INTERFACES) {
                updateLocalAddresses(na);
            }
        }
    });
    updateLocalAddresses(na);
    pi.getUIManager().addUIListener(new UIManagerListener() {

        @Override
        public void UIAttached(final UIInstance instance) {
            if (instance instanceof UISWTInstance) {
                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                if (uif != null) {
                    uiUpdaterListener = new UIUpdaterListener() {

                        @Override
                        public void updateComplete(int count) {
                            last_update_count = count;
                            updateStatus(true);
                        }
                    };
                    uif.getUIUpdater().addListener(uiUpdaterListener);
                }
                Utils.execSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        ImageLoader imageLoader = ImageLoader.getInstance();
                        icon_idle = imageLoader.getImage("pair_sb_idle");
                        icon_green = imageLoader.getImage("pair_sb_green");
                        icon_red = imageLoader.getImage("pair_sb_red");
                        UISWTInstance ui_instance = (UISWTInstance) instance;
                        status = ui_instance.createStatusEntry();
                        last_tooltip_text = MessageText.getString("pairing.ui.icon.tip");
                        status.setTooltipText(last_tooltip_text);
                        status.setImageEnabled(true);
                        status.setImage(icon_idle);
                        last_image = icon_idle;
                        boolean is_visible = icon_enable.getValue();
                        status.setVisible(is_visible);
                        if (is_visible) {
                            updateStatus(false);
                        }
                        final MenuItem mi_show = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "pairing.ui.icon.show");
                        mi_show.setStyle(MenuItem.STYLE_CHECK);
                        mi_show.setData(Boolean.valueOf(is_visible));
                        mi_show.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                icon_enable.setValue(false);
                            }
                        });
                        iconEnableListener = new ParameterListener() {

                            @Override
                            public void parameterChanged(Parameter param) {
                                boolean is_visible = icon_enable.getValue();
                                status.setVisible(is_visible);
                                mi_show.setData(Boolean.valueOf(is_visible));
                                if (is_visible) {
                                    updateStatus(false);
                                }
                            }
                        };
                        icon_enable.addListener(iconEnableListener);
                        MenuItem mi_pairing = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "MainWindow.menu.pairing");
                        mi_pairing.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif == null) {
                                    Debug.out("UIFunctions not available, can't open remote pairing window");
                                } else {
                                    uif.openRemotePairingWindow();
                                }
                            }
                        });
                        MenuItem mi_sep = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "");
                        mi_sep.setStyle(MenuItem.STYLE_SEPARATOR);
                        MenuItem mi_options = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "MainWindow.menu.view.configuration");
                        mi_options.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif != null) {
                                    uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, PairingManager.CONFIG_SECTION_ID);
                                }
                            }
                        });
                        UISWTStatusEntryListener click_listener = new UISWTStatusEntryListener() {

                            @Override
                            public void entryClicked(UISWTStatusEntry entry) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif != null) {
                                    uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, PairingManager.CONFIG_SECTION_ID);
                                }
                            }
                        };
                        status.setListener(click_listener);
                    }
                });
            }
        }

        @Override
        public void UIDetached(UIInstance instance) {
            if (instance instanceof UISWTInstance) {
                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                if (uif != null && uiUpdaterListener != null) {
                    uif.getUIUpdater().removeListener(uiUpdaterListener);
                    uiUpdaterListener = null;
                }
                if (status != null) {
                    // menu items get destroyed with this call
                    status.destroy();
                    status = null;
                }
                if (icon_enable != null && iconEnableListener != null) {
                    icon_enable.removeListener(iconEnableListener);
                    iconEnableListener = null;
                }
            }
        }
    });
}
Also used : UIUpdaterListener(com.biglybt.ui.common.updater.UIUpdater.UIUpdaterListener) UISWTStatusEntryListener(com.biglybt.ui.swt.pif.UISWTStatusEntryListener) MenuItem(com.biglybt.pif.ui.menus.MenuItem) NetworkAdminPropertyChangeListener(com.biglybt.core.networkmanager.admin.NetworkAdminPropertyChangeListener) NetworkAdmin(com.biglybt.core.networkmanager.admin.NetworkAdmin) UIFunctions(com.biglybt.ui.UIFunctions) UISWTStatusEntry(com.biglybt.ui.swt.pif.UISWTStatusEntry) ParameterListener(com.biglybt.pif.ui.config.ParameterListener) BooleanParameter(com.biglybt.pif.ui.config.BooleanParameter) Parameter(com.biglybt.pif.ui.config.Parameter) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UISWTInstance(com.biglybt.ui.swt.pif.UISWTInstance) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) UIInstance(com.biglybt.pif.ui.UIInstance)

Example 5 with Parameter

use of com.biglybt.pif.ui.config.Parameter in project BiglyBT by BiglySoftware.

the class SearchUI method delayedInit.

private void delayedInit() {
    final MetaSearchManager manager = MetaSearchManagerFactory.getSingleton();
    if (manager == null) {
        return;
    }
    BasicPluginConfigModel configModel = ui_manager.createBasicPluginConfigModel(ConfigSection.SECTION_ROOT, CONFIG_SECTION_ID);
    // proxy enable
    final BooleanParameter proxy_enable = configModel.addBooleanParameter2("search.proxy.enable", "search.proxy.enable", manager.getProxyRequestsEnabled());
    proxy_enable.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            manager.setProxyRequestsEnabled(proxy_enable.getValue());
        }
    });
    // open rcm on search
    final BooleanParameter paramRCMWindow = configModel.addBooleanParameter2("search.showRCMView", "search.showRCMView", false);
}
Also used : ParameterListener(com.biglybt.pif.ui.config.ParameterListener) BooleanParameter(com.biglybt.pif.ui.config.BooleanParameter) Parameter(com.biglybt.pif.ui.config.Parameter) MetaSearchManager(com.biglybt.core.metasearch.MetaSearchManager) BooleanParameter(com.biglybt.pif.ui.config.BooleanParameter) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Aggregations

Parameter (com.biglybt.pif.ui.config.Parameter)5 BooleanParameter (com.biglybt.pif.ui.config.BooleanParameter)3 UIInstance (com.biglybt.pif.ui.UIInstance)2 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)2 ParameterListener (com.biglybt.pif.ui.config.ParameterListener)2 MenuItem (com.biglybt.pif.ui.menus.MenuItem)2 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)2 BasicPluginConfigModel (com.biglybt.pif.ui.model.BasicPluginConfigModel)2 ConfigurationDefaults (com.biglybt.core.config.impl.ConfigurationDefaults)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 MetaSearchManager (com.biglybt.core.metasearch.MetaSearchManager)1 NetworkAdmin (com.biglybt.core.networkmanager.admin.NetworkAdmin)1 NetworkAdminPropertyChangeListener (com.biglybt.core.networkmanager.admin.NetworkAdminPropertyChangeListener)1 PEPeer (com.biglybt.core.peer.PEPeer)1 PEPeerManager (com.biglybt.core.peer.PEPeerManager)1 Tag (com.biglybt.core.tag.Tag)1 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 TRTrackerAnnouncerResponsePeer (com.biglybt.core.tracker.client.TRTrackerAnnouncerResponsePeer)1 MagnetURIHandler (com.biglybt.net.magneturi.MagnetURIHandler)1 MagnetURIHandlerException (com.biglybt.net.magneturi.MagnetURIHandlerException)1