From 9489aa2cbda25bb1ed87e87d2fcf550ac0b6142a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 16:23:08 -0600 Subject: Adding in a get_menu function. --- docs/reference/libappindicator-sections.txt | 1 + src/libappindicator/app-indicator.c | 22 +++++++++++++++++++++- src/libappindicator/app-indicator.h | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/docs/reference/libappindicator-sections.txt b/docs/reference/libappindicator-sections.txt index 68b120a..70df0b8 100644 --- a/docs/reference/libappindicator-sections.txt +++ b/docs/reference/libappindicator-sections.txt @@ -28,5 +28,6 @@ app_indicator_get_category app_indicator_get_status app_indicator_get_icon app_indicator_get_attention_icon +app_indicator_get_menu diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index e38e760..4852633 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -776,7 +776,7 @@ fallback (AppIndicator * self) static void status_icon_activate (GtkStatusIcon * icon, gpointer data) { - g_debug("Status Icon Activate"); + return; } @@ -1267,3 +1267,23 @@ app_indicator_get_attention_icon (AppIndicator *self) return self->priv->attention_icon_name; } + +/** + app_indicator_get_menu: + @self: The #AppIndicator object to use + + Gets the menu being used for this application indicator. + + Return value: A menu object or #NULL if one hasn't been set. +*/ +GtkMenu * +app_indicator_get_menu (AppIndicator *self) +{ + AppIndicatorPrivate *priv; + + g_return_val_if_fail (IS_APP_INDICATOR (self), NULL); + + priv = self->priv; + + return GTK_MENU(priv->menu); +} diff --git a/src/libappindicator/app-indicator.h b/src/libappindicator/app-indicator.h index a8d82ab..03656ce 100644 --- a/src/libappindicator/app-indicator.h +++ b/src/libappindicator/app-indicator.h @@ -228,6 +228,7 @@ AppIndicatorCategory app_indicator_get_category (AppIndicator * AppIndicatorStatus app_indicator_get_status (AppIndicator *self); const gchar * app_indicator_get_icon (AppIndicator *self); const gchar * app_indicator_get_attention_icon (AppIndicator *self); +GtkMenu * app_indicator_get_menu (AppIndicator *self); G_END_DECLS -- cgit v1.2.3 From 10521bbccfe5ab6cb9dac60a31ee055f7a6384e0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 16:28:34 -0600 Subject: Showing items in sample --- example/simple-client.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/example/simple-client.c b/example/simple-client.c index 8ff3827..83c2335 100644 --- a/example/simple-client.c +++ b/example/simple-client.c @@ -73,26 +73,31 @@ main (int argc, char ** argv) g_signal_connect (item, "activate", G_CALLBACK (item_clicked_cb), "1"); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_widget_show(item); item = gtk_radio_menu_item_new_with_label (NULL, "2"); g_signal_connect (item, "activate", G_CALLBACK (item_clicked_cb), "2"); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_widget_show(item); item = gtk_menu_item_new_with_label ("3"); g_signal_connect (item, "activate", G_CALLBACK (item_clicked_cb), "3"); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_widget_show(item); GtkWidget *toggle_item = gtk_menu_item_new_with_label ("Toggle 3"); g_signal_connect (toggle_item, "activate", G_CALLBACK (toggle_sensitivity_cb), item); gtk_menu_shell_append (GTK_MENU_SHELL (menu), toggle_item); + gtk_widget_show(item); item = gtk_image_menu_item_new_from_stock (GTK_STOCK_NEW, NULL); g_signal_connect (item, "activate", G_CALLBACK (image_clicked_cb), NULL); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_widget_show(item); app_indicator_set_menu (ci, GTK_MENU (menu)); -- cgit v1.2.3 From 6068e6cdb6fa92235c662706c8eabcff4207e1fa Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 16:28:53 -0600 Subject: Popping up menu on activate. --- src/libappindicator/app-indicator.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 4852633..f330870 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -776,6 +776,17 @@ fallback (AppIndicator * self) static void status_icon_activate (GtkStatusIcon * icon, gpointer data) { + GtkMenu * menu = app_indicator_get_menu(APP_INDICATOR(data)); + if (menu == NULL) + return; + + gtk_menu_popup(menu, + NULL, /* Parent Menu */ + NULL, /* Parent item */ + gtk_status_icon_position_menu, + icon, + 1, /* Button */ + gtk_get_current_event_time()); return; } -- cgit v1.2.3 From 67493d4ea9196f625b25e53ffbb26d30dace04dd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 18:53:19 -0600 Subject: Showing the toggle_item as well as the others. --- example/simple-client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/simple-client.c b/example/simple-client.c index 83c2335..6dcf5d1 100644 --- a/example/simple-client.c +++ b/example/simple-client.c @@ -91,7 +91,7 @@ main (int argc, char ** argv) g_signal_connect (toggle_item, "activate", G_CALLBACK (toggle_sensitivity_cb), item); gtk_menu_shell_append (GTK_MENU_SHELL (menu), toggle_item); - gtk_widget_show(item); + gtk_widget_show(toggle_item); item = gtk_image_menu_item_new_from_stock (GTK_STOCK_NEW, NULL); g_signal_connect (item, "activate", -- cgit v1.2.3 From c26cab9055e9d909babb509e606b35ec47574c78 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 19:52:02 -0600 Subject: Making it so that the icon will update in the fallback case with changes to the properties of the AppIndicator. --- src/libappindicator/app-indicator.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index f330870..f66888f 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -136,6 +136,7 @@ static void register_service_cb (DBusGProxy * proxy, GError * error, gpointer da static void start_fallback_timer (AppIndicator * self, gboolean do_it_now); static gboolean fallback_timer_expire (gpointer data); static GtkStatusIcon * fallback (AppIndicator * self); +static void status_icon_changes (GObject * icon, GParamSpec * pspec, gpointer data); static void status_icon_activate (GtkStatusIcon * icon, gpointer data); static void unfallback (AppIndicator * self, GtkStatusIcon * status_icon); static void watcher_proxy_destroyed (GObject * object, gpointer data); @@ -751,6 +752,28 @@ fallback (AppIndicator * self) gtk_status_icon_set_title(icon, app_indicator_get_id(self)); + g_signal_connect(G_OBJECT(self), "notify::" PROP_STATUS_S, + G_CALLBACK(status_icon_changes), icon); + g_signal_connect(G_OBJECT(self), "notify::" PROP_ICON_NAME_S, + G_CALLBACK(status_icon_changes), icon); + g_signal_connect(G_OBJECT(self), "notify::" PROP_ATTENTION_ICON_NAME_S, + G_CALLBACK(status_icon_changes), icon); + + status_icon_changes(G_OBJECT(icon), NULL, self); + + g_signal_connect(G_OBJECT(icon), "activate", G_CALLBACK(status_icon_activate), self); + + return NULL; +} + +/* This tracks changes to either the status or the icons + that are associated with the app indicator */ +static void +status_icon_changes (GObject * oicon, GParamSpec * pspec, gpointer data) +{ + AppIndicator * self = APP_INDICATOR(data); + GtkStatusIcon * icon = GTK_STATUS_ICON(oicon); + switch (app_indicator_get_status(self)) { case APP_INDICATOR_STATUS_PASSIVE: gtk_status_icon_set_visible(icon, FALSE); @@ -766,9 +789,7 @@ fallback (AppIndicator * self) break; }; - g_signal_connect(G_OBJECT(icon), "activate", G_CALLBACK(status_icon_activate), self); - - return NULL; + return; } /* Handles the activate action by the status icon by showing @@ -796,6 +817,7 @@ status_icon_activate (GtkStatusIcon * icon, gpointer data) static void unfallback (AppIndicator * self, GtkStatusIcon * status_icon) { + g_signal_handlers_disconnect_by_func(G_OBJECT(self), status_icon_changes, status_icon); g_object_unref(G_OBJECT(status_icon)); return; } -- cgit v1.2.3 From c303c0c49f7ab1b0747e5cb12111f8b3ac4cd46e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 20:25:33 -0600 Subject: Realized that we didn't really use the 'notify' signal... now using the better ones anyway. --- src/libappindicator/app-indicator.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index f66888f..e1b332a 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -136,7 +136,8 @@ static void register_service_cb (DBusGProxy * proxy, GError * error, gpointer da static void start_fallback_timer (AppIndicator * self, gboolean do_it_now); static gboolean fallback_timer_expire (gpointer data); static GtkStatusIcon * fallback (AppIndicator * self); -static void status_icon_changes (GObject * icon, GParamSpec * pspec, gpointer data); +static void status_icon_status_wrapper (AppIndicator * self, const gchar * status, gpointer data); +static void status_icon_changes (AppIndicator * self, gpointer data); static void status_icon_activate (GtkStatusIcon * icon, gpointer data); static void unfallback (AppIndicator * self, GtkStatusIcon * status_icon); static void watcher_proxy_destroyed (GObject * object, gpointer data); @@ -752,27 +753,34 @@ fallback (AppIndicator * self) gtk_status_icon_set_title(icon, app_indicator_get_id(self)); - g_signal_connect(G_OBJECT(self), "notify::" PROP_STATUS_S, + g_signal_connect(G_OBJECT(self), APP_INDICATOR_SIGNAL_NEW_STATUS, G_CALLBACK(status_icon_changes), icon); - g_signal_connect(G_OBJECT(self), "notify::" PROP_ICON_NAME_S, + g_signal_connect(G_OBJECT(self), APP_INDICATOR_SIGNAL_NEW_ICON, G_CALLBACK(status_icon_changes), icon); - g_signal_connect(G_OBJECT(self), "notify::" PROP_ATTENTION_ICON_NAME_S, + g_signal_connect(G_OBJECT(self), APP_INDICATOR_SIGNAL_NEW_ATTENTION_ICON, G_CALLBACK(status_icon_changes), icon); - status_icon_changes(G_OBJECT(icon), NULL, self); + status_icon_changes(self, icon); g_signal_connect(G_OBJECT(icon), "activate", G_CALLBACK(status_icon_activate), self); return NULL; } +/* A wrapper as the status update prototype is a little + bit different, but we want to handle it the same. */ +static void +status_icon_status_wrapper (AppIndicator * self, const gchar * status, gpointer data) +{ + return status_icon_changes(self, data); +} + /* This tracks changes to either the status or the icons that are associated with the app indicator */ static void -status_icon_changes (GObject * oicon, GParamSpec * pspec, gpointer data) +status_icon_changes (AppIndicator * self, gpointer data) { - AppIndicator * self = APP_INDICATOR(data); - GtkStatusIcon * icon = GTK_STATUS_ICON(oicon); + GtkStatusIcon * icon = GTK_STATUS_ICON(data); switch (app_indicator_get_status(self)) { case APP_INDICATOR_STATUS_PASSIVE: @@ -817,6 +825,7 @@ status_icon_activate (GtkStatusIcon * icon, gpointer data) static void unfallback (AppIndicator * self, GtkStatusIcon * status_icon) { + g_signal_handlers_disconnect_by_func(G_OBJECT(self), status_icon_status_wrapper, status_icon); g_signal_handlers_disconnect_by_func(G_OBJECT(self), status_icon_changes, status_icon); g_object_unref(G_OBJECT(status_icon)); return; -- cgit v1.2.3 From 544ac3aa1cae817a4ec66fa4a880ba283298cabf Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Jan 2010 09:52:51 -0600 Subject: Using better naming for 'do_it_now' parameter. --- src/libappindicator/app-indicator.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index e1b332a..40c7c3e 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -133,7 +133,7 @@ static void app_indicator_get_property (GObject * object, guint prop_id, GValue /* Other stuff */ static void check_connect (AppIndicator * self); static void register_service_cb (DBusGProxy * proxy, GError * error, gpointer data); -static void start_fallback_timer (AppIndicator * self, gboolean do_it_now); +static void start_fallback_timer (AppIndicator * self, gboolean disable_timeout); static gboolean fallback_timer_expire (gpointer data); static GtkStatusIcon * fallback (AppIndicator * self); static void status_icon_status_wrapper (AppIndicator * self, const gchar * status, gpointer data); @@ -685,7 +685,7 @@ dbus_owner_change (DBusGProxy * proxy, const gchar * name, const gchar * prev, c there is a change. Also, provides an override mode for cases where it's unlikely that a timer will help anything. */ static void -start_fallback_timer (AppIndicator * self, gboolean do_it_now) +start_fallback_timer (AppIndicator * self, gboolean disable_timeout) { g_return_if_fail(IS_APP_INDICATOR(self)); AppIndicatorPrivate * priv = APP_INDICATOR(self)->priv; @@ -708,7 +708,7 @@ start_fallback_timer (AppIndicator * self, gboolean do_it_now) G_CALLBACK(dbus_owner_change), self, NULL); } - if (do_it_now) { + if (disable_timeout) { fallback_timer_expire(self); } else { priv->fallback_timer = g_timeout_add(DEFAULT_FALLBACK_TIMER, fallback_timer_expire, self); -- cgit v1.2.3 From 2bfabeb52a894375a76be19cbd034ad56214b766 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Jan 2010 09:54:59 -0600 Subject: Making a more descriptive error on 'unfallback' not existing. --- src/libappindicator/app-indicator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 40c7c3e..c3bce35 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -736,7 +736,7 @@ fallback_timer_expire (gpointer data) class->unfallback(APP_INDICATOR(data), priv->status_icon); priv->status_icon = NULL; } else { - g_warning("Can't 'unfallback' and I have an allocated status_icon. Might be a memory leak!"); + g_warning("No 'unfallback' function but the 'fallback' function returned a non-NULL result."); } } -- cgit v1.2.3 From 09442ab9099e7a35394ec692560c19672bdbc2d2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Jan 2010 09:55:42 -0600 Subject: Returning the icon we've created. --- src/libappindicator/app-indicator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index c3bce35..6c969c2 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -764,7 +764,7 @@ fallback (AppIndicator * self) g_signal_connect(G_OBJECT(icon), "activate", G_CALLBACK(status_icon_activate), self); - return NULL; + return icon; } /* A wrapper as the status update prototype is a little -- cgit v1.2.3 From f0104e11357b5804aea2ecead13f99231b671a75 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Jan 2010 10:36:02 -0600 Subject: 0.0.9 --- configure.ac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 713f40e..ebd6b20 100644 --- a/configure.ac +++ b/configure.ac @@ -1,11 +1,11 @@ -AC_INIT(indicator-application, 0.0.8, ted@canonical.com) -AC_COPYRIGHT([Copyright 2009 Canonical]) +AC_INIT(indicator-application, 0.0.9, ted@canonical.com) +AC_COPYRIGHT([Copyright 2009, 2010 Canonical]) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(indicator-application, 0.0.8) +AM_INIT_AUTOMAKE(indicator-application, 0.0.9) AM_MAINTAINER_MODE -- cgit v1.2.3