Search in sources :

Example 16 with UIManager

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

the class Handler method canProcessWithoutConnection.

@Override
public boolean canProcessWithoutConnection(URL url, boolean processUrlNow) {
    String host = url.getHost();
    if (host.equalsIgnoreCase("install-plugin") && url.getPath().length() > 1) {
        String plugin_id = url.getPath().substring(1);
        PluginInstaller installer = CoreFactory.getSingleton().getPluginManager().getPluginInstaller();
        try {
            StandardPlugin installablePlugin = installer.getStandardPlugin(plugin_id);
            if (installablePlugin == null) {
                UIManager ui_manager = PluginInitializer.getDefaultInterface().getUIManager();
                String details = MessageText.getString("plugininstall.notfound.desc", new String[] { plugin_id });
                ui_manager.showMessageBox("plugininstall.notfound.title", "!" + details + "!", UIManagerEvent.MT_OK);
                return true;
            }
            installer.requestInstall(MessageText.getString("plugininstall.biglybturl"), installablePlugin);
        } catch (PluginException e) {
            UIManager ui_manager = PluginInitializer.getDefaultInterface().getUIManager();
            ui_manager.showMessageBox("plugininstall.error.title", "!" + e.getMessage() + "!", UIManagerEvent.MT_OK);
            Debug.out(e);
        }
        return true;
    }
    return false;
}
Also used : PluginInstaller(com.biglybt.pif.installer.PluginInstaller) PluginException(com.biglybt.pif.PluginException) UIManager(com.biglybt.pif.ui.UIManager) StandardPlugin(com.biglybt.pif.installer.StandardPlugin)

Example 17 with UIManager

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

the class StaticUtilities method getUIManager.

/**
 * gets the default UI manager and also waits for up to a specified time for a UI instance to
 * attach. useful when doing things during initialisation
 * @param millis_to_wait_for_attach
 * @return
 */
public static UIManager getUIManager(long millis_to_wait_for_attach) {
    final UIManager ui_manager = PluginInitializer.getDefaultInterface().getUIManager();
    if (ui_manager.getUIInstances().length == 0) {
        final AESemaphore sem = new AESemaphore("waitforui");
        ui_manager.addUIListener(new UIManagerListener() {

            @Override
            public void UIAttached(UIInstance instance) {
                ui_manager.removeUIListener(this);
                sem.releaseForever();
            }

            @Override
            public void UIDetached(UIInstance instance) {
            }
        });
        // UIAttached is only fired once initialisation is complete. However, the instance
        // can be made available prior to this and there is a case where this event is blocking
        // the firing of the completion event. therefore pick it up if present directly
        long time_to_go = millis_to_wait_for_attach;
        while (ui_manager.getUIInstances().length == 0) {
            if (sem.reserve(1000)) {
                break;
            }
            time_to_go -= 1000;
            if (time_to_go <= 0) {
                Debug.out("Timeout waiting for UI to attach");
                break;
            }
        }
    }
    return (ui_manager);
}
Also used : UIManager(com.biglybt.pif.ui.UIManager) AESemaphore(com.biglybt.core.util.AESemaphore) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) UIInstance(com.biglybt.pif.ui.UIInstance)

Example 18 with UIManager

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

the class StartStopRulesDefaultPlugin method initialize.

@Override
public void initialize(PluginInterface _plugin_interface) {
    if (bAlreadyInitialized) {
        System.err.println("StartStopRulesDefaultPlugin Already initialized!!");
    } else {
        bAlreadyInitialized = true;
    }
    AEDiagnostics.addWeakEvidenceGenerator(this);
    monoStartedOn = SystemTime.getMonotonousTime();
    pi = _plugin_interface;
    plugin_config = pi.getPluginconfig();
    plugin_config.setPluginConfigKeyPrefix("");
    download_manager = pi.getDownloadManager();
    // Create a configModel for StartStopRules
    // We always need to do this in order to set up configuration defaults
    UIManager manager = pi.getUIManager();
    // TODO: don't name it Q
    final BasicPluginConfigModel configModel = manager.createBasicPluginConfigModel(ConfigSection.SECTION_ROOT, "Q");
    setupConfigModel(configModel);
    pi.addListener(new PluginListener() {

        @Override
        public void initializationComplete() {
        }

        @Override
        public void closedownInitiated() {
            closingDown = true;
            // we don't want to go off recalculating stuff when config is saved
            // on closedown
            COConfigurationManager.removeListener(StartStopRulesDefaultPlugin.this);
        }

        @Override
        public void closedownComplete() {
        /* not implemented */
        }
    });
    Runnable r = new Runnable() {

        @Override
        public void run() {
            download_manager.addListener(new StartStopDMListener());
            SimpleTimer.addPeriodicEvent("StartStop:gross", CHECK_FOR_GROSS_CHANGE_PERIOD, new ChangeCheckerTimerTask());
            SimpleTimer.addPeriodicEvent("StartStop:check", PROCESS_CHECK_PERIOD, new ChangeFlagCheckerTask());
        }
    };
    pi.getUtilities().createDelayedTask(r).queue();
    log = pi.getLogger().getTimeStampedChannel("StartStopRules");
    log.log(LoggerChannel.LT_INFORMATION, "Default StartStopRules Plugin Initialisation");
    COConfigurationManager.addListener(this);
    try {
        pi.getUIManager().createLoggingViewModel(log, true);
        pi.getUIManager().addUIListener(new UIManagerListener() {

            @Override
            public void UIAttached(UIInstance instance) {
                TableManager tm = pi.getUIManager().getTableManager();
                seedingRankColumn = tm.createColumn(TableManager.TABLE_MYTORRENTS_COMPLETE, "SeedingRank");
                seedingRankColumn.initialize(TableColumn.ALIGN_TRAIL, TableColumn.POSITION_LAST, 80, TableColumn.INTERVAL_LIVE);
                TableCellRefreshListener columnListener = new SeedingRankColumnListener(downloadDataMap, plugin_config);
                seedingRankColumn.addCellRefreshListener(columnListener);
                tm.addColumn(seedingRankColumn);
                TableColumn downloadingRankColumn = tm.createColumn(TableManager.TABLE_MYTORRENTS_INCOMPLETE, "DownloadingRank");
                downloadingRankColumn.setMinimumRequiredUserMode(1);
                downloadingRankColumn.initialize(TableColumn.ALIGN_TRAIL, TableColumn.POSITION_INVISIBLE, 80, TableColumn.INTERVAL_LIVE);
                columnListener = new DownloadingRankColumnListener(StartStopRulesDefaultPlugin.this);
                downloadingRankColumn.addCellRefreshListener(columnListener);
                tm.addColumn(downloadingRankColumn);
                if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
                    // We have our own config model :)
                    configModel.destroy();
                    try {
                        swt_ui = (UIAdapter) Class.forName("com.biglybt.plugin.startstoprules.defaultplugin.ui.swt.StartStopRulesDefaultPluginSWTUI").getConstructor(new Class[] { PluginInterface.class }).newInstance(new Object[] { pi });
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            }

            @Override
            public void UIDetached(UIInstance instance) {
            }
        });
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
    reloadConfigParams();
}
Also used : UIManager(com.biglybt.pif.ui.UIManager) PluginListener(com.biglybt.pif.PluginListener) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) UIInstance(com.biglybt.pif.ui.UIInstance) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Example 19 with UIManager

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

the class DHTTrackerPlugin method initialize.

@Override
public void initialize(PluginInterface _plugin_interface) {
    plugin_interface = _plugin_interface;
    log = plugin_interface.getLogger().getTimeStampedChannel(PLUGIN_NAME);
    ta_networks = plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_NETWORKS);
    ta_peer_sources = plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_PEER_SOURCES);
    UIManager ui_manager = plugin_interface.getUIManager();
    model = ui_manager.createBasicPluginViewModel(PLUGIN_RESOURCE_ID);
    model.setConfigSectionID(PLUGIN_CONFIGSECTION_ID);
    BasicPluginConfigModel config = ui_manager.createBasicPluginConfigModel(ConfigSection.SECTION_PLUGINS, PLUGIN_CONFIGSECTION_ID);
    track_normal_when_offline = config.addBooleanParameter2("dhttracker.tracknormalwhenoffline", "dhttracker.tracknormalwhenoffline", TRACK_NORMAL_DEFAULT);
    track_limited_when_online = config.addBooleanParameter2("dhttracker.tracklimitedwhenonline", "dhttracker.tracklimitedwhenonline", TRACK_LIMITED_DEFAULT);
    track_limited_when_online.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            configChanged();
        }
    });
    track_normal_when_offline.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            track_limited_when_online.setEnabled(track_normal_when_offline.getValue());
            configChanged();
        }
    });
    if (!track_normal_when_offline.getValue()) {
        track_limited_when_online.setEnabled(false);
    }
    interesting_pub_max = plugin_interface.getPluginconfig().getPluginIntParameter("dhttracker.presencepubmax", INTERESTING_PUB_MAX_DEFAULT);
    if (!TRACK_NORMAL_DEFAULT) {
        // should be TRUE by default
        System.out.println("**** DHT Tracker default set for testing purposes ****");
    }
    BooleanParameter enable_alt = config.addBooleanParameter2("dhttracker.enable_alt", "dhttracker.enable_alt", true);
    IntParameter alt_port = config.addIntParameter2("dhttracker.alt_port", "dhttracker.alt_port", 0, 0, 65535);
    enable_alt.addEnabledOnSelection(alt_port);
    config.createGroup("dhttracker.alt_group", new Parameter[] { enable_alt, alt_port });
    if (enable_alt.getValue()) {
        alt_lookup_handler = new DHTTrackerPluginAlt(alt_port.getValue());
    }
    model.getActivity().setVisible(false);
    model.getProgress().setVisible(false);
    model.getLogArea().setMaximumSize(80000);
    log.addListener(new LoggerChannelListener() {

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

        @Override
        public void messageLogged(String str, Throwable error) {
            model.getLogArea().appendText(error.toString() + "\n");
        }
    });
    model.getStatus().setText(MessageText.getString("ManagerItem.initializing"));
    log.log("Waiting for Distributed Database initialisation");
    plugin_interface.addListener(new PluginListener() {

        @Override
        public void initializationComplete() {
            boolean release_now = true;
            try {
                final PluginInterface dht_pi = plugin_interface.getPluginManager().getPluginInterfaceByClass(DHTPlugin.class);
                if (dht_pi != null) {
                    dht = (DHTPlugin) dht_pi.getPlugin();
                    final DelayedTask dt = plugin_interface.getUtilities().createDelayedTask(new Runnable() {

                        @Override
                        public void run() {
                            AEThread2 t = new AEThread2("DHTTrackerPlugin:init", true) {

                                @Override
                                public void run() {
                                    try {
                                        if (dht.isEnabled()) {
                                            log.log("DDB Available");
                                            model.getStatus().setText(MessageText.getString("DHTView.activity.status.false"));
                                            initialise();
                                        } else {
                                            log.log("DDB Disabled");
                                            model.getStatus().setText(MessageText.getString("dht.status.disabled"));
                                            notRunning();
                                        }
                                    } catch (Throwable e) {
                                        log.log("DDB Failed", e);
                                        model.getStatus().setText(MessageText.getString("DHTView.operations.failed"));
                                        notRunning();
                                    } finally {
                                        initialised_sem.releaseForever();
                                    }
                                }
                            };
                            t.start();
                        }
                    });
                    dt.queue();
                    release_now = false;
                } else {
                    log.log("DDB Plugin missing");
                    model.getStatus().setText(MessageText.getString("DHTView.operations.failed"));
                    notRunning();
                }
            } finally {
                if (release_now) {
                    initialised_sem.releaseForever();
                }
            }
        }

        @Override
        public void closedownInitiated() {
        }

        @Override
        public void closedownComplete() {
        }
    });
}
Also used : LoggerChannelListener(com.biglybt.pif.logging.LoggerChannelListener) PluginInterface(com.biglybt.pif.PluginInterface) UIManager(com.biglybt.pif.ui.UIManager) PluginListener(com.biglybt.pif.PluginListener) DelayedTask(com.biglybt.pif.utils.DelayedTask) DHTPlugin(com.biglybt.plugin.dht.DHTPlugin) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Example 20 with UIManager

use of com.biglybt.pif.ui.UIManager 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)

Aggregations

UIManager (com.biglybt.pif.ui.UIManager)48 UIInstance (com.biglybt.pif.ui.UIInstance)14 PluginInterface (com.biglybt.pif.PluginInterface)13 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)13 UISWTInstance (com.biglybt.ui.swt.pif.UISWTInstance)10 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)8 MenuItem (com.biglybt.pif.ui.menus.MenuItem)7 MenuManager (com.biglybt.pif.ui.menus.MenuManager)7 LoggerChannelListener (com.biglybt.pif.logging.LoggerChannelListener)6 DownloadManager (com.biglybt.core.download.DownloadManager)5 BasicPluginConfigModel (com.biglybt.pif.ui.model.BasicPluginConfigModel)5 URL (java.net.URL)5 TableManager (com.biglybt.pif.ui.tables.TableManager)4 TableColumnManager (com.biglybt.ui.common.table.impl.TableColumnManager)4 ArrayList (java.util.ArrayList)4 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)3 PluginListener (com.biglybt.pif.PluginListener)3 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)3 BasicPluginViewModel (com.biglybt.pif.ui.model.BasicPluginViewModel)3 DelayedTask (com.biglybt.pif.utils.DelayedTask)3