Search in sources :

Example 11 with ChatInstance

use of com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance in project BiglyBT by BiglySoftware.

the class MenuBuildUtils method addChatMenu.

public static void addChatMenu(Menu menu, String menu_resource_key, final String chat_key) {
    final Menu chat_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
    final org.eclipse.swt.widgets.MenuItem chat_item = new org.eclipse.swt.widgets.MenuItem(menu, SWT.CASCADE);
    Messages.setLanguageText(chat_item, menu_resource_key);
    chat_item.setMenu(chat_menu);
    chat_menu.addMenuListener(new MenuAdapter() {

        @Override
        public void menuShown(MenuEvent e) {
            for (org.eclipse.swt.widgets.MenuItem mi : chat_menu.getItems()) {
                mi.dispose();
            }
            if (!BuddyPluginUtils.isBetaChatAvailable()) {
                return;
            }
            org.eclipse.swt.widgets.MenuItem chat_pub = new org.eclipse.swt.widgets.MenuItem(chat_menu, SWT.PUSH);
            Messages.setLanguageText(chat_pub, "label.public");
            chat_pub.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    pub_chat_pending.set(true);
                    BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_PUBLIC, chat_key, new BuddyPluginUtils.CreateChatCallback() {

                        @Override
                        public void complete(ChatInstance chat) {
                            pub_chat_pending.set(false);
                        }
                    });
                }
            });
            if (pub_chat_pending.get()) {
                chat_pub.setEnabled(false);
                chat_pub.setText(chat_pub.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
            }
            if (BuddyPluginUtils.isBetaChatAnonAvailable()) {
                org.eclipse.swt.widgets.MenuItem chat_priv = new org.eclipse.swt.widgets.MenuItem(chat_menu, SWT.PUSH);
                Messages.setLanguageText(chat_priv, "label.anon");
                chat_priv.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event event) {
                        anon_chat_pending.set(true);
                        BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_I2P, chat_key, new BuddyPluginUtils.CreateChatCallback() {

                            @Override
                            public void complete(ChatInstance chat) {
                                anon_chat_pending.set(false);
                            }
                        });
                    }
                });
                if (anon_chat_pending.get()) {
                    chat_priv.setEnabled(false);
                    chat_priv.setText(chat_priv.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
                }
            } else {
                org.eclipse.swt.widgets.MenuItem chat_priv = new org.eclipse.swt.widgets.MenuItem(chat_menu, SWT.PUSH);
                chat_priv.setText(MessageText.getString("label.anon") + "...");
                chat_priv.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event event) {
                        I2PHelpers.installI2PHelper(null, null, null);
                    }
                });
                if (I2PHelpers.isInstallingI2PHelper()) {
                    chat_priv.setEnabled(false);
                    chat_priv.setText(chat_priv.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
                }
            }
        }
    });
}
Also used : MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) Listener(org.eclipse.swt.widgets.Listener) MenuListener(org.eclipse.swt.events.MenuListener) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) MenuAdapter(org.eclipse.swt.events.MenuAdapter) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) Event(org.eclipse.swt.widgets.Event) MenuEvent(org.eclipse.swt.events.MenuEvent) Menu(org.eclipse.swt.widgets.Menu) BuddyPluginUtils(com.biglybt.plugin.net.buddy.BuddyPluginUtils) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 12 with ChatInstance

use of com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance in project BiglyBT by BiglySoftware.

the class MenuBuildUtils method addChatMenu.

public static MenuItem addChatMenu(final MenuManager menu_manager, final MenuItem chat_item, final ChatKeyResolver chat_key_resolver) {
    chat_item.setStyle(MenuItem.STYLE_MENU);
    chat_item.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object data) {
            menu.removeAllChildItems();
            {
                MenuItem chat_pub = menu_manager.addMenuItem(chat_item, "label.public");
                chat_pub.addMultiListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        Object[] rows = (Object[]) target;
                        if (rows.length > 0) {
                            final AtomicInteger count = new AtomicInteger(rows.length);
                            pub_chat_pending.set(true);
                            for (Object obj : rows) {
                                String chat_key = chat_key_resolver.getChatKey(obj);
                                if (chat_key != null) {
                                    BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_PUBLIC, chat_key, new BuddyPluginUtils.CreateChatCallback() {

                                        @Override
                                        public void complete(ChatInstance chat) {
                                            if (count.decrementAndGet() == 0) {
                                                pub_chat_pending.set(false);
                                            }
                                        }
                                    });
                                }
                            }
                        }
                    }
                });
                if (pub_chat_pending.get()) {
                    chat_pub.setEnabled(false);
                    chat_pub.setText(chat_pub.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
                }
            }
            if (BuddyPluginUtils.isBetaChatAnonAvailable()) {
                MenuItem chat_priv = menu_manager.addMenuItem(chat_item, "label.anon");
                chat_priv.addMultiListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        Object[] rows = (Object[]) target;
                        if (rows.length > 0) {
                            final AtomicInteger count = new AtomicInteger(rows.length);
                            anon_chat_pending.set(true);
                            for (Object obj : rows) {
                                String chat_key = chat_key_resolver.getChatKey(obj);
                                if (chat_key != null) {
                                    BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_I2P, chat_key, new BuddyPluginUtils.CreateChatCallback() {

                                        @Override
                                        public void complete(ChatInstance chat) {
                                            if (count.decrementAndGet() == 0) {
                                                anon_chat_pending.set(false);
                                            }
                                        }
                                    });
                                }
                            }
                        }
                    }
                });
                if (anon_chat_pending.get()) {
                    chat_priv.setEnabled(false);
                    chat_priv.setText(chat_priv.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
                }
            } else {
                MenuItem chat_priv = menu_manager.addMenuItem(chat_item, "label.anon");
                chat_priv.setText(MessageText.getString("label.anon") + "...");
                chat_priv.addMultiListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        I2PHelpers.installI2PHelper(null, null, null);
                    }
                });
                if (I2PHelpers.isInstallingI2PHelper()) {
                    chat_priv.setEnabled(false);
                    chat_priv.setText(chat_priv.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
                }
            }
        }
    });
    return (chat_item);
}
Also used : MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) BuddyPluginUtils(com.biglybt.plugin.net.buddy.BuddyPluginUtils)

Example 13 with ChatInstance

use of com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance in project BiglyBT by BiglySoftware.

the class TorrentUtil method isFileTorrent.

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

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

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

Aggregations

ChatInstance (com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance)13 MenuItem (com.biglybt.pif.ui.menus.MenuItem)6 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)5 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)3 TableContextMenuItem (com.biglybt.pif.ui.tables.TableContextMenuItem)3 Download (com.biglybt.pif.download.Download)2 BuddyPluginUtils (com.biglybt.plugin.net.buddy.BuddyPluginUtils)2 UISWTStatusEntry (com.biglybt.ui.swt.pif.UISWTStatusEntry)2 UISWTView (com.biglybt.ui.swt.pif.UISWTView)2 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)2 IOException (java.io.IOException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)2 MenuAdapter (org.eclipse.swt.events.MenuAdapter)2 MenuEvent (org.eclipse.swt.events.MenuEvent)2 MenuListener (org.eclipse.swt.events.MenuListener)2 Composite (org.eclipse.swt.widgets.Composite)2