Search in sources :

Example 61 with Core

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

the class TorrentMenuFancy method buildTorrentCustomMenu_Control.

public void buildTorrentCustomMenu_Control(final Composite cParent, final DownloadManager[] dms) {
    final int userMode = COConfigurationManager.getIntParameter("User Mode");
    boolean start = false;
    boolean stop = false;
    boolean pause = false;
    boolean recheck = false;
    boolean barsOpened = true;
    boolean bChangeDir = hasSelection;
    for (int i = 0; i < dms.length; i++) {
        DownloadManager dm = dms[i];
        if (barsOpened && !DownloadBar.getManager().isOpen(dm)) {
            barsOpened = false;
        }
        stop = stop || ManagerUtils.isStopable(dm);
        start = start || ManagerUtils.isStartable(dm);
        pause = pause || ManagerUtils.isPauseable(dm);
        recheck = recheck || dm.canForceRecheck();
        boolean stopped = ManagerUtils.isStopped(dm);
        int state = dm.getState();
        bChangeDir &= (state == DownloadManager.STATE_ERROR || state == DownloadManager.STATE_STOPPED || state == DownloadManager.STATE_QUEUED);
        /**
         * Only perform a test on disk if:
         *    1) We are currently set to allow the "Change Data Directory" option, and
         *    2) We've only got one item selected - otherwise, we may potentially end up checking massive
         *       amounts of files across multiple torrents before we generate a menu.
         */
        if (bChangeDir && dms.length == 1) {
            bChangeDir = dm.isDataAlreadyAllocated();
            if (bChangeDir && state == DownloadManager.STATE_ERROR) {
                // filesExist is way too slow!
                bChangeDir = !dm.filesExist(true);
            } else {
                DiskManagerFileInfo[] files = dm.getDiskManagerFileInfoSet().getFiles();
                bChangeDir = false;
                for (DiskManagerFileInfo info : files) {
                    if (info.isSkipped()) {
                        continue;
                    }
                    bChangeDir = !info.getFile(true).exists();
                    break;
                }
            }
        }
    }
    Composite cQuickCommands = new Composite(cParent, SWT.NONE);
    // cQuickCommands.setBackground(ColorCache.getRandomColor());
    RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
    rowLayout.justify = true;
    rowLayout.marginLeft = 0;
    rowLayout.marginRight = 0;
    cQuickCommands.setLayout(rowLayout);
    GridData gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    Utils.setLayoutData(cQuickCommands, gd);
    // Queue
    createActionButton(dms, cQuickCommands, "MyTorrentsView.menu.queue", "start", start, new ListenerGetOffSWT() {

        @Override
        void handleEventOffSWT(Event event) {
            TorrentUtil.queueDataSources(dms, true);
        }
    });
    // Force Start
    if (userMode > 0) {
        boolean forceStart = false;
        boolean forceStartEnabled = false;
        for (int i = 0; i < dms.length; i++) {
            DownloadManager dm = dms[i];
            forceStartEnabled = forceStartEnabled || ManagerUtils.isForceStartable(dm);
            forceStart = forceStart || dm.isForceStart();
        }
        final boolean newForceStart = !forceStart;
        createActionButton(dms, cQuickCommands, "MyTorrentsView.menu.forceStart", "forcestart", forceStartEnabled, forceStart ? SWT.BORDER : SWT.PUSH, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager dm) {
                if (ManagerUtils.isForceStartable(dm)) {
                    dm.setForceStart(newForceStart);
                }
            }
        });
    }
    // Pause
    if (userMode > 0) {
        createActionButton(dms, cQuickCommands, "v3.MainWindow.button.pause", "pause", pause, new ListenerGetOffSWT() {

            @Override
            public void handleEventOffSWT(Event event) {
                TorrentUtil.pauseDataSources(dms);
            }
        });
    }
    // Stop
    createActionButton(dms, cQuickCommands, "MyTorrentsView.menu.stop", "stop", stop, new ListenerGetOffSWT() {

        @Override
        public void handleEventOffSWT(Event event) {
            TorrentUtil.stopDataSources(dms);
        }
    });
    // Force Recheck
    createActionButton(dms, cQuickCommands, "MyTorrentsView.menu.recheck", "recheck", recheck, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager dm) {
            if (dm.canForceRecheck()) {
                dm.forceRecheck();
            }
        }
    });
    // Delete
    createActionButton(dms, cQuickCommands, "menu.delete.options", "delete", hasSelection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            TorrentUtil.removeDownloads(dms, null, true);
        }
    });
    if (bChangeDir) {
        createRow(cParent, "MyTorrentsView.menu.changeDirectory", null, new Listener() {

            @Override
            public void handleEvent(Event e) {
                TorrentUtil.changeDirSelectedTorrents(dms, parentShell);
            }
        });
    }
    // Open Details
    if (hasSelection) {
        createRow(cParent, "MyTorrentsView.menu.showdetails", "details", new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager dm) {
                UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                if (uiFunctions != null) {
                    uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, dm);
                }
            }
        });
    }
    // Open Bar
    if (hasSelection) {
        FancyRowInfo row = createRow(cParent, "MyTorrentsView.menu.showdownloadbar", "downloadBar", new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager dm) {
                if (DownloadBar.getManager().isOpen(dm)) {
                    DownloadBar.close(dm);
                } else {
                    DownloadBar.open(dm, parentShell);
                }
            }
        });
        row.setSelection(barsOpened);
    }
    if (hasSelection) {
        FancyRowInfo rowSpeedDL = createRow(cParent, "MyTorrentsView.menu.downSpeedLimit", "image.torrentspeed.down", false, new Listener() {

            @Override
            public void handleEvent(Event e) {
                Event event = new Event();
                event.type = SWT.MouseUp;
                event.widget = e.widget;
                event.stateMask = e.stateMask;
                event.button = e.button;
                e.display.post(event);
                Core core = CoreFactory.getSingleton();
                SelectableSpeedMenu.invokeSlider((Control) event.widget, core, dms, false, shell);
                if (e.display.getActiveShell() != shell) {
                    if (!shell.isDisposed()) {
                        shell.dispose();
                    }
                    return;
                }
                FancyRowInfo rowInfo = findRowInfo(event.widget);
                if (rowInfo != null) {
                    updateRowSpeed(rowInfo, false);
                }
            }
        });
        rowSpeedDL.keepMenu = true;
        updateRowSpeed(rowSpeedDL, false);
    }
    if (hasSelection) {
        FancyRowInfo rowSpeedUL = createRow(cParent, "MyTorrentsView.menu.upSpeedLimit", "image.torrentspeed.up", false, new Listener() {

            @Override
            public void handleEvent(Event e) {
                Event event = new Event();
                event.type = SWT.MouseUp;
                event.widget = e.widget;
                event.stateMask = e.stateMask;
                event.button = e.button;
                e.display.post(event);
                Core core = CoreFactory.getSingleton();
                SelectableSpeedMenu.invokeSlider((Control) e.widget, core, dms, true, shell);
                if (e.display.getActiveShell() != shell) {
                    if (!shell.isDisposed()) {
                        shell.dispose();
                    }
                    return;
                }
                FancyRowInfo rowInfo = findRowInfo(event.widget);
                if (rowInfo != null) {
                    updateRowSpeed(rowInfo, true);
                }
            }
        });
        rowSpeedUL.keepMenu = true;
        updateRowSpeed(rowSpeedUL, true);
    }
    if (hasSelection && userMode > 0) {
        createMenuRow(cParent, "MyTorrentsView.menu.tracker", null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu menu) {
                boolean changeUrl = hasSelection;
                boolean manualUpdate = true;
                boolean allStopped = true;
                boolean canMove = true;
                int userMode = COConfigurationManager.getIntParameter("User Mode");
                final boolean use_open_containing_folder = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
                for (DownloadManager dm : dms) {
                    boolean stopped = ManagerUtils.isStopped(dm);
                    allStopped &= stopped;
                    canMove = canMove && dm.canMoveDataFiles();
                    if (userMode < 2) {
                        TRTrackerAnnouncer trackerClient = dm.getTrackerClient();
                        if (trackerClient != null) {
                            boolean update_state = ((SystemTime.getCurrentTime() / 1000 - trackerClient.getLastUpdateTime() >= TRTrackerAnnouncer.REFRESH_MINIMUM_SECS));
                            manualUpdate = manualUpdate & update_state;
                        }
                    }
                }
                TorrentUtil.addTrackerTorrentMenu(menu, dms, changeUrl, manualUpdate, allStopped, use_open_containing_folder, canMove);
            }
        });
    }
    if (hasSelection) {
        Core core = CoreFactory.getSingleton();
        SpeedLimitHandler slh = SpeedLimitHandler.getSingleton(core);
        if (slh.hasAnyProfiles()) {
            createMenuRow(cParent, IMenuConstants.MENU_ID_SPEED_LIMITS, null, new FancyMenuRowInfoListener() {

                @Override
                public void buildMenu(Menu menu) {
                    TorrentUtil.addSpeedLimitsMenu(dms, menu);
                }
            });
        }
    }
    if (userMode > 0 && hasSelection) {
        boolean can_pause = false;
        for (int i = 0; i < dms.length; i++) {
            DownloadManager dm = dms[i];
            if (ManagerUtils.isPauseable(dm)) {
                can_pause = true;
                break;
            }
        }
        if (can_pause) {
            createRow(detailArea, "MainWindow.menu.transfers.pausetransfersfor", null, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    TorrentUtil.pauseDownloadsFor(dms);
                }
            });
        }
    }
    if (userMode > 0 && dms.length > 1) {
        createRow(cParent, "label.options.and.info", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                if (uiFunctions != null) {
                    uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, dms);
                }
            }
        });
    }
    if (userMode > 0) {
        createMenuRow(cParent, "MyTorrentsView.menu.peersource", null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu menu) {
                TorrentUtil.addPeerSourceSubMenu(dms, menu);
            }
        });
    }
    // Sequential download
    {
        boolean allSeq = true;
        boolean AllNonSeq = true;
        for (int j = 0; j < dms.length; j++) {
            DownloadManager dm = dms[j];
            boolean seq = dm.getDownloadState().getFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD);
            if (seq) {
                AllNonSeq = false;
            } else {
                allSeq = false;
            }
        }
        boolean bChecked;
        if (allSeq) {
            bChecked = true;
        } else if (AllNonSeq) {
            bChecked = false;
        } else {
            bChecked = false;
        }
        final boolean newSeq = !bChecked;
        FancyRowInfo row = createRow(cParent, "menu.sequential.download", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager dm) {
                dm.getDownloadState().setFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD, newSeq);
            }
        });
        row.setSelection(bChecked);
    }
    // IP Filter Enable
    if (userMode > 0 && IpFilterManagerFactory.getSingleton().getIPFilter().isEnabled()) {
        boolean allEnabled = true;
        boolean allDisabled = true;
        for (int j = 0; j < dms.length; j++) {
            DownloadManager dm = dms[j];
            boolean filterDisabled = dm.getDownloadState().getFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER);
            if (filterDisabled) {
                allEnabled = false;
            } else {
                allDisabled = false;
            }
        }
        boolean bChecked;
        if (allEnabled) {
            bChecked = true;
        } else if (allDisabled) {
            bChecked = false;
        } else {
            bChecked = false;
        }
        final boolean newDisable = bChecked;
        FancyRowInfo row = createRow(cParent, "MyTorrentsView.menu.ipf_enable", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager dm) {
                dm.getDownloadState().setFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER, newDisable);
            }
        });
        row.setSelection(bChecked);
    }
    if (userMode > 1) {
        createMenuRow(cParent, "MyTorrentsView.menu.networks", null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu menu) {
                TorrentUtil.addNetworksSubMenu(dms, menu);
            }
        });
    }
    // Advanced menu with stuff I don't know where to put
    if (userMode > 0) {
        createMenuRow(cParent, "MyTorrentsView.menu.advancedmenu", null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu menu) {
                boolean allStopped = true;
                boolean allScanSelected = true;
                boolean allScanNotSelected = true;
                boolean fileMove = true;
                boolean allResumeIncomplete = true;
                boolean hasClearableLinks = false;
                boolean hasRevertableFiles = false;
                for (DownloadManager dm : dms) {
                    boolean stopped = ManagerUtils.isStopped(dm);
                    allStopped &= stopped;
                    fileMove = fileMove && dm.canMoveDataFiles();
                    boolean scan = dm.getDownloadState().getFlag(DownloadManagerState.FLAG_SCAN_INCOMPLETE_PIECES);
                    // include DND files in incomplete stat, since a recheck may
                    // find those files have been completed
                    boolean incomplete = !dm.isDownloadComplete(true);
                    allScanSelected = incomplete && allScanSelected && scan;
                    allScanNotSelected = incomplete && allScanNotSelected && !scan;
                    DownloadManagerState dms = dm.getDownloadState();
                    if (dms.isResumeDataComplete()) {
                        allResumeIncomplete = false;
                    }
                    if (stopped && !hasClearableLinks) {
                        if (dm.getDiskManagerFileInfoSet().nbFiles() > 1) {
                            if (dms.getFileLinks().hasLinks()) {
                                hasClearableLinks = true;
                            }
                        }
                    }
                    if (dm.getDownloadState().getFileLinks().size() > 0) {
                        hasRevertableFiles = true;
                    }
                }
                boolean fileRescan = allScanSelected || allScanNotSelected;
                final MenuItem itemFileRescan = new MenuItem(menu, SWT.CHECK);
                Messages.setLanguageText(itemFileRescan, "MyTorrentsView.menu.rescanfile");
                itemFileRescan.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager dm) {
                        dm.getDownloadState().setFlag(DownloadManagerState.FLAG_SCAN_INCOMPLETE_PIECES, itemFileRescan.getSelection());
                    }
                });
                itemFileRescan.setSelection(allScanSelected);
                itemFileRescan.setEnabled(fileRescan);
                // revert
                final MenuItem itemRevertFiles = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(itemRevertFiles, "MyTorrentsView.menu.revertfiles");
                itemRevertFiles.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager[] dms) {
                        FilesViewMenuUtil.revertFiles(tv, dms);
                    }
                });
                itemRevertFiles.setEnabled(hasRevertableFiles);
                // clear links
                final MenuItem itemClearLinks = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(itemClearLinks, "FilesView.menu.clear.links");
                itemClearLinks.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager dm) {
                        if (ManagerUtils.isStopped(dm) && dm.getDownloadState().getFileLinks().hasLinks()) {
                            DiskManagerFileInfoSet fis = dm.getDiskManagerFileInfoSet();
                            if (fis.nbFiles() > 1) {
                                DiskManagerFileInfo[] files = fis.getFiles();
                                for (DiskManagerFileInfo file_info : files) {
                                    File file_link = file_info.getFile(true);
                                    File file_nolink = file_info.getFile(false);
                                    if (!file_nolink.getAbsolutePath().equals(file_link.getAbsolutePath())) {
                                        file_info.setLink(null);
                                    }
                                }
                            }
                        }
                    }
                });
                itemClearLinks.setEnabled(hasClearableLinks);
                // clear allocation
                MenuItem itemFileClearAlloc = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(itemFileClearAlloc, "MyTorrentsView.menu.clear_alloc_data");
                itemFileClearAlloc.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager dm) {
                        dm.setDataAlreadyAllocated(false);
                    }
                });
                itemFileClearAlloc.setEnabled(allStopped);
                // clear resume
                MenuItem itemFileClearResume = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(itemFileClearResume, "MyTorrentsView.menu.clear_resume_data");
                itemFileClearResume.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager dm) {
                        dm.getDownloadState().clearResumeData();
                    }
                });
                itemFileClearResume.setEnabled(allStopped);
                // set resume complete
                MenuItem itemFileSetResumeComplete = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(itemFileSetResumeComplete, "MyTorrentsView.menu.set.resume.complete");
                itemFileSetResumeComplete.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager dm) {
                        TorrentUtils.setResumeDataCompletelyValid(dm.getDownloadState());
                    }
                });
                itemFileSetResumeComplete.setEnabled(allStopped && allResumeIncomplete);
                if (userMode > 1 && isSeedingView) {
                    boolean canSetSuperSeed = false;
                    boolean superSeedAllYes = true;
                    boolean superSeedAllNo = true;
                    for (DownloadManager dm : dms) {
                        PEPeerManager pm = dm.getPeerManager();
                        if (pm != null) {
                            if (pm.canToggleSuperSeedMode()) {
                                canSetSuperSeed = true;
                            }
                            if (pm.isSuperSeedMode()) {
                                superSeedAllYes = false;
                            } else {
                                superSeedAllNo = false;
                            }
                        } else {
                            superSeedAllYes = false;
                            superSeedAllNo = false;
                        }
                    }
                    final MenuItem itemSuperSeed = new MenuItem(menu, SWT.CHECK);
                    Messages.setLanguageText(itemSuperSeed, "ManagerItem.superseeding");
                    boolean enabled = canSetSuperSeed && (superSeedAllNo || superSeedAllYes);
                    itemSuperSeed.setEnabled(enabled);
                    final boolean selected = superSeedAllNo;
                    if (enabled) {
                        itemSuperSeed.setSelection(selected);
                        itemSuperSeed.addListener(SWT.Selection, new ListenerDMTask(dms) {

                            @Override
                            public void run(DownloadManager dm) {
                                PEPeerManager pm = dm.getPeerManager();
                                if (pm != null) {
                                    if (pm.isSuperSeedMode() == selected && pm.canToggleSuperSeedMode()) {
                                        pm.setSuperSeedMode(!selected);
                                    }
                                }
                            }
                        });
                    }
                }
            }
        });
    }
}
Also used : TableSelectedRowsListener(com.biglybt.ui.swt.views.table.TableSelectedRowsListener) SpeedLimitHandler(com.biglybt.core.speedmanager.SpeedLimitHandler) DownloadManager(com.biglybt.core.download.DownloadManager) DownloadManagerState(com.biglybt.core.download.DownloadManagerState) UIFunctions(com.biglybt.ui.UIFunctions) TableRowCore(com.biglybt.ui.common.table.TableRowCore) TableCellCore(com.biglybt.ui.common.table.TableCellCore) Core(com.biglybt.core.Core) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) DiskManagerFileInfoSet(com.biglybt.core.disk.DiskManagerFileInfoSet) MenuItem(com.biglybt.pif.ui.menus.MenuItem) Point(org.eclipse.swt.graphics.Point) TRTrackerAnnouncer(com.biglybt.core.tracker.client.TRTrackerAnnouncer) PEPeerManager(com.biglybt.core.peer.PEPeerManager) File(java.io.File)

Example 62 with Core

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

the class TorrentUtil method repositionManual.

public static void repositionManual(final TableView tv, final DownloadManager[] dms, final Shell shell, final boolean isSeedingView) {
    SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("MyTorrentsView.dialog.setPosition.title", "MyTorrentsView.dialog.setPosition.text");
    entryWindow.prompt(new UIInputReceiverListener() {

        @Override
        public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
            if (!entryWindow.hasSubmittedInput()) {
                return;
            }
            String sReturn = entryWindow.getSubmittedInput();
            if (sReturn == null)
                return;
            int newPosition = -1;
            try {
                newPosition = Integer.valueOf(sReturn).intValue();
            } catch (NumberFormatException er) {
            // Ignore
            }
            Core core = CoreFactory.getSingleton();
            if (core == null) {
                return;
            }
            int size = core.getGlobalManager().downloadManagerCount(isSeedingView);
            if (newPosition > size)
                newPosition = size;
            if (newPosition <= 0) {
                MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                mb.setText(MessageText.getString("MyTorrentsView.dialog.NumberError.title"));
                mb.setMessage(MessageText.getString("MyTorrentsView.dialog.NumberError.text"));
                mb.open();
                return;
            }
            moveSelectedTorrentsTo(tv, dms, newPosition);
        }
    });
}
Also used : UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) Core(com.biglybt.core.Core) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore)

Example 63 with Core

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

the class UI method coreCreated.

@Override
public void coreCreated(Core core) {
    super.coreCreated(core);
    SimpleDateFormat temp = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
    UIConst.startTime = new Date();
    Logger.getLogger("biglybt").fatal(Constants.APP_NAME + " started at " + temp.format(UIConst.startTime));
    core.addLifecycleListener(new CoreLifecycleAdapter() {

        @Override
        public void started(Core core) {
            startUI();
        }

        @Override
        public void stopped(Core core) {
            super.stopped(core);
            SimpleDateFormat temp = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
            Logger.getLogger("biglybt").fatal(Constants.APP_NAME + " stopped at " + temp.format(new Date()));
        }
    });
    if (core.isStarted()) {
        startUI();
    }
}
Also used : CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Core(com.biglybt.core.Core)

Example 64 with Core

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

the class UIConfigDefaultsSWTv3 method initialize.

public static void initialize(Core core) {
    ConfigurationManager config = ConfigurationManager.getInstance();
    if ("az2".equalsIgnoreCase(config.getStringParameter("ui", "az3"))) {
        return;
    }
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    boolean startAdvanced = userMode > 1;
    boolean configNeedsSave = false;
    if (System.getProperty("FORCE_PROGRESSIVE", "").length() > 0) {
        // TODO HACK FOR DEMO PURPOSES ONLY!
        config.setParameter("Prioritize First Piece", true);
        configNeedsSave = true;
    }
    final ConfigurationDefaults defaults = ConfigurationDefaults.getInstance();
    defaults.addParameter("ui", "az3");
    defaults.addParameter("Auto Upload Speed Enabled", true);
    defaults.addParameter(ConfigurationDefaults.CFG_TORRENTADD_OPENOPTIONS, startAdvanced ? ConfigurationDefaults.CFG_TORRENTADD_OPENOPTIONS_ALWAYS : ConfigurationDefaults.CFG_TORRENTADD_OPENOPTIONS_MANY);
    // defaults.addParameter("Add URL Silently", true);			not used 11/30/2015 - see "Activate Window On External Download"
    // defaults.addParameter("add_torrents_silently", true);	not used 11/30/2015
    defaults.addParameter("Popup Download Finished", false);
    defaults.addParameter("Popup Download Added", false);
    defaults.addParameter("Status Area Show SR", false);
    defaults.addParameter("Status Area Show NAT", false);
    defaults.addParameter("Status Area Show IPF", false);
    defaults.addParameter("Status Area Show RIP", true);
    defaults.addParameter("Message Popup Autoclose in Seconds", 10);
    defaults.addParameter("window.maximized", true);
    defaults.addParameter("update.autodownload", true);
    // defaults.addParameter("suppress_file_download_dialog", true);
    defaults.addParameter("auto_remove_inactive_items", false);
    defaults.addParameter("show_torrents_menu", false);
    config.removeParameter("v3.home-tab.starttab");
    defaults.addParameter("MyTorrentsView.table.style", 0);
    defaults.addParameter("v3.Show Welcome", true);
    defaults.addParameter("Library.viewmode", startAdvanced ? 1 : 0);
    defaults.addParameter("LibraryDL.viewmode", startAdvanced ? 1 : 0);
    defaults.addParameter("LibraryDL.UseDefaultIndicatorColor", false);
    defaults.addParameter("LibraryUnopened.viewmode", startAdvanced ? 1 : 0);
    defaults.addParameter("LibraryCD.viewmode", startAdvanced ? 1 : 0);
    defaults.addParameter("Library.EnableSimpleView", 1);
    defaults.addParameter("Library.CatInSideBar", startAdvanced ? 1 : 0);
    defaults.addParameter("Library.TagInSideBar", 1);
    defaults.addParameter("Library.ShowTabsInTorrentView", 1);
    defaults.addParameter("list.dm.dblclick", "0");
    // === defaults used by MainWindow
    defaults.addParameter("vista.adminquit", false);
    defaults.addParameter("Start Minimized", false);
    defaults.addParameter("Password enabled", false);
    defaults.addParameter("ToolBar.showText", true);
    defaults.addParameter("Table.extendedErase", !Constants.isWindowsXP);
    defaults.addParameter("Table.useTree", true);
    // by default, turn off some slidey warning
    // Since they are plugin configs, we need to set the default after the
    // plugin sets the default
    core.addLifecycleListener(new CoreLifecycleAdapter() {

        @Override
        public void started(Core core) {
            defaults.addParameter("Plugin.DHT.dht.warn.user", false);
            defaults.addParameter("Plugin.UPnP.upnp.alertothermappings", false);
            defaults.addParameter("Plugin.UPnP.upnp.alertdeviceproblems", false);
        }
    });
    // run
    if (!COConfigurationManager.hasParameter("v3.StartTab", true)) {
        // Reset 'big' columns, remove some tables that no longer exist
        Map<?, ?> map = FileUtil.readResilientConfigFile("tables.config");
        if (map != null && map.size() > 0) {
            Object[] keys = map.keySet().toArray();
            boolean removedSome = false;
            for (int i = 0; i < keys.length; i++) {
                if (keys[i] instanceof String) {
                    String sKey = (String) keys[i];
                    if (sKey.endsWith(".big") || sKey.startsWith("Table.library-") || sKey.startsWith("Table.Media") || sKey.startsWith("Table.activity.table") || sKey.equals("Table.Activity.big") || sKey.equals("Table.Activity_SB")) {
                        map.remove(sKey);
                        removedSome = true;
                    }
                }
            }
            if (removedSome) {
                FileUtil.writeResilientConfigFile("tables.config", map);
            }
        }
    }
    if (configNeedsSave) {
        config.save();
    }
}
Also used : CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) COConfigurationManager(com.biglybt.core.config.COConfigurationManager) Core(com.biglybt.core.Core)

Example 65 with Core

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

the class SBC_SubscriptionResultsView method skinObjectInitialShow.

@Override
public Object skinObjectInitialShow(SWTSkinObject skinObject, Object params) {
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(Core core) {
            initColumns(core);
        }
    });
    MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
    if (mdi != null && ds != null) {
        String mdi_key = "Subscription_" + ByteFormatter.encodeString(ds.getPublicKey());
        mdi_entry = mdi.getEntry(mdi_key);
        if (mdi_entry != null) {
            mdi_entry.addToolbarEnabler(this);
        }
    }
    if (ds != null) {
        if ((ds.getViewOptions() & Subscription.VO_HIDE_HEADER) != 0) {
            SWTSkinObject top_area = getSkinObject("toparea");
            top_area.setVisible(false);
        }
        SWTSkinObjectText title = (SWTSkinObjectText) getSkinObject("title");
        if (title != null) {
            title.setText(MessageText.getString("subs.results.view.title", new String[] { ds.getName() }));
            Control control = title.getControl();
            final Menu menu = new Menu(control);
            control.setMenu(menu);
            final String menu_key = SubscriptionMDIEntry.setupMenus(ds, null);
            menu.addMenuListener(new MenuListener() {

                @Override
                public void menuShown(MenuEvent e) {
                    for (MenuItem mi : menu.getItems()) {
                        mi.dispose();
                    }
                    com.biglybt.pif.ui.menus.MenuItem[] menu_items = MenuItemManager.getInstance().getAllAsArray(menu_key);
                    MenuBuildUtils.addPluginMenuItems(menu_items, menu, true, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Object[] { ds }));
                }

                @Override
                public void menuHidden(MenuEvent e) {
                // TODO Auto-generated method stub
                }
            });
        }
    }
    SWTSkinObjectTextbox soFilterBox = (SWTSkinObjectTextbox) getSkinObject("filterbox");
    if (soFilterBox != null) {
        txtFilter = soFilterBox.getTextControl();
    }
    final SWTSkinObject soFilterArea = getSkinObject("filterarea");
    if (soFilterArea != null) {
        SWTSkinObjectToggle soFilterButton = (SWTSkinObjectToggle) getSkinObject("filter-button");
        if (soFilterButton != null) {
            boolean toggled = COConfigurationManager.getBooleanParameter("Subscription View Filter Options Expanded", false);
            if (toggled) {
                soFilterButton.setToggled(true);
                soFilterArea.setVisible(true);
            }
            soFilterButton.addSelectionListener(new SWTSkinToggleListener() {

                @Override
                public void toggleChanged(SWTSkinObjectToggle so, boolean toggled) {
                    COConfigurationManager.setParameter("Subscription View Filter Options Expanded", toggled);
                    soFilterArea.setVisible(toggled);
                    Utils.relayout(soFilterArea.getControl().getParent());
                }
            });
        }
        Composite parent = (Composite) soFilterArea.getControl();
        Label label;
        FormData fd;
        GridLayout layout;
        int sepHeight = 20;
        Composite cFilters = new Composite(parent, SWT.NONE);
        fd = Utils.getFilledFormData();
        cFilters.setLayoutData(fd);
        layout = new GridLayout(1, true);
        layout.marginBottom = layout.marginTop = layout.marginLeft = layout.marginRight = 0;
        layout.marginWidth = layout.marginHeight = 0;
        cFilters.setLayout(layout);
        SubscriptionResultFilter filters = null;
        Runnable pFilterUpdater = null;
        if (ds != null && ds.isUpdateable()) {
            try {
                filters = ds.getFilters();
                Composite pFilters = new Composite(cFilters, SWT.NONE);
                pFilters.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                layout = new GridLayout(1, false);
                layout.marginBottom = layout.marginTop = layout.marginLeft = layout.marginRight = 0;
                layout.marginWidth = layout.marginHeight = 0;
                pFilters.setLayout(layout);
                final Label pflabel = new Label(pFilters, SWT.NONE);
                pflabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                final SubscriptionResultFilter f_filters = filters;
                pFilterUpdater = new Runnable() {

                    @Override
                    public void run() {
                        long kInB = DisplayFormatters.getKinB();
                        long mInB = kInB * kInB;
                        long min_size = f_filters.getMinSze() / mInB;
                        long max_size = f_filters.getMaxSize() / mInB;
                        pflabel.setText(MessageText.getString("subs.persistent.filters", new String[] { getString(f_filters.getWithWords()), getString(f_filters.getWithoutWords()), String.valueOf(min_size < 0 ? 0 : min_size), String.valueOf(max_size < 0 ? 0 : max_size) }));
                    }
                };
                pFilterUpdater.run();
            } catch (Throwable e) {
                Debug.out(e);
            }
        }
        Composite vFilters = new Composite(cFilters, SWT.NONE);
        vFilters.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
        rowLayout.spacing = 5;
        rowLayout.marginBottom = rowLayout.marginTop = rowLayout.marginLeft = rowLayout.marginRight = 0;
        rowLayout.center = true;
        vFilters.setLayout(rowLayout);
        // with/without keywords
        ImageLoader imageLoader = ImageLoader.getInstance();
        for (int i = 0; i < 2; i++) {
            final boolean with = i == 0;
            if (!with) {
                label = new Label(vFilters, SWT.VERTICAL | SWT.SEPARATOR);
                label.setLayoutData(new RowData(-1, sepHeight));
            }
            Composite cWithKW = new Composite(vFilters, SWT.NONE);
            layout = new GridLayout(2, false);
            layout.marginWidth = 0;
            layout.marginBottom = layout.marginTop = layout.marginLeft = layout.marginRight = 0;
            cWithKW.setLayout(layout);
            // Label lblWithKW = new Label(cWithKW, SWT.NONE);
            // lblWithKW.setText(MessageText.getString(with?"SubscriptionResults.filter.with.words":"SubscriptionResults.filter.without.words"));
            Label lblWithKWImg = new Label(cWithKW, SWT.NONE);
            lblWithKWImg.setImage(imageLoader.getImage(with ? "icon_filter_plus" : "icon_filter_minus"));
            final Text textWithKW = new Text(cWithKW, SWT.BORDER);
            textWithKW.setMessage(MessageText.getString(with ? "SubscriptionResults.filter.with.words" : "SubscriptionResults.filter.without.words"));
            GridData gd = new GridData();
            gd.widthHint = Utils.adjustPXForDPI(100);
            textWithKW.setLayoutData(gd);
            textWithKW.addModifyListener(new ModifyListener() {

                @Override
                public void modifyText(ModifyEvent e) {
                    String text = textWithKW.getText().toLowerCase(Locale.US);
                    String[] bits = text.split("\\s+");
                    Set<String> temp = new HashSet<>();
                    for (String bit : bits) {
                        bit = bit.trim();
                        if (bit.length() > 0) {
                            temp.add(bit);
                        }
                    }
                    String[] words = temp.toArray(new String[temp.size()]);
                    synchronized (filter_lock) {
                        if (with) {
                            with_keywords = words;
                        } else {
                            without_keywords = words;
                        }
                    }
                    refilter_dispatcher.dispatch();
                }
            });
        }
        // min size
        label = new Label(vFilters, SWT.VERTICAL | SWT.SEPARATOR);
        label.setLayoutData(new RowData(-1, sepHeight));
        Composite cMinSize = new Composite(vFilters, SWT.NONE);
        layout = new GridLayout(2, false);
        layout.marginWidth = 0;
        layout.marginBottom = layout.marginTop = layout.marginLeft = layout.marginRight = 0;
        cMinSize.setLayout(layout);
        Label lblMinSize = new Label(cMinSize, SWT.NONE);
        lblMinSize.setText(MessageText.getString("SubscriptionResults.filter.min_size"));
        Spinner spinMinSize = new Spinner(cMinSize, SWT.BORDER);
        spinMinSize.setMinimum(0);
        // 100 TB should do...
        spinMinSize.setMaximum(100 * 1024 * 1024);
        spinMinSize.setSelection(minSize);
        spinMinSize.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                minSize = ((Spinner) event.widget).getSelection();
                refilter_dispatcher.dispatch();
            }
        });
        // max size
        label = new Label(vFilters, SWT.VERTICAL | SWT.SEPARATOR);
        label.setLayoutData(new RowData(-1, sepHeight));
        Composite cMaxSize = new Composite(vFilters, SWT.NONE);
        layout = new GridLayout(2, false);
        layout.marginWidth = 0;
        layout.marginBottom = layout.marginTop = layout.marginLeft = layout.marginRight = 0;
        cMaxSize.setLayout(layout);
        Label lblMaxSize = new Label(cMaxSize, SWT.NONE);
        lblMaxSize.setText(MessageText.getString("SubscriptionResults.filter.max_size"));
        Spinner spinMaxSize = new Spinner(cMaxSize, SWT.BORDER);
        spinMaxSize.setMinimum(0);
        // 100 TB should do...
        spinMaxSize.setMaximum(100 * 1024 * 1024);
        spinMaxSize.setSelection(maxSize);
        spinMaxSize.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                maxSize = ((Spinner) event.widget).getSelection();
                refilter_dispatcher.dispatch();
            }
        });
        if (filters != null) {
            label = new Label(vFilters, SWT.VERTICAL | SWT.SEPARATOR);
            label.setLayoutData(new RowData(-1, sepHeight));
            final SubscriptionResultFilter f_filters = filters;
            final Runnable f_pFilterUpdater = pFilterUpdater;
            Button save = new Button(vFilters, SWT.PUSH);
            save.setText(MessageText.getString("ConfigView.button.save"));
            save.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    try {
                        long kInB = DisplayFormatters.getKinB();
                        long mInB = kInB * kInB;
                        f_filters.update(with_keywords, without_keywords, minSize * mInB, maxSize * mInB);
                        f_pFilterUpdater.run();
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            });
        }
        parent.layout(true);
    }
    return null;
}
Also used : TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener) SubscriptionListener(com.biglybt.core.subs.SubscriptionListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) MultipleDocumentInterfaceSWT(com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT) Core(com.biglybt.core.Core) MessageText(com.biglybt.core.internat.MessageText) SubscriptionResultFilter(com.biglybt.core.subs.SubscriptionResultFilter) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

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