Search in sources :

Example 21 with UIFunctions

use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.

the class UI method coreCreated.

@Override
public void coreCreated(Core core) {
    super.coreCreated(core);
    UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
    if (uiFunctions != null) {
        openQueuedTorrents();
    } else {
        core.addLifecycleListener(new CoreLifecycleAdapter() {

            @Override
            public void componentCreated(Core core, CoreComponent component) {
                if (component instanceof UIFunctionsSWT) {
                    openQueuedTorrents();
                    core.removeLifecycleListener(this);
                }
            }
        });
    }
}
Also used : CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) UIFunctions(com.biglybt.ui.UIFunctions) CoreComponent(com.biglybt.core.CoreComponent) Core(com.biglybt.core.Core)

Example 22 with UIFunctions

use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.

the class TorrentOpener method addTorrent.

/**
 * @param torrentOptions
 * @return
 * @since 5.0.0.1
 *
 * @TODO: Remove SWT UI parts (use UIFunctions) and move out of SWT tree
 */
public static final boolean addTorrent(final TorrentOpenOptions torrentOptions) {
    try {
        if (torrentOptions.getTorrent() == null) {
            return false;
        }
        final DownloadManagerInitialisationAdapter dmia = new DownloadManagerInitialisationAdapter() {

            @Override
            public int getActions() {
                return (ACT_ASSIGNS_TAGS);
            }

            @Override
            public void initialised(DownloadManager dm, boolean for_seeding) {
                DiskManagerFileInfoSet file_info_set = dm.getDiskManagerFileInfoSet();
                DiskManagerFileInfo[] fileInfos = file_info_set.getFiles();
                boolean reorder_mode = COConfigurationManager.getBooleanParameter("Enable reorder storage mode");
                int reorder_mode_min_mb = COConfigurationManager.getIntParameter("Reorder storage mode min MB");
                try {
                    dm.getDownloadState().suppressStateSave(true);
                    boolean[] toSkip = new boolean[fileInfos.length];
                    boolean[] toCompact = new boolean[fileInfos.length];
                    boolean[] toReorderCompact = new boolean[fileInfos.length];
                    int[] priorities = null;
                    int comp_num = 0;
                    int reorder_comp_num = 0;
                    final TorrentOpenFileOptions[] files = torrentOptions.getFiles();
                    for (int iIndex = 0; iIndex < fileInfos.length; iIndex++) {
                        DiskManagerFileInfo fileInfo = fileInfos[iIndex];
                        if (iIndex >= 0 && iIndex < files.length && files[iIndex].lSize == fileInfo.getLength()) {
                            // Always pull destination file from fileInfo and not from
                            // TorrentFileInfo because the destination may have changed
                            // by magic code elsewhere
                            File fDest = fileInfo.getFile(true);
                            if (files[iIndex].isLinked()) {
                                fDest = files[iIndex].getDestFileFullName();
                                // Can't use fileInfo.setLink(fDest) as it renames
                                // the existing file if there is one
                                dm.getDownloadState().setFileLink(iIndex, fileInfo.getFile(false), fDest);
                            }
                            if (files[iIndex].isToDownload()) {
                                int priority = files[iIndex].getPriority();
                                if (priority != 0) {
                                    if (priorities == null) {
                                        priorities = new int[fileInfos.length];
                                    }
                                    priorities[iIndex] = priority;
                                }
                            } else {
                                toSkip[iIndex] = true;
                                if (!fDest.exists()) {
                                    if (reorder_mode && (fileInfo.getLength() / (1024 * 1024)) >= reorder_mode_min_mb) {
                                        toReorderCompact[iIndex] = true;
                                        reorder_comp_num++;
                                    } else {
                                        toCompact[iIndex] = true;
                                        comp_num++;
                                    }
                                }
                            }
                        }
                    }
                    if (files.length == 1) {
                        TorrentOpenFileOptions file = files[0];
                        if (file.isManualRename()) {
                            String fileRename = file.getDestFileName();
                            if (fileRename != null && fileRename.length() > 0) {
                                dm.getDownloadState().setDisplayName(fileRename);
                            }
                        }
                    } else {
                        String folderRename = torrentOptions.getManualRename();
                        if (folderRename != null && folderRename.length() > 0) {
                            dm.getDownloadState().setDisplayName(folderRename);
                        }
                    }
                    if (comp_num > 0) {
                        file_info_set.setStorageTypes(toCompact, DiskManagerFileInfo.ST_COMPACT);
                    }
                    if (reorder_comp_num > 0) {
                        file_info_set.setStorageTypes(toReorderCompact, DiskManagerFileInfo.ST_REORDER_COMPACT);
                    }
                    file_info_set.setSkipped(toSkip, true);
                    if (priorities != null) {
                        file_info_set.setPriority(priorities);
                    }
                    int maxUp = torrentOptions.getMaxUploadSpeed();
                    int kInB = DisplayFormatters.getKinB();
                    if (maxUp > 0) {
                        dm.getStats().setUploadRateLimitBytesPerSecond(maxUp * kInB);
                    }
                    int maxDown = torrentOptions.getMaxDownloadSpeed();
                    if (maxDown > 0) {
                        dm.getStats().setDownloadRateLimitBytesPerSecond(maxDown * kInB);
                    }
                    DownloadManagerState dm_state = dm.getDownloadState();
                    if (torrentOptions.disableIPFilter) {
                        dm_state.setFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER, true);
                    }
                    if (torrentOptions.peerSource != null) {
                        for (String peerSource : torrentOptions.peerSource.keySet()) {
                            boolean enable = torrentOptions.peerSource.get(peerSource);
                            dm_state.setPeerSourceEnabled(peerSource, enable);
                        }
                    }
                    Map<String, Boolean> enabledNetworks = torrentOptions.getEnabledNetworks();
                    if (enabledNetworks != null) {
                        if (!dm_state.getFlag(DownloadManagerState.FLAG_INITIAL_NETWORKS_SET)) {
                            for (String net : enabledNetworks.keySet()) {
                                boolean enable = enabledNetworks.get(net);
                                dm_state.setNetworkEnabled(net, enable);
                            }
                        }
                    }
                    List<Tag> initialTags = torrentOptions.getInitialTags();
                    for (Tag t : initialTags) {
                        t.addTaggable(dm);
                    }
                    List<List<String>> trackers = torrentOptions.getTrackers(true);
                    if (trackers != null) {
                        TOTorrent torrent = dm.getTorrent();
                        TorrentUtils.listToAnnounceGroups(trackers, torrent);
                        try {
                            TorrentUtils.writeToFile(torrent);
                        } catch (Throwable e2) {
                            Debug.printStackTrace(e2);
                        }
                    }
                    if (torrentOptions.bSequentialDownload) {
                        dm_state.setFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD, true);
                    }
                    File moc = torrentOptions.getMoveOnComplete();
                    if (moc != null) {
                        dm_state.setAttribute(DownloadManagerState.AT_MOVE_ON_COMPLETE_DIR, moc.getAbsolutePath());
                    }
                } finally {
                    dm.getDownloadState().suppressStateSave(false);
                }
            }
        };
        CoreFactory.addCoreRunningListener(new CoreRunningListener() {

            @Override
            public void coreRunning(Core core) {
                TOTorrent torrent = torrentOptions.getTorrent();
                byte[] hash = null;
                try {
                    hash = torrent.getHash();
                } catch (TOTorrentException e1) {
                }
                int iStartState = (torrentOptions.getStartMode() == TorrentOpenOptions.STARTMODE_STOPPED) ? DownloadManager.STATE_STOPPED : DownloadManager.STATE_QUEUED;
                GlobalManager gm = core.getGlobalManager();
                DownloadManager dm = gm.addDownloadManager(torrentOptions.sFileName, hash, torrentOptions.getParentDir(), torrentOptions.getSubDir(), iStartState, true, torrentOptions.getStartMode() == TorrentOpenOptions.STARTMODE_SEEDING, dmia);
                // since gm.addDown.. will handle it.
                if (dm == null) {
                    return;
                }
                if (torrentOptions.iQueueLocation == TorrentOpenOptions.QUEUELOCATION_TOP) {
                    gm.moveTop(new DownloadManager[] { dm });
                }
                if (torrentOptions.getStartMode() == TorrentOpenOptions.STARTMODE_FORCESTARTED) {
                    dm.setForceStart(true);
                }
            }
        });
    } catch (Exception e) {
        UIFunctions uif = UIFunctionsManager.getUIFunctions();
        if (uif != null) {
            uif.showErrorMessage("OpenTorrentWindow.mb.openError", Debug.getStackTrace(e), new String[] { torrentOptions.sOriginatingLocation, e.getMessage() });
        }
        return false;
    }
    return true;
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager) DownloadManagerState(com.biglybt.core.download.DownloadManagerState) GlobalManager(com.biglybt.core.global.GlobalManager) UIFunctions(com.biglybt.ui.UIFunctions) CoreRunningListener(com.biglybt.core.CoreRunningListener) ArrayList(java.util.ArrayList) List(java.util.List) Core(com.biglybt.core.Core) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) TorrentOpenFileOptions(com.biglybt.core.torrent.impl.TorrentOpenFileOptions) DiskManagerFileInfoSet(com.biglybt.core.disk.DiskManagerFileInfoSet) DownloadManagerInitialisationAdapter(com.biglybt.core.download.DownloadManagerInitialisationAdapter) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) TOTorrent(com.biglybt.core.torrent.TOTorrent) Tag(com.biglybt.core.tag.Tag) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File)

Example 23 with UIFunctions

use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.

the class BaseMdiEntry method importStandAlone.

public static SWTSkinObjectContainer importStandAlone(SWTSkinObjectContainer soParent, Map<String, Object> map, Runnable callback) {
    String mdi_type = (String) map.get("mdi");
    String skin_ref = (String) map.get("skin_ref");
    String skin_id = (String) map.get("skin_id");
    SWTSkin skin = SWTSkinFactory.lookupSkin(skin_id);
    String parent_id = (String) map.get("parent_id");
    String id = (String) map.get("id");
    Object data_source = map.get("data_source");
    if (data_source != null) {
        if (data_source instanceof Map) {
            Map<String, Object> ds_map = (Map<String, Object>) data_source;
            if (ds_map != null) {
                ds_map = new HashMap<String, Object>(ds_map);
                ds_map.put("callback", callback);
            }
            data_source = ds_map == null ? null : DataSourceResolver.importDataSource(ds_map);
        } else if (data_source instanceof List) {
            List l = (List) data_source;
            String type = (String) l.get(0);
            Long value = (Long) l.get(1);
            if (type.equals("i")) {
                data_source = value.intValue();
            }
        }
    }
    int control_type = ((Number) map.get("control_type")).intValue();
    Map<String, Object> el_map = (Map<String, Object>) map.get("event_listener");
    UISWTViewEventListener event_listener = null;
    if (el_map != null) {
        try {
            String class_name = (String) el_map.get("name");
            if (class_name != null) {
                Class<? extends UISWTViewCoreEventListenerEx> cla = (Class<? extends UISWTViewCoreEventListenerEx>) Class.forName(class_name);
                List p_types = (List) el_map.get("p_types");
                List p_vals = (List) el_map.get("p_vals");
                if (p_types != null && !p_types.isEmpty()) {
                    List<Class> types = new ArrayList<>();
                    List<Object> args = new ArrayList<>();
                    for (int i = 0; i < p_types.size(); i++) {
                        String type = (String) p_types.get(i);
                        Object val = p_vals.get(i);
                        if (type.equals("bool")) {
                            types.add(boolean.class);
                            args.add(((Long) val) != 0);
                        } else if (type.equals("long")) {
                            types.add(long.class);
                            args.add((Long) val);
                        } else if (type.equals("string")) {
                            types.add(String.class);
                            args.add((String) val);
                        } else {
                            Debug.out("Unsupported type: " + type);
                        }
                    }
                    event_listener = cla.getConstructor(types.toArray(new Class<?>[types.size()])).newInstance(args.toArray(new Object[args.size()]));
                } else {
                    event_listener = cla.newInstance();
                }
            } else {
                String plugin_id = (String) el_map.get("plugin_id");
                PluginInterface pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByID(plugin_id);
                if (pi != null) {
                    String ipc_method = (String) el_map.get("ipc_method");
                    List p_types = (List) el_map.get("p_types");
                    List p_vals = (List) el_map.get("p_vals");
                    List<Object> args = new ArrayList<>();
                    if (p_types != null && !p_types.isEmpty()) {
                        List<Class> types = new ArrayList<>();
                        for (int i = 0; i < p_types.size(); i++) {
                            String type = (String) p_types.get(i);
                            Object val = p_vals.get(i);
                            if (type.equals("bool")) {
                                types.add(boolean.class);
                                args.add(((Long) val) != 0);
                            } else if (type.equals("long")) {
                                types.add(long.class);
                                args.add((Long) val);
                            } else if (type.equals("string")) {
                                types.add(String.class);
                                args.add((String) val);
                            } else {
                                Debug.out("Unsupported type: " + type);
                            }
                        }
                    }
                    event_listener = (UISWTViewEventListener) pi.getIPC().invoke(ipc_method, args.toArray(new Object[args.size()]));
                } else {
                    boolean try_install = false;
                    synchronized (installing_pids) {
                        if (!installing_pids.contains(plugin_id)) {
                            installing_pids.add(plugin_id);
                            try_install = true;
                        }
                    }
                    if (try_install) {
                        boolean went_async = false;
                        try {
                            UIFunctions uif = UIFunctionsManager.getUIFunctions();
                            String plugin_name = (String) el_map.get("plugin_name");
                            String remember_id = "basemdi.import.view.install." + plugin_id;
                            String title = MessageText.getString("plugin.required");
                            String text = MessageText.getString("plugin.required.info", new String[] { plugin_name });
                            UIFunctionsUserPrompter prompter = uif.getUserPrompter(title, text, new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 0);
                            if (remember_id != null) {
                                prompter.setRemember(remember_id, false, MessageText.getString("MessageBoxWindow.nomoreprompting"));
                            }
                            prompter.setAutoCloseInMS(0);
                            prompter.open(null);
                            boolean install = prompter.waitUntilClosed() == 0;
                            if (install) {
                                went_async = true;
                                uif.installPlugin(plugin_id, "plugin.generic.install", new UIFunctions.actionListener() {

                                    @Override
                                    public void actionComplete(Object result) {
                                        try {
                                            if (callback != null) {
                                                if (result instanceof Boolean) {
                                                    if ((Boolean) result) {
                                                        callback.run();
                                                    }
                                                }
                                            }
                                        } finally {
                                            synchronized (installing_pids) {
                                                installing_pids.remove(plugin_id);
                                            }
                                        }
                                    }
                                });
                            }
                        } finally {
                            if (!went_async) {
                                synchronized (installing_pids) {
                                    installing_pids.remove(plugin_id);
                                }
                            }
                        }
                    }
                }
            }
        } catch (Throwable e) {
            Debug.out(e);
        }
    }
    if (mdi_type.equals("sidebar")) {
        return (SideBarEntrySWT.buildStandAlone(soParent, skin_ref, skin, parent_id, id, data_source, control_type, null, event_listener, true));
    } else {
        return (TabbedEntry.buildStandAlone(soParent, skin_ref, skin, parent_id, id, data_source, control_type, null, event_listener, true));
    }
}
Also used : UIFunctionsUserPrompter(com.biglybt.ui.UIFunctionsUserPrompter) UIFunctions(com.biglybt.ui.UIFunctions) List(java.util.List) PluginInterface(com.biglybt.pif.PluginInterface) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) SWTSkin(com.biglybt.ui.swt.skin.SWTSkin) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) PluginUISWTSkinObject(com.biglybt.ui.swt.pif.PluginUISWTSkinObject)

Example 24 with UIFunctions

use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.

the class SBC_SearchResultsView method buildEngineArea.

private void buildEngineArea(final SearchInstance search) {
    if (engine_area.isDisposed()) {
        return;
    }
    final Engine[] engines = search == null ? new Engine[0] : search.getEngines();
    Utils.disposeComposite(engine_area, false);
    Arrays.sort(engines, new Comparator<Engine>() {

        @Override
        public int compare(Engine o1, Engine o2) {
            return (o1.getName().compareTo(o2.getName()));
        }
    });
    RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
    rowLayout.spacing = 3;
    rowLayout.marginBottom = rowLayout.marginTop = rowLayout.marginLeft = rowLayout.marginRight = 0;
    rowLayout.pack = false;
    engine_area.setLayout(rowLayout);
    final Composite label_comp = new Composite(engine_area, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.marginBottom = layout.marginTop = layout.marginLeft = layout.marginRight = 1;
    label_comp.setLayout(layout);
    Label label = new Label(label_comp, SWT.NULL);
    Messages.setLanguageText(label, "label.show.results.from");
    GridData grid_data = new GridData(SWT.LEFT, SWT.CENTER, true, true);
    label.setLayoutData(grid_data);
    final List<Button> buttons = new ArrayList<>();
    final List<Label> result_counts = new ArrayList<>();
    final List<ImageLabel> indicators = new ArrayList<>();
    label.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            deselected_engines.clear();
            for (Button b : buttons) {
                b.setSelection(true);
            }
            refilter();
        }
    });
    for (final Engine engine : engines) {
        final Composite engine_comp = new Composite(engine_area, SWT.NULL);
        layout = new GridLayout(3, false);
        layout.marginBottom = layout.marginTop = layout.marginLeft = layout.marginRight = 1;
        engine_comp.setLayout(layout);
        engine_comp.addPaintListener(new PaintListener() {

            @Override
            public void paintControl(PaintEvent e) {
                GC gc = e.gc;
                gc.setForeground(Colors.grey);
                Point size = engine_comp.getSize();
                gc.drawRectangle(new Rectangle(0, 0, size.x - 1, size.y - 1));
            }
        });
        final Button button = new Button(engine_comp, SWT.CHECK);
        button.setData(engine);
        buttons.add(button);
        button.setText(engine.getName());
        button.setSelection(!deselected_engines.contains(engine.getUID()));
        Image image = getIcon(engine, new ImageLoadListener() {

            @Override
            public void imageLoaded(Image image) {
                button.setImage(image);
            }
        });
        if (image != null) {
            try {
                button.setImage(image);
            } catch (Throwable e) {
            }
        }
        button.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                String id = engine.getUID();
                if (button.getSelection()) {
                    deselected_engines.remove(id);
                } else {
                    deselected_engines.add(id);
                }
                refilter();
            }
        });
        Menu menu = new Menu(button);
        button.setMenu(menu);
        MenuItem mi = new MenuItem(menu, SWT.PUSH);
        mi.setText(MessageText.getString("label.this.site.only"));
        mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                deselected_engines.clear();
                button.setSelection(true);
                for (Button b : buttons) {
                    if (b != button) {
                        b.setSelection(false);
                        deselected_engines.add(((Engine) b.getData()).getUID());
                    }
                }
                refilter();
            }
        });
        MenuItem miCreateSubscription = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(miCreateSubscription, "menu.search.create.subscription");
        miCreateSubscription.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                Map filterMap = buildFilterMap();
                SearchUtils.showCreateSubscriptionDialog(engine.getId(), current_search.sq.term, filterMap);
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
        SearchUtils.addMenus(menu, engine, true);
        Label results = new Label(engine_comp, SWT.NULL);
        GC temp = new GC(results);
        Point size = temp.textExtent("(888)");
        temp.dispose();
        GridData gd = new GridData();
        gd.widthHint = Utils.adjustPXForDPI(size.x);
        results.setLayoutData(gd);
        result_counts.add(results);
        ImageLabel indicator = new ImageLabel(engine_comp, vitality_images[0]);
        indicators.add(indicator);
        indicator.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                deselected_engines.clear();
                boolean only_me_selected = button.getSelection();
                if (only_me_selected) {
                    for (Button b : buttons) {
                        if (b != button) {
                            if (b.getSelection()) {
                                only_me_selected = false;
                            }
                        }
                    }
                }
                if (only_me_selected) {
                    button.setSelection(false);
                    deselected_engines.add(engine.getUID());
                    for (Button b : buttons) {
                        if (b != button) {
                            b.setSelection(true);
                        }
                    }
                } else {
                    button.setSelection(true);
                    for (Button b : buttons) {
                        if (b != button) {
                            b.setSelection(false);
                            deselected_engines.add(((Engine) b.getData()).getUID());
                        }
                    }
                }
                refilter();
            }
        });
    }
    Composite cAddEdit = new Composite(engine_area, SWT.NONE);
    cAddEdit.setLayout(new GridLayout());
    Button btnAddEdit = new Button(cAddEdit, SWT.PUSH);
    btnAddEdit.setLayoutData(new GridData(SWT.CENTER, 0, true, true));
    Messages.setLanguageText(btnAddEdit, "button.add.edit.search.templates");
    btnAddEdit.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            UIFunctions functions = UIFunctionsManager.getUIFunctions();
            if (functions != null) {
                functions.viewURL(Constants.URL_SEARCH_ADDEDIT, null, "");
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    Composite cCreateTemplate = new Composite(engine_area, SWT.NONE);
    cCreateTemplate.setLayout(new GridLayout());
    Button btnCreateTemplate = new Button(cCreateTemplate, SWT.PUSH);
    btnCreateTemplate.setLayoutData(new GridData(SWT.CENTER, 0, true, true));
    Messages.setLanguageText(btnCreateTemplate, "menu.search.create.subscription");
    btnCreateTemplate.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Map filterMap = buildFilterMap();
            SearchUtils.showCreateSubscriptionDialog(-1, current_search.sq.term, buildFilterMap());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    if (engines.length > 0) {
        new AEThread2("updater") {

            int ticks;

            int image_index = 0;

            volatile boolean running = true;

            @Override
            public void run() {
                while (running) {
                    if (label_comp.isDisposed()) {
                        return;
                    }
                    try {
                        Thread.sleep(100);
                    } catch (Throwable e) {
                    }
                    Utils.execSWTThread(new Runnable() {

                        @Override
                        public void run() {
                            if (label_comp.isDisposed()) {
                                return;
                            }
                            ticks++;
                            image_index++;
                            if (image_index == vitality_images.length) {
                                image_index = 0;
                            }
                            boolean do_results = ticks % 5 == 0;
                            boolean all_done = do_results;
                            for (int i = 0; i < engines.length; i++) {
                                Object[] status = search.getEngineStatus(engines[i]);
                                int state = (Integer) status[0];
                                ImageLabel indicator = indicators.get(i);
                                if (state == 0) {
                                    indicator.setImage(vitality_images[image_index]);
                                } else if (state == 1) {
                                    indicator.setImage(ok_image);
                                } else if (state == 2) {
                                    indicator.setImage(fail_image);
                                    String msg = (String) status[2];
                                    if (msg != null) {
                                        indicator.setToolTipText(msg);
                                    }
                                } else {
                                    indicator.setImage(auth_image);
                                }
                                if (do_results) {
                                    if (state == 0) {
                                        all_done = false;
                                    }
                                    String str = "(" + status[1] + ")";
                                    Label rc = result_counts.get(i);
                                    if (!str.equals(rc.getText())) {
                                        rc.setText(str);
                                    }
                                }
                            }
                            if (all_done) {
                                running = false;
                            }
                        }
                    });
                }
            }
        }.start();
    }
    engine_area.layout(true);
}
Also used : Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) UIFunctions(com.biglybt.ui.UIFunctions) RowLayout(org.eclipse.swt.layout.RowLayout) Menu(org.eclipse.swt.widgets.Menu) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine) Engine(com.biglybt.core.metasearch.Engine) Composite(org.eclipse.swt.widgets.Composite) MenuItem(org.eclipse.swt.widgets.MenuItem) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridData(org.eclipse.swt.layout.GridData) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject)

Example 25 with UIFunctions

use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.

the class MyTrackerView method tableRefresh.

// @see TableRefreshListener#tableRefresh()
@Override
public void tableRefresh() {
    if (getComposite() == null || getComposite().isDisposed()) {
        return;
    }
    UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
    if (uiFunctions != null) {
        uiFunctions.refreshIconBar();
    }
    // Store values for columns that are calculate from peer information, so
    // that we only have to do one loop.  (As opposed to each cell doing a loop)
    // Calculate code copied from TrackerTableItem
    TableRowCore[] rows = tv.getRows();
    for (int x = 0; x < rows.length; x++) {
        TableRowSWT row = (TableRowSWT) rows[x];
        if (row == null) {
            continue;
        }
        TRHostTorrent host_torrent = (TRHostTorrent) rows[x].getDataSource(true);
        if (host_torrent == null) {
            continue;
        }
        long uploaded = host_torrent.getTotalUploaded();
        long downloaded = host_torrent.getTotalDownloaded();
        long left = host_torrent.getTotalLeft();
        int seed_count = host_torrent.getSeedCount();
        host_torrent.setData("GUI_PeerCount", new Long(host_torrent.getLeecherCount()));
        host_torrent.setData("GUI_SeedCount", new Long(seed_count));
        host_torrent.setData("GUI_BadNATCount", new Long(host_torrent.getBadNATCount()));
        host_torrent.setData("GUI_Uploaded", new Long(uploaded));
        host_torrent.setData("GUI_Downloaded", new Long(downloaded));
        host_torrent.setData("GUI_Left", new Long(left));
        if (seed_count != 0) {
            Color fg = row.getForeground();
            if (fg != null && fg.equals(Colors.blues[Colors.BLUES_MIDDARK])) {
                row.setForeground(Colors.blues[Colors.BLUES_MIDDARK]);
            }
        }
    }
}
Also used : TableRowSWT(com.biglybt.ui.swt.views.table.TableRowSWT) UIFunctions(com.biglybt.ui.UIFunctions) Color(org.eclipse.swt.graphics.Color) TRHostTorrent(com.biglybt.core.tracker.host.TRHostTorrent)

Aggregations

UIFunctions (com.biglybt.ui.UIFunctions)68 DownloadManager (com.biglybt.core.download.DownloadManager)16 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)9 GridLayout (org.eclipse.swt.layout.GridLayout)9 PluginInterface (com.biglybt.pif.PluginInterface)8 MenuItem (com.biglybt.pif.ui.menus.MenuItem)8 File (java.io.File)8 SelectionEvent (org.eclipse.swt.events.SelectionEvent)8 GridData (org.eclipse.swt.layout.GridData)8 CoreRunningListener (com.biglybt.core.CoreRunningListener)7 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 Menu (org.eclipse.swt.widgets.Menu)7 Core (com.biglybt.core.Core)6 LogEvent (com.biglybt.core.logging.LogEvent)6 UIFunctionsUserPrompter (com.biglybt.ui.UIFunctionsUserPrompter)6 Composite (org.eclipse.swt.widgets.Composite)6 MenuItem (org.eclipse.swt.widgets.MenuItem)6 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)5 GlobalManager (com.biglybt.core.global.GlobalManager)5 LogAlert (com.biglybt.core.logging.LogAlert)5