From 2a913873186288d10321fc13de7565a198da568c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 11 Jan 2010 13:21:50 -0600 Subject: Adding in the class functions for handling the fallback. --- src/libappindicator/app-indicator.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libappindicator/app-indicator.h b/src/libappindicator/app-indicator.h index a680c33..a8d82ab 100644 --- a/src/libappindicator/app-indicator.h +++ b/src/libappindicator/app-indicator.h @@ -148,10 +148,12 @@ typedef struct _AppIndicatorPrivate AppIndicatorPrivate; @new_attention_icon: Slot for #AppIndicator::new-attention-icon. @new_status: Slot for #AppIndicator::new-status. @connection_changed: Slot for #AppIndicator::connection-changed. + @fallback: Function that gets called to make a #GtkStatusIcon when + there is no Application Indicator area available. + @unfallback: The function that gets called if an Application + Indicator area appears after the fallback has been created. @app_indicator_reserved_1: Reserved for future use. @app_indicator_reserved_2: Reserved for future use. - @app_indicator_reserved_3: Reserved for future use. - @app_indicator_reserved_4: Reserved for future use. The signals and external functions that make up the #AppIndicator class object. @@ -174,11 +176,14 @@ struct _AppIndicatorClass { gboolean connected, gpointer user_data); + /* Overridable Functions */ + GtkStatusIcon * (*fallback) (AppIndicator * indicator); + void (*unfallback) (AppIndicator * indicator, + GtkStatusIcon * status_icon); + /* Reserved */ void (*app_indicator_reserved_1)(void); void (*app_indicator_reserved_2)(void); - void (*app_indicator_reserved_3)(void); - void (*app_indicator_reserved_4)(void); }; /** -- cgit v1.2.3 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(-) 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(-) 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(-) 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(+) 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(+) 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(+) 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 4a1b7228d3fd9cfa163082c2bbf5b2982c6b525b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 15:41:16 -0600 Subject: Getting the start of the fallback tests in place. --- .bzrignore | 2 + tests/Makefile.am | 35 +++++++++++++ tests/test-libappindicator-fallback-watcher.c | 73 +++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 tests/test-libappindicator-fallback-watcher.c diff --git a/.bzrignore b/.bzrignore index 977611c..17798c8 100644 --- a/.bzrignore +++ b/.bzrignore @@ -87,3 +87,5 @@ docs/reference/xml docs/reference/tmpl/app-indicator.sgml docs/reference/tmpl/app-indicator.sgml.bak src/libappindicator/appindicator-0.1.pc +tests/test-libappindicator-fallback-item +tests/test-libappindicator-fallback-watcher diff --git a/tests/Makefile.am b/tests/Makefile.am index 845b41c..e5847c5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,6 +3,8 @@ check_PROGRAMS = \ test-libappindicator \ test-libappindicator-dbus-client \ test-libappindicator-dbus-server \ + test-libappindicator-fallback-watcher \ + test-libappindicator-fallback-item \ test-simple-app TESTS = @@ -58,6 +60,39 @@ test_libappindicator_dbus_server_LDADD = \ $(INDICATOR_LIBS) \ $(top_builddir)/src/libappindicator.la +######################################### +## test-libappindicator-fallback +######################################### + +test_libappindicator_fallback_watcher_SOURCES = \ + test-libappindicator-fallback-watcher.c + +test_libappindicator_fallback_watcher_CFLAGS = \ + $(INDICATOR_CFLAGS) \ + -Wall -Werror \ + -I$(top_srcdir)/src + +test_libappindicator_fallback_watcher_LDADD = \ + $(INDICATOR_LIBS) \ + $(top_builddir)/src/libappindicator.la + +test_libappindicator_fallback_item_SOURCES = \ + test-libappindicator-fallback-watcher.c + +test_libappindicator_fallback_item_CFLAGS = \ + $(INDICATOR_CFLAGS) \ + -Wall -Werror \ + -I$(top_srcdir)/src + +test_libappindicator_fallback_item_LDADD = \ + $(INDICATOR_LIBS) \ + $(top_builddir)/src/libappindicator.la + +test-libappindicator-fallback: test-libappindicator-fallback-watcher test-libappindicator-fallback-item Makefile.am + @echo "#!/bin/sh" > $@ + @echo $(DBUS_RUNNER) --task ./test-libappindicator-fallback-watcher --task-name Watcher --ignore-return --task ./test-libappindicator-fallback-item --task-name Item >> $@ + @chmod +x $@ + ######################################### ## Actual tests ######################################### diff --git a/tests/test-libappindicator-fallback-watcher.c b/tests/test-libappindicator-fallback-watcher.c new file mode 100644 index 0000000..67109e5 --- /dev/null +++ b/tests/test-libappindicator-fallback-watcher.c @@ -0,0 +1,73 @@ +/* +This puts the NotificationWatcher on the bus, kinda. Enough to +trick the Item into unfalling back. + +Copyright 2010 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#include +#include +#include + +#include "../src/dbus-shared.h" + +static GMainLoop * mainloop = NULL; + +gboolean +kill_func (gpointer userdata) +{ + g_main_loop_quit(mainloop); + return FALSE; +} + +int +main (int argv, char ** argc) +{ + g_type_init(); + + /* Wait 1/4 a second, which should trigger the fallback */ + g_usleep(250000); + + GError * error = NULL; + DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + if (error != NULL) { + g_error("Unable to get session bus: %s", error->message); + return 1; + } + + DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); + guint nameret = 0; + + if (!org_freedesktop_DBus_request_name(bus_proxy, NOTIFICATION_WATCHER_DBUS_ADDR, 0, &nameret, &error)) { + g_error("Unable to call to request name"); + return 1; + } + + if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { + g_error("Unable to get name"); + return 1; + } + + /* After we've got the name, let it unfallback, and then we'll drop again */ + g_timeout_add(250, kill_func, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return 0; +} -- cgit v1.2.3 From 348bcfba144c1e2f3025352f23f038829558bc7f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 16:04:58 -0600 Subject: Woah, this is pretty sweet. I hope it works. --- tests/test-libappindicator-fallback-watcher.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test-libappindicator-fallback-watcher.c b/tests/test-libappindicator-fallback-watcher.c index 67109e5..07d8da6 100644 --- a/tests/test-libappindicator-fallback-watcher.c +++ b/tests/test-libappindicator-fallback-watcher.c @@ -23,11 +23,25 @@ with this program. If not, see . #include #include #include +#include #include "../src/dbus-shared.h" static GMainLoop * mainloop = NULL; +static DBusHandlerResult +dbus_filter (DBusConnection * connection, DBusMessage * message, void * user_data) +{ + if (dbus_message_is_method_call(message, NOTIFICATION_WATCHER_DBUS_ADDR, "RegisterStatusNotifierItem")) { + DBusMessage * reply = dbus_message_new_method_return(message); + dbus_connection_send(connection, reply, NULL); + dbus_message_unref(reply); + return DBUS_HANDLER_RESULT_HANDLED; + } + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + gboolean kill_func (gpointer userdata) { @@ -63,6 +77,8 @@ main (int argv, char ** argc) return 1; } + dbus_connection_add_filter(dbus_g_connection_get_connection(session_bus), dbus_filter, NULL, NULL); + /* After we've got the name, let it unfallback, and then we'll drop again */ g_timeout_add(250, kill_func, NULL); -- cgit v1.2.3 From cc31c237cd5da314e584570220bd0bf359b725be Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 16:31:59 -0600 Subject: Adding in the item side of things. --- tests/Makefile.am | 2 +- tests/test-libappindicator-fallback-item.c | 84 ++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 tests/test-libappindicator-fallback-item.c diff --git a/tests/Makefile.am b/tests/Makefile.am index e5847c5..f543e92 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -77,7 +77,7 @@ test_libappindicator_fallback_watcher_LDADD = \ $(top_builddir)/src/libappindicator.la test_libappindicator_fallback_item_SOURCES = \ - test-libappindicator-fallback-watcher.c + test-libappindicator-fallback-item.c test_libappindicator_fallback_item_CFLAGS = \ $(INDICATOR_CFLAGS) \ diff --git a/tests/test-libappindicator-fallback-item.c b/tests/test-libappindicator-fallback-item.c new file mode 100644 index 0000000..02724fe --- /dev/null +++ b/tests/test-libappindicator-fallback-item.c @@ -0,0 +1,84 @@ +#include +#include +#include + +#define TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE (test_libappindicator_fallback_item_get_type ()) +#define TEST_LIBAPPINDICATOR_FALLBACK_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE, TestLibappindicatorFallbackItem)) +#define TEST_LIBAPPINDICATOR_FALLBACK_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE, TestLibappindicatorFallbackItemClass)) +#define IS_TEST_LIBAPPINDICATOR_FALLBACK_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE)) +#define IS_TEST_LIBAPPINDICATOR_FALLBACK_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE)) +#define TEST_LIBAPPINDICATOR_FALLBACK_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE, TestLibappindicatorFallbackItemClass)) + +typedef struct _TestLibappindicatorFallbackItem TestLibappindicatorFallbackItem; +typedef struct _TestLibappindicatorFallbackItemClass TestLibappindicatorFallbackItemClass; + +struct _TestLibappindicatorFallbackItemClass { + AppIndicatorClass parent_class; + +}; + +struct _TestLibappindicatorFallbackItem { + AppIndicator parent; + +}; + +GType test_libappindicator_fallback_item_get_type (void); + +#define TEST_LIBAPPINDICATOR_FALLBACK_ITEM_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE, TestLibappindicatorFallbackItemPrivate)) + +static void test_libappindicator_fallback_item_class_init (TestLibappindicatorFallbackItemClass *klass); +static void test_libappindicator_fallback_item_init (TestLibappindicatorFallbackItem *self); +static GtkStatusIcon * fallback (AppIndicator * indicator); +static void unfallback (AppIndicator * indicator, GtkStatusIcon * status_icon); + +G_DEFINE_TYPE (TestLibappindicatorFallbackItem, test_libappindicator_fallback_item, APP_INDICATOR_TYPE); + +static void +test_libappindicator_fallback_item_class_init (TestLibappindicatorFallbackItemClass *klass) +{ + AppIndicatorClass * aiclass = APP_INDICATOR_CLASS(klass); + + aiclass->fallback = fallback; + aiclass->unfallback = unfallback; +} + +static void +test_libappindicator_fallback_item_init (TestLibappindicatorFallbackItem *self) +{ +} + +GMainLoop * mainloop = NULL; + +static GtkStatusIcon * +fallback (AppIndicator * indicator) +{ + g_debug("Fallback"); + return NULL; +} + +static void +unfallback (AppIndicator * indicator, GtkStatusIcon * status_icon) +{ + g_debug("Unfallback"); + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + + TestLibappindicatorFallbackItem * item = g_object_new(TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE, + "id", "test-id", + "category", "other", + "icon-name", "bob", + NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_object_unref(G_OBJECT(item)); + + return 0; +} -- cgit v1.2.3 From d0abe1ebd34409a7074a39c6af017b2cfb49abf4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 16:36:26 -0600 Subject: Printing status in watcher --- tests/test-libappindicator-fallback-watcher.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test-libappindicator-fallback-watcher.c b/tests/test-libappindicator-fallback-watcher.c index 07d8da6..90c7db8 100644 --- a/tests/test-libappindicator-fallback-watcher.c +++ b/tests/test-libappindicator-fallback-watcher.c @@ -54,9 +54,13 @@ main (int argv, char ** argc) { g_type_init(); + g_debug("Waiting to init."); + /* Wait 1/4 a second, which should trigger the fallback */ g_usleep(250000); + g_debug("Initing"); + GError * error = NULL; DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); if (error != NULL) { @@ -82,8 +86,12 @@ main (int argv, char ** argc) /* After we've got the name, let it unfallback, and then we'll drop again */ g_timeout_add(250, kill_func, NULL); + g_debug("Entering Mainloop"); + mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); + g_debug("Exiting"); + return 0; } -- cgit v1.2.3 From a216db21dd72d491edaca5c7746d3a2a23b17dd1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 16:39:27 -0600 Subject: Adding a kill function and letting the test fail over it. --- tests/test-libappindicator-fallback-item.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/test-libappindicator-fallback-item.c b/tests/test-libappindicator-fallback-item.c index 02724fe..83dc876 100644 --- a/tests/test-libappindicator-fallback-item.c +++ b/tests/test-libappindicator-fallback-item.c @@ -49,6 +49,7 @@ test_libappindicator_fallback_item_init (TestLibappindicatorFallbackItem *self) } GMainLoop * mainloop = NULL; +gboolean passed = FALSE; static GtkStatusIcon * fallback (AppIndicator * indicator) @@ -64,6 +65,14 @@ unfallback (AppIndicator * indicator, GtkStatusIcon * status_icon) return; } +gboolean +kill_func (gpointer data) +{ + g_debug("Kill Function"); + g_main_loop_quit(mainloop); + return FALSE; +} + int main (int argc, char ** argv) { @@ -75,10 +84,16 @@ main (int argc, char ** argv) "icon-name", "bob", NULL); + g_timeout_add_seconds(1, kill_func, NULL); + mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); g_object_unref(G_OBJECT(item)); - return 0; + if (passed) { + return 0; + } else { + return 1; + } } -- cgit v1.2.3 From 9a2102419fa43910995539a90981727838cc6c40 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 16:44:13 -0600 Subject: Adding state transitions that'll get us to a passed state. --- tests/test-libappindicator-fallback-item.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test-libappindicator-fallback-item.c b/tests/test-libappindicator-fallback-item.c index 83dc876..ce3182c 100644 --- a/tests/test-libappindicator-fallback-item.c +++ b/tests/test-libappindicator-fallback-item.c @@ -51,10 +51,29 @@ test_libappindicator_fallback_item_init (TestLibappindicatorFallbackItem *self) GMainLoop * mainloop = NULL; gboolean passed = FALSE; +enum { + STATE_INIT, + STATE_FALLBACK, + STATE_UNFALLBACK, + STATE_REFALLBACK +}; + +gint state = STATE_INIT; + static GtkStatusIcon * fallback (AppIndicator * indicator) { g_debug("Fallback"); + if (state == STATE_INIT) { + state = STATE_FALLBACK; + } else if (state == STATE_UNFALLBACK) { + state = STATE_REFALLBACK; + passed = TRUE; + g_main_loop_quit(mainloop); + } else { + g_debug("Error, fallback in state: %d", state); + passed = FALSE; + } return NULL; } @@ -62,6 +81,12 @@ static void unfallback (AppIndicator * indicator, GtkStatusIcon * status_icon) { g_debug("Unfallback"); + if (state == STATE_FALLBACK) { + state = STATE_UNFALLBACK; + } else { + g_debug("Error, unfallback in state: %d", state); + passed = FALSE; + } return; } -- cgit v1.2.3 From 7783a495fb275ce70757ea1d0fcec67e7855f2d9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 16:45:09 -0600 Subject: Adding the fallback test to the suite --- tests/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Makefile.am b/tests/Makefile.am index f543e92..c94ebdd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -93,6 +93,8 @@ test-libappindicator-fallback: test-libappindicator-fallback-watcher test-libapp @echo $(DBUS_RUNNER) --task ./test-libappindicator-fallback-watcher --task-name Watcher --ignore-return --task ./test-libappindicator-fallback-item --task-name Item >> $@ @chmod +x $@ +TESTS += test-libappindicator-fallback + ######################################### ## Actual tests ######################################### -- 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(-) 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 f55bf250c331a4384f00ada67df4ff525b8c4ffe Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 17:00:56 -0600 Subject: Adding a menu so that the app indicator will init --- tests/test-libappindicator-fallback-item.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test-libappindicator-fallback-item.c b/tests/test-libappindicator-fallback-item.c index ce3182c..38fdeea 100644 --- a/tests/test-libappindicator-fallback-item.c +++ b/tests/test-libappindicator-fallback-item.c @@ -101,13 +101,16 @@ kill_func (gpointer data) int main (int argc, char ** argv) { - g_type_init(); + gtk_init(&argc, &argv); TestLibappindicatorFallbackItem * item = g_object_new(TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE, "id", "test-id", "category", "other", "icon-name", "bob", NULL); + + GtkWidget * menu = gtk_menu_new(); + app_indicator_set_menu(APP_INDICATOR(item), GTK_MENU(menu)); g_timeout_add_seconds(1, kill_func, 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(-) 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 3ac18fb423b9894b85d06acd841ce6d3f5a41132 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 08:24:19 -0600 Subject: Ignoring the generated fallback test itself --- .bzrignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.bzrignore b/.bzrignore index 17798c8..a218817 100644 --- a/.bzrignore +++ b/.bzrignore @@ -89,3 +89,4 @@ docs/reference/tmpl/app-indicator.sgml.bak src/libappindicator/appindicator-0.1.pc tests/test-libappindicator-fallback-item tests/test-libappindicator-fallback-watcher +tests/test-libappindicator-fallback -- 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(-) 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 5898ca0cf3754ee733ba670feedf5046e921c6e7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 08:33:21 -0600 Subject: Making sure to return a value so that unfallback gets called. --- tests/test-libappindicator-fallback-item.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-libappindicator-fallback-item.c b/tests/test-libappindicator-fallback-item.c index 38fdeea..1ff70c8 100644 --- a/tests/test-libappindicator-fallback-item.c +++ b/tests/test-libappindicator-fallback-item.c @@ -74,7 +74,7 @@ fallback (AppIndicator * indicator) g_debug("Error, fallback in state: %d", state); passed = FALSE; } - return NULL; + return (GtkStatusIcon *)5; } static void -- 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(-) 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(-) 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(+) 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(-) 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 5d075987c3469ae7f1538143546e94d208abf1cf Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 11:35:42 -0600 Subject: Really we should have gotten the final cleanup unfallback, which we weren't testing for either. --- tests/test-libappindicator-fallback-item.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test-libappindicator-fallback-item.c b/tests/test-libappindicator-fallback-item.c index 1ff70c8..291bc7c 100644 --- a/tests/test-libappindicator-fallback-item.c +++ b/tests/test-libappindicator-fallback-item.c @@ -55,7 +55,8 @@ enum { STATE_INIT, STATE_FALLBACK, STATE_UNFALLBACK, - STATE_REFALLBACK + STATE_REFALLBACK, + STATE_REUNFALLBACK }; gint state = STATE_INIT; @@ -68,8 +69,6 @@ fallback (AppIndicator * indicator) state = STATE_FALLBACK; } else if (state == STATE_UNFALLBACK) { state = STATE_REFALLBACK; - passed = TRUE; - g_main_loop_quit(mainloop); } else { g_debug("Error, fallback in state: %d", state); passed = FALSE; @@ -83,6 +82,10 @@ unfallback (AppIndicator * indicator, GtkStatusIcon * status_icon) g_debug("Unfallback"); if (state == STATE_FALLBACK) { state = STATE_UNFALLBACK; + } else if (state == STATE_REFALLBACK) { + state = STATE_REUNFALLBACK; + passed = TRUE; + g_main_loop_quit(mainloop); } else { g_debug("Error, unfallback in state: %d", state); passed = FALSE; -- 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(-) 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