Search in sources :

Example 46 with MessageBoxShell

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

the class Initializer method run.

@Override
public void run() {
    DelayedTask delayed_task = UtilitiesImpl.addDelayedTask("SWT Initialisation", new Runnable() {

        @Override
        public void run() {
            init_task.reserve();
        }
    });
    delayed_task.queueFirst();
    // initialise the SWT locale util
    long startTime = SystemTime.getCurrentTime();
    new LocaleUtilSWT(core);
    final Display display = Utils.getDisplay();
    new UIMagnetHandler(core);
    if (!STARTUP_UIFIRST) {
        // Ensure colors initialized
        Colors.getInstance();
        UIConfigDefaultsSWT.initialize();
        UIConfigDefaultsSWTv3.initialize(core);
    } else {
        COConfigurationManager.setBooleanDefault("Show Splash", false);
    }
    if (COConfigurationManager.getBooleanParameter("Show Splash")) {
        display.asyncExec(new AERunnable() {

            @Override
            public void runSupport() {
                new SplashWindow(display, Initializer.this);
            }
        });
    }
    System.out.println("Locale Initializing took " + (SystemTime.getCurrentTime() - startTime) + "ms");
    startTime = SystemTime.getCurrentTime();
    core.addLifecycleListener(new CoreLifecycleAdapter() {

        @Override
        public void componentCreated(Core core, CoreComponent component) {
            Initializer.this.reportPercent(curPercent + 1);
            if (component instanceof GlobalManager) {
                reportCurrentTaskByKey("splash.initializePlugins");
                InitialisationFunctions.earlyInitialisation(core);
            } else if (component instanceof PluginInterface) {
                PluginInterface pi = (PluginInterface) component;
                String name = pi.getPluginName();
                String version = pi.getPluginVersion();
                // text says initializing, but it's actually initialized.  close enough
                String s = MessageText.getString("splash.plugin.init") + " " + name + (version == null ? "" : (" v" + version));
                reportCurrentTask(s);
            }
        }

        // @see com.biglybt.core.CoreLifecycleAdapter#started(com.biglybt.core.Core)
        @Override
        public void started(Core core) {
            handleCoreStarted(core);
        }

        @Override
        public void stopping(Core core) {
            Alerts.stopInitiated();
        }

        @Override
        public void stopped(Core core) {
        }

        @Override
        public boolean syncInvokeRequired() {
            return (true);
        }

        @Override
        public boolean requiresPluginInitCompleteBeforeStartedEvent() {
            return (false);
        }

        @Override
        public boolean stopRequested(Core _core) throws CoreException {
            return handleStopRestart(false);
        }

        @Override
        public boolean restartRequested(final Core core) {
            return handleStopRestart(true);
        }
    });
    reportCurrentTaskByKey("splash.initializeCore");
    boolean uiClassic = COConfigurationManager.getStringParameter("ui").equals("az2");
    try {
        new SearchUI();
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
    try {
        subscriptionManagerUI = new SubscriptionManagerUI();
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
    if (!uiClassic) {
        try {
            deviceManagerUI = new DeviceManagerUI(core);
        } catch (Throwable e) {
            Debug.printStackTrace(e);
        }
    }
    if (core.canStart()) {
        // Other UIs could start the core before us
        if (!core.isStarted()) {
            core.start();
        } else {
            handleCoreStarted(core);
        }
        reportPercent(50);
        System.out.println("Core Initializing took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        reportCurrentTaskByKey("splash.initializeUIElements");
        // Ensure colors initialized
        Colors.getInstance();
        reportPercent(curPercent + 1);
        Alerts.init();
        reportPercent(curPercent + 1);
        ProgressWindow.register(core);
        reportPercent(curPercent + 1);
        new SWTNetworkSelection();
        reportPercent(curPercent + 1);
        new AuthenticatorWindow();
        new CryptoWindow();
        reportPercent(curPercent + 1);
        new CertificateTrustWindow();
        core.getPluginManager().getPluginInstaller().addListener(new PluginInstallerListener() {

            @Override
            public boolean installRequest(final String reason, final InstallablePlugin plugin) throws PluginException {
                if (plugin instanceof StandardPlugin) {
                    Map<Integer, Object> properties = new HashMap<>();
                    properties.put(UpdateCheckInstance.PT_UI_EXTRA_MESSAGE, reason);
                    plugin.install(false, false, false, properties);
                    return (true);
                } else {
                    return (false);
                }
            }
        });
    } else {
        CoreWaiterSWT.startupAbandoned();
        final AESemaphore sem = new AESemaphore("waiter");
        Utils.execSWTThread(new Runnable() {

            @Override
            public void run() {
                MessageBoxShell mb = new MessageBoxShell(MessageText.getString("msgbox.force.close.title"), MessageText.getString("msgbox.force.close.text", new String[] { core.getLockFile().getAbsolutePath() }), new String[] { MessageText.getString("Button.ok") }, 0);
                mb.setIconResource("error");
                mb.setModal(true);
                mb.open(new UserPrompterResultListener() {

                    @Override
                    public void prompterClosed(int result) {
                        sem.releaseForever();
                    }
                });
            }
        });
        sem.reserve();
        SESecurityManager.exitVM(1);
    }
}
Also used : DeviceManagerUI(com.biglybt.ui.swt.devices.DeviceManagerUI) PluginInstallerListener(com.biglybt.pif.installer.PluginInstallerListener) AuthenticatorWindow(com.biglybt.ui.swt.auth.AuthenticatorWindow) SearchUI(com.biglybt.ui.swt.search.SearchUI) CertificateTrustWindow(com.biglybt.ui.swt.auth.CertificateTrustWindow) GlobalManager(com.biglybt.core.global.GlobalManager) DelayedTask(com.biglybt.pif.utils.DelayedTask) SubscriptionManagerUI(com.biglybt.ui.swt.subscriptions.SubscriptionManagerUI) PluginInterface(com.biglybt.pif.PluginInterface) PluginException(com.biglybt.pif.PluginException) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) StandardPlugin(com.biglybt.pif.installer.StandardPlugin) InstallablePlugin(com.biglybt.pif.installer.InstallablePlugin) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) CryptoWindow(com.biglybt.ui.swt.auth.CryptoWindow) SWTNetworkSelection(com.biglybt.ui.swt.networks.SWTNetworkSelection) Map(java.util.Map) HashMap(java.util.HashMap) Display(org.eclipse.swt.widgets.Display)

Example 47 with MessageBoxShell

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

the class TorrentUtil method removeDownloadStubs.

public static void removeDownloadStubs(final DownloadStubEx[] dms, final AERunnable deleteFailed, final boolean forcePrompt) {
    if (dms == null) {
        return;
    }
    for (int i = 0; i < dms.length; i++) {
        DownloadStubEx dm = dms[i];
        boolean deleteTorrent = COConfigurationManager.getBooleanParameter("def.deletetorrent");
        int confirm = COConfigurationManager.getIntParameter("tb.confirm.delete.content");
        boolean doPrompt = confirm == 0 | forcePrompt;
        if (doPrompt) {
            String title = MessageText.getString("deletedata.title");
            String text = MessageText.getString("v3.deleteContent.message", new String[] { dm.getName() });
            String[] buttons;
            int defaultButtonPos;
            buttons = new String[] { MessageText.getString("Button.cancel"), MessageText.getString("Button.deleteContent.fromComputer"), MessageText.getString("Button.deleteContent.fromLibrary") };
            /*
				int[] buttonVals = new int[] {
					SWT.CANCEL,
					1,
					2
				};
				*/
            defaultButtonPos = 2;
            final MessageBoxShell mb = new MessageBoxShell(title, text, buttons, defaultButtonPos);
            int numLeft = (dms.length - i);
            if (numLeft > 1) {
                mb.setRemember("na", false, MessageText.getString("v3.deleteContent.applyToAll", new String[] { "" + numLeft }));
                // never store remember state
                mb.setRememberOnlyIfButton(-3);
            }
            mb.setRelatedObject(dm);
            mb.setLeftImage("image.trash");
            mb.addCheckBox("deletecontent.also.deletetorrent", 2, deleteTorrent);
            final int index = i;
            mb.open(new UserPrompterResultListener() {

                @Override
                public void prompterClosed(int result) {
                    ImageLoader.getInstance().releaseImage("image.trash");
                    removeDownloadStubsPrompterClosed(dms, index, deleteFailed, result, mb.isRemembered(), mb.getCheckBoxEnabled());
                }
            });
            return;
        } else {
            boolean deleteData = confirm == 1;
            removeDownloadStubsPrompterClosed(dms, i, deleteFailed, deleteData ? 1 : 2, true, deleteTorrent);
        }
    }
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) DownloadStubEx(com.biglybt.pif.download.DownloadStub.DownloadStubEx)

Example 48 with MessageBoxShell

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

the class TorrentUtil method isFileTorrent.

/**
 * quick check to see if a file might be a torrent
 * @param torrentFile
 * @return
 *
 * @since 3.0.2.3
 */
public static boolean isFileTorrent(String originatingLocation, File torrentFile, String torrentName, boolean warnOnError) {
    String sFirstChunk = null;
    try {
        sFirstChunk = FileUtil.readFileAsString(torrentFile, 16384).toLowerCase();
        try {
            if (!sFirstChunk.startsWith("d")) {
                sFirstChunk = FileUtil.readGZippedFileAsString(torrentFile, 16384).toLowerCase();
            }
        } catch (Throwable e) {
        }
    } catch (IOException e) {
        Debug.out("warning", e);
    }
    if (sFirstChunk == null) {
        sFirstChunk = "";
    }
    if (!sFirstChunk.startsWith("d")) {
        boolean isHTML = sFirstChunk.contains("<html");
        String retry_url = UrlUtils.parseTextForMagnets(torrentName);
        if (retry_url == null) {
            retry_url = UrlUtils.parseTextForMagnets(sFirstChunk);
        }
        if (retry_url != null) {
            TorrentOpener.openTorrent(retry_url);
            return false;
        }
        if (warnOnError) {
            String[] buttons;
            String chat_key = null;
            String chat_net = null;
            if (originatingLocation != null && originatingLocation.toLowerCase(Locale.US).startsWith("http")) {
                try {
                    URL url = new URL(originatingLocation);
                    String host = url.getHost();
                    String interesting = DNSUtils.getInterestingHostSuffix(host);
                    if (interesting != null) {
                        String net = AENetworkClassifier.categoriseAddress(host);
                        if ((net == AENetworkClassifier.AT_PUBLIC && BuddyPluginUtils.isBetaChatAvailable()) || (net == AENetworkClassifier.AT_I2P && BuddyPluginUtils.isBetaChatAnonAvailable())) {
                            chat_key = "Torrent Error: " + interesting;
                            chat_net = net;
                        }
                    }
                } catch (Throwable e) {
                }
            }
            if (chat_key == null) {
                buttons = new String[] { MessageText.getString("Button.ok") };
            } else {
                buttons = new String[] { MessageText.getString("label.chat"), MessageText.getString("Button.ok") };
            }
            MessageBoxShell boxShell = new MessageBoxShell(MessageText.getString("OpenTorrentWindow.mb.notTorrent.title"), MessageText.getString("OpenTorrentWindow.mb.notTorrent.text", new String[] { torrentName, isHTML ? "" : MessageText.getString("OpenTorrentWindow.mb.notTorrent.cannot.display") }), buttons, buttons.length - 1);
            if (isHTML) {
                boxShell.setHtml(sFirstChunk);
            }
            final String f_chat_key = chat_key;
            final String f_chat_net = chat_net;
            boxShell.open(new UserPrompterResultListener() {

                @Override
                public void prompterClosed(int result) {
                    if (f_chat_key != null && result == 0) {
                        BuddyPluginUtils.createBetaChat(f_chat_net, f_chat_key, new BuddyPluginUtils.CreateChatCallback() {

                            @Override
                            public void complete(ChatInstance chat) {
                                if (chat != null) {
                                    chat.setInteresting(true);
                                }
                            }
                        });
                    }
                }
            });
        }
        return false;
    }
    return true;
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) IOException(java.io.IOException) URL(java.net.URL)

Example 49 with MessageBoxShell

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

the class SubscriptionManagerUI method removeWithConfirm.

protected static void removeWithConfirm(final Subscription subs) {
    MessageBoxShell mb = new MessageBoxShell(MessageText.getString("message.confirm.delete.title"), MessageText.getString("message.confirm.delete.text", new String[] { subs.getName() }), new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 1);
    mb.open(new UserPrompterResultListener() {

        @Override
        public void prompterClosed(int result) {
            if (result == 0) {
                subs.remove();
            }
        }
    });
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell)

Example 50 with MessageBoxShell

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

the class SBC_ActivityTableView method removeEntries.

private void removeEntries(final ActivitiesEntry[] toRemove, final int startIndex) {
    final ActivitiesEntry entry = toRemove[startIndex];
    if (entry == null || ActivitiesConstants.TYPEID_HEADER.equals(entry.getTypeID())) {
        int nextIndex = startIndex + 1;
        if (nextIndex < toRemove.length) {
            removeEntries(toRemove, nextIndex);
        }
        return;
    }
    MessageBoxShell mb = new MessageBoxShell(MessageText.getString("v3.activity.remove.title"), MessageText.getString("v3.activity.remove.text", new String[] { entry.getText() }));
    mb.setRemember(tableID + "-Remove", false, MessageText.getString("MessageBoxWindow.nomoreprompting"));
    if (startIndex == toRemove.length - 1) {
        mb.setButtons(0, new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, new Integer[] { 0, 1 });
        mb.setRememberOnlyIfButton(0);
    } else {
        mb.setButtons(1, new String[] { MessageText.getString("Button.removeAll"), MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, new Integer[] { 2, 0, 1 });
        mb.setRememberOnlyIfButton(1);
    }
    mb.setHandleHTML(false);
    mb.open(new UserPrompterResultListener() {

        @Override
        public void prompterClosed(int result) {
            if (result == 2) {
                int numToRemove = toRemove.length - startIndex;
                ActivitiesEntry[] toGroupRemove = new ActivitiesEntry[numToRemove];
                System.arraycopy(toRemove, startIndex, toGroupRemove, 0, numToRemove);
                ActivitiesManager.removeEntries(toGroupRemove);
                return;
            } else if (result == 0) {
                ActivitiesManager.removeEntries(new ActivitiesEntry[] { entry });
            }
            int nextIndex = startIndex + 1;
            if (nextIndex < toRemove.length) {
                removeEntries(toRemove, nextIndex);
            }
        }
    });
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell)

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