Search in sources :

Example 46 with Core

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

the class MenuFactory method handleShowChanges.

private static void handleShowChanges() {
    final String NL = "\r\n";
    StringWriter content = new StringWriter();
    content.append("**** Please review the contents of this before submitting it ****" + NL + NL);
    content.append("Settings" + NL);
    IndentWriter iw = new IndentWriter(new PrintWriter(content));
    iw.indent();
    try {
        COConfigurationManager.dumpConfigChanges(iw);
    } finally {
        iw.exdent();
        iw.close();
    }
    Core core = CoreFactory.getSingleton();
    content.append("Plugins" + NL);
    PluginInterface[] plugins = core.getPluginManager().getPlugins();
    for (PluginInterface pi : plugins) {
        if (pi.getPluginState().isBuiltIn()) {
            continue;
        }
        content.append("    ").append(pi.getPluginName()).append(": ").append(pi.getPluginVersion()).append(NL);
    }
    java.util.List<DownloadManager> dms = core.getGlobalManager().getDownloadManagers();
    content.append("Downloads - ").append(String.valueOf(dms.size())).append(NL);
    iw = new IndentWriter(new PrintWriter(content));
    iw.indent();
    try {
        for (DownloadManager dm : dms) {
            String hash_str;
            try {
                byte[] hash = dm.getTorrent().getHash();
                hash_str = Base32.encode(hash).substring(0, 16);
            } catch (Throwable e) {
                hash_str = "<no hash>";
            }
            iw.println(hash_str + ": " + DisplayFormatters.formatDownloadStatus(dm));
            iw.indent();
            dm.getDownloadState().dump(iw);
            try {
            } finally {
                iw.exdent();
            }
        }
    } finally {
        iw.exdent();
        iw.close();
    }
    content.append("Categories" + NL);
    Category[] cats = CategoryManager.getCategories();
    iw = new IndentWriter(new PrintWriter(content));
    iw.indent();
    try {
        for (Category cat : cats) {
            iw.println(cat.getName());
            iw.indent();
            try {
                cat.dump(iw);
            } finally {
                iw.exdent();
            }
        }
    } finally {
        iw.exdent();
        iw.close();
    }
    content.append("Speed Limits" + NL);
    iw = new IndentWriter(new PrintWriter(content));
    iw.indent();
    try {
        SpeedLimitHandler.getSingleton(core).dump(iw);
    } finally {
        iw.exdent();
        iw.close();
    }
    new TextViewerWindow(MessageText.getString("config.changes.title"), null, content.toString(), false);
}
Also used : Category(com.biglybt.core.category.Category) PluginInterface(com.biglybt.pif.PluginInterface) DownloadManager(com.biglybt.core.download.DownloadManager) StringWriter(java.io.StringWriter) com.biglybt.core.util(com.biglybt.core.util) PrintWriter(java.io.PrintWriter) Core(com.biglybt.core.Core)

Example 47 with Core

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

the class MainStatusBar method initStatusBar.

/**
 * @return composite holding the statusbar
 */
public Composite initStatusBar(final Composite _parent) {
    this.parent = _parent;
    this.display = parent.getDisplay();
    this.uiFunctions = UIFunctionsManager.getUIFunctions();
    ImageLoader imageLoader = ImageLoader.getInstance();
    FormData formData;
    Color fgColor = parent.getForeground();
    statusBar = new Composite(parent, SWT.NONE);
    statusBar.setForeground(fgColor);
    isAZ3 = "az3".equalsIgnoreCase(COConfigurationManager.getStringParameter("ui"));
    statusBar.getShell().addListener(SWT.Deiconify, new Listener() {

        @Override
        public void handleEvent(Event event) {
            Utils.execSWTThreadLater(0, new AERunnable() {

                @Override
                public void runSupport() {
                    if (!statusBar.isDisposed()) {
                        statusBar.layout();
                    }
                }
            });
        }
    });
    statusBar.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            if (uiFunctions != null) {
                UIUpdater uiUpdater = uiFunctions.getUIUpdater();
                if (uiUpdater != null) {
                    uiUpdater.removeUpdater(MainStatusBar.this);
                }
            }
            PRManager.removeListener(progressListener);
            Utils.disposeSWTObjects(imgRec, imgSent);
            Utils.removeParameterListeners(mapConfigListeners);
            if (alert_flasher_event != null) {
                alert_flasher_event.cancel();
                alert_flasher_event = null;
            }
            if (alertHistoryListener != null) {
                Alerts.removeMessageHistoryListener(alertHistoryListener);
                alertHistoryListener = null;
            }
        }
    });
    GridLayout layout_status = new GridLayout();
    layout_status.numColumns = 20;
    layout_status.horizontalSpacing = 0;
    layout_status.verticalSpacing = 0;
    layout_status.marginHeight = 0;
    if (Constants.isOSX) {
        // OSX has a resize widget on the bottom right.  It's about 15px wide.
        try {
            layout_status.marginRight = 15;
        } catch (NoSuchFieldError e) {
            // Pre SWT 3.1
            layout_status.marginWidth = 15;
        }
    } else {
        layout_status.marginWidth = 0;
    }
    statusBar.setLayout(layout_status);
    // Either the Status Text
    statusText = new CLabel(statusBar, borderFlag);
    statusText.setForeground(fgColor);
    Utils.setLayoutData(statusText, new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
    addStatusBarMenu(statusText);
    GC gc = new GC(statusText);
    // add 6, because CLabel forces a 3 pixel indent
    int height = Math.max(16, gc.getFontMetrics().getHeight()) + 6;
    gc.dispose();
    formData = new FormData();
    formData.height = height;
    // 2 params for Pre SWT 3.0
    formData.bottom = new FormAttachment(100, 0);
    // 2 params for Pre SWT 3.0
    formData.left = new FormAttachment(0, 0);
    // 2 params for Pre SWT 3.0
    formData.right = new FormAttachment(100, 0);
    statusBar.setLayoutData(formData);
    Listener listener = new Listener() {

        @Override
        public void handleEvent(Event e) {
            if (clickListener == null) {
                if (updateWindow != null) {
                    updateWindow.show();
                }
            } else {
                clickListener.UIStatusTextClicked();
            }
        }
    };
    statusText.addListener(SWT.MouseUp, listener);
    statusText.addListener(SWT.MouseDoubleClick, listener);
    // KN: Don't know why OSX is treated differently but this check was already here from the previous code
    if (Constants.isOSX) {
        progressBar = new AZProgressBar(statusBar, true);
    } else {
        progressBar = new AZProgressBar(statusBar, false);
    }
    progressBar.setVisible(false);
    progressGridData = new GridData(SWT.CENTER, SWT.CENTER, false, false);
    progressGridData.widthHint = 5;
    Utils.setLayoutData(progressBar, progressGridData);
    // addRIP();
    /*
		 * Progress reporting window image label
		 */
    progressViewerImageLabel = new CLabelPadding(statusBar, SWT.NONE);
    // image set below after adding listener
    progressViewerImageLabel.setToolTipText(MessageText.getString("Progress.reporting.statusbar.button.tooltip"));
    progressViewerImageLabel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            /*
				 * Opens the progress viewer if any of the reporters in the array is NOT already opened
				 * KN: TODO -- This is only a partial solution to minimize the occurrence of the main progress window
				 * opening more than once.  The one remaining case where multiple windows will still open is
				 * when you have one opened already... then run another process such as a torrent file download...
				 * at this point this new process is not in the already opened window so the check would
				 * allow the second window to open.
				 */
            IProgressReporter[] reporters = PRManager.getReportersArray(false);
            if (reporters.length == 0) {
                /*
					 * If there's nothing to see then open the window; the default widow will say there's nothing to see
					 * KN: calling isShowingEmpty return true is there is already a window opened showing the empty panel
					 */
                if (!ProgressReporterWindow.isShowingEmpty()) {
                    ProgressReporterWindow.open(reporters, ProgressReporterWindow.SHOW_TOOLBAR);
                }
            } else {
                for (int i = 0; i < reporters.length; i++) {
                    if (!ProgressReporterWindow.isOpened(reporters[i])) {
                        ProgressReporterWindow.open(reporters, ProgressReporterWindow.SHOW_TOOLBAR);
                        break;
                    }
                }
            }
        }
    });
    progressViewerImageLabel.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            ImageLoader imageLoader = ImageLoader.getInstance();
            imageLoader.releaseImage("progress_error");
            imageLoader.releaseImage("progress_info");
            imageLoader.releaseImage("progress_viewer");
        }
    });
    this.plugin_label_composite = new Composite(statusBar, SWT.NONE);
    this.plugin_label_composite.setForeground(fgColor);
    GridLayout gridLayout = new GridLayout();
    gridLayout.horizontalSpacing = 0;
    gridLayout.verticalSpacing = 0;
    gridLayout.marginHeight = 0;
    gridLayout.marginBottom = 0;
    gridLayout.marginTop = 0;
    gridLayout.marginLeft = 0;
    gridLayout.marginRight = 0;
    // Something nice and big. :)
    gridLayout.numColumns = 20;
    GridData gridData = new GridData(GridData.FILL_VERTICAL);
    gridData.heightHint = height;
    gridData.minimumHeight = height;
    plugin_label_composite.setLayout(gridLayout);
    plugin_label_composite.setLayoutData(gridData);
    srStatus = new CLabelPadding(statusBar, borderFlag);
    srStatus.setText(MessageText.getString("SpeedView.stats.ratio"));
    Utils.addAndFireParameterListener(mapConfigListeners, true, "Status Area Show SR", new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            srStatus.setVisible(COConfigurationManager.getBooleanParameter(parameterName));
            statusBar.layout();
        }
    });
    natStatus = new CLabelPadding(statusBar, borderFlag);
    natStatus.setText("");
    final Menu natStatusMenu = new Menu(statusBar.getShell(), SWT.POP_UP);
    natStatus.setMenu(natStatusMenu);
    MenuItem nat_test = new MenuItem(natStatusMenu, SWT.PUSH);
    Messages.setLanguageText(nat_test, "MainWindow.menu.tools.nattest");
    nat_test.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            new NatTestWindow();
        }
    });
    Utils.addAndFireParameterListener(mapConfigListeners, true, "Status Area Show NAT", new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            natStatus.setVisible(COConfigurationManager.getBooleanParameter(parameterName));
            statusBar.layout();
        }
    });
    dhtStatus = new CLabelPadding(statusBar, borderFlag);
    dhtStatus.setText("");
    dhtStatus.setToolTipText(MessageText.getString("MainWindow.dht.status.tooltip"));
    Utils.addAndFireParameterListener(mapConfigListeners, true, "Status Area Show DDB", new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            dhtStatus.setVisible(COConfigurationManager.getBooleanParameter(parameterName));
            statusBar.layout();
        }
    });
    // ip filters
    ipBlocked = new CLabelPadding(statusBar, borderFlag);
    // $NON-NLS-1$
    ipBlocked.setText("{} IPs:");
    Messages.setLanguageText(ipBlocked, "MainWindow.IPs.tooltip");
    ipBlocked.addListener(SWT.MouseDoubleClick, new ListenerNeedingCoreRunning() {

        @Override
        public void handleEvent(Core core, Event event) {
            BlockedIpsWindow.showBlockedIps(core, parent.getShell());
        }
    });
    final Menu menuIPFilter = new Menu(statusBar.getShell(), SWT.POP_UP);
    ipBlocked.setMenu(menuIPFilter);
    menuIPFilter.addListener(SWT.Show, new Listener() {

        @Override
        public void handleEvent(Event e) {
            MenuItem[] oldItems = menuIPFilter.getItems();
            for (int i = 0; i < oldItems.length; i++) {
                oldItems[i].dispose();
            }
            if (!CoreFactory.isCoreRunning()) {
                return;
            }
            Core core = CoreFactory.getSingleton();
            final IpFilter ip_filter = core.getIpFilterManager().getIPFilter();
            final MenuItem ipfEnable = new MenuItem(menuIPFilter, SWT.CHECK);
            ipfEnable.setSelection(ip_filter.isEnabled());
            Messages.setLanguageText(ipfEnable, "MyTorrentsView.menu.ipf_enable");
            ipfEnable.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    ip_filter.setEnabled(ipfEnable.getSelection());
                }
            });
            final MenuItem ipfOptions = new MenuItem(menuIPFilter, SWT.PUSH);
            Messages.setLanguageText(ipfOptions, "ipfilter.options");
            ipfOptions.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    UIFunctions uif = UIFunctionsManager.getUIFunctions();
                    if (uif != null) {
                        uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, "ipfilter");
                    }
                }
            });
        }
    });
    Utils.addAndFireParameterListener(mapConfigListeners, true, "Status Area Show IPF", new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            ipBlocked.setVisible(COConfigurationManager.getBooleanParameter(parameterName));
            statusBar.layout();
        }
    });
    // down speed
    statusDown = new CLabelPadding(statusBar, borderFlag);
    statusDown.setImage(imageLoader.getImage("down"));
    // statusDown.setText(/*MessageText.getString("ConfigView.download.abbreviated") +*/"n/a");
    Messages.setLanguageText(statusDown, "MainWindow.status.updowndetails.tooltip");
    Listener lStats = new Listener() {

        @Override
        public void handleEvent(Event e) {
            uiFunctions.getMDI().loadEntryByID(StatsView.VIEW_ID, true, false, "TransferStatsView");
        }
    };
    statusUp = new CLabelPadding(statusBar, borderFlag);
    statusUp.setImage(imageLoader.getImage("up"));
    // statusUp.setText(/*MessageText.getString("ConfigView.upload.abbreviated") +*/"n/a");
    Messages.setLanguageText(statusUp, "MainWindow.status.updowndetails.tooltip");
    statusDown.addListener(SWT.MouseDoubleClick, lStats);
    statusUp.addListener(SWT.MouseDoubleClick, lStats);
    Listener lDHT = new Listener() {

        @Override
        public void handleEvent(Event e) {
            uiFunctions.getMDI().loadEntryByID(StatsView.VIEW_ID, true, false, "DHTView");
        }
    };
    dhtStatus.addListener(SWT.MouseDoubleClick, lDHT);
    Listener lSR = new Listener() {

        @Override
        public void handleEvent(Event e) {
            uiFunctions.getMDI().loadEntryByID(StatsView.VIEW_ID, true, false, "SpeedView");
            OverallStats stats = StatsFactory.getStats();
            if (stats == null) {
                return;
            }
            long ratio = (1000 * stats.getUploadedBytes() / (stats.getDownloadedBytes() + 1));
            if (ratio < 900) {
            // Utils.launch(Constants.AZUREUS_WIKI + "Share_Ratio");
            }
        }
    };
    srStatus.addListener(SWT.MouseDoubleClick, lSR);
    Listener lNAT = new ListenerNeedingCoreRunning() {

        @Override
        public void handleEvent(Core core, Event e) {
            uiFunctions.getMDI().loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, true, false, ConfigSection.SECTION_CONNECTION);
            if (PluginInitializer.getDefaultInterface().getConnectionManager().getNATStatus() != ConnectionManager.NAT_OK) {
                Utils.launch(Constants.AZUREUS_WIKI + "NAT_problem");
            }
        }
    };
    natStatus.addListener(SWT.MouseDoubleClick, lNAT);
    boolean bSpeedMenu = COConfigurationManager.getBooleanParameter("GUI_SWT_bOldSpeedMenu");
    if (bSpeedMenu) {
        // Status Bar Menu construction
        final Menu menuUpSpeed = new Menu(statusBar.getShell(), SWT.POP_UP);
        menuUpSpeed.addListener(SWT.Show, new Listener() {

            @Override
            public void handleEvent(Event e) {
                if (!CoreFactory.isCoreRunning()) {
                    return;
                }
                Core core = CoreFactory.getSingleton();
                GlobalManager globalManager = core.getGlobalManager();
                SelectableSpeedMenu.generateMenuItems(menuUpSpeed, core, globalManager, true);
            }
        });
        statusUp.setMenu(menuUpSpeed);
    } else {
        statusUp.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                if (!(e.button == 3 || (e.button == 1 && e.stateMask == SWT.CONTROL))) {
                    return;
                }
                Event event = new Event();
                event.type = SWT.MouseUp;
                event.widget = e.widget;
                event.stateMask = e.stateMask;
                event.button = e.button;
                e.widget.getDisplay().post(event);
                CoreWaiterSWT.waitForCoreRunning(new CoreRunningListener() {

                    @Override
                    public void coreRunning(Core core) {
                        SelectableSpeedMenu.invokeSlider(statusUp, core, true);
                    }
                });
            }
        });
    }
    if (bSpeedMenu) {
        final Menu menuDownSpeed = new Menu(statusBar.getShell(), SWT.POP_UP);
        menuDownSpeed.addListener(SWT.Show, new Listener() {

            @Override
            public void handleEvent(Event e) {
                if (!CoreFactory.isCoreRunning()) {
                    return;
                }
                Core core = CoreFactory.getSingleton();
                GlobalManager globalManager = core.getGlobalManager();
                SelectableSpeedMenu.generateMenuItems(menuDownSpeed, core, globalManager, false);
            }
        });
        statusDown.setMenu(menuDownSpeed);
    } else {
        statusDown.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                if (!(e.button == 3 || (e.button == 1 && e.stateMask == SWT.CONTROL))) {
                    return;
                }
                Event event = new Event();
                event.type = SWT.MouseUp;
                event.widget = e.widget;
                event.stateMask = e.stateMask;
                event.button = e.button;
                e.widget.getDisplay().post(event);
                CoreWaiterSWT.waitForCoreRunning(new CoreRunningListener() {

                    @Override
                    public void coreRunning(Core core) {
                        SelectableSpeedMenu.invokeSlider(statusDown, core, false);
                    }
                });
            }
        });
    }
    statusWarnings = new CLabelPadding(statusBar, borderFlag);
    warningIcon = imageLoader.getImage("image.sidebar.vitality.alert");
    warningGreyIcon = imageLoader.getImage("image.sidebar.vitality.alert-gray");
    infoIcon = imageLoader.getImage("image.sidebar.vitality.info");
    updateStatusWarnings(null, false);
    Messages.setLanguageText(statusWarnings, "MainWindow.status.warning.tooltip");
    alertHistoryListener = new AlertHistoryListener() {

        @Override
        public void alertHistoryAdded(LogAlert alert) {
            updateStatusWarnings(alert, true);
        }

        @Override
        public void alertHistoryRemoved(LogAlert alert) {
            updateStatusWarnings(alert, false);
        }
    };
    Alerts.addMessageHistoryListener(alertHistoryListener);
    statusWarnings.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent e) {
            if (e.button != 1) {
                return;
            }
            if (SystemWarningWindow.numWarningWindowsOpen > 0) {
                return;
            }
            ArrayList<LogAlert> alerts = Alerts.getUnviewedLogAlerts();
            if (alerts.size() == 0) {
                return;
            }
            Shell shell = statusWarnings.getShell();
            Rectangle bounds = statusWarnings.getClientArea();
            Point ptBottomRight = statusWarnings.toDisplay(bounds.x + bounds.width, bounds.y);
            new SystemWarningWindow(alerts.get(0), ptBottomRight, shell, 0);
        }

        @Override
        public void mouseDown(MouseEvent e) {
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
        }
    });
    Menu menuStatusWarnings = new Menu(statusBar.getShell(), SWT.POP_UP);
    statusWarnings.setMenu(menuStatusWarnings);
    final MenuItem dismissAllItem = new MenuItem(menuStatusWarnings, SWT.PUSH);
    menuStatusWarnings.addListener(SWT.Show, new Listener() {

        @Override
        public void handleEvent(Event e) {
            dismissAllItem.setEnabled(Alerts.getUnviewedLogAlerts().size() > 0);
        }
    });
    Messages.setLanguageText(dismissAllItem, "label.dismiss.all");
    dismissAllItem.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            ArrayList<LogAlert> alerts = Alerts.getUnviewedLogAlerts();
            for (LogAlert a : alerts) {
                Alerts.markAlertAsViewed(a);
            }
        }
    });
    Utils.addAndFireParameterListener(mapConfigListeners, true, "status.rategraphs", new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            boolean doRateGraphs = COConfigurationManager.getBooleanParameter("status.rategraphs");
            if (doRateGraphs) {
                if (imgRec == null || imgRec.isDisposed()) {
                    imgRec = new Image(display, 100, 20);
                    GC gc = new GC(imgRec);
                    gc.setBackground(statusDown.getBackground());
                    gc.fillRectangle(0, 0, 100, 20);
                    gc.dispose();
                    statusDown.setBackgroundImage(imgRec);
                }
                if (imgSent == null || imgSent.isDisposed()) {
                    imgSent = new Image(display, 100, 20);
                    GC gc = new GC(imgSent);
                    gc.setBackground(statusUp.getBackground());
                    gc.fillRectangle(0, 0, 100, 20);
                    gc.dispose();
                    statusUp.setBackgroundImage(imgSent);
                }
            } else {
                statusUp.setBackgroundImage(null);
                statusDown.setBackgroundImage(null);
                Utils.disposeSWTObjects(imgRec, imgSent);
                imgRec = imgSent = null;
            }
        }
    });
    // ///////
    progressListener = new ProgressListener();
    PRManager.addListener(progressListener);
    uiFunctions.getUIUpdater().addUpdater(this);
    ArrayList<Runnable> list;
    this_mon.enter();
    try {
        list = listRunAfterInit;
        listRunAfterInit = null;
    } finally {
        this_mon.exit();
    }
    for (Runnable runnable : list) {
        try {
            runnable.run();
        } catch (Exception e) {
            Debug.out(e);
        }
    }
    statusBar.layout(true);
    return statusBar;
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager) UIFunctions(com.biglybt.ui.UIFunctions) AlertHistoryListener(com.biglybt.ui.swt.Alerts.AlertHistoryListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) FormAttachment(org.eclipse.swt.layout.FormAttachment) Core(com.biglybt.core.Core) FormData(org.eclipse.swt.layout.FormData) LogAlert(com.biglybt.core.logging.LogAlert) UIUpdater(com.biglybt.ui.common.updater.UIUpdater) CLabel(org.eclipse.swt.custom.CLabel) IpFilter(com.biglybt.core.ipfilter.IpFilter) ParameterListener(com.biglybt.core.config.ParameterListener) UIStatusTextClickListener(com.biglybt.ui.UIStatusTextClickListener) AlertHistoryListener(com.biglybt.ui.swt.Alerts.AlertHistoryListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) OverallStats(com.biglybt.core.stats.transfer.OverallStats) GridLayout(org.eclipse.swt.layout.GridLayout) NatTestWindow(com.biglybt.ui.swt.nat.NatTestWindow) GridData(org.eclipse.swt.layout.GridData) ParameterListener(com.biglybt.core.config.ParameterListener) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 48 with Core

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

the class TagUIUtils method setupSideBarMenus.

public static void setupSideBarMenus(final MenuManager menuManager) {
    com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem("sidebar." + MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, "ConfigView.section.style.TagInSidebar");
    menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_CHECK);
    menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {

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

        @Override
        public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
            menu.setData(Boolean.valueOf(COConfigurationManager.getBooleanParameter("Library.TagInSideBar")));
        }
    });
    // tag options
    menuItem = menuManager.addMenuItem("sidebar." + MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, "label.tags");
    menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
    menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {

        @Override
        public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
            menu.removeAllChildItems();
            // manual
            final TagType manual_tt = TagManagerFactory.getTagManager().getTagType(TagType.TT_DOWNLOAD_MANUAL);
            com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem(menu, manual_tt.getTagTypeName(false));
            menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
            menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {

                @Override
                public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
                    menu.removeAllChildItems();
                    final List<Tag> all_tags = manual_tt.getTags();
                    List<String> menu_names = new ArrayList<>();
                    Map<String, Tag> menu_name_map = new IdentityHashMap<>();
                    boolean all_visible = true;
                    boolean all_invisible = true;
                    boolean has_ut = false;
                    for (Tag t : all_tags) {
                        String name = t.getTagName(true);
                        menu_names.add(name);
                        menu_name_map.put(name, t);
                        if (t.isVisible()) {
                            all_invisible = false;
                        } else {
                            all_visible = false;
                        }
                        TagFeatureProperties props = (TagFeatureProperties) t;
                        TagProperty prop = props.getProperty(TagFeatureProperties.PR_UNTAGGED);
                        if (prop != null) {
                            Boolean b = prop.getBoolean();
                            if (b != null && b) {
                                has_ut = true;
                            }
                        }
                    }
                    com.biglybt.pif.ui.menus.MenuItem showAllItem = menuManager.addMenuItem(menu, "label.show.all");
                    showAllItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
                    showAllItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {

                        @Override
                        public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                            for (Tag t : all_tags) {
                                t.setVisible(true);
                            }
                        }
                    });
                    com.biglybt.pif.ui.menus.MenuItem hideAllItem = menuManager.addMenuItem(menu, "popup.error.hideall");
                    hideAllItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
                    hideAllItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {

                        @Override
                        public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                            for (Tag t : all_tags) {
                                t.setVisible(false);
                            }
                        }
                    });
                    com.biglybt.pif.ui.menus.MenuItem sepItem = menuManager.addMenuItem(menu, "sepm");
                    sepItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
                    showAllItem.setEnabled(!all_visible);
                    hideAllItem.setEnabled(!all_invisible);
                    List<Object> menu_structure = MenuBuildUtils.splitLongMenuListIntoHierarchy(menu_names, TagUIUtils.MAX_TOP_LEVEL_TAGS_IN_MENU);
                    for (Object obj : menu_structure) {
                        List<Tag> bucket_tags = new ArrayList<>();
                        com.biglybt.pif.ui.menus.MenuItem parent_menu;
                        if (obj instanceof String) {
                            parent_menu = menu;
                            bucket_tags.add(menu_name_map.get((String) obj));
                        } else {
                            Object[] entry = (Object[]) obj;
                            List<String> tag_names = (List<String>) entry[1];
                            boolean sub_all_visible = true;
                            boolean sub_some_visible = false;
                            for (String name : tag_names) {
                                Tag tag = menu_name_map.get(name);
                                if (tag.isVisible()) {
                                    sub_some_visible = true;
                                } else {
                                    sub_all_visible = false;
                                }
                                bucket_tags.add(tag);
                            }
                            String mod;
                            if (sub_all_visible) {
                                mod = " (*)";
                            } else if (sub_some_visible) {
                                mod = " (+)";
                            } else {
                                mod = "";
                            }
                            parent_menu = menuManager.addMenuItem(menu, "!" + (String) entry[0] + mod + "!");
                            parent_menu.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
                        }
                        for (final Tag tag : bucket_tags) {
                            com.biglybt.pif.ui.menus.MenuItem m = menuManager.addMenuItem(parent_menu, tag.getTagName(false));
                            m.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_CHECK);
                            m.setData(Boolean.valueOf(tag.isVisible()));
                            m.addListener(new MenuItemListener() {

                                @Override
                                public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                                    tag.setVisible(!tag.isVisible());
                                }
                            });
                        }
                    }
                    if (!has_ut) {
                        sepItem = menuManager.addMenuItem(menu, "sepu");
                        sepItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
                        com.biglybt.pif.ui.menus.MenuItem m = menuManager.addMenuItem(menu, "label.untagged");
                        m.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
                        m.addListener(new MenuItemListener() {

                            @Override
                            public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                                try {
                                    String tag_name = MessageText.getString("label.untagged");
                                    Tag ut_tag = manual_tt.getTag(tag_name, true);
                                    if (ut_tag == null) {
                                        ut_tag = manual_tt.createTag(tag_name, true);
                                    }
                                    TagFeatureProperties tp = (TagFeatureProperties) ut_tag;
                                    tp.getProperty(TagFeatureProperties.PR_UNTAGGED).setBoolean(true);
                                } catch (TagException e) {
                                    Debug.out(e);
                                }
                            }
                        });
                    }
                }
            });
            menuItem = menuManager.addMenuItem(menu, "label.add.tag");
            menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {

                @Override
                public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                    createManualTag(null);
                }
            });
            com.biglybt.pif.ui.menus.MenuItem sepItem = menuManager.addMenuItem(menu, "sep1");
            sepItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
            // auto
            menuItem = menuManager.addMenuItem(menu, "wizard.maketorrent.auto");
            menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
            menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {

                @Override
                public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
                    menu.removeAllChildItems();
                    // autos
                    List<TagType> tag_types = TagManagerFactory.getTagManager().getTagTypes();
                    for (final TagType tag_type : tag_types) {
                        if (tag_type.getTagType() == TagType.TT_DOWNLOAD_CATEGORY) {
                            continue;
                        }
                        if (!tag_type.isTagTypeAuto()) {
                            continue;
                        }
                        if (tag_type.getTags().size() == 0) {
                            continue;
                        }
                        com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem(menu, tag_type.getTagTypeName(false));
                        menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
                        menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {

                            @Override
                            public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
                                menu.removeAllChildItems();
                                final List<Tag> tags = tag_type.getTags();
                                com.biglybt.pif.ui.menus.MenuItem showAllItem = menuManager.addMenuItem(menu, "label.show.all");
                                showAllItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
                                showAllItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {

                                    @Override
                                    public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                                        for (Tag t : tags) {
                                            t.setVisible(true);
                                        }
                                    }
                                });
                                com.biglybt.pif.ui.menus.MenuItem hideAllItem = menuManager.addMenuItem(menu, "popup.error.hideall");
                                hideAllItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
                                hideAllItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {

                                    @Override
                                    public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                                        for (Tag t : tags) {
                                            t.setVisible(false);
                                        }
                                    }
                                });
                                boolean all_visible = true;
                                boolean all_invisible = true;
                                for (Tag t : tags) {
                                    if (t.isVisible()) {
                                        all_invisible = false;
                                    } else {
                                        all_visible = false;
                                    }
                                }
                                showAllItem.setEnabled(!all_visible);
                                hideAllItem.setEnabled(!all_invisible);
                                com.biglybt.pif.ui.menus.MenuItem sepItem = menuManager.addMenuItem(menu, "sep2");
                                sepItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
                                for (final Tag t : tags) {
                                    com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem(menu, t.getTagName(false));
                                    menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_CHECK);
                                    menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {

                                        @Override
                                        public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                                            t.setVisible(menu.isSelected());
                                        }
                                    });
                                    menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {

                                        @Override
                                        public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
                                            menu.setData(t.isVisible());
                                        }
                                    });
                                }
                            }
                        });
                    }
                }
            });
            sepItem = menuManager.addMenuItem(menu, "sep3");
            sepItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
            menuItem = menuManager.addMenuItem(menu, "tag.show.stats");
            menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {

                @Override
                public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                    UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                    uiFunctions.getMDI().showEntryByID(StatsView.VIEW_ID, "TagStatsView");
                }
            });
            menuItem = menuManager.addMenuItem(menu, "tag.show.overview");
            menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {

                @Override
                public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                    UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                    uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TAGS);
                }
            });
        }
    });
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(Core core) {
            checkTagSharing(true);
        }
    });
}
Also used : MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UIFunctions(com.biglybt.ui.UIFunctions) CoreRunningListener(com.biglybt.core.CoreRunningListener) List(java.util.List) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) Core(com.biglybt.core.Core) TagProperty(com.biglybt.core.tag.TagFeatureProperties.TagProperty)

Example 49 with Core

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

the class Main method main.

public static void main(String[] args) {
    if (DEBUG_STARTUPTIME) {
        lastDebugTime = System.currentTimeMillis();
    }
    if (Launcher.checkAndLaunch(Main.class, args))
        return;
    // This *has* to be done first as it sets system properties that are read and cached by Java
    COConfigurationManager.preInitialise();
    if (DEBUG_STARTUPTIME) {
        logTime("args: " + Arrays.toString(args));
    }
    Thread.currentThread().setName(Constants.APP_NAME);
    String mi_str = System.getProperty("MULTI_INSTANCE");
    boolean mi = mi_str != null && mi_str.equalsIgnoreCase("true");
    if (DEBUG_STARTUPTIME) {
        logTime("preInit");
    }
    try {
        // Build a list of UIS
        Options uiOptions = new Options();
        Builder builder = Option.builder("u").longOpt("ui").argName("uis").hasArg();
        uiOptions.addOption(builder.build());
        if (Constants.isWindows) {
            builder = Option.builder("console");
            uiOptions.addOption(builder.build());
        }
        try {
            CommandLine commandLine = new DefaultParser().parse(uiOptions, args, true);
            buildUIList(commandLine);
        } catch (ParseException e) {
        }
        // Add UIS Command Line Options
        Options options = UIConst.buildOptions();
        commands = UIConst.buildCommandLine(options, args);
        if (commands == null) {
            System.exit(0);
        }
        if (DEBUG_STARTUPTIME) {
            logTime("buildCommandLine");
        }
        if (!mi) {
            startServer = new StartServer();
            if (startServer.getServerState() == StartServer.STATE_FAULTY) {
                System.setProperty("transitory.startup", "1");
                // looks like there's already a process listening on 127.0.0.1:<port>
                // attempt to pass args to existing instance
                // First, do some OSX magic because parameters are passed via OpenDocument API and other callbacks
                args = CocoaMagic(args);
                if (!new CoreSingleInstanceClient().sendArgs(args, 5000)) {
                    // arg passing attempt failed, so start core anyway
                    String msg = "There appears to be another process already listening on socket [127.0.0.1:" + Constants.INSTANCE_PORT + "].\n\nLocate and terminate the other program or change the control port - <a href=\"" + Constants.URL_WIKI + "w/Commandline_options#Changing_the_Control_Port\">see the wiki for details</a>.";
                    System.err.println(msg);
                    return;
                } else {
                    // we sent params to other core, don't init the core
                    return;
                }
            }
            if (commands.hasOption("closedown") || commands.hasOption("shutdown") || commands.hasOption("restart")) {
                return;
            }
            if (DEBUG_STARTUPTIME) {
                logTime("StartServer");
            }
        } else {
            System.out.println("MULTI_INSTANCE enabled");
        }
        // Special Exit if user ask for help
        if (commands != null && commands.hasOption('h')) {
            HelpFormatter hf = new HelpFormatter();
            hf.setOptionComparator(null);
            hf.printHelp("[options] [torrent [torrent ...]]", options);
            if (startServer != null) {
                startServer.stopIt();
            }
            System.exit(0);
        }
        boolean isFirst = true;
        for (IUserInterface ui : UIConst.UIS.values()) {
            ui.init(isFirst, (UIConst.UIS.size() > 1));
            isFirst = false;
        }
        neverStarted = true;
        core = CoreFactory.create();
        if (DEBUG_STARTUPTIME) {
            logTime("Core Create");
        }
        for (IUserInterface ui : UIConst.UIS.values()) {
            ui.coreCreated(core);
        }
        if (DEBUG_STARTUPTIME) {
            logTime("UIConst.set" + Constants.AZUREUS_NAME + "Core");
        }
        UIConst.processArgs(commands, options, args);
        if (DEBUG_STARTUPTIME) {
            logTime("UIConst.processArgs");
        }
        if (startServer != null) {
            startServer.setDaemon(true);
            startServer.start();
        }
        neverStarted = !core.isStarted();
        core.addLifecycleListener(new CoreLifecycleAdapter() {

            @Override
            public void started(Core core) {
                Main.neverStarted = false;
            }

            @Override
            public void stopping(Core core) {
                Main.stopping = true;
            }

            @Override
            public void stopped(Core core) {
                if (startServer != null) {
                    startServer.stopIt();
                }
                Main.stopped = true;
            }
        });
        for (IUserInterface ui : UIConst.UIS.values()) {
            ui.takeMainThread();
            if (stopping) {
                break;
            }
        }
        if (neverStarted) {
            if (DEBUG_STARTUPTIME) {
                logTime("takeMainThread");
            }
            core.start();
            if (DEBUG_STARTUPTIME) {
                logTime("coreStart");
            }
        }
        if (!stopping) {
            // no one took the main thread!
            while (!stopped) {
                try {
                    Thread.sleep(200);
                    // (not case "-u console,Swt")
                    if (newUI != null) {
                        IUserInterface threadTaker = newUI;
                        newUI = null;
                        threadTaker.takeMainThread();
                    }
                } catch (InterruptedException e) {
                }
            }
        }
    } catch (CoreException e) {
        System.out.println("Start fails:");
        e.printStackTrace();
    }
    if (DEBUG_STARTUPTIME) {
        logTime("DONE");
    }
}
Also used : CoreSingleInstanceClient(com.biglybt.core.impl.CoreSingleInstanceClient) CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) IUserInterface(com.biglybt.ui.common.IUserInterface) Builder(org.apache.commons.cli.Option.Builder) CoreException(com.biglybt.core.CoreException) StartServer(com.biglybt.ui.common.StartServer) Core(com.biglybt.core.Core)

Example 50 with Core

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

the class MySharesView method tableViewInitialized.

private void tableViewInitialized() {
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(Core core) {
            createRows(core);
        }
    });
    if (dropTarget == null) {
        dropTarget = tv.createDropTarget(DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_TARGET_MOVE);
        if (dropTarget != null) {
            dropTarget.setTransfer(new Transfer[] { FixedHTMLTransfer.getInstance(), FixedURLTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() });
            dropTarget.addDropListener(new DropTargetAdapter() {

                @Override
                public void drop(DropTargetEvent event) {
                    if (!share(event.data)) {
                        TorrentOpener.openDroppedTorrents(event, true);
                    }
                }
            });
        }
    }
}
Also used : CoreRunningListener(com.biglybt.core.CoreRunningListener) Core(com.biglybt.core.Core)

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