aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2011-02-03 12:49:01 +0100
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2011-02-03 12:49:01 +0100
commitb5660e8977f5d4ffa28bfe4cfe30e5d7cf4ce944 (patch)
tree91d9e8441bda99a520e6bd24a82da1dece1142d0 /src
parent0d97a5e6201be283ba2dd017297b71122c7f19e2 (diff)
parent19c543fd42571ef3e011db21a6d93e93d7da4483 (diff)
downloadlibayatana-appindicator-b5660e8977f5d4ffa28bfe4cfe30e5d7cf4ce944.tar.gz
libayatana-appindicator-b5660e8977f5d4ffa28bfe4cfe30e5d7cf4ce944.tar.bz2
libayatana-appindicator-b5660e8977f5d4ffa28bfe4cfe30e5d7cf4ce944.zip
Merge against new trunk
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/app-indicator.c394
-rw-r--r--src/appindicator3-0.1.pc.in2
3 files changed, 24 insertions, 374 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 069247f..b9ee3e1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -45,7 +45,7 @@ glib_enum_headers = $(addprefix $(srcdir)/, $(libappindicator_headers))
DISTCLEANFILES += app-indicator-enum-types.c
-libappindicatorincludedir=$(includedir)/libappindicator$(VER)-0.1/libappindicator
+libappindicatorincludedir=$(includedir)/libappindicator-0.1/libappindicator
libappindicator_headers = \
app-indicator.h
diff --git a/src/app-indicator.c b/src/app-indicator.c
index 26d8c73..7bee341 100644
--- a/src/app-indicator.c
+++ b/src/app-indicator.c
@@ -34,6 +34,7 @@ License version 3 and version 2.1 along with this program. If not, see
#include <libdbusmenu-glib/menuitem.h>
#include <libdbusmenu-glib/server.h>
#include <libdbusmenu-gtk/client.h>
+#include <libdbusmenu-gtk/parser.h>
#include <libindicator/indicator-desktop-shortcuts.h>
@@ -178,7 +179,6 @@ static void unfallback (AppIndicator * self, GtkStatusIcon * status_icon);
static gchar * append_panel_icon_suffix (const gchar * icon_name);
static void watcher_owner_changed (GObject * obj, GParamSpec * pspec, gpointer user_data);
static void client_menu_changed (GtkWidget *widget, GtkWidget *child, AppIndicator *indicator);
-static void submenu_changed (GtkWidget *widget, GtkWidget *child, gpointer data);
static void theme_changed_cb (GtkIconTheme * theme, gpointer user_data);
static GVariant * bus_get_prop (GDBusConnection * connection, const gchar * sender, const gchar * path, const gchar * interface, const gchar * property, GError ** error, gpointer user_data);
static void bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar * path, const gchar * interface, const gchar * method, GVariant * params, GDBusMethodInvocation * invocation, gpointer user_data);
@@ -1759,385 +1759,35 @@ app_indicator_set_icon_theme_path (AppIndicator *self, const gchar *icon_theme_p
return;
}
-static void
-activate_menuitem (DbusmenuMenuitem *mi, guint timestamp, gpointer user_data)
-{
- GtkWidget *widget = (GtkWidget *)user_data;
-
- gtk_menu_item_activate (GTK_MENU_ITEM (widget));
-}
-
-static void
-widget_toggled (GtkWidget *widget, DbusmenuMenuitem *mi)
-{
- dbusmenu_menuitem_property_set_int (mi,
- DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
- gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget)) ? DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED);
-}
-
-static void
-menuitem_iterate (GtkWidget *widget,
- gpointer data)
-{
- if (GTK_IS_LABEL (widget))
- {
- DbusmenuMenuitem *child = (DbusmenuMenuitem *)data;
-
- dbusmenu_menuitem_property_set (child,
- DBUSMENU_MENUITEM_PROP_LABEL,
- gtk_label_get_text (GTK_LABEL (widget)));
- }
-}
-
-static gboolean
-should_show_image (GtkImage *image)
-{
- GtkWidget *item;
-
- item = gtk_widget_get_ancestor (GTK_WIDGET (image),
- GTK_TYPE_IMAGE_MENU_ITEM);
-
- if (item)
- {
- GtkSettings *settings;
- gboolean gtk_menu_images;
-
- settings = gtk_widget_get_settings (item);
-
- g_object_get (settings, "gtk-menu-images", &gtk_menu_images, NULL);
-
- if (gtk_menu_images)
- return TRUE;
-
- return gtk_image_menu_item_get_always_show_image (GTK_IMAGE_MENU_ITEM (item));
- }
-
- return FALSE;
-}
-
-static void
-update_icon_name (DbusmenuMenuitem *menuitem,
- GtkImage *image)
-{
- const gchar *icon_name = NULL;
-
- if (gtk_image_get_storage_type (image) != GTK_IMAGE_ICON_NAME)
- return;
-
- gtk_image_get_icon_name (image, &icon_name, NULL);
-
- if (should_show_image (image))
- dbusmenu_menuitem_property_set (menuitem,
- DBUSMENU_MENUITEM_PROP_ICON_NAME,
- icon_name);
- else
- dbusmenu_menuitem_property_remove (menuitem,
- DBUSMENU_MENUITEM_PROP_ICON_NAME);
-}
-
-/* return value specifies whether the label is set or not */
-static gboolean
-update_stock_item (DbusmenuMenuitem *menuitem,
- GtkImage *image)
-{
- GtkStockItem stock;
- gchar *stock_id = NULL;
-
- if (gtk_image_get_storage_type (image) != GTK_IMAGE_STOCK)
- return FALSE;
-
- gtk_image_get_stock (image, &stock_id, NULL);
- gtk_stock_lookup (stock_id, &stock);
-
- if (should_show_image (image))
- dbusmenu_menuitem_property_set (menuitem,
- DBUSMENU_MENUITEM_PROP_ICON_NAME,
- stock_id);
- else
- dbusmenu_menuitem_property_remove (menuitem,
- DBUSMENU_MENUITEM_PROP_ICON_NAME);
-
- const gchar * label = dbusmenu_menuitem_property_get (menuitem,
- DBUSMENU_MENUITEM_PROP_LABEL);
-
- if (stock.label != NULL && label != NULL)
- {
- dbusmenu_menuitem_property_set (menuitem,
- DBUSMENU_MENUITEM_PROP_LABEL,
- stock.label);
-
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-image_notify_cb (GtkWidget *widget,
- GParamSpec *pspec,
- gpointer data)
-{
- DbusmenuMenuitem *child = (DbusmenuMenuitem *)data;
- GtkImage *image = GTK_IMAGE (widget);
-
- if (pspec->name == g_intern_static_string ("stock"))
- {
- update_stock_item (child, image);
- }
- else if (pspec->name == g_intern_static_string ("icon-name"))
- {
- update_icon_name (child, image);
- }
-}
-
-static void
-widget_notify_cb (GtkWidget *widget,
- GParamSpec *pspec,
- gpointer data)
-{
- DbusmenuMenuitem *child = (DbusmenuMenuitem *)data;
-
- if (pspec->name == g_intern_static_string ("sensitive"))
- {
- dbusmenu_menuitem_property_set_bool (child,
- DBUSMENU_MENUITEM_PROP_ENABLED,
- gtk_widget_is_sensitive (widget));
- }
- else if (pspec->name == g_intern_static_string ("label"))
- {
- dbusmenu_menuitem_property_set (child,
- DBUSMENU_MENUITEM_PROP_LABEL,
- gtk_menu_item_get_label (GTK_MENU_ITEM (widget)));
- }
- else if (pspec->name == g_intern_static_string ("visible"))
- {
- dbusmenu_menuitem_property_set_bool (child,
- DBUSMENU_MENUITEM_PROP_VISIBLE,
- gtk_widget_get_visible (widget));
- }
-}
-
-static void
-action_notify_cb (GtkAction *action,
- GParamSpec *pspec,
- gpointer data)
-{
- DbusmenuMenuitem *child = (DbusmenuMenuitem *)data;
-
- if (pspec->name == g_intern_static_string ("active"))
- {
- dbusmenu_menuitem_property_set_bool (child,
- DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
- gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
- }
-
- if (pspec->name == g_intern_static_string ("label"))
- {
- dbusmenu_menuitem_property_set (child,
- DBUSMENU_MENUITEM_PROP_LABEL,
- gtk_action_get_label (action));
- }
-}
-
-static void
-container_iterate (GtkWidget *widget,
- gpointer data)
-{
- DbusmenuMenuitem *root = (DbusmenuMenuitem *)data;
- DbusmenuMenuitem *child;
- GtkWidget *submenu = NULL;
- const gchar *label = NULL;
- gboolean label_set = FALSE;
-
- if (GTK_IS_TEAROFF_MENU_ITEM(widget)) {
- return;
- }
-
- child = dbusmenu_menuitem_new ();
-
- if (GTK_IS_SEPARATOR_MENU_ITEM (widget))
- {
- dbusmenu_menuitem_property_set (child,
- "type",
- DBUSMENU_CLIENT_TYPES_SEPARATOR);
- }
- else
- {
- if (GTK_IS_CHECK_MENU_ITEM (widget))
- {
- GtkCheckMenuItem *check;
-
- check = GTK_CHECK_MENU_ITEM (widget);
- label = gtk_menu_item_get_label (GTK_MENU_ITEM (widget));
-
- dbusmenu_menuitem_property_set (child,
- DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE,
- GTK_IS_RADIO_MENU_ITEM (widget) ? DBUSMENU_MENUITEM_TOGGLE_RADIO : DBUSMENU_MENUITEM_TOGGLE_CHECK);
-
- dbusmenu_menuitem_property_set (child,
- DBUSMENU_MENUITEM_PROP_LABEL,
- label);
-
- label_set = TRUE;
-
- dbusmenu_menuitem_property_set_int (child,
- DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
- gtk_check_menu_item_get_active (check) ? DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED);
-
- g_signal_connect (widget,
- "toggled",
- G_CALLBACK (widget_toggled),
- child);
- }
- else if (GTK_IS_IMAGE_MENU_ITEM (widget))
- {
- GtkWidget *image;
- GtkImageType image_type;
-
- image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (widget));
- image_type = gtk_image_get_storage_type (GTK_IMAGE (image));
-
- g_signal_connect (image,
- "notify",
- G_CALLBACK (image_notify_cb),
- child);
-
- if (image_type == GTK_IMAGE_STOCK)
- {
- label_set = update_stock_item (child, GTK_IMAGE (image));
- }
- else if (image_type == GTK_IMAGE_ICON_NAME)
- {
- update_icon_name (child, GTK_IMAGE (image));
- }
- }
- }
-
- if (!label_set)
- {
- if (label != NULL)
- {
- dbusmenu_menuitem_property_set (child,
- DBUSMENU_MENUITEM_PROP_LABEL,
- label);
- }
- else
- {
- /* find label child widget */
- gtk_container_forall (GTK_CONTAINER (widget),
- menuitem_iterate,
- child);
- }
- }
-
- if (GTK_IS_MENU_ITEM (widget))
- {
- submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
- if (submenu != NULL)
- {
- gtk_container_foreach (GTK_CONTAINER (submenu),
- container_iterate,
- child);
- g_signal_connect_object (submenu,
- "child-added",
- G_CALLBACK (submenu_changed),
- child,
- 0);
- g_signal_connect_object (submenu,
- "child-removed",
- G_CALLBACK (submenu_changed),
- child,
- 0);
- }
- }
-
- dbusmenu_menuitem_property_set_bool (child,
- DBUSMENU_MENUITEM_PROP_ENABLED,
- gtk_widget_is_sensitive (widget));
- dbusmenu_menuitem_property_set_bool (child,
- DBUSMENU_MENUITEM_PROP_VISIBLE,
- gtk_widget_get_visible (widget));
-
- g_signal_connect (widget, "notify",
- G_CALLBACK (widget_notify_cb), child);
-
- if (GTK_IS_ACTIVATABLE (widget))
- {
- GtkActivatable *activatable = GTK_ACTIVATABLE (widget);
-
- if (gtk_activatable_get_use_action_appearance (activatable))
- {
- GtkAction *action = gtk_activatable_get_related_action (activatable);
-
- if (action)
- {
- g_signal_connect_object (action, "notify",
- G_CALLBACK (action_notify_cb),
- child,
- G_CONNECT_AFTER);
- }
- }
- }
-
- g_signal_connect (G_OBJECT (child),
- DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
- G_CALLBACK (activate_menuitem), widget);
- dbusmenu_menuitem_child_append (root, child);
-
- /* Get rid of initial ref now that the root is
- holding the object */
- g_object_unref(child);
-
- return;
-}
-
-static void
-submenu_changed (GtkWidget *widget,
- GtkWidget *child,
- gpointer data)
-{
- DbusmenuMenuitem *root = (DbusmenuMenuitem *)data;
- GList *children, *l;
- children = dbusmenu_menuitem_get_children (root);
-
- for (l = children; l;)
- {
- DbusmenuMenuitem *c = (DbusmenuMenuitem *)l->data;
- l = l->next;
- dbusmenu_menuitem_child_delete (root, c);
- }
-
- gtk_container_foreach (GTK_CONTAINER (widget),
- container_iterate,
- root);
-}
-
+/* Does the dbusmenu related work. If there isn't a server, it builds
+ one and if there are menus it runs the parse to put those menus into
+ the server. */
static void
setup_dbusmenu (AppIndicator *self)
{
- AppIndicatorPrivate *priv;
- DbusmenuMenuitem *root;
+ AppIndicatorPrivate *priv;
+ DbusmenuMenuitem *root = NULL;
- priv = self->priv;
- root = dbusmenu_menuitem_new ();
+ priv = self->priv;
- if (priv->menu)
- {
- gtk_container_foreach (GTK_CONTAINER (priv->menu),
- container_iterate,
- root);
- }
+ if (priv->menu) {
+ root = dbusmenu_gtk_parse_menu_structure(priv->menu);
+ }
- if (priv->menuservice == NULL)
- {
- gchar * path = g_strdup_printf(DEFAULT_ITEM_PATH "/%s/Menu", priv->clean_id);
- priv->menuservice = dbusmenu_server_new (path);
- g_free(path);
- }
+ if (priv->menuservice == NULL) {
+ gchar * path = g_strdup_printf(DEFAULT_ITEM_PATH "/%s/Menu", priv->clean_id);
+ priv->menuservice = dbusmenu_server_new (path);
+ g_free(path);
+ }
- dbusmenu_server_set_root (priv->menuservice, root);
+ dbusmenu_server_set_root (priv->menuservice, root);
+
+ /* Drop our local ref as set_root should get it's own. */
+ if (root != NULL) {
+ g_object_unref(root);
+ }
- return;
+ return;
}
static void
diff --git a/src/appindicator3-0.1.pc.in b/src/appindicator3-0.1.pc.in
index f59ac70..0ffe409 100644
--- a/src/appindicator3-0.1.pc.in
+++ b/src/appindicator3-0.1.pc.in
@@ -4,7 +4,7 @@ libdir=@libdir@
bindir=@bindir@
includedir=@includedir@
-Cflags: -I${includedir}/libappindicator3-0.1
+Cflags: -I${includedir}/libappindicator-0.1
Requires: dbusmenu-glib-0.4 gtk+-3.0
Libs: -L${libdir} -lappindicator3