Search in sources :

Example 26 with UIInputReceiver

use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.

the class TorrentUtil method pauseDownloadsFor.

protected static void pauseDownloadsFor(DownloadManager[] dms) {
    final List<DownloadManager> dms_to_pause = new ArrayList<>();
    for (int i = 0; i < dms.length; i++) {
        DownloadManager dm = dms[i];
        if (dm.isPaused() || ManagerUtils.isPauseable(dm)) {
            dms_to_pause.add(dm);
        }
    }
    if (dms_to_pause.size() == 0) {
        return;
    }
    String text = MessageText.getString("dialog.pause.for.period.text");
    SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("dialog.pause.for.period.title", "!" + text + "!");
    int def = COConfigurationManager.getIntParameter("pause.for.period.default", 10);
    entryWindow.setPreenteredText(String.valueOf(def), false);
    entryWindow.prompt(new UIInputReceiverListener() {

        @Override
        public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
            if (!entryWindow.hasSubmittedInput()) {
                return;
            }
            String sReturn = entryWindow.getSubmittedInput();
            if (sReturn == null) {
                return;
            }
            int mins = -1;
            try {
                mins = Integer.valueOf(sReturn).intValue();
            } catch (NumberFormatException er) {
            // Ignore
            }
            if (mins <= 0) {
                MessageBox mb = new MessageBox(Utils.findAnyShell(), SWT.ICON_ERROR | SWT.OK);
                mb.setText(MessageText.getString("MyTorrentsView.dialog.NumberError.title"));
                mb.setMessage(MessageText.getString("MyTorrentsView.dialog.NumberError.text"));
                mb.open();
                return;
            }
            COConfigurationManager.setParameter("pause.for.period.default", mins);
            ManagerUtils.asyncPauseForPeriod(dms_to_pause, mins * 60);
        }
    });
}
Also used : UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 27 with UIInputReceiver

use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.

the class TorrentUtil method promptUserForComment.

public static void promptUserForComment(String text, Consumer<String> consumer) {
    // Create dialog box.
    String msg_key_prefix = "MyTorrentsView.menu.edit_comment.enter.";
    SimpleTextEntryWindow text_entry = new SimpleTextEntryWindow();
    text_entry.setTitle(msg_key_prefix + "title");
    text_entry.setMessage(msg_key_prefix + "message");
    text_entry.setPreenteredText(text, false);
    text_entry.setWidthHint(800);
    text_entry.setLineHeight(10);
    text_entry.setMultiLine(true);
    text_entry.setResizeable(true);
    text_entry.setDetectURLs(true);
    text_entry.setRememberLocationSize("ui.torrent.comment");
    text_entry.prompt(new UIInputReceiverListener() {

        @Override
        public void UIInputReceiverClosed(UIInputReceiver text_entry) {
            if (text_entry.hasSubmittedInput()) {
                String value = text_entry.getSubmittedInput();
                final String value_to_set = (value.length() == 0) ? null : value;
                consumer.accept(value_to_set);
            }
        }
    });
}
Also used : UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Example 28 with UIInputReceiver

use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.

the class TorrentUtil method promptUserForDescription.

public static void promptUserForDescription(final DownloadManager[] dms) {
    if (dms.length == 0) {
        return;
    }
    DownloadManager dm = dms[0];
    String desc = null;
    try {
        desc = PlatformTorrentUtils.getContentDescription(dm.getTorrent());
        if (desc == null) {
            desc = "";
        }
    } catch (Throwable e) {
    }
    String msg_key_prefix = "MyTorrentsView.menu.edit_description.enter.";
    SimpleTextEntryWindow text_entry = new SimpleTextEntryWindow();
    text_entry.setTitle(msg_key_prefix + "title");
    text_entry.setMessage(msg_key_prefix + "message");
    text_entry.setPreenteredText(desc, false);
    text_entry.setMultiLine(true);
    text_entry.setResizeable(true);
    text_entry.setWidthHint(500);
    text_entry.setLineHeight(16);
    text_entry.prompt(new UIInputReceiverListener() {

        @Override
        public void UIInputReceiverClosed(UIInputReceiver text_entry) {
            if (text_entry.hasSubmittedInput()) {
                String value = text_entry.getSubmittedInput();
                final String value_to_set = (value.length() == 0) ? null : value;
                ListenerDMTask task = new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager dm) {
                        PlatformTorrentUtils.setContentDescription(dm.getTorrent(), value_to_set);
                    }
                };
                task.go();
            }
        }
    });
}
Also used : UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 29 with UIInputReceiver

use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.

the class BuddyPluginViewInstance method addBuddyTable.

private Comparator<BuddyPluginBuddy> addBuddyTable(Composite child1, boolean is_public) {
    Table buddy_table = new Table(child1, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL);
    List<BuddyPluginBuddy> buddies;
    if (is_public) {
        public_buddy_table = buddy_table;
        buddies = public_buddies;
    } else {
        anon_buddy_table = buddy_table;
        buddies = anon_buddies;
    }
    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(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(is_public);
        }
    };
    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;
    buddy_table.setLayoutData(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<InetSocketAddress> addresses = buddy.getAdjustedIPs();
            InetSocketAddress ip = buddy.getIP();
            InetSocketAddress adj = buddy.getAdjustedIP();
            InetSocketAddress latest_v4 = buddy.getLatestIP(true);
            InetSocketAddress latest_v6 = buddy.getLatestIP(false);
            Set<InetSocketAddress> all_ips = new HashSet<>();
            all_ips.addAll(addresses);
            all_ips.add(ip);
            all_ips.add(adj);
            all_ips.add(latest_v4);
            all_ips.add(latest_v6);
            all_ips.remove(null);
            String str = "";
            if (all_ips.isEmpty()) {
                str = "<none>";
            } else {
                Set<String> done = new HashSet<>();
                for (InetSocketAddress a : all_ips) {
                    String host = AddressUtils.getHostAddress(a);
                    if (!done.contains(host)) {
                        done.add(host);
                        str += (str.isEmpty() ? "" : ", ") + host;
                    }
                }
            }
            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);
    // 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();
                                buddy.getPluginNetwork().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.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);
                }
            }
        }
    });
    // 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) {
            TableItem[] selection = buddy_table.getSelection();
            List<BuddyPluginBuddy> buddies = new ArrayList<>();
            Set<String> enabled_tags = new HashSet<>();
            for (int i = 0; i < selection.length; i++) {
                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                buddies.add(buddy);
                Set<String> et = buddy.getLocalAuthorisedRSSTagsOrCategories();
                if (et == null) {
                    enabled_tags.clear();
                    break;
                } else {
                    if (i == 0) {
                        enabled_tags.addAll(et);
                    } else {
                        enabled_tags.retainAll(et);
                        if (enabled_tags.isEmpty()) {
                            break;
                        }
                    }
                }
            }
            TagManager tm = TagManagerFactory.getTagManager();
            List<Tag> all_tags = tm.getTagType(TagType.TT_DOWNLOAD_CATEGORY).getTags();
            all_tags.addAll(tm.getTagType(TagType.TT_DOWNLOAD_MANUAL).getTags());
            Map<String, Tag> tag_map = new HashMap<>();
            for (Tag t : all_tags) {
                tag_map.put(t.getTagName(true), t);
            }
            List<Tag> selected_tags = new ArrayList<>();
            for (String s : enabled_tags) {
                Tag t = tag_map.get(s);
                if (t != null) {
                    selected_tags.add(t);
                }
            }
            TagUIUtilsV3.showTagSelectionDialog(all_tags, selected_tags, false, (tags) -> {
                Set<String> tag_names = new HashSet<>();
                for (Tag t : tags) {
                    tag_names.add(t.getTagName(true));
                }
                for (BuddyPluginBuddy buddy : buddies) {
                    buddy.setLocalAuthorisedRSSTagsOrCategories(tag_names);
                }
            });
        }
    });
    // 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();
            List<BuddyPluginBuddy> buddies = new ArrayList<>();
            Set<String> avail_cats = new TreeSet<>();
            for (int i = 0; i < selection.length; i++) {
                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                buddies.add(buddy);
                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.CHECK);
                subs_item.setText(cat);
                boolean all_subs = true;
                boolean some_subs = false;
                for (BuddyPluginBuddy buddy : buddies) {
                    if (buddy.isSubscribedToCategory(cat)) {
                        some_subs = true;
                    } else {
                        all_subs = false;
                    }
                }
                subs_item.setSelection(all_subs);
                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) {
        }
    });
    // set local name
    MenuItem set_name_item = new MenuItem(menu, SWT.PUSH);
    set_name_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.setname"));
    set_name_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.setname"));
            prompter.setLocalisedMessage(lu.getLocalisedMessageText("azbuddy.ui.menu.setname_msg"));
            try {
                prompter.prompt(new UIInputReceiverListener() {

                    @Override
                    public void UIInputReceiverClosed(UIInputReceiver prompter) {
                        String text = prompter.getSubmittedInput();
                        if (text != null) {
                            text = text.trim();
                            for (int i = 0; i < selection.length; i++) {
                                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                                buddy.setMyName(text);
                            }
                        }
                    }
                });
            } catch (Throwable e) {
            }
        }
    });
    MenuItem ygm_item;
    if (Constants.isCVSVersion()) {
        // ygm
        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);
                    }
                }
            }
        });
    } else {
        ygm_item = null;
    }
    new MenuItem(menu, SWT.SEPARATOR);
    // 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());
            }
        }
    });
    // 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(is_public));
                        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(is_public));
                    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(is_public, 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(is_public, 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());
                }
            }
        }
    });
    new MenuItem(menu, SWT.SEPARATOR);
    // 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;
    }
    final MenuItem remove_item = new MenuItem(menu, SWT.PUSH);
    remove_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.remove"));
    Utils.setMenuItemImage(remove_item, "delete");
    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();
            }
        }
    });
    // 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);
            if (ygm_item != null) {
                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);
            set_name_item.setEnabled(selection.length == 1);
        }

        @Override
        public void menuHidden(MenuEvent arg0) {
        }
    });
    return (comparator);
}
Also used : Messages(com.biglybt.ui.swt.Messages) COConfigurationManager(com.biglybt.core.config.COConfigurationManager) TagManagerFactory(com.biglybt.core.tag.TagManagerFactory) Colors(com.biglybt.ui.swt.mainwindow.Colors) UIFunctionsManager(com.biglybt.ui.UIFunctionsManager) Point(org.eclipse.swt.graphics.Point) Clipboard(org.eclipse.swt.dnd.Clipboard) Utils(com.biglybt.ui.swt.Utils) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) org.eclipse.swt.custom(org.eclipse.swt.custom) IntSwtParameter(com.biglybt.ui.swt.config.IntSwtParameter) LocaleUtilities(com.biglybt.pif.utils.LocaleUtilities) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) org.eclipse.swt.layout(org.eclipse.swt.layout) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) MessageText(com.biglybt.core.internat.MessageText) InetSocketAddress(java.net.InetSocketAddress) Transfer(org.eclipse.swt.dnd.Transfer) com.biglybt.plugin.net.buddy(com.biglybt.plugin.net.buddy) List(java.util.List) CryptoManagerKeyListener(com.biglybt.core.security.CryptoManagerKeyListener) SWT(org.eclipse.swt.SWT) TagUIUtilsV3(com.biglybt.ui.swt.utils.TagUIUtilsV3) UIFunctions(com.biglybt.ui.UIFunctions) UIManagerEvent(com.biglybt.pif.ui.UIManagerEvent) java.util(java.util) Tag(com.biglybt.core.tag.Tag) TagManager(com.biglybt.core.tag.TagManager) I2PHelpers(com.biglybt.plugin.I2PHelpers) CryptoManagerFactory(com.biglybt.core.security.CryptoManagerFactory) SimpleDateFormat(java.text.SimpleDateFormat) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) CryptoManager(com.biglybt.core.security.CryptoManager) BuddyPluginTracker(com.biglybt.plugin.net.buddy.tracker.BuddyPluginTracker) CryptoHandler(com.biglybt.core.security.CryptoHandler) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) PluginInterface(com.biglybt.pif.PluginInterface) TextTransfer(org.eclipse.swt.dnd.TextTransfer) UIInstance(com.biglybt.pif.ui.UIInstance) org.eclipse.swt.events(org.eclipse.swt.events) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) org.eclipse.swt.widgets(org.eclipse.swt.widgets) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) com.biglybt.core.util(com.biglybt.core.util) Color(org.eclipse.swt.graphics.Color) TagType(com.biglybt.core.tag.TagType) ClipboardCopy(com.biglybt.ui.swt.mainwindow.ClipboardCopy) PluginConfig(com.biglybt.pif.PluginConfig) InetSocketAddress(java.net.InetSocketAddress) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) Rectangle(org.eclipse.swt.graphics.Rectangle) List(java.util.List) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) CryptoManagerKeyListener(com.biglybt.core.security.CryptoManagerKeyListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) 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) TagManager(com.biglybt.core.tag.TagManager) UIManagerEvent(com.biglybt.pif.ui.UIManagerEvent) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) Tag(com.biglybt.core.tag.Tag) SimpleDateFormat(java.text.SimpleDateFormat)

Example 30 with UIInputReceiver

use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.

the class TableViewPainted method openFilterDialog.

@Override
public void openFilterDialog() {
    if (filter == null) {
        return;
    }
    SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow();
    entryWindow.initTexts("MyTorrentsView.dialog.setFilter.title", null, "MyTorrentsView.dialog.setFilter.text", new String[] { MessageText.getString(getTableID() + "View" + ".header") });
    entryWindow.setPreenteredText(filter.text, false);
    entryWindow.prompt(new UIInputReceiverListener() {

        @Override
        public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
            if (!entryWindow.hasSubmittedInput()) {
                return;
            }
            String message = entryWindow.getSubmittedInput();
            if (message == null) {
                message = "";
            }
            setFilterText(message, false);
        }
    });
}
Also used : SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Aggregations

UIInputReceiver (com.biglybt.pif.ui.UIInputReceiver)38 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)36 SimpleTextEntryWindow (com.biglybt.ui.swt.SimpleTextEntryWindow)21 List (java.util.List)11 DownloadManager (com.biglybt.core.download.DownloadManager)9 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)7 TrackerEditorListener (com.biglybt.ui.swt.maketorrent.TrackerEditorListener)7 Point (org.eclipse.swt.graphics.Point)7 CoreRunningListener (com.biglybt.core.CoreRunningListener)6 File (java.io.File)6 MenuEvent (org.eclipse.swt.events.MenuEvent)6 ParameterListener (com.biglybt.core.config.ParameterListener)5 MessageText (com.biglybt.core.internat.MessageText)5 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)5 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)5 TableViewSWTMenuFillListener (com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener)5 DisposeEvent (org.eclipse.swt.events.DisposeEvent)5 DisposeListener (org.eclipse.swt.events.DisposeListener)5