Search in sources :

Example 31 with PluginInterface

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

the class Show method showDHTStats.

protected void showDHTStats(ConsoleInput ci) {
    try {
        PluginInterface def = ci.core.getPluginManager().getDefaultPluginInterface();
        PluginInterface dht_pi = def.getPluginManager().getPluginInterfaceByClass(DHTPlugin.class);
        if (dht_pi == null) {
            ci.out.println("\tDHT isn't present");
            return;
        }
        DHTPlugin dht_plugin = (DHTPlugin) dht_pi.getPlugin();
        if (dht_plugin.getStatus() != DHTPlugin.STATUS_RUNNING) {
            ci.out.println("\tDHT isn't running yet (disabled or initialising)");
            return;
        }
        DHT[] dhts = dht_plugin.getDHTs();
        for (int i = 0; i < dhts.length; i++) {
            if (i > 0) {
                ci.out.println("");
            }
            DHT dht = dhts[i];
            DHTTransport transport = dht.getTransport();
            DHTTransportStats t_stats = transport.getStats();
            DHTDBStats d_stats = dht.getDataBase().getStats();
            DHTControlStats c_stats = dht.getControl().getStats();
            DHTRouterStats r_stats = dht.getRouter().getStats();
            long[] rs = r_stats.getStats();
            DHTNetworkPosition[] nps = transport.getLocalContact().getNetworkPositions();
            String np_str = "";
            for (int j = 0; j < nps.length; j++) {
                np_str += (j == 0 ? "" : ",") + nps[j];
            }
            ci.out.println("DHT:ip=" + transport.getLocalContact().getAddress() + ",net=" + transport.getNetwork() + ",prot=V" + transport.getProtocolVersion() + ",np=" + np_str + ",sleeping=" + dht.isSleeping());
            ci.out.println("Router" + ":nodes=" + rs[DHTRouterStats.ST_NODES] + ",leaves=" + rs[DHTRouterStats.ST_LEAVES] + ",contacts=" + rs[DHTRouterStats.ST_CONTACTS] + ",replacement=" + rs[DHTRouterStats.ST_REPLACEMENTS] + ",live=" + rs[DHTRouterStats.ST_CONTACTS_LIVE] + ",unknown=" + rs[DHTRouterStats.ST_CONTACTS_UNKNOWN] + ",failing=" + rs[DHTRouterStats.ST_CONTACTS_DEAD]);
            ci.out.println("Transport" + ":" + t_stats.getString());
            int[] dbv_details = d_stats.getValueDetails();
            ci.out.println("Control:dht=" + c_stats.getEstimatedDHTSize() + ", Database:keys=" + d_stats.getKeyCount() + ",vals=" + dbv_details[DHTDBStats.VD_VALUE_COUNT] + ",loc=" + dbv_details[DHTDBStats.VD_LOCAL_SIZE] + ",dir=" + dbv_details[DHTDBStats.VD_DIRECT_SIZE] + ",ind=" + dbv_details[DHTDBStats.VD_INDIRECT_SIZE] + ",div_f=" + dbv_details[DHTDBStats.VD_DIV_FREQ] + ",div_s=" + dbv_details[DHTDBStats.VD_DIV_SIZE]);
            dht.getRouter().print();
        }
    } catch (Throwable e) {
        e.printStackTrace(ci.out);
    }
}
Also used : DHTDBStats(com.biglybt.core.dht.db.DHTDBStats) PluginInterface(com.biglybt.pif.PluginInterface) DHT(com.biglybt.core.dht.DHT) DHTNetworkPosition(com.biglybt.core.dht.netcoords.DHTNetworkPosition) DHTPlugin(com.biglybt.plugin.dht.DHTPlugin) DHTRouterStats(com.biglybt.core.dht.router.DHTRouterStats) DHTControlStats(com.biglybt.core.dht.control.DHTControlStats)

Example 32 with PluginInterface

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

the class UI method startUI.

private void startUI() {
    boolean created_console = false;
    if (console == null || !console.isAlive()) {
        // ConsoleInput.printconsolehelp(System.out);
        System.out.println();
        PrintStream this_out = System.out;
        // Unless a system property tells us not to, we'll take stdout and stderr offline.
        if (!"on".equals(System.getProperty(SystemProperties.SYSPROP_CONSOLE_NOISY)) && isFirst()) {
            // We'll hide any output to stdout or stderr - we don't want to litter our
            // view.
            PrintStream ps = new PrintStream(new java.io.OutputStream() {

                @Override
                public void write(int c) {
                }

                @Override
                public void write(byte[] b, int i1, int i2) {
                }
            });
            System.setOut(ps);
            System.setErr(ps);
            com.biglybt.core.logging.Logger.allowLoggingToStdErr(false);
        }
        console = new ConsoleInput("Main", core, System.in, this_out, Boolean.TRUE);
        console.printwelcome();
        console.printconsolehelp();
        created_console = true;
    }
    PluginInterface pi = core.getPluginManager().getDefaultPluginInterface();
    UIManager ui_manager = pi.getUIManager();
    ui_manager.addUIEventListener(this);
    try {
        ui_manager.attachUI(this);
    } catch (UIException e) {
        e.printStackTrace();
    }
    TorrentDownloaderFactory.initManager(core.getGlobalManager(), true, true, COConfigurationManager.getStringParameter("Default save path"));
    if (created_console && System.getProperty(SystemProperties.SYSPROP_CONSOLE_MULTIUSER) != null) {
        UserManager manager = UserManager.getInstance(pi);
        console.registerCommand(new UserCommand(manager));
    }
}
Also used : java.io(java.io) PluginInterface(com.biglybt.pif.PluginInterface) UserCommand(com.biglybt.ui.console.multiuser.commands.UserCommand) UserManager(com.biglybt.ui.console.multiuser.UserManager)

Example 33 with PluginInterface

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

the class Archive method execute.

@Override
public void execute(String commandName, ConsoleInput ci, List<String> args) {
    if (args.size() > 0) {
        PluginInterface pi = ci.getCore().getPluginManager().getDefaultPluginInterface();
        DownloadStub[] stubs = pi.getDownloadManager().getDownloadStubs();
        String sub = args.get(0);
        int index = -1;
        if (args.size() > 1) {
            String index_str = args.get(1);
            try {
                index = Integer.parseInt(index_str);
                index--;
                if (index < 0 || index >= stubs.length) {
                    index = -1;
                }
            } catch (Throwable e) {
            }
            if (index == -1) {
                ci.out.println("Invalid archive index: " + index_str);
            }
        }
        if (sub.equals("list") || sub.equals("l")) {
            int pos = 1;
            ci.out.println("> -----");
            for (DownloadStub stub : stubs) {
                System.out.println(" " + (pos++) + "\t" + stub.getName() + " (" + DisplayFormatters.formatByteCountToKiBEtc(stub.getTorrentSize()) + ")");
            }
            ci.out.println("> -----");
        } else if (index != -1 && (sub.equals("show") || sub.equals("s"))) {
            try {
                DownloadStub stub = stubs[index];
                ci.out.println("> -----");
                ci.out.println("  " + stub.getName() + " - hash=" + ByteFormatter.encodeString(stub.getTorrentHash()));
                DownloadStubFile[] files = stub.getStubFiles();
                ci.out.println("  Files: " + files.length);
                for (DownloadStubFile file : files) {
                    long length = file.getLength();
                    ci.out.println("    " + file.getFile() + " - " + (length < 0 ? ("Not downloaded") : DisplayFormatters.formatByteCountToKiBEtc(length)));
                }
                ci.out.println("> -----");
            } catch (Throwable e) {
                ci.out.print(e);
            }
        } else if (index != -1 && (sub.equals("restore") || sub.equals("res"))) {
            try {
                Download d = stubs[index].destubbify();
                ci.out.println("> Restore of " + d.getName() + " succeeded.");
            } catch (Throwable e) {
                ci.out.print(e);
            }
        } else if (index != -1 && (sub.equals("delete") || sub.equals("del"))) {
            try {
                DownloadStub stub = stubs[index];
                String name = stub.getName();
                stub.remove();
                ci.out.println("> Delete of " + name + " succeeded.");
            } catch (Throwable e) {
                ci.out.print(e);
            }
        } else {
            ci.out.println("Unsupported sub-command: " + sub);
            return;
        }
    } else {
        printHelp(ci.out, args);
    }
}
Also used : DownloadStub(com.biglybt.pif.download.DownloadStub) DownloadStubFile(com.biglybt.pif.download.DownloadStub.DownloadStubFile) PluginInterface(com.biglybt.pif.PluginInterface) Download(com.biglybt.pif.download.Download)

Example 34 with PluginInterface

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

the class DevicesFTUX method open.

void open(Runnable fire_on_install) {
    synchronized (to_fire_on_complete) {
        to_fire_on_complete.add(fire_on_install);
    }
    // This is a simple dialog box, so instead of using SkinnedDialog, we'll
    // just built it old school
    shell = ShellFactory.createMainShell(SWT.DIALOG_TRIM);
    shell.setText(MessageText.getString("devices.turnon.title"));
    Utils.setShellIcon(shell);
    text_area = new StyledText(shell, SWT.BORDER);
    text_area.setEditable(false);
    text_area.setLeftMargin(5);
    String blurb = MessageText.getString("devices.turnon.info");
    text_area.setText("\n" + blurb + "\n");
    checkITunes = new Button(shell, SWT.CHECK);
    checkITunes.setSelection(true);
    Messages.setLanguageText(checkITunes, "devices.turnon.itunes");
    PluginInterface itunes_plugin = null;
    try {
        itunes_plugin = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByID("azitunes", true);
    } catch (Throwable ignored) {
    }
    if (itunes_plugin != null && itunes_plugin.getPluginState().isOperational()) {
        checkITunes.setEnabled(false);
    }
    Link lblLearnMore = new Link(shell, SWT.NONE);
    lblLearnMore.setText("<A HREF=\"" + Constants.URL_DEVICES_FAQ + "\">" + MessageText.getString("label.learnmore") + "</A>");
    lblLearnMore.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Utils.launch(Constants.URL_DEVICES_FAQ);
        }
    });
    Button btnInstall = new Button(shell, SWT.NONE);
    Messages.setLanguageText(btnInstall, "Button.turnon");
    btnInstall.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            doInstall(checkITunes.getSelection());
        }
    });
    shell.setDefaultButton(btnInstall);
    Button btnCancel = new Button(shell, SWT.NONE);
    Messages.setLanguageText(btnCancel, "Button.cancel");
    btnCancel.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            shell.dispose();
        }
    });
    shell.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_ESCAPE) {
                shell.dispose();
            }
        }
    });
    install_area_parent = new Composite(shell, SWT.NONE);
    install_area_parent.setLayout(new FormLayout());
    install_area_parent.setVisible(false);
    install_area = new Composite(install_area_parent, SWT.NONE);
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = formLayout.marginHeight = 0;
    shell.setLayout(formLayout);
    FormData fd;
    fd = Utils.getFilledFormData();
    fd.top = new FormAttachment(0, +5);
    fd.bottom = new FormAttachment(btnInstall, -5, SWT.TOP);
    fd.left = new FormAttachment(0, +5);
    fd.right = new FormAttachment(100, -5);
    text_area.setLayoutData(fd);
    fd = new FormData();
    fd.bottom = new FormAttachment(100, -10);
    fd.right = new FormAttachment(100, -10);
    btnCancel.setLayoutData(fd);
    fd = new FormData();
    fd.bottom = new FormAttachment(100, -10);
    fd.right = new FormAttachment(btnCancel, -12);
    // 
    fd.left = new FormAttachment(lblLearnMore, +12);
    btnInstall.setLayoutData(fd);
    fd = new FormData();
    fd.bottom = new FormAttachment(100, -5);
    fd.left = new FormAttachment(0, 10);
    fd.right = new FormAttachment(btnInstall, -12);
    checkITunes.setLayoutData(fd);
    fd = new FormData();
    fd.top = new FormAttachment(checkITunes, 0, SWT.CENTER);
    fd.left = new FormAttachment(checkITunes, 5);
    lblLearnMore.setLayoutData(fd);
    fd = new FormData();
    fd.top = new FormAttachment(text_area, 0);
    fd.bottom = new FormAttachment(100, 0);
    fd.left = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    install_area_parent.setLayoutData(fd);
    fd = new FormData();
    fd.height = btnInstall.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
    fd.bottom = new FormAttachment(100, -5);
    fd.left = new FormAttachment(0, 5);
    fd.right = new FormAttachment(100, -12);
    install_area.setLayoutData(fd);
    Utils.makeButtonsEqualWidth(Arrays.asList(btnInstall, btnCancel));
    shell.pack();
    Utils.centreWindow(shell);
    btnInstall.setFocus();
    shell.open();
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) StyledText(org.eclipse.swt.custom.StyledText) PluginInstallationListener(com.biglybt.pif.installer.PluginInstallationListener) TraverseListener(org.eclipse.swt.events.TraverseListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) PluginInterface(com.biglybt.pif.PluginInterface) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 35 with PluginInterface

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

the class TransferPanel2 method show.

/* (non-Javadoc)
   * @see com.biglybt.ui.swt.wizard.IWizardPanel#show()
   */
@Override
public void show() {
    wizard.setTitle(MessageText.getString("configureWizard.transfer.title"));
    wizard.setCurrentInfo(MessageText.getString("configureWizard.transfer2.hint"));
    final Composite rootPanel = wizard.getPanel();
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    rootPanel.setLayout(layout);
    Composite panel = new Composite(rootPanel, SWT.NULL);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    Utils.setLayoutData(panel, gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    panel.setLayout(layout);
    Label label = new Label(panel, SWT.WRAP);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    Utils.setLayoutData(label, gridData);
    Messages.setLanguageText(label, "configureWizard.transfer2.message");
    final Group gRadio = new Group(panel, SWT.NULL);
    Messages.setLanguageText(gRadio, "configureWizard.transfer2.group");
    Utils.setLayoutData(gRadio, gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    gRadio.setLayout(layout);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    Utils.setLayoutData(gRadio, gridData);
    // auto button
    Button auto_button = new Button(gRadio, SWT.RADIO);
    Messages.setLanguageText(auto_button, "auto.mode");
    auto_button.setSelection(true);
    new Label(gRadio, SWT.NULL);
    // speed test button
    label = new Label(gRadio, SWT.NULL);
    Messages.setLanguageText(label, "configureWizard.transfer2.test.info");
    final Button speed_test = new Button(gRadio, SWT.NULL);
    Messages.setLanguageText(speed_test, "configureWizard.transfer2.test");
    final SelectionAdapter speed_test_listener = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            speed_test.setEnabled(false);
            test_in_progress = true;
            updateNextEnabled();
            rootPanel.getShell().setEnabled(false);
            UIFunctionsManager.getUIFunctions().installPlugin("mlab", "dlg.install.mlab", new UIFunctions.actionListener() {

                @Override
                public void actionComplete(Object result) {
                    if (result instanceof Boolean) {
                        PluginInterface pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByID("mlab");
                        if (pi == null) {
                            Debug.out("mlab plugin not found");
                            enableTest();
                        } else {
                            IPCInterface callback = new IPCInterface() {

                                @Override
                                public Object invoke(String methodName, Object[] params) {
                                    try {
                                        if (methodName.equals("results")) {
                                            Map<String, Object> results = (Map<String, Object>) params[0];
                                            Long up_rate = (Long) results.get("up");
                                            if (up_rate != null) {
                                                final int u = up_rate.intValue();
                                                if (u > 0) {
                                                    Utils.execSWTThread(new Runnable() {

                                                        @Override
                                                        public void run() {
                                                            updateUp(u, false);
                                                        }
                                                    });
                                                }
                                            }
                                        }
                                        return (null);
                                    } finally {
                                        enableTest();
                                    }
                                }

                                @Override
                                public boolean canInvoke(String methodName, Object[] params) {
                                    return (true);
                                }
                            };
                            try {
                                pi.getIPC().invoke("runTest", new Object[] { new HashMap<String, Object>(), callback, false });
                            } catch (Throwable e) {
                                Debug.out(e);
                                enableTest();
                            }
                        }
                    } else {
                        try {
                            Throwable error = (Throwable) result;
                            Debug.out(error);
                        } finally {
                            enableTest();
                        }
                    }
                }

                protected void enableTest() {
                    Utils.execSWTThread(new Runnable() {

                        @Override
                        public void run() {
                            speed_test.setEnabled(true);
                            test_in_progress = false;
                            updateNextEnabled();
                            rootPanel.getShell().setEnabled(true);
                        }
                    });
                }
            });
        }
    };
    speed_test.addSelectionListener(speed_test_listener);
    // manual
    final Button manual_button = new Button(gRadio, SWT.RADIO);
    Messages.setLanguageText(manual_button, "manual.mode");
    new Label(gRadio, SWT.NULL);
    // drop down speed selector
    final Label manual_label = new Label(gRadio, SWT.NULL);
    Messages.setLanguageText(manual_label, "configureWizard.transfer2.mselect");
    String[] connection_labels = new String[connection_rates.length];
    connection_labels[0] = MessageText.getString("configureWizard.transfer2.current");
    String dial_up = MessageText.getString("dial.up");
    for (int i = 1; i < connection_rates.length; i++) {
        connection_labels[i] = (i < 3 ? (dial_up + " ") : "xxx/") + DisplayFormatters.formatByteCountToBitsPerSec(connection_rates[i] / 8);
    }
    final Combo connection_speed = new Combo(gRadio, SWT.SINGLE | SWT.READ_ONLY);
    for (int i = 0; i < connection_rates.length; i++) {
        connection_speed.add(connection_labels[i]);
    }
    connection_speed.select(0);
    connection_speed.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event arg0) {
            int index = connection_speed.getSelectionIndex();
            updateUp(connection_rates[index] / 8, true);
        }
    });
    final Label manual2_label = new Label(gRadio, SWT.WRAP);
    Messages.setLanguageText(manual2_label, "configureWizard.transfer2.mselect.info");
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    Utils.setLayoutData(manual2_label, gridData);
    Listener listener = new Listener() {

        @Override
        public void handleEvent(Event arg0) {
            boolean is_manual = manual_button.getSelection();
            speed_test.setEnabled(!is_manual);
            connection_speed.setEnabled(is_manual);
            manual_label.setEnabled(is_manual);
            manual2_label.setEnabled(is_manual);
            manual_mode = is_manual;
            updateNextEnabled();
        }
    };
    manual_button.addListener(SWT.Selection, listener);
    listener.handleEvent(null);
    uprate_label = new Label(panel, SWT.WRAP);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.verticalIndent = 10;
    Utils.setLayoutData(uprate_label, gridData);
    updateUp(0, true);
    manual_mode = false;
    updateNextEnabled();
    if (wizard.getWizardMode() == ConfigureWizard.WIZARD_MODE_SPEED_TEST_AUTO) {
        Utils.execSWTThreadLater(0, new Runnable() {

            @Override
            public void run() {
                speed_test_listener.widgetSelected(null);
            }
        });
    }
}
Also used : HashMap(java.util.HashMap) GridLayout(org.eclipse.swt.layout.GridLayout) UIFunctions(com.biglybt.ui.UIFunctions) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IPCInterface(com.biglybt.pif.ipc.IPCInterface) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) PluginInterface(com.biglybt.pif.PluginInterface) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) HashMap(java.util.HashMap) Map(java.util.Map)

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