Search in sources :

Example 1 with PluginEngine

use of com.biglybt.core.metasearch.impl.plugin.PluginEngine in project BiglyBT by BiglySoftware.

the class MetaSearchImpl method resolveProvider.

public SearchProvider resolveProvider(PluginEngine for_engine) {
    List<EngineImpl> l = engines.getList();
    for (EngineImpl e : l) {
        if (e instanceof PluginEngine) {
            PluginEngine pe = (PluginEngine) e;
            SearchProvider provider = pe.getProvider();
            if (provider != null) {
                if (pe.getName().equals(for_engine.getName())) {
                    return (provider);
                }
            }
        }
    }
    return (null);
}
Also used : SearchProvider(com.biglybt.pif.utils.search.SearchProvider) PluginEngine(com.biglybt.core.metasearch.impl.plugin.PluginEngine)

Example 2 with PluginEngine

use of com.biglybt.core.metasearch.impl.plugin.PluginEngine in project BiglyBT by BiglySoftware.

the class MetaSearchImpl method importFromPlugin.

public EngineImpl importFromPlugin(String _pid, SearchProvider provider) throws IOException {
    synchronized (this) {
        // unfortunately pid can be internationalised and thus musn't be used as a key to
        // a bencoded-map as it can lead of nastyness. Delete any existing entries that have
        // got out of control
        Iterator<String> it = plugin_map.keySet().iterator();
        while (it.hasNext()) {
            if (it.next().length() > 1024) {
                Debug.out("plugin_map corrupted, resetting");
                plugin_map.clear();
                break;
            }
        }
        String pid = Base32.encode(_pid.getBytes("UTF-8"));
        Long l_id = plugin_map.get(pid);
        long id;
        if (l_id == null) {
            id = manager.getLocalTemplateID();
            plugin_map.put(pid, new Long(id));
            configDirty();
        } else {
            id = l_id.longValue();
        }
        EngineImpl engine = (EngineImpl) getEngine(id);
        if (engine == null) {
            engine = new PluginEngine(this, id, provider);
            engine.setSource(Engine.ENGINE_SOURCE_LOCAL);
            engine.setSelectionState(Engine.SEL_STATE_MANUAL_SELECTED);
            addEngine(engine);
        } else {
            if (engine instanceof PluginEngine) {
                ((PluginEngine) engine).setProvider(provider);
            } else {
                Debug.out("Inconsistent: plugin must be a PluginEngine!");
                plugin_map.remove(pid);
                removeEngine(engine);
                throw (new IOException("Inconsistent"));
            }
        }
        return (engine);
    }
}
Also used : PluginEngine(com.biglybt.core.metasearch.impl.plugin.PluginEngine) IOException(java.io.IOException)

Example 3 with PluginEngine

use of com.biglybt.core.metasearch.impl.plugin.PluginEngine in project BiglyBT by BiglySoftware.

the class SearchUtils method addMenus.

public static void addMenus(Menu engine_menu, final Engine engine, boolean separator_required) {
    if (separator_required) {
        new MenuItem(engine_menu, SWT.SEPARATOR);
        separator_required = false;
    }
    if (!(engine instanceof PluginEngine)) {
        MenuItem export_json = new MenuItem(engine_menu, SWT.PUSH);
        Messages.setLanguageText(export_json, "menu.export.json.to.clipboard");
        export_json.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                final Shell shell = Utils.findAnyShell();
                shell.getDisplay().asyncExec(new AERunnable() {

                    @Override
                    public void runSupport() {
                        try {
                            ClipboardCopy.copyToClipBoard(engine.exportToVuzeFile().exportToJSON());
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                });
            }
        });
        final Subscription subs = engine.getSubscription();
        if (subs != null) {
            MenuItem export_uri = new MenuItem(engine_menu, SWT.PUSH);
            Messages.setLanguageText(export_uri, "label.copy.uri.to.clip");
            export_uri.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    final Shell shell = Utils.findAnyShell();
                    shell.getDisplay().asyncExec(new AERunnable() {

                        @Override
                        public void runSupport() {
                            try {
                                ClipboardCopy.copyToClipBoard(subs.getURI());
                            } catch (Throwable e) {
                                Debug.out(e);
                            }
                        }
                    });
                }
            });
        }
        new MenuItem(engine_menu, SWT.SEPARATOR);
        MenuItem remove_item = new MenuItem(engine_menu, SWT.PUSH);
        Messages.setLanguageText(remove_item, "Button.remove");
        Utils.setMenuItemImage(remove_item, "delete");
        remove_item.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                engine.setSelectionState(Engine.SEL_STATE_FORCE_DESELECTED);
            }
        });
        separator_required = true;
    }
    if (separator_required) {
        new MenuItem(engine_menu, SWT.SEPARATOR);
        separator_required = false;
    }
    MenuItem show_props = new MenuItem(engine_menu, SWT.PUSH);
    Messages.setLanguageText(show_props, "Subscription.menu.properties");
    show_props.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            showProperties(engine);
        }
    });
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) Shell(org.eclipse.swt.widgets.Shell) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) PluginEngine(com.biglybt.core.metasearch.impl.plugin.PluginEngine) Subscription(com.biglybt.core.subs.Subscription)

Example 4 with PluginEngine

use of com.biglybt.core.metasearch.impl.plugin.PluginEngine in project BiglyBT by BiglySoftware.

the class SearchUtils method addMenus.

public static void addMenus(final MenuManager menuManager) {
    final com.biglybt.pif.ui.menus.MenuItem template_menu = menuManager.addMenuItem("sidebar.Search", "Search.menu.engines");
    template_menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    template_menu.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
    template_menu.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
            template_menu.removeAllChildItems();
            Engine[] engines = MetaSearchManagerFactory.getSingleton().getMetaSearch().getEngines(true, false);
            Arrays.sort(engines, new Comparator<Engine>() {

                @Override
                public int compare(Engine o1, Engine o2) {
                    return (o1.getName().compareToIgnoreCase(o2.getName()));
                }
            });
            com.biglybt.pif.ui.menus.MenuItem import_menu = menuManager.addMenuItem(template_menu, "menu.import.json.from.clipboard");
            import_menu.addListener(new MenuItemListener() {

                @Override
                public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                    importFromClipboard();
                }
            });
            com.biglybt.pif.ui.menus.MenuItem sep = menuManager.addMenuItem(template_menu, "!sep!");
            sep.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
            for (int i = 0; i < engines.length; i++) {
                final Engine engine = engines[i];
                com.biglybt.pif.ui.menus.MenuItem engine_menu = menuManager.addMenuItem(template_menu, "!" + engine.getName() + "!");
                engine_menu.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
                if (!(engine instanceof PluginEngine)) {
                    com.biglybt.pif.ui.menus.MenuItem mi = menuManager.addMenuItem(engine_menu, "MyTorrentsView.menu.exportmenu");
                    mi.addListener(new MenuItemListener() {

                        @Override
                        public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                            final Shell shell = Utils.findAnyShell();
                            shell.getDisplay().asyncExec(new AERunnable() {

                                @Override
                                public void runSupport() {
                                    FileDialog dialog = new FileDialog(shell, SWT.SYSTEM_MODAL | SWT.SAVE);
                                    dialog.setFilterPath(TorrentOpener.getFilterPathData());
                                    dialog.setText(MessageText.getString("metasearch.export.select.template.file"));
                                    dialog.setFilterExtensions(VuzeFileHandler.getVuzeFileFilterExtensions());
                                    dialog.setFilterNames(VuzeFileHandler.getVuzeFileFilterExtensions());
                                    String path = TorrentOpener.setFilterPathData(dialog.open());
                                    if (path != null) {
                                        if (!VuzeFileHandler.isAcceptedVuzeFileName(path)) {
                                            path = VuzeFileHandler.getVuzeFileName(path);
                                        }
                                        try {
                                            engine.exportToVuzeFile(new File(path));
                                        } catch (Throwable e) {
                                            Debug.out(e);
                                        }
                                    }
                                }
                            });
                        }
                    });
                    com.biglybt.pif.ui.menus.MenuItem copy_mi = menuManager.addMenuItem(engine_menu, "menu.export.json.to.clipboard");
                    copy_mi.addListener(new MenuItemListener() {

                        @Override
                        public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                            final Shell shell = Utils.findAnyShell();
                            shell.getDisplay().asyncExec(new AERunnable() {

                                @Override
                                public void runSupport() {
                                    try {
                                        ClipboardCopy.copyToClipBoard(engine.exportToVuzeFile().exportToJSON());
                                    } catch (Throwable e) {
                                        Debug.out(e);
                                    }
                                }
                            });
                        }
                    });
                    final Subscription subs = engine.getSubscription();
                    if (subs != null) {
                        com.biglybt.pif.ui.menus.MenuItem copy_uri = menuManager.addMenuItem(engine_menu, "label.copy.uri.to.clip");
                        copy_uri.addListener(new MenuItemListener() {

                            @Override
                            public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                                final Shell shell = Utils.findAnyShell();
                                shell.getDisplay().asyncExec(new AERunnable() {

                                    @Override
                                    public void runSupport() {
                                        try {
                                            ClipboardCopy.copyToClipBoard(subs.getURI());
                                        } catch (Throwable e) {
                                            Debug.out(e);
                                        }
                                    }
                                });
                            }
                        });
                    }
                    if (engine instanceof WebEngine) {
                        final WebEngine we = (WebEngine) engine;
                        if (we.isNeedsAuth()) {
                            String cookies = we.getCookies();
                            if (cookies != null && cookies.length() > 0) {
                                mi = menuManager.addMenuItem(engine_menu, "Subscription.menu.resetauth");
                                mi.addListener(new MenuItemListener() {

                                    @Override
                                    public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                                        we.setCookies(null);
                                    }
                                });
                            }
                        }
                    }
                }
                if (!(engine instanceof PluginEngine)) {
                    if (engine_menu.getItems().length > 0) {
                        com.biglybt.pif.ui.menus.MenuItem mi = menuManager.addMenuItem(engine_menu, "Subscription.menu.sep");
                        mi.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
                    }
                    com.biglybt.pif.ui.menus.MenuItem mi = menuManager.addMenuItem(engine_menu, "Button.remove");
                    mi.addListener(new MenuItemListener() {

                        @Override
                        public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                            engine.setSelectionState(Engine.SEL_STATE_FORCE_DESELECTED);
                        }
                    });
                    mi = menuManager.addMenuItem(engine_menu, "Subscription.menu.sep2");
                    mi.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
                }
                if (engine_menu.getItems().length > 0) {
                    com.biglybt.pif.ui.menus.MenuItem mi = menuManager.addMenuItem(engine_menu, "Subscription.menu.sep2");
                    mi.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
                }
                com.biglybt.pif.ui.menus.MenuItem mi = menuManager.addMenuItem(engine_menu, "Subscription.menu.properties");
                mi.addListener(new MenuItemListener() {

                    @Override
                    public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                        showProperties(engine);
                    }
                });
            }
        }
    });
    com.biglybt.pif.ui.menus.MenuItem chat_menu = menuManager.addMenuItem("sidebar.Search", "label.chat");
    chat_menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    MenuBuildUtils.addChatMenu(menuManager, chat_menu, new MenuBuildUtils.ChatKeyResolver() {

        @Override
        public String getChatKey(Object object) {
            return ("Search Templates");
        }
    });
    com.biglybt.pif.ui.menus.MenuItem export_menu = menuManager.addMenuItem("sidebar.Search", "search.export.all");
    export_menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    export_menu.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
    export_menu.addListener(new MenuItemListener() {

        @Override
        public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
            exportAll();
        }
    });
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) MenuItem(org.eclipse.swt.widgets.MenuItem) PluginEngine(com.biglybt.core.metasearch.impl.plugin.PluginEngine) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) Shell(org.eclipse.swt.widgets.Shell) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) Subscription(com.biglybt.core.subs.Subscription) FileDialog(org.eclipse.swt.widgets.FileDialog) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine) Engine(com.biglybt.core.metasearch.Engine) PluginEngine(com.biglybt.core.metasearch.impl.plugin.PluginEngine) MenuBuildUtils(com.biglybt.ui.swt.MenuBuildUtils)

Aggregations

PluginEngine (com.biglybt.core.metasearch.impl.plugin.PluginEngine)4 Subscription (com.biglybt.core.subs.Subscription)2 AERunnable (com.biglybt.core.util.AERunnable)2 MenuItem (org.eclipse.swt.widgets.MenuItem)2 Shell (org.eclipse.swt.widgets.Shell)2 Engine (com.biglybt.core.metasearch.Engine)1 WebEngine (com.biglybt.core.metasearch.impl.web.WebEngine)1 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)1 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)1 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)1 SearchProvider (com.biglybt.pif.utils.search.SearchProvider)1 MenuBuildUtils (com.biglybt.ui.swt.MenuBuildUtils)1 File (java.io.File)1 IOException (java.io.IOException)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1