Search in sources :

Example 1 with StringParameter

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

the class LocalTrackerPlugin method initialize.

@Override
public void initialize(PluginInterface _plugin_interface) {
    plugin_interface = _plugin_interface;
    ta_networks = plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_NETWORKS);
    ta_peer_sources = plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_PEER_SOURCES);
    mon = plugin_interface.getUtilities().getMonitor();
    log = plugin_interface.getLogger().getTimeStampedChannel(PLUGIN_NAME);
    UIManager ui_manager = plugin_interface.getUIManager();
    BasicPluginConfigModel config = ui_manager.createBasicPluginConfigModel(ConfigSection.SECTION_PLUGINS, PLUGIN_CONFIGSECTION_ID);
    config.addLabelParameter2("Plugin.localtracker.info");
    enabled = config.addBooleanParameter2("Plugin.localtracker.enable", "Plugin.localtracker.enable", true);
    config.addLabelParameter2("Plugin.localtracker.networks.info");
    final StringParameter subnets = config.addStringParameter2("Plugin.localtracker.networks", "Plugin.localtracker.networks", "");
    final BooleanParameter include_wellknown = config.addBooleanParameter2("Plugin.localtracker.wellknownlocals", "Plugin.localtracker.wellknownlocals", true);
    config.addLabelParameter2("Plugin.localtracker.autoadd.info");
    final StringParameter autoadd = config.addStringParameter2("Plugin.localtracker.autoadd", "Plugin.localtracker.autoadd", "");
    /*
		 * actually these parameters affect LAN detection as a whole, not just the local tracker,
		 * so leave them enabled...
		 *
		enabled.addEnabledOnSelection( lp1 );
		enabled.addEnabledOnSelection( subnets );
		enabled.addEnabledOnSelection( lp2 );
		enabled.addEnabledOnSelection( autoadd );
		*/
    final BasicPluginViewModel view_model = plugin_interface.getUIManager().createBasicPluginViewModel("Plugin.localtracker.name");
    view_model.setConfigSectionID(PLUGIN_CONFIGSECTION_ID);
    view_model.getActivity().setVisible(false);
    view_model.getProgress().setVisible(false);
    log.addListener(new LoggerChannelListener() {

        @Override
        public void messageLogged(int type, String content) {
            view_model.getLogArea().appendText(content + "\n");
        }

        @Override
        public void messageLogged(String str, Throwable error) {
            if (str.length() > 0) {
                view_model.getLogArea().appendText(str + "\n");
            }
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            error.printStackTrace(pw);
            pw.flush();
            view_model.getLogArea().appendText(sw.toString() + "\n");
        }
    });
    plugin_start_time = plugin_interface.getUtilities().getCurrentSystemTime();
    // Assume we have a core, since this is a plugin
    instance_manager = CoreFactory.getSingleton().getInstanceManager();
    instance_manager.addListener(this);
    plugin_interface.getPluginconfig().addListener(new PluginConfigListener() {

        @Override
        public void configSaved() {
            processSubNets(subnets.getValue(), include_wellknown.getValue());
            processAutoAdd(autoadd.getValue());
        }
    });
    processSubNets(subnets.getValue(), include_wellknown.getValue());
    processAutoAdd(autoadd.getValue());
    final DelayedTask dt = plugin_interface.getUtilities().createDelayedTask(new Runnable() {

        @Override
        public void run() {
            plugin_interface.getDownloadManager().addListener(LocalTrackerPlugin.this);
        }
    });
    dt.queue();
}
Also used : StringParameter(com.biglybt.pif.ui.config.StringParameter) LoggerChannelListener(com.biglybt.pif.logging.LoggerChannelListener) UIManager(com.biglybt.pif.ui.UIManager) PluginConfigListener(com.biglybt.pif.PluginConfigListener) BasicPluginViewModel(com.biglybt.pif.ui.model.BasicPluginViewModel) BooleanParameter(com.biglybt.pif.ui.config.BooleanParameter) StringWriter(java.io.StringWriter) DelayedTask(com.biglybt.pif.utils.DelayedTask) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel) PrintWriter(java.io.PrintWriter)

Example 2 with StringParameter

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

the class BuddyPlugin method initialize.

@Override
public void initialize(final PluginInterface _plugin_interface) {
    plugin_interface = _plugin_interface;
    ta_category = plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_CATEGORY);
    logger = plugin_interface.getLogger().getChannel("Friends");
    logger.setDiagnostic();
    plugin_networks = new BuddyPluginNetwork[] { new BuddyPluginNetwork(plugin_interface, this, AENetworkClassifier.AT_PUBLIC), new BuddyPluginNetwork(plugin_interface, this, AENetworkClassifier.AT_I2P) };
    final LocaleUtilities lu = plugin_interface.getUtilities().getLocaleUtilities();
    Properties l10n_constants = new Properties();
    l10n_constants.put("azbuddy.classic.link.url", Wiki.FRIENDS);
    l10n_constants.put("azbuddy.dchat.link.url", Wiki.DECENTRALIZED_CHAT);
    l10n_constants.put("azbuddy.profile.info.url", Wiki.FRIENDS_PUBLIC_PROFILE);
    lu.integrateLocalisedMessageBundle(l10n_constants);
    lu.addListener(new LocaleListener() {

        @Override
        public void localeChanged(Locale l) {
            updateLocale(lu);
        }
    });
    updateLocale(lu);
    BasicPluginConfigModel config = plugin_interface.getUIManager().createBasicPluginConfigModel("Views.plugins." + VIEW_ID + ".title");
    // enabled
    classic_enabled_param = config.addBooleanParameter2("azbuddy.enabled", "azbuddy.enabled", false);
    ParameterTabFolder network_tab = config.createTabFolder();
    ParameterGroup network_anon_item = null;
    for (int i = 0; i < 2; i++) {
        boolean is_pub_tab = i == 0;
        String suffix = is_pub_tab ? "" : ".anon";
        // nickname
        StringParameter nick_param = config.addStringParameter2("azbuddy.nickname" + suffix, "azbuddy.nickname", "");
        nick_param.setGenerateIntermediateEvents(false);
        nick_param.addListener(new ParameterListener() {

            @Override
            public void parameterChanged(Parameter param) {
                updateNickName(is_pub_tab, nick_param.getValue());
            }
        });
        // online status
        String[] os_values = STATUS_VALUES;
        String[] os_labels = STATUS_STRINGS;
        StringListParameter os_param = config.addStringListParameter2("azbuddy.online_status" + suffix, "azbuddy.online_status", os_values, os_labels, os_values[0]);
        os_param.addListener(new ParameterListener() {

            @Override
            public void parameterChanged(Parameter param) {
                updateOnlineStatus(is_pub_tab, Integer.parseInt(os_param.getValue()));
            }
        });
        // If we add this then use proper message texts in the STATUS_STRINGS
        os_param.setVisible(SUPPORT_ONLINE_STATUS);
        StringParameter profile_param = config.addStringParameter2("azbuddy.profile.info" + suffix, "", "");
        profile_param.setLabelText("<a href=\"" + MessageText.getString("azbuddy.profile.info.url") + "\">" + MessageText.getString("azbuddy.profile.info") + "</a>");
        profile_param.setMultiLine(5);
        profile_param.setGenerateIntermediateEvents(false);
        profile_param.addListener(new ParameterListener() {

            @Override
            public void parameterChanged(Parameter param) {
                updateProfiles();
            }
        });
        ParameterGroup profile_group = config.createGroup(is_pub_tab ? "azbuddy.public.profile" : "azbuddy.anon.profile", new Parameter[] { profile_param });
        ParameterGroup network_item = config.createGroup(is_pub_tab ? "label.public" : "label.anon", new Parameter[] { nick_param, os_param, profile_group });
        if (is_pub_tab) {
            nick_name_public_param = nick_param;
            online_status_public_param = os_param;
            profile_public_param = profile_param;
        } else {
            nick_name_anon_param = nick_param;
            online_status_anon_param = os_param;
            profile_anon_param = profile_param;
            network_anon_item = network_item;
        }
        network_tab.addTab(network_item);
    }
    updateProfiles();
    // protocol speed
    final IntParameter protocol_speed = config.addIntParameter2("azbuddy.protocolspeed", "azbuddy.protocolspeed", 32);
    protocol_speed.setMinimumRequiredUserMode(Parameter.MODE_ADVANCED);
    ConnectionManager cman = plugin_interface.getConnectionManager();
    int inbound_limit = protocol_speed.getValue() * 1024;
    inbound_limiter = cman.createRateLimiter("buddy_up", inbound_limit);
    outbound_limiter = cman.createRateLimiter("buddy_down", 0);
    protocol_speed.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            inbound_limiter.setRateLimitBytesPerSecond(protocol_speed.getValue() * 1024);
        }
    });
    // chat notifications
    enable_chat_notifications = config.addBooleanParameter2("azbuddy.enable_chat_notif", "azbuddy.enable_chat_notif", true);
    // default published tags or cats
    cat_pub = config.addStringParameter2("azbuddy.enable_cat_pub", "azbuddy.enable_cat_pub", "");
    cat_pub.setGenerateIntermediateEvents(false);
    setPublicTagsOrCategories(cat_pub.getValue(), false);
    final BooleanParameter tracker_enable = config.addBooleanParameter2("azbuddy.tracker.enabled", "azbuddy.tracker.enabled", true);
    final BooleanParameter tracker_so_enable = config.addBooleanParameter2("azbuddy.tracker.seeding.only.enabled", "azbuddy.tracker.seeding.only.enabled", false);
    // nasty hack but the existing text has a \t prefix that causes UI weirdness but I don't want to change it and
    // end up with missing translations...
    tracker_so_enable.setLabelText(MessageText.getString("azbuddy.tracker.seeding.only.enabled").trim());
    tracker_so_enable.setIndent(1, true);
    final BooleanParameter buddies_lan_local = config.addBooleanParameter2("azbuddy.tracker.con.lan.local", "azbuddy.tracker.con.lan.local", true);
    buddies_lan_local.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            lan_local_peers = buddies_lan_local.getValue();
        }
    });
    lan_local_peers = buddies_lan_local.getValue();
    final BooleanParameter buddies_fp_enable = config.addBooleanParameter2("azbuddy.tracker.fp.enable", "azbuddy.tracker.fp.enable", true);
    buddies_fp_enable.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            fp_enable = buddies_fp_enable.getValue();
        }
    });
    fp_enable = buddies_fp_enable.getValue();
    cat_pub.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            setPublicTagsOrCategories(cat_pub.getValue(), false);
        }
    });
    config.createGroup("label.friends", new Parameter[] { classic_enabled_param, network_tab, protocol_speed, enable_chat_notifications, cat_pub, tracker_enable, tracker_so_enable, buddies_lan_local, buddies_fp_enable });
    // decentralised stuff
    beta_enabled_param = config.addBooleanParameter2("azbuddy.dchat.decentralized.enabled", "azbuddy.dchat.decentralized.enabled", true);
    config.createGroup("azbuddy.dchat.decentralized", new Parameter[] { beta_enabled_param });
    config.addLabelParameter2("azbuddy.dchat.more.settings");
    // config end
    beta_plugin = new BuddyPluginBeta(plugin_interface, this, beta_enabled_param);
    for (String table_id : TableManager.TABLE_MYTORRENTS_ALL) {
        TableContextMenuItem menu_item = plugin_interface.getUIManager().getTableManager().addContextMenuItem(table_id, "azbuddy.contextmenu");
        menu_item.setStyle(TableContextMenuItem.STYLE_MENU);
        menu_item.setHeaderCategory(MenuItem.HEADER_SOCIAL);
        MenuItemFillListener menu_fill_listener = new MenuItemFillListener() {

            @Override
            public void menuWillBeShown(MenuItem menu, Object _target) {
                menu.removeAllChildItems();
                if (!(isClassicEnabled() && isAvailable())) {
                    menu.setEnabled(false);
                    return;
                }
                final List<Torrent> torrents = new ArrayList<>();
                if (_target instanceof TableRow) {
                    addDownload(torrents, (TableRow) _target);
                } else {
                    TableRow[] rows = (TableRow[]) _target;
                    for (TableRow row : rows) {
                        addDownload(torrents, row);
                    }
                }
                if (torrents.size() == 0) {
                    menu.setEnabled(false);
                } else {
                    List<BuddyPluginBuddy> buddies = getBuddies();
                    for (int i = 0; i < buddies.size(); i++) {
                        final BuddyPluginBuddy buddy = (BuddyPluginBuddy) buddies.get(i);
                        boolean online = buddy.isOnline(true);
                        TableContextMenuItem item = plugin_interface.getUIManager().getTableManager().addContextMenuItem(menu_item, "!" + (buddy.getName() + (buddy.isPublicNetwork() ? "" : (" (" + MessageText.getString("label.anon.medium") + ")"))) + (online ? "" : (" - " + MessageText.getString("label.disconnected"))) + "!");
                        item.addMultiListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                for (Torrent torrent : torrents) {
                                    buddy.getPluginNetwork().getAZ2Handler().sendAZ2Torrent(torrent, buddy);
                                }
                            }
                        });
                        item.setEnabled(online);
                    }
                    menu.setEnabled(true);
                }
            }

            protected void addDownload(List<Torrent> torrents, TableRow row) {
                Object obj = row.getDataSource();
                Download download;
                if (obj instanceof Download) {
                    download = (Download) obj;
                } else {
                    DiskManagerFileInfo file = (DiskManagerFileInfo) obj;
                    try {
                        download = file.getDownload();
                    } catch (DownloadException e) {
                        Debug.printStackTrace(e);
                        return;
                    }
                }
                Torrent torrent = download.getTorrent();
                if (torrent != null && !TorrentUtils.isReallyPrivate(PluginCoreUtils.unwrap(torrent))) {
                    torrents.add(torrent);
                }
            }
        };
        menu_item.addFillListener(menu_fill_listener);
    }
    buddy_tracker = new BuddyPluginTracker(this, tracker_enable, tracker_so_enable);
    plugin_interface.getUIManager().addUIListener(new UIManagerListener() {

        @Override
        public void UIAttached(final UIInstance instance) {
            if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
                try {
                    synchronized (swt_ui_waiters) {
                        swt_ui = (BuddyPluginViewInterface) Class.forName("com.biglybt.plugin.net.buddy.swt.BuddyPluginView").getConstructor(new Class[] { BuddyPlugin.class, UIInstance.class }).newInstance(new Object[] { BuddyPlugin.this, instance });
                        for (Runnable r : swt_ui_waiters) {
                            try {
                                r.run();
                            } catch (Throwable e) {
                                Debug.out(e);
                            }
                        }
                        swt_ui_waiters.clear();
                    }
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
            setupDisablePrompt(instance);
        }

        @Override
        public void UIDetached(UIInstance instance) {
            if (instance.getUIType().equals(UIInstance.UIT_SWT) && swt_ui != null) {
                swt_ui.destroy();
                swt_ui = null;
            }
        }
    });
    final ParameterGroup f_network_anon_item = network_anon_item;
    ParameterListener enabled_listener = new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            boolean classic_enabled = classic_enabled_param.getValue();
            nick_name_public_param.setEnabled(classic_enabled);
            online_status_public_param.setEnabled(classic_enabled);
            nick_name_anon_param.setEnabled(classic_enabled);
            online_status_anon_param.setEnabled(classic_enabled);
            protocol_speed.setEnabled(classic_enabled);
            enable_chat_notifications.setEnabled(classic_enabled);
            cat_pub.setEnabled(classic_enabled);
            tracker_enable.setEnabled(classic_enabled);
            tracker_so_enable.setEnabled(classic_enabled && tracker_enable.getValue());
            buddies_lan_local.setEnabled(classic_enabled);
            buddies_fp_enable.setEnabled(classic_enabled);
            network_tab.setEnabled(classic_enabled);
            f_network_anon_item.setEnabled(classic_enabled && I2PHelpers.isI2PInstalled());
            if (param != null) {
                for (BuddyPluginNetwork pn : plugin_networks) {
                    pn.setClassicEnabledInternal(classic_enabled);
                }
                fireEnabledStateChanged();
            }
        }
    };
    classic_enabled_param.addListener(enabled_listener);
    beta_enabled_param.addListener(enabled_listener);
    tracker_enable.addListener(enabled_listener);
    for (BuddyPluginNetwork pn : plugin_networks) {
        pn.loadConfig();
        pn.registerMessageHandler();
    }
    plugin_interface.addListener(new PluginListener() {

        @Override
        public void initializationComplete() {
            enabled_listener.parameterChanged(null);
            final DelayedTask dt = plugin_interface.getUtilities().createDelayedTask(new Runnable() {

                @Override
                public void run() {
                    new AEThread2("BuddyPlugin:init", true) {

                        @Override
                        public void run() {
                            startup();
                            beta_plugin.startup();
                            initialization_complete.set(true);
                        }
                    }.start();
                }
            });
            dt.queue();
        }

        @Override
        public void closedownInitiated() {
        // meh, moved this to core listener below as we need to closedown before
        // i2p plugin so connections aren't torn down before we can tidily close
        }

        @Override
        public void closedownComplete() {
        }
    });
    CoreFactory.getSingleton().addLifecycleListener(new CoreLifecycleAdapter() {

        @Override
        public boolean syncInvokeRequired() {
            return (true);
        }

        @Override
        public void stopping(Core core) {
            for (BuddyPluginNetwork pn : plugin_networks) {
                pn.saveConfig(true);
                pn.closedown();
            }
            beta_plugin.closedown();
        }
    });
}
Also used : Locale(java.util.Locale) Torrent(com.biglybt.pif.torrent.Torrent) CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) LocaleUtilities(com.biglybt.pif.utils.LocaleUtilities) ArrayList(java.util.ArrayList) Properties(java.util.Properties) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) PluginListener(com.biglybt.pif.PluginListener) ConnectionManager(com.biglybt.pif.network.ConnectionManager) DownloadException(com.biglybt.pif.download.DownloadException) DelayedTask(com.biglybt.pif.utils.DelayedTask) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) CopyOnWriteList(com.biglybt.core.util.CopyOnWriteList) List(java.util.List) ArrayList(java.util.ArrayList) BuddyPluginTracker(com.biglybt.plugin.net.buddy.tracker.BuddyPluginTracker) LocaleListener(com.biglybt.pif.utils.LocaleListener) Download(com.biglybt.pif.download.Download) UIInstance(com.biglybt.pif.ui.UIInstance) ParameterTabFolder(com.biglybt.pif.ui.config.ParameterTabFolder) Core(com.biglybt.core.Core) StringParameter(com.biglybt.pif.ui.config.StringParameter) DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) BooleanParameter(com.biglybt.pif.ui.config.BooleanParameter) AEThread2(com.biglybt.core.util.AEThread2) StringListParameter(com.biglybt.pif.ui.config.StringListParameter) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) ParameterGroup(com.biglybt.pif.ui.config.ParameterGroup) TableRow(com.biglybt.pif.ui.tables.TableRow) ParameterListener(com.biglybt.pif.ui.config.ParameterListener) BooleanParameter(com.biglybt.pif.ui.config.BooleanParameter) StringParameter(com.biglybt.pif.ui.config.StringParameter) Parameter(com.biglybt.pif.ui.config.Parameter) StringListParameter(com.biglybt.pif.ui.config.StringListParameter) IntParameter(com.biglybt.pif.ui.config.IntParameter) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel) IntParameter(com.biglybt.pif.ui.config.IntParameter)

Aggregations

BooleanParameter (com.biglybt.pif.ui.config.BooleanParameter)2 StringParameter (com.biglybt.pif.ui.config.StringParameter)2 BasicPluginConfigModel (com.biglybt.pif.ui.model.BasicPluginConfigModel)2 DelayedTask (com.biglybt.pif.utils.DelayedTask)2 Core (com.biglybt.core.Core)1 CoreLifecycleAdapter (com.biglybt.core.CoreLifecycleAdapter)1 AEThread2 (com.biglybt.core.util.AEThread2)1 CopyOnWriteList (com.biglybt.core.util.CopyOnWriteList)1 PluginConfigListener (com.biglybt.pif.PluginConfigListener)1 PluginListener (com.biglybt.pif.PluginListener)1 DiskManagerFileInfo (com.biglybt.pif.disk.DiskManagerFileInfo)1 Download (com.biglybt.pif.download.Download)1 DownloadException (com.biglybt.pif.download.DownloadException)1 LoggerChannelListener (com.biglybt.pif.logging.LoggerChannelListener)1 ConnectionManager (com.biglybt.pif.network.ConnectionManager)1 Torrent (com.biglybt.pif.torrent.Torrent)1 UIInstance (com.biglybt.pif.ui.UIInstance)1 UIManager (com.biglybt.pif.ui.UIManager)1 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)1 IntParameter (com.biglybt.pif.ui.config.IntParameter)1