Search in sources :

Example 6 with ParameterListener

use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.

the class SubscriptionManagerImpl method initWithCore.

protected void initWithCore(Core _core) {
    synchronized (this) {
        if (started) {
            return;
        }
        started = true;
    }
    core = _core;
    final PluginInterface default_pi = PluginInitializer.getDefaultInterface();
    rss_publisher = new SubscriptionRSSFeed(this, default_pi);
    TorrentManager tm = default_pi.getTorrentManager();
    ta_subs_download = tm.getPluginAttribute("azsubs.subs_dl");
    ta_subs_download_rd = tm.getPluginAttribute("azsubs.subs_dl_rd");
    ta_subscription_info = tm.getPluginAttribute("azsubs.subs_info");
    ta_category = tm.getAttribute(TorrentAttribute.TA_CATEGORY);
    ta_networks = tm.getAttribute(TorrentAttribute.TA_NETWORKS);
    PluginInterface dht_plugin_pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByClass(DHTPlugin.class);
    if (dht_plugin_pi != null) {
        dht_plugin_public = (DHTPlugin) dht_plugin_pi.getPlugin();
        /*
			if ( Constants.isCVSVersion()){

				addListener(
						new SubscriptionManagerListener()
						{
							public void
							subscriptionAdded(
								Subscription subscription )
							{
							}

							public void
							subscriptionChanged(
								Subscription		subscription )
							{
							}

							public void
							subscriptionRemoved(
								Subscription subscription )
							{
							}

							public void
							associationsChanged(
								byte[] hash )
							{
								System.out.println( "Subscriptions changed: " + ByteFormatter.encodeString( hash ));

								Subscription[] subs = getKnownSubscriptions( hash );

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

									System.out.println( "    " + subs[i].getString());
								}
							}
						});
			}
			*/
        default_pi.getDownloadManager().addListener(new DownloadManagerListener() {

            @Override
            public void downloadAdded(Download download) {
                Torrent torrent = download.getTorrent();
                if (torrent != null) {
                    byte[] hash = torrent.getHash();
                    Object[] entry;
                    synchronized (potential_associations2) {
                        entry = (Object[]) potential_associations2.remove(new HashWrapper(hash));
                    }
                    if (entry != null) {
                        SubscriptionImpl[] subs = (SubscriptionImpl[]) entry[0];
                        String subs_str = "";
                        for (int i = 0; i < subs.length; i++) {
                            subs_str += (i == 0 ? "" : ",") + subs[i].getName();
                        }
                        log("Applying deferred asocciation for " + ByteFormatter.encodeString(hash) + " -> " + subs_str);
                        recordAssociationsSupport(hash, subs, ((Boolean) entry[1]).booleanValue());
                    }
                }
            }

            @Override
            public void downloadRemoved(Download download) {
            }
        }, false);
        default_pi.getDownloadManager().addDownloadWillBeAddedListener(new DownloadWillBeAddedListener() {

            @Override
            public void initialised(Download download) {
                Torrent torrent = download.getTorrent();
                if (torrent != null) {
                    byte[] hash = torrent.getHash();
                    HashWrapper hw = new HashWrapper(hash);
                    Object[] entry;
                    synchronized (potential_associations2) {
                        entry = (Object[]) potential_associations2.get(hw);
                    }
                    if (entry != null) {
                        SubscriptionImpl[] subs = (SubscriptionImpl[]) entry[0];
                        prepareDownload(download, subs, null);
                    } else {
                        synchronized (potential_associations3) {
                            entry = potential_associations3.get(hw);
                        }
                        if (entry != null) {
                            Subscription[] subs = (Subscription[]) entry[0];
                            SubscriptionResult[] results = (SubscriptionResult[]) entry[1];
                            prepareDownload(download, subs, results);
                        }
                    }
                }
            }
        });
        TorrentUtils.addTorrentAttributeListener(new TorrentUtils.torrentAttributeListener() {

            @Override
            public void attributeSet(TOTorrent torrent, String attribute, Object value) {
                if (attribute == TorrentUtils.TORRENT_AZ_PROP_OBTAINED_FROM) {
                    try {
                        checkPotentialAssociations(torrent.getHash(), (String) value);
                    } catch (Throwable e) {
                        Debug.printStackTrace(e);
                    }
                }
            }
        });
        DelayedTask delayed_task = UtilitiesImpl.addDelayedTask("Subscriptions", new Runnable() {

            @Override
            public void run() {
                new AEThread2("Subscriptions:delayInit", true) {

                    @Override
                    public void run() {
                        asyncInit();
                    }
                }.start();
            }

            protected void asyncInit() {
                Download[] downloads = default_pi.getDownloadManager().getDownloads();
                for (int i = 0; i < downloads.length; i++) {
                    Download download = downloads[i];
                    if (download.getBooleanAttribute(ta_subs_download)) {
                        Map rd = download.getMapAttribute(ta_subs_download_rd);
                        boolean delete_it;
                        if (rd == null) {
                            delete_it = true;
                        } else {
                            delete_it = !recoverSubscriptionUpdate(download, rd);
                        }
                        if (delete_it) {
                            removeDownload(download, true);
                        }
                    }
                }
                default_pi.getDownloadManager().addListener(new DownloadManagerListener() {

                    @Override
                    public void downloadAdded(final Download download) {
                        if (!downloadIsIgnored(download)) {
                            if (!dht_plugin_public.isInitialising()) {
                                // if new download then we want to check out its subscription status
                                lookupAssociations(download.getMapAttribute(ta_subscription_info) == null);
                            } else {
                                new AEThread2("Subscriptions:delayInit", true) {

                                    @Override
                                    public void run() {
                                        lookupAssociations(download.getMapAttribute(ta_subscription_info) == null);
                                    }
                                }.start();
                            }
                        }
                    }

                    @Override
                    public void downloadRemoved(Download download) {
                    }
                }, false);
                for (int i = 0; i < PUB_ASSOC_CONC_MAX; i++) {
                    if (publishAssociations()) {
                        break;
                    }
                }
                publishSubscriptions();
                COConfigurationManager.addParameterListener(CONFIG_MAX_RESULTS, new ParameterListener() {

                    @Override
                    public void parameterChanged(String name) {
                        final int max_results = COConfigurationManager.getIntParameter(CONFIG_MAX_RESULTS);
                        new AEThread2("Subs:max results changer", true) {

                            @Override
                            public void run() {
                                checkMaxResults(max_results);
                            }
                        }.start();
                    }
                });
                SimpleTimer.addPeriodicEvent("SubscriptionChecker", TIMER_PERIOD, new TimerEventPerformer() {

                    private int ticks;

                    @Override
                    public void perform(TimerEvent event) {
                        ticks++;
                        checkStuff(ticks);
                    }
                });
            }
        });
        delayed_task.queue();
    }
    if (isSearchEnabled()) {
        try {
            default_pi.getUtilities().registerSearchProvider(new SearchProvider() {

                private Map<Integer, Object> properties = new HashMap<>();

                {
                    properties.put(PR_NAME, MessageText.getString("ConfigView.section.Subscriptions"));
                    try {
                        URL url = MagnetURIHandler.getSingleton().registerResource(new MagnetURIHandler.ResourceProvider() {

                            @Override
                            public String getUID() {
                                return (SubscriptionManager.class.getName() + ".2");
                            }

                            @Override
                            public String getFileType() {
                                return ("png");
                            }

                            @Override
                            public byte[] getData() {
                                InputStream is = getClass().getClassLoader().getResourceAsStream("com/biglybt/ui/images/subscription_icon_1616.png");
                                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) {
                                    return (null);
                                }
                            }
                        });
                        properties.put(PR_ICON_URL, url.toExternalForm());
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }

                @Override
                public SearchInstance search(Map<String, Object> search_parameters, SearchObserver observer) throws SearchException {
                    try {
                        return (searchSubscriptions(search_parameters, observer));
                    } catch (Throwable e) {
                        throw (new SearchException("Search failed", e));
                    }
                }

                @Override
                public Object getProperty(int property) {
                    return (properties.get(property));
                }

                @Override
                public void setProperty(int property, Object value) {
                    properties.put(property, value);
                }
            });
        } catch (Throwable e) {
            Debug.out("Failed to register search provider");
        }
    }
    default_pi.getUtilities().registerJSONRPCServer(new Utilities.JSONServer() {

        private List<String> methods = new ArrayList<>();

        {
            methods.add("vuze-subs-list");
        }

        @Override
        public String getName() {
            return ("Subscriptions");
        }

        @Override
        public List<String> getSupportedMethods() {
            return (methods);
        }

        @Override
        public Map call(String method, Map args) throws PluginException {
            throw (new PluginException("derp"));
        }
    });
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent) TOTorrent(com.biglybt.core.torrent.TOTorrent) URL(java.net.URL) Utilities(com.biglybt.pif.utils.Utilities) StaticUtilities(com.biglybt.pif.utils.StaticUtilities) DelayedTask(com.biglybt.pif.utils.DelayedTask) PlatformTorrentUtils(com.biglybt.core.torrent.PlatformTorrentUtils) GZIPInputStream(java.util.zip.GZIPInputStream) PluginInterface(com.biglybt.pif.PluginInterface) PluginException(com.biglybt.pif.PluginException) TorrentManager(com.biglybt.pif.torrent.TorrentManager) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TOTorrent(com.biglybt.core.torrent.TOTorrent) ParameterListener(com.biglybt.core.config.ParameterListener)

Example 7 with ParameterListener

use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.

the class LongTermStatsGenericImpl method getTotalUsageInPeriod.

@Override
public long[] getTotalUsageInPeriod(int period_type, double multiplier, RecordAccepter accepter) {
    if (start_of_week == -1) {
        COConfigurationManager.addAndFireParameterListeners(new String[] { "long.term.stats.weekstart", "long.term.stats.monthstart" }, new ParameterListener() {

            @Override
            public void parameterChanged(String name) {
                start_of_week = COConfigurationManager.getIntParameter("long.term.stats.weekstart");
                start_of_month = COConfigurationManager.getIntParameter("long.term.stats.monthstart");
            }
        });
    }
    long now = SystemTime.getCurrentTime();
    long top_time;
    long bottom_time;
    if (period_type == PT_CURRENT_HOUR) {
        bottom_time = (now / HOUR_IN_MILLIS) * HOUR_IN_MILLIS;
        top_time = bottom_time + HOUR_IN_MILLIS - 1;
    } else if (period_type == PT_SLIDING_HOUR) {
        bottom_time = now - (long) (multiplier * HOUR_IN_MILLIS);
        top_time = now;
    } else if (period_type == PT_SLIDING_DAY) {
        bottom_time = now - (long) (multiplier * DAY_IN_MILLIS);
        top_time = now;
    } else if (period_type == PT_SLIDING_WEEK) {
        bottom_time = now - (long) (multiplier * WEEK_IN_MILLIS);
        top_time = now;
    } else {
        Calendar calendar = new GregorianCalendar();
        calendar.setTimeInMillis(now);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        top_time = calendar.getTimeInMillis() + DAY_IN_MILLIS - 1;
        if (period_type == PT_CURRENT_DAY) {
        } else if (period_type == PT_CURRENT_WEEK) {
            // sun = 1, mon = 2 etc
            int day_of_week = calendar.get(Calendar.DAY_OF_WEEK);
            if (day_of_week == start_of_week) {
            } else if (day_of_week > start_of_week) {
                calendar.add(Calendar.DAY_OF_WEEK, -(day_of_week - start_of_week));
            } else {
                calendar.add(Calendar.DAY_OF_WEEK, -(7 - (start_of_week - day_of_week)));
            }
        } else {
            if (start_of_month == 1) {
                calendar.set(Calendar.DAY_OF_MONTH, 1);
            } else {
                int day_of_month = calendar.get(Calendar.DAY_OF_MONTH);
                if (day_of_month == start_of_month) {
                } else if (day_of_month > start_of_month) {
                    calendar.set(Calendar.DAY_OF_MONTH, start_of_month);
                } else {
                    calendar.add(Calendar.MONTH, -1);
                    calendar.set(Calendar.DAY_OF_MONTH, start_of_month);
                }
            }
        }
        bottom_time = calendar.getTimeInMillis();
    }
    return (getTotalUsageInPeriod(new Date(bottom_time), new Date(top_time), accepter));
}
Also used : ParameterListener(com.biglybt.core.config.ParameterListener)

Example 8 with ParameterListener

use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.

the class AEDiagnostics method startup.

public static synchronized void startup(boolean _enable_pending) {
    if (started_up) {
        return;
    }
    started_up = true;
    enable_pending_writes = _enable_pending;
    try {
        // Minimize risk of loading to much when in transitory startup mode
        boolean transitoryStartup = System.getProperty("transitory.startup", "0").equals("1");
        if (transitoryStartup) {
            // no xxx_?.log logging for you!
            loggers_enabled = false;
            return;
        }
        debug_dir = FileUtil.getUserFile("logs");
        debug_save_dir = new File(debug_dir, "save");
        COConfigurationManager.addAndFireParameterListeners(new String[] { "Logger.Enabled", "Logger.DebugFiles.Enabled", "Logger.DebugFiles.SizeKB" }, new ParameterListener() {

            @Override
            public void parameterChanged(String parameterName) {
                logging_enabled = COConfigurationManager.getBooleanParameter("Logger.Enabled");
                loggers_enabled = logging_enabled && COConfigurationManager.getBooleanParameter("Logger.DebugFiles.Enabled");
                if (!loggers_enabled) {
                    boolean skipCVSCheck = System.getProperty("skip.loggers.enabled.cvscheck", "0").equals("1");
                    loggers_enabled = (!skipCVSCheck && Constants.IS_CVS_VERSION) || COConfigurationManager.getBooleanParameter("Logger.DebugFiles.Enabled.Force");
                }
                if (System.getProperty("diag.logsize", null) == null) {
                    int kb = COConfigurationManager.getIntParameter("Logger.DebugFiles.SizeKB", 0) * 1024;
                    if (kb > 0) {
                        MAX_FILE_SIZE_ACTUAL[0] = kb;
                    }
                }
            }
        });
        boolean was_tidy = COConfigurationManager.getBooleanParameter(CONFIG_KEY);
        new AEThread2("asyncify", true) {

            @Override
            public void run() {
                SimpleTimer.addEvent("AEDiagnostics:logCleaner", SystemTime.getCurrentTime() + 60000 + RandomUtils.nextInt(15000), new TimerEventPerformer() {

                    @Override
                    public void perform(TimerEvent event) {
                        cleanOldLogs();
                    }
                });
            }
        }.start();
        if (debug_dir.exists()) {
            boolean save_logs = System.getProperty("az.logging.save.debug", "true").equals("true");
            long now = SystemTime.getCurrentTime();
            File[] files = debug_dir.listFiles();
            if (files != null) {
                boolean file_found = false;
                for (int i = 0; i < files.length; i++) {
                    File file = files[i];
                    if (file.isDirectory()) {
                        continue;
                    }
                    if (!was_tidy) {
                        file_found = true;
                        if (save_logs) {
                            if (!debug_save_dir.exists()) {
                                debug_save_dir.mkdir();
                            }
                            FileUtil.copyFile(file, new File(debug_save_dir, now + "_" + file.getName()));
                        }
                    }
                }
                if (file_found) {
                    Logger.logTextResource(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_WARNING, "diagnostics.log_found"), new String[] { debug_save_dir.toString() });
                }
            }
        } else {
            debug_dir.mkdir();
        }
        AEJavaManagement.initialise();
    } catch (Throwable e) {
        if (!(e instanceof NoClassDefFoundError)) {
            Debug.printStackTrace(e);
        }
    } finally {
        startup_complete = true;
    }
}
Also used : LogAlert(com.biglybt.core.logging.LogAlert) ParameterListener(com.biglybt.core.config.ParameterListener)

Example 9 with ParameterListener

use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.

the class MainWindowImpl method postPluginSetup.

private void postPluginSetup(Core core) {
    // we pass core in just as reminder that this function needs core
    if (core == null) {
        return;
    }
    // if (!Utils.isAZ2UI()) {
    ActivitiesManager.initialize(core);
    // }
    LocProvUtils.initialise(core);
    if (!Constants.isSafeMode) {
        MainHelpers.initTransferBar();
        configIconBarEnabledListener = new ParameterListener() {

            @Override
            public void parameterChanged(String parameterName) {
                setVisible(WINDOW_ELEMENT_TOOLBAR, COConfigurationManager.getBooleanParameter(parameterName));
            }
        };
        COConfigurationManager.addAndFireParameterListener("IconBar.enabled", configIconBarEnabledListener);
    }
    // share progress window
    new ProgressWindow(Utils.getDisplay());
}
Also used : ProgressWindow(com.biglybt.ui.swt.sharing.progress.ProgressWindow) ParameterListener(com.biglybt.core.config.ParameterListener)

Example 10 with ParameterListener

use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.

the class MainWindowImpl method createWindow.

/**
 * @param uiInitializer
 *
 * called in both delayedCore and !delayedCore
 */
private void createWindow(IUIIntializer uiInitializer) {
    // System.out.println("MainWindow: createWindow)");
    long startTime = SystemTime.getCurrentTime();
    UIFunctionsSWT existing_uif = UIFunctionsManagerSWT.getUIFunctionsSWT();
    uiFunctions = new UIFunctionsImpl(this);
    UIFunctionsManager.setUIFunctions(uiFunctions);
    Utils.disposeComposite(shell);
    increaseProgress(uiInitializer, "splash.initializeGui");
    System.out.println("UIFunctions/ImageLoad took " + (SystemTime.getCurrentTime() - startTime) + "ms");
    startTime = SystemTime.getCurrentTime();
    shell = existing_uif == null ? new Shell(Utils.getDisplay(), SWT.SHELL_TRIM) : existing_uif.getMainShell();
    if (Constants.isWindows) {
        try {
            Class<?> ehancerClass = Class.forName("com.biglybt.ui.swt.win32.Win32UIEnhancer");
            Method method = ehancerClass.getMethod("initMainShell", Shell.class);
            method.invoke(null, shell);
        } catch (Exception e) {
            Debug.outNoStack(Debug.getCompressedStackTrace(e, 0, 30), true);
        }
    }
    try {
        shell.setData("class", this);
        shell.setText(UIFunctions.MAIN_WINDOW_NAME);
        Utils.setShellIcon(shell);
        Utils.linkShellMetricsToConfig(shell, "window");
        // Shell activeShell = display.getActiveShell();
        // shell.setVisible(true);
        // shell.moveBelow(activeShell);
        System.out.println("new shell took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        increaseProgress(uiInitializer, "v3.splash.initSkin");
        skin = SWTSkinFactory.getInstance();
        if (Utils.isAZ2UI()) {
            SWTSkinProperties skinProperties = skin.getSkinProperties();
            String skinPath = SkinPropertiesImpl.PATH_SKIN_DEFS + "skin3_classic";
            ResourceBundle rb = ResourceBundle.getBundle(skinPath);
            skinProperties.addResourceBundle(rb, skinPath);
        }
        /*
			 * KN: passing the skin to the uifunctions so it can be used by UIFunctionsSWT.createMenu()
			 */
        uiFunctions.setSkin(skin);
        System.out.println("new shell setup took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        initSkinListeners();
        increaseProgress(uiInitializer, "v3.splash.initSkin");
        // 0ms
        // System.out.println("skinlisteners init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        // startTime = SystemTime.getCurrentTime();
        String startID = Utils.isAZ2UI() ? "classic.shell" : "main.shell";
        skin.initialize(shell, startID, uiInitializer);
        increaseProgress(uiInitializer, "v3.splash.initSkin");
        System.out.println("skin init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        menu = uiFunctions.createMainMenu(shell);
        shell.setData("MainMenu", menu);
        System.out.println("MainMenu init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        increaseProgress(uiInitializer, "v3.splash.initSkin");
        skin.layout();
        try {
            Utils.createTorrentDropTarget(shell, false);
        } catch (Throwable e) {
            Logger.log(new LogEvent(LOGID, "Drag and Drop not available", e));
        }
        shell.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                if (configIconBarEnabledListener != null) {
                    COConfigurationManager.removeParameterListener("IconBar.enabled", configIconBarEnabledListener);
                }
                if (configShowStatusInTitleListener != null) {
                    COConfigurationManager.removeParameterListener("Show Status In Window Title", configShowStatusInTitleListener);
                }
                if (configShowDLBasketListener != null) {
                    COConfigurationManager.removeParameterListener("Show Download Basket", configShowDLBasketListener);
                }
                if (configMonitorClipboardListener != null) {
                    COConfigurationManager.removeParameterListener("Monitor Clipboard For Torrents", configMonitorClipboardListener);
                }
                if (gmListener != null) {
                    GlobalManager gm = core.getGlobalManager();
                    if (gm != null) {
                        gm.removeListener(gmListener);
                    }
                    gmListener = null;
                }
                if (uiFunctions != null) {
                    uiFunctions.dispose();
                }
                if (navigationListener != null) {
                    NavigationHelper.removeListener(navigationListener);
                    navigationListener = null;
                }
                StimulusRPC.unhookListeners();
                UISkinnableManagerSWT skinnableManagerSWT = UISkinnableManagerSWT.getInstance();
                skinnableManagerSWT.removeSkinnableListener(MessageBoxShell.class.toString(), uiSkinnableSWTListener);
            // comment out: shell can dispose without us wanting core to be..
            // dispose(false, false);
            }
        });
        shell.addShellListener(new ShellAdapter() {

            @Override
            public void shellClosed(ShellEvent event) {
                if (disposedOrDisposing) {
                    return;
                }
                if (COConfigurationManager.getBooleanParameter("Close To Tray") && ((systemTraySWT != null && COConfigurationManager.getBooleanParameter("Enable System Tray")) || COConfigurationManager.getBooleanParameter("System Tray Disabled Override"))) {
                    minimizeToTray(event);
                } else {
                    event.doit = dispose(false, false);
                }
            }

            @Override
            public void shellActivated(ShellEvent e) {
                Shell shellAppModal = Utils.findFirstShellWithStyle(SWT.APPLICATION_MODAL);
                if (shellAppModal != null) {
                    shellAppModal.forceActive();
                } else {
                    shell.forceActive();
                }
            }

            @Override
            public void shellIconified(ShellEvent event) {
                if (disposedOrDisposing) {
                    return;
                }
                if (COConfigurationManager.getBooleanParameter("Minimize To Tray") && ((systemTraySWT != null && COConfigurationManager.getBooleanParameter("Enable System Tray")) || COConfigurationManager.getBooleanParameter("System Tray Disabled Override"))) {
                    minimizeToTray(event);
                }
            }

            @Override
            public void shellDeiconified(ShellEvent e) {
                if (Constants.isOSX && COConfigurationManager.getBooleanParameter("Password enabled")) {
                    shell.setVisible(false);
                    if (PasswordWindow.showPasswordWindow(Utils.getDisplay())) {
                        shell.setVisible(true);
                    }
                }
            }
        });
        Utils.getDisplay().addFilter(SWT.KeyDown, new Listener() {

            @Override
            public void handleEvent(Event event) {
                // Another window has control, skip filter
                Control focus_control = event.display.getFocusControl();
                if (focus_control != null && focus_control.getShell() != shell)
                    return;
                int key = event.character;
                if ((event.stateMask & SWT.MOD1) != 0 && event.character <= 26 && event.character > 0)
                    key += 'a' - 1;
                if (key == 'l' && (event.stateMask & SWT.MOD1) != 0) {
                    // Ctrl-L: Open URL
                    if (core == null) {
                        return;
                    }
                    GlobalManager gm = core.getGlobalManager();
                    if (gm != null) {
                        UIFunctionsManagerSWT.getUIFunctionsSWT().openTorrentWindow();
                        event.doit = false;
                    }
                } else if (key == 'd' && (event.stateMask & SWT.MOD1) != 0) {
                    // dump
                    if (Constants.isCVSVersion()) {
                        Utils.dump(shell);
                    }
                } else if (key == 'f' && (event.stateMask & (SWT.MOD1 + SWT.SHIFT)) == SWT.MOD1 + SWT.SHIFT) {
                    shell.setFullScreen(!shell.getFullScreen());
                } else if (event.keyCode == SWT.F1) {
                    Utils.launch(Constants.URL_WIKI);
                }
            }
        });
        increaseProgress(uiInitializer, "v3.splash.initSkin");
        System.out.println("pre skin widgets init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        if (core != null) {
            StimulusRPC.hookListeners(core, this);
        }
        increaseProgress(uiInitializer, "v3.splash.initSkin");
        // 0ms
        // System.out.println("hooks init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        // startTime = SystemTime.getCurrentTime();
        initMDI();
        System.out.println("skin widgets (1/2) init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        initWidgets2();
        increaseProgress(uiInitializer, "v3.splash.initSkin");
        System.out.println("skin widgets (2/2) init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        System.out.println("pre SWTInstance init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        increaseProgress(uiInitializer, "v3.splash.hookPluginUI");
        startTime = SystemTime.getCurrentTime();
        TableColumnCreatorV3.initCoreColumns();
        System.out.println("Init Core Columns took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        increaseProgress(uiInitializer, "v3.splash.hookPluginUI");
        startTime = SystemTime.getCurrentTime();
        // attach the UI to plugins
        // Must be done before initializing views, since plugins may register
        // table columns and other objects
        uiSWTInstanceImpl = new UISWTInstanceImpl();
        uiSWTInstanceImpl.init(uiInitializer);
        System.out.println("SWTInstance init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        increaseProgress(uiInitializer, "splash.initializeGui");
        startTime = SystemTime.getCurrentTime();
    } catch (Throwable t) {
        Debug.out(t);
    } finally {
        String configID = SkinConstants.VIEWID_PLUGINBAR + ".visible";
        if (!ConfigurationDefaults.getInstance().doesParameterDefaultExist(configID)) {
            COConfigurationManager.setBooleanDefault(configID, true);
        }
        setVisible(WINDOW_ELEMENT_TOPBAR, COConfigurationManager.getBooleanParameter(configID) && COConfigurationManager.getIntParameter("User Mode") > 1);
        setVisible(WINDOW_ELEMENT_TOOLBAR, COConfigurationManager.getBooleanParameter("IconBar.enabled"));
        shell.layout(true, true);
        System.out.println("shell.layout took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        showMainWindow();
        // ================
        increaseProgress(uiInitializer, "splash.initializeGui");
        System.out.println("shell.open took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        processStartupDMS();
        System.out.println("processStartupDMS took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        if (core != null) {
            postPluginSetup(core);
        }
        System.out.println("postPluginSetup init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        navigationListener = new navigationListener() {

            @Override
            public void processCommand(final int type, final String[] args) {
                Utils.execSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        UIFunctions uif = UIFunctionsManager.getUIFunctions();
                        if (type == NavigationHelper.COMMAND_SWITCH_TO_TAB) {
                            MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
                            if (mdi == null) {
                                return;
                            }
                            mdi.showEntryByID(args[0]);
                            if (uif != null) {
                                uif.bringToFront();
                            }
                        } else if (type == NavigationHelper.COMMAND_CONDITION_CHECK) {
                        }
                    }
                });
            }
        };
        NavigationHelper.addListener(navigationListener);
        if (!Constants.isOSX) {
            configShowStatusInTitleListener = new ParameterListener() {

                private TimerEventPeriodic timer;

                private String old_text;

                private String my_last_text;

                @Override
                public void parameterChanged(final String name) {
                    Utils.execSWTThread(new AERunnable() {

                        @Override
                        public void runSupport() {
                            boolean enable = COConfigurationManager.getBooleanParameter(name);
                            if (enable) {
                                if (timer == null) {
                                    timer = SimpleTimer.addPeriodicEvent("window.title.updater", 1000, new TimerEventPerformer() {

                                        @Override
                                        public void perform(TimerEvent event) {
                                            Utils.execSWTThread(new AERunnable() {

                                                @Override
                                                public void runSupport() {
                                                    if (shell.isDisposed()) {
                                                        return;
                                                    }
                                                    String current_txt = shell.getText();
                                                    if (current_txt != null && !current_txt.equals(my_last_text)) {
                                                        old_text = current_txt;
                                                    }
                                                    String txt = getCurrentTitleText();
                                                    if (txt != null) {
                                                        if (!txt.equals(current_txt)) {
                                                            shell.setText(txt);
                                                        }
                                                        my_last_text = txt;
                                                    }
                                                }
                                            });
                                        }
                                    });
                                }
                            } else {
                                if (timer != null) {
                                    timer.cancel();
                                    timer = null;
                                }
                                if (old_text != null && !shell.isDisposed()) {
                                    shell.setText(old_text);
                                }
                            }
                        }
                    });
                }
            };
            COConfigurationManager.addAndFireParameterListener("Show Status In Window Title", configShowStatusInTitleListener);
        }
    }
}
Also used : MdiEntryLogIdListener(com.biglybt.ui.mdi.MdiEntryLogIdListener) ParameterListener(com.biglybt.core.config.ParameterListener) MdiListener(com.biglybt.ui.mdi.MdiListener) NavigationHelper.navigationListener(com.biglybt.util.NavigationHelper.navigationListener) GlobalManagerListener(com.biglybt.core.global.GlobalManagerListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) ObfuscateShell(com.biglybt.ui.swt.debug.ObfuscateShell) GlobalManager(com.biglybt.core.global.GlobalManager) UIFunctions(com.biglybt.ui.UIFunctions) UISWTInstanceImpl(com.biglybt.ui.swt.pifimpl.UISWTInstanceImpl) NavigationHelper.navigationListener(com.biglybt.util.NavigationHelper.navigationListener) Method(java.lang.reflect.Method) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface) ParameterListener(com.biglybt.core.config.ParameterListener)

Aggregations

ParameterListener (com.biglybt.core.config.ParameterListener)43 CoreRunningListener (com.biglybt.core.CoreRunningListener)5 LogAlert (com.biglybt.core.logging.LogAlert)5 PriorityParameterListener (com.biglybt.core.config.PriorityParameterListener)4 LogEvent (com.biglybt.core.logging.LogEvent)4 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)4 ArrayList (java.util.ArrayList)4 Core (com.biglybt.core.Core)3 ConfigurationManager (com.biglybt.core.config.impl.ConfigurationManager)3 GlobalManager (com.biglybt.core.global.GlobalManager)3 GlobalManagerAdapter (com.biglybt.core.global.GlobalManagerAdapter)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 DownloadManager (com.biglybt.core.download.DownloadManager)2 GlobalManagerListener (com.biglybt.core.global.GlobalManagerListener)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 AERunnable (com.biglybt.core.util.AERunnable)2 MenuItem (com.biglybt.pif.ui.menus.MenuItem)2 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)2 DelayedTask (com.biglybt.pif.utils.DelayedTask)2