Search in sources :

Example 21 with Core

use of com.biglybt.core.Core in project BiglyBT by BiglySoftware.

the class CoreWaiterSWT method waitForCore.

public static void waitForCore(final TriggerInThread triggerInThread, final CoreRunningListener l) {
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(final Core core) {
            if (triggerInThread == TriggerInThread.ANY_THREAD) {
                l.coreRunning(core);
            } else if (triggerInThread == TriggerInThread.NEW_THREAD) {
                new AEThread2("CoreWaiterInvoke", true) {

                    @Override
                    public void run() {
                        l.coreRunning(core);
                    }
                }.start();
            }
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    // TODO: Need to detect cancel (can't rely on shell status since it may never open)
                    if (shell != null && !shell.isDisposed()) {
                        shell.dispose();
                        shell = null;
                    }
                    if (triggerInThread == TriggerInThread.SWT_THREAD) {
                        l.coreRunning(core);
                    }
                }
            });
        }
    });
    if (!CoreFactory.isCoreRunning()) {
        if (DEBUG) {
            System.out.println("NOT AVAIL FOR " + Debug.getCompressedStackTrace());
        }
        Utils.execSWTThread(new AERunnable() {

            @Override
            public void runSupport() {
                showWaitWindow();
            }
        });
    } else if (DEBUG) {
        System.out.println("NO NEED TO WAIT.. CORE AVAIL! " + Debug.getCompressedStackTrace());
    }
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) CoreRunningListener(com.biglybt.core.CoreRunningListener) AEThread2(com.biglybt.core.util.AEThread2) Core(com.biglybt.core.Core)

Example 22 with Core

use of com.biglybt.core.Core in project BiglyBT by BiglySoftware.

the class TorrentUtil method addSpeedLimitsMenu.

protected static void addSpeedLimitsMenu(DownloadManager[] dms, Menu menu) {
    Core core = CoreFactory.getSingleton();
    Shell menu_shell = menu.getShell();
    final SpeedLimitHandler slh = SpeedLimitHandler.getSingleton(core);
    boolean all_have_limit = true;
    Set<String> common_profiles = new HashSet<>();
    final List<byte[]> dm_hashes = new ArrayList<>();
    for (int i = 0; i < dms.length; i++) {
        DownloadManager dm = dms[i];
        int maxul = dm.getStats().getUploadRateLimitBytesPerSecond();
        int maxdl = dm.getStats().getDownloadRateLimitBytesPerSecond();
        if (maxul == 0 && maxdl == 0) {
            all_have_limit = false;
        }
        TOTorrent t = dm.getTorrent();
        if (t == null) {
            common_profiles.clear();
        } else {
            try {
                byte[] hash = t.getHash();
                dm_hashes.add(hash);
                List<String> profs = slh.getProfilesForDownload(hash);
                if (i == 0) {
                    common_profiles.addAll(profs);
                } else {
                    common_profiles.retainAll(profs);
                }
            } catch (TOTorrentException e) {
                Debug.out(e);
                common_profiles.clear();
            }
        }
    }
    java.util.List<String> profiles = slh.getProfileNames();
    // add to profile
    final Menu add_to_prof_menu = new Menu(menu_shell, SWT.DROP_DOWN);
    MenuItem add_to_prof_item = new MenuItem(menu, SWT.CASCADE);
    add_to_prof_item.setMenu(add_to_prof_menu);
    Messages.setLanguageText(add_to_prof_item, "MyTorrentsView.menu.sl_add_to_prof");
    if (!all_have_limit) {
        add_to_prof_item.setEnabled(false);
    } else {
        for (final String p : profiles) {
            MenuItem addItem = new MenuItem(add_to_prof_menu, SWT.PUSH);
            addItem.setText(p);
            addItem.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event arg0) {
                    slh.addDownloadsToProfile(p, dm_hashes);
                    MenuFactory.showText("MainWindow.menu.speed_limits.info.title", MessageText.getString("MainWindow.menu.speed_limits.info.prof", new String[] { p }), slh.getProfile(p));
                }
            });
        }
    }
    // remove from profile
    final Menu remove_from_prof_menu = new Menu(menu_shell, SWT.DROP_DOWN);
    MenuItem remove_from_prof_item = new MenuItem(menu, SWT.CASCADE);
    remove_from_prof_item.setMenu(remove_from_prof_menu);
    Messages.setLanguageText(remove_from_prof_item, "MyTorrentsView.menu.sl_remove_from_prof");
    if (common_profiles.isEmpty()) {
        remove_from_prof_item.setEnabled(false);
    } else {
        for (final String p : common_profiles) {
            MenuItem addItem = new MenuItem(remove_from_prof_menu, SWT.PUSH);
            addItem.setText(p);
            addItem.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event arg0) {
                    slh.removeDownloadsFromProfile(p, dm_hashes);
                    MenuFactory.showText("MainWindow.menu.speed_limits.info.title", MessageText.getString("MainWindow.menu.speed_limits.info.prof", new String[] { p }), slh.getProfile(p));
                }
            });
        }
    }
}
Also used : UIManagerListener(com.biglybt.pif.ui.UIManagerListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) WebSeedsEditorListener(com.biglybt.ui.swt.maketorrent.WebSeedsEditorListener) UIToolBarActivationListener(com.biglybt.pif.ui.toolbar.UIToolBarActivationListener) TrackerEditorListener(com.biglybt.ui.swt.maketorrent.TrackerEditorListener) SpeedLimitHandler(com.biglybt.core.speedmanager.SpeedLimitHandler) DownloadManager(com.biglybt.core.download.DownloadManager) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) java.util(java.util) com.biglybt.core.util(com.biglybt.core.util) TOTorrent(com.biglybt.core.torrent.TOTorrent) MenuEvent(org.eclipse.swt.events.MenuEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Core(com.biglybt.core.Core) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore)

Example 23 with Core

use of com.biglybt.core.Core in project BiglyBT by BiglySoftware.

the class UI method coreCreated.

@Override
public void coreCreated(Core core) {
    super.coreCreated(core);
    UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
    if (uiFunctions != null) {
        openQueuedTorrents();
    } else {
        core.addLifecycleListener(new CoreLifecycleAdapter() {

            @Override
            public void componentCreated(Core core, CoreComponent component) {
                if (component instanceof UIFunctionsSWT) {
                    openQueuedTorrents();
                    core.removeLifecycleListener(this);
                }
            }
        });
    }
}
Also used : CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) UIFunctions(com.biglybt.ui.UIFunctions) CoreComponent(com.biglybt.core.CoreComponent) Core(com.biglybt.core.Core)

Example 24 with Core

use of com.biglybt.core.Core in project BiglyBT by BiglySoftware.

the class MenuFactory method buildTorrentMenu.

public static void buildTorrentMenu(Menu menu) {
    DownloadManager[] current_dls = (DownloadManager[]) menu.getData("downloads");
    current_dls = ManagerUtils.cleanUp(current_dls);
    if (current_dls.length == 0) {
        return;
    }
    if (CoreFactory.isCoreRunning()) {
        boolean is_detailed_view = ((Boolean) menu.getData("is_detailed_view")).booleanValue();
        TableViewSWT<?> tv = (TableViewSWT<?>) menu.getData("TableView");
        Core core = CoreFactory.getSingleton();
        TorrentUtil.fillTorrentMenu(menu, current_dls, core, !is_detailed_view, 0, tv);
    }
    com.biglybt.pif.ui.menus.MenuItem[] menu_items;
    menu_items = MenuItemManager.getInstance().getAllAsArray(new String[] { MenuManager.MENU_TORRENT_MENU, MenuManager.MENU_DOWNLOAD_CONTEXT });
    final Object[] plugin_dls = DownloadManagerImpl.getDownloadStatic(current_dls);
    if (menu_items.length > 0) {
        addSeparatorMenuItem(menu);
        MenuBuildUtils.addPluginMenuItems(menu_items, menu, true, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(plugin_dls));
    }
    menu_items = null;
    /**
     * OK, "hack" time - we'll allow plugins which add menu items against
     * a table to appear in this menu. We'll have to fake the table row
     * object though. All downloads need to share a common table.
     */
    String table_to_use = null;
    for (int i = 0; i < current_dls.length; i++) {
        String table_name = (current_dls[i].isDownloadComplete(false) ? TableManager.TABLE_MYTORRENTS_COMPLETE : TableManager.TABLE_MYTORRENTS_INCOMPLETE);
        if (table_to_use == null || table_to_use.equals(table_name)) {
            table_to_use = table_name;
        } else {
            table_to_use = null;
            break;
        }
    }
    if (table_to_use != null) {
        menu_items = TableContextMenuManager.getInstance().getAllAsArray(table_to_use);
    }
    if (menu_items != null) {
        addSeparatorMenuItem(menu);
        TableRow[] dls_as_rows = null;
        dls_as_rows = new TableRow[plugin_dls.length];
        for (int i = 0; i < plugin_dls.length; i++) {
            dls_as_rows[i] = wrapAsRow(plugin_dls[i], table_to_use);
        }
        MenuBuildUtils.addPluginMenuItems(menu_items, menu, true, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(dls_as_rows));
    }
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager) TableViewSWT(com.biglybt.ui.swt.views.table.TableViewSWT) Core(com.biglybt.core.Core)

Example 25 with Core

use of com.biglybt.core.Core in project BiglyBT by BiglySoftware.

the class MenuFactory method addSpeedLimitsToMenu.

public static MenuItem addSpeedLimitsToMenu(final Menu menuParent) {
    MenuItem speedLimitsMenuItem = createTopLevelMenuItem(menuParent, MENU_ID_SPEED_LIMITS);
    MenuBuildUtils.addMaintenanceListenerForMenu(speedLimitsMenuItem.getMenu(), new MenuBuildUtils.MenuBuilder() {

        @Override
        public void buildMenu(Menu menu, MenuEvent menuEvent) {
            if (CoreFactory.isCoreRunning()) {
                Core core = CoreFactory.getSingleton();
                final SpeedLimitHandler slh = SpeedLimitHandler.getSingleton(core);
                MenuItem viewCurrentItem = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(viewCurrentItem, "MainWindow.menu.speed_limits.view_current");
                viewCurrentItem.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event arg0) {
                        showText("MainWindow.menu.speed_limits.info.title", "MainWindow.menu.speed_limits.info.curr", slh.getCurrent());
                    }
                });
                java.util.List<String> profiles = slh.getProfileNames();
                Menu profiles_menu = new Menu(Utils.findAnyShell(), SWT.DROP_DOWN);
                MenuItem profiles_item = new MenuItem(menu, SWT.CASCADE);
                profiles_item.setMenu(profiles_menu);
                Messages.setLanguageText(profiles_item, "MainWindow.menu.speed_limits.profiles");
                if (profiles.size() == 0) {
                    profiles_item.setEnabled(false);
                } else {
                    for (final String p : profiles) {
                        Menu profile_menu = new Menu(Utils.findAnyShell(), SWT.DROP_DOWN);
                        MenuItem profile_item = new MenuItem(profiles_menu, SWT.CASCADE);
                        profile_item.setMenu(profile_menu);
                        profile_item.setText(p);
                        MenuItem loadItem = new MenuItem(profile_menu, SWT.PUSH);
                        Messages.setLanguageText(loadItem, "MainWindow.menu.speed_limits.load");
                        loadItem.addListener(SWT.Selection, new Listener() {

                            @Override
                            public void handleEvent(Event arg0) {
                                showText("MainWindow.menu.speed_limits.info.title", MessageText.getString("MainWindow.menu.speed_limits.info.prof", new String[] { p }), slh.loadProfile(p));
                            }
                        });
                        MenuItem viewItem = new MenuItem(profile_menu, SWT.PUSH);
                        Messages.setLanguageText(viewItem, "MainWindow.menu.speed_limits.view");
                        viewItem.addListener(SWT.Selection, new Listener() {

                            @Override
                            public void handleEvent(Event arg0) {
                                showText("MainWindow.menu.speed_limits.info.title", MessageText.getString("MainWindow.menu.speed_limits.info.prof", new String[] { p }), slh.getProfile(p));
                            }
                        });
                        addSeparatorMenuItem(profile_menu);
                        MenuItem deleteItem = new MenuItem(profile_menu, SWT.PUSH);
                        Messages.setLanguageText(deleteItem, "MainWindow.menu.speed_limits.delete");
                        deleteItem.addListener(SWT.Selection, new Listener() {

                            @Override
                            public void handleEvent(Event arg0) {
                                slh.deleteProfile(p);
                            }
                        });
                    }
                }
                MenuItem saveItem = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(saveItem, "MainWindow.menu.speed_limits.save_current");
                saveItem.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event arg0) {
                        UISWTInputReceiver entry = new SimpleTextEntryWindow();
                        entry.allowEmptyInput(false);
                        entry.setLocalisedTitle(MessageText.getString("MainWindow.menu.speed_limits.profile"));
                        entry.prompt(new UIInputReceiverListener() {

                            @Override
                            public void UIInputReceiverClosed(UIInputReceiver entry) {
                                if (!entry.hasSubmittedInput()) {
                                    return;
                                }
                                String input = entry.getSubmittedInput().trim();
                                if (input.length() > 0) {
                                    showText("MainWindow.menu.speed_limits.info.title", MessageText.getString("MainWindow.menu.speed_limits.info.prof", new String[] { input }), slh.saveProfile(input));
                                }
                            }
                        });
                    }
                });
                addSeparatorMenuItem(menu);
                MenuItem resetItem = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(resetItem, "MainWindow.menu.speed_limits.reset");
                resetItem.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event arg0) {
                        showText("MainWindow.menu.speed_limits.info.title", "MainWindow.menu.speed_limits.info.curr", slh.reset());
                    }
                });
                addSeparatorMenuItem(menu);
                MenuItem scheduleItem = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(scheduleItem, "MainWindow.menu.speed_limits.schedule");
                scheduleItem.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event arg0) {
                        Utils.execSWTThreadLater(1, new Runnable() {

                            @Override
                            public void run() {
                                java.util.List<String> lines = slh.getSchedule();
                                StringBuilder text = new StringBuilder(80 * lines.size());
                                for (String s : lines) {
                                    if (text.length() > 0) {
                                        text.append("\n");
                                    }
                                    text.append(s);
                                }
                                final TextViewerWindow viewer = new TextViewerWindow("MainWindow.menu.speed_limits.schedule.title", "MainWindow.menu.speed_limits.schedule.msg", text.toString(), false);
                                viewer.setEditable(true);
                                viewer.addListener(new TextViewerWindow.TextViewerWindowListener() {

                                    @Override
                                    public void closed() {
                                        if (viewer.getOKPressed()) {
                                            String text = viewer.getText();
                                            String[] lines = text.split("\n");
                                            java.util.List<String> updated_lines = new ArrayList<>(Arrays.asList(lines));
                                            java.util.List<String> result = slh.setSchedule(updated_lines);
                                            if (result != null && result.size() > 0) {
                                                showText("MainWindow.menu.speed_limits.schedule.title", "MainWindow.menu.speed_limits.schedule.err", result);
                                            }
                                        }
                                    }
                                });
                            }
                        });
                    }
                });
                addSeparatorMenuItem(menu);
                MenuItem helpItem = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(helpItem, "MainWindow.menu.speed_limits.wiki");
                helpItem.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event arg0) {
                        Utils.launch(MessageText.getString("MainWindow.menu.speed_limits.wiki.url"));
                    }
                });
            }
        }
    });
    return (speedLimitsMenuItem);
}
Also used : UpdateCheckInstanceListener(com.biglybt.pif.update.UpdateCheckInstanceListener) ParameterListener(com.biglybt.core.config.ParameterListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) SpeedLimitHandler(com.biglybt.core.speedmanager.SpeedLimitHandler) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Core(com.biglybt.core.Core) UISWTInputReceiver(com.biglybt.ui.swt.pif.UISWTInputReceiver) com.biglybt.core.util(com.biglybt.core.util) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Aggregations

Core (com.biglybt.core.Core)71 CoreRunningListener (com.biglybt.core.CoreRunningListener)37 DownloadManager (com.biglybt.core.download.DownloadManager)17 CoreLifecycleAdapter (com.biglybt.core.CoreLifecycleAdapter)12 GlobalManager (com.biglybt.core.global.GlobalManager)10 File (java.io.File)9 GridLayout (org.eclipse.swt.layout.GridLayout)8 UIFunctions (com.biglybt.ui.UIFunctions)6 Composite (org.eclipse.swt.widgets.Composite)6 ParameterListener (com.biglybt.core.config.ParameterListener)5 LogAlert (com.biglybt.core.logging.LogAlert)5 TOTorrent (com.biglybt.core.torrent.TOTorrent)5 AERunnable (com.biglybt.core.util.AERunnable)5 GridData (org.eclipse.swt.layout.GridData)5 DownloadManagerInitialisationAdapter (com.biglybt.core.download.DownloadManagerInitialisationAdapter)4 PluginInterface (com.biglybt.pif.PluginInterface)4 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)4 ArrayList (java.util.ArrayList)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 MessageText (com.biglybt.core.internat.MessageText)3