Search in sources :

Example 36 with UIFunctions

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

the class DisplayListener method handleMessage.

@Override
public void handleMessage(BrowserMessage message) {
    String opid = message.getOperationId();
    if (OP_COPY_TO_CLIPBOARD.equals(opid)) {
        Map decodedMap = message.getDecodedMap();
        ClipboardCopy.copyToClipBoard(MapUtils.getMapString(decodedMap, "text", ""));
    } else if (OP_BRING_TO_FRONT.equals(opid)) {
        bringToFront();
    } else if (OP_SHOW_DONATION_WINDOW.equals(opid)) {
        Map decodedMap = message.getDecodedMap();
        DonationWindow.open(true, MapUtils.getMapString(decodedMap, "source-ref", "RPC"));
    } else if (OP_OPEN_SEARCH.equals(opid)) {
        Map decodedMap = message.getDecodedMap();
        UIFunctions uif = UIFunctionsManager.getUIFunctions();
        if (uif != null) {
            uif.doSearch(MapUtils.getMapString(decodedMap, "search-text", ""));
        }
    } else {
        throw new IllegalArgumentException("Unknown operation: " + opid);
    }
}
Also used : UIFunctions(com.biglybt.ui.UIFunctions) Map(java.util.Map)

Example 37 with UIFunctions

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

the class DeviceManagerUI method buildCategories.

private void buildCategories(boolean full) {
    if (full) {
        MenuManager menu_manager = ui_manager.getMenuManager();
        // renderers
        categoryView renderers_category = addDeviceCategory(Device.DT_MEDIA_RENDERER, "device.renderer.view.title", "image.sidebar.device.renderer");
        categories.add(renderers_category);
        MenuItem re_menu_item = menu_manager.addMenuItem("sidebar." + renderers_category.getKey(), "device.show");
        re_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        re_menu_item.addListener(show_listener);
        re_menu_item.addFillListener(show_fill_listener);
        re_menu_item = menu_manager.addMenuItem("sidebar." + renderers_category.getKey(), "sep_re");
        re_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        re_menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
        re_menu_item = menu_manager.addMenuItem("sidebar." + renderers_category.getKey(), "device.renderer.remove_all");
        re_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        re_menu_item.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                new AEThread2("doit") {

                    @Override
                    public void run() {
                        UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
                        long res = ui_manager.showMessageBox("device.mediaserver.remove_all.title", "device.renderer.remove_all.desc", UIManagerEvent.MT_YES | UIManagerEvent.MT_NO);
                        if (res == UIManagerEvent.MT_YES) {
                            Device[] devices = device_manager.getDevices();
                            for (Device d : devices) {
                                if (d.getType() == Device.DT_MEDIA_RENDERER) {
                                    if (d.canRemove()) {
                                        d.remove();
                                    }
                                }
                            }
                        }
                    }
                }.start();
            }
        });
        // media servers
        categoryView media_servers_category = addDeviceCategory(Device.DT_CONTENT_DIRECTORY, "device.mediaserver.view.title", "image.sidebar.device.mediaserver");
        categories.add(media_servers_category);
        MenuItem ms_menu_item = menu_manager.addMenuItem("sidebar." + media_servers_category.getKey(), "device.show");
        ms_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        ms_menu_item.addListener(show_listener);
        ms_menu_item.addFillListener(show_fill_listener);
        ms_menu_item = menu_manager.addMenuItem("sidebar." + media_servers_category.getKey(), "device.mediaserver.configure");
        ms_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        ms_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, "upnpmediaserver.name");
                }
            }
        });
        ms_menu_item = menu_manager.addMenuItem("sidebar." + media_servers_category.getKey(), "sep_ms");
        ms_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        ms_menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
        ms_menu_item = menu_manager.addMenuItem("sidebar." + media_servers_category.getKey(), "device.mediaserver.remove_all");
        ms_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        ms_menu_item.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                new AEThread2("doit") {

                    @Override
                    public void run() {
                        UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
                        long res = ui_manager.showMessageBox("device.mediaserver.remove_all.title", "device.mediaserver.remove_all.desc", UIManagerEvent.MT_YES | UIManagerEvent.MT_NO);
                        if (res == UIManagerEvent.MT_YES) {
                            Device[] devices = device_manager.getDevices();
                            for (Device d : devices) {
                                if (d.getType() == Device.DT_CONTENT_DIRECTORY) {
                                    if (d.canRemove()) {
                                        d.remove();
                                    }
                                }
                            }
                        }
                    }
                }.start();
            }
        });
        // routers
        categoryView routers_category = addDeviceCategory(Device.DT_INTERNET_GATEWAY, "device.router.view.title", "image.sidebar.device.router");
        categories.add(routers_category);
        MenuItem rt_menu_item = menu_manager.addMenuItem("sidebar." + routers_category.getKey(), "device.show");
        rt_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        rt_menu_item.addListener(show_listener);
        rt_menu_item.addFillListener(show_fill_listener);
        rt_menu_item = menu_manager.addMenuItem("sidebar." + routers_category.getKey(), "device.router.configure");
        rt_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        rt_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, "UPnP");
                }
            }
        });
    }
    // internet
    categoryView internet_category = addDeviceCategory(Device.DT_INTERNET, "MainWindow.about.section.internet", "image.sidebar.device.internet");
    categories.add(internet_category);
}
Also used : UPnPDevice(com.biglybt.net.upnp.UPnPDevice) UnassociatedDevice(com.biglybt.core.devices.DeviceManager.UnassociatedDevice) UPnPRootDevice(com.biglybt.net.upnp.UPnPRootDevice) UIFunctions(com.biglybt.ui.UIFunctions) MenuManager(com.biglybt.pif.ui.menus.MenuManager) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener)

Example 38 with UIFunctions

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

the class BaseMDI method fillMenu.

public void fillMenu(Menu menu, final MdiEntry entry, String menuID) {
    com.biglybt.pif.ui.menus.MenuItem[] menu_items;
    menu_items = MenuItemManager.getInstance().getAllAsArray(menuID);
    MenuBuildUtils.addPluginMenuItems(menu_items, menu, false, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Object[] { entry }));
    if (entry != null) {
        menu_items = MenuItemManager.getInstance().getAllAsArray(getMenuIdPrefix() + entry.getId());
        if (menu_items.length == 0) {
            if (entry instanceof UISWTView) {
                PluginInterface pi = ((UISWTView) entry).getPluginInterface();
                if (pi != null) {
                    final List<String> relevant_sections = new ArrayList<>();
                    List<ConfigSectionHolder> sections = ConfigSectionRepository.getInstance().getHolderList();
                    for (ConfigSectionHolder cs : sections) {
                        if (pi == cs.getPluginInterface()) {
                            relevant_sections.add(cs.configSectionGetName());
                        }
                    }
                    if (relevant_sections.size() > 0) {
                        MenuItem mi = pi.getUIManager().getMenuManager().addMenuItem(getMenuIdPrefix() + entry.getId(), "MainWindow.menu.view.configuration");
                        mi.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                        mi.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif != null) {
                                    for (String s : relevant_sections) {
                                        uif.getMDI().showEntryByID(SIDEBAR_SECTION_CONFIG, s);
                                    }
                                }
                            }
                        });
                        menu_items = MenuItemManager.getInstance().getAllAsArray(getMenuIdPrefix() + entry.getId());
                    }
                }
            }
        }
        MenuBuildUtils.addPluginMenuItems(menu_items, menu, false, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Object[] { entry }));
        MdiSWTMenuHackListener[] menuHackListeners = getMenuHackListeners();
        for (MdiSWTMenuHackListener l : menuHackListeners) {
            try {
                l.menuWillBeShown(entry, menu);
            } catch (Exception e) {
                Debug.out(e);
            }
        }
        if (currentEntry instanceof SideBarEntrySWT) {
            menuHackListeners = ((SideBarEntrySWT) entry).getMenuHackListeners();
            for (MdiSWTMenuHackListener l : menuHackListeners) {
                try {
                    l.menuWillBeShown(entry, menu);
                } catch (Exception e) {
                    Debug.out(e);
                }
            }
        }
    }
    menu_items = MenuItemManager.getInstance().getAllAsArray(menuID + "._end_");
    if (menu_items.length > 0) {
        MenuBuildUtils.addPluginMenuItems(menu_items, menu, false, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Object[] { entry }));
    }
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) SideBarEntrySWT(com.biglybt.ui.swt.views.skin.sidebar.SideBarEntrySWT) ConfigSectionHolder(com.biglybt.pifimpl.local.ui.config.ConfigSectionHolder) MenuItem(com.biglybt.pif.ui.menus.MenuItem) UISWTView(com.biglybt.ui.swt.pif.UISWTView) UIFunctions(com.biglybt.ui.UIFunctions) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) MenuBuildUtils(com.biglybt.ui.swt.MenuBuildUtils)

Example 39 with UIFunctions

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

the class TorrentOpener method openTorrentsFromStrings.

/**
 * Adds torrents that are listed in torrents array.  torrent array can
 * can contain urls or file names.  File names get pathPrefix appended.
 * <P>
 * will open url download dialog, or warning dialogs
 *
 * @since 5.0.0.1
 */
public static void openTorrentsFromStrings(TorrentOpenOptions optionsToClone, Shell parent, String pathPrefix, String[] torrents, String referrer, TorrentDownloaderCallBackInterface listener, boolean forceTorrentOptionsWindow) {
    // if no torrents, but pathPrefix is directory, collect all torrents in it
    if (torrents == null || torrents.length == 0) {
        if (pathPrefix == null) {
            return;
        }
        File path = new File(pathPrefix);
        if (!path.isDirectory()) {
            return;
        }
        List<String> newTorrents = new ArrayList<>();
        File[] listFiles = path.listFiles();
        for (File file : listFiles) {
            try {
                if (file.isFile() && TorrentUtils.isTorrentFile(file.getAbsolutePath())) {
                    newTorrents.add(file.getName());
                }
            } catch (FileNotFoundException e) {
            } catch (IOException e) {
            }
        }
        if (newTorrents.size() == 0) {
            return;
        }
        torrents = newTorrents.toArray(new String[0]);
    }
    // trim out any .vuze files
    final VuzeFileHandler vfh = VuzeFileHandler.getSingleton();
    List<VuzeFile> vuze_files = new ArrayList<>();
    for (String line : torrents) {
        line = line.trim();
        if (line.startsWith("\"") && line.endsWith("\"")) {
            if (line.length() < 3) {
                line = "";
            } else {
                line = line.substring(1, line.length() - 2);
            }
        }
        TorrentOpenOptions torrentOptions = optionsToClone == null ? new TorrentOpenOptions() : new TorrentOpenOptions(optionsToClone);
        File file = pathPrefix == null ? new File(line) : new File(pathPrefix, line);
        if (file.exists()) {
            try {
                VuzeFile vf = vfh.loadVuzeFile(file);
                if (vf != null) {
                    vuze_files.add(vf);
                    continue;
                }
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
            try {
                File torrentDir = new File(COConfigurationManager.getDirectoryParameter("General_sDefaultTorrent_Directory"));
                if (COConfigurationManager.getBooleanParameter("Save Torrent Files") && torrentDir.exists() && file.getParentFile().equals(torrentDir)) {
                    torrentOptions.setDeleteFileOnCancel(false);
                }
            } catch (Throwable e) {
            }
            UIFunctions uif = UIFunctionsManager.getUIFunctions();
            if (TorrentOpener.mergeFileIntoTorrentInfo(file.getAbsolutePath(), null, torrentOptions)) {
                uif.addTorrentWithOptions(forceTorrentOptionsWindow, torrentOptions);
            }
            continue;
        }
        final String url = UrlUtils.parseTextForURL(line, true);
        if (url != null) {
            // we used to load any URL, but that results in double loading..
            if (VuzeFileHandler.isAcceptedVuzeFileName(url)) {
                new AEThread2("VuzeLoader") {

                    @Override
                    public void run() {
                        try {
                            // XXX This takes a while..
                            VuzeFile vf = vfh.loadVuzeFile(url);
                            if (vf != null) {
                                vfh.handleFiles(new VuzeFile[] { vf }, VuzeFileComponent.COMP_TYPE_NONE);
                            }
                        } catch (Throwable e) {
                            Debug.printStackTrace(e);
                        }
                    }
                }.start();
                continue;
            }
            new FileDownloadWindow(parent, url, referrer, null, torrentOptions, listener);
        }
    }
    if (vuze_files.size() > 0) {
        VuzeFile[] vfs = new VuzeFile[vuze_files.size()];
        vuze_files.toArray(vfs);
        vfh.handleFiles(vfs, VuzeFileComponent.COMP_TYPE_NONE);
    }
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) TorrentOpenOptions(com.biglybt.core.torrent.impl.TorrentOpenOptions) UIFunctions(com.biglybt.ui.UIFunctions) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File) VuzeFileHandler(com.biglybt.core.vuzefile.VuzeFileHandler)

Example 40 with UIFunctions

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

the class PMSWTImpl method initialise.

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

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

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

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

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

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

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

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

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

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

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

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