From 3d71f7f6f3da9d796bc7c9050d8b6df0eeb1179d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 9 Nov 2009 21:55:02 -0600 Subject: Adding in the dbus shared header. --- src/libcustomindicator/custom-indicator.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/libcustomindicator/custom-indicator.c b/src/libcustomindicator/custom-indicator.c index a4835cc..6138daf 100644 --- a/src/libcustomindicator/custom-indicator.c +++ b/src/libcustomindicator/custom-indicator.c @@ -11,6 +11,8 @@ #include "notification-item-server.h" #include "notification-watcher-client.h" +#include "../dbus-shared.h" + /** CustomIndicatorPrivate: @id: The ID of the indicator. Maps to CustomIndicator::id. -- cgit v1.2.3 From f7cfd25bc2cf4696a579d8b7374666ee5e6bb3b3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 23 Nov 2009 11:44:29 -0600 Subject: Adding a remove function and switching to the position in the list being the position. --- src/indicator-custom.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/indicator-custom.c b/src/indicator-custom.c index 7cb9142..3bd2aa9 100644 --- a/src/indicator-custom.c +++ b/src/indicator-custom.c @@ -55,7 +55,6 @@ struct _IndicatorCustomPrivate { typedef struct _ApplicationEntry ApplicationEntry; struct _ApplicationEntry { - guint position; IndicatorObjectEntry entry; }; @@ -115,7 +114,7 @@ indicator_custom_dispose (GObject *object) while (priv->applications != NULL) { application_removed(priv->service_proxy, - ((ApplicationEntry *)priv->applications->data)->position, + 0, INDICATOR_CUSTOM(object)); } @@ -237,20 +236,44 @@ application_added (DBusGProxy * proxy, const gchar * iconname, gint position, co IndicatorCustomPrivate * priv = INDICATOR_CUSTOM_GET_PRIVATE(custom); ApplicationEntry * app = g_new(ApplicationEntry, 1); - app->position = position; app->entry.image = GTK_IMAGE(gtk_image_new_from_icon_name(iconname, GTK_ICON_SIZE_MENU)); app->entry.label = NULL; app->entry.menu = GTK_MENU(dbusmenu_gtkmenu_new((gchar *)dbusaddress, (gchar *)dbusobject)); - priv->applications = g_list_prepend(priv->applications, app); + priv->applications = g_list_insert(priv->applications, app, position); + /* TODO: Need to deal with position here somehow */ g_signal_emit(G_OBJECT(custom), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID, 0, &(app->entry), TRUE); return; } +/* This removes the application from the list and free's all + of the memory associated with it. */ static void -application_removed (DBusGProxy * proxy, gint position , IndicatorCustom * custom) +application_removed (DBusGProxy * proxy, gint position, IndicatorCustom * custom) { + IndicatorCustomPrivate * priv = INDICATOR_CUSTOM_GET_PRIVATE(custom); + ApplicationEntry * app = (ApplicationEntry *)g_list_nth_data(priv->applications, position); + + if (app == NULL) { + g_warning("Unable to find application at position: %d", position); + return; + } + + priv->applications = g_list_remove(priv->applications, app); + g_signal_emit(G_OBJECT(custom), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID, 0, &(app->entry), TRUE); + + if (app->entry.image != NULL) { + g_object_unref(G_OBJECT(app->entry.image)); + } + if (app->entry.label != NULL) { + g_warning("Odd, an application indicator with a label?"); + g_object_unref(G_OBJECT(app->entry.label)); + } + if (app->entry.menu != NULL) { + g_object_unref(G_OBJECT(app->entry.menu)); + } + g_free(app); return; } -- cgit v1.2.3 From f22ff6a153ca3b6ebc6cab0177913823f0251be7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 23 Nov 2009 12:02:40 -0600 Subject: Cleaning up main a little bit and handling the 'disconnected' case that doesn't yet quite exist. --- src/custom-service.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src') diff --git a/src/custom-service.c b/src/custom-service.c index 3205bc2..5bd9b96 100644 --- a/src/custom-service.c +++ b/src/custom-service.c @@ -5,22 +5,52 @@ #include "custom-service-watcher.h" #include "dbus-shared.h" +/* The base main loop */ static GMainLoop * mainloop = NULL; +/* Where the application registry lives */ static CustomServiceAppstore * appstore = NULL; +/* Interface for applications */ static CustomServiceWatcher * watcher = NULL; +/* The service management interface */ static IndicatorService * service = NULL; + +/* Recieves the disonnection signal from the service + object and closes the mainloop. */ +static void +service_disconnected (IndicatorService * service, gpointer data) +{ + g_debug("Service disconnected"); + if (mainloop != NULL) { + g_main_loop_quit(mainloop); + } + return; +} +/* Builds up the core objects and puts us spinning into + a main loop. */ int main (int argc, char ** argv) { g_type_init(); + /* Bring us up as a basic indicator service */ service = indicator_service_new(INDICATOR_CUSTOM_DBUS_ADDR); + g_signal_connect(G_OBJECT(service), "disconnected", G_CALLBACK(service_disconnected), NULL); + + /* Building our app store */ appstore = CUSTOM_SERVICE_APPSTORE(g_object_new(CUSTOM_SERVICE_APPSTORE_TYPE, NULL)); + + /* Adding a watcher for the Apps coming up */ watcher = custom_service_watcher_new(appstore); + /* Building and executing our main loop */ mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); + /* Unref'ing all the objects */ + g_object_unref(G_OBJECT(watcher)); + g_object_unref(G_OBJECT(appstore)); + g_object_unref(G_OBJECT(service)); + return 0; } -- cgit v1.2.3 From efd63e3ff881a38bdbd466774dcf506b485166c2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 23 Nov 2009 12:52:14 -0600 Subject: Fixing custom indicator watcher object path. --- src/custom-service-watcher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/custom-service-watcher.c b/src/custom-service-watcher.c index a0a1b27..7cc15ee 100644 --- a/src/custom-service-watcher.c +++ b/src/custom-service-watcher.c @@ -104,7 +104,7 @@ custom_service_watcher_init (CustomServiceWatcher *self) } dbus_g_connection_register_g_object(session_bus, - INDICATOR_CUSTOM_DBUS_OBJ "/more", + NOTIFICATION_WATCHER_DBUS_OBJ, G_OBJECT(self)); return; -- cgit v1.2.3 From 5a87d20ea3873748036185ae74da33ed88cf9d63 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 23 Nov 2009 13:09:58 -0600 Subject: Commenting. --- src/custom-service-appstore.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/custom-service-appstore.c b/src/custom-service-appstore.c index a69bde6..81910dd 100644 --- a/src/custom-service-appstore.c +++ b/src/custom-service-appstore.c @@ -164,20 +164,27 @@ get_all_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError * err return; } +/* Adding a new NotificationItem object from DBus in to the + appstore. First, we need to get the information on it + though. */ void custom_service_appstore_application_add (CustomServiceAppstore * appstore, const gchar * dbus_name, const gchar * dbus_object) { + /* Make sure we got a sensible request */ g_return_if_fail(IS_CUSTOM_SERVICE_APPSTORE(appstore)); g_return_if_fail(dbus_name != NULL && dbus_name[0] != '\0'); g_return_if_fail(dbus_object != NULL && dbus_object[0] != '\0'); CustomServiceAppstorePrivate * priv = CUSTOM_SERVICE_APPSTORE_GET_PRIVATE(appstore); + /* Build the application entry. This will be carried + along until we're sure we've got everything. */ Application * app = g_new(Application, 1); app->dbus_name = g_strdup(dbus_name); app->dbus_object = g_strdup(dbus_object); app->appstore = appstore; + /* Get the DBus proxy for the NotificationItem interface */ GError * error = NULL; app->dbus_proxy = dbus_g_proxy_new_for_name_owner(priv->bus, app->dbus_name, @@ -192,6 +199,7 @@ custom_service_appstore_application_add (CustomServiceAppstore * appstore, const return; } + /* Grab the property proxy interface */ app->prop_proxy = dbus_g_proxy_new_for_name_owner(priv->bus, app->dbus_name, app->dbus_object, @@ -206,11 +214,14 @@ custom_service_appstore_application_add (CustomServiceAppstore * appstore, const return; } + /* Get all the propertiees */ org_freedesktop_DBus_Properties_get_all_async(app->prop_proxy, NOTIFICATION_ITEM_DBUS_IFACE, get_all_properties_cb, app); + /* We're returning, nothing is yet added until the properties + come back and give us more info. */ return; } -- cgit v1.2.3 From 9a4835415f4df9b906a4d489245b0aecab43c09d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 23 Nov 2009 13:26:32 -0600 Subject: Adding in a TODO --- src/custom-service-appstore.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/custom-service-appstore.c b/src/custom-service-appstore.c index 81910dd..6cb2dd9 100644 --- a/src/custom-service-appstore.c +++ b/src/custom-service-appstore.c @@ -152,6 +152,10 @@ get_all_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError * err CustomServiceAppstorePrivate * priv = CUSTOM_SERVICE_APPSTORE_GET_PRIVATE(app->appstore); priv->applications = g_list_prepend(priv->applications, app); + + /* TODO: We need to have the position determined better. This + would involve looking at the name and category and sorting + it with the other entries. */ g_signal_emit(G_OBJECT(app->appstore), signals[APPLICATION_ADDED], 0, -- cgit v1.2.3 From 2c04418795e644efafc0204656dd575844ba0976 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 23 Nov 2009 14:51:51 -0600 Subject: Connecting to a notification watcher. --- src/libcustomindicator/custom-indicator.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/libcustomindicator/custom-indicator.c b/src/libcustomindicator/custom-indicator.c index 6138daf..b2d1384 100644 --- a/src/libcustomindicator/custom-indicator.c +++ b/src/libcustomindicator/custom-indicator.c @@ -11,7 +11,7 @@ #include "notification-item-server.h" #include "notification-watcher-client.h" -#include "../dbus-shared.h" +#include "dbus-shared.h" /** CustomIndicatorPrivate: @@ -93,6 +93,7 @@ static void custom_indicator_set_property (GObject * object, guint prop_id, cons static void custom_indicator_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); /* Other stuff */ static void check_connect (CustomIndicator * self); +static void register_service_cb (DBusGProxy * proxy, GError * error, gpointer data); /* GObject type */ G_DEFINE_TYPE (CustomIndicator, custom_indicator, G_TYPE_OBJECT); @@ -279,10 +280,25 @@ custom_indicator_init (CustomIndicator *self) g_error_free(error); return; } + dbus_g_connection_register_g_object(connection, "/need/a/path", G_OBJECT(self)); + priv->watcher_proxy = dbus_g_proxy_new_for_name_owner(connection, + INDICATOR_CUSTOM_DBUS_ADDR, + NOTIFICATION_WATCHER_DBUS_OBJ, + NOTIFICATION_WATCHER_DBUS_IFACE, + &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); + return; + } + + org_ayatana_indicator_custom_NotificationWatcher_register_service_async(priv->watcher_proxy, "/need/a/path", register_service_cb, self); + return; } @@ -600,6 +616,15 @@ check_connect (CustomIndicator * self) } +static void +register_service_cb (DBusGProxy * proxy, GError * error, gpointer data) +{ + if (error != NULL) { + g_warning("Unable to connect to the Notification Watcher: %s", error->message); + } + return; +} + /* ************************* */ /* Public Functions */ -- cgit v1.2.3