Search in sources :

Example 1 with PropertiesWindow

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

the class BuddyPluginViewBetaChat method buildParticipantMenu.

private void buildParticipantMenu(final Menu menu, final List<ChatParticipant> participants) {
    boolean can_ignore = false;
    boolean can_listen = false;
    boolean can_pin = false;
    boolean can_unpin = false;
    boolean can_spam = false;
    boolean can_unspam = false;
    for (ChatParticipant participant : participants) {
        if (DEBUG_ENABLED) {
            System.out.println(participant.getName() + "/" + participant.getAddress() + "/" + participant.getZoneOffset() + " - pk=" + Base32.encode(participant.getPublicKey()));
            List<ChatMessage> messages = participant.getMessages();
            for (ChatMessage msg : messages) {
                System.out.println("    " + msg.getTimeStamp() + ", " + msg.getAddress() + "/" + msg.getZoneOffset() + " - " + msg.getMessage());
            }
        }
        if (participant.isIgnored()) {
            can_listen = true;
        } else {
            can_ignore = true;
        }
        if (participant.isPinned()) {
            can_unpin = true;
        } else {
            if (!participant.isMe()) {
                can_pin = true;
            }
        }
        if (participant.isSpammer()) {
            can_unspam = true;
        } else {
            can_spam |= participant.canSpammer();
        }
    }
    final MenuItem ignore_item = new MenuItem(menu, SWT.PUSH);
    ignore_item.setText(lu.getLocalisedMessageText("label.mute"));
    ignore_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean changed = false;
            for (ChatParticipant participant : participants) {
                if (!participant.isIgnored()) {
                    participant.setIgnored(true);
                    changed = true;
                }
            }
            if (changed) {
                messagesChanged();
                participantsChanged();
            }
        }
    });
    ignore_item.setEnabled(can_ignore);
    final MenuItem listen_item = new MenuItem(menu, SWT.PUSH);
    listen_item.setText(lu.getLocalisedMessageText("label.listen"));
    listen_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean changed = false;
            for (ChatParticipant participant : participants) {
                if (participant.isIgnored()) {
                    participant.setIgnored(false);
                    changed = true;
                }
            }
            if (changed) {
                messagesChanged();
                participantsChanged();
            }
        }
    });
    listen_item.setEnabled(can_listen);
    // spam
    final MenuItem spam_item = new MenuItem(menu, SWT.PUSH);
    spam_item.setText(lu.getLocalisedMessageText("label.spam"));
    spam_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean changed = false;
            for (ChatParticipant participant : participants) {
                if (participant.canSpammer()) {
                    participant.setSpammer(true);
                    changed = true;
                }
            }
            if (changed) {
                messagesChanged();
                participantsChanged();
            }
        }
    });
    spam_item.setEnabled(can_spam);
    final MenuItem unspam_item = new MenuItem(menu, SWT.PUSH);
    unspam_item.setText(lu.getLocalisedMessageText("label.not.spam"));
    unspam_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean changed = false;
            for (ChatParticipant participant : participants) {
                if (participant.isSpammer()) {
                    participant.setSpammer(false);
                    changed = true;
                }
            }
            if (changed) {
                messagesChanged();
                participantsChanged();
            }
        }
    });
    unspam_item.setEnabled(can_unspam);
    // pin
    new MenuItem(menu, SWT.SEPARATOR);
    final MenuItem pin_item = new MenuItem(menu, SWT.PUSH);
    pin_item.setText(lu.getLocalisedMessageText("label.pin"));
    pin_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean changed = false;
            for (ChatParticipant participant : participants) {
                if (!participant.isPinned()) {
                    if (!participant.isMe()) {
                        participant.setPinned(true);
                        setProperties(participant);
                        changed = true;
                    }
                }
            }
            if (changed) {
                messagesChanged();
            }
        }
    });
    pin_item.setEnabled(can_pin);
    final MenuItem unpin_item = new MenuItem(menu, SWT.PUSH);
    unpin_item.setText(lu.getLocalisedMessageText("label.unpin"));
    unpin_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean changed = false;
            for (ChatParticipant participant : participants) {
                if (participant.isPinned()) {
                    participant.setPinned(false);
                    setProperties(participant);
                    changed = true;
                }
            }
            if (changed) {
                messagesChanged();
            }
        }
    });
    unpin_item.setEnabled(can_unpin);
    if (!chat.isPrivateChat()) {
        new MenuItem(menu, SWT.SEPARATOR);
        final MenuItem private_chat_item = new MenuItem(menu, SWT.PUSH);
        private_chat_item.setText(lu.getLocalisedMessageText("label.private.chat"));
        final byte[] chat_pk = chat.getPublicKey();
        private_chat_item.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                for (ChatParticipant participant : participants) {
                    if (TEST_LOOPBACK_CHAT || !Arrays.equals(participant.getPublicKey(), chat_pk)) {
                        try {
                            ChatInstance chat = participant.createPrivateChat();
                            createChatWindow(view, plugin, chat);
                        } catch (Throwable f) {
                            Debug.out(f);
                        }
                    }
                }
            }
        });
        // friends sub menu
        {
            boolean is_public_chat = !chat.isAnonymous();
            Menu friends_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
            MenuItem friends_item = new MenuItem(menu, SWT.CASCADE);
            friends_item.setMenu(friends_menu);
            friends_item.setText(MessageText.getString("Views.plugins.azbuddy.title"));
            final MenuItem send_fk_item = new MenuItem(friends_menu, SWT.PUSH);
            send_fk_item.setText(lu.getLocalisedMessageText("label.send.friend.key"));
            send_fk_item.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    if (!plugin.isClassicEnabled()) {
                        plugin.setClassicEnabled(true, false);
                    }
                    for (ChatParticipant participant : participants) {
                        boolean is_me = Arrays.equals(participant.getPublicKey(), chat_pk);
                        boolean is_friend = participant.getFriendStatus() != 0;
                        if (!(is_friend || is_me)) {
                            try {
                                ChatInstance chat = participant.createPrivateChat();
                                createChatWindow(view, plugin, chat);
                                String message = "!azbuddy.send.friend.key.msg[" + UrlUtils.encode(getFriendURI(is_public_chat)) + "]!";
                                chat.sendMessage(message, null);
                            } catch (Throwable f) {
                                Debug.out(f);
                            }
                        }
                    }
                }
            });
            if (participants.size() == 1) {
                ChatParticipant participant = participants.get(0);
                boolean is_me = Arrays.equals(participant.getPublicKey(), chat_pk);
                String fk = participant.getFriendKey();
                boolean is_friend = participant.getFriendStatus() != 0;
                final MenuItem add_fk_item = new MenuItem(friends_menu, SWT.PUSH);
                add_fk_item.setText(lu.getLocalisedMessageText("azbuddy.add.friend.key"));
                add_fk_item.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        if (!plugin.isClassicEnabled()) {
                            plugin.setClassicEnabled(true, false);
                        }
                        plugin.addBuddy(is_public_chat, fk, BuddyPluginNetwork.SUBSYSTEM_AZ2);
                        try {
                            ChatInstance chat = participant.createPrivateChat();
                            createChatWindow(view, plugin, chat);
                            String message = "!azbuddy.add.friend.key.msg[" + UrlUtils.encode(getFriendURI(is_public_chat)) + "]!";
                            chat.sendMessage(message, null);
                        } catch (Throwable f) {
                            Debug.out(f);
                        }
                    }
                });
                add_fk_item.setEnabled(fk != null && !is_me && !is_friend);
                if (is_friend) {
                    BuddyPluginBuddy buddy = plugin.getBuddyFromPublicKey(fk);
                    // cats - share
                    final MenuItem cat_share_item = new MenuItem(friends_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) {
                            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<>();
                            Set<String> enabled_tags = buddy.getLocalAuthorisedRSSTagsOrCategories();
                            if (enabled_tags != null) {
                                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));
                                }
                                buddy.setLocalAuthorisedRSSTagsOrCategories(tag_names);
                            });
                        }
                    });
                    // cats - subscribe
                    final Menu cat_subs_menu = new Menu(friends_menu.getShell(), SWT.DROP_DOWN);
                    final MenuItem cat_subs_item = new MenuItem(friends_menu, SWT.CASCADE);
                    Messages.setLanguageText(cat_subs_item, "azbuddy.ui.menu.cat_subs");
                    cat_subs_item.setMenu(cat_subs_menu);
                    Set<String> cats = buddy.getRemoteAuthorisedRSSTagsOrCategories();
                    cat_subs_item.setEnabled(cats != null && !cats.isEmpty());
                    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();
                            }
                            if (cats != null) {
                                for (final String cat : cats) {
                                    final MenuItem subs_item = new MenuItem(cat_subs_menu, SWT.CHECK);
                                    subs_item.setText(cat);
                                    subs_item.setSelection(buddy.isSubscribedToCategory(cat));
                                    subs_item.addSelectionListener(new SelectionAdapter() {

                                        @Override
                                        public void widgetSelected(SelectionEvent event) {
                                            if (buddy.isRemoteRSSTagOrCategoryAuthorised(cat)) {
                                                try {
                                                    buddy.subscribeToCategory(cat);
                                                } catch (Throwable e) {
                                                }
                                            }
                                        }
                                    });
                                }
                            }
                        }

                        @Override
                        public void menuHidden(MenuEvent arg0) {
                        }
                    });
                }
            }
            boolean pc_enable = false;
            boolean sk_enable = false;
            if (chat_pk != null) {
                for (ChatParticipant participant : participants) {
                    boolean is_me = Arrays.equals(participant.getPublicKey(), chat_pk);
                    boolean is_friend = participant.getFriendStatus() != 0;
                    if (!is_me) {
                        if (!is_friend) {
                            sk_enable = true;
                        }
                        pc_enable = true;
                    }
                }
            }
            private_chat_item.setEnabled(pc_enable);
            send_fk_item.setEnabled(sk_enable);
            friends_item.setEnabled(!participants.isEmpty());
        }
    }
    if (participants.size() == 1) {
        new MenuItem(menu, SWT.SEPARATOR);
        ChatParticipant participant = participants.get(0);
        String fk = participant.getFriendKey();
        final MenuItem mi_profile = new MenuItem(menu, SWT.PUSH);
        mi_profile.setText(lu.getLocalisedMessageText("label.profile") + "...");
        mi_profile.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                List<String> props = participant.getProfileData();
                List<String> names = new ArrayList<String>();
                List<String> values = new ArrayList<String>();
                names.add("label.help");
                values.add(Wiki.FRIENDS_PUBLIC_PROFILE);
                names.add("");
                values.add("");
                for (String prop : props) {
                    String[] bits = prop.split("=", 2);
                    if (bits.length == 2) {
                        names.add("!" + bits[0] + "!");
                        values.add(bits[1]);
                    }
                }
                BuddyPluginBuddy buddy = plugin.getBuddyFromPublicKey(fk);
                String nick = "";
                if (buddy != null) {
                    String n = buddy.getNickName();
                    if (n != null && !n.isEmpty()) {
                        nick = ": " + n;
                    }
                }
                new PropertiesWindow(lu.getLocalisedMessageText("label.profile") + nick, names, values);
            }
        });
        mi_profile.setEnabled(fk != null && participant.getProfileData() != null);
        final MenuItem mi_properties = new MenuItem(menu, SWT.PUSH);
        mi_properties.setText(lu.getLocalisedMessageText("Subscription.menu.properties"));
        List<String> names = new ArrayList<String>();
        List<String> values = new ArrayList<String>();
        names.add("label.zone.offset");
        values.add(participant.getZoneOffset());
        mi_properties.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                new PropertiesWindow(participant.getName(), names, values);
            }
        });
        mi_properties.setEnabled(!names.isEmpty());
        new MenuItem(menu, SWT.SEPARATOR);
        final MenuItem mi_copy_clip = new MenuItem(menu, SWT.PUSH);
        mi_copy_clip.setText(lu.getLocalisedMessageText("label.copy.to.clipboard"));
        mi_copy_clip.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                StringBuffer sb = new StringBuffer();
                sb.append(participants.get(0).getName(true));
                if (Constants.isCVSVersion()) {
                    List<ChatMessage> messages = participants.get(0).getMessages();
                    for (ChatMessage msg : messages) {
                        sb.append("\r\n" + msg.getMessage());
                    }
                }
                ClipboardCopy.copyToClipBoard(sb.toString());
            }
        });
    }
}
Also used : List(java.util.List) PropertiesWindow(com.biglybt.ui.swt.PropertiesWindow) TagManager(com.biglybt.core.tag.TagManager) BuddyPluginBuddy(com.biglybt.plugin.net.buddy.BuddyPluginBuddy) Tag(com.biglybt.core.tag.Tag)

Example 2 with PropertiesWindow

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

the class SearchUtils method showProperties.

private static void showProperties(Engine engine) {
    String engine_str;
    String auth_str = String.valueOf(false);
    engine_str = engine.getNameEx();
    String url_str = null;
    if (engine instanceof WebEngine) {
        WebEngine web_engine = (WebEngine) engine;
        if (web_engine.isNeedsAuth()) {
            auth_str = String.valueOf(true) + ": cookies=" + toString(web_engine.getRequiredCookies());
        }
        url_str = web_engine.getSearchUrl();
    }
    String[] keys = { "subs.prop.template", "subs.prop.auth", "subs.prop.query", "label.anon", "subs.prop.version" };
    String[] values = { engine_str, auth_str, url_str, String.valueOf(engine.isAnonymous()), String.valueOf(engine.getVersion()) };
    new PropertiesWindow(engine.getName(), keys, values);
}
Also used : PropertiesWindow(com.biglybt.ui.swt.PropertiesWindow) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine)

Aggregations

PropertiesWindow (com.biglybt.ui.swt.PropertiesWindow)2 WebEngine (com.biglybt.core.metasearch.impl.web.WebEngine)1 Tag (com.biglybt.core.tag.Tag)1 TagManager (com.biglybt.core.tag.TagManager)1 BuddyPluginBuddy (com.biglybt.plugin.net.buddy.BuddyPluginBuddy)1 List (java.util.List)1