Search in sources :

Example 36 with MessageBoxShell

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

the class BuddyPluginViewInstance method addBuddyTable.

private Comparator<BuddyPluginBuddy> addBuddyTable(Composite child1) {
    buddy_table = new Table(child1, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL);
    final String[] headers = { "azbuddy.ui.table.name", "azbuddy.ui.table.online", "azbuddy.ui.table.lastseen", "azbuddy.ui.table.last_ygm", "azbuddy.ui.table.last_msg", "azbuddy.ui.table.loc_cat", "azbuddy.ui.table.rem_cat", "azbuddy.ui.table.read_cat", "azbuddy.ui.table.con", "azbuddy.ui.table.track", "azbuddy.ui.table.msg_in", "azbuddy.ui.table.msg_out", "azbuddy.ui.table.msg_queued", "label.bytesIn", "label.bytesOut", "azbuddy.ui.table.ss" };
    int[] sizes = { 250, 100, 100, 100, 200, 100, 100, 100, 75, 75, 75, 75, 75, 75, 75, 40 };
    int[] aligns = { SWT.LEFT, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.LEFT, SWT.LEFT, SWT.LEFT, SWT.LEFT, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER };
    for (int i = 0; i < headers.length; i++) {
        TableColumn tc = new TableColumn(buddy_table, aligns[i]);
        tc.setWidth(Utils.adjustPXForDPI(sizes[i]));
        Messages.setLanguageText(tc, headers[i]);
    }
    buddy_table.setHeaderVisible(true);
    TableColumn[] columns = buddy_table.getColumns();
    columns[0].setData(new Integer(FilterComparator.FIELD_NAME));
    columns[1].setData(new Integer(FilterComparator.FIELD_ONLINE));
    columns[2].setData(new Integer(FilterComparator.FIELD_LAST_SEEN));
    columns[3].setData(new Integer(FilterComparator.FIELD_YGM));
    columns[4].setData(new Integer(FilterComparator.FIELD_LAST_MSG));
    columns[5].setData(new Integer(FilterComparator.FIELD_LOC_CAT));
    columns[6].setData(new Integer(FilterComparator.FIELD_REM_CAT));
    columns[7].setData(new Integer(FilterComparator.FIELD_READ_CAT));
    columns[8].setData(new Integer(FilterComparator.FIELD_CON));
    columns[9].setData(new Integer(FilterComparator.FIELD_TRACK));
    columns[10].setData(new Integer(FilterComparator.FIELD_MSG_IN));
    columns[11].setData(new Integer(FilterComparator.FIELD_MSG_OUT));
    columns[12].setData(new Integer(FilterComparator.FIELD_QUEUED));
    columns[13].setData(new Integer(FilterComparator.FIELD_BYTES_IN));
    columns[14].setData(new Integer(FilterComparator.FIELD_BYTES_OUT));
    columns[15].setData(new Integer(FilterComparator.FIELD_SS));
    final FilterComparator comparator = new FilterComparator();
    Listener sort_listener = new Listener() {

        @Override
        public void handleEvent(Event e) {
            TableColumn tc = (TableColumn) e.widget;
            int field = ((Integer) tc.getData()).intValue();
            comparator.setField(field);
            Collections.sort(buddies, comparator);
            updateTable();
        }
    };
    for (int i = 0; i < columns.length; i++) {
        columns[i].addListener(SWT.Selection, sort_listener);
    }
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.heightHint = buddy_table.getHeaderHeight() * 3;
    Utils.setLayoutData(buddy_table, gridData);
    buddy_table.addListener(SWT.SetData, new Listener() {

        @Override
        public void handleEvent(Event event) {
            TableItem item = (TableItem) event.item;
            int index = buddy_table.indexOf(item);
            if (index < 0 || index >= buddies.size()) {
                return;
            }
            BuddyPluginBuddy buddy = (BuddyPluginBuddy) buddies.get(index);
            item.setText(0, buddy.getName());
            int os;
            if (buddy.isOnline(false)) {
                os = buddy.getOnlineStatus();
            } else {
                os = BuddyPlugin.STATUS_APPEAR_OFFLINE;
            }
            if (os == BuddyPlugin.STATUS_APPEAR_OFFLINE) {
                item.setText(1, "");
            } else {
                item.setText(1, plugin.getOnlineStatus(os));
            }
            long lo = buddy.getLastTimeOnline();
            item.setText(2, lo == 0 ? "" : new SimpleDateFormat().format(new Date(lo)));
            long last_ygm = buddy.getLastMessagePending();
            item.setText(3, last_ygm == 0 ? "" : new SimpleDateFormat().format(new Date(last_ygm)));
            String lm = buddy.getLastMessageReceived();
            item.setText(4, lm == null ? "" : lm);
            String loc_cat = buddy.getLocalAuthorisedRSSTagsOrCategoriesAsString();
            if (loc_cat == null) {
                loc_cat = "";
            }
            item.setText(5, "" + loc_cat);
            String rem_cat = buddy.getRemoteAuthorisedRSSTagsOrCategoriesAsString();
            if (rem_cat == null) {
                rem_cat = "";
            }
            item.setText(6, "" + rem_cat);
            String read_cat = buddy.getLocalReadTagsOrCategoriesAsString();
            if (read_cat == null) {
                read_cat = "";
            }
            item.setText(7, "" + read_cat);
            item.setText(8, "" + buddy.getConnectionsString());
            item.setText(9, "" + tracker.getTrackingStatus(buddy));
            String in_frag = buddy.getMessageInFragmentDetails();
            item.setText(10, "" + buddy.getMessageInCount() + (in_frag.length() == 0 ? "" : ("+" + in_frag)));
            item.setText(11, "" + buddy.getMessageOutCount());
            item.setText(12, "" + buddy.getMessageHandler().getMessageCount());
            item.setText(13, "" + DisplayFormatters.formatByteCountToKiBEtc(buddy.getBytesInCount()));
            item.setText(14, "" + DisplayFormatters.formatByteCountToKiBEtc(buddy.getBytesOutCount()));
            item.setText(15, "" + buddy.getSubsystem() + " v" + buddy.getVersion());
            item.setData(buddy);
        }
    });
    final Listener tt_label_listener = new Listener() {

        @Override
        public void handleEvent(Event event) {
            Label label = (Label) event.widget;
            Shell shell = label.getShell();
            switch(event.type) {
                case SWT.MouseDown:
                    Event e = new Event();
                    e.item = (TableItem) label.getData("_TABLEITEM");
                    buddy_table.setSelection(new TableItem[] { (TableItem) e.item });
                    buddy_table.notifyListeners(SWT.Selection, e);
                // fall through
                case SWT.MouseExit:
                    shell.dispose();
                    break;
            }
        }
    };
    Listener tt_table_listener = new Listener() {

        private Shell tip = null;

        private Label label = null;

        @Override
        public void handleEvent(Event event) {
            switch(event.type) {
                case SWT.Dispose:
                case SWT.KeyDown:
                case SWT.MouseMove:
                    {
                        if (tip == null)
                            break;
                        tip.dispose();
                        tip = null;
                        label = null;
                        break;
                    }
                case SWT.MouseHover:
                    {
                        Point mouse_position = new Point(event.x, event.y);
                        TableItem item = buddy_table.getItem(mouse_position);
                        if (item != null) {
                            if (tip != null && !tip.isDisposed()) {
                                tip.dispose();
                                tip = null;
                            }
                            int index = buddy_table.indexOf(item);
                            if (index < 0 || index >= buddies.size()) {
                                return;
                            }
                            BuddyPluginBuddy buddy = (BuddyPluginBuddy) buddies.get(index);
                            int item_index = 0;
                            for (int i = 0; i < headers.length; i++) {
                                Rectangle bounds = item.getBounds(i);
                                if (bounds.contains(mouse_position)) {
                                    item_index = i;
                                    break;
                                }
                            }
                            if (item_index != 0) {
                                return;
                            }
                            tip = new Shell(buddy_table.getShell(), SWT.ON_TOP | SWT.TOOL);
                            tip.setLayout(new FillLayout());
                            label = new Label(tip, SWT.NONE);
                            label.setForeground(buddy_table.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
                            label.setBackground(buddy_table.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
                            label.setData("_TABLEITEM", item);
                            label.setText(getToolTip(buddy));
                            label.addListener(SWT.MouseExit, tt_label_listener);
                            label.addListener(SWT.MouseDown, tt_label_listener);
                            Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                            Rectangle rect = item.getBounds(item_index);
                            Point pt = buddy_table.toDisplay(rect.x, rect.y);
                            tip.setBounds(pt.x, pt.y, size.x, size.y);
                            tip.setVisible(true);
                        }
                    }
            }
        }

        protected String getToolTip(BuddyPluginBuddy buddy) {
            List<InetAddress> addresses = buddy.getAdjustedIPs();
            InetAddress ip = buddy.getIP();
            InetAddress adj = buddy.getAdjustedIP();
            String str = "";
            if (ip == null) {
                str = "<none>";
            } else if (ip == adj) {
                str = ip.getHostAddress();
            } else {
                str = ip.getHostAddress() + "{";
                for (int i = 0; i < addresses.size(); i++) {
                    str += (i == 0 ? "" : "/") + addresses.get(i).getHostAddress();
                }
                str += "}";
            }
            return ("ip=" + str + ",tcp=" + buddy.getTCPPort() + ",udp=" + buddy.getUDPPort());
        }
    };
    buddy_table.addListener(SWT.Dispose, tt_table_listener);
    buddy_table.addListener(SWT.KeyDown, tt_table_listener);
    buddy_table.addListener(SWT.MouseMove, tt_table_listener);
    buddy_table.addListener(SWT.MouseHover, tt_table_listener);
    buddy_table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.stateMask == SWT.MOD1) {
                int key = event.character;
                if (key <= 26 && key > 0) {
                    key += 'a' - 1;
                }
                if (key == 'a') {
                    buddy_table.selectAll();
                    event.doit = false;
                }
            } else if (event.stateMask == 0 && event.keyCode == SWT.DEL) {
                TableItem[] selection = buddy_table.getSelection();
                String str = "";
                for (int i = 0; i < selection.length; i++) {
                    BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                    str += (str.isEmpty() ? "" : ", ") + buddy.getName();
                }
                MessageBoxShell mb = new MessageBoxShell(MessageText.getString("message.confirm.delete.title"), MessageText.getString("message.confirm.delete.text", new String[] { str }), new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 1);
                mb.open(new UserPrompterResultListener() {

                    @Override
                    public void prompterClosed(int result) {
                        if (result == 0) {
                            for (int i = 0; i < selection.length; i++) {
                                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                                buddy.remove();
                            }
                            buddy_table.setSelection(new int[0]);
                        }
                    }
                });
                event.doit = false;
            }
        }
    });
    final Menu menu = new Menu(buddy_table);
    final MenuItem remove_item = new MenuItem(menu, SWT.PUSH);
    remove_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.remove"));
    remove_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TableItem[] selection = buddy_table.getSelection();
            for (int i = 0; i < selection.length; i++) {
                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                buddy.remove();
            }
        }
    });
    // get public key
    final MenuItem get_pk_item = new MenuItem(menu, SWT.PUSH);
    get_pk_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.copypk"));
    get_pk_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            TableItem[] selection = buddy_table.getSelection();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < selection.length; i++) {
                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                sb.append(buddy.getPublicKey()).append("\r\n");
            }
            if (sb.length() > 0) {
                writeToClipboard(sb.toString());
            }
        }
    });
    // disconnect message
    final MenuItem disconnect_msg_item;
    if (Constants.isCVSVersion()) {
        disconnect_msg_item = new MenuItem(menu, SWT.PUSH);
        disconnect_msg_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.disconnect"));
        disconnect_msg_item.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent event) {
                TableItem[] selection = buddy_table.getSelection();
                for (int i = 0; i < selection.length; i++) {
                    BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                    buddy.disconnect();
                }
            }
        });
    } else {
        disconnect_msg_item = null;
    }
    // send message
    final MenuItem send_msg_item = new MenuItem(menu, SWT.PUSH);
    send_msg_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.send"));
    send_msg_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            final TableItem[] selection = buddy_table.getSelection();
            UIInputReceiver prompter = ui_instance.getInputReceiver();
            prompter.setLocalisedTitle(lu.getLocalisedMessageText("azbuddy.ui.menu.send"));
            prompter.setLocalisedMessage(lu.getLocalisedMessageText("azbuddy.ui.menu.send_msg"));
            try {
                prompter.prompt(new UIInputReceiverListener() {

                    @Override
                    public void UIInputReceiverClosed(UIInputReceiver prompter) {
                        String text = prompter.getSubmittedInput();
                        if (text != null) {
                            for (int i = 0; i < selection.length; i++) {
                                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                                plugin.getAZ2Handler().sendAZ2Message(buddy, text);
                            }
                        }
                    }
                });
            } catch (Throwable e) {
            }
        }
    });
    // chat
    final MenuItem chat_item = new MenuItem(menu, SWT.PUSH);
    chat_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.chat"));
    chat_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            TableItem[] selection = buddy_table.getSelection();
            BuddyPluginBuddy[] buddies = new BuddyPluginBuddy[selection.length];
            for (int i = 0; i < selection.length; i++) {
                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                buddies[i] = buddy;
            }
            plugin.getAZ2Handler().createChat(buddies);
        }
    });
    // ping
    final MenuItem ping_item = new MenuItem(menu, SWT.PUSH);
    ping_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.ping"));
    ping_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            TableItem[] selection = buddy_table.getSelection();
            for (int i = 0; i < selection.length; i++) {
                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                try {
                    buddy.ping();
                } catch (Throwable e) {
                    print("Ping failed", e);
                }
            }
        }
    });
    // ygm
    final MenuItem ygm_item = new MenuItem(menu, SWT.PUSH);
    ygm_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.ygm"));
    ygm_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            TableItem[] selection = buddy_table.getSelection();
            for (int i = 0; i < selection.length; i++) {
                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                try {
                    buddy.setMessagePending();
                } catch (Throwable e) {
                    print("YGM failed", e);
                }
            }
        }
    });
    // encrypt
    final MenuItem encrypt_item = new MenuItem(menu, SWT.PUSH);
    encrypt_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.enc"));
    encrypt_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            TableItem[] selection = buddy_table.getSelection();
            String str = readFromClipboard();
            if (str != null) {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < selection.length; i++) {
                    BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                    try {
                        byte[] contents = str.getBytes("UTF-8");
                        BuddyPlugin.cryptoResult result = buddy.encrypt(contents);
                        sb.append("key: ");
                        sb.append(plugin.getPublicKey());
                        sb.append("\r\n");
                        sb.append("hash: ");
                        sb.append(Base32.encode(result.getChallenge()));
                        sb.append("\r\n");
                        sb.append("payload: ");
                        sb.append(Base32.encode(result.getPayload()));
                        sb.append("\r\n\r\n");
                    } catch (Throwable e) {
                        print("YGM failed", e);
                    }
                }
                writeToClipboard(sb.toString());
            }
        }
    });
    // decrypt
    final MenuItem decrypt_item = new MenuItem(menu, SWT.PUSH);
    decrypt_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.dec"));
    decrypt_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            String str = readFromClipboard();
            if (str != null) {
                String[] bits = str.split("\n");
                StringBuilder sb = new StringBuilder();
                BuddyPluginBuddy buddy = null;
                byte[] hash = null;
                for (int i = 0; i < bits.length; i++) {
                    String bit = bits[i].trim();
                    if (bit.length() > 0) {
                        int pos = bit.indexOf(':');
                        if (pos == -1) {
                            continue;
                        }
                        String lhs = bit.substring(0, pos).trim();
                        String rhs = bit.substring(pos + 1).trim();
                        if (lhs.equals("key")) {
                            buddy = plugin.getBuddyFromPublicKey(rhs);
                        } else if (lhs.equals("hash")) {
                            hash = Base32.decode(rhs);
                        } else if (lhs.equals("payload")) {
                            byte[] payload = Base32.decode(rhs);
                            if (buddy != null) {
                                try {
                                    BuddyPlugin.cryptoResult result = buddy.decrypt(payload);
                                    byte[] sha1 = new SHA1Simple().calculateHash(result.getChallenge());
                                    sb.append("key: ");
                                    sb.append(buddy.getPublicKey());
                                    sb.append("\r\n");
                                    sb.append("hash_ok: ").append(Arrays.equals(hash, sha1));
                                    sb.append("\r\n");
                                    sb.append("payload: ");
                                    sb.append(new String(result.getPayload(), "UTF-8"));
                                    sb.append("\r\n\r\n");
                                } catch (Throwable e) {
                                    print("decrypt failed", e);
                                }
                            }
                        }
                    }
                }
                if (sb.length() > 0) {
                    writeToClipboard(sb.toString());
                }
            }
        }
    });
    // sign
    final MenuItem sign_item = new MenuItem(menu, SWT.PUSH);
    sign_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.sign"));
    sign_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            String str = readFromClipboard();
            if (str != null) {
                StringBuilder sb = new StringBuilder();
                try {
                    sb.append("key: ");
                    sb.append(plugin.getPublicKey());
                    sb.append("\r\n");
                    byte[] payload = str.getBytes("UTF-8");
                    sb.append("data: ");
                    sb.append(Base32.encode(payload));
                    sb.append("\r\n");
                    byte[] sig = plugin.sign(payload);
                    sb.append("sig: ");
                    sb.append(Base32.encode(sig));
                    sb.append("\r\n");
                } catch (Throwable e) {
                    print("sign failed", e);
                }
                if (sb.length() > 0) {
                    writeToClipboard(sb.toString());
                }
            }
        }
    });
    // verify
    final MenuItem verify_item = new MenuItem(menu, SWT.PUSH);
    verify_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.verify"));
    verify_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            String str = readFromClipboard();
            if (str != null) {
                String[] bits = str.split("\n");
                StringBuilder sb = new StringBuilder();
                String pk = null;
                byte[] data = null;
                for (int i = 0; i < bits.length; i++) {
                    String bit = bits[i].trim();
                    if (bit.length() > 0) {
                        int pos = bit.indexOf(':');
                        if (pos == -1) {
                            continue;
                        }
                        String lhs = bit.substring(0, pos).trim();
                        String rhs = bit.substring(pos + 1).trim();
                        if (lhs.equals("key")) {
                            pk = rhs;
                        } else if (lhs.equals("data")) {
                            data = Base32.decode(rhs);
                        } else if (lhs.equals("sig")) {
                            byte[] sig = Base32.decode(rhs);
                            if (pk != null && data != null) {
                                try {
                                    sb.append("key: ");
                                    sb.append(pk);
                                    sb.append("\r\n");
                                    boolean ok = plugin.verify(pk, data, sig);
                                    sb.append("sig_ok: ").append(ok);
                                    sb.append("\r\n");
                                    sb.append("data: ");
                                    sb.append(new String(data, "UTF-8"));
                                    sb.append("\r\n\r\n");
                                } catch (Throwable e) {
                                    print("decrypt failed", e);
                                }
                            }
                        }
                    }
                }
                if (sb.length() > 0) {
                    writeToClipboard(sb.toString());
                }
            }
        }
    });
    // cats
    Menu cat_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
    MenuItem cat_item = new MenuItem(menu, SWT.CASCADE);
    Messages.setLanguageText(cat_item, "azbuddy.ui.menu.cat");
    cat_item.setMenu(cat_menu);
    // cats - share
    final MenuItem cat_share_item = new MenuItem(cat_menu, SWT.PUSH);
    cat_share_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.cat.share"));
    cat_share_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            UIInputReceiver prompter = ui_instance.getInputReceiver();
            prompter.setLocalisedTitle(lu.getLocalisedMessageText("azbuddy.ui.menu.cat.set"));
            prompter.setLocalisedMessage(lu.getLocalisedMessageText("azbuddy.ui.menu.cat.set_msg"));
            prompter.prompt(new UIInputReceiverListener() {

                @Override
                public void UIInputReceiverClosed(UIInputReceiver prompter) {
                    String cats = prompter.getSubmittedInput();
                    if (cats != null) {
                        cats = cats.trim();
                        if (cats.equalsIgnoreCase("None")) {
                            cats = "";
                        }
                        TableItem[] selection = buddy_table.getSelection();
                        for (int i = 0; i < selection.length; i++) {
                            BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                            buddy.setLocalAuthorisedRSSTagsOrCategories(cats);
                        }
                    }
                }
            });
        }
    });
    // cats - subscribe
    final Menu cat_subs_menu = new Menu(cat_menu.getShell(), SWT.DROP_DOWN);
    final MenuItem cat_subs_item = new MenuItem(cat_menu, SWT.CASCADE);
    Messages.setLanguageText(cat_subs_item, "azbuddy.ui.menu.cat_subs");
    cat_subs_item.setMenu(cat_subs_menu);
    cat_subs_menu.addMenuListener(new MenuListener() {

        @Override
        public void menuShown(MenuEvent arg0) {
            MenuItem[] items = cat_subs_menu.getItems();
            for (int i = 0; i < items.length; i++) {
                items[i].dispose();
            }
            final TableItem[] selection = buddy_table.getSelection();
            Set<String> avail_cats = new TreeSet<>();
            for (int i = 0; i < selection.length; i++) {
                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                Set<String> cats = buddy.getRemoteAuthorisedRSSTagsOrCategories();
                if (cats != null) {
                    avail_cats.addAll(cats);
                }
            }
            for (final String cat : avail_cats) {
                final MenuItem subs_item = new MenuItem(cat_subs_menu, SWT.PUSH);
                subs_item.setText(cat);
                subs_item.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent event) {
                        for (int i = 0; i < selection.length; i++) {
                            BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                            if (buddy.isRemoteRSSTagOrCategoryAuthorised(cat)) {
                                try {
                                    buddy.subscribeToCategory(cat);
                                } catch (Throwable e) {
                                    print("Failed", e);
                                }
                            }
                        }
                    }
                });
            }
        }

        @Override
        public void menuHidden(MenuEvent arg0) {
        }
    });
    // done with menus
    buddy_table.setMenu(menu);
    menu.addMenuListener(new MenuListener() {

        @Override
        public void menuShown(MenuEvent arg0) {
            boolean available = plugin.isAvailable();
            TableItem[] selection = buddy_table.getSelection();
            remove_item.setEnabled(selection.length > 0);
            get_pk_item.setEnabled(available && selection.length > 0);
            if (disconnect_msg_item != null) {
                disconnect_msg_item.setEnabled(selection.length > 0);
            }
            send_msg_item.setEnabled(available && selection.length > 0);
            chat_item.setEnabled(available && selection.length > 0);
            ping_item.setEnabled(available && selection.length > 0);
            ygm_item.setEnabled(available && selection.length > 0);
            encrypt_item.setEnabled(selection.length > 0);
            decrypt_item.setEnabled(true);
            sign_item.setEnabled(true);
            verify_item.setEnabled(true);
            cat_item.setEnabled(selection.length > 0);
        }

        @Override
        public void menuHidden(MenuEvent arg0) {
        }
    });
    return (comparator);
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) Rectangle(org.eclipse.swt.graphics.Rectangle) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UIManagerEvent(com.biglybt.pif.ui.UIManagerEvent) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) SimpleDateFormat(java.text.SimpleDateFormat) InetAddress(java.net.InetAddress)

Example 37 with MessageBoxShell

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

the class SBC_ChatOverview method initTable.

private void initTable(Composite control) {
    if (tv == null) {
        tv = TableViewFactory.createTableViewSWT(ChatInstance.class, TABLE_CHAT, TABLE_CHAT, new TableColumnCore[0], ColumnChatName.COLUMN_ID, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
        if (txtFilter != null) {
            tv.enableFilterCheck(txtFilter, this);
        }
        tv.setRowDefaultHeightEM(1);
        table_parent = new Composite(control, SWT.BORDER);
        table_parent.setLayoutData(Utils.getFilledFormData());
        GridLayout layout = new GridLayout();
        layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
        table_parent.setLayout(layout);
        tv.addMenuFillListener(this);
        tv.addSelectionListener(this, false);
        tv.addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e) {
                if (e.stateMask == 0 && e.keyCode == SWT.DEL) {
                    Object[] datasources = tv.getSelectedDataSources().toArray();
                    if (datasources.length > 0) {
                        List<ChatInstance> chats = new ArrayList<>();
                        String str = "";
                        for (Object object : datasources) {
                            if (object instanceof ChatInstance) {
                                ChatInstance chat = (ChatInstance) object;
                                chats.add(chat);
                                if (chats.size() == 1) {
                                    str = chat.getDisplayName();
                                    if (str == null) {
                                        str = chat.getName();
                                    }
                                } else if (chats.size() == 2) {
                                    str += ", ...";
                                }
                            }
                        }
                        MessageBoxShell mb = new MessageBoxShell(MessageText.getString("message.confirm.delete.title"), MessageText.getString("message.confirm.delete.text", new String[] { str }), new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 1);
                        mb.open(new UserPrompterResultListener() {

                            @Override
                            public void prompterClosed(int result) {
                                if (result == 0) {
                                    for (ChatInstance chat : chats) {
                                        chat.remove();
                                    }
                                }
                            }
                        });
                    }
                    e.doit = false;
                }
            }
        });
        tv.initialize(table_parent);
    }
    control.layout(true);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) KeyAdapter(org.eclipse.swt.events.KeyAdapter) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) List(java.util.List) ArrayList(java.util.ArrayList) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject)

Example 38 with MessageBoxShell

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

the class ConfigSectionBackupRestore method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    ImageLoader imageLoader = ImageLoader.getInstance();
    Image imgOpenFolder = imageLoader.getImage("openFolderButton");
    GridData gridData;
    GridLayout layout;
    final Composite cBR = new Composite(parent, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    cBR.setLayoutData(gridData);
    layout = new GridLayout();
    layout.numColumns = 1;
    cBR.setLayout(layout);
    Label info_label = new Label(cBR, SWT.WRAP);
    Messages.setLanguageText(info_label, "ConfigView.section.br.overview");
    gridData = Utils.getWrappableLabelGridData(1, GridData.HORIZONTAL_ALIGN_FILL);
    info_label.setLayoutData(gridData);
    // wiki link
    final Label linkLabel = new Label(cBR, SWT.NULL);
    linkLabel.setText(MessageText.getString("ConfigView.label.please.visit.here"));
    linkLabel.setData(Constants.URL_WIKI + "w/Backup_And_Restore");
    linkLabel.setCursor(linkLabel.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    linkLabel.setForeground(Colors.blue);
    gridData = Utils.getWrappableLabelGridData(1, 0);
    linkLabel.setLayoutData(gridData);
    linkLabel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent arg0) {
            Utils.launch((String) ((Label) arg0.widget).getData());
        }

        @Override
        public void mouseDown(MouseEvent arg0) {
            Utils.launch((String) ((Label) arg0.widget).getData());
        }
    });
    ClipboardCopy.addCopyToClipMenu(linkLabel);
    final BackupManager backup_manager = BackupManagerFactory.getManager(CoreFactory.getSingleton());
    // backup
    Group gBackup = new Group(cBR, SWT.NULL);
    Messages.setLanguageText(gBackup, "br.backup");
    layout = new GridLayout(2, false);
    gBackup.setLayout(layout);
    gBackup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // info
    Label last_backup_label = new Label(gBackup, SWT.NULL);
    Messages.setLanguageText(last_backup_label, "br.backup.last.time");
    final Label last_backup_time = new Label(gBackup, SWT.NULL);
    Label last_backup_error_label = new Label(gBackup, SWT.NULL);
    Messages.setLanguageText(last_backup_error_label, "br.backup.last.error");
    final Label last_backup_error = new Label(gBackup, SWT.NULL);
    final Runnable stats_updater = new Runnable() {

        @Override
        public void run() {
            long backup_time = backup_manager.getLastBackupTime();
            last_backup_time.setText(backup_time == 0 ? "" : String.valueOf(new Date(backup_time)));
            last_backup_error.setText(backup_manager.getLastBackupError());
        }
    };
    stats_updater.run();
    // manual button
    Label backup_manual_label = new Label(gBackup, SWT.NULL);
    Messages.setLanguageText(backup_manual_label, "br.backup.manual.info");
    Button backup_button = new Button(gBackup, SWT.PUSH);
    Messages.setLanguageText(backup_button, "br.backup");
    backup_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            String def_dir = COConfigurationManager.getStringParameter("br.backup.folder.default");
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
            if (def_dir != null) {
                dialog.setFilterPath(def_dir);
            }
            dialog.setMessage(MessageText.getString("br.backup.folder.info"));
            dialog.setText(MessageText.getString("br.backup.folder.title"));
            String path = dialog.open();
            if (path != null) {
                COConfigurationManager.setParameter("br.backup.folder.default", path);
                runBackup(backup_manager, path, stats_updater);
            }
        }
    });
    final BooleanParameter auto_backup_enable = new BooleanParameter(gBackup, "br.backup.auto.enable", "br.backup.auto.enable");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    auto_backup_enable.setLayoutData(gridData);
    Composite gDefaultDir = new Composite(gBackup, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 3;
    layout.marginHeight = 2;
    gDefaultDir.setLayout(layout);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    gDefaultDir.setLayoutData(gridData);
    Label lblDefaultDir = new Label(gDefaultDir, SWT.NONE);
    Messages.setLanguageText(lblDefaultDir, "ConfigView.section.file.defaultdir.ask");
    lblDefaultDir.setLayoutData(new GridData());
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    final StringParameter pathParameter = new StringParameter(gDefaultDir, "br.backup.auto.dir", "");
    pathParameter.setLayoutData(gridData);
    if (pathParameter.getValue().length() == 0) {
        String def_dir = COConfigurationManager.getStringParameter("br.backup.folder.default");
        pathParameter.setValue(def_dir);
    }
    Button browse = new Button(gDefaultDir, SWT.PUSH);
    browse.setImage(imgOpenFolder);
    imgOpenFolder.setBackground(browse.getBackground());
    browse.setToolTipText(MessageText.getString("ConfigView.button.browse"));
    browse.addListener(SWT.Selection, new Listener() {

        /* (non-Javadoc)
			 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
			 */
        @Override
        public void handleEvent(Event event) {
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
            dialog.setFilterPath(pathParameter.getValue());
            dialog.setMessage(MessageText.getString("br.backup.auto.dir.select"));
            dialog.setText(MessageText.getString("ConfigView.section.file.defaultdir.ask"));
            String path = dialog.open();
            if (path != null) {
                pathParameter.setValue(path);
                COConfigurationManager.setParameter("br.backup.folder.default", path);
            }
        }
    });
    Composite gPeriod = new Composite(gDefaultDir, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 6;
    layout.marginLeft = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.marginTop = 0;
    layout.marginBottom = 0;
    gPeriod.setLayout(layout);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    gPeriod.setLayoutData(gridData);
    Label lbl_backup_days = new Label(gPeriod, SWT.NULL);
    Messages.setLanguageText(lbl_backup_days, "br.backup.auto.everydays");
    IntParameter backup_everydays = new IntParameter(gPeriod, "br.backup.auto.everydays", 0, Integer.MAX_VALUE);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    backup_everydays.setLayoutData(gridData);
    Label lbl_backup_hours = new Label(gPeriod, SWT.NULL);
    Messages.setLanguageText(lbl_backup_hours, "br.backup.auto.everyhours");
    IntParameter backup_everyhours = new IntParameter(gPeriod, "br.backup.auto.everyhours", 1, Integer.MAX_VALUE);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    backup_everyhours.setLayoutData(gridData);
    // for whatever reason if you set enable synchronously it gets reset :(
    Utils.execSWTThreadLater(1, new Runnable() {

        public void run() {
            backup_everyhours.setEnabled(backup_everydays.getValue() == 0);
        }
    });
    backup_everydays.addChangeListener(new ParameterChangeAdapter() {

        @Override
        public void parameterChanged(Parameter p, boolean caused_internally) {
            backup_everyhours.setEnabled(backup_everydays.getValue() == 0);
        }
    });
    Label lbl_backup_retain = new Label(gDefaultDir, SWT.NULL);
    Messages.setLanguageText(lbl_backup_retain, "br.backup.auto.retain");
    IntParameter backup_retain = new IntParameter(gDefaultDir, "br.backup.auto.retain", 1, Integer.MAX_VALUE);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    backup_retain.setLayoutData(gridData);
    BooleanParameter chkNotify = new BooleanParameter(gDefaultDir, "br.backup.notify", "br.backup.notify");
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    chkNotify.setLayoutData(gridData);
    Label backup_auto_label = new Label(gDefaultDir, SWT.NULL);
    Messages.setLanguageText(backup_auto_label, "br.backup.auto.now");
    Button backup_auto_button = new Button(gDefaultDir, SWT.PUSH);
    Messages.setLanguageText(backup_auto_button, "br.test");
    backup_auto_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            runBackup(backup_manager, null, stats_updater);
        }
    });
    auto_backup_enable.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(gDefaultDir));
    // restore
    Group gRestore = new Group(cBR, SWT.NULL);
    Messages.setLanguageText(gRestore, "br.restore");
    layout = new GridLayout(2, false);
    gRestore.setLayout(layout);
    gRestore.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Label restore_label = new Label(gRestore, SWT.NULL);
    Messages.setLanguageText(restore_label, "br.restore.info");
    Button restore_button = new Button(gRestore, SWT.PUSH);
    Messages.setLanguageText(restore_button, "br.restore");
    restore_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            String def_dir = COConfigurationManager.getStringParameter("br.backup.folder.default");
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
            if (def_dir != null) {
                dialog.setFilterPath(def_dir);
            }
            dialog.setMessage(MessageText.getString("br.restore.folder.info"));
            dialog.setText(MessageText.getString("br.restore.folder.title"));
            final String path = dialog.open();
            if (path != null) {
                MessageBoxShell mb = new MessageBoxShell(SWT.ICON_WARNING | SWT.OK | SWT.CANCEL, MessageText.getString("br.restore.warning.title"), MessageText.getString("br.restore.warning.info"));
                mb.setDefaultButtonUsingStyle(SWT.CANCEL);
                mb.setParent(parent.getShell());
                mb.open(new UserPrompterResultListener() {

                    @Override
                    public void prompterClosed(int returnVal) {
                        if (returnVal != SWT.OK) {
                            return;
                        }
                        final TextViewerWindow viewer = new TextViewerWindow(MessageText.getString("br.backup.progress"), null, "", true, true);
                        viewer.setEditable(false);
                        viewer.setOKEnabled(false);
                        backup_manager.restore(new File(path), new BackupManager.BackupListener() {

                            @Override
                            public boolean reportProgress(String str) {
                                return (append(str, false));
                            }

                            @Override
                            public void reportComplete() {
                                append("Restore Complete!", true);
                                Utils.execSWTThread(new AERunnable() {

                                    @Override
                                    public void runSupport() {
                                        MessageBoxShell mb = new MessageBoxShell(SWT.ICON_INFORMATION | SWT.OK, MessageText.getString("ConfigView.section.security.restart.title"), MessageText.getString("ConfigView.section.security.restart.msg"));
                                        mb.setParent(parent.getShell());
                                        mb.open(new UserPrompterResultListener() {

                                            @Override
                                            public void prompterClosed(int returnVal) {
                                                UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
                                                if (uiFunctions != null) {
                                                    uiFunctions.dispose(true, false);
                                                }
                                            }
                                        });
                                    }
                                });
                            }

                            @Override
                            public void reportError(Throwable error) {
                                append("Restore Failed: " + Debug.getNestedExceptionMessage(error), true);
                            }

                            private boolean append(final String str, final boolean complete) {
                                if (viewer.isDisposed()) {
                                    return (false);
                                }
                                Utils.execSWTThread(new AERunnable() {

                                    @Override
                                    public void runSupport() {
                                        if (str.endsWith("...")) {
                                            viewer.append(str);
                                        } else {
                                            viewer.append(str + "\r\n");
                                        }
                                        if (complete) {
                                            viewer.setOKEnabled(true);
                                        }
                                    }
                                });
                                return (true);
                            }
                        });
                        viewer.goModal();
                    }
                });
            }
        }
    });
    return (cBR);
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) ParameterChangeListener(com.biglybt.ui.swt.config.ParameterChangeListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) TextViewerWindow(com.biglybt.ui.swt.TextViewerWindow) StringParameter(com.biglybt.ui.swt.config.StringParameter) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) ParameterChangeAdapter(com.biglybt.ui.swt.config.ParameterChangeAdapter) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) BackupManager(com.biglybt.core.backup.BackupManager) BooleanParameter(com.biglybt.ui.swt.config.BooleanParameter) Date(java.util.Date) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) AERunnable(com.biglybt.core.util.AERunnable) GridData(org.eclipse.swt.layout.GridData) MouseEvent(org.eclipse.swt.events.MouseEvent) BooleanParameter(com.biglybt.ui.swt.config.BooleanParameter) StringParameter(com.biglybt.ui.swt.config.StringParameter) IntParameter(com.biglybt.ui.swt.config.IntParameter) Parameter(com.biglybt.ui.swt.config.Parameter) ChangeSelectionActionPerformer(com.biglybt.ui.swt.config.ChangeSelectionActionPerformer) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) File(java.io.File) IntParameter(com.biglybt.ui.swt.config.IntParameter)

Example 39 with MessageBoxShell

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

the class TorrentUIUtilsV3 method _loadTorrent.

private static void _loadTorrent(final Core core, final DownloadUrlInfo dlInfo, // open player
final boolean playNow, // as for open player but don't actually open it
final boolean playPrepare, final boolean bringToFront) {
    if (dlInfo instanceof DownloadUrlInfoSWT) {
        DownloadUrlInfoSWT dlInfoSWT = (DownloadUrlInfoSWT) dlInfo;
        dlInfoSWT.invoke(playNow ? "play" : "download");
        return;
    }
    String url = dlInfo.getDownloadURL();
    try {
        Matcher m = hashPattern.matcher(url);
        if (m.find()) {
            String hash = m.group(1);
            GlobalManager gm = core.getGlobalManager();
            final DownloadManager dm = gm.getDownloadManager(new HashWrapper(Base32.decode(hash)));
            if (dm != null) {
                if (playNow || playPrepare) {
                    new AEThread2("playExisting", true) {

                        @Override
                        public void run() {
                            if (playNow) {
                                Debug.outNoStack("loadTorrent already exists.. playing", false);
                                TorrentListViewsUtils.playOrStream(dm, -1);
                            } else {
                                Debug.outNoStack("loadTorrent already exists.. preparing", false);
                                PlayUtils.prepareForPlay(dm);
                            }
                        }
                    }.start();
                } else {
                    new MessageBoxShell(SWT.OK, MSG_ALREADY_EXISTS, new String[] { " ", dm.getDisplayName(), MessageText.getString(MSG_ALREADY_EXISTS_NAME) }).open(null);
                }
                return;
            }
        }
        UIFunctionsSWT uiFunctions = (UIFunctionsSWT) UIFunctionsManager.getUIFunctions();
        if (uiFunctions != null) {
            // if (!COConfigurationManager.getBooleanParameter("add_torrents_silently")) { not used 11/30/2015
            if (bringToFront) {
                uiFunctions.bringToFront();
            }
            // }
            Shell shell = uiFunctions.getMainShell();
            if (shell != null) {
                new FileDownloadWindow(shell, url, dlInfo.getReferer(), dlInfo.getRequestProperties(), null, new TorrentDownloaderCallBackInterface() {

                    @Override
                    public void TorrentDownloaderEvent(int state, TorrentDownloader inf) {
                        if (state == TorrentDownloader.STATE_FINISHED) {
                            File file = inf.getFile();
                            file.deleteOnExit();
                            // Do a quick check to see if it's a torrent
                            if (!TorrentUtil.isFileTorrent(dlInfo.getDownloadURL(), file, file.getName(), true)) {
                                return;
                            }
                            TOTorrent torrent;
                            try {
                                torrent = TorrentUtils.readFromFile(file, false);
                            } catch (TOTorrentException e) {
                                Debug.out(e);
                                return;
                            }
                            // Security: Only allow torrents from whitelisted trackers
                            if (playNow && !PlatformTorrentUtils.isPlatformTracker(torrent)) {
                                Debug.out("stopped loading torrent because it's not in whitelist");
                                return;
                            }
                            HashWrapper hw;
                            try {
                                hw = torrent.getHashWrapper();
                            } catch (TOTorrentException e1) {
                                Debug.out(e1);
                                return;
                            }
                            GlobalManager gm = core.getGlobalManager();
                            if (playNow || playPrepare) {
                                DownloadManager existingDM = gm.getDownloadManager(hw);
                                if (existingDM != null) {
                                    if (playNow) {
                                        TorrentListViewsUtils.playOrStream(existingDM, -1);
                                    } else {
                                        PlayUtils.prepareForPlay(existingDM);
                                    }
                                    return;
                                }
                            }
                            final HashWrapper fhw = hw;
                            GlobalManagerListener l = new GlobalManagerAdapter() {

                                @Override
                                public void downloadManagerAdded(DownloadManager dm) {
                                    try {
                                        core.getGlobalManager().removeListener(this);
                                        handleDMAdded(dm, playNow, playPrepare, fhw);
                                    } catch (Exception e) {
                                        Debug.out(e);
                                    }
                                }
                            };
                            gm.addListener(l, false);
                            TorrentOpener.openTorrent(file.getAbsolutePath());
                        }
                    }
                });
            }
        }
    } catch (Exception e) {
        Debug.out(e);
    }
}
Also used : TorrentDownloaderCallBackInterface(com.biglybt.core.torrentdownloader.TorrentDownloaderCallBackInterface) Matcher(java.util.regex.Matcher) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) DownloadManager(com.biglybt.core.download.DownloadManager) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) DownloadUrlInfoSWT(com.biglybt.ui.swt.browser.listener.DownloadUrlInfoSWT) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) Shell(org.eclipse.swt.widgets.Shell) GlobalManager(com.biglybt.core.global.GlobalManager) GlobalManagerAdapter(com.biglybt.core.global.GlobalManagerAdapter) TOTorrent(com.biglybt.core.torrent.TOTorrent) GlobalManagerListener(com.biglybt.core.global.GlobalManagerListener) TorrentDownloader(com.biglybt.core.torrentdownloader.TorrentDownloader) TOTorrentFile(com.biglybt.core.torrent.TOTorrentFile) File(java.io.File)

Example 40 with MessageBoxShell

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

the class ConfigureWizard method onClose.

@Override
public void onClose() {
    try {
        if (!completed && wizard_mode != WIZARD_MODE_SPEED_TEST_AUTO && !COConfigurationManager.getBooleanParameter("Wizard Completed")) {
            MessageBoxShell mb = new MessageBoxShell(MessageText.getString("wizard.close.confirmation"), MessageText.getString("wizard.close.message"), new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 0);
            mb.open(new UserPrompterResultListener() {

                @Override
                public void prompterClosed(int result) {
                    if (result == 1) {
                        COConfigurationManager.setParameter("Wizard Completed", true);
                        COConfigurationManager.save();
                    }
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    super.onClose();
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) 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