From d8c7246f702c687b4f532cfb66c5eeb545aa175d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 11 Jan 2010 14:05:24 -0600 Subject: Setting the fallback functions so that we can go round trip on setting up this API. --- src/libappindicator/app-indicator.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 7560a97..9f0ca54 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -64,8 +64,9 @@ struct _AppIndicatorPrivate { gchar *icon_name; gchar *attention_icon_name; gchar * icon_path; - DbusmenuServer *menuservice; - GtkWidget *menu; + DbusmenuServer *menuservice; + GtkWidget *menu; + GtkStatusIcon * status_icon; /* Fun stuff */ DBusGProxy *watcher_proxy; @@ -122,6 +123,8 @@ 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 GtkStatusIcon * fallback (AppIndicator * self); +static void unfallback (AppIndicator * self, GtkStatusIcon * status_icon); /* GObject type */ G_DEFINE_TYPE (AppIndicator, app_indicator, G_TYPE_OBJECT); @@ -141,6 +144,10 @@ app_indicator_class_init (AppIndicatorClass *klass) object_class->set_property = app_indicator_set_property; object_class->get_property = app_indicator_get_property; + /* Our own funcs */ + klass->fallback = fallback; + klass->unfallback = unfallback; + /* Properties */ g_object_class_install_property (object_class, PROP_ID, @@ -568,6 +575,24 @@ category_from_enum (AppIndicatorCategory category) return value->value_nick; } +/* Creates a StatusIcon that can be used when the application + indicator area isn't available. */ +static GtkStatusIcon * +fallback (AppIndicator * self) +{ + + return NULL; +} + +/* Removes the status icon as the application indicator area + is now up and running again. */ +static void +unfallback (AppIndicator * self, GtkStatusIcon * status_icon) +{ + + return; +} + /* ************************* */ /* Public Functions */ -- cgit v1.2.3 From f8d6a7d026be10ea4cdb486cfa945ad697403f26 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 11 Jan 2010 16:27:19 -0600 Subject: Initing and destroying the status_icon variable --- src/libappindicator/app-indicator.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 9f0ca54..2650342 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -302,6 +302,8 @@ app_indicator_init (AppIndicator *self) priv->watcher_proxy = NULL; priv->connection = NULL; + priv->status_icon = NULL; + /* Put the object on DBus */ GError * error = NULL; priv->connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); @@ -325,13 +327,21 @@ app_indicator_init (AppIndicator *self) static void app_indicator_dispose (GObject *object) { - AppIndicator *self = APP_INDICATOR (object); + AppIndicator *self = APP_INDICATOR (object); AppIndicatorPrivate *priv = self->priv; if (priv->status != APP_INDICATOR_STATUS_PASSIVE) { app_indicator_set_status(self, APP_INDICATOR_STATUS_PASSIVE); } + if (priv->status_icon != NULL) { + AppIndicatorClass * class = APP_INDICATOR_CLASS(object); + if (class->unfallback != NULL) { + class->unfallback(self, priv->status_icon); + } + priv->status_icon = NULL; + } + if (priv->menu != NULL) { g_object_unref(G_OBJECT(priv->menu)); priv->menu = NULL; -- cgit v1.2.3 From 40d3056382d3856f8e22d0bd6d2a4f4a411917f2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 11:40:50 -0600 Subject: Start timer fallback --- src/libappindicator/app-indicator.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index e3de406..63f69c9 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -127,6 +127,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 GtkStatusIcon * fallback (AppIndicator * self); static void unfallback (AppIndicator * self, GtkStatusIcon * status_icon); @@ -557,8 +558,8 @@ check_connect (AppIndicator *self) &error); if (error != NULL) { g_warning("Unable to create Ayatana Watcher proxy! %s", error->message); - /* TODO: This is where we should start looking at fallbacks */ g_error_free(error); + start_fallback_timer(self, FALSE); return; } @@ -576,6 +577,7 @@ register_service_cb (DBusGProxy * proxy, GError * error, gpointer data) g_warning("Unable to connect to the Notification Watcher: %s", error->message); g_object_unref(G_OBJECT(priv->watcher_proxy)); priv->watcher_proxy = NULL; + start_fallback_timer(APP_INDICATOR(data), TRUE); } return; } @@ -587,6 +589,18 @@ category_from_enum (AppIndicatorCategory category) value = g_enum_get_value ((GEnumClass *)g_type_class_ref (APP_INDICATOR_TYPE_INDICATOR_CATEGORY), category); return value->value_nick; +} + +/* A function that will start the fallback timer if it's not + already started. It sets up the DBus watcher to see if + 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) +{ + + + } /* Creates a StatusIcon that can be used when the application -- cgit v1.2.3 From 7e5e095f25954857936213bd7136fb1e18583819 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 11:55:35 -0600 Subject: Some comments --- src/libappindicator/app-indicator.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 63f69c9..b28a876 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -568,12 +568,16 @@ check_connect (AppIndicator *self) return; } +/* Responce from the DBus command to register a service + with a NotificationWatcher. */ static void register_service_cb (DBusGProxy * proxy, GError * error, gpointer data) { AppIndicatorPrivate * priv = APP_INDICATOR_GET_PRIVATE(data); if (error != NULL) { + /* They didn't respond, ewww. Not sure what they could + be doing */ g_warning("Unable to connect to the Notification Watcher: %s", error->message); g_object_unref(G_OBJECT(priv->watcher_proxy)); priv->watcher_proxy = NULL; @@ -582,6 +586,8 @@ register_service_cb (DBusGProxy * proxy, GError * error, gpointer data) return; } +/* A helper function to get the nick out of a given + category enum value. */ static const gchar * category_from_enum (AppIndicatorCategory category) { -- cgit v1.2.3 From 9518459fda51ce675794115b401e36cb2f4306f5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 13:37:40 -0600 Subject: Fallback timer pointer lifecycle. --- src/libappindicator/app-indicator.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index b28a876..687ce21 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -66,7 +66,9 @@ struct _AppIndicatorPrivate { gchar * icon_path; DbusmenuServer *menuservice; GtkWidget *menu; + GtkStatusIcon * status_icon; + gint fallback_timer; /* Fun stuff */ DBusGProxy *watcher_proxy; @@ -116,6 +118,9 @@ enum { #define DEFAULT_ITEM_PATH "/org/ayatana/NotificationItem" #define DEFAULT_MENU_PATH "/org/ayatana/NotificationItem/Menu" +/* More constants */ +#define DEFAULT_FALLBACK_TIMER 100 /* in milliseconds */ + /* Boiler plate */ static void app_indicator_class_init (AppIndicatorClass *klass); static void app_indicator_init (AppIndicator *self); @@ -308,6 +313,7 @@ app_indicator_init (AppIndicator *self) priv->connection = NULL; priv->status_icon = NULL; + priv->fallback_timer = 0; /* Put the object on DBus */ GError * error = NULL; @@ -347,6 +353,11 @@ app_indicator_dispose (GObject *object) priv->status_icon = NULL; } + if (priv->fallback_timer != 0) { + g_source_remove(priv->fallback_timer); + priv->fallback_timer = 0; + } + if (priv->menu != NULL) { g_object_unref(G_OBJECT(priv->menu)); priv->menu = NULL; @@ -583,6 +594,9 @@ register_service_cb (DBusGProxy * proxy, GError * error, gpointer data) priv->watcher_proxy = NULL; start_fallback_timer(APP_INDICATOR(data), TRUE); } + + /* TODO: Unfallback here */ + return; } @@ -604,7 +618,13 @@ category_from_enum (AppIndicatorCategory category) static void start_fallback_timer (AppIndicator * self, gboolean do_it_now) { + AppIndicatorPrivate * priv = APP_INDICATOR_GET_PRIVATE(self); + if (priv->fallback_timer != 0) { + /* The timer is set, let's just be happy with the one + we've already got running */ + return; + } } -- cgit v1.2.3 From 36d47b56783c1b1ea3356d532e00a13f61f174df Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 14:05:33 -0600 Subject: Setup the fallback timer and flesh out it's actions. --- src/libappindicator/app-indicator.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 687ce21..b33a51d 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -133,6 +133,7 @@ static void app_indicator_get_property (GObject * object, guint prop_id, GValue 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 gboolean fallback_timer_expire (gpointer data); static GtkStatusIcon * fallback (AppIndicator * self); static void unfallback (AppIndicator * self, GtkStatusIcon * status_icon); @@ -626,7 +627,37 @@ start_fallback_timer (AppIndicator * self, gboolean do_it_now) return; } + /* TODO: Setup what we need to check things out */ + if (do_it_now) { + fallback_timer_expire(self); + } else { + priv->fallback_timer = g_timeout_add(DEFAULT_FALLBACK_TIMER, fallback_timer_expire, self); + } + + return; +} + +/* A function that gets executed when we want to change the + state of the fallback. */ +static gboolean +fallback_timer_expire (gpointer data) +{ + AppIndicatorPrivate * priv = APP_INDICATOR_GET_PRIVATE(data); + AppIndicatorClass * class = APP_INDICATOR_CLASS(data); + + if (priv->status_icon == NULL) { + if (class->fallback != NULL) { + priv->status_icon = class->fallback(APP_INDICATOR(data)); + } + } else { + if (class->unfallback != NULL) { + class->unfallback(APP_INDICATOR(data), priv->status_icon); + priv->status_icon = NULL; + } + } + + return FALSE; } /* Creates a StatusIcon that can be used when the application -- cgit v1.2.3 From bded6da0bb607eac38bb7f32bb74df0543a3de1b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 16:55:39 -0600 Subject: Wrong class function --- src/libappindicator/app-indicator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index b33a51d..c1b9bf8 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -644,7 +644,7 @@ static gboolean fallback_timer_expire (gpointer data) { AppIndicatorPrivate * priv = APP_INDICATOR_GET_PRIVATE(data); - AppIndicatorClass * class = APP_INDICATOR_CLASS(data); + AppIndicatorClass * class = APP_INDICATOR_GET_CLASS(data); if (priv->status_icon == NULL) { if (class->fallback != NULL) { -- cgit v1.2.3 From 7e0feb2329d04007a4b98104f1d76a5e6d4384b4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 21:12:46 -0600 Subject: Setting up a dbus proxy and starting to look at owner change events on it when we don't have a NotificationWatcher to look at. --- src/libappindicator/app-indicator.c | 53 ++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index c1b9bf8..4018083 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -73,6 +73,7 @@ struct _AppIndicatorPrivate { /* Fun stuff */ DBusGProxy *watcher_proxy; DBusGConnection *connection; + DBusGProxy * dbus_proxy; }; /* Signals Stuff */ @@ -312,6 +313,7 @@ app_indicator_init (AppIndicator *self) priv->watcher_proxy = NULL; priv->connection = NULL; + priv->dbus_proxy = NULL; priv->status_icon = NULL; priv->fallback_timer = 0; @@ -364,6 +366,11 @@ app_indicator_dispose (GObject *object) priv->menu = NULL; } + if (priv->dbus_proxy != NULL) { + g_object_unref(G_OBJECT(priv->dbus_proxy)); + priv->dbus_proxy = NULL; + } + if (priv->watcher_proxy != NULL) { dbus_g_connection_flush(priv->connection); g_object_unref(G_OBJECT(priv->watcher_proxy)); @@ -612,6 +619,40 @@ category_from_enum (AppIndicatorCategory category) return value->value_nick; } +/* Watching the dbus owner change events to see if someone + we care about pops up! */ +static void +dbus_owner_change (DBusGProxy * proxy, const gchar * name, const gchar * prev, const gchar * new, gpointer data) +{ + if (new == NULL || new[0] == '\0') { + /* We only care about folks coming on the bus. Exit quickly otherwise. */ + return; + } + + if (g_strcmp0(name, NOTIFICATION_WATCHER_DBUS_ADDR)) { + /* We only care about this address, reject all others. */ + return; + } + + /* Woot, there's a new notification watcher in town. */ + + AppIndicatorPrivate * priv = APP_INDICATOR_GET_PRIVATE(data); + + if (priv->fallback_timer != 0) { + /* Stop a timer */ + g_source_remove(priv->fallback_timer); + + /* Stop listening to bus events */ + g_object_unref(G_OBJECT(priv->dbus_proxy)); + priv->dbus_proxy = NULL; + } + + /* Let's start from the very beginning */ + check_connect(APP_INDICATOR(data)); + + return; +} + /* A function that will start the fallback timer if it's not already started. It sets up the DBus watcher to see if there is a change. Also, provides an override mode for cases @@ -627,7 +668,17 @@ start_fallback_timer (AppIndicator * self, gboolean do_it_now) return; } - /* TODO: Setup what we need to check things out */ + if (priv->dbus_proxy == NULL) { + priv->dbus_proxy = dbus_g_proxy_new_for_name(priv->connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS); + dbus_g_proxy_add_signal(priv->dbus_proxy, "NameOwnerChanged", + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, + G_TYPE_INVALID); + dbus_g_proxy_connect_signal(priv->dbus_proxy, "NameOwnerChanged", + G_CALLBACK(dbus_owner_change), self, NULL); + } if (do_it_now) { fallback_timer_expire(self); -- cgit v1.2.3 From 5739297b7d0a67be588044a4be2163fb5cafbb78 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 08:33:04 -0600 Subject: Calling the unfallback function if we're doing this for the second time. --- src/libappindicator/app-indicator.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 4018083..7ade413 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -603,7 +603,13 @@ register_service_cb (DBusGProxy * proxy, GError * error, gpointer data) start_fallback_timer(APP_INDICATOR(data), TRUE); } - /* TODO: Unfallback here */ + if (priv->status_icon) { + AppIndicatorClass * class = APP_INDICATOR_GET_CLASS(data); + if (class->unfallback != NULL) { + class->unfallback(APP_INDICATOR(data), priv->status_icon); + priv->status_icon = NULL; + } + } return; } -- cgit v1.2.3 From 06a6bb7fcbbd703bade0aaff06ab2349b3644724 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 08:38:14 -0600 Subject: Removing a warning. --- src/libappindicator/app-indicator.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 7ade413..31b6c6b 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -576,7 +576,8 @@ check_connect (AppIndicator *self) NOTIFICATION_WATCHER_DBUS_IFACE, &error); if (error != NULL) { - g_warning("Unable to create Ayatana Watcher proxy! %s", error->message); + /* Unable to get proxy, but we're handling that now so + it's not a warning anymore. */ g_error_free(error); start_fallback_timer(self, FALSE); return; -- cgit v1.2.3 From c959db1f7d3f188f86c34076637949582b7e9f6b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 09:29:55 -0600 Subject: Adding a function to watch if the watcher proxy gets destroyed. --- src/libappindicator/app-indicator.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 31b6c6b..3fff6df 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -137,6 +137,7 @@ 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 unfallback (AppIndicator * self, GtkStatusIcon * status_icon); +static void watcher_proxy_destroyed (GObject * object, gpointer data); /* GObject type */ G_DEFINE_TYPE (AppIndicator, app_indicator, G_TYPE_OBJECT); @@ -559,7 +560,7 @@ app_indicator_get_property (GObject * object, guint prop_id, GValue * value, GPa static void check_connect (AppIndicator *self) { - AppIndicatorPrivate *priv = self->priv; + AppIndicatorPrivate *priv = self->priv; /* We're alreadying connecting or trying to connect. */ if (priv->watcher_proxy != NULL) return; @@ -583,11 +584,25 @@ check_connect (AppIndicator *self) return; } + g_signal_connect(G_OBJECT(priv->watcher_proxy), "destroy", G_CALLBACK(watcher_proxy_destroyed), self); org_freedesktop_StatusNotifierWatcher_register_status_notifier_item_async(priv->watcher_proxy, DEFAULT_ITEM_PATH, register_service_cb, self); return; } +/* A function that gets called when the watcher dies. Like + dies dies. Not our friend anymore. */ +static void +watcher_proxy_destroyed (GObject * object, gpointer data) +{ + AppIndicator * self = APP_INDICATOR(data); + g_return_if_fail(self != NULL); + + self->priv->watcher_proxy = NULL; + start_fallback_timer(self, FALSE); + return; +} + /* Responce from the DBus command to register a service with a NotificationWatcher. */ static void -- cgit v1.2.3 From 89aa4a7b791024085162be440d2ec79afedf1b7d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 10:03:06 -0600 Subject: Clear the fallback timer pointer after using it. --- src/libappindicator/app-indicator.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 3fff6df..6bff61a 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -730,6 +730,7 @@ fallback_timer_expire (gpointer data) } } + priv->fallback_timer = 0; return FALSE; } -- cgit v1.2.3 From 88c99aca2e2a95a3dc540285f7dc53d020f526d0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 11:21:31 -0600 Subject: Getting the class the proper way --- src/libappindicator/app-indicator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 6bff61a..259ba3e 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -350,7 +350,7 @@ app_indicator_dispose (GObject *object) } if (priv->status_icon != NULL) { - AppIndicatorClass * class = APP_INDICATOR_CLASS(object); + AppIndicatorClass * class = APP_INDICATOR_GET_CLASS(object); if (class->unfallback != NULL) { class->unfallback(self, priv->status_icon); } -- cgit v1.2.3 From b1b9134542bd3bcfa6b5492f0a7f1b83cf0ec32f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 12:25:49 -0600 Subject: Fleshing out the fallback function, so it should create an icon. --- src/libappindicator/app-indicator.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 259ba3e..a3ad1ee 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -739,6 +739,24 @@ fallback_timer_expire (gpointer data) static GtkStatusIcon * fallback (AppIndicator * self) { + GtkStatusIcon * icon = gtk_status_icon_new(); + + gtk_status_icon_set_title(icon, app_indicator_get_id(self)); + + switch (app_indicator_get_status(self)) { + case APP_INDICATOR_STATUS_PASSIVE: + gtk_status_icon_set_visible(icon, FALSE); + gtk_status_icon_set_from_icon_name(icon, app_indicator_get_icon(self)); + break; + case APP_INDICATOR_STATUS_ACTIVE: + gtk_status_icon_set_from_icon_name(icon, app_indicator_get_icon(self)); + gtk_status_icon_set_visible(icon, TRUE); + break; + case APP_INDICATOR_STATUS_ATTENTION: + gtk_status_icon_set_from_icon_name(icon, app_indicator_get_attention_icon(self)); + gtk_status_icon_set_visible(icon, TRUE); + break; + }; return NULL; } @@ -748,7 +766,7 @@ fallback (AppIndicator * self) static void unfallback (AppIndicator * self, GtkStatusIcon * status_icon) { - + g_object_unref(G_OBJECT(status_icon)); return; } -- cgit v1.2.3 From 60236935d5da0be2de0833cded25ad9361305a43 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 13:30:32 -0600 Subject: Checking for the status of the variable getting passed in. --- src/libappindicator/app-indicator.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index a3ad1ee..baa2159 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -716,7 +716,9 @@ start_fallback_timer (AppIndicator * self, gboolean do_it_now) static gboolean fallback_timer_expire (gpointer data) { - AppIndicatorPrivate * priv = APP_INDICATOR_GET_PRIVATE(data); + g_return_val_if_fail(IS_APP_INDICATOR(data), FALSE); + + AppIndicatorPrivate * priv = APP_INDICATOR(data)->priv; AppIndicatorClass * class = APP_INDICATOR_GET_CLASS(data); if (priv->status_icon == NULL) { @@ -727,7 +729,9 @@ fallback_timer_expire (gpointer data) if (class->unfallback != NULL) { 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!"); + } } priv->fallback_timer = 0; -- cgit v1.2.3 From 303db3c924690a134dcc6c0159f3a9dfc5a761fa Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 14:02:23 -0600 Subject: Explicitly checking for the APP_INDICATOR. Confused. --- src/libappindicator/app-indicator.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index baa2159..a098170 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -682,6 +682,8 @@ dbus_owner_change (DBusGProxy * proxy, const gchar * name, const gchar * prev, c static void start_fallback_timer (AppIndicator * self, gboolean do_it_now) { + g_return_if_fail(IS_APP_INDICATOR(self)); + AppIndicatorPrivate * priv = APP_INDICATOR_GET_PRIVATE(self); if (priv->fallback_timer != 0) { -- cgit v1.2.3 From e67b856409825b020e2d71b510d05abc1cdef31c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 14:05:33 -0600 Subject: Checking more for whether we have an APP_INDICATOR object --- src/libappindicator/app-indicator.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index a098170..e581829 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -608,7 +608,8 @@ watcher_proxy_destroyed (GObject * object, gpointer data) static void register_service_cb (DBusGProxy * proxy, GError * error, gpointer data) { - AppIndicatorPrivate * priv = APP_INDICATOR_GET_PRIVATE(data); + g_return_if_fail(IS_APP_INDICATOR(data)); + AppIndicatorPrivate * priv = APP_INDICATOR(data)->priv; if (error != NULL) { /* They didn't respond, ewww. Not sure what they could @@ -683,8 +684,7 @@ static void start_fallback_timer (AppIndicator * self, gboolean do_it_now) { g_return_if_fail(IS_APP_INDICATOR(self)); - - AppIndicatorPrivate * priv = APP_INDICATOR_GET_PRIVATE(self); + AppIndicatorPrivate * priv = APP_INDICATOR(self)->priv; if (priv->fallback_timer != 0) { /* The timer is set, let's just be happy with the one -- cgit v1.2.3 From ef9589128e31165cf83b576ac50688db582760f2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 14:53:18 -0600 Subject: Remove the 'destroy' signal handler before destroying the watcher proxy. --- src/libappindicator/app-indicator.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index e581829..7dd2894 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -374,6 +374,7 @@ app_indicator_dispose (GObject *object) if (priv->watcher_proxy != NULL) { dbus_g_connection_flush(priv->connection); + g_signal_handlers_disconnect_by_func(G_OBJECT(priv->watcher_proxy), watcher_proxy_destroyed, self); g_object_unref(G_OBJECT(priv->watcher_proxy)); priv->watcher_proxy = NULL; } -- cgit v1.2.3 From bf390ec6d9aa02fe5fed6278f6f9bb249557e210 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 16:10:25 -0600 Subject: Connecting to the activate signal --- src/libappindicator/app-indicator.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/libappindicator/app-indicator.c') diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 7dd2894..e38e760 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_activate (GtkStatusIcon * icon, gpointer data); static void unfallback (AppIndicator * self, GtkStatusIcon * status_icon); static void watcher_proxy_destroyed (GObject * object, gpointer data); @@ -765,9 +766,20 @@ fallback (AppIndicator * self) break; }; + g_signal_connect(G_OBJECT(icon), "activate", G_CALLBACK(status_icon_activate), self); + return NULL; } +/* Handles the activate action by the status icon by showing + the menu in a popup. */ +static void +status_icon_activate (GtkStatusIcon * icon, gpointer data) +{ + g_debug("Status Icon Activate"); + return; +} + /* Removes the status icon as the application indicator area is now up and running again. */ static void -- cgit v1.2.3 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. --- src/libappindicator/app-indicator.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/libappindicator/app-indicator.c') 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); +} -- 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(+) (limited to 'src/libappindicator/app-indicator.c') 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 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(-) (limited to 'src/libappindicator/app-indicator.c') 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(-) (limited to 'src/libappindicator/app-indicator.c') 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(-) (limited to 'src/libappindicator/app-indicator.c') 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(-) (limited to 'src/libappindicator/app-indicator.c') 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(-) (limited to 'src/libappindicator/app-indicator.c') 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