Search in sources :

Example 1 with PluginInterface

use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.

the class SB_Transfers method addHeaderMenu.

protected void addHeaderMenu() {
    PluginInterface pi = PluginInitializer.getDefaultInterface();
    UIManager uim = pi.getUIManager();
    assert uim != null;
    final MenuManager menuManager = uim.getMenuManager();
    MenuItem menuItem;
    menuItem = menuManager.addMenuItem("sidebar." + MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, "MyTorrentsView.menu.setCategory.add");
    menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    menuItem.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            CategoryUIUtils.showCreateCategoryDialog(null);
        }
    });
    // cats in sidebar
    menuItem.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object data) {
            menu.setVisible(COConfigurationManager.getBooleanParameter("Library.CatInSideBar"));
        }
    });
    menuItem = menuManager.addMenuItem("sidebar." + MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, "ConfigView.section.style.CatInSidebar");
    menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    menuItem.setStyle(MenuItem.STYLE_CHECK);
    menuItem.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            boolean b = COConfigurationManager.getBooleanParameter("Library.CatInSideBar");
            COConfigurationManager.setParameter("Library.CatInSideBar", !b);
        }
    });
    menuItem.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object data) {
            menu.setVisible(CategoryManager.getCategories().length > 0);
            menu.setData(COConfigurationManager.getBooleanParameter("Library.CatInSideBar"));
        }
    });
    // show tags in sidebar
    TagUIUtils.setupSideBarMenus(menuManager);
}
Also used : MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) PluginInterface(com.biglybt.pif.PluginInterface) MenuManager(com.biglybt.pif.ui.menus.MenuManager) UIManager(com.biglybt.pif.ui.UIManager) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener)

Example 2 with PluginInterface

use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.

the class SideBar method addGeneralMenus.

/**
 * @since 3.1.0.1
 */
private void addGeneralMenus() {
    PluginManager pm = CoreFactory.getSingleton().getPluginManager();
    PluginInterface pi = pm.getDefaultPluginInterface();
    UIManager uim = pi.getUIManager();
    MenuManager menuManager = uim.getMenuManager();
    {
        MenuItem menuItem = menuManager.addMenuItem("sidebar._end_", "menu.add.to.dashboard");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addFillListener(new MenuItemFillListener() {

            @Override
            public void menuWillBeShown(MenuItem menu, Object data) {
                SideBarEntrySWT sbe = (SideBarEntrySWT) currentEntry;
                if (sbe != null && sbe.getId().equals(MultipleDocumentInterface.SIDEBAR_HEADER_DASHBOARD)) {
                    menu.setVisible(false);
                } else {
                    menu.setVisible(sbe != null && sbe.canBuildStandAlone());
                }
            }
        });
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                SideBarEntrySWT sbe = (SideBarEntrySWT) currentEntry;
                if (sbe != null) {
                    MainMDISetup.getSb_dashboard().addItem(sbe);
                }
            }
        });
    }
    {
        MenuItem menuItem = menuManager.addMenuItem("sidebar._end_", "menu.pop.out");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addFillListener(new MenuItemFillListener() {

            @Override
            public void menuWillBeShown(MenuItem menu, Object data) {
                SideBarEntrySWT sbe = (SideBarEntrySWT) currentEntry;
                menu.setVisible(sbe != null && sbe.canBuildStandAlone());
            }
        });
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                SideBarEntrySWT sbe = (SideBarEntrySWT) currentEntry;
                if (sbe != null) {
                    SkinnedDialog skinnedDialog = new SkinnedDialog("skin3_dlg_sidebar_popout", "shell", // standalone
                    null, SWT.RESIZE | SWT.MAX | SWT.DIALOG_TRIM);
                    SWTSkin skin = skinnedDialog.getSkin();
                    SWTSkinObjectContainer cont = sbe.buildStandAlone((SWTSkinObjectContainer) skin.getSkinObject("content-area"));
                    if (cont != null) {
                        skinnedDialog.setTitle(sbe.getTitle());
                        skinnedDialog.open();
                    } else {
                        skinnedDialog.close();
                    }
                }
            }
        });
    }
}
Also used : PluginManager(com.biglybt.pif.PluginManager) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) PluginInterface(com.biglybt.pif.PluginInterface) MenuManager(com.biglybt.pif.ui.menus.MenuManager) UIManager(com.biglybt.pif.ui.UIManager) MenuItem(com.biglybt.pif.ui.menus.MenuItem) PluginUISWTSkinObject(com.biglybt.ui.swt.pif.PluginUISWTSkinObject) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) SkinnedDialog(com.biglybt.ui.swt.views.skin.SkinnedDialog)

Example 3 with PluginInterface

use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.

the class ConfigSectionPlugins method rebuildPluginIFs.

/**
 * @return
 *
 * @since 3.0.5.3
 */
private List rebuildPluginIFs() {
    List pluginIFs = Arrays.asList(CoreFactory.getSingleton().getPluginManager().getPlugins());
    for (Iterator iter = pluginIFs.iterator(); iter.hasNext(); ) {
        PluginInterface pi = (PluginInterface) iter.next();
        // COConfigurationManager will not add the same listener twice
        COConfigurationManager.addWeakParameterListener(this, false, "PluginInfo." + pi.getPluginID() + ".enabled");
    }
    return pluginIFs;
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) List(java.util.List)

Example 4 with PluginInterface

use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.

the class TorrentListViewsUtils method openInEMP.

/**
 * New version accepts map with ASX parameters. If the params are null then is uses the
 * old version to start the player. If the
 *
 * @param dm - DownloadManager
 * @return - int: 0 = ok, 1 = fail, 2 = abandon, installation in progress
 * @since 3.0.4.4 -
 */
private static int openInEMP(final DownloadManager dm, final int _file_index, final boolean complete_only, final String referal) {
    try {
        int file_index = -1;
        if (_file_index == -1) {
            EnhancedDownloadManager edm = DownloadManagerEnhancer.getSingleton().getEnhancedDownload(dm);
            if (edm != null) {
                file_index = edm.getPrimaryFileIndex();
            }
        } else {
            file_index = _file_index;
        }
        if (file_index == -1) {
            return (1);
        }
        final int f_file_index = file_index;
        com.biglybt.pif.disk.DiskManagerFileInfo file = PluginCoreUtils.wrap(dm).getDiskManagerFileInfo()[file_index];
        final URL url;
        if ((!complete_only) && file.getDownloaded() != file.getLength()) {
            url = PlayUtils.getMediaServerContentURL(file);
        } else {
            url = null;
        }
        if (url != null) {
            if (PlayUtils.isStreamPermitted()) {
                final boolean show_debug_window = false;
                new AEThread2("stream:async") {

                    @Override
                    public void run() {
                        StreamManager sm = StreamManager.getSingleton();
                        synchronized (TorrentListViewsUtils.class) {
                            if (current_stream != null && !current_stream.isCancelled()) {
                                if (current_stream.getURL().equals(url)) {
                                    current_stream.setPreviewMode(!current_stream.getPreviewMode());
                                    return;
                                }
                                current_stream.cancel();
                                current_stream = null;
                            }
                            if (show_debug_window && (stream_viewer == null || stream_viewer.isDisposed())) {
                                Utils.execSWTThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        if (stream_viewer != null) {
                                            stream_viewer.close();
                                        }
                                        stream_viewer = new TextViewerWindow("Stream Status", "Debug information for stream process", "", false);
                                        stream_viewer.addListener(new TextViewerWindow.TextViewerWindowListener() {

                                            @Override
                                            public void closed() {
                                                synchronized (TorrentListViewsUtils.class) {
                                                    if (current_stream != null) {
                                                        current_stream.cancel();
                                                        current_stream = null;
                                                    }
                                                }
                                            }
                                        });
                                    }
                                });
                            }
                            current_stream = sm.stream(dm, f_file_index, url, false, new StreamManagerDownloadListener() {

                                private long last_log = 0;

                                @Override
                                public void updateActivity(String str) {
                                    append("Activity: " + str);
                                }

                                @Override
                                public void updateStats(int secs_until_playable, int buffer_secs, long buffer_bytes, int target_secs) {
                                    long now = SystemTime.getMonotonousTime();
                                    if (now - last_log >= 1000) {
                                        last_log = now;
                                        append("stats: play in " + secs_until_playable + " sec, buffer=" + DisplayFormatters.formatByteCountToKiBEtc(buffer_bytes) + "/" + buffer_secs + " sec - target=" + target_secs + " sec");
                                    }
                                }

                                @Override
                                public void ready() {
                                    append("ready");
                                }

                                @Override
                                public void failed(Throwable error) {
                                    append("failed: " + Debug.getNestedExceptionMessage(error));
                                    Debug.out(error);
                                }

                                private void append(final String str) {
                                    if (stream_viewer != null) {
                                        Utils.execSWTThread(new Runnable() {

                                            @Override
                                            public void run() {
                                                if (stream_viewer != null && !stream_viewer.isDisposed()) {
                                                    stream_viewer.append(str + "\r\n");
                                                }
                                            }
                                        });
                                    }
                                }
                            });
                        }
                    }
                }.start();
            } else {
            // FeatureManagerUI.openStreamPlusWindow(referal);
            }
            return (0);
        }
        synchronized (TorrentListViewsUtils.class) {
            if (current_stream != null && !current_stream.isCancelled()) {
                current_stream.cancel();
                current_stream = null;
            }
        }
        Class epwClass = null;
        try {
            // Assumed we have a core, since we are passed a
            // DownloadManager
            PluginInterface pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByID("azemp", false);
            if (pi == null) {
                return (installEMP(dm.getDisplayName(), new Runnable() {

                    @Override
                    public void run() {
                        openInEMP(dm, f_file_index, complete_only, referal);
                    }
                }));
            } else if (!pi.getPluginState().isOperational()) {
                return (1);
            }
            epwClass = pi.getPlugin().getClass().getClassLoader().loadClass("com.azureus.plugins.azemp.ui.swt.emp.EmbeddedPlayerWindowSWT");
        } catch (ClassNotFoundException e1) {
            return 1;
        }
        try {
            Method method = epwClass.getMethod("openWindow", new Class[] { File.class, String.class });
            File f = file.getFile(true);
            method.invoke(null, new Object[] { f, f.getName() });
            return (0);
        } catch (Throwable e) {
            debug("file/name open method missing");
        }
        // fall through here if old emp
        Method method = epwClass.getMethod("openWindow", new Class[] { DownloadManager.class });
        method.invoke(null, new Object[] { dm });
        return 0;
    } catch (Throwable e) {
        e.printStackTrace();
        if (e.getMessage() == null || !e.getMessage().toLowerCase().endsWith("only")) {
            Debug.out(e);
        }
    }
    return 1;
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) Method(java.lang.reflect.Method) URL(java.net.URL) TextViewerWindow(com.biglybt.ui.swt.TextViewerWindow) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File)

Example 5 with PluginInterface

use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.

the class TableViewSWT_TabsCommon method buildFolder.

private void buildFolder(final Composite form, final String props_prefix) {
    PluginInterface pi = PluginInitializer.getDefaultInterface();
    UIManager uim = pi.getUIManager();
    MenuManager menuManager = uim.getMenuManager();
    menuItemShowTabs = menuManager.addMenuItem(props_prefix + "._end_", "ConfigView.section.style.ShowTabsInTorrentView");
    menuItemShowTabs.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    menuItemShowTabs.setStyle(MenuItem.STYLE_CHECK);
    menuItemShowTabs.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object data) {
            menu.setData(COConfigurationManager.getBooleanParameter("Library.ShowTabsInTorrentView"));
        }
    });
    menuItemShowTabs.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            COConfigurationManager.setParameter("Library.ShowTabsInTorrentView", (Boolean) menu.getData());
        }
    });
    cTabsHolder.addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event e) {
            if (tabbedMDI.getMinimized()) {
                fdHeightChanger.height = tabbedMDI.getFolderHeight();
                cTabsHolder.getParent().layout();
                return;
            }
            Double l = (Double) sash.getData("PCT");
            if (l != null) {
                int newHeight = (int) (form.getBounds().height * l.doubleValue());
                if (newHeight != fdHeightChanger.height) {
                    fdHeightChanger.height = newHeight;
                    cTabsHolder.getParent().layout();
                }
            }
        }
    });
    String[] restricted_to = tv.getTabViewsRestrictedTo();
    Set<String> rt_set = new HashSet<>();
    if (restricted_to != null) {
        rt_set.addAll(Arrays.asList(restricted_to));
    }
    // Call plugin listeners
    UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
    if (uiFunctions != null) {
        UISWTInstance pluginUI = uiFunctions.getUISWTInstance();
        if (pluginUI != null) {
            UISWTViewEventListenerWrapper[] pluginViews = pluginUI.getViewListeners(tv.getTableID());
            if (pluginViews != null) {
                for (final UISWTViewEventListenerWrapper l : pluginViews) {
                    if (l == null) {
                        continue;
                    }
                    try {
                        String view_id = l.getViewID();
                        if (restricted_to != null && !rt_set.contains(view_id)) {
                            continue;
                        }
                        tabbedMDI.registerEntry(view_id, new MdiEntryCreationListener2() {

                            @Override
                            public MdiEntry createMDiEntry(MultipleDocumentInterface mdi, String id, Object datasource, Map<?, ?> params) {
                                return addTabView(l, null);
                            }
                        });
                        tabbedMDI.loadEntryByID(view_id, false);
                    } catch (Exception e) {
                    // skip, plugin probably specifically asked to not be added
                    }
                }
            }
        }
    }
    if (!tabbedMDI.getMinimized()) {
        MdiEntry[] entries = tabbedMDI.getEntries();
        if (entries.length > 0) {
            tabbedMDI.showEntry(entries[0]);
        }
    }
}
Also used : MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) TabbedMdiMaximizeListener(com.biglybt.ui.swt.mdi.TabbedMdiMaximizeListener) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) Listener(org.eclipse.swt.widgets.Listener) SelectedContentListener(com.biglybt.ui.selectedcontent.SelectedContentListener) UIManager(com.biglybt.pif.ui.UIManager) MdiEntryCreationListener2(com.biglybt.ui.mdi.MdiEntryCreationListener2) MdiEntry(com.biglybt.ui.mdi.MdiEntry) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) HashSet(java.util.HashSet) PluginInterface(com.biglybt.pif.PluginInterface) MenuItem(com.biglybt.pif.ui.menus.MenuItem) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) MenuManager(com.biglybt.pif.ui.menus.MenuManager) Event(org.eclipse.swt.widgets.Event) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) UISWTViewEventListenerWrapper(com.biglybt.ui.swt.pif.UISWTInstance.UISWTViewEventListenerWrapper) UISWTInstance(com.biglybt.ui.swt.pif.UISWTInstance)

Aggregations

PluginInterface (com.biglybt.pif.PluginInterface)120 URL (java.net.URL)15 IPCInterface (com.biglybt.pif.ipc.IPCInterface)14 UIManager (com.biglybt.pif.ui.UIManager)13 PluginManager (com.biglybt.pif.PluginManager)12 HashMap (java.util.HashMap)12 List (java.util.List)12 Download (com.biglybt.pif.download.Download)10 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)10 File (java.io.File)10 Map (java.util.Map)10 DownloadManager (com.biglybt.core.download.DownloadManager)9 UIFunctions (com.biglybt.ui.UIFunctions)9 ArrayList (java.util.ArrayList)9 PluginException (com.biglybt.pif.PluginException)8 MenuItem (com.biglybt.pif.ui.menus.MenuItem)8 MenuManager (com.biglybt.pif.ui.menus.MenuManager)8 DHTPlugin (com.biglybt.plugin.dht.DHTPlugin)8 DHT (com.biglybt.core.dht.DHT)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7