Search in sources :

Example 61 with UIFunctions

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

the class TorrentUtil method publishTorrents.

public static void publishTorrents(final Object[] download_managers) {
    ListenerDMTask task = new ListenerDMTask(toDMS(download_managers), true, true) {

        @Override
        public void run(DownloadManager dm) {
            ManagerUtils.publish(CoreFactory.getSingleton(), dm);
        }
    };
    task.go();
    UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
    if (uiFunctions != null) {
        uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_MY_TRACKER);
    }
}
Also used : UIFunctions(com.biglybt.ui.UIFunctions) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 62 with UIFunctions

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

the class UpdateMonitor method complete.

@Override
public void complete(final UpdateCheckInstance instance) {
    if (instance.isLowNoise()) {
        handleLowNoise(instance);
        return;
    }
    boolean hasDownloads = false;
    Update[] us = instance.getUpdates();
    for (int i = 0; i < us.length; i++) {
        if (us[i].getDownloaders().length > 0) {
            hasDownloads = true;
            break;
        }
    }
    try {
        int ui = (Integer) instance.getProperty(UpdateCheckInstance.PT_UI_STYLE);
        if (ui == UpdateCheckInstance.PT_UI_STYLE_SIMPLE) {
            new SimpleInstallUI(this, instance);
            return;
        } else if (ui == UpdateCheckInstance.PT_UI_STYLE_NONE) {
            new SilentInstallUI(this, instance);
            return;
        }
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
    // we can get here for either update actions (triggered above) or for plugin
    // install actions (triggered by the plugin installer)
    boolean update_action = instance.getType() == UpdateCheckInstance.UCI_UPDATE;
    UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
    if (uiFunctions != null) {
        uiFunctions.setStatusText("");
    }
    if (hasDownloads) {
        // don't show another update if one's already there!
        UpdateWindow this_window = null;
        boolean autoDownload = COConfigurationManager.getBooleanParameter("update.autodownload");
        if (update_action) {
            if (!autoDownload && (current_update_window == null || current_update_window.isDisposed())) {
                this_window = current_update_window = new UpdateWindow(this, azCore, instance);
            }
        } else {
            // always show an installer window
            this_window = new UpdateWindow(this, azCore, instance);
        }
        if (this_window != null) {
            for (int i = 0; i < us.length; i++) {
                if (us[i].getDownloaders().length > 0) {
                    this_window.addUpdate(us[i]);
                }
            }
            this_window.updateAdditionComplete();
        } else {
            if (autoDownload) {
                new UpdateAutoDownloader(us, new UpdateAutoDownloader.cbCompletion() {

                    @Override
                    public void allUpdatesComplete(boolean requiresRestart, boolean bHadMandatoryUpdates) {
                        Boolean b = (Boolean) instance.getProperty(UpdateCheckInstance.PT_CLOSE_OR_RESTART_ALREADY_IN_PROGRESS);
                        if (b != null && b) {
                            return;
                        }
                        if (requiresRestart) {
                            handleRestart();
                        } else if (bHadMandatoryUpdates) {
                            // no restart and mandatory -> rescan for optional updates now
                            requestRecheck();
                        }
                    }
                });
            } else {
                if (Logger.isEnabled())
                    Logger.log(new LogEvent(LOGID, LogEvent.LT_WARNING, "UpdateMonitor: user dialog already " + "in progress, updates skipped"));
            }
        }
    } else {
        if (Logger.isEnabled())
            Logger.log(new LogEvent(LOGID, "UpdateMonitor: check instance " + "resulted in no user-actionable updates"));
    }
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) UIFunctions(com.biglybt.ui.UIFunctions)

Example 63 with UIFunctions

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

the class SideBar method skinObjectDestroyed.

@Override
public Object skinObjectDestroyed(SWTSkinObject skinObject, Object params) {
    try {
        UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
        if (uiFunctions != null) {
            UIUpdater uiUpdater = uiFunctions.getUIUpdater();
            if (uiUpdater != null) {
                uiUpdater.removeUpdater(this);
            }
        }
    } catch (Exception e) {
        Debug.out(e);
    }
    COConfigurationManager.removeParameterListener("Show Side Bar", configShowSideBarListener);
    COConfigurationManager.removeParameterListener("config.skin.color.sidebar.bg", configBGColorListener);
    if (swtViewListener != null) {
        try {
            UISWTInstanceImpl uiSWTinstance = (UISWTInstanceImpl) UIFunctionsManagerSWT.getUIFunctionsSWT().getUISWTInstance();
            uiSWTinstance.removeSWTViewListener(swtViewListener);
        } catch (Throwable ignore) {
        }
    }
    return super.skinObjectDestroyed(skinObject, params);
}
Also used : UIFunctions(com.biglybt.ui.UIFunctions) UIUpdater(com.biglybt.ui.common.updater.UIUpdater) UISWTInstanceImpl(com.biglybt.ui.swt.pifimpl.UISWTInstanceImpl)

Example 64 with UIFunctions

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

the class ConfigSectionPlugins method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    if (!CoreFactory.isCoreRunning()) {
        Composite cSection = new Composite(parent, SWT.NULL);
        cSection.setLayout(new FillLayout());
        Label lblNotAvail = new Label(cSection, SWT.WRAP);
        Messages.setLanguageText(lblNotAvail, "core.not.available");
        return cSection;
    }
    GridLayout layout;
    GridData gridData;
    Label label;
    ImageLoader imageLoader = ImageLoader.getInstance();
    imgRedLed = imageLoader.getImage("redled");
    imgGreenLed = imageLoader.getImage("greenled");
    Composite infoGroup = new Composite(parent, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    Utils.setLayoutData(infoGroup, gridData);
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    infoGroup.setLayout(layout);
    infoGroup.setLayout(new GridLayout());
    String sep = System.getProperty("file.separator");
    File fUserPluginDir = FileUtil.getUserFile("plugins");
    String sUserPluginDir;
    try {
        sUserPluginDir = fUserPluginDir.getCanonicalPath();
    } catch (Throwable e) {
        sUserPluginDir = fUserPluginDir.toString();
    }
    if (!sUserPluginDir.endsWith(sep)) {
        sUserPluginDir += sep;
    }
    File fAppPluginDir = FileUtil.getApplicationFile("plugins");
    String sAppPluginDir;
    try {
        sAppPluginDir = fAppPluginDir.getCanonicalPath();
    } catch (Throwable e) {
        sAppPluginDir = fAppPluginDir.toString();
    }
    if (!sAppPluginDir.endsWith(sep)) {
        sAppPluginDir += sep;
    }
    label = new Label(infoGroup, SWT.WRAP);
    Utils.setLayoutData(label, new GridData(GridData.FILL_HORIZONTAL));
    Messages.setLanguageText(label, "ConfigView.pluginlist.whereToPut");
    label = new Label(infoGroup, SWT.WRAP);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalIndent = 10;
    Utils.setLayoutData(label, gridData);
    label.setText(sUserPluginDir.replaceAll("&", "&&"));
    label.setForeground(Colors.blue);
    label.setCursor(label.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    final String _sUserPluginDir = sUserPluginDir;
    label.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent arg0) {
            if (_sUserPluginDir.endsWith("/plugins/") || _sUserPluginDir.endsWith("\\plugins\\")) {
                File f = new File(_sUserPluginDir);
                String dir = _sUserPluginDir;
                if (!(f.exists() && f.isDirectory())) {
                    dir = _sUserPluginDir.substring(0, _sUserPluginDir.length() - 9);
                }
                Utils.launch(dir);
            }
        }
    });
    label = new Label(infoGroup, SWT.WRAP);
    Utils.setLayoutData(label, new GridData(GridData.FILL_HORIZONTAL));
    Messages.setLanguageText(label, "ConfigView.pluginlist.whereToPutOr");
    label = new Label(infoGroup, SWT.WRAP);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalIndent = 10;
    Utils.setLayoutData(label, gridData);
    label.setText(sAppPluginDir.replaceAll("&", "&&"));
    label.setForeground(Colors.blue);
    label.setCursor(label.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    final String _sAppPluginDir = sAppPluginDir;
    // TODO : Fix it for windows
    label.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent arg0) {
            if (_sAppPluginDir.endsWith("/plugins/") || _sAppPluginDir.endsWith("\\plugins\\")) {
                File f = new File(_sAppPluginDir);
                if (f.exists() && f.isDirectory()) {
                    Utils.launch(_sAppPluginDir);
                } else {
                    String appDir = _sAppPluginDir.substring(0, _sAppPluginDir.length() - 9);
                    System.out.println(appDir);
                    Utils.launch(appDir);
                }
            }
        }
    });
    pluginIFs = rebuildPluginIFs();
    Collections.sort(pluginIFs, new Comparator() {

        @Override
        public int compare(Object o1, Object o2) {
            return (((PluginInterface) o1).getPluginName().compareToIgnoreCase(((PluginInterface) o2).getPluginName()));
        }
    });
    Label labelInfo = new Label(infoGroup, SWT.WRAP);
    Utils.setLayoutData(labelInfo, new GridData(GridData.FILL_HORIZONTAL));
    Messages.setLanguageText(labelInfo, "ConfigView.pluginlist.info");
    table = new Table(infoGroup, SWT.BORDER | SWT.SINGLE | SWT.CHECK | SWT.VIRTUAL | SWT.FULL_SELECTION);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.heightHint = 200;
    gridData.widthHint = 200;
    Utils.setLayoutData(table, gridData);
    for (int i = 0; i < COLUMN_HEADERS.length; i++) {
        final TableColumn tc = new TableColumn(table, COLUMN_ALIGNS[i]);
        tc.setWidth(Utils.adjustPXForDPI(COLUMN_SIZES[i]));
        tc.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                boolean ascending = comparator.setField(table.indexOf(tc));
                try {
                    table.setSortColumn(tc);
                    table.setSortDirection(ascending ? SWT.UP : SWT.DOWN);
                } catch (NoSuchMethodError ignore) {
                // Ignore Pre 3.0
                }
                Collections.sort(pluginIFs, comparator);
                table.clearAll();
            }
        });
        Messages.setLanguageText(tc, HEADER_PREFIX + COLUMN_HEADERS[i]);
    }
    table.setHeaderVisible(true);
    Composite cButtons = new Composite(infoGroup, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 5;
    cButtons.setLayout(layout);
    Utils.setLayoutData(cButtons, new GridData());
    final Button btnUnload = new Button(cButtons, SWT.PUSH);
    Utils.setLayoutData(btnUnload, new GridData());
    Messages.setLanguageText(btnUnload, "ConfigView.pluginlist.unloadSelected");
    btnUnload.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final int[] items = table.getSelectionIndices();
            new AEThread2("unload") {

                @Override
                public void run() {
                    for (int i = 0; i < items.length; i++) {
                        int index = items[i];
                        if (index >= 0 && index < pluginIFs.size()) {
                            PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
                            if (pluginIF.getPluginState().isOperational()) {
                                if (pluginIF.getPluginState().isUnloadable()) {
                                    try {
                                        pluginIF.getPluginState().unload();
                                    } catch (PluginException e1) {
                                        // TODO Auto-generated catch block
                                        e1.printStackTrace();
                                    }
                                }
                            }
                            Utils.execSWTThread(new Runnable() {

                                @Override
                                public void run() {
                                    pluginIFs = rebuildPluginIFs();
                                    table.setItemCount(pluginIFs.size());
                                    Collections.sort(pluginIFs, comparator);
                                    table.clearAll();
                                }
                            });
                        }
                    }
                }
            }.start();
        }
    });
    btnUnload.setEnabled(false);
    final Button btnLoad = new Button(cButtons, SWT.PUSH);
    Utils.setLayoutData(btnUnload, new GridData());
    Messages.setLanguageText(btnLoad, "ConfigView.pluginlist.loadSelected");
    btnLoad.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final int[] items = table.getSelectionIndices();
            new AEThread2("load") {

                @Override
                public void run() {
                    for (int i = 0; i < items.length; i++) {
                        int index = items[i];
                        if (index >= 0 && index < pluginIFs.size()) {
                            PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
                            // Already loaded.
                            if (pluginIF.getPluginState().isOperational()) {
                                continue;
                            }
                            // initialise.
                            if (pluginIF.getPluginState().isDisabled()) {
                                if (pluginIF.getPluginState().hasFailed()) {
                                    continue;
                                }
                                pluginIF.getPluginState().setDisabled(false);
                            }
                            try {
                                pluginIF.getPluginState().reload();
                            } catch (PluginException e1) {
                                // TODO Auto-generated catch block
                                Debug.printStackTrace(e1);
                            }
                            Utils.execSWTThread(new Runnable() {

                                @Override
                                public void run() {
                                    if (table == null || table.isDisposed()) {
                                        return;
                                    }
                                    pluginIFs = rebuildPluginIFs();
                                    table.setItemCount(pluginIFs.size());
                                    Collections.sort(pluginIFs, comparator);
                                    table.clearAll();
                                }
                            });
                        }
                    }
                }
            }.start();
        }
    });
    btnLoad.setEnabled(false);
    // scan
    final Button btnScan = new Button(cButtons, SWT.PUSH);
    Utils.setLayoutData(btnScan, new GridData());
    Messages.setLanguageText(btnScan, "ConfigView.pluginlist.scan");
    btnScan.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            CoreFactory.getSingleton().getPluginManager().refreshPluginList(false);
            pluginIFs = rebuildPluginIFs();
            table.setItemCount(pluginIFs.size());
            Collections.sort(pluginIFs, comparator);
            table.clearAll();
        }
    });
    // uninstall
    final Button btnUninstall = new Button(cButtons, SWT.PUSH);
    Utils.setLayoutData(btnUninstall, new GridData());
    Messages.setLanguageText(btnUninstall, "ConfigView.pluginlist.uninstallSelected");
    btnUninstall.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            btnUninstall.setEnabled(false);
            final int[] items = table.getSelectionIndices();
            new AEThread2("uninstall") {

                @Override
                public void run() {
                    try {
                        List<PluginInterface> pis = new ArrayList<>();
                        for (int i = 0; i < items.length; i++) {
                            int index = items[i];
                            if (index >= 0 && index < pluginIFs.size()) {
                                PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
                                pis.add(pluginIF);
                            }
                        }
                        if (pis.size() > 0) {
                            PluginInterface[] ps = new PluginInterface[pis.size()];
                            pis.toArray(ps);
                            try {
                                final AESemaphore wait_sem = new AESemaphore("unist:wait");
                                ps[0].getPluginManager().getPluginInstaller().uninstall(ps, new PluginInstallationListener() {

                                    @Override
                                    public void completed() {
                                        wait_sem.release();
                                    }

                                    @Override
                                    public void cancelled() {
                                        wait_sem.release();
                                    }

                                    @Override
                                    public void failed(PluginException e) {
                                        wait_sem.release();
                                    }
                                });
                                wait_sem.reserve();
                            } catch (Exception e) {
                                Debug.printStackTrace(e);
                            }
                        }
                    } finally {
                        Utils.execSWTThread(new Runnable() {

                            @Override
                            public void run() {
                                pluginIFs = rebuildPluginIFs();
                                table.setItemCount(pluginIFs.size());
                                Collections.sort(pluginIFs, comparator);
                                table.clearAll();
                                table.setSelection(new int[0]);
                            }
                        });
                    }
                }
            }.start();
        }
    });
    btnUninstall.setEnabled(false);
    table.addListener(SWT.SetData, new Listener() {

        @Override
        public void handleEvent(Event event) {
            TableItem item = (TableItem) event.item;
            int index = table.indexOf(item);
            PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
            for (int i = 0; i < COLUMN_HEADERS.length; i++) {
                if (i == FilterComparator.FIELD_NAME)
                    item.setImage(i, pluginIF.getPluginState().isOperational() ? imgGreenLed : imgRedLed);
                String sText = comparator.getFieldValue(i, pluginIF);
                if (sText == null)
                    sText = "";
                item.setText(i, sText);
            }
            item.setGrayed(pluginIF.getPluginState().isMandatory());
            boolean bEnabled = pluginIF.getPluginState().isLoadedAtStartup();
            Utils.setCheckedInSetData(item, bEnabled);
            item.setData("PluginID", pluginIF.getPluginID());
            Utils.alternateRowBackground(item);
        }
    });
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            TableItem[] items = table.getSelection();
            if (items.length == 1) {
                int index = table.indexOf(items[0]);
                PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
                PluginConfigModel[] models = pluginIF.getUIManager().getPluginConfigModels();
                for (PluginConfigModel model : models) {
                    if (model.getPluginInterface() == pluginIF) {
                        if (model instanceof BasicPluginConfigModel) {
                            String id = ((BasicPluginConfigModel) model).getSection();
                            UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                            if (uiFunctions != null) {
                                uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, id);
                            }
                        }
                    }
                }
            }
        }
    });
    table.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TableItem item = (TableItem) e.item;
            int index = table.indexOf(item);
            PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
            if (e.detail == SWT.CHECK) {
                if (item.getGrayed()) {
                    if (!item.getChecked())
                        item.setChecked(true);
                    return;
                }
                pluginIF.getPluginState().setDisabled(!item.getChecked());
                pluginIF.getPluginState().setLoadedAtStartup(item.getChecked());
            }
            btnUnload.setEnabled(pluginIF.getPluginState().isOperational() && pluginIF.getPluginState().isUnloadable());
            btnLoad.setEnabled(!pluginIF.getPluginState().isOperational() && !pluginIF.getPluginState().hasFailed());
            btnUninstall.setEnabled(!(pluginIF.getPluginState().isBuiltIn() || pluginIF.getPluginState().isMandatory()));
        }
    });
    table.setItemCount(pluginIFs.size());
    return infoGroup;
}
Also used : ParameterListener(com.biglybt.core.config.ParameterListener) PluginInstallationListener(com.biglybt.pif.installer.PluginInstallationListener) GridLayout(org.eclipse.swt.layout.GridLayout) PluginInstallationListener(com.biglybt.pif.installer.PluginInstallationListener) UIFunctions(com.biglybt.ui.UIFunctions) SelectionEvent(org.eclipse.swt.events.SelectionEvent) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel) PluginConfigModel(com.biglybt.pif.ui.model.PluginConfigModel) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) PluginInterface(com.biglybt.pif.PluginInterface) PluginException(com.biglybt.pif.PluginException) MouseAdapter(org.eclipse.swt.events.MouseAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) PluginException(com.biglybt.pif.PluginException) GridData(org.eclipse.swt.layout.GridData) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) File(java.io.File) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Example 65 with UIFunctions

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

the class SBC_TagsOverview method selected.

@Override
public void selected(TableRowCore[] row) {
    updateSelectedContent();
    UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
    if (uiFunctions != null) {
        uiFunctions.refreshIconBar();
    }
}
Also used : UIFunctions(com.biglybt.ui.UIFunctions)

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