Search in sources :

Example 1 with IpFilter

use of com.biglybt.core.ipfilter.IpFilter in project BiglyBT by BiglySoftware.

the class MainStatusBar method updateIPBlocked.

/**
 * @since 3.1.1.1
 */
private void updateIPBlocked() {
    if (!CoreFactory.isCoreRunning()) {
        return;
    }
    Core core = CoreFactory.getSingleton();
    // IP Filter Status Section
    IpFilter ip_filter = core.getIpFilterManager().getIPFilter();
    ipBlocked.setForeground(display.getSystemColor(ip_filter.isEnabled() ? SWT.COLOR_WIDGET_FOREGROUND : SWT.COLOR_WIDGET_NORMAL_SHADOW));
    ipBlocked.setText("IPs: " + numberFormat.format(ip_filter.getNbRanges()) + " - " + numberFormat.format(ip_filter.getNbIpsBlockedAndLoggable()) + "/" + numberFormat.format(ip_filter.getNbBannedIps()) + "/" + numberFormat.format(core.getIpFilterManager().getBadIps().getNbBadIps()));
    ipBlocked.setToolTipText(MessageText.getString("MainWindow.IPs.tooltip", new String[] { ip_filter.isEnabled() ? DisplayFormatters.formatDateShort(ip_filter.getLastUpdateTime()) : MessageText.getString("ipfilter.disabled") }));
}
Also used : IpFilter(com.biglybt.core.ipfilter.IpFilter) Core(com.biglybt.core.Core)

Example 2 with IpFilter

use of com.biglybt.core.ipfilter.IpFilter in project BiglyBT by BiglySoftware.

the class CacheDiscovery method initialise.

public static void initialise(final DownloadManagerEnhancer dme) {
    ip_filter.addListener(new IPFilterListener() {

        @Override
        public void IPFilterEnabledChanged(boolean is_enabled) {
        }

        @Override
        public boolean canIPBeBanned(String ip) {
            return (canBan(ip));
        }

        @Override
        public void IPBanned(BannedIp ip) {
        }

        @Override
        public void IPBlockedListChanged(IpFilter filter) {
        }

        @Override
        public boolean canIPBeBlocked(String ip, byte[] torrent_hash) {
            EnhancedDownloadManager dm = dme.getEnhancedDownload(torrent_hash);
            if (dm == null) {
                return (true);
            }
            return (true);
        }
    });
    new AEThread2("CacheDiscovery:ban checker", true) {

        @Override
        public void run() {
            BannedIp[] bans = ip_filter.getBannedIps();
            for (int i = 0; i < bans.length; i++) {
                String ip = bans[i].getIp();
                if (!canBan(ip)) {
                    ip_filter.unban(ip);
                }
            }
        }
    }.start();
}
Also used : IpFilter(com.biglybt.core.ipfilter.IpFilter) BannedIp(com.biglybt.core.ipfilter.BannedIp) IPFilterListener(com.biglybt.core.ipfilter.IPFilterListener) EnhancedDownloadManager(com.biglybt.core.download.EnhancedDownloadManager)

Example 3 with IpFilter

use of com.biglybt.core.ipfilter.IpFilter in project BiglyBT by BiglySoftware.

the class PeersViewBase method fillMenu.

private static void fillMenu(final Menu menu, final PEPeer[] peers, final Shell shell, DownloadManager download_specific) {
    boolean hasSelection = (peers.length > 0);
    boolean downSpeedDisabled = false;
    boolean downSpeedUnlimited = false;
    long totalDownSpeed = 0;
    long downSpeedSetMax = 0;
    long maxDown = 0;
    boolean upSpeedDisabled = false;
    boolean upSpeedUnlimited = false;
    long totalUpSpeed = 0;
    long upSpeedSetMax = 0;
    long maxUp = 0;
    GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
    final IdentityHashSet<DownloadManager> download_managers = new IdentityHashSet<>();
    Map<PEPeer, DownloadManager> peer_dm_map = new HashMap<>();
    if (hasSelection) {
        for (int i = 0; i < peers.length; i++) {
            PEPeer peer = peers[i];
            PEPeerManager m = peer.getManager();
            if (m != null) {
                if (gm != null) {
                    DownloadManager dm = gm.getDownloadManager(new HashWrapper(m.getHash()));
                    if (dm != null) {
                        peer_dm_map.put(peer, dm);
                        download_managers.add(dm);
                    }
                }
            }
            try {
                int maxul = peer.getStats().getUploadRateLimitBytesPerSecond();
                maxUp += maxul * 4;
                if (maxul == 0) {
                    upSpeedUnlimited = true;
                } else {
                    if (maxul > upSpeedSetMax) {
                        upSpeedSetMax = maxul;
                    }
                }
                if (maxul == -1) {
                    maxul = 0;
                    upSpeedDisabled = true;
                }
                totalUpSpeed += maxul;
                int maxdl = peer.getStats().getDownloadRateLimitBytesPerSecond();
                maxDown += maxdl * 4;
                if (maxdl == 0) {
                    downSpeedUnlimited = true;
                } else {
                    if (maxdl > downSpeedSetMax) {
                        downSpeedSetMax = maxdl;
                    }
                }
                if (maxdl == -1) {
                    maxdl = 0;
                    downSpeedDisabled = true;
                }
                totalDownSpeed += maxdl;
            } catch (Exception ex) {
                Debug.printStackTrace(ex);
            }
        }
    }
    if (download_specific != null) {
        final MenuItem block_item = new MenuItem(menu, SWT.CHECK);
        PEPeer peer = peers.length == 0 ? null : peers[0];
        if (peer == null || peer.getManager().getDiskManager().getRemainingExcludingDND() > 0) {
            // disallow peer upload blocking when downloading
            block_item.setSelection(false);
            block_item.setEnabled(false);
        } else {
            block_item.setEnabled(true);
            block_item.setSelection(peer.isSnubbed());
        }
        if (peer != null) {
            final boolean newSnubbedValue = !peer.isSnubbed();
            Messages.setLanguageText(block_item, "PeersView.menu.blockupload");
            block_item.addListener(SWT.Selection, new PeersRunner(peers) {

                @Override
                public void run(PEPeer peer) {
                    peer.setSnubbed(newSnubbedValue);
                }
            });
        }
    } else {
        if (download_managers.size() > 0) {
            MenuItem itemDetails = new MenuItem(menu, SWT.PUSH);
            Messages.setLanguageText(itemDetails, "PeersView.menu.showdownload");
            Utils.setMenuItemImage(itemDetails, "details");
            itemDetails.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                    if (uiFunctions != null) {
                        for (DownloadManager dm : download_managers) {
                            uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, dm);
                        }
                    }
                }
            });
            new MenuItem(menu, SWT.SEPARATOR);
        }
    }
    BuddyPlugin bp = BuddyPluginUtils.getPlugin();
    if (bp != null) {
        boolean has_pb = false;
        boolean has_public = false;
        for (PEPeer peer : peers) {
            if (AENetworkClassifier.categoriseAddress(peer.getIp()) == AENetworkClassifier.AT_PUBLIC) {
                has_public = true;
                DownloadManager dm = peer_dm_map.get(peer);
                if (dm != null && bp.isPartialBuddy(PluginCoreUtils.wrap(dm), PluginCoreUtils.wrap(peer))) {
                    has_pb = true;
                }
            }
        }
        MenuItem boost_item = new MenuItem(menu, SWT.CHECK);
        Messages.setLanguageText(boost_item, "PeersView.menu.boost");
        boost_item.setSelection(has_pb);
        boost_item.setEnabled(has_public);
        boost_item.addListener(SWT.Selection, new PeersRunner(peers) {

            @Override
            public void run(PEPeer peer) {
                boolean sel = boost_item.getSelection();
                if (AENetworkClassifier.categoriseAddress(peer.getIp()) == AENetworkClassifier.AT_PUBLIC) {
                    DownloadManager dm = peer_dm_map.get(peer);
                    if (dm != null) {
                        bp.setPartialBuddy(PluginCoreUtils.wrap(dm), PluginCoreUtils.wrap(peer), sel);
                    }
                }
            }
        });
    }
    final MenuItem kick_item = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(kick_item, "PeersView.menu.kick");
    kick_item.addListener(SWT.Selection, new PeersRunner(peers) {

        @Override
        public void run(PEPeer peer) {
            peer.getManager().removePeer(peer, "Peer kicked");
        }
    });
    final MenuItem ban_item = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(ban_item, "PeersView.menu.kickandban");
    ban_item.addListener(SWT.Selection, new PeersRunner(peers) {

        @Override
        public void run(PEPeer peer) {
            String msg = MessageText.getString("PeersView.menu.kickandban.reason");
            IpFilterManagerFactory.getSingleton().getIPFilter().ban(peer.getIp(), msg, true);
            peer.getManager().removePeer(peer, "Peer kicked and banned");
        }
    });
    final MenuItem ban_for_item = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(ban_for_item, "PeersView.menu.kickandbanfor");
    ban_for_item.addListener(SWT.Selection, new PeersRunner(peers) {

        @Override
        public boolean run(final PEPeer[] peers) {
            String text = MessageText.getString("dialog.ban.for.period.text");
            SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("dialog.ban.for.period.title", "!" + text + "!");
            int def = COConfigurationManager.getIntParameter("ban.for.period.default", 60);
            entryWindow.setPreenteredText(String.valueOf(def), false);
            entryWindow.prompt(new UIInputReceiverListener() {

                @Override
                public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
                    if (!entryWindow.hasSubmittedInput()) {
                        return;
                    }
                    String sReturn = entryWindow.getSubmittedInput();
                    if (sReturn == null) {
                        return;
                    }
                    int mins = -1;
                    try {
                        mins = Integer.valueOf(sReturn).intValue();
                    } catch (NumberFormatException er) {
                    // Ignore
                    }
                    if (mins <= 0) {
                        MessageBox mb = new MessageBox(Utils.findAnyShell(), SWT.ICON_ERROR | SWT.OK);
                        mb.setText(MessageText.getString("MyTorrentsView.dialog.NumberError.title"));
                        mb.setMessage(MessageText.getString("MyTorrentsView.dialog.NumberError.text"));
                        mb.open();
                        return;
                    }
                    COConfigurationManager.setParameter("ban.for.period.default", mins);
                    IpFilter filter = IpFilterManagerFactory.getSingleton().getIPFilter();
                    for (PEPeer peer : peers) {
                        String msg = MessageText.getString("PeersView.menu.kickandbanfor.reason", new String[] { String.valueOf(mins) });
                        filter.ban(peer.getIp(), msg, true, mins);
                        peer.getManager().removePeer(peer, "Peer kicked and banned");
                    }
                }
            });
            return (true);
        }
    });
    // === advanced menu ===
    final MenuItem itemAdvanced = new MenuItem(menu, SWT.CASCADE);
    Messages.setLanguageText(itemAdvanced, "MyTorrentsView.menu.advancedmenu");
    itemAdvanced.setEnabled(hasSelection);
    final Menu menuAdvanced = new Menu(shell, SWT.DROP_DOWN);
    itemAdvanced.setMenu(menuAdvanced);
    // advanced > Download Speed Menu //
    Map<String, Object> menu_properties = new HashMap<>();
    menu_properties.put(ViewUtils.SM_PROP_PERMIT_UPLOAD_DISABLE, true);
    menu_properties.put(ViewUtils.SM_PROP_PERMIT_DOWNLOAD_DISABLE, true);
    ViewUtils.addSpeedMenu(shell, menuAdvanced, true, true, false, hasSelection, downSpeedDisabled, downSpeedUnlimited, totalDownSpeed, downSpeedSetMax, maxDown, upSpeedDisabled, upSpeedUnlimited, totalUpSpeed, upSpeedSetMax, maxUp, peers.length, menu_properties, new ViewUtils.SpeedAdapter() {

        @Override
        public void setDownSpeed(int speed) {
            if (peers.length > 0) {
                for (int i = 0; i < peers.length; i++) {
                    try {
                        PEPeer peer = (PEPeer) peers[i];
                        peer.getStats().setDownloadRateLimitBytesPerSecond(speed);
                    } catch (Exception e) {
                        Debug.printStackTrace(e);
                    }
                }
            }
        }

        @Override
        public void setUpSpeed(int speed) {
            if (peers.length > 0) {
                for (int i = 0; i < peers.length; i++) {
                    try {
                        PEPeer peer = (PEPeer) peers[i];
                        peer.getStats().setUploadRateLimitBytesPerSecond(speed);
                    } catch (Exception e) {
                        Debug.printStackTrace(e);
                    }
                }
            }
        }
    });
    addPeersMenu(download_specific, "", menu);
}
Also used : IdentityHashSet(com.biglybt.core.util.IdentityHashSet) PEPeer(com.biglybt.core.peer.PEPeer) IpFilter(com.biglybt.core.ipfilter.IpFilter) SelectionListener(org.eclipse.swt.events.SelectionListener) TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) Listener(org.eclipse.swt.widgets.Listener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) TableSelectionListener(com.biglybt.ui.common.table.TableSelectionListener) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) TableLifeCycleListener(com.biglybt.ui.common.table.TableLifeCycleListener) HashMap(java.util.HashMap) DownloadManager(com.biglybt.core.download.DownloadManager) BuddyPlugin(com.biglybt.plugin.net.buddy.BuddyPlugin) GlobalManager(com.biglybt.core.global.GlobalManager) UIFunctions(com.biglybt.ui.UIFunctions) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) Menu(org.eclipse.swt.widgets.Menu) MenuItem(org.eclipse.swt.widgets.MenuItem) MessageBox(org.eclipse.swt.widgets.MessageBox) HashWrapper(com.biglybt.core.util.HashWrapper) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PEPeerManager(com.biglybt.core.peer.PEPeerManager) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Example 4 with IpFilter

use of com.biglybt.core.ipfilter.IpFilter 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)

Aggregations

IpFilter (com.biglybt.core.ipfilter.IpFilter)4 Core (com.biglybt.core.Core)2 GlobalManager (com.biglybt.core.global.GlobalManager)2 UIFunctions (com.biglybt.ui.UIFunctions)2 CoreRunningListener (com.biglybt.core.CoreRunningListener)1 ParameterListener (com.biglybt.core.config.ParameterListener)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 EnhancedDownloadManager (com.biglybt.core.download.EnhancedDownloadManager)1 BannedIp (com.biglybt.core.ipfilter.BannedIp)1 IPFilterListener (com.biglybt.core.ipfilter.IPFilterListener)1 LogAlert (com.biglybt.core.logging.LogAlert)1 PEPeer (com.biglybt.core.peer.PEPeer)1 PEPeerManager (com.biglybt.core.peer.PEPeerManager)1 OverallStats (com.biglybt.core.stats.transfer.OverallStats)1 HashWrapper (com.biglybt.core.util.HashWrapper)1 IdentityHashSet (com.biglybt.core.util.IdentityHashSet)1 UIInputReceiver (com.biglybt.pif.ui.UIInputReceiver)1 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)1 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)1 BuddyPlugin (com.biglybt.plugin.net.buddy.BuddyPlugin)1