use of com.biglybt.pif.ui.menus.MenuItemListener in project BiglyBT by BiglySoftware.
the class ChatMDIEntry method setupMdiEntry.
private void setupMdiEntry(UIManager ui_manager) {
mdi_entry.setViewTitleInfo(this);
MdiEntryDropListener drop_listener = new MdiEntryDropListener() {
@Override
public boolean mdiEntryDrop(MdiEntry entry, Object payload) {
if (payload instanceof String[]) {
String[] derp = (String[]) payload;
if (derp.length > 0) {
payload = derp[0];
}
}
if (!(payload instanceof String)) {
return false;
}
MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
if (mdi != null) {
String drop = (String) payload;
if (view == null) {
drop_outstanding = drop;
} else {
view.handleDrop(drop);
}
mdi.showEntry(mdi_entry);
return (true);
} else {
return (false);
}
}
};
mdi_entry.addListener(drop_listener);
mdi_entry.addListener(new MdiCloseListener() {
@Override
public void mdiEntryClosed(MdiEntry entry, boolean user) {
chat.removeListener(adapter);
chat.destroy();
}
});
String menu_key = "sidebar." + mdi_entry.getViewID();
MenuManager menu_manager = ui_manager.getMenuManager();
MenuItem menu_item = menu_manager.addMenuItem(menu_key, "iconBar.remove");
Utils.setMenuItemImage(menu_item, "delete");
menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
chat.remove();
}
});
menu_item = menu_manager.addMenuItem(menu_key, "sep");
menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
mdi_entry.setImageLeftID("image.sidebar.chat-overview");
chat.addListener(adapter);
}
use of com.biglybt.pif.ui.menus.MenuItemListener in project BiglyBT by BiglySoftware.
the class BuddyPlugin method initialize.
@Override
public void initialize(final PluginInterface _plugin_interface) {
plugin_interface = _plugin_interface;
ta_category = plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_CATEGORY);
logger = plugin_interface.getLogger().getChannel("Friends");
logger.setDiagnostic();
plugin_networks = new BuddyPluginNetwork[] { new BuddyPluginNetwork(plugin_interface, this, AENetworkClassifier.AT_PUBLIC), new BuddyPluginNetwork(plugin_interface, this, AENetworkClassifier.AT_I2P) };
final LocaleUtilities lu = plugin_interface.getUtilities().getLocaleUtilities();
Properties l10n_constants = new Properties();
l10n_constants.put("azbuddy.classic.link.url", Wiki.FRIENDS);
l10n_constants.put("azbuddy.dchat.link.url", Wiki.DECENTRALIZED_CHAT);
l10n_constants.put("azbuddy.profile.info.url", Wiki.FRIENDS_PUBLIC_PROFILE);
lu.integrateLocalisedMessageBundle(l10n_constants);
lu.addListener(new LocaleListener() {
@Override
public void localeChanged(Locale l) {
updateLocale(lu);
}
});
updateLocale(lu);
BasicPluginConfigModel config = plugin_interface.getUIManager().createBasicPluginConfigModel("Views.plugins." + VIEW_ID + ".title");
// enabled
classic_enabled_param = config.addBooleanParameter2("azbuddy.enabled", "azbuddy.enabled", false);
ParameterTabFolder network_tab = config.createTabFolder();
ParameterGroup network_anon_item = null;
for (int i = 0; i < 2; i++) {
boolean is_pub_tab = i == 0;
String suffix = is_pub_tab ? "" : ".anon";
// nickname
StringParameter nick_param = config.addStringParameter2("azbuddy.nickname" + suffix, "azbuddy.nickname", "");
nick_param.setGenerateIntermediateEvents(false);
nick_param.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
updateNickName(is_pub_tab, nick_param.getValue());
}
});
// online status
String[] os_values = STATUS_VALUES;
String[] os_labels = STATUS_STRINGS;
StringListParameter os_param = config.addStringListParameter2("azbuddy.online_status" + suffix, "azbuddy.online_status", os_values, os_labels, os_values[0]);
os_param.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
updateOnlineStatus(is_pub_tab, Integer.parseInt(os_param.getValue()));
}
});
// If we add this then use proper message texts in the STATUS_STRINGS
os_param.setVisible(SUPPORT_ONLINE_STATUS);
StringParameter profile_param = config.addStringParameter2("azbuddy.profile.info" + suffix, "", "");
profile_param.setLabelText("<a href=\"" + MessageText.getString("azbuddy.profile.info.url") + "\">" + MessageText.getString("azbuddy.profile.info") + "</a>");
profile_param.setMultiLine(5);
profile_param.setGenerateIntermediateEvents(false);
profile_param.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
updateProfiles();
}
});
ParameterGroup profile_group = config.createGroup(is_pub_tab ? "azbuddy.public.profile" : "azbuddy.anon.profile", new Parameter[] { profile_param });
ParameterGroup network_item = config.createGroup(is_pub_tab ? "label.public" : "label.anon", new Parameter[] { nick_param, os_param, profile_group });
if (is_pub_tab) {
nick_name_public_param = nick_param;
online_status_public_param = os_param;
profile_public_param = profile_param;
} else {
nick_name_anon_param = nick_param;
online_status_anon_param = os_param;
profile_anon_param = profile_param;
network_anon_item = network_item;
}
network_tab.addTab(network_item);
}
updateProfiles();
// protocol speed
final IntParameter protocol_speed = config.addIntParameter2("azbuddy.protocolspeed", "azbuddy.protocolspeed", 32);
protocol_speed.setMinimumRequiredUserMode(Parameter.MODE_ADVANCED);
ConnectionManager cman = plugin_interface.getConnectionManager();
int inbound_limit = protocol_speed.getValue() * 1024;
inbound_limiter = cman.createRateLimiter("buddy_up", inbound_limit);
outbound_limiter = cman.createRateLimiter("buddy_down", 0);
protocol_speed.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
inbound_limiter.setRateLimitBytesPerSecond(protocol_speed.getValue() * 1024);
}
});
// chat notifications
enable_chat_notifications = config.addBooleanParameter2("azbuddy.enable_chat_notif", "azbuddy.enable_chat_notif", true);
// default published tags or cats
cat_pub = config.addStringParameter2("azbuddy.enable_cat_pub", "azbuddy.enable_cat_pub", "");
cat_pub.setGenerateIntermediateEvents(false);
setPublicTagsOrCategories(cat_pub.getValue(), false);
final BooleanParameter tracker_enable = config.addBooleanParameter2("azbuddy.tracker.enabled", "azbuddy.tracker.enabled", true);
final BooleanParameter tracker_so_enable = config.addBooleanParameter2("azbuddy.tracker.seeding.only.enabled", "azbuddy.tracker.seeding.only.enabled", false);
// nasty hack but the existing text has a \t prefix that causes UI weirdness but I don't want to change it and
// end up with missing translations...
tracker_so_enable.setLabelText(MessageText.getString("azbuddy.tracker.seeding.only.enabled").trim());
tracker_so_enable.setIndent(1, true);
final BooleanParameter buddies_lan_local = config.addBooleanParameter2("azbuddy.tracker.con.lan.local", "azbuddy.tracker.con.lan.local", true);
buddies_lan_local.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
lan_local_peers = buddies_lan_local.getValue();
}
});
lan_local_peers = buddies_lan_local.getValue();
final BooleanParameter buddies_fp_enable = config.addBooleanParameter2("azbuddy.tracker.fp.enable", "azbuddy.tracker.fp.enable", true);
buddies_fp_enable.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
fp_enable = buddies_fp_enable.getValue();
}
});
fp_enable = buddies_fp_enable.getValue();
cat_pub.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
setPublicTagsOrCategories(cat_pub.getValue(), false);
}
});
config.createGroup("label.friends", new Parameter[] { classic_enabled_param, network_tab, protocol_speed, enable_chat_notifications, cat_pub, tracker_enable, tracker_so_enable, buddies_lan_local, buddies_fp_enable });
// decentralised stuff
beta_enabled_param = config.addBooleanParameter2("azbuddy.dchat.decentralized.enabled", "azbuddy.dchat.decentralized.enabled", true);
config.createGroup("azbuddy.dchat.decentralized", new Parameter[] { beta_enabled_param });
config.addLabelParameter2("azbuddy.dchat.more.settings");
// config end
beta_plugin = new BuddyPluginBeta(plugin_interface, this, beta_enabled_param);
for (String table_id : TableManager.TABLE_MYTORRENTS_ALL) {
TableContextMenuItem menu_item = plugin_interface.getUIManager().getTableManager().addContextMenuItem(table_id, "azbuddy.contextmenu");
menu_item.setStyle(TableContextMenuItem.STYLE_MENU);
menu_item.setHeaderCategory(MenuItem.HEADER_SOCIAL);
MenuItemFillListener menu_fill_listener = new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object _target) {
menu.removeAllChildItems();
if (!(isClassicEnabled() && isAvailable())) {
menu.setEnabled(false);
return;
}
final List<Torrent> torrents = new ArrayList<>();
if (_target instanceof TableRow) {
addDownload(torrents, (TableRow) _target);
} else {
TableRow[] rows = (TableRow[]) _target;
for (TableRow row : rows) {
addDownload(torrents, row);
}
}
if (torrents.size() == 0) {
menu.setEnabled(false);
} else {
List<BuddyPluginBuddy> buddies = getBuddies();
for (int i = 0; i < buddies.size(); i++) {
final BuddyPluginBuddy buddy = (BuddyPluginBuddy) buddies.get(i);
boolean online = buddy.isOnline(true);
TableContextMenuItem item = plugin_interface.getUIManager().getTableManager().addContextMenuItem(menu_item, "!" + (buddy.getName() + (buddy.isPublicNetwork() ? "" : (" (" + MessageText.getString("label.anon.medium") + ")"))) + (online ? "" : (" - " + MessageText.getString("label.disconnected"))) + "!");
item.addMultiListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
for (Torrent torrent : torrents) {
buddy.getPluginNetwork().getAZ2Handler().sendAZ2Torrent(torrent, buddy);
}
}
});
item.setEnabled(online);
}
menu.setEnabled(true);
}
}
protected void addDownload(List<Torrent> torrents, TableRow row) {
Object obj = row.getDataSource();
Download download;
if (obj instanceof Download) {
download = (Download) obj;
} else {
DiskManagerFileInfo file = (DiskManagerFileInfo) obj;
try {
download = file.getDownload();
} catch (DownloadException e) {
Debug.printStackTrace(e);
return;
}
}
Torrent torrent = download.getTorrent();
if (torrent != null && !TorrentUtils.isReallyPrivate(PluginCoreUtils.unwrap(torrent))) {
torrents.add(torrent);
}
}
};
menu_item.addFillListener(menu_fill_listener);
}
buddy_tracker = new BuddyPluginTracker(this, tracker_enable, tracker_so_enable);
plugin_interface.getUIManager().addUIListener(new UIManagerListener() {
@Override
public void UIAttached(final UIInstance instance) {
if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
try {
synchronized (swt_ui_waiters) {
swt_ui = (BuddyPluginViewInterface) Class.forName("com.biglybt.plugin.net.buddy.swt.BuddyPluginView").getConstructor(new Class[] { BuddyPlugin.class, UIInstance.class }).newInstance(new Object[] { BuddyPlugin.this, instance });
for (Runnable r : swt_ui_waiters) {
try {
r.run();
} catch (Throwable e) {
Debug.out(e);
}
}
swt_ui_waiters.clear();
}
} catch (Throwable e) {
Debug.out(e);
}
}
setupDisablePrompt(instance);
}
@Override
public void UIDetached(UIInstance instance) {
if (instance.getUIType().equals(UIInstance.UIT_SWT) && swt_ui != null) {
swt_ui.destroy();
swt_ui = null;
}
}
});
final ParameterGroup f_network_anon_item = network_anon_item;
ParameterListener enabled_listener = new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
boolean classic_enabled = classic_enabled_param.getValue();
nick_name_public_param.setEnabled(classic_enabled);
online_status_public_param.setEnabled(classic_enabled);
nick_name_anon_param.setEnabled(classic_enabled);
online_status_anon_param.setEnabled(classic_enabled);
protocol_speed.setEnabled(classic_enabled);
enable_chat_notifications.setEnabled(classic_enabled);
cat_pub.setEnabled(classic_enabled);
tracker_enable.setEnabled(classic_enabled);
tracker_so_enable.setEnabled(classic_enabled && tracker_enable.getValue());
buddies_lan_local.setEnabled(classic_enabled);
buddies_fp_enable.setEnabled(classic_enabled);
network_tab.setEnabled(classic_enabled);
f_network_anon_item.setEnabled(classic_enabled && I2PHelpers.isI2PInstalled());
if (param != null) {
for (BuddyPluginNetwork pn : plugin_networks) {
pn.setClassicEnabledInternal(classic_enabled);
}
fireEnabledStateChanged();
}
}
};
classic_enabled_param.addListener(enabled_listener);
beta_enabled_param.addListener(enabled_listener);
tracker_enable.addListener(enabled_listener);
for (BuddyPluginNetwork pn : plugin_networks) {
pn.loadConfig();
pn.registerMessageHandler();
}
plugin_interface.addListener(new PluginListener() {
@Override
public void initializationComplete() {
enabled_listener.parameterChanged(null);
final DelayedTask dt = plugin_interface.getUtilities().createDelayedTask(new Runnable() {
@Override
public void run() {
new AEThread2("BuddyPlugin:init", true) {
@Override
public void run() {
startup();
beta_plugin.startup();
initialization_complete.set(true);
}
}.start();
}
});
dt.queue();
}
@Override
public void closedownInitiated() {
// meh, moved this to core listener below as we need to closedown before
// i2p plugin so connections aren't torn down before we can tidily close
}
@Override
public void closedownComplete() {
}
});
CoreFactory.getSingleton().addLifecycleListener(new CoreLifecycleAdapter() {
@Override
public boolean syncInvokeRequired() {
return (true);
}
@Override
public void stopping(Core core) {
for (BuddyPluginNetwork pn : plugin_networks) {
pn.saveConfig(true);
pn.closedown();
}
beta_plugin.closedown();
}
});
}
use of com.biglybt.pif.ui.menus.MenuItemListener in project BiglyBT by BiglySoftware.
the class BaseMDI method fillMenu.
public void fillMenu(Menu menu, final MdiEntry entry, String menuID) {
com.biglybt.pif.ui.menus.MenuItem[] menu_items;
menu_items = MenuItemManager.getInstance().getAllAsArray(menuID);
MenuBuildUtils.addPluginMenuItems(menu_items, menu, false, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Object[] { entry }));
if (entry != null) {
menu_items = MenuItemManager.getInstance().getAllAsArray(getMenuIdPrefix() + entry.getViewID());
if (menu_items.length == 0) {
if (entry instanceof UISWTView) {
PluginInterface pi = ((UISWTView) entry).getPluginInterface();
if (pi != null) {
final List<String> relevant_sections = new ArrayList<>();
List<ConfigSectionHolder> sections = ConfigSectionRepository.getInstance().getHolderList();
for (ConfigSectionHolder cs : sections) {
if (pi == cs.getPluginInterface()) {
relevant_sections.add(cs.getConfigSectionID());
}
}
if (relevant_sections.size() > 0) {
MenuItem mi = pi.getUIManager().getMenuManager().addMenuItem(getMenuIdPrefix() + entry.getViewID(), "MainWindow.menu.view.configuration");
mi.setDisposeWithUIDetach(UIInstance.UIT_SWT);
mi.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (uif != null) {
for (String s : relevant_sections) {
uif.getMDI().showEntryByID(SIDEBAR_SECTION_CONFIG, s);
}
}
}
});
menu_items = MenuItemManager.getInstance().getAllAsArray(getMenuIdPrefix() + entry.getViewID());
}
}
}
}
MenuBuildUtils.addPluginMenuItems(menu_items, menu, false, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Object[] { entry }));
MdiSWTMenuHackListener[] menuHackListeners = getMenuHackListeners();
for (MdiSWTMenuHackListener l : menuHackListeners) {
try {
l.menuWillBeShown(entry, menu);
} catch (Exception e) {
Debug.out(e);
}
}
if (currentEntry instanceof BaseMdiEntry) {
menuHackListeners = ((BaseMdiEntry) entry).getMenuHackListeners();
for (MdiSWTMenuHackListener l : menuHackListeners) {
try {
l.menuWillBeShown(entry, menu);
} catch (Exception e) {
Debug.out(e);
}
}
}
}
menu_items = MenuItemManager.getInstance().getAllAsArray(menuID + "._end_");
if (menu_items.length > 0) {
MenuBuildUtils.addPluginMenuItems(menu_items, menu, false, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Object[] { entry }));
}
}
use of com.biglybt.pif.ui.menus.MenuItemListener in project BiglyBT by BiglySoftware.
the class DateCompletedItem method addMenu.
private void addMenu() {
TableContextMenuItem menuItem = addContextMenuItem("MyTorrentsView.menu.datecomp.reset");
menuItem.setHeaderCategory(MenuItem.HEADER_OTHER);
menuItem.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object target) {
boolean enabled = false;
if (target != null) {
Object[] o = (Object[]) target;
for (Object object : o) {
if (object instanceof TableRowCore) {
object = ((TableRowCore) object).getDataSource(true);
}
if (object instanceof DownloadManager) {
DownloadManager dm = (DownloadManager) object;
if (dm.isDownloadComplete(false)) {
enabled = true;
break;
}
}
}
}
menuItem.setEnabled(enabled);
}
});
menuItem.addMultiListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
if (target == null) {
return;
}
Object[] o = (Object[]) target;
Utils.getOffOfSWTThread(() -> {
for (Object object : o) {
if (object instanceof TableRowCore) {
TableRowCore row = (TableRowCore) object;
object = row.getDataSource(true);
if (object instanceof DownloadManager) {
DownloadManager dm = (DownloadManager) object;
if (dm.isDownloadComplete(false)) {
long last_mod = 0;
DiskManagerFileInfo[] files = dm.getDiskManagerFileInfoSet().getFiles();
for (DiskManagerFileInfo file : files) {
if (!file.isSkipped()) {
File f = file.getFile(true);
if (f.length() == file.getLength()) {
long mod = f.lastModified();
if (mod > last_mod) {
last_mod = mod;
}
}
}
}
if (last_mod > 0) {
DownloadManagerState dms = dm.getDownloadState();
dms.setLongParameter(DownloadManagerState.PARAM_DOWNLOAD_FILE_COMPLETED_TIME, last_mod);
dms.setLongParameter(DownloadManagerState.PARAM_DOWNLOAD_COMPLETED_TIME, last_mod);
dms.setLongAttribute(DownloadManagerState.AT_COMPLETE_LAST_TIME, last_mod);
row.invalidate(true);
row.refresh(true);
}
}
}
}
}
});
}
});
}
use of com.biglybt.pif.ui.menus.MenuItemListener 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();
if (chat_key_resolver.canShareMessage()) {
MenuItem chat_share = menu_manager.addMenuItem(chat_item, "menu.share.download");
addChatSelectionMenu(menu_manager, chat_share, null, new ChatSelectionListener() {
public void chatSelected(Object target, String chat) {
}
public void chatAvailable(Object target, ChatInstance chat) {
chat_key_resolver.shareMessage(target, chat);
}
});
MenuItem mi = menu_manager.addMenuItem(chat_item, "sep");
mi.setStyle(MenuItem.STYLE_SEPARATOR);
}
MenuItem discuss_menu = menu_manager.addMenuItem(chat_item, chat_key_resolver.getResourceKey());
discuss_menu.setStyle(MenuItem.STYLE_MENU);
{
MenuItem chat_pub = menu_manager.addMenuItem(discuss_menu, "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(discuss_menu, "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);
}
Aggregations