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") + ")");
}
}
}
});
}
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);
}
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;
}
Aggregations