Search in sources :

Example 11 with UIFunctions

use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.

the class DeviceManagerUI method createOverallMenu.

private void createOverallMenu(final MenuManager menu_manager, String parentID) {
    MenuItem de_menu_item = menu_manager.addMenuItem(parentID, "device.search");
    de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_menu_item.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            search();
        }
    });
    // show generic
    de_menu_item = menu_manager.addMenuItem(parentID, "device.showGeneric");
    de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_menu_item.setStyle(MenuItem.STYLE_CHECK);
    de_menu_item.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object data) {
            boolean is_hidden = COConfigurationManager.getBooleanParameter(CONFIG_VIEW_HIDE_REND_GENERIC, true);
            menu.setData(!is_hidden);
            boolean enabled = false;
            if (is_hidden) {
                Device[] devices = device_manager.getDevices();
                for (Device d : devices) {
                    if (d.isHidden()) {
                        continue;
                    }
                    if (d instanceof DeviceMediaRenderer) {
                        DeviceMediaRenderer rend = (DeviceMediaRenderer) d;
                        if (rend.isNonSimple()) {
                            enabled = true;
                        }
                    }
                }
            } else {
                enabled = true;
            }
            menu.setEnabled(enabled);
        }
    });
    de_menu_item.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            COConfigurationManager.setParameter(CONFIG_VIEW_HIDE_REND_GENERIC, !COConfigurationManager.getBooleanParameter(CONFIG_VIEW_HIDE_REND_GENERIC, true));
        }
    });
    // show tagged
    de_menu_item = menu_manager.addMenuItem(parentID, "device.onlyShowTagged");
    de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_menu_item.setStyle(MenuItem.STYLE_CHECK);
    de_menu_item.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object data) {
            menu.setData(COConfigurationManager.getBooleanParameter(CONFIG_VIEW_SHOW_ONLY_TAGGED, false));
            Device[] devices = device_manager.getDevices();
            boolean has_tagged = false;
            for (Device d : devices) {
                if (d.isTagged()) {
                    has_tagged = true;
                    break;
                }
            }
            menu.setEnabled(has_tagged);
        }
    });
    de_menu_item.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            COConfigurationManager.setParameter(CONFIG_VIEW_SHOW_ONLY_TAGGED, !COConfigurationManager.getBooleanParameter(CONFIG_VIEW_SHOW_ONLY_TAGGED, false));
        }
    });
    // show hidden
    de_menu_item = menu_manager.addMenuItem(parentID, "device.show");
    de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_menu_item.addListener(show_listener);
    de_menu_item.addFillListener(show_fill_listener);
    // simple
    de_menu_item = menu_manager.addMenuItem(parentID, "devices.sidebar.simple");
    de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_menu_item.setStyle(MenuItem.STYLE_CHECK);
    de_menu_item.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object data) {
            menu.setData(COConfigurationManager.getIntParameter(CONFIG_VIEW_TYPE, SBV_SIMPLE) == SBV_SIMPLE);
        }
    });
    de_menu_item.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            COConfigurationManager.setParameter(CONFIG_VIEW_TYPE, ((Boolean) menu.getData()) ? SBV_SIMPLE : SBV_FULL);
        }
    });
    de_menu_item = menu_manager.addMenuItem(parentID, "sep");
    de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
    // on complete do
    final MenuItem de_oxc_menu = menu_manager.addMenuItem(parentID, "devices.sidebar.onxcodecomplete");
    de_oxc_menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_oxc_menu.setStyle(MenuItem.STYLE_MENU);
    de_oxc_menu.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object data) {
            menu.removeAllChildItems();
            final List<MenuItem> oxc_items = new ArrayList<>();
            final MenuItem oxc_nothing = menu_manager.addMenuItem(de_oxc_menu, "devices.sidebar.oxc.nothing");
            oxc_items.add(oxc_nothing);
            oxc_nothing.setStyle(MenuItem.STYLE_CHECK);
            oxc_nothing.setData(oxc_action == OXC_NOTHING);
            final MenuItem oxc_close_vuze = menu_manager.addMenuItem(de_oxc_menu, "devices.sidebar.oxc.closevuze");
            oxc_items.add(oxc_close_vuze);
            oxc_close_vuze.setStyle(MenuItem.STYLE_CHECK);
            oxc_close_vuze.setData(oxc_action == OXC_QUIT_VUZE);
            PlatformManager pm = PlatformManagerFactory.getPlatformManager();
            int sdt = pm.getShutdownTypes();
            final Map<MenuItem, String> oxc_pm_map = new HashMap<>();
            for (int type : PlatformManager.SD_ALL) {
                if ((sdt | type) != 0) {
                    String action = OXC_NOTHING;
                    if (type == PlatformManager.SD_SLEEP) {
                        action = OXC_SLEEP;
                    } else if (type == PlatformManager.SD_HIBERNATE) {
                        action = OXC_HIBERNATE;
                    } else if (type == PlatformManager.SD_SHUTDOWN) {
                        action = OXC_SHUTDOWN;
                    } else {
                        Debug.out("Unknown type: " + type);
                    }
                    MenuItem oxc_pm = menu_manager.addMenuItem(de_oxc_menu, "devices.sidebar.oxc.pm." + type);
                    oxc_items.add(oxc_pm);
                    oxc_pm.setStyle(MenuItem.STYLE_CHECK);
                    oxc_pm.setData(oxc_action == action);
                    oxc_pm_map.put(oxc_pm, action);
                }
            }
            MenuItemListener oxc_mil = new MenuItemListener() {

                @Override
                public void selected(MenuItem menu, Object target) {
                    if ((Boolean) menu.getData()) {
                        if (menu == oxc_nothing) {
                            setOXCState(OXC_NOTHING);
                        } else if (menu == oxc_close_vuze) {
                            setOXCState(OXC_QUIT_VUZE);
                        } else {
                            setOXCState(oxc_pm_map.get(menu));
                        }
                    }
                }
            };
            for (MenuItem mi : oxc_items) {
                mi.addListener(oxc_mil);
            }
        }
    });
    de_menu_item = menu_manager.addMenuItem(parentID, "sep2");
    de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
    // options
    de_menu_item = menu_manager.addMenuItem(parentID, "MainWindow.menu.view.configuration");
    de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_menu_item.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, CONFIG_SECTION_ID);
            }
        }
    });
    if (Constants.isCVSVersion()) {
        de_menu_item = menu_manager.addMenuItem(parentID, "!(CVS Only)Show FTUX!");
        de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        de_menu_item.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                DevicesFTUX.showForDebug();
            }
        });
    }
}
Also used : PlatformManager(com.biglybt.platform.PlatformManager) UPnPDevice(com.biglybt.net.upnp.UPnPDevice) UnassociatedDevice(com.biglybt.core.devices.DeviceManager.UnassociatedDevice) UPnPRootDevice(com.biglybt.net.upnp.UPnPRootDevice) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) UIFunctions(com.biglybt.ui.UIFunctions) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) List(java.util.List)

Example 12 with UIFunctions

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

Example 13 with UIFunctions

use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.

the class OpenTorrentWindow method TorrentDownloaderEvent.

@Override
public void TorrentDownloaderEvent(int state, TorrentDownloader inf) {
    // We set this flag to false if we detected the file was not a torrent
    if (!inf.getDeleteFileOnCancel() && (state == TorrentDownloader.STATE_CANCELLED || state == TorrentDownloader.STATE_ERROR || state == TorrentDownloader.STATE_DUPLICATE || state == TorrentDownloader.STATE_FINISHED)) {
        File file = inf.getFile();
        // we already know it isn't a torrent.. we are just using the call
        // to popup the message
        boolean done = false;
        if (RSSUtils.isRSSFeed(file)) {
            try {
                URL url = new URL(inf.getURL());
                UIManager ui_manager = StaticUtilities.getUIManager(10 * 1000);
                if (ui_manager != null) {
                    String details = MessageText.getString("subscription.request.add.message", new String[] { inf.getURL() });
                    long res = ui_manager.showMessageBox("subscription.request.add.title", "!" + details + "!", UIManagerEvent.MT_YES | UIManagerEvent.MT_NO);
                    if (res == UIManagerEvent.MT_YES) {
                        SubscriptionManager sm = PluginInitializer.getDefaultInterface().getUtilities().getSubscriptionManager();
                        sm.requestSubscription(url);
                        done = true;
                    }
                }
            } catch (Throwable e) {
                Debug.out(e);
            }
        }
        if (!done) {
            TorrentUtil.isFileTorrent(inf.getURL(), file, inf.getURL(), true);
        }
        if (file.exists()) {
            file.delete();
        }
        return;
    }
    if (state == TorrentDownloader.STATE_INIT) {
    } else if (state == TorrentDownloader.STATE_FINISHED) {
        File file = inf.getFile();
        TorrentOpenOptions torrentOptions = new TorrentOpenOptions();
        if (!TorrentOpener.mergeFileIntoTorrentInfo(file.getAbsolutePath(), inf.getURL(), torrentOptions)) {
            if (file.exists())
                file.delete();
        } else {
            UIFunctions uif = UIFunctionsManager.getUIFunctions();
            boolean b = uif.addTorrentWithOptions(false, torrentOptions);
            if (!b && file.exists()) {
                file.delete();
            }
        }
    } else if (state == TorrentDownloader.STATE_CANCELLED || state == TorrentDownloader.STATE_ERROR || state == TorrentDownloader.STATE_DUPLICATE) {
    } else if (state == TorrentDownloader.STATE_DOWNLOADING) {
        int count = inf.getLastReadCount();
        int numRead = inf.getTotalRead();
        if (!inf.getDeleteFileOnCancel() && numRead >= 16384) {
            inf.cancel();
        } else if (numRead == count && count > 0) {
            final byte[] bytes = inf.getLastReadBytes();
            if (bytes[0] != 'd' && bytes[0] != '<') {
                inf.setDeleteFileOnCancel(false);
            }
        }
    } else {
        return;
    }
}
Also used : TorrentOpenOptions(com.biglybt.core.torrent.impl.TorrentOpenOptions) UIFunctions(com.biglybt.ui.UIFunctions) UIManager(com.biglybt.pif.ui.UIManager) SubscriptionManager(com.biglybt.pif.utils.subscriptions.SubscriptionManager) File(java.io.File) URL(java.net.URL)

Example 14 with UIFunctions

use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.

the class MainMDISetup method setupSidebarVuzeUI.

private static void setupSidebarVuzeUI(final MultipleDocumentInterfaceSWT mdi) {
    String[] preferredOrder = new String[] { MultipleDocumentInterface.SIDEBAR_HEADER_DASHBOARD, MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, MultipleDocumentInterface.SIDEBAR_HEADER_VUZE, MultipleDocumentInterface.SIDEBAR_HEADER_DISCOVERY, MultipleDocumentInterface.SIDEBAR_HEADER_DEVICES, MultipleDocumentInterface.SIDEBAR_HEADER_PLUGINS };
    mdi.setPreferredOrder(preferredOrder);
    sb_dashboard = new SB_Dashboard(mdi);
    for (int i = 0; i < preferredOrder.length; i++) {
        String id = preferredOrder[i];
        mdi.registerEntry(id, new MdiEntryCreationListener() {

            @Override
            public MdiEntry createMDiEntry(String id) {
                MdiEntry entry;
                if (id.equals(MultipleDocumentInterface.SIDEBAR_HEADER_DASHBOARD)) {
                    entry = sb_dashboard.setupMDIEntry();
                } else {
                    entry = mdi.createHeader(id, "sidebar." + id, null);
                    if (entry == null) {
                        return (null);
                    }
                    entry.setDefaultExpanded(true);
                    if (id.equals(MultipleDocumentInterface.SIDEBAR_HEADER_PLUGINS)) {
                        entry.addListener(new MdiChildCloseListener() {

                            @Override
                            public void mdiChildEntryClosed(MdiEntry parent, MdiEntry child, boolean user) {
                                if (mdi.getChildrenOf(parent.getId()).size() == 0) {
                                    parent.close(true);
                                }
                            }
                        });
                        PluginInterface pi = PluginInitializer.getDefaultInterface();
                        UIManager uim = pi.getUIManager();
                        MenuManager menuManager = uim.getMenuManager();
                        MenuItem menuItem;
                        menuItem = menuManager.addMenuItem("sidebar." + MultipleDocumentInterface.SIDEBAR_HEADER_PLUGINS, "label.plugin.options");
                        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                        menuItem.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, "plugins");
                                }
                            }
                        });
                    }
                }
                return entry;
            }
        });
    }
    sb_transfers = new SB_Transfers(mdi, true);
    sb_vuze = new SB_Vuze(mdi);
    new SB_Discovery(mdi);
    mdi.loadEntryByID(MultipleDocumentInterface.SIDEBAR_HEADER_DASHBOARD, false);
    mdi.loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_LIBRARY, false);
    if (COConfigurationManager.getBooleanParameter("Show New In Side Bar")) {
        mdi.loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_LIBRARY_UNOPENED, false);
    }
    mdi.loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_SUBSCRIPTIONS, false);
    mdi.loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_DEVICES, false);
    mdi.loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES, false);
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) UIManager(com.biglybt.pif.ui.UIManager) MenuItem(com.biglybt.pif.ui.menus.MenuItem) UIFunctions(com.biglybt.ui.UIFunctions) MenuManager(com.biglybt.pif.ui.menus.MenuManager) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener)

Example 15 with UIFunctions

use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.

the class IpFilterAutoLoaderImpl method downloadFiltersAsync.

/**
 * @param url
 *
 * @since 3.0.1.5
 */
void downloadFiltersAsync(URL url) {
    ResourceDownloader rd = ResourceDownloaderFactoryImpl.getSingleton().create(url);
    // old dl exists, load old one while new one downloads async
    rd.addListener(new ResourceDownloaderAdapter() {

        // @see com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter#reportPercentComplete(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader, int)
        @Override
        public void reportPercentComplete(ResourceDownloader downloader, int percentage) {
        }

        @Override
        public boolean completed(ResourceDownloader downloader, InputStream data) {
            try {
                setNextAutoDownload(true);
                Logger.log(new LogEvent(LOGID, "downloaded..waiting"));
                // since this is a different thread, we can use class_mon as
                // a cheap semaphore to wait until previous load completes
                class_mon.enter();
                Logger.log(new LogEvent(LOGID, "downloaded.. copying"));
                try {
                    FileUtil.copyFile(data, FileUtil.getUserFile("ipfilter.dl"));
                    AEThread thread = new AEThread("reload ipfilters", true) {

                        @Override
                        public void runSupport() {
                            try {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif != null) {
                                    uif.setStatusText("reloading.filters");
                                }
                                ipFilter.reload(false);
                                if (uif != null) {
                                    uif.setStatusText(null);
                                }
                            } catch (Exception e) {
                                Debug.out(e);
                            }
                        }
                    };
                    thread.setPriority(Thread.NORM_PRIORITY - 1);
                    thread.start();
                } catch (Exception e) {
                    Debug.out(e);
                }
            } finally {
                class_mon.exit();
            }
            return true;
        }
    });
    rd.asyncDownload();
}
Also used : ResourceDownloaderAdapter(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter) LogEvent(com.biglybt.core.logging.LogEvent) GZIPInputStream(java.util.zip.GZIPInputStream) ZipInputStream(java.util.zip.ZipInputStream) UIFunctions(com.biglybt.ui.UIFunctions) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) MalformedURLException(java.net.MalformedURLException) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException)

Aggregations

UIFunctions (com.biglybt.ui.UIFunctions)68 DownloadManager (com.biglybt.core.download.DownloadManager)16 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)9 GridLayout (org.eclipse.swt.layout.GridLayout)9 PluginInterface (com.biglybt.pif.PluginInterface)8 MenuItem (com.biglybt.pif.ui.menus.MenuItem)8 File (java.io.File)8 SelectionEvent (org.eclipse.swt.events.SelectionEvent)8 GridData (org.eclipse.swt.layout.GridData)8 CoreRunningListener (com.biglybt.core.CoreRunningListener)7 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 Menu (org.eclipse.swt.widgets.Menu)7 Core (com.biglybt.core.Core)6 LogEvent (com.biglybt.core.logging.LogEvent)6 UIFunctionsUserPrompter (com.biglybt.ui.UIFunctionsUserPrompter)6 Composite (org.eclipse.swt.widgets.Composite)6 MenuItem (org.eclipse.swt.widgets.MenuItem)6 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)5 GlobalManager (com.biglybt.core.global.GlobalManager)5 LogAlert (com.biglybt.core.logging.LogAlert)5