diff options
author | Ingo Bauersachs <ingo@jitsi.org> | 2017-01-14 00:32:32 +0100 |
---|---|---|
committer | Ingo Bauersachs <ingo@jitsi.org> | 2017-01-14 00:32:32 +0100 |
commit | 56944196405c61da3e407cbaa4e4a76017ac43d2 (patch) | |
tree | 4a10f1b0d3c7a91068de85d6b1b2ddbecf0bc834 /src | |
parent | 59c28f3b0eed75ed0f88bcda00f379906c3d00c9 (diff) | |
download | jitsi-56944196405c61da3e407cbaa4e4a76017ac43d2.zip jitsi-56944196405c61da3e407cbaa4e4a76017ac43d2.tar.gz jitsi-56944196405c61da3e407cbaa4e4a76017ac43d2.tar.bz2 |
AppIndicator logging and clean up
Diffstat (limited to 'src')
3 files changed, 88 insertions, 55 deletions
diff --git a/src/net/java/sip/communicator/impl/osdependent/systemtray/appindicator/AppIndicatorTrayIcon.java b/src/net/java/sip/communicator/impl/osdependent/systemtray/appindicator/AppIndicatorTrayIcon.java index 8779312..a5bbee1 100644 --- a/src/net/java/sip/communicator/impl/osdependent/systemtray/appindicator/AppIndicatorTrayIcon.java +++ b/src/net/java/sip/communicator/impl/osdependent/systemtray/appindicator/AppIndicatorTrayIcon.java @@ -106,15 +106,22 @@ class AppIndicatorTrayIcon implements TrayIcon public Pointer gtkPixbuf; public Component menuItem; public MenuItemSignalHandler signalHandler; + public long gtkSignalHandler; @Override public void componentAdded(ContainerEvent e) { AppIndicatorTrayIcon.this.printMenu(popup.getComponents(), 1); gtk.gdk_threads_enter(); - createGtkMenuItems(this, new Component[]{e.getChild()}); - gtk.gtk_widget_show_all(popupPeer.gtkMenu); - gtk.gdk_threads_leave(); + try + { + createGtkMenuItems(this, new Component[]{e.getChild()}); + gtk.gtk_widget_show_all(popupPeer.gtkMenu); + } + finally + { + gtk.gdk_threads_leave(); + } } @Override @@ -126,9 +133,16 @@ class AppIndicatorTrayIcon implements TrayIcon if (c.menuItem == e.getChild()) { gtk.gdk_threads_enter(); - gtk.gtk_widget_destroy(c.gtkMenuItem); - gtk.gdk_threads_leave(); - cleanMenu(c); + try + { + cleanMenu(c); + } + finally + { + gtk.gdk_threads_leave(); + } + + children.remove(c); break; } } @@ -137,20 +151,16 @@ class AppIndicatorTrayIcon implements TrayIcon public void createTray() { - appIndicator = ai.app_indicator_new( + File iconFile = new File(imageIconToPath(mainIcon)); + appIndicator = ai.app_indicator_new_with_path( "jitsi", - "indicator-messages-new", - AppIndicator1.APP_INDICATOR_CATEGORY.COMMUNICATIONS.ordinal()); + iconFile.getName().replaceFirst("[.][^.]+$", ""), + AppIndicator1.APP_INDICATOR_CATEGORY.COMMUNICATIONS.ordinal(), + iconFile.getParent()); ai.app_indicator_set_title(appIndicator, title); setupGtkMenu(); - String path = imageIconToPath(mainIcon); - if (path != null) - { - ai.app_indicator_set_icon_full(appIndicator, path, "Jitsi"); - } - ai.app_indicator_set_status( appIndicator, AppIndicator1.APP_INDICATOR_STATUS.ACTIVE.ordinal()); @@ -180,6 +190,7 @@ class AppIndicatorTrayIcon implements TrayIcon private void cleanMenu(PopupMenuPeer peer) { + logger.debug("Clean requested for: " + peer.menuItem); for (PopupMenuPeer p : peer.children) { cleanMenu(p); @@ -188,22 +199,20 @@ class AppIndicatorTrayIcon implements TrayIcon // - the root menu is released when it's unset from the indicator // - gtk auto-frees menu item, submenu, image, and pixbuf // - the imagebuffer was jna allocated, GC should take care of freeing - peer.gtkImageBuffer = null; - removeListeners(peer); - } + if (peer.gtkSignalHandler > 0) + { + gobject.g_signal_handler_disconnect( + peer.gtkMenuItem, + peer.gtkSignalHandler); + } - private void removeListeners(PopupMenuPeer peer) - { + gtk.gtk_widget_destroy(peer.gtkMenuItem); + peer.gtkImageBuffer = null; if (peer.menuItem instanceof JMenu) { ((JMenu)peer.menuItem).removeContainerListener(peer); ((JMenu)peer.menuItem).getPopupMenu().removeContainerListener(peer); } - - for (PopupMenuPeer p : peer.children) - { - removeListeners(p); - } } private void createGtkMenuItems( @@ -212,17 +221,15 @@ class AppIndicatorTrayIcon implements TrayIcon { for (Component em : components) { - logger.debug("Creating item for " + em.getClass().getName()); PopupMenuPeer peer = new PopupMenuPeer(parent, em); if (em instanceof JPopupMenu.Separator) { + logger.debug("Creating separator"); peer.gtkMenuItem = gtk.gtk_separator_menu_item_new(); } if (em instanceof JMenuItem) { - JMenuItem m = (JMenuItem)em; - logger.debug(" title: " + m.getText()); createGtkMenuItem(peer); } @@ -246,6 +253,8 @@ class AppIndicatorTrayIcon implements TrayIcon private void createGtkMenuItem(PopupMenuPeer peer) { JMenuItem m = (JMenuItem)peer.menuItem; + logger.debug("Creating item for " + m.getClass().getName() + ": " + + m.getText()); if (m instanceof JCheckBoxMenuItem) { peer.gtkMenuItem = gtk.gtk_check_menu_item_new_with_label( @@ -292,13 +301,14 @@ class AppIndicatorTrayIcon implements TrayIcon peer.gtkMenuItem, m.isEnabled() ? 1 : 0); peer.signalHandler = new MenuItemSignalHandler(peer); - gobject.g_signal_connect_data( + peer.gtkSignalHandler = gobject.g_signal_connect_data( peer.gtkMenuItem, "activate", peer.signalHandler, null, null, 0); + logger.debug("Signal for " + ((JMenuItem)m).getText() + " is " + peer.gtkSignalHandler); } } @@ -426,17 +436,24 @@ class AppIndicatorTrayIcon implements TrayIcon { if (logger.isDebugEnabled()) { - logger.debug(menu.getText() + "::" + evt); + logger.debug(menu.getText() + "::" + evt.getPropertyName()); } switch (evt.getPropertyName()) { case JMenuItem.TEXT_CHANGED_PROPERTY: gtk.gdk_threads_enter(); - gtk.gtk_menu_item_set_label( - peer.gtkMenuItem, - evt.getNewValue().toString()); - gtk.gdk_threads_leave(); + try + { + gtk.gtk_menu_item_set_label( + peer.gtkMenuItem, + evt.getNewValue().toString()); + } + finally + { + gtk.gdk_threads_leave(); + } + break; // case JMenuItem.ICON_CHANGED_PROPERTY: // gtk.gtk_image_menu_item_set_image(gtkMenuItem, image); @@ -454,10 +471,16 @@ class AppIndicatorTrayIcon implements TrayIcon { logger.debug(menu.getText() + " -> " + menu.isSelected()); gtk.gdk_threads_enter(); - gtk.gtk_check_menu_item_set_active( - peer.gtkMenuItem, - menu.isSelected() ? 1 : 0); - gtk.gdk_threads_leave(); + try + { + gtk.gtk_check_menu_item_set_active( + peer.gtkMenuItem, + menu.isSelected() ? 1 : 0); + } + finally + { + gtk.gdk_threads_leave(); + } } } @@ -522,6 +545,9 @@ class AppIndicatorTrayIcon implements TrayIcon { if (peer.menuItem == menuItem) { + logger.debug("Setting default action to: " + + ((JMenuItem)menuItem).getText() + + " @" + peer.gtkMenuItem); return peer.gtkMenuItem; } @@ -553,10 +579,14 @@ class AppIndicatorTrayIcon implements TrayIcon @Override public void setIcon(ImageIcon icon) throws NullPointerException { - ai.app_indicator_set_icon_full( - appIndicator, - imageIconToPath(icon), - "Jitsi"); + mainIcon = icon; + if (appIndicator != null) + { + ai.app_indicator_set_icon_full( + appIndicator, + imageIconToPath(icon), + "Jitsi"); + } } @Override diff --git a/src/net/java/sip/communicator/impl/osdependent/systemtray/appindicator/Gobject.java b/src/net/java/sip/communicator/impl/osdependent/systemtray/appindicator/Gobject.java index 8a2349e..72c96cb 100644 --- a/src/net/java/sip/communicator/impl/osdependent/systemtray/appindicator/Gobject.java +++ b/src/net/java/sip/communicator/impl/osdependent/systemtray/appindicator/Gobject.java @@ -49,10 +49,24 @@ interface Gobject extends Library * @param data data to pass to c_handler calls. * @param destroy_data a GClosureNotify for data. * @param connect_flags a combination of GConnectFlags. + * + * @return the handler id (always greater than 0 for successful connections) */ - void g_signal_connect_data(Pointer instance, String detailed_signal, + long g_signal_connect_data(Pointer instance, String detailed_signal, SignalHandler c_handler, Pointer data, Pointer destroy_data, int connect_flags); + + /** + * Disconnects a handler from an instance so it will not be called during + * any future or currently ongoing emissions of the signal it has been + * connected to. The handler_id becomes invalid and may be reused. The + * handler_id has to be a valid signal handler id, connected to a signal of + * instance . + * + * @param instance The instance to remove the signal handler from. + * @param handler_id Handler id of the handler to be disconnected. + */ + void g_signal_handler_disconnect(Pointer instance, long handler_id); /** * Decreases the reference count of object. When its reference count drops diff --git a/src/net/java/sip/communicator/impl/osdependent/systemtray/appindicator/Gtk.java b/src/net/java/sip/communicator/impl/osdependent/systemtray/appindicator/Gtk.java index 7b74428..b66d59f 100644 --- a/src/net/java/sip/communicator/impl/osdependent/systemtray/appindicator/Gtk.java +++ b/src/net/java/sip/communicator/impl/osdependent/systemtray/appindicator/Gtk.java @@ -20,7 +20,7 @@ package net.java.sip.communicator.impl.osdependent.systemtray.appindicator; import com.sun.jna.*; /** - * JNA mappings for the gtk2 library. Only functions required for the try menu + * JNA mappings for the gtk2 library. Only functions required for the tray menu * are defined. * * @author Ingo Bauersachs @@ -44,14 +44,7 @@ interface Gtk extends Library void gtk_init(int argc, String[] argv); void gtk_main(); Pointer gtk_menu_new(); - Pointer gtk_menu_item_new(); - Pointer gtk_menu_item_new_with_label(String label); - Pointer gtk_image_menu_item_new_with_mnemonic(String label); Pointer gtk_image_menu_item_new_with_label(String label); - Pointer gtk_image_new_from_gicon(Pointer icon, int size); - Pointer gtk_image_new_from_stock(String stock_id, int size); - Pointer gtk_image_new_from_icon_name(String icon_name, int size); - Pointer gtk_image_new_from_file(String filename); Pointer gtk_separator_menu_item_new(); void gtk_menu_item_set_submenu(Pointer menu_item, Pointer submenu); void gtk_image_menu_item_set_image(Pointer image_menu_item, Pointer image); @@ -60,15 +53,11 @@ interface Gtk extends Library void gtk_menu_shell_append(Pointer menu_shell, Pointer child); void gtk_widget_set_sensitive(Pointer widget, int sesitive); void gtk_widget_show_all(Pointer widget); - //void gtk_container_remove(Pointer container, Pointer widget); void gtk_widget_destroy(Pointer widget); - void gtk_widget_show(Pointer widget); Pointer gtk_check_menu_item_new_with_label(String label); int gtk_check_menu_item_get_active(Pointer check_menu_item); void gtk_check_menu_item_set_active(Pointer check_menu_item, int is_active); - Pointer g_file_new_for_uri(String uri); - Pointer g_file_icon_new(Pointer file); void gdk_threads_enter(); void gdk_threads_leave(); |