Search in sources :

Example 41 with MessageBoxShell

use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.

the class UIFunctionsImpl method addTorrentWithOptions.

@Override
public boolean addTorrentWithOptions(final TorrentOpenOptions torrentOptions, Map<String, Object> addOptions) {
    Boolean is_silent = (Boolean) addOptions.get(UIFunctions.OTO_SILENT);
    if (is_silent == null) {
        is_silent = UIFunctions.OTO_SILENT_DEFAULT;
    }
    if (CoreFactory.isCoreRunning()) {
        Core core = CoreFactory.getSingleton();
        GlobalManager gm = core.getGlobalManager();
        // Check if torrent already exists in gm, and add if not
        TOTorrent torrent = torrentOptions.getTorrent();
        DownloadManager existingDownload = gm.getDownloadManager(torrent);
        if (existingDownload != null) {
            if (!is_silent) {
                final String fExistingName = existingDownload.getDisplayName();
                final DownloadManager fExistingDownload = existingDownload;
                fExistingDownload.fireGlobalManagerEvent(GlobalManagerEvent.ET_REQUEST_ATTENTION);
                Utils.execSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        boolean can_merge = TorrentUtils.canMergeAnnounceURLs(torrentOptions.getTorrent(), fExistingDownload.getTorrent());
                        long existed_for = SystemTime.getCurrentTime() - fExistingDownload.getCreationTime();
                        Shell mainShell = UIFunctionsManagerSWT.getUIFunctionsSWT().getMainShell();
                        if ((Display.getDefault().getActiveShell() == null || !mainShell.isVisible() || mainShell.getMinimized()) && (!can_merge)) {
                            if (existed_for > 15 * 1000) {
                                new MessageSlideShell(Display.getCurrent(), SWT.ICON_INFORMATION, MSG_ALREADY_EXISTS, null, new String[] { // : prefix is deliberate to disable click on ref in message as might be an unwanted action
                                ":" + torrentOptions.sOriginatingLocation, fExistingName, MessageText.getString(MSG_ALREADY_EXISTS_NAME) }, new Object[] { fExistingDownload }, -1);
                            }
                        } else {
                            if (can_merge) {
                                String text = MessageText.getString(MSG_ALREADY_EXISTS + ".text", new String[] { ":" + torrentOptions.sOriginatingLocation, fExistingName, MessageText.getString(MSG_ALREADY_EXISTS_NAME) });
                                text += "\n\n" + MessageText.getString("openTorrentWindow.mb.alreadyExists.merge");
                                MessageBoxShell mb = new MessageBoxShell(SWT.YES | SWT.NO, MessageText.getString(MSG_ALREADY_EXISTS + ".title"), text);
                                mb.open(new UserPrompterResultListener() {

                                    @Override
                                    public void prompterClosed(int result) {
                                        if (result == SWT.YES) {
                                            TorrentUtils.mergeAnnounceURLs(torrentOptions.getTorrent(), fExistingDownload.getTorrent());
                                        }
                                    }
                                });
                            } else {
                                if (existed_for > 15 * 1000) {
                                    MessageBoxShell mb = new MessageBoxShell(SWT.OK, MSG_ALREADY_EXISTS, new String[] { ":" + torrentOptions.sOriginatingLocation, fExistingName, MessageText.getString(MSG_ALREADY_EXISTS_NAME) });
                                    mb.open(null);
                                }
                            }
                        }
                    }
                });
            }
            if (torrentOptions.getDeleteFileOnCancel()) {
                File torrentFile = new File(torrentOptions.sFileName);
                torrentFile.delete();
            }
            return (true);
        } else {
            try {
                final DownloadStub archived = core.getPluginManager().getDefaultPluginInterface().getDownloadManager().lookupDownloadStub(torrent.getHash());
                if (archived != null) {
                    if (is_silent) {
                        // restore it for them
                        archived.destubbify();
                        if (torrentOptions.getDeleteFileOnCancel()) {
                            File torrentFile = new File(torrentOptions.sFileName);
                            torrentFile.delete();
                        }
                        return (true);
                    } else {
                        Utils.execSWTThread(new AERunnable() {

                            @Override
                            public void runSupport() {
                                Shell mainShell = UIFunctionsManagerSWT.getUIFunctionsSWT().getMainShell();
                                String existingName = archived.getName();
                                if (Display.getDefault().getActiveShell() == null || !mainShell.isVisible() || mainShell.getMinimized()) {
                                    new MessageSlideShell(Display.getCurrent(), SWT.ICON_INFORMATION, "OpenTorrentWindow.mb.inArchive", null, new String[] { existingName }, new Object[0], -1);
                                } else {
                                    MessageBoxShell mb = new MessageBoxShell(SWT.OK, "OpenTorrentWindow.mb.inArchive", new String[] { existingName });
                                    mb.open(null);
                                }
                            }
                        });
                        return (true);
                    }
                }
            } catch (Throwable e) {
                Debug.out(e);
            }
            if (!is_silent) {
                try {
                    DownloadHistoryManager dlm = (DownloadHistoryManager) core.getGlobalManager().getDownloadHistoryManager();
                    final long[] existing = dlm.getDates(torrentOptions.getTorrent().getHash());
                    if (existing != null) {
                        long redownloaded = existing[3];
                        if (SystemTime.getCurrentTime() - redownloaded > 60 * 10 * 1000) {
                            Utils.execSWTThread(new AERunnable() {

                                @Override
                                public void runSupport() {
                                    Shell mainShell = UIFunctionsManagerSWT.getUIFunctionsSWT().getMainShell();
                                    if (mainShell != null && !mainShell.isDisposed()) {
                                        new MessageSlideShell(mainShell.getDisplay(), SWT.ICON_INFORMATION, "OpenTorrentWindow.mb.inHistory", null, new String[] { torrentOptions.getTorrentName(), new SimpleDateFormat().format(new Date(existing[0])) }, new Object[] {}, -1);
                                    }
                                }
                            });
                        }
                    }
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
        }
    }
    Boolean force = (Boolean) addOptions.get(UIFunctions.OTO_FORCE_OPEN);
    if (force == null) {
        force = UIFunctions.OTO_FORCE_OPEN_DEFAULT;
    }
    if (!force) {
        TOTorrent torrent = torrentOptions.getTorrent();
        boolean is_featured = torrent != null && PlatformTorrentUtils.isFeaturedContent(torrent);
        String showAgainMode = COConfigurationManager.getStringParameter(ConfigurationDefaults.CFG_TORRENTADD_OPENOPTIONS);
        if (is_featured || is_silent || (showAgainMode != null && ((showAgainMode.equals(ConfigurationDefaults.CFG_TORRENTADD_OPENOPTIONS_NEVER)) || (showAgainMode.equals(ConfigurationDefaults.CFG_TORRENTADD_OPENOPTIONS_MANY) && torrentOptions.getFiles() != null && torrentOptions.getFiles().length == 1)))) {
            // we're about to silently add the download - ensure that it is going to be saved somewhere vaguely sensible
            // as the current save location is simply taken from the 'default download' config which can be blank (for example)
            boolean looks_good = false;
            String save_loc = torrentOptions.getParentDir().trim();
            if (save_loc.length() == 0) {
            // blank :(
            } else if (save_loc.startsWith(".")) {
            // relative to who knows where
            } else {
                File f = new File(save_loc);
                if (!f.exists()) {
                    f.mkdirs();
                }
                if (f.isDirectory() && FileUtil.canWriteToDirectory(f)) {
                    if (!f.equals(AETemporaryFileHandler.getTempDirectory())) {
                        looks_good = true;
                    }
                }
            }
            if (looks_good) {
                TorrentManagerImpl t_man = TorrentManagerImpl.getSingleton();
                t_man.optionsAdded(torrentOptions);
                t_man.optionsAccepted(torrentOptions);
                boolean ok = TorrentOpener.addTorrent(torrentOptions);
                t_man.optionsRemoved(torrentOptions);
                return (ok);
            }
            torrentOptions.setParentDir("");
            if (is_silent) {
                return (false);
            } else {
                MessageBoxShell mb = new MessageBoxShell(SWT.OK | SWT.ICON_ERROR, "OpenTorrentWindow.mb.invaliddefsave", new String[] { save_loc });
                mb.open(new UserPrompterResultListener() {

                    @Override
                    public void prompterClosed(int result) {
                        OpenTorrentOptionsWindow.addTorrent(torrentOptions);
                    }
                });
            }
            return (true);
        }
    }
    if (is_silent) {
        return (false);
    } else {
        OpenTorrentOptionsWindow.addTorrent(torrentOptions);
        return (true);
    }
}
Also used : DownloadHistoryManager(com.biglybt.core.history.DownloadHistoryManager) MessageSlideShell(com.biglybt.ui.swt.shells.MessageSlideShell) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) TorrentManagerImpl(com.biglybt.pifimpl.local.torrent.TorrentManagerImpl) DownloadManager(com.biglybt.core.download.DownloadManager) Date(java.util.Date) Point(org.eclipse.swt.graphics.Point) DownloadStub(com.biglybt.pif.download.DownloadStub) MessageSlideShell(com.biglybt.ui.swt.shells.MessageSlideShell) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) GlobalManager(com.biglybt.core.global.GlobalManager) TOTorrent(com.biglybt.core.torrent.TOTorrent) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) UISWTViewCore(com.biglybt.ui.swt.pifimpl.UISWTViewCore) Core(com.biglybt.core.Core)

Example 42 with MessageBoxShell

use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.

the class MainMDISetup method setupSideBar.

public static void setupSideBar(final MultipleDocumentInterfaceSWT mdi, final MdiListener l) {
    if (Utils.isAZ2UI()) {
        setupSidebarClassic(mdi);
    } else {
        setupSidebarVuzeUI(mdi);
    }
    SBC_TorrentDetailsView.TorrentDetailMdiEntry.register(mdi);
    PluginInterface pi = PluginInitializer.getDefaultInterface();
    pi.getUIManager().addUIListener(new UIManagerListener2() {

        @Override
        public void UIDetached(UIInstance instance) {
        }

        @Override
        public void UIAttached(UIInstance instance) {
        }

        @Override
        public void UIAttachedComplete(UIInstance instance) {
            PluginInitializer.getDefaultInterface().getUIManager().removeUIListener(this);
            MdiEntry currentEntry = mdi.getCurrentEntry();
            if (currentEntry != null) {
                // User or another plugin selected an entry
                return;
            }
            final String CFG_STARTTAB = "v3.StartTab";
            final String CFG_STARTTAB_DS = "v3.StartTab.ds";
            String startTab;
            String datasource = null;
            boolean showWelcome = false;
            if (showWelcome) {
                startTab = SideBar.SIDEBAR_SECTION_WELCOME;
            } else {
                if (!COConfigurationManager.hasParameter(CFG_STARTTAB, true)) {
                    COConfigurationManager.setParameter(CFG_STARTTAB, SideBar.SIDEBAR_SECTION_LIBRARY);
                }
                startTab = COConfigurationManager.getStringParameter(CFG_STARTTAB);
                datasource = COConfigurationManager.getStringParameter(CFG_STARTTAB_DS, null);
            }
            if (!mdi.loadEntryByID(startTab, true, false, datasource)) {
                mdi.showEntryByID(SideBar.SIDEBAR_SECTION_LIBRARY);
            }
            if (l != null) {
                mdi.addListener(l);
            }
        }
    });
    configBetaEnabledListener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            boolean enabled = COConfigurationManager.getBooleanParameter("Beta Programme Enabled");
            if (enabled) {
                boolean closed = COConfigurationManager.getBooleanParameter("Beta Programme Sidebar Closed");
                if (!closed) {
                    mdi.loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_BETAPROGRAM, false);
                }
            }
        }
    };
    COConfigurationManager.addAndFireParameterListener("Beta Programme Enabled", configBetaEnabledListener);
    mdi.registerEntry(StatsView.VIEW_ID, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_PLUGINS, new StatsView(), id, true, null, null);
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_ALLPEERS, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, new PeersSuperView(), id, true, null, null);
            entry.setImageLeftID("image.sidebar.allpeers");
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_LOGGER, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_PLUGINS, new LoggerView(), id, true, null, null);
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_TAGS, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, id, "tagsview", "{tags.view.heading}", null, null, true, null);
            entry.setImageLeftID("image.sidebar.tag-overview");
            entry.setDefaultExpanded(true);
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_TAG_DISCOVERY, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_SECTION_TAGS, id, "tagdiscoveryview", "{mdi.entry.tagdiscovery}", null, null, true, null);
            entry.setImageLeftID("image.sidebar.tag-overview");
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_CHAT, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            final ViewTitleInfo title_info = new ViewTitleInfo() {

                @Override
                public Object getTitleInfoProperty(int propertyID) {
                    BuddyPluginBeta bp = BuddyPluginUtils.getBetaPlugin();
                    if (bp == null) {
                        return (null);
                    }
                    if (propertyID == TITLE_INDICATOR_TEXT) {
                        int num = 0;
                        for (ChatInstance chat : bp.getChats()) {
                            if (chat.getMessageOutstanding()) {
                                num++;
                            }
                        }
                        if (num > 0) {
                            return (String.valueOf(num));
                        } else {
                            return (null);
                        }
                    } else if (propertyID == TITLE_INDICATOR_COLOR) {
                        for (ChatInstance chat : bp.getChats()) {
                            if (chat.getMessageOutstanding()) {
                                if (chat.hasUnseenMessageWithNick()) {
                                    return (SBC_ChatOverview.COLOR_MESSAGE_WITH_NICK);
                                }
                            }
                        }
                    }
                    return null;
                }
            };
            MdiEntry mdi_entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_DISCOVERY, MultipleDocumentInterface.SIDEBAR_SECTION_CHAT, "chatsview", "{mdi.entry.chatsoverview}", title_info, null, true, null);
            mdi_entry.setImageLeftID("image.sidebar.chat-overview");
            final TimerEventPeriodic timer = SimpleTimer.addPeriodicEvent("sb:chatup", 5 * 1000, new TimerEventPerformer() {

                private String last_text;

                private int[] last_colour;

                @Override
                public void perform(TimerEvent event) {
                    String text = (String) title_info.getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_TEXT);
                    int[] colour = (int[]) title_info.getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_COLOR);
                    boolean changed = text != last_text && (text == null || last_text == null || !text.equals(last_text));
                    if (!changed) {
                        changed = colour != last_colour && (colour == null || last_colour == null || !Arrays.equals(colour, last_colour));
                    }
                    if (changed) {
                        last_text = text;
                        last_colour = colour;
                        mdi_entry.redraw();
                    }
                    ViewTitleInfoManager.refreshTitleInfo(title_info);
                }
            });
            mdi_entry.addListener(new MdiCloseListener() {

                @Override
                public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                    timer.cancel();
                }
            });
            return mdi_entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_ARCHIVED_DOWNLOADS, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            final com.biglybt.pif.download.DownloadManager download_manager = PluginInitializer.getDefaultInterface().getDownloadManager();
            final ViewTitleInfo title_info = new ViewTitleInfo() {

                @Override
                public Object getTitleInfoProperty(int propertyID) {
                    if (propertyID == TITLE_INDICATOR_TEXT) {
                        int num = download_manager.getDownloadStubCount();
                        return (String.valueOf(num));
                    }
                    return null;
                }
            };
            MdiEntry entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, MultipleDocumentInterface.SIDEBAR_SECTION_ARCHIVED_DOWNLOADS, "archivedlsview", "{mdi.entry.archiveddownloadsview}", title_info, null, true, null);
            entry.setImageLeftID("image.sidebar.archive");
            final DownloadStubListener stub_listener = new DownloadStubListener() {

                @Override
                public void downloadStubEventOccurred(DownloadStubEvent event) {
                    ViewTitleInfoManager.refreshTitleInfo(title_info);
                }
            };
            download_manager.addDownloadStubListener(stub_listener, false);
            entry.addListener(new MdiCloseListener() {

                @Override
                public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                    download_manager.removeDownloadStubListener(stub_listener);
                }
            });
            entry.addListener(new MdiEntryDropListener() {

                @Override
                public boolean mdiEntryDrop(MdiEntry entry, Object data) {
                    if (data instanceof String) {
                        String str = (String) data;
                        if (str.startsWith("DownloadManager\n")) {
                            String[] bits = str.split("\n");
                            com.biglybt.pif.download.DownloadManager dm = PluginInitializer.getDefaultInterface().getDownloadManager();
                            List<Download> downloads = new ArrayList<>();
                            boolean failed = false;
                            for (int i = 1; i < bits.length; i++) {
                                byte[] hash = Base32.decode(bits[i]);
                                try {
                                    Download download = dm.getDownload(hash);
                                    if (download.canStubbify()) {
                                        downloads.add(download);
                                    } else {
                                        failed = true;
                                    }
                                } catch (Throwable e) {
                                }
                            }
                            final boolean f_failed = failed;
                            ManagerUtils.moveToArchive(downloads, new ManagerUtils.ArchiveCallback() {

                                boolean error = f_failed;

                                @Override
                                public void failed(DownloadStub original, Throwable e) {
                                    error = true;
                                }

                                @Override
                                public void completed() {
                                    if (error) {
                                        String title = MessageText.getString("archive.failed.title");
                                        String text = MessageText.getString("archive.failed.text");
                                        MessageBoxShell prompter = new MessageBoxShell(title, text, new String[] { MessageText.getString("Button.ok") }, 0);
                                        prompter.setAutoCloseInMS(0);
                                        prompter.open(null);
                                    }
                                }
                            });
                        }
                        return (true);
                    }
                    return false;
                }
            });
            return entry;
        }
    });
    // download history
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_DOWNLOAD_HISTORY, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            final DownloadHistoryManager history_manager = (DownloadHistoryManager) CoreFactory.getSingleton().getGlobalManager().getDownloadHistoryManager();
            final ViewTitleInfo title_info = new ViewTitleInfo() {

                @Override
                public Object getTitleInfoProperty(int propertyID) {
                    if (propertyID == TITLE_INDICATOR_TEXT) {
                        if (history_manager == null) {
                            return (null);
                        } else if (history_manager.isEnabled()) {
                            int num = history_manager.getHistoryCount();
                            return (String.valueOf(num));
                        } else {
                            return (MessageText.getString("label.disabled"));
                        }
                    }
                    return null;
                }
            };
            MdiEntry entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, MultipleDocumentInterface.SIDEBAR_SECTION_DOWNLOAD_HISTORY, "downloadhistoryview", "{mdi.entry.downloadhistoryview}", title_info, null, true, null);
            entry.setImageLeftID("image.sidebar.logview");
            if (history_manager != null) {
                final DownloadHistoryListener history_listener = new DownloadHistoryListener() {

                    @Override
                    public void downloadHistoryEventOccurred(DownloadHistoryEvent event) {
                        ViewTitleInfoManager.refreshTitleInfo(title_info);
                    }
                };
                history_manager.addListener(history_listener, false);
                entry.addListener(new MdiCloseListener() {

                    @Override
                    public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                        history_manager.removeListener(history_listener);
                    }
                });
            }
            return entry;
        }
    });
    // torrent options
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, TorrentOptionsView.class, MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, true, null, null);
            entry.setImageLeftID("image.sidebar.torrentoptions");
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_MY_SHARES, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, MySharesView.class, MultipleDocumentInterface.SIDEBAR_SECTION_MY_SHARES, true, null, null);
            entry.setImageLeftID("image.sidebar.myshares");
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_MY_TRACKER, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, MyTrackerView.class, MultipleDocumentInterface.SIDEBAR_SECTION_MY_TRACKER, true, null, null);
            entry.setImageLeftID("image.sidebar.mytracker");
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_CLIENT_STATS, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_PLUGINS, ClientStatsView.class, MultipleDocumentInterface.SIDEBAR_SECTION_CLIENT_STATS, true, null, null);
            entry.setImageLeftID("image.sidebar.clientstats");
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, new MdiEntryCreationListener2() {

        @Override
        public MdiEntry createMDiEntry(MultipleDocumentInterface mdi, String id, Object datasource, Map<?, ?> params) {
            String section = (datasource instanceof String) ? ((String) datasource) : null;
            boolean uiClassic = COConfigurationManager.getStringParameter("ui").equals("az2");
            if (uiClassic || COConfigurationManager.getBooleanParameter("Show Options In Side Bar")) {
                MdiEntry entry = ((MultipleDocumentInterfaceSWT) mdi).createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_PLUGINS, ConfigView.class, MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, true, null, null);
                entry.setImageLeftID("image.sidebar.config");
                return entry;
            }
            ConfigShell.getInstance().open(section);
            return null;
        }
    });
    try {
        if (!COConfigurationManager.getBooleanParameter("my.shares.view.auto.open.done", false)) {
            final ShareManager share_manager = pi.getShareManager();
            if (share_manager.getShares().length > 0) {
            // stop showing this by default
            // mdi.showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_MY_SHARES);
            } else {
                shareManagerListener = new ShareManagerListener() {

                    boolean done = false;

                    @Override
                    public void resourceModified(ShareResource old_resource, ShareResource new_resource) {
                    }

                    @Override
                    public void resourceDeleted(ShareResource resource) {
                    }

                    @Override
                    public void resourceAdded(ShareResource resource) {
                        if (done) {
                            return;
                        }
                        done = true;
                        share_manager.removeListener(this);
                        COConfigurationManager.setParameter("my.shares.view.auto.open.done", true);
                        mdi.loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_MY_SHARES, false);
                    }

                    @Override
                    public void reportProgress(int percent_complete) {
                    }

                    @Override
                    public void reportCurrentTask(String task_description) {
                    }
                };
                share_manager.addListener(shareManagerListener);
            }
        }
    } catch (Throwable t) {
    }
    try {
        if (!COConfigurationManager.getBooleanParameter("my.tracker.view.auto.open.done", false)) {
            // Load Tracker View on first host of file
            TRHost trackerHost = CoreFactory.getSingleton().getTrackerHost();
            trackerHostListener = new TRHostListener() {

                boolean done = false;

                @Override
                public void torrentRemoved(TRHostTorrent t) {
                }

                @Override
                public void torrentChanged(TRHostTorrent t) {
                }

                @Override
                public void torrentAdded(TRHostTorrent t) {
                    if (done) {
                        return;
                    }
                    done = true;
                    trackerHost.removeListener(this);
                    COConfigurationManager.setParameter("my.tracker.view.auto.open.done", true);
                    mdi.loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_MY_TRACKER, false);
                }

                @Override
                public boolean handleExternalRequest(InetSocketAddress client_address, String user, String url, URL absolute_url, String header, InputStream is, OutputStream os, AsyncController async) throws IOException {
                    return false;
                }
            };
            trackerHost.addListener(trackerHostListener);
        }
    } catch (Throwable t) {
    }
    UIManager uim = pi.getUIManager();
    if (uim != null) {
        MenuItem menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "tags.view.heading");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TAGS);
            }
        });
        menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "tag.discovery.view.heading");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TAG_DISCOVERY);
            }
        });
        menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "chats.view.heading");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CHAT);
            }
        });
        menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "archivedlsview.view.heading");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_ARCHIVED_DOWNLOADS);
            }
        });
        menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "downloadhistoryview.view.heading");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_DOWNLOAD_HISTORY);
            }
        });
    }
// System.out.println("Activate sidebar " + startTab + " took "
// + (SystemTime.getCurrentTime() - startTime) + "ms");
// startTime = SystemTime.getCurrentTime();
}
Also used : TimerEventPeriodic(com.biglybt.core.util.TimerEventPeriodic) DownloadHistoryManager(com.biglybt.core.history.DownloadHistoryManager) ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) InetSocketAddress(java.net.InetSocketAddress) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) UIManager(com.biglybt.pif.ui.UIManager) UIManagerListener2(com.biglybt.pif.ui.UIManagerListener2) DownloadStub(com.biglybt.pif.download.DownloadStub) TimerEventPerformer(com.biglybt.core.util.TimerEventPerformer) TimerEvent(com.biglybt.core.util.TimerEvent) ShareManagerListener(com.biglybt.pif.sharing.ShareManagerListener) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UIInstance(com.biglybt.pif.ui.UIInstance) StatsView(com.biglybt.ui.swt.views.stats.StatsView) ClientStatsView(com.biglybt.ui.swt.views.clientstats.ClientStatsView) TRHostTorrent(com.biglybt.core.tracker.host.TRHostTorrent) DownloadStubEvent(com.biglybt.pif.download.DownloadStubEvent) TRHost(com.biglybt.core.tracker.host.TRHost) DownloadHistoryListener(com.biglybt.core.history.DownloadHistoryListener) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo) AsyncController(com.biglybt.core.util.AsyncController) ShareManager(com.biglybt.pif.sharing.ShareManager) ManagerUtils(com.biglybt.ui.swt.views.utils.ManagerUtils) URL(java.net.URL) DownloadHistoryEvent(com.biglybt.core.history.DownloadHistoryEvent) BuddyPluginBeta(com.biglybt.plugin.net.buddy.BuddyPluginBeta) Download(com.biglybt.pif.download.Download) ShareResource(com.biglybt.pif.sharing.ShareResource) InputStream(java.io.InputStream) PluginInterface(com.biglybt.pif.PluginInterface) DownloadStubListener(com.biglybt.pif.download.DownloadStubListener) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) MenuItem(com.biglybt.pif.ui.menus.MenuItem) IOException(java.io.IOException) TRHostListener(com.biglybt.core.tracker.host.TRHostListener) ParameterListener(com.biglybt.core.config.ParameterListener) ClientStatsView(com.biglybt.ui.swt.views.clientstats.ClientStatsView)

Example 43 with MessageBoxShell

use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.

the class UIMessageImpl method ask0.

private int ask0() {
    int style = 0;
    switch(this.input_type) {
        case INPUT_OK_CANCEL:
            style |= SWT.CANCEL;
        case INPUT_OK:
            style |= SWT.OK;
            break;
        case INPUT_RETRY_CANCEL_IGNORE:
            style |= SWT.IGNORE;
        case INPUT_RETRY_CANCEL:
            style |= SWT.RETRY;
            style |= SWT.CANCEL;
            break;
        case INPUT_YES_NO_CANCEL:
            style |= SWT.CANCEL;
        case INPUT_YES_NO:
            style |= SWT.YES;
            style |= SWT.NO;
            break;
    }
    switch(this.message_type) {
        case MSG_ERROR:
            style |= SWT.ICON_ERROR;
            break;
        case MSG_INFO:
            style |= SWT.ICON_INFORMATION;
            break;
        case MSG_QUESTION:
            style |= SWT.ICON_QUESTION;
            break;
        case MSG_WARN:
            style |= SWT.ICON_WARNING;
            break;
        case MSG_WORKING:
            style |= SWT.ICON_WORKING;
            break;
    }
    MessageBoxShell mb = new MessageBoxShell(style, this.title, this.messagesAsString());
    mb.open(null);
    int result = mb.waitUntilClosed();
    switch(result) {
        case SWT.OK:
            return ANSWER_OK;
        case SWT.YES:
            return ANSWER_YES;
        case SWT.NO:
            return ANSWER_NO;
        case SWT.ABORT:
            return ANSWER_ABORT;
        case SWT.RETRY:
            return ANSWER_RETRY;
        case SWT.IGNORE:
            return ANSWER_IGNORE;
        default:
            // Cancel if anything else is returned.
            return ANSWER_CANCEL;
    }
}
Also used : MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell)

Example 44 with MessageBoxShell

use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.

the class UISWTInstanceImpl method eventOccurred.

@Override
public boolean eventOccurred(final UIManagerEvent event) {
    boolean done = true;
    final Object data = event.getData();
    switch(event.getType()) {
        case UIManagerEvent.ET_SHOW_TEXT_MESSAGE:
            {
                Utils.execSWTThread(new Runnable() {

                    @Override
                    public void run() {
                        String[] params = (String[]) data;
                        new TextViewerWindow(params[0], params[1], params[2]);
                    }
                });
                break;
            }
        case UIManagerEvent.ET_SHOW_MSG_BOX:
            {
                final int[] result = { UIManagerEvent.MT_NONE };
                Utils.execSWTThread(new Runnable() {

                    @Override
                    public void run() {
                        UIFunctionsManagerSWT.getUIFunctionsSWT().bringToFront();
                        Object[] params = (Object[]) data;
                        long _styles = ((Long) (params[2])).longValue();
                        int styles = 0;
                        int def = 0;
                        if ((_styles & UIManagerEvent.MT_YES) != 0) {
                            styles |= SWT.YES;
                        }
                        if ((_styles & UIManagerEvent.MT_YES_DEFAULT) != 0) {
                            styles |= SWT.YES;
                            def = SWT.YES;
                        }
                        if ((_styles & UIManagerEvent.MT_NO) != 0) {
                            styles |= SWT.NO;
                        }
                        if ((_styles & UIManagerEvent.MT_NO_DEFAULT) != 0) {
                            styles |= SWT.NO;
                            def = SWT.NO;
                        }
                        if ((_styles & UIManagerEvent.MT_OK) != 0) {
                            styles |= SWT.OK;
                        }
                        if ((_styles & UIManagerEvent.MT_OK_DEFAULT) != 0) {
                            styles |= SWT.OK;
                            def = SWT.OK;
                        }
                        if ((_styles & UIManagerEvent.MT_CANCEL) != 0) {
                            styles |= SWT.CANCEL;
                        }
                        MessageBoxShell mb = new MessageBoxShell(styles, MessageText.getString((String) params[0]), MessageText.getString((String) params[1]));
                        if (def != 0) {
                            mb.setDefaultButtonUsingStyle(def);
                        }
                        if (params.length == 4 && params[3] instanceof Map) {
                            Map<String, Object> options = (Map<String, Object>) params[3];
                            String rememberID = (String) options.get(UIManager.MB_PARAM_REMEMBER_ID);
                            Boolean rememberByDefault = (Boolean) options.get(UIManager.MB_PARAM_REMEMBER_BY_DEF);
                            String rememberText = (String) options.get(UIManager.MB_PARAM_REMEMBER_RES);
                            if (rememberID != null && rememberByDefault != null && rememberText != null) {
                                mb.setRemember(rememberID, rememberByDefault, rememberText);
                                Number rememberIfOnlyButton = (Number) options.get(UIManager.MB_PARAM_REMEMBER_IF_ONLY_BUTTON);
                                if (rememberIfOnlyButton != null) {
                                    mb.setRememberOnlyIfButton(rememberIfOnlyButton.intValue());
                                }
                            }
                            Number auto_close_ms = (Number) options.get(UIManager.MB_PARAM_AUTO_CLOSE_MS);
                            if (auto_close_ms != null) {
                                mb.setAutoCloseInMS(auto_close_ms.intValue());
                            }
                        } else if (params.length >= 6) {
                            String rememberID = (String) params[3];
                            Boolean rememberByDefault = (Boolean) params[4];
                            String rememberText = (String) params[5];
                            if (rememberID != null && rememberByDefault != null && rememberText != null) {
                                mb.setRemember(rememberID, rememberByDefault, rememberText);
                            }
                        }
                        mb.open(null);
                        int _r = mb.waitUntilClosed();
                        int r = 0;
                        if ((_r & SWT.YES) != 0) {
                            r |= UIManagerEvent.MT_YES;
                        }
                        if ((_r & SWT.NO) != 0) {
                            r |= UIManagerEvent.MT_NO;
                        }
                        if ((_r & SWT.OK) != 0) {
                            r |= UIManagerEvent.MT_OK;
                        }
                        if ((_r & SWT.CANCEL) != 0) {
                            r |= UIManagerEvent.MT_CANCEL;
                        }
                        result[0] = r;
                    }
                }, false);
                event.setResult(new Long(result[0]));
                break;
            }
        case UIManagerEvent.ET_OPEN_TORRENT_VIA_FILE:
            {
                TorrentOpener.openTorrent(((File) data).toString());
                break;
            }
        case UIManagerEvent.ET_OPEN_TORRENT_VIA_TORRENT:
            {
                Torrent t = (Torrent) data;
                try {
                    File f = AETemporaryFileHandler.createTempFile();
                    t.writeToFile(f);
                    TorrentOpener.openTorrent(f.toString());
                } catch (Throwable e) {
                    Debug.printStackTrace(e);
                }
                break;
            }
        case UIManagerEvent.ET_OPEN_TORRENT_VIA_URL:
            {
                Display display = Utils.getDisplay();
                display.syncExec(new AERunnable() {

                    @Override
                    public void runSupport() {
                        Object[] params = (Object[]) data;
                        URL target = (URL) params[0];
                        URL referrer = (URL) params[1];
                        boolean auto_download = ((Boolean) params[2]).booleanValue();
                        Map<?, ?> request_properties = (Map<?, ?>) params[3];
                        if (auto_download) {
                            final Shell shell = uiFunctions.getMainShell();
                            if (shell != null) {
                                final List<String> alt_uris = new ArrayList<>();
                                if (request_properties != null) {
                                    request_properties = new HashMap(request_properties);
                                    for (int i = 1; i < 16; i++) {
                                        String key = "X-Alternative-URI-" + i;
                                        String uri = (String) request_properties.remove(key);
                                        if (uri != null) {
                                            alt_uris.add(uri);
                                        } else {
                                            break;
                                        }
                                    }
                                }
                                final Map<?, ?> f_request_properties = request_properties;
                                new FileDownloadWindow(shell, target.toString(), referrer == null ? null : referrer.toString(), request_properties, new Runnable() {

                                    int alt_index = 0;

                                    @Override
                                    public void run() {
                                        if (alt_index < alt_uris.size()) {
                                            String alt_target = alt_uris.get(alt_index++);
                                            new FileDownloadWindow(shell, alt_target, null, f_request_properties, this);
                                        }
                                    }
                                });
                            }
                        } else {
                            // TODO: handle referrer?
                            TorrentOpener.openTorrent(target.toString());
                        }
                    }
                });
                break;
            }
        case UIManagerEvent.ET_PLUGIN_VIEW_MODEL_CREATED:
            {
                if (data instanceof BasicPluginViewModel) {
                    BasicPluginViewModel model = (BasicPluginViewModel) data;
                    // property bundles can't handle spaces in keys
                    // 
                    // If this behaviour changes, change the openView(model)
                    // method lower down.
                    String sViewID = model.getName().replaceAll(" ", ".");
                    BasicPluginViewImpl view = new BasicPluginViewImpl(model);
                    addView(UISWTInstance.VIEW_MAIN, sViewID, view);
                }
                break;
            }
        case UIManagerEvent.ET_PLUGIN_VIEW_MODEL_DESTROYED:
            {
                if (data instanceof BasicPluginViewModel) {
                    BasicPluginViewModel model = (BasicPluginViewModel) data;
                    // property bundles can't handle spaces in keys
                    // 
                    // If this behaviour changes, change the openView(model)
                    // method lower down.
                    String sViewID = model.getName().replaceAll(" ", ".");
                    removeViews(UISWTInstance.VIEW_MAIN, sViewID);
                }
                break;
            }
        case UIManagerEvent.ET_PLUGIN_CONFIG_MODEL_CREATED:
            {
                if (data instanceof BasicPluginConfigModel) {
                    BasicPluginConfigModel model = (BasicPluginConfigModel) data;
                    BasicPluginConfigImpl view = new BasicPluginConfigImpl(new WeakReference<>(model));
                    config_view_map.put(model, view);
                    ConfigSectionRepository.getInstance().addConfigSection(view, model.getPluginInterface());
                }
                break;
            }
        case UIManagerEvent.ET_PLUGIN_CONFIG_MODEL_DESTROYED:
            {
                if (data instanceof BasicPluginConfigModel) {
                    BasicPluginConfigModel model = (BasicPluginConfigModel) data;
                    BasicPluginConfigImpl view = config_view_map.get(model);
                    if (view != null) {
                        ConfigSectionRepository.getInstance().removeConfigSection(view);
                    }
                }
                break;
            }
        case UIManagerEvent.ET_COPY_TO_CLIPBOARD:
            {
                ClipboardCopy.copyToClipBoard((String) data);
                break;
            }
        case UIManagerEvent.ET_OPEN_URL:
            {
                Utils.launch(((URL) data).toExternalForm());
                break;
            }
        case UIManagerEvent.ET_SHOW_CONFIG_SECTION:
            {
                event.setResult(Boolean.FALSE);
                if (!(data instanceof String)) {
                    break;
                }
                event.setResult(Boolean.TRUE);
                uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, data);
                break;
            }
        case UIManagerEvent.ET_FILE_OPEN:
            {
                File file_to_use = (File) data;
                Utils.launch(file_to_use.getAbsolutePath());
                break;
            }
        case UIManagerEvent.ET_FILE_SHOW:
            {
                File file_to_use = (File) data;
                final boolean use_open_containing_folder = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
                ManagerUtils.open(file_to_use, use_open_containing_folder);
                break;
            }
        case UIManagerEvent.ET_HIDE_ALL:
            {
                boolean hide = (Boolean) data;
                uiFunctions.setHideAll(hide);
                break;
            }
        case UIManagerEvent.ET_HIDE_ALL_TOGGLE:
            {
                uiFunctions.setHideAll(!uiFunctions.getHideAll());
                break;
            }
        default:
            {
                done = false;
                break;
            }
    }
    return (done);
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) Torrent(com.biglybt.pif.torrent.Torrent) BasicPluginViewModel(com.biglybt.pif.ui.model.BasicPluginViewModel) URL(java.net.URL) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) Shell(org.eclipse.swt.widgets.Shell) WeakReference(java.lang.ref.WeakReference) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) AERunnable(com.biglybt.core.util.AERunnable) File(java.io.File) Display(org.eclipse.swt.widgets.Display) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Example 45 with MessageBoxShell

use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.

the class NameItem method inplaceValueSet.

@Override
public boolean inplaceValueSet(TableCell cell, String value, boolean finalEdit) {
    if (value.equalsIgnoreCase(cell.getText()) || "".equals(value) || "".equals(cell.getText()))
        return true;
    final DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) cell.getDataSource();
    final File target;
    try {
        target = new File(fileInfo.getFile(true).getParentFile(), value).getCanonicalFile();
    } catch (IOException e) {
        return false;
    }
    if (!finalEdit)
        return !target.exists();
    if (target.exists())
        return false;
    // code stolen from FilesView
    final boolean[] result = { false };
    boolean paused = fileInfo.getDownloadManager().pause();
    FileUtil.runAsTask(new CoreOperationTask() {

        @Override
        public void run(CoreOperation operation) {
            result[0] = fileInfo.setLink(target);
        }

        @Override
        public ProgressCallback getProgressCallback() {
            return null;
        }
    });
    if (paused)
        fileInfo.getDownloadManager().resume();
    if (!result[0]) {
        new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("FilesView.rename.failed.title"), MessageText.getString("FilesView.rename.failed.text")).open(null);
    }
    return true;
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) CoreOperation(com.biglybt.core.CoreOperation) CoreOperationTask(com.biglybt.core.CoreOperationTask) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) IOException(java.io.IOException) File(java.io.File)

Aggregations

MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)53 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)24 File (java.io.File)10 ArrayList (java.util.ArrayList)7 GridData (org.eclipse.swt.layout.GridData)7 DownloadManager (com.biglybt.core.download.DownloadManager)6 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 Map (java.util.Map)5 TOTorrent (com.biglybt.core.torrent.TOTorrent)4 TOTorrentFile (com.biglybt.core.torrent.TOTorrentFile)4 AERunnable (com.biglybt.core.util.AERunnable)4 UIInputReceiver (com.biglybt.pif.ui.UIInputReceiver)4 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)4 URL (java.net.URL)4 HashMap (java.util.HashMap)4 List (java.util.List)4 MouseAdapter (org.eclipse.swt.events.MouseAdapter)4 MouseEvent (org.eclipse.swt.events.MouseEvent)4 Point (org.eclipse.swt.graphics.Point)4