Search in sources :

Example 11 with Category

use of com.biglybt.core.category.Category 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 12 with Category

use of com.biglybt.core.category.Category in project BiglyBT by BiglySoftware.

the class CategoryUIUtils method showCreateCategoryDialog.

public static void showCreateCategoryDialog(final UIFunctions.TagReturner tagReturner) {
    SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("CategoryAddWindow.title", "CategoryAddWindow.message");
    entryWindow.setParentShell(Utils.findAnyShell());
    entryWindow.prompt(new UIInputReceiverListener() {

        @Override
        public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
            if (entryWindow.hasSubmittedInput()) {
                TagUIUtils.checkTagSharing(false);
                Category newCategory = CategoryManager.createCategory(entryWindow.getSubmittedInput());
                if (tagReturner != null) {
                    tagReturner.returnedTags(new Tag[] { newCategory });
                }
            }
        }
    });
}
Also used : Category(com.biglybt.core.category.Category) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) Tag(com.biglybt.core.tag.Tag)

Example 13 with Category

use of com.biglybt.core.category.Category in project BiglyBT by BiglySoftware.

the class MySharesView method addCategorySubMenu.

private void addCategorySubMenu() {
    MenuItem[] items = menuCategory.getItems();
    int i;
    for (i = 0; i < items.length; i++) {
        items[i].dispose();
    }
    Category[] categories = CategoryManager.getCategories();
    Arrays.sort(categories);
    if (categories.length > 0) {
        Category catUncat = CategoryManager.getCategory(Category.TYPE_UNCATEGORIZED);
        if (catUncat != null) {
            final MenuItem itemCategory = new MenuItem(menuCategory, SWT.PUSH);
            Messages.setLanguageText(itemCategory, catUncat.getName());
            itemCategory.setData("Category", catUncat);
            itemCategory.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    MenuItem item = (MenuItem) event.widget;
                    assignSelectedToCategory((Category) item.getData("Category"));
                }
            });
            new MenuItem(menuCategory, SWT.SEPARATOR);
        }
        for (i = 0; i < categories.length; i++) {
            if (categories[i].getType() == Category.TYPE_USER) {
                final MenuItem itemCategory = new MenuItem(menuCategory, SWT.PUSH);
                itemCategory.setText(categories[i].getName());
                itemCategory.setData("Category", categories[i]);
                itemCategory.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event event) {
                        MenuItem item = (MenuItem) event.widget;
                        assignSelectedToCategory((Category) item.getData("Category"));
                    }
                });
            }
        }
        new MenuItem(menuCategory, SWT.SEPARATOR);
    }
    final MenuItem itemAddCategory = new MenuItem(menuCategory, SWT.PUSH);
    Messages.setLanguageText(itemAddCategory, "MyTorrentsView.menu.setCategory.add");
    itemAddCategory.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            addCategory();
        }
    });
}
Also used : Category(com.biglybt.core.category.Category) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener) MdiEntryDropListener(com.biglybt.ui.mdi.MdiEntryDropListener) TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) CoreRunningListener(com.biglybt.core.CoreRunningListener)

Example 14 with Category

use of com.biglybt.core.category.Category in project BiglyBT by BiglySoftware.

the class MyTorrentsView method buildCatAndTag.

/**
 * @since 3.1.1.1
 */
private void buildCatAndTag(List<Tag> tags) {
    if (tags.size() == 0 || cCategoriesAndTags.isDisposed()) {
        return;
    }
    int iFontPixelsHeight = Utils.adjustPXForDPI(10);
    int iFontPointHeight = (iFontPixelsHeight * 72) / Utils.getDPIRaw(cCategoriesAndTags.getDisplay()).y;
    Label spacer = null;
    int max_rd_height = 0;
    allTags = tags;
    if (buttonListener == null) {
        buttonListener = new Listener() {

            boolean bDownPressed;

            private TimerEvent timerEvent;

            @Override
            public void handleEvent(Event event) {
                Button curButton = (Button) event.widget;
                if (event.type == SWT.MouseDown) {
                    if (timerEvent == null) {
                        timerEvent = SimpleTimer.addEvent("MouseHold", SystemTime.getOffsetTime(1000), new TimerEventPerformer() {

                            @Override
                            public void perform(TimerEvent te) {
                                timerEvent = null;
                                if (!bDownPressed) {
                                    return;
                                }
                                bDownPressed = false;
                                // held
                                Utils.execSWTThread(new Runnable() {

                                    public void run() {
                                        Object[] ds = tv.getSelectedDataSources().toArray();
                                        Tag tag = (Tag) curButton.getData("Tag");
                                        if (tag instanceof Category) {
                                            TorrentUtil.assignToCategory(ds, (Category) tag);
                                            return;
                                        }
                                        boolean doAdd = false;
                                        for (Object obj : ds) {
                                            if (obj instanceof DownloadManager) {
                                                DownloadManager dm = (DownloadManager) obj;
                                                if (!tag.hasTaggable(dm)) {
                                                    doAdd = true;
                                                    break;
                                                }
                                            }
                                        }
                                        for (Object obj : ds) {
                                            if (obj instanceof DownloadManager) {
                                                DownloadManager dm = (DownloadManager) obj;
                                                if (doAdd) {
                                                    tag.addTaggable(dm);
                                                } else {
                                                    tag.removeTaggable(dm);
                                                }
                                            }
                                        }
                                        setSelection(curButton.getParent());
                                        curButton.setEnabled(false);
                                        SimpleTimer.addEvent("ButtonEnable", SystemTime.getOffsetTime(10), new TimerEventPerformer() {

                                            @Override
                                            public void perform(TimerEvent te) {
                                                Utils.execSWTThread(new Runnable() {

                                                    public void run() {
                                                        curButton.setEnabled(true);
                                                    }
                                                });
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }
                    bDownPressed = true;
                    return;
                } else {
                    if (timerEvent != null) {
                        timerEvent.cancel();
                        timerEvent = null;
                    }
                    if (!bDownPressed) {
                        setSelection(curButton.getParent());
                        return;
                    }
                }
                bDownPressed = false;
                boolean add = (event.stateMask & SWT.MOD1) != 0;
                boolean isEnabled = curButton.getSelection();
                Tag tag = (Tag) curButton.getData("Tag");
                if (!isEnabled) {
                    removeTagFromCurrent(tag);
                } else {
                    if (add) {
                        Category catAll = CategoryManager.getCategory(Category.TYPE_ALL);
                        if (tag.equals(catAll)) {
                            setCurrentTags(new Tag[] { catAll });
                        } else {
                            Tag[] newTags = new Tag[currentTags.length + 1];
                            System.arraycopy(currentTags, 0, newTags, 0, currentTags.length);
                            newTags[currentTags.length] = tag;
                            newTags = (Tag[]) removeFromArray(newTags, catAll);
                            setCurrentTags(newTags);
                        }
                    } else {
                        setCurrentTags(new Tag[] { (Tag) curButton.getData("Tag") });
                    }
                }
                setSelection(curButton.getParent());
            }

            private void setSelection(Composite parent) {
                Control[] controls = parent.getChildren();
                for (int i = 0; i < controls.length; i++) {
                    if (!(controls[i] instanceof Button)) {
                        continue;
                    }
                    Button b = (Button) controls[i];
                    Tag btag = (Tag) b.getData("Tag");
                    b.setSelection(isCurrent(btag));
                }
            }
        };
        buttonHoverListener = new Listener() {

            @Override
            public void handleEvent(Event event) {
                Button curButton = (Button) event.widget;
                Tag tag = (Tag) curButton.getData("Tag");
                if (!(tag instanceof Category)) {
                    curButton.setToolTipText(TagUIUtils.getTagTooltip(tag, true));
                    return;
                }
                Category category = (Category) tag;
                List<DownloadManager> dms = category.getDownloadManagers(globalManager.getDownloadManagers());
                long ttlActive = 0;
                long ttlSize = 0;
                long ttlRSpeed = 0;
                long ttlSSpeed = 0;
                int count = 0;
                for (DownloadManager dm : dms) {
                    if (!category.hasTaggable(dm)) {
                        continue;
                    }
                    count++;
                    if (dm.getState() == DownloadManager.STATE_DOWNLOADING || dm.getState() == DownloadManager.STATE_SEEDING) {
                        ttlActive++;
                    }
                    DownloadManagerStats stats = dm.getStats();
                    ttlSize += stats.getSizeExcludingDND();
                    ttlRSpeed += stats.getDataReceiveRate();
                    ttlSSpeed += stats.getDataSendRate();
                }
                String up_details = "";
                String down_details = "";
                if (category.getType() != Category.TYPE_ALL) {
                    String up_str = MessageText.getString("GeneralView.label.maxuploadspeed");
                    String down_str = MessageText.getString("GeneralView.label.maxdownloadspeed");
                    String unlimited_str = MessageText.getString("MyTorrentsView.menu.setSpeed.unlimited");
                    int up_speed = category.getUploadSpeed();
                    int down_speed = category.getDownloadSpeed();
                    up_details = up_str + ": " + (up_speed == 0 ? unlimited_str : DisplayFormatters.formatByteCountToKiBEtc(up_speed));
                    down_details = down_str + ": " + (down_speed == 0 ? unlimited_str : DisplayFormatters.formatByteCountToKiBEtc(down_speed));
                }
                if (count == 0) {
                    curButton.setToolTipText(down_details + "\n" + up_details + "\nTotal: 0");
                    return;
                }
                curButton.setToolTipText((up_details.length() == 0 ? "" : (down_details + "\n" + up_details + "\n")) + "Total: " + count + "\n" + "Downloading/Seeding: " + ttlActive + "\n" + "\n" + "Total Speed: " + DisplayFormatters.formatByteCountToKiBEtcPerSec(ttlRSpeed) + " / " + DisplayFormatters.formatByteCountToKiBEtcPerSec(ttlSSpeed) + "\n" + "Average Speed: " + DisplayFormatters.formatByteCountToKiBEtcPerSec(ttlRSpeed / (ttlActive == 0 ? 1 : ttlActive)) + " / " + DisplayFormatters.formatByteCountToKiBEtcPerSec(ttlSSpeed / (ttlActive == 0 ? 1 : ttlActive)) + "\n" + "Size: " + DisplayFormatters.formatByteCountToKiBEtc(ttlSize));
            }
        };
        buttonDropTargetListener = new DropTargetAdapter() {

            @Override
            public void dragOver(DropTargetEvent e) {
                if (drag_drop_line_start >= 0) {
                    boolean doAdd = false;
                    Control curButton = ((DropTarget) e.widget).getControl();
                    Tag tag = (Tag) curButton.getData("Tag");
                    Object[] ds = tv.getSelectedDataSources().toArray();
                    if (tag != null) {
                        for (Object obj : ds) {
                            if (obj instanceof DownloadManager) {
                                DownloadManager dm = (DownloadManager) obj;
                                if (!tag.hasTaggable(dm)) {
                                    doAdd = true;
                                    break;
                                }
                            }
                        }
                    }
                    e.detail = doAdd ? DND.DROP_COPY : DND.DROP_MOVE;
                } else {
                    e.detail = DND.DROP_NONE;
                }
            }

            @Override
            public void drop(DropTargetEvent e) {
                e.detail = DND.DROP_NONE;
                if (drag_drop_line_start >= 0) {
                    drag_drop_line_start = -1;
                    drag_drop_rows = null;
                    Object[] ds = tv.getSelectedDataSources().toArray();
                    Control curButton = ((DropTarget) e.widget).getControl();
                    Tag tag = (Tag) curButton.getData("Tag");
                    if (tag instanceof Category) {
                        TorrentUtil.assignToCategory(ds, (Category) tag);
                        return;
                    }
                    boolean doAdd = false;
                    for (Object obj : ds) {
                        if (obj instanceof DownloadManager) {
                            DownloadManager dm = (DownloadManager) obj;
                            if (!tag.hasTaggable(dm)) {
                                doAdd = true;
                                break;
                            }
                        }
                    }
                    for (Object obj : ds) {
                        if (obj instanceof DownloadManager) {
                            DownloadManager dm = (DownloadManager) obj;
                            if (doAdd) {
                                tag.addTaggable(dm);
                            } else {
                                tag.removeTaggable(dm);
                            }
                        }
                    }
                }
            }
        };
    }
    for (final Tag tag : tags) {
        boolean isCat = (tag instanceof Category);
        final Button button = new Button(cCategoriesAndTags, SWT.TOGGLE);
        if (isCat) {
            if (spacer == null) {
                spacer = new Label(cCategoriesAndTags, SWT.NONE);
                RowData rd = new RowData();
                rd.width = 8;
                spacer.setLayoutData(rd);
                spacer.moveAbove(null);
            }
            button.moveAbove(spacer);
        }
        button.addKeyListener(this);
        if (fontButton == null) {
            Font f = button.getFont();
            FontData fd = f.getFontData()[0];
            fd.setHeight(iFontPointHeight);
            fontButton = new Font(cCategoriesAndTags.getDisplay(), fd);
        }
        button.setText("|");
        button.setFont(fontButton);
        button.pack(true);
        if (button.computeSize(100, SWT.DEFAULT).y > 0) {
            RowData rd = new RowData();
            int rd_height = button.computeSize(100, SWT.DEFAULT).y - 2 + button.getBorderWidth() * 2;
            rd.height = rd_height;
            max_rd_height = Math.max(max_rd_height, rd_height);
            button.setLayoutData(rd);
        }
        String tag_name = tag.getTagName(true);
        button.setText(tag_name);
        button.setData("Tag", tag);
        if (isCurrent(tag)) {
            button.setSelection(true);
        }
        button.addListener(SWT.MouseUp, buttonListener);
        button.addListener(SWT.MouseDown, buttonListener);
        button.addListener(SWT.MouseHover, buttonHoverListener);
        final DropTarget tabDropTarget = new DropTarget(button, DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
        Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
        tabDropTarget.setTransfer(types);
        tabDropTarget.addDropListener(buttonDropTargetListener);
        button.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                if (!tabDropTarget.isDisposed()) {
                    tabDropTarget.dispose();
                }
            }
        });
        Menu menu = new Menu(button);
        button.setMenu(menu);
        if (isCat) {
            CategoryUIUtils.setupCategoryMenu(menu, (Category) tag);
        } else {
            TagUIUtils.createSideBarMenuItems(menu, tag);
        }
    }
    if (max_rd_height > 0) {
        RowLayout layout = (RowLayout) cCategoriesAndTags.getLayout();
        int top_margin = (24 - max_rd_height + 1) / 2;
        if (top_margin > 0) {
            layout.marginTop = top_margin;
        }
    }
    cCategoriesAndTags.getParent().layout(true, true);
}
Also used : ParameterListener(com.biglybt.core.config.ParameterListener) TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) DownloadManagerListener(com.biglybt.core.download.DownloadManagerListener) UIToolBarActivationListener(com.biglybt.pif.ui.toolbar.UIToolBarActivationListener) GlobalManagerListener(com.biglybt.core.global.GlobalManagerListener) TableRowRefreshListener(com.biglybt.pif.ui.tables.TableRowRefreshListener) GlobalManagerEventListener(com.biglybt.core.global.GlobalManagerEventListener) Category(com.biglybt.core.category.Category) DownloadManager(com.biglybt.core.download.DownloadManager) RowData(org.eclipse.swt.layout.RowData) RowLayout(org.eclipse.swt.layout.RowLayout) List(java.util.List) DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats) SWTRunnable(com.biglybt.ui.swt.utils.SWTRunnable) FixedURLTransfer(com.biglybt.ui.swt.FixedURLTransfer) GlobalManagerEvent(com.biglybt.core.global.GlobalManagerEvent) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) LogEvent(com.biglybt.core.logging.LogEvent)

Example 15 with Category

use of com.biglybt.core.category.Category in project BiglyBT by BiglySoftware.

the class MyTrackerView method addCategorySubMenu.

private void addCategorySubMenu() {
    MenuItem[] items = menuCategory.getItems();
    int i;
    for (i = 0; i < items.length; i++) {
        items[i].dispose();
    }
    Category[] categories = CategoryManager.getCategories();
    Arrays.sort(categories);
    if (categories.length > 0) {
        Category catUncat = CategoryManager.getCategory(Category.TYPE_UNCATEGORIZED);
        if (catUncat != null) {
            final MenuItem itemCategory = new MenuItem(menuCategory, SWT.PUSH);
            Messages.setLanguageText(itemCategory, catUncat.getName());
            itemCategory.setData("Category", catUncat);
            itemCategory.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    MenuItem item = (MenuItem) event.widget;
                    assignSelectedToCategory((Category) item.getData("Category"));
                }
            });
            new MenuItem(menuCategory, SWT.SEPARATOR);
        }
        for (i = 0; i < categories.length; i++) {
            if (categories[i].getType() == Category.TYPE_USER) {
                final MenuItem itemCategory = new MenuItem(menuCategory, SWT.PUSH);
                itemCategory.setText(categories[i].getName());
                itemCategory.setData("Category", categories[i]);
                itemCategory.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event event) {
                        MenuItem item = (MenuItem) event.widget;
                        assignSelectedToCategory((Category) item.getData("Category"));
                    }
                });
            }
        }
        new MenuItem(menuCategory, SWT.SEPARATOR);
    }
    final MenuItem itemAddCategory = new MenuItem(menuCategory, SWT.PUSH);
    Messages.setLanguageText(itemAddCategory, "MyTorrentsView.menu.setCategory.add");
    itemAddCategory.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            addCategory();
        }
    });
}
Also used : Category(com.biglybt.core.category.Category) CategoryManagerListener(com.biglybt.core.category.CategoryManagerListener) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener) TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) Listener(org.eclipse.swt.widgets.Listener) TRHostListener(com.biglybt.core.tracker.host.TRHostListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) Event(org.eclipse.swt.widgets.Event) MenuItem(org.eclipse.swt.widgets.MenuItem)

Aggregations

Category (com.biglybt.core.category.Category)22 DownloadManager (com.biglybt.core.download.DownloadManager)10 CoreRunningListener (com.biglybt.core.CoreRunningListener)4 TableViewSWTMenuFillListener (com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener)4 CategoryManagerListener (com.biglybt.core.category.CategoryManagerListener)3 Tag (com.biglybt.core.tag.Tag)3 UIPluginViewToolBarListener (com.biglybt.pif.ui.UIPluginViewToolBarListener)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Core (com.biglybt.core.Core)2 CategoryListener (com.biglybt.core.category.CategoryListener)2 ParameterListener (com.biglybt.core.config.ParameterListener)2 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)2 DownloadManagerStats (com.biglybt.core.download.DownloadManagerStats)2 GlobalManager (com.biglybt.core.global.GlobalManager)2 GlobalManagerAdapter (com.biglybt.core.global.GlobalManagerAdapter)2 LogEvent (com.biglybt.core.logging.LogEvent)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 PluginInterface (com.biglybt.pif.PluginInterface)2 DownloadManagerListener (com.biglybt.core.download.DownloadManagerListener)1