Search in sources :

Example 91 with PluginInterface

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

the class ConfigSectionInterfaceDisplay method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    boolean isAZ3 = COConfigurationManager.getStringParameter("ui").equals("az3");
    Label label;
    GridLayout layout;
    GridData gridData;
    Composite cSection = new Composite(parent, SWT.NULL);
    Utils.setLayoutData(cSection, new GridData(GridData.FILL_BOTH));
    layout = new GridLayout();
    layout.numColumns = 1;
    cSection.setLayout(layout);
    // various stuff
    Group gVarious = new Group(cSection, SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 1;
    gVarious.setLayout(layout);
    Utils.setLayoutData(gVarious, new GridData(GridData.FILL_HORIZONTAL));
    gVarious.setText(MessageText.getString("label.various"));
    new BooleanParameter(gVarious, "Show Download Basket", "ConfigView.section.style.showdownloadbasket");
    new BooleanParameter(gVarious, "suppress_file_download_dialog", "ConfigView.section.interface.display.suppress.file.download.dialog");
    new BooleanParameter(gVarious, "Suppress Sharing Dialog", "ConfigView.section.interface.display.suppress.sharing.dialog");
    new BooleanParameter(gVarious, "show_torrents_menu", "Menu.show.torrent.menu");
    if (!Constants.isUnix) {
        // TextWithHistory issues on Linux
        new BooleanParameter(gVarious, "mainwindow.search.history.enabled", "search.history.enable");
    }
    if (Constants.isWindowsXP) {
        final Button enableXPStyle = new Button(gVarious, SWT.CHECK);
        Messages.setLanguageText(enableXPStyle, "ConfigView.section.style.enableXPStyle");
        boolean enabled = false;
        boolean valid = false;
        try {
            File f = new File(System.getProperty("java.home") + "\\bin\\javaw.exe.manifest");
            if (f.exists()) {
                enabled = true;
            }
            f = FileUtil.getApplicationFile("javaw.exe.manifest");
            if (f.exists()) {
                valid = true;
            }
        } catch (Exception e) {
            Debug.printStackTrace(e);
            valid = false;
        }
        enableXPStyle.setEnabled(valid);
        enableXPStyle.setSelection(enabled);
        enableXPStyle.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event arg0) {
                // In case we enable the XP Style
                if (enableXPStyle.getSelection()) {
                    try {
                        File fDest = new File(System.getProperty("java.home") + "\\bin\\javaw.exe.manifest");
                        File fOrigin = new File("javaw.exe.manifest");
                        if (!fDest.exists() && fOrigin.exists()) {
                            FileUtil.copyFile(fOrigin, fDest);
                        }
                    } catch (Exception e) {
                        Debug.printStackTrace(e);
                    }
                } else {
                    try {
                        File fDest = new File(System.getProperty("java.home") + "\\bin\\javaw.exe.manifest");
                        fDest.delete();
                    } catch (Exception e) {
                        Debug.printStackTrace(e);
                    }
                }
            }
        });
    }
    if (Constants.isOSX) {
        new BooleanParameter(gVarious, "enable_small_osx_fonts", "ConfigView.section.style.osx_small_fonts");
    }
    // Reuse the labels of the other menu actions.
    if (PlatformManagerFactory.getPlatformManager().hasCapability(PlatformManagerCapabilities.ShowFileInBrowser)) {
        BooleanParameter bp = new BooleanParameter(gVarious, "MyTorrentsView.menu.show_parent_folder_enabled", "ConfigView.section.style.use_show_parent_folder");
        Messages.setLanguageText(bp.getControl(), "ConfigView.section.style.use_show_parent_folder", new String[] { MessageText.getString("MyTorrentsView.menu.open_parent_folder"), MessageText.getString("MyTorrentsView.menu.explore") });
        if (Constants.isOSX) {
            new BooleanParameter(gVarious, "FileBrowse.usePathFinder", "ConfigView.section.style.usePathFinder");
        }
    }
    if (userMode > 0) {
        final BooleanParameter paramEnableForceDPI = new BooleanParameter(gVarious, "enable.ui.forceDPI", "ConfigView.section.style.forceDPI");
        paramEnableForceDPI.setLayoutData(new GridData());
        IntParameter forceDPI = new IntParameter(gVarious, "Force DPI", 0, Integer.MAX_VALUE);
        forceDPI.setLayoutData(new GridData());
        paramEnableForceDPI.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(forceDPI.getControl()));
    }
    // toolbar
    {
        Group gToolBar = new Group(cSection, SWT.NULL);
        Messages.setLanguageText(gToolBar, "MainWindow.menu.view.iconbar");
        int gToolBarSpan = 6 + (isAZ3 ? 1 : 2);
        layout = new GridLayout();
        layout.numColumns = gToolBarSpan;
        gToolBar.setLayout(layout);
        Utils.setLayoutData(gToolBar, new GridData(GridData.FILL_HORIZONTAL));
        BooleanParameter enabled = null;
        if (!isAZ3) {
            enabled = new BooleanParameter(gToolBar, "IconBar.enabled", "ConfigView.section.style.showiconbar");
            GridData gd = new GridData();
            gd.horizontalSpan = gToolBarSpan;
            enabled.setLayoutData(gd);
        }
        if (isAZ3) {
            new BooleanParameter(gToolBar, "IconBar.visible.play", "iconBar.stream");
        }
        new BooleanParameter(gToolBar, "IconBar.visible.run", "iconBar.run");
        if (!isAZ3) {
            new BooleanParameter(gToolBar, "IconBar.visible.top", "iconBar.top");
        }
        new BooleanParameter(gToolBar, "IconBar.visible.up", "iconBar.up");
        new BooleanParameter(gToolBar, "IconBar.visible.down", "iconBar.down");
        if (!isAZ3) {
            new BooleanParameter(gToolBar, "IconBar.visible.bottom", "iconBar.bottom");
        }
        new BooleanParameter(gToolBar, "IconBar.visible." + TorrentUtil.TU_ITEM_RECHECK, "MyTorrentsView.menu.recheck");
        new BooleanParameter(gToolBar, "IconBar.visible." + TorrentUtil.TU_ITEM_CHECK_FILES, "MyTorrentsView.menu.checkfilesexist");
        BooleanParameter sss = new BooleanParameter(gToolBar, "IconBar.start.stop.separate", "ConfigView.section.style.start.stop.separate");
        GridData gd = new GridData();
        gd.horizontalSpan = gToolBarSpan;
        sss.setLayoutData(gd);
    }
    if (isAZ3) {
        Group gSideBar = new Group(cSection, SWT.NULL);
        Messages.setLanguageText(gSideBar, "v3.MainWindow.menu.view.sidebar");
        layout = new GridLayout();
        layout.numColumns = 2;
        gSideBar.setLayout(layout);
        Utils.setLayoutData(gSideBar, new GridData(GridData.FILL_HORIZONTAL));
        new BooleanParameter(gSideBar, "Show Side Bar", "sidebar.show");
        label = new Label(gSideBar, SWT.NULL);
        label = new Label(gSideBar, SWT.NULL);
        Messages.setLanguageText(label, "sidebar.top.level.gap");
        new IntParameter(gSideBar, "Side Bar Top Level Gap", 0, 5);
        new BooleanParameter(gSideBar, "Show Options In Side Bar", "sidebar.show.options");
        label = new Label(gSideBar, SWT.NULL);
        BooleanParameter showNew = new BooleanParameter(gSideBar, "Show New In Side Bar", "sidebar.show.new");
        label = new Label(gSideBar, SWT.NULL);
        showNew.addChangeListener(new ParameterChangeAdapter() {

            @Override
            public void parameterChanged(Parameter p, boolean caused_internally) {
                if (showNew.isSelected()) {
                    UIFunctionsManager.getUIFunctions().getMDI().loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_LIBRARY_UNOPENED, false);
                } else {
                    UIFunctionsManager.getUIFunctions().getMDI().closeEntry(MultipleDocumentInterface.SIDEBAR_SECTION_LIBRARY_UNOPENED);
                }
            }
        });
        BooleanParameter showDL = new BooleanParameter(gSideBar, "Show Downloading In Side Bar", "sidebar.show.downloading");
        label = new Label(gSideBar, SWT.NULL);
        showDL.addChangeListener(new ParameterChangeAdapter() {

            @Override
            public void parameterChanged(Parameter p, boolean caused_internally) {
                if (showDL.isSelected()) {
                    UIFunctionsManager.getUIFunctions().getMDI().loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_LIBRARY_DL, false);
                } else {
                    UIFunctionsManager.getUIFunctions().getMDI().closeEntry(MultipleDocumentInterface.SIDEBAR_SECTION_LIBRARY_DL);
                }
            }
        });
    }
    // status bar
    Group cStatusBar = new Group(cSection, SWT.NULL);
    Messages.setLanguageText(cStatusBar, "ConfigView.section.style.status");
    layout = new GridLayout();
    layout.numColumns = 1;
    cStatusBar.setLayout(layout);
    Utils.setLayoutData(cStatusBar, new GridData(GridData.FILL_HORIZONTAL));
    new BooleanParameter(cStatusBar, "Status Area Show SR", "ConfigView.section.style.status.show_sr");
    new BooleanParameter(cStatusBar, "Status Area Show NAT", "ConfigView.section.style.status.show_nat");
    new BooleanParameter(cStatusBar, "Status Area Show DDB", "ConfigView.section.style.status.show_ddb");
    new BooleanParameter(cStatusBar, "Status Area Show IPF", "ConfigView.section.style.status.show_ipf");
    new BooleanParameter(cStatusBar, "status.rategraphs", "ConfigView.section.style.status.show_rategraphs");
    if (userMode > 0) {
        Group cUnits = new Group(cSection, SWT.NULL);
        Messages.setLanguageText(cUnits, "ConfigView.section.style.units");
        layout = new GridLayout();
        layout.numColumns = 1;
        cUnits.setLayout(layout);
        Utils.setLayoutData(cUnits, new GridData(GridData.FILL_HORIZONTAL));
        new BooleanParameter(cUnits, "config.style.useSIUnits", "ConfigView.section.style.useSIUnits");
        new BooleanParameter(cUnits, "config.style.forceSIValues", "ConfigView.section.style.forceSIValues");
        new BooleanParameter(cUnits, "config.style.useUnitsRateBits", "ConfigView.section.style.useUnitsRateBits");
        new BooleanParameter(cUnits, "config.style.doNotUseGB", "ConfigView.section.style.doNotUseGB");
        new BooleanParameter(cUnits, "config.style.dataStatsOnly", "ConfigView.section.style.dataStatsOnly");
        new BooleanParameter(cUnits, "config.style.separateProtDataStats", "ConfigView.section.style.separateProtDataStats");
        new BooleanParameter(cUnits, "ui.scaled.graphics.binary.based", "ConfigView.section.style.scaleBinary");
    }
    if (userMode > 0) {
        Group formatters_group = new Group(cSection, SWT.NULL);
        Messages.setLanguageText(formatters_group, "ConfigView.label.general.formatters");
        layout = new GridLayout();
        formatters_group.setLayout(layout);
        Utils.setLayoutData(formatters_group, new GridData(GridData.FILL_HORIZONTAL));
        StringAreaParameter formatters = new StringAreaParameter(formatters_group, "config.style.formatOverrides");
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.heightHint = formatters.getPreferredHeight(3);
        formatters.setLayoutData(gridData);
        Composite format_info = new Composite(formatters_group, SWT.NULL);
        layout = new GridLayout();
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 3;
        format_info.setLayout(layout);
        Utils.setLayoutData(format_info, new GridData(GridData.FILL_HORIZONTAL));
        new LinkLabel(format_info, "ConfigView.label.general.formatters.link", MessageText.getString("ConfigView.label.general.formatters.link.url"));
        label = new Label(format_info, SWT.NULL);
        Messages.setLanguageText(label, "GeneralView.label.status");
        InfoParameter info_param = new InfoParameter(format_info, "config.style.formatOverrides.status");
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        info_param.setLayoutData(gridData);
    }
    if (userMode > 0) {
        Group gExternalBrowser = new Group(cSection, SWT.NULL);
        layout = new GridLayout();
        layout.numColumns = 1;
        gExternalBrowser.setLayout(layout);
        Utils.setLayoutData(gExternalBrowser, new GridData(GridData.FILL_HORIZONTAL));
        gExternalBrowser.setText(MessageText.getString("config.external.browser"));
        label = new Label(gExternalBrowser, SWT.WRAP);
        Messages.setLanguageText(label, "config.external.browser.info1");
        Utils.setLayoutData(label, Utils.getWrappableLabelGridData(1, 0));
        label = new Label(gExternalBrowser, SWT.WRAP);
        Messages.setLanguageText(label, "config.external.browser.info2");
        Utils.setLayoutData(label, Utils.getWrappableLabelGridData(1, 0));
        // browser selection
        final java.util.List<String[]> browser_choices = new ArrayList<>();
        browser_choices.add(new String[] { "system", MessageText.getString("external.browser.system") });
        browser_choices.add(new String[] { "manual", MessageText.getString("external.browser.manual") });
        java.util.List<PluginInterface> pis = CoreFactory.getSingleton().getPluginManager().getPluginsWithMethod("launchURL", new Class[] { URL.class, boolean.class, Runnable.class });
        String pi_names = "";
        for (PluginInterface pi : pis) {
            String pi_name = pi.getPluginName();
            pi_names += (pi_names.length() == 0 ? "" : "/") + pi_name;
            browser_choices.add(new String[] { "plugin:" + pi.getPluginID(), pi_name });
        }
        final Composite cEBArea = new Composite(gExternalBrowser, SWT.WRAP);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        Utils.setLayoutData(cEBArea, gridData);
        layout = new GridLayout();
        layout.numColumns = 2;
        layout.marginHeight = 0;
        cEBArea.setLayout(layout);
        label = new Label(cEBArea, SWT.WRAP);
        Messages.setLanguageText(label, "config.external.browser.select");
        final Composite cEB = new Group(cEBArea, SWT.WRAP);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        Utils.setLayoutData(cEB, gridData);
        layout = new GridLayout();
        layout.numColumns = browser_choices.size();
        layout.marginHeight = 0;
        cEB.setLayout(layout);
        java.util.List<Button> buttons = new ArrayList<>();
        for (int i = 0; i < browser_choices.size(); i++) {
            Button button = new Button(cEB, SWT.RADIO);
            button.setText(browser_choices.get(i)[1]);
            button.setData("index", String.valueOf(i));
            buttons.add(button);
        }
        String existing = COConfigurationManager.getStringParameter("browser.external.id", browser_choices.get(0)[0]);
        int existing_index = -1;
        for (int i = 0; i < browser_choices.size(); i++) {
            if (browser_choices.get(i)[0].equals(existing)) {
                existing_index = i;
                break;
            }
        }
        if (existing_index == -1) {
            existing_index = 0;
            COConfigurationManager.setParameter("browser.external.id", browser_choices.get(0)[0]);
        }
        buttons.get(existing_index).setSelection(true);
        Messages.setLanguageText(new Label(cEBArea, SWT.WRAP), "config.external.browser.prog");
        Composite manualArea = new Composite(cEBArea, SWT.NULL);
        layout = new GridLayout(2, false);
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        manualArea.setLayout(layout);
        Utils.setLayoutData(manualArea, new GridData(GridData.FILL_HORIZONTAL));
        final Parameter manualProg = new FileParameter(manualArea, "browser.external.prog", "", new String[] {});
        manualProg.setEnabled(existing_index == 1);
        Listener radioListener = new Listener() {

            @Override
            public void handleEvent(Event event) {
                Button button = (Button) event.widget;
                if (button.getSelection()) {
                    Control[] children = cEB.getChildren();
                    for (int j = 0; j < children.length; j++) {
                        Control child = children[j];
                        if (child != button && child instanceof Button) {
                            Button b = (Button) child;
                            b.setSelection(false);
                        }
                    }
                    int index = Integer.parseInt((String) button.getData("index"));
                    COConfigurationManager.setParameter("browser.external.id", browser_choices.get(index)[0]);
                    manualProg.setEnabled(index == 1);
                }
            }
        };
        for (Button b : buttons) {
            b.addListener(SWT.Selection, radioListener);
        }
        if (pis.size() > 0) {
            Composite nonPubArea = new Composite(gExternalBrowser, SWT.NULL);
            layout = new GridLayout(2, false);
            layout.marginHeight = 0;
            nonPubArea.setLayout(layout);
            Utils.setLayoutData(nonPubArea, new GridData(GridData.FILL_HORIZONTAL));
            String temp = MessageText.getString("config.external.browser.non.pub", new String[] { pi_names });
            BooleanParameter non_pub = new BooleanParameter(nonPubArea, "browser.external.non.pub", true, "!" + temp + "!");
        }
        // test launch
        Composite testArea = new Composite(gExternalBrowser, SWT.NULL);
        layout = new GridLayout(4, false);
        layout.marginHeight = 0;
        testArea.setLayout(layout);
        Utils.setLayoutData(testArea, new GridData(GridData.FILL_HORIZONTAL));
        label = new Label(testArea, SWT.WRAP);
        Messages.setLanguageText(label, "config.external.browser.test");
        final Button test_button = new Button(testArea, SWT.PUSH);
        Messages.setLanguageText(test_button, "configureWizard.nat.test");
        final Text test_url = new Text(testArea, SWT.BORDER);
        Utils.setLayoutData(test_url, new GridData(GridData.FILL_HORIZONTAL));
        test_url.setText("http://www.vuze.com/");
        test_button.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                test_button.setEnabled(false);
                final String url_str = test_url.getText().trim();
                new AEThread2("async") {

                    @Override
                    public void run() {
                        try {
                            Utils.launch(url_str, true);
                        } finally {
                            Utils.execSWTThread(new Runnable() {

                                @Override
                                public void run() {
                                    if (!test_button.isDisposed()) {
                                        test_button.setEnabled(true);
                                    }
                                }
                            });
                        }
                    }
                }.start();
            }
        });
        label = new Label(testArea, SWT.NULL);
        Utils.setLayoutData(label, new GridData(GridData.FILL_HORIZONTAL));
    }
    if (userMode > 1) {
        Group gInternalBrowser = new Group(cSection, SWT.NULL);
        layout = new GridLayout();
        layout.numColumns = 1;
        gInternalBrowser.setLayout(layout);
        Utils.setLayoutData(gInternalBrowser, new GridData(GridData.FILL_HORIZONTAL));
        gInternalBrowser.setText(MessageText.getString("config.internal.browser"));
        label = new Label(gInternalBrowser, SWT.WRAP);
        gridData = Utils.getWrappableLabelGridData(1, GridData.FILL_HORIZONTAL);
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "config.internal.browser.info1");
        final BooleanParameter intbrow_disable = new BooleanParameter(gInternalBrowser, "browser.internal.disable", "config.browser.internal.disable");
        label = new Label(gInternalBrowser, SWT.WRAP);
        gridData = Utils.getWrappableLabelGridData(1, GridData.FILL_HORIZONTAL);
        gridData.horizontalIndent = 15;
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "config.browser.internal.disable.info");
        label = new Label(gInternalBrowser, SWT.WRAP);
        gridData = Utils.getWrappableLabelGridData(1, GridData.FILL_HORIZONTAL);
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "config.internal.browser.info3");
        java.util.List<PluginInterface> pis = AEProxyFactory.getPluginHTTPProxyProviders(true);
        final java.util.List<String[]> proxy_choices = new ArrayList<>();
        proxy_choices.add(new String[] { "none", MessageText.getString("label.none") });
        for (PluginInterface pi : pis) {
            proxy_choices.add(new String[] { "plugin:" + pi.getPluginID(), pi.getPluginName() });
        }
        final Composite cIPArea = new Composite(gInternalBrowser, SWT.WRAP);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        Utils.setLayoutData(cIPArea, gridData);
        layout = new GridLayout();
        layout.numColumns = 2;
        layout.marginHeight = 0;
        cIPArea.setLayout(layout);
        label = new Label(cIPArea, SWT.WRAP);
        gridData = Utils.getWrappableLabelGridData(1, GridData.FILL_HORIZONTAL);
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "config.internal.browser.proxy.select");
        final Composite cIP = new Group(cIPArea, SWT.WRAP);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        Utils.setLayoutData(cIP, gridData);
        layout = new GridLayout();
        layout.numColumns = proxy_choices.size();
        layout.marginHeight = 0;
        cIP.setLayout(layout);
        java.util.List<Button> buttons = new ArrayList<>();
        for (int i = 0; i < proxy_choices.size(); i++) {
            Button button = new Button(cIP, SWT.RADIO);
            button.setText(proxy_choices.get(i)[1]);
            button.setData("index", String.valueOf(i));
            buttons.add(button);
        }
        String existing = COConfigurationManager.getStringParameter("browser.internal.proxy.id", proxy_choices.get(0)[0]);
        int existing_index = -1;
        for (int i = 0; i < proxy_choices.size(); i++) {
            if (proxy_choices.get(i)[0].equals(existing)) {
                existing_index = i;
                break;
            }
        }
        if (existing_index == -1) {
            existing_index = 0;
            COConfigurationManager.setParameter("browser.internal.proxy.id", proxy_choices.get(0)[0]);
        }
        buttons.get(existing_index).setSelection(true);
        Listener radioListener = new Listener() {

            @Override
            public void handleEvent(Event event) {
                Button button = (Button) event.widget;
                if (button.getSelection()) {
                    Control[] children = cIP.getChildren();
                    for (int j = 0; j < children.length; j++) {
                        Control child = children[j];
                        if (child != button && child instanceof Button) {
                            Button b = (Button) child;
                            b.setSelection(false);
                        }
                    }
                    int index = Integer.parseInt((String) button.getData("index"));
                    COConfigurationManager.setParameter("browser.internal.proxy.id", proxy_choices.get(index)[0]);
                }
            }
        };
        for (Button b : buttons) {
            b.addListener(SWT.Selection, radioListener);
        }
    }
    // refresh
    Group gRefresh = new Group(cSection, SWT.NULL);
    gRefresh.setText(MessageText.getString("upnp.refresh.button"));
    layout = new GridLayout();
    layout.numColumns = 2;
    gRefresh.setLayout(layout);
    Utils.setLayoutData(gRefresh, new GridData(GridData.FILL_HORIZONTAL));
    label = new Label(gRefresh, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.section.style.guiUpdate");
    int[] values = { 10, 25, 50, 100, 250, 500, 1000, 2000, 5000, 10000, 15000 };
    String[] labels = { "10 ms", "25 ms", "50 ms", "100 ms", "250 ms", "500 ms", "1 s", "2 s", "5 s", "10 s", "15 s" };
    new IntListParameter(gRefresh, "GUI Refresh", 1000, labels, values);
    label = new Label(gRefresh, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.section.style.inactiveUpdate");
    gridData = new GridData();
    IntParameter inactiveUpdate = new IntParameter(gRefresh, "Refresh When Inactive", 1, Integer.MAX_VALUE);
    inactiveUpdate.setLayoutData(gridData);
    label = new Label(gRefresh, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.section.style.graphicsUpdate");
    gridData = new GridData();
    IntParameter graphicUpdate = new IntParameter(gRefresh, "Graphics Update", 1, Integer.MAX_VALUE);
    graphicUpdate.setLayoutData(gridData);
    return cSection;
}
Also used : LinkLabel(com.biglybt.ui.swt.components.LinkLabel) ArrayList(java.util.ArrayList) GridLayout(org.eclipse.swt.layout.GridLayout) PluginInterface(com.biglybt.pif.PluginInterface) MessageText(com.biglybt.core.internat.MessageText) AEThread2(com.biglybt.core.util.AEThread2) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) GridData(org.eclipse.swt.layout.GridData) File(java.io.File)

Example 92 with PluginInterface

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

the class ConfigSectionLogging method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    ImageLoader imageLoader = ImageLoader.getInstance();
    Image imgOpenFolder = imageLoader.getImage("openFolderButton");
    GridData gridData;
    GridLayout layout;
    Composite gLogging = new Composite(parent, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    Utils.setLayoutData(gLogging, gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    gLogging.setLayout(layout);
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    BooleanParameter enable_logger = new BooleanParameter(gLogging, "Logger.Enabled", "ConfigView.section.logging.loggerenable");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    enable_logger.setLayoutData(gridData);
    // row
    final BooleanParameter enableLogging = new BooleanParameter(gLogging, "Logging Enable", "ConfigView.section.logging.enable");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    enableLogging.setLayoutData(gridData);
    Composite cArea = new Composite(gLogging, SWT.NULL);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 3;
    cArea.setLayout(layout);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    cArea.setLayoutData(gridData);
    // row
    Label lStatsPath = new Label(cArea, SWT.NULL);
    // $NON-NLS-1$
    Messages.setLanguageText(lStatsPath, "ConfigView.section.logging.logdir");
    gridData = new GridData();
    gridData.widthHint = 150;
    // $NON-NLS-1$ //$NON-NLS-2$
    final StringParameter pathParameter = new StringParameter(cArea, "Logging Dir");
    pathParameter.setLayoutData(gridData);
    Button browse = new Button(cArea, SWT.PUSH);
    browse.setImage(imgOpenFolder);
    imgOpenFolder.setBackground(browse.getBackground());
    browse.setToolTipText(MessageText.getString("ConfigView.button.browse"));
    browse.addListener(SWT.Selection, new Listener() {

        /* (non-Javadoc)
       * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
       */
        @Override
        public void handleEvent(Event event) {
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
            dialog.setFilterPath(pathParameter.getValue());
            // $NON-NLS-1$
            dialog.setText(MessageText.getString("ConfigView.section.logging.choosedefaultsavepath"));
            String path = dialog.open();
            if (path != null) {
                pathParameter.setValue(path);
            }
        }
    });
    Label lMaxLog = new Label(cArea, SWT.NULL);
    Messages.setLanguageText(lMaxLog, "ConfigView.section.logging.maxsize");
    final String[] lmLabels = new String[logFileSizes.length];
    final int[] lmValues = new int[logFileSizes.length];
    for (int i = 0; i < logFileSizes.length; i++) {
        int num = logFileSizes[i];
        lmLabels[i] = " " + num + " MB";
        lmValues[i] = num;
    }
    IntListParameter paramMaxSize = new IntListParameter(cArea, "Logging Max Size", lmLabels, lmValues);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    paramMaxSize.setLayoutData(gridData);
    if (userMode > 1) {
        Label timeStampLbl = new Label(cArea, SWT.NULL);
        Messages.setLanguageText(timeStampLbl, "ConfigView.section.logging.timestamp");
        Utils.setLayoutData(timeStampLbl, new GridData());
        StringParameter timeStamp = new StringParameter(cArea, "Logging Timestamp");
        gridData = new GridData();
        gridData.horizontalSpan = 2;
        gridData.widthHint = 150;
        timeStamp.setLayoutData(gridData);
    }
    /**
     * FileLogging filter, consisting of a List of types (info, warning, error)
     * and a checkbox Table of component IDs.
     */
    final String sFilterPrefix = "ConfigView.section.logging.filter";
    Group gLogIDs = new Group(gLogging, SWT.NULL);
    Messages.setLanguageText(gLogIDs, sFilterPrefix);
    layout = new GridLayout();
    layout.numColumns = 2;
    gLogIDs.setLayout(layout);
    gridData = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true);
    gridData.horizontalSpan = 2;
    Utils.setLayoutData(gLogIDs, gridData);
    final List listLogTypes = new List(gLogIDs, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL);
    gridData = new GridData(SWT.NULL, SWT.BEGINNING, false, false);
    listLogTypes.setLayoutData(gridData);
    final int[] logTypes = { LogEvent.LT_INFORMATION, LogEvent.LT_WARNING, LogEvent.LT_ERROR };
    for (int i = 0; i < logTypes.length; i++) listLogTypes.add(MessageText.getString("ConfigView.section.logging.log" + i + "type"));
    listLogTypes.select(0);
    final LogIDs[] logIDs = FileLogging.configurableLOGIDs;
    // Arrays.sort(logIDs);
    final Table tableLogIDs = new Table(gLogIDs, SWT.CHECK | SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
    gridData = new GridData(GridData.FILL_BOTH);
    tableLogIDs.setLayoutData(gridData);
    tableLogIDs.setLinesVisible(false);
    tableLogIDs.setHeaderVisible(false);
    TableColumn column = new TableColumn(tableLogIDs, SWT.NONE);
    for (int i = 0; i < logIDs.length; i++) {
        TableItem item = new TableItem(tableLogIDs, SWT.NULL);
        item.setText(0, MessageText.getString(sFilterPrefix + "." + logIDs[i], logIDs[i].toString()));
        item.setData(logIDs[i]);
        boolean checked = COConfigurationManager.getBooleanParameter("bLog." + logTypes[0] + "." + logIDs[i], true);
        item.setChecked(checked);
    }
    column.pack();
    // Update table when list selection changes
    listLogTypes.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int index = listLogTypes.getSelectionIndex();
            if (index < 0 || index >= logTypes.length)
                return;
            TableItem[] items = tableLogIDs.getItems();
            for (int i = 0; i < items.length; i++) {
                boolean checked = COConfigurationManager.getBooleanParameter("bLog." + logTypes[index] + "." + items[i].getData(), true);
                items[i].setChecked(checked);
            }
        }
    });
    // Save config when checkbox is clicked
    tableLogIDs.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.detail != SWT.CHECK)
                return;
            int index = listLogTypes.getSelectionIndex();
            if (index < 0 || index >= logTypes.length)
                return;
            TableItem item = (TableItem) e.item;
            COConfigurationManager.setParameter("bLog." + logTypes[index] + "." + item.getData(), item.getChecked());
        }
    });
    final Control[] controls_main = { cArea, gLogIDs };
    final ChangeSelectionActionPerformer perf2 = new ChangeSelectionActionPerformer(controls_main);
    enableLogging.setAdditionalActionPerformer(perf2);
    enable_logger.setAdditionalActionPerformer(new IAdditionalActionPerformer() {

        ChangeSelectionActionPerformer p1 = new ChangeSelectionActionPerformer(new Control[] { enableLogging.getControl() });

        @Override
        public void performAction() {
            p1.performAction();
        }

        @Override
        public void setSelected(boolean selected) {
            p1.setSelected(selected);
            if (!selected && enableLogging.isSelected())
                enableLogging.setSelected(false);
        }

        @Override
        public void setIntValue(int value) {
        /*nothing*/
        }

        @Override
        public void setStringValue(String value) {
        /*nothing*/
        }
    });
    if (userMode > 0) {
        Composite cDebugFiles = new Composite(gLogging, SWT.NULL);
        layout = new GridLayout();
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 3;
        cDebugFiles.setLayout(layout);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        cDebugFiles.setLayoutData(gridData);
        Label l_debug_file_size = new Label(cDebugFiles, SWT.NULL);
        Messages.setLanguageText(l_debug_file_size, "ConfigView.section.logging.debugfilesize");
        l_debug_file_size.setLayoutData(new GridData());
        new IntParameter(cDebugFiles, "Logger.DebugFiles.SizeKB", 10, Integer.MAX_VALUE);
        new Label(cDebugFiles, SWT.NULL).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    }
    if (userMode > 1) {
        // advanced option
        Group cAO = new Group(gLogging, SWT.NULL);
        cAO.setText(MessageText.getString("dht.advanced.group"));
        layout = new GridLayout();
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 5;
        cAO.setLayout(layout);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        cAO.setLayoutData(gridData);
        // name
        Label aoName = new Label(cAO, SWT.NULL);
        Messages.setLanguageText(aoName, "label.name");
        aoName.setLayoutData(new GridData());
        final StringParameter name = new StringParameter(cAO, "Advanced Option Name");
        gridData = new GridData();
        gridData.widthHint = 150;
        name.setLayoutData(gridData);
        // value
        Label aoValue = new Label(cAO, SWT.NULL);
        Messages.setLanguageText(aoValue, "label.value");
        aoName.setLayoutData(new GridData());
        final StringParameter value = new StringParameter(cAO, "Advanced Option Value");
        gridData = new GridData();
        gridData.widthHint = 150;
        value.setLayoutData(gridData);
        // set
        Button set_option = new Button(cAO, SWT.PUSH);
        Messages.setLanguageText(set_option, "Button.set");
        set_option.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                String key = name.getValue().trim();
                if ((key.startsWith("'") && key.endsWith("'")) || (key.startsWith("\"") && key.endsWith("\""))) {
                    key = key.substring(1, key.length() - 1);
                }
                if (key.length() > 0) {
                    if (key.startsWith("!")) {
                        key = key.substring(1);
                    } else {
                        key = "adv.setting." + key;
                    }
                    String val = value.getValue().trim();
                    boolean is_string = false;
                    if ((val.startsWith("'") && val.endsWith("'")) || (val.startsWith("\"") && val.endsWith("\""))) {
                        val = val.substring(1, val.length() - 1);
                        is_string = true;
                    }
                    if (val.length() == 0) {
                        COConfigurationManager.removeParameter(key);
                    } else {
                        if (is_string) {
                            COConfigurationManager.setParameter(key, val);
                        } else {
                            String lc_val = val.toLowerCase(Locale.US);
                            if (lc_val.equals("false") || lc_val.equals("true")) {
                                COConfigurationManager.setParameter(key, lc_val.startsWith("t"));
                            } else {
                                try {
                                    long l = Long.parseLong(val);
                                    COConfigurationManager.setParameter(key, l);
                                } catch (Throwable e) {
                                    COConfigurationManager.setParameter(key, val);
                                }
                            }
                        }
                    }
                    COConfigurationManager.save();
                }
            }
        });
    }
    // network diagnostics
    Label generate_net_info = new Label(gLogging, SWT.NULL);
    Messages.setLanguageText(generate_net_info, "ConfigView.section.logging.netinfo");
    Button generate_net_button = new Button(gLogging, SWT.PUSH);
    Messages.setLanguageText(generate_net_button, "ConfigView.section.logging.generatediagnostics");
    generate_net_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            new AEThread2("GenerateNetDiag", true) {

                @Override
                public void run() {
                    StringWriter sw = new StringWriter();
                    PrintWriter pw = new PrintWriter(sw);
                    IndentWriter iw = new IndentWriter(pw);
                    NetworkAdmin admin = NetworkAdmin.getSingleton();
                    admin.generateDiagnostics(iw);
                    pw.close();
                    final String info = sw.toString();
                    Logger.log(new LogEvent(LOGID, "Network Info:\n" + info));
                    Utils.execSWTThread(new Runnable() {

                        @Override
                        public void run() {
                            ClipboardCopy.copyToClipBoard(info);
                        }
                    });
                }
            }.start();
        }
    });
    // stats
    Label generate_stats_info = new Label(gLogging, SWT.NULL);
    Messages.setLanguageText(generate_stats_info, "ConfigView.section.logging.statsinfo");
    Button generate_stats_button = new Button(gLogging, SWT.PUSH);
    Messages.setLanguageText(generate_stats_button, "ConfigView.section.logging.generatediagnostics");
    generate_stats_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            java.util.Set types = new HashSet();
            types.add(CoreStats.ST_ALL);
            Map reply = CoreStats.getStats(types);
            Iterator it = reply.entrySet().iterator();
            StringBuilder buffer = new StringBuilder(16000);
            while (it.hasNext()) {
                Map.Entry entry = (Map.Entry) it.next();
                buffer.append(entry.getKey()).append(" -> ").append(entry.getValue()).append("\r\n");
            }
            String str = buffer.toString();
            ClipboardCopy.copyToClipBoard(str);
            Logger.log(new LogEvent(LOGID, "Stats Info:\n" + str));
        }
    });
    // diagnostics
    Label generate_info = new Label(gLogging, SWT.NULL);
    Messages.setLanguageText(generate_info, "ConfigView.section.logging.generatediagnostics.info");
    Button generate_button = new Button(gLogging, SWT.PUSH);
    Messages.setLanguageText(generate_button, "ConfigView.section.logging.generatediagnostics");
    generate_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            AEDiagnostics.generateEvidence(pw);
            pw.close();
            String evidence = sw.toString();
            ClipboardCopy.copyToClipBoard(evidence);
            Logger.log(new LogEvent(LOGID, "Evidence Generation:\n" + evidence));
        }
    });
    if (false) {
        Button test_button = new Button(gLogging, SWT.PUSH);
        test_button.setText("Test");
        test_button.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                try {
                    PluginInterface pi = CoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface();
                    UpdateInstaller installer = pi.getUpdateManager().createInstaller();
                    installer.addMoveAction("C:\\temp\\file1", "C:\\temp\\file2");
                    installer.installNow(new UpdateInstallerListener() {

                        @Override
                        public void reportProgress(String str) {
                            System.out.println(str);
                        }

                        @Override
                        public void complete() {
                            System.out.println("complete");
                        }

                        @Override
                        public void failed(UpdateException e) {
                            System.out.println("failed");
                            e.printStackTrace();
                        }
                    });
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        });
    }
    return gLogging;
}
Also used : Image(org.eclipse.swt.graphics.Image) NetworkAdmin(com.biglybt.core.networkmanager.admin.NetworkAdmin) SelectionEvent(org.eclipse.swt.events.SelectionEvent) HashSet(java.util.HashSet) LogEvent(com.biglybt.core.logging.LogEvent) AEThread2(com.biglybt.core.util.AEThread2) UpdateInstaller(com.biglybt.pif.update.UpdateInstaller) Map(java.util.Map) IndentWriter(com.biglybt.core.util.IndentWriter) UpdateInstallerListener(com.biglybt.pif.update.UpdateInstallerListener) HashSet(java.util.HashSet) GridLayout(org.eclipse.swt.layout.GridLayout) StringWriter(java.io.StringWriter) Iterator(java.util.Iterator) UpdateException(com.biglybt.pif.update.UpdateException) PrintWriter(java.io.PrintWriter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) PluginInterface(com.biglybt.pif.PluginInterface) LogIDs(com.biglybt.core.logging.LogIDs) UpdateInstallerListener(com.biglybt.pif.update.UpdateInstallerListener) GridData(org.eclipse.swt.layout.GridData) LogEvent(com.biglybt.core.logging.LogEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 93 with PluginInterface

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

the class AENameServiceDescriptor method checkI2PInstall.

private static void checkI2PInstall(final String host_name) {
    synchronized (AENameServiceDescriptor.class) {
        if (i2p_checked) {
            return;
        }
        try {
            Core core = CoreFactory.getSingleton();
            if (core != null) {
                i2p_checked = true;
                PluginInterface pi = core.getPluginManager().getDefaultPluginInterface();
                pi.addListener(new PluginAdapter() {

                    @Override
                    public void initializationComplete() {
                        if (I2PHelpers.isI2PInstalled()) {
                            return;
                        }
                        final boolean[] install_outcome = { false };
                        String enable_i2p_reason = MessageText.getString("azneti2phelper.install.reason.dns", new String[] { host_name });
                        I2PHelpers.installI2PHelper(enable_i2p_reason, "azneti2phelper.install.dns.resolve", install_outcome, new Runnable() {

                            @Override
                            public void run() {
                                if (!install_outcome[0]) {
                                }
                            }
                        });
                    }
                });
            }
        } catch (Throwable e) {
        }
    }
}
Also used : PluginAdapter(com.biglybt.pif.PluginAdapter) PluginInterface(com.biglybt.pif.PluginInterface) Core(com.biglybt.core.Core)

Example 94 with PluginInterface

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

the class VersionCheckClient method getVersionCheckInfoSupport.

protected Map getVersionCheckInfoSupport(String reason, boolean only_if_cached, boolean force, boolean v6) {
    try {
        synchronized (listeners) {
            if (REASON_UPDATE_CHECK_START.equals(reason)) {
                startCheckRan = true;
            }
            for (VersionCheckClientListener l : listeners) {
                l.versionCheckStarted(reason);
            }
        }
    } catch (Throwable t) {
        Debug.out(t);
    }
    if (v6) {
        if (enable_v6) {
            try {
                check_mon.enter();
                long time_diff = SystemTime.getCurrentTime() - last_check_time_v6;
                force = force || time_diff > CACHE_PERIOD || time_diff < 0;
                if (last_check_data_v6 == null || last_check_data_v6.size() == 0 || force) {
                    // flag is set as its had not chance of being cached yet!
                    if (only_if_cached && last_check_data_v6 != null) {
                        return (new HashMap());
                    }
                    try {
                        last_check_data_v6 = performVersionCheck(constructVersionCheckMessage(reason), true, true, true);
                        if (last_check_data_v6 != null && last_check_data_v6.size() > 0) {
                            COConfigurationManager.setParameter("versioncheck.cache.v6", last_check_data_v6);
                        }
                    } catch (SocketException t) {
                    // internet is broken
                    // Debug.out(t.getClass().getName() + ": " + t.getMessage());
                    } catch (UnknownHostException t) {
                    // dns is broken
                    // Debug.out(t.getClass().getName() + ": " + t.getMessage());
                    } catch (Throwable t) {
                        Debug.out(t);
                        last_check_data_v6 = new HashMap();
                    }
                } else {
                    Logger.log(new LogEvent(LOGID, "VersionCheckClient is using " + "cached version check info. Using " + last_check_data_v6.size() + " reply keys."));
                }
            } finally {
                check_mon.exit();
            }
        }
        if (last_check_data_v6 == null)
            last_check_data_v6 = new HashMap();
        return last_check_data_v6;
    } else {
        try {
            check_mon.enter();
            long time_diff = SystemTime.getCurrentTime() - last_check_time_v4;
            force = force || time_diff > CACHE_PERIOD || time_diff < 0;
            if (last_check_data_v4 == null || last_check_data_v4.size() == 0 || force) {
                // flag is set as its had not chance of being cached yet!
                if (only_if_cached && last_check_data_v4 != null) {
                    return (new HashMap());
                }
                try {
                    last_check_data_v4 = performVersionCheck(constructVersionCheckMessage(reason), true, true, false);
                    if (last_check_data_v4 != null && last_check_data_v4.size() > 0) {
                        COConfigurationManager.setParameter("versioncheck.cache.v4", last_check_data_v4);
                    }
                    try {
                        if (CoreFactory.isCoreAvailable() && CoreFactory.getSingleton().getPluginManager().isInitialized()) {
                            // installed plugin IDs
                            PluginInterface[] plugins = CoreFactory.getSingleton().getPluginManager().getPluginInterfaces();
                            for (int i = 0; i < plugins.length; i++) {
                                PluginInterface plugin = plugins[i];
                                Map data = plugin.getPluginconfig().getPluginMapParameter("plugin.versionserver.data", null);
                                if (data != null) {
                                    plugin.getPluginconfig().setPluginMapParameter("plugin.versionserver.data", new HashMap());
                                }
                            }
                        }
                    } catch (Throwable e) {
                    }
                } catch (UnknownHostException t) {
                    // no internet
                    Debug.outNoStack("VersionCheckClient - " + t.getClass().getName() + ": " + t.getMessage());
                } catch (IOException t) {
                    // General connection problem.
                    Debug.outNoStack("VersionCheckClient - " + t.getClass().getName() + ": " + t.getMessage());
                } catch (Throwable t) {
                    Debug.out(t);
                    last_check_data_v4 = new HashMap();
                }
            } else {
                if (Logger.isEnabled())
                    Logger.log(new LogEvent(LOGID, "VersionCheckClient is using " + "cached version check info. Using " + last_check_data_v4.size() + " reply keys."));
            }
        } finally {
            check_mon.exit();
        }
        if (last_check_data_v4 == null)
            last_check_data_v4 = new HashMap();
        last_feature_flag_cache_time = 0;
        return last_check_data_v4;
    }
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) PluginInterface(com.biglybt.pif.PluginInterface)

Example 95 with PluginInterface

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

the class VersionCheckClient method constructVersionCheckMessage.

/**
 * Construct the default version check message.
 * @return message to send
 */
public static Map<String, Object> constructVersionCheckMessage(String reason) {
    // only send if anonymous-check flag is not set
    boolean send_info = COConfigurationManager.getBooleanParameter("Send Version Info");
    Map<String, Object> message = new HashMap<>();
    // always send
    message.put("appid", SystemProperties.getApplicationIdentifier());
    message.put("appname", SystemProperties.getApplicationName());
    message.put("version", Constants.AZUREUS_VERSION);
    message.put("first_version", COConfigurationManager.getStringParameter("First Recorded Version", ""));
    String sub_ver = Constants.AZUREUS_SUBVER;
    if (sub_ver.length() > 0) {
        message.put("subver", sub_ver);
    }
    if (COConfigurationManager.getBooleanParameter("Beta Programme Enabled")) {
        message.put("beta_prog", "true");
    }
    message.put("ui", COConfigurationManager.getStringParameter("ui", "unknown"));
    message.put("os", Constants.OSName);
    message.put("os_version", System.getProperty("os.version"));
    // see http://lopica.sourceforge.net/os.html
    message.put("os_arch", System.getProperty("os.arch"));
    // might be needed to openjdk on osx
    message.put("os_arch_dm", System.getProperty("sun.arch.data.model"));
    boolean using_phe = COConfigurationManager.getBooleanParameter("network.transport.encrypted.require");
    message.put("using_phe", using_phe ? new Long(1) : new Long(0));
    message.put("imode", COConfigurationManager.getStringParameter("installer.mode", ""));
    // swt stuff
    try {
        Class c = Class.forName("org.eclipse.swt.SWT");
        String swt_platform = (String) c.getMethod("getPlatform", new Class[] {}).invoke(null, new Object[] {});
        message.put("swt_platform", swt_platform);
        Integer swt_version = (Integer) c.getMethod("getVersion", new Class[] {}).invoke(null, new Object[] {});
        message.put("swt_version", new Long(swt_version.longValue()));
    } catch (ClassNotFoundException e) {
    /* ignore */
    } catch (NoClassDefFoundError er) {
    /* ignore */
    } catch (InvocationTargetException err) {
    /* ignore */
    } catch (Throwable t) {
        t.printStackTrace();
    }
    int last_send_time = COConfigurationManager.getIntParameter("Send Version Info Last Time", -1);
    int current_send_time = (int) (SystemTime.getCurrentTime() / 1000);
    COConfigurationManager.setParameter("Send Version Info Last Time", current_send_time);
    String id = COConfigurationManager.getStringParameter("ID", null);
    if (id != null && send_info) {
        message.put("id", id);
        try {
            byte[] id2 = CryptoManagerFactory.getSingleton().getSecureID();
            message.put("id2", id2);
        } catch (Throwable e) {
        }
        if (last_send_time != -1 && last_send_time < current_send_time) {
            // time since last
            message.put("tsl", new Long(current_send_time - last_send_time));
        }
        message.put("reason", reason);
        String java_version = Constants.JAVA_VERSION;
        if (java_version == null) {
            java_version = "unknown";
        }
        message.put("java", java_version);
        String java_vendor = System.getProperty("java.vm.vendor");
        if (java_vendor == null) {
            java_vendor = "unknown";
        }
        message.put("javavendor", java_vendor);
        int api_level = Constants.API_LEVEL;
        if (api_level > 0) {
            message.put("api_level", api_level);
        }
        long max_mem = Runtime.getRuntime().maxMemory() / (1024 * 1024);
        message.put("javamx", new Long(max_mem));
        String java_rt_name = System.getProperty("java.runtime.name");
        if (java_rt_name != null) {
            message.put("java_rt_name", java_rt_name);
        }
        String java_rt_version = System.getProperty("java.runtime.version");
        if (java_rt_version != null) {
            message.put("java_rt_version", java_rt_version);
        }
        OverallStats stats = StatsFactory.getStats();
        if (stats != null) {
            // long total_bytes_downloaded 	= stats.getDownloadedBytes();
            // long total_bytes_uploaded		= stats.getUploadedBytes();
            long total_uptime = stats.getTotalUpTime();
            // removed due to complaints about anonymous stats collection
            // message.put( "total_bytes_downloaded", new Long( total_bytes_downloaded ) );
            // message.put( "total_bytes_uploaded", new Long( total_bytes_uploaded ) );
            message.put("total_uptime", new Long(total_uptime));
        // message.put( "dlstats", stats.getDownloadStats());
        }
        try {
            int port = UDPNetworkManager.getSingleton().getUDPNonDataListeningPortNumber();
            message.put("dht", port);
        } catch (Throwable e) {
            Debug.out(e);
        }
        try {
            NetworkAdminASN current_asn = NetworkAdmin.getSingleton().getCurrentASN();
            message.put("ip_as", current_asn.getAS());
            String asn = current_asn.getASName();
            if (asn.length() > 64) {
                asn = asn.substring(0, 64);
            }
            message.put("ip_asn", asn);
        } catch (Throwable e) {
            Debug.out(e);
        }
        // send locale, so we can determine which languages need attention
        message.put("locale", Locale.getDefault().toString());
        String originalLocale = System.getProperty("user.language") + "_" + System.getProperty("user.country");
        String variant = System.getProperty("user.variant");
        if (variant != null && variant.length() > 0) {
            originalLocale += "_" + variant;
        }
        message.put("orig_locale", originalLocale);
        // We may want to reply differently if the user is in Beginner mode vs Advanced
        message.put("user_mode", COConfigurationManager.getIntParameter("User Mode", -1));
        try {
            if (CoreFactory.isCoreAvailable() && CoreFactory.getSingleton().getPluginManager().isInitialized()) {
                // installed plugin IDs
                PluginInterface[] plugins = CoreFactory.getSingleton().getPluginManager().getPluginInterfaces();
                List pids = new ArrayList();
                List vs_data = new ArrayList();
                for (int i = 0; i < plugins.length; i++) {
                    PluginInterface plugin = plugins[i];
                    String pid = plugin.getPluginID();
                    String info = plugin.getPluginconfig().getPluginStringParameter("plugin.info");
                    // filter out built-in and core ones
                    if ((info != null && info.length() > 0) || (!pid.startsWith("<") && !pid.startsWith("azbp") && !pid.startsWith("azupdater") && !pid.startsWith("azplatform") && !pids.contains(pid))) {
                        if (info != null && info.length() > 0) {
                            if (info.length() < 256) {
                                pid += ":" + info;
                            } else {
                                Debug.out("Plugin '" + pid + "' reported excessive info string '" + info + "'");
                            }
                        }
                        pids.add(pid);
                    }
                    Map data = plugin.getPluginconfig().getPluginMapParameter("plugin.versionserver.data", null);
                    if (data != null) {
                        Map payload = new HashMap();
                        byte[] data_bytes = BEncoder.encode(data);
                        if (data_bytes.length > 16 * 1024) {
                            Debug.out("Plugin '" + pid + "' reported excessive version server data (length=" + data_bytes.length + ")");
                            payload.put("error", "data too long: " + data_bytes.length);
                        } else {
                            payload.put("data", data_bytes);
                        }
                        payload.put("id", pid);
                        payload.put("version", plugin.getPluginVersion());
                        vs_data.add(payload);
                    }
                }
                message.put("plugins", pids);
                if (vs_data.size() > 0) {
                    message.put("plugin_data", vs_data);
                }
            }
        } catch (Throwable e) {
            Debug.out(e);
        }
    }
    return message;
}
Also used : OverallStats(com.biglybt.core.stats.transfer.OverallStats) NetworkAdminASN(com.biglybt.core.networkmanager.admin.NetworkAdminASN) PluginInterface(com.biglybt.pif.PluginInterface) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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