From 6d922ea1dee5f63ca852950938c04be68124c30f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 7 Jan 2010 13:08:40 -0600 Subject: Setting up and connecting to the item signals --- src/application-service-appstore.c | 45 +++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index 1391d33..e832a71 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -42,6 +42,10 @@ static gboolean _application_service_server_get_applications (ApplicationService #define NOTIFICATION_ITEM_PROP_AICON_NAME "AttentionIconName" #define NOTIFICATION_ITEM_PROP_MENU "Menu" +#define NOTIFICATION_ITEM_SIG_NEW_ICON "NewIcon" +#define NOTIFICATION_ITEM_SIG_NEW_AICON "NewAttentionIcon" +#define NOTIFICATION_ITEM_SIG_NEW_STATUS "NewStatus" + /* Private Stuff */ typedef struct _ApplicationServiceAppstorePrivate ApplicationServiceAppstorePrivate; struct _ApplicationServiceAppstorePrivate { @@ -56,6 +60,7 @@ struct _Application { ApplicationServiceAppstore * appstore; /* not ref'd */ DBusGProxy * dbus_proxy; DBusGProxy * prop_proxy; + gboolean validated; /* Whether we've gotten all the parameters and they look good. */ }; #define APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(o) \ @@ -155,6 +160,9 @@ application_service_appstore_finalize (GObject *object) return; } +/* Return from getting the properties from the item. We're looking at those + and making sure we have everythign that we need. If we do, then we'll + move on up to sending this onto the indicator. */ static void get_all_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError * error, gpointer data) { @@ -172,6 +180,8 @@ get_all_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError * err return; } + app->validated = TRUE; + ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(app->appstore); priv->applications = g_list_prepend(priv->applications, app); @@ -235,6 +245,10 @@ application_removed_cb (DBusGProxy * proxy, gpointer userdata) return; } +void new_icon (void) { } +void new_aicon (void) { } +void new_status (void) { } + /* Adding a new NotificationItem object from DBus in to the appstore. First, we need to get the information on it though. */ @@ -251,8 +265,9 @@ application_service_appstore_application_add (ApplicationServiceAppstore * appst /* Build the application entry. This will be carried along until we're sure we've got everything. */ - Application * app = g_new(Application, 1); + Application * app = g_new0(Application, 1); + app->validated = FALSE; app->dbus_name = g_strdup(dbus_name); app->dbus_object = g_strdup(dbus_object); app->appstore = appstore; @@ -290,6 +305,34 @@ application_service_appstore_application_add (ApplicationServiceAppstore * appst return; } + /* Connect to signals */ + dbus_g_proxy_add_signal(app->dbus_proxy, + NOTIFICATION_ITEM_SIG_NEW_ICON, + G_TYPE_INVALID); + dbus_g_proxy_add_signal(app->dbus_proxy, + NOTIFICATION_ITEM_SIG_NEW_AICON, + G_TYPE_INVALID); + dbus_g_proxy_add_signal(app->dbus_proxy, + NOTIFICATION_ITEM_SIG_NEW_STATUS, + G_TYPE_STRING, + G_TYPE_INVALID); + + dbus_g_proxy_connect_signal(app->dbus_proxy, + NOTIFICATION_ITEM_SIG_NEW_ICON, + G_CALLBACK(new_icon), + app, + NULL); + dbus_g_proxy_connect_signal(app->dbus_proxy, + NOTIFICATION_ITEM_SIG_NEW_AICON, + G_CALLBACK(new_aicon), + app, + NULL); + dbus_g_proxy_connect_signal(app->dbus_proxy, + NOTIFICATION_ITEM_SIG_NEW_STATUS, + G_CALLBACK(new_status), + app, + NULL); + /* Get all the propertiees */ org_freedesktop_DBus_Properties_get_all_async(app->prop_proxy, NOTIFICATION_ITEM_DBUS_IFACE, -- cgit v1.2.3 From f7e660f7f5a1133cc2a3bf341a2301f38160995a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 7 Jan 2010 13:37:56 -0600 Subject: Cleaning up signal handlers. --- src/application-service-appstore.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index e832a71..dfd932e 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -245,9 +245,38 @@ application_removed_cb (DBusGProxy * proxy, gpointer userdata) return; } -void new_icon (void) { } -void new_aicon (void) { } -void new_status (void) { } +/* Called when the Notification Item signals that it + has a new icon. */ +static void +new_icon (DBusGProxy * proxy, gpointer data) +{ + Application * app = (Application *)data; + if (!app->validated) return; + + return; +} + +/* Called when the Notification Item signals that it + has a new attention icon. */ +static void +new_aicon (DBusGProxy * proxy, gpointer data) +{ + Application * app = (Application *)data; + if (!app->validated) return; + + return; +} + +/* Called when the Notification Item signals that it + has a new status. */ +static void +new_status (DBusGProxy * proxy, const gchar * status, gpointer data) +{ + Application * app = (Application *)data; + if (!app->validated) return; + + return; +} /* Adding a new NotificationItem object from DBus in to the appstore. First, we need to get the information on it -- cgit v1.2.3 From 2c767da806cf8919a9ef1a827235f746f9693292 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 7 Jan 2010 13:53:42 -0600 Subject: Adding an icon_changed signal to the application store --- src/application-service-appstore.c | 8 ++++++++ src/application-service-appstore.h | 1 + src/application-service-marshal.list | 1 + src/application-service.xml | 4 ++++ 4 files changed, 14 insertions(+) diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index dfd932e..f24b36f 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -70,6 +70,7 @@ struct _Application { enum { APPLICATION_ADDED, APPLICATION_REMOVED, + APPLICATION_ICON_CHANGED, LAST_SIGNAL }; @@ -107,6 +108,13 @@ application_service_appstore_class_init (ApplicationServiceAppstoreClass *klass) NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT, G_TYPE_NONE); + signals[APPLICATION_ICON_CHANGED] = g_signal_new ("application-icon-changed", + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (ApplicationServiceAppstore, application_icon_changed), + NULL, NULL, + _application_service_marshal_VOID__INT_STRING, + G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_STRING, G_TYPE_NONE); dbus_g_object_type_install_info(APPLICATION_SERVICE_APPSTORE_TYPE, diff --git a/src/application-service-appstore.h b/src/application-service-appstore.h index edf1a37..7ab20c5 100644 --- a/src/application-service-appstore.h +++ b/src/application-service-appstore.h @@ -47,6 +47,7 @@ struct _ApplicationServiceAppstore { void (*application_added) (ApplicationServiceAppstore * appstore, gchar *, gint, gchar *, gchar *, gpointer); void (*application_removed) (ApplicationServiceAppstore * appstore, gint, gpointer); + void (*application_icon_changed)(ApplicationServiceAppstore * appstore, gint, const gchar *, gpointer); }; GType application_service_appstore_get_type (void); diff --git a/src/application-service-marshal.list b/src/application-service-marshal.list index a122bf8..99d13c0 100644 --- a/src/application-service-marshal.list +++ b/src/application-service-marshal.list @@ -17,3 +17,4 @@ # You should have received a copy of the GNU General Public License along # with this program. If not, see . VOID: STRING, INT, STRING, STRING +VOID: INT, STRING diff --git a/src/application-service.xml b/src/application-service.xml index fdd25bb..57d429b 100644 --- a/src/application-service.xml +++ b/src/application-service.xml @@ -39,6 +39,10 @@ with this program. If not, see . + + + + -- cgit v1.2.3 From 655f6d113305163d87643f9282f09b96fe5ccbe5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 7 Jan 2010 14:07:16 -0600 Subject: Responding to the icon changed signal in the indicator. --- src/indicator-application.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/indicator-application.c b/src/indicator-application.c index f3566e4..221be04 100644 --- a/src/indicator-application.c +++ b/src/indicator-application.c @@ -93,6 +93,7 @@ static GList * get_entries (IndicatorObject * io); static void connected (IndicatorServiceManager * sm, gboolean connected, IndicatorApplication * application); static void application_added (DBusGProxy * proxy, const gchar * iconname, gint position, const gchar * dbusaddress, const gchar * dbusobject, IndicatorApplication * application); static void application_removed (DBusGProxy * proxy, gint position , IndicatorApplication * application); +static void application_icon_changed (DBusGProxy * proxy, gint position, const gchar * iconname, IndicatorApplication * application); static void get_applications (DBusGProxy *proxy, GPtrArray *OUT_applications, GError *error, gpointer userdata); G_DEFINE_TYPE (IndicatorApplication, indicator_application, INDICATOR_OBJECT_TYPE); @@ -118,6 +119,11 @@ indicator_application_class_init (IndicatorApplicationClass *klass) G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_object_register_marshaller(_application_service_marshal_VOID__INT_STRING, + G_TYPE_NONE, + G_TYPE_INT, + G_TYPE_STRING, + G_TYPE_INVALID); return; } @@ -216,6 +222,11 @@ connected (IndicatorServiceManager * sm, gboolean connected, IndicatorApplicatio "ApplicationRemoved", G_TYPE_INT, G_TYPE_INVALID); + dbus_g_proxy_add_signal(priv->service_proxy, + "ApplicationIconChanged", + G_TYPE_INT, + G_TYPE_STRING, + G_TYPE_INVALID); /* Connect to them */ g_debug("Connect to them."); @@ -229,6 +240,11 @@ connected (IndicatorServiceManager * sm, gboolean connected, IndicatorApplicatio G_CALLBACK(application_removed), application, NULL /* Disconnection Signal */); + dbus_g_proxy_connect_signal(priv->service_proxy, + "ApplicationIconChanged", + G_CALLBACK(application_icon_changed), + application, + NULL /* Disconnection Signal */); /* Query it for existing applications */ g_debug("Request current apps"); @@ -317,6 +333,23 @@ application_removed (DBusGProxy * proxy, gint position, IndicatorApplication * a return; } +/* The callback for the signal that the icon for an application + has changed. */ +static void +application_icon_changed (DBusGProxy * proxy, gint position, const gchar * iconname, IndicatorApplication * application) +{ + IndicatorApplicationPrivate * priv = INDICATOR_APPLICATION_GET_PRIVATE(application); + ApplicationEntry * app = (ApplicationEntry *)g_list_nth_data(priv->applications, position); + + if (app == NULL) { + g_warning("Unable to find application at position: %d", position); + return; + } + + gtk_image_set_from_icon_name(app->entry.image, iconname, GTK_ICON_SIZE_MENU); + return; +} + /* This repsonds to the list of applications that the service has and calls application_added on each one of them. */ static void -- cgit v1.2.3 From 16fb78b663704da483de14c54fbcc4088a754c0e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 7 Jan 2010 14:18:31 -0600 Subject: Adding in a status variable --- src/application-service-appstore.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index f24b36f..128139b 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -53,6 +53,13 @@ struct _ApplicationServiceAppstorePrivate { GList * applications; }; +typedef enum _ApplicationStatus ApplicationStatus; +enum _ApplicationStatus { + APP_STATUS_PASSIVE, + APP_STATUS_ACTIVE, + APP_STATUS_ATTENTION +}; + typedef struct _Application Application; struct _Application { gchar * dbus_name; @@ -61,6 +68,7 @@ struct _Application { DBusGProxy * dbus_proxy; DBusGProxy * prop_proxy; gboolean validated; /* Whether we've gotten all the parameters and they look good. */ + ApplicationStatus status; }; #define APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(o) \ @@ -308,6 +316,7 @@ application_service_appstore_application_add (ApplicationServiceAppstore * appst app->dbus_name = g_strdup(dbus_name); app->dbus_object = g_strdup(dbus_object); app->appstore = appstore; + app->status = APP_STATUS_PASSIVE; /* Get the DBus proxy for the NotificationItem interface */ GError * error = NULL; -- cgit v1.2.3 From 45e742eba4c7cae1c732c83acae43033f5c39e90 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 7 Jan 2010 16:27:18 -0600 Subject: Moving the list of applications management into the state change function. This makes it so that we can handle it appearing and disappearing all in one special place. --- src/application-service-appstore.c | 136 ++++++++++++++++++++++++++++++------- 1 file changed, 111 insertions(+), 25 deletions(-) diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index 128139b..385bd16 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -53,6 +53,10 @@ struct _ApplicationServiceAppstorePrivate { GList * applications; }; +#define APP_STATUS_PASSIVE_STR "passive" +#define APP_STATUS_ACTIVE_STR "active" +#define APP_STATUS_ATTENTION_STR "attention" + typedef enum _ApplicationStatus ApplicationStatus; enum _ApplicationStatus { APP_STATUS_PASSIVE, @@ -69,6 +73,9 @@ struct _Application { DBusGProxy * prop_proxy; gboolean validated; /* Whether we've gotten all the parameters and they look good. */ ApplicationStatus status; + gchar * icon; + gchar * aicon; + gchar * menu; }; #define APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(o) \ @@ -89,6 +96,8 @@ static void application_service_appstore_class_init (ApplicationServiceAppstoreC static void application_service_appstore_init (ApplicationServiceAppstore *self); static void application_service_appstore_dispose (GObject *object); static void application_service_appstore_finalize (GObject *object); +static ApplicationStatus string_to_status(const gchar * status_string); +static void apply_status (Application * app, ApplicationStatus status); G_DEFINE_TYPE (ApplicationServiceAppstore, application_service_appstore, G_TYPE_OBJECT); @@ -190,6 +199,7 @@ get_all_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError * err Application * app = (Application *)data; if (g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_MENU) == NULL || + g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_STATUS) == NULL || g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_ICON_NAME) == NULL) { g_warning("Notification Item on object %s of %s doesn't have enough properties.", app->dbus_object, app->dbus_name); g_free(app); // Need to do more than this, but it gives the idea of the flow we're going for. @@ -198,24 +208,28 @@ get_all_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError * err app->validated = TRUE; - ApplicationServiceAppstorePrivate * priv = APPLICATION_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, - g_value_get_string(g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_ICON_NAME)), - 0, /* Position */ - app->dbus_name, - g_value_get_string(g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_MENU)), - TRUE); + app->icon = g_value_dup_string(g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_ICON_NAME)); + app->menu = g_value_dup_string(g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_MENU)); + if (g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_AICON_NAME) != NULL) { + app->aicon = g_value_dup_string(g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_ICON_NAME)); + } + + apply_status(app, string_to_status(g_value_get_string(g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_STATUS)))); return; } +/* Simple translation function -- could be optimized */ +static ApplicationStatus +string_to_status(const gchar * status_string) +{ + if (!g_strcmp0(status_string, APP_STATUS_ACTIVE_STR)) + return APP_STATUS_ACTIVE; + if (!g_strcmp0(status_string, APP_STATUS_ATTENTION_STR)) + return APP_STATUS_ATTENTION; + return APP_STATUS_PASSIVE; +} + /* A simple global function for dealing with freeing the information in an Application structure */ static void @@ -229,6 +243,15 @@ application_free (Application * app) if (app->dbus_object != NULL) { g_free(app->dbus_object); } + if (app->icon != NULL) { + g_free(app->icon); + } + if (app->aicon != NULL) { + g_free(app->aicon); + } + if (app->menu != NULL) { + g_free(app->menu); + } g_free(app); return; @@ -240,24 +263,84 @@ static void application_removed_cb (DBusGProxy * proxy, gpointer userdata) { Application * app = (Application *)userdata; - ApplicationServiceAppstore * appstore = app->appstore; - ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(appstore); - GList * applistitem = g_list_find(priv->applications, app); - if (applistitem == NULL) { - g_warning("Removing an application that isn't in the application list?"); + /* Remove from the panel */ + apply_status(app, APP_STATUS_PASSIVE); + + /* Destroy the data */ + application_free(app); + return; +} + +/* Change the status of the application. If we're going passive + it removes it from the panel. If we're coming online, then + it add it to the panel. Otherwise it changes the icon. */ +static void +apply_status (Application * app, ApplicationStatus status) +{ + if (app->status == status) { return; } - gint position = g_list_position(priv->applications, applistitem); + ApplicationServiceAppstore * appstore = app->appstore; + ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(appstore); - g_signal_emit(G_OBJECT(appstore), - signals[APPLICATION_REMOVED], 0, - position, TRUE); + /* This means we're going off line */ + if (status == APP_STATUS_PASSIVE) { + GList * applistitem = g_list_find(priv->applications, app); + if (applistitem == NULL) { + g_warning("Removing an application that isn't in the application list?"); + return; + } + + gint position = g_list_position(priv->applications, applistitem); + + g_signal_emit(G_OBJECT(appstore), + signals[APPLICATION_REMOVED], 0, + position, TRUE); + + priv->applications = g_list_remove(priv->applications, app); + } else { + /* Figure out which icon we should be using */ + gchar * newicon = app->icon; + if (status == APP_STATUS_ATTENTION && app->aicon != NULL) { + newicon = app->aicon; + } + + /* Determine whether we're already shown or not */ + if (app->status == APP_STATUS_PASSIVE) { + /* Put on panel */ + 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, + newicon, + 0, /* Position */ + app->dbus_name, + app->menu, + TRUE); + } else { + /* Icon update */ + GList * applistitem = g_list_find(priv->applications, app); + if (applistitem == NULL) { + g_warning("Change the icon of an application that isn't in the application list?"); + return; + } + + gint position = g_list_position(priv->applications, applistitem); + + g_signal_emit(G_OBJECT(appstore), + signals[APPLICATION_ICON_CHANGED], 0, + position, newicon, TRUE); + } + } - priv->applications = g_list_remove(priv->applications, app); + app->status = status; - application_free(app); return; } @@ -317,6 +400,9 @@ application_service_appstore_application_add (ApplicationServiceAppstore * appst app->dbus_object = g_strdup(dbus_object); app->appstore = appstore; app->status = APP_STATUS_PASSIVE; + app->icon = NULL; + app->aicon = NULL; + app->menu = NULL; /* Get the DBus proxy for the NotificationItem interface */ GError * error = NULL; -- cgit v1.2.3 From 4abe47b6935cb7c3e38f0e5c75f167eb0d3a9597 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 7 Jan 2010 16:48:12 -0600 Subject: Fleshing out the signal functions for updates. Some do more callbacks. --- src/application-service-appstore.c | 105 +++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index 385bd16..51bbca9 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -344,6 +344,98 @@ apply_status (Application * app, ApplicationStatus status) return; } +/* Gets the data back on an updated icon signal. Hopefully + a new fun icon. */ +static void +new_icon_cb (DBusGProxy * proxy, GValue value, GError * error, gpointer userdata) +{ + /* Check for errors */ + if (error != NULL) { + g_warning("Unable to get updated icon name: %s", error->message); + return; + } + + /* Grab the icon and make sure we have one */ + const gchar * newicon = g_value_get_string(&value); + if (newicon == NULL) { + g_warning("Bad new icon :("); + return; + } + + Application * app = (Application *) userdata; + + if (g_strcmp0(newicon, app->icon)) { + /* If the new icon is actually a new icon */ + if (app->icon != NULL) g_free(app->icon); + app->icon = g_strdup(newicon); + + if (app->status == APP_STATUS_ACTIVE) { + ApplicationServiceAppstore * appstore = app->appstore; + ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(appstore); + + GList * applistitem = g_list_find(priv->applications, app); + if (applistitem == NULL) { + g_warning("Change the icon of an application that isn't in the application list?"); + return; + } + + gint position = g_list_position(priv->applications, applistitem); + + g_signal_emit(G_OBJECT(appstore), + signals[APPLICATION_ICON_CHANGED], 0, + position, newicon, TRUE); + } + } + + return; +} + +/* Gets the data back on an updated aicon signal. Hopefully + a new fun icon. */ +static void +new_aicon_cb (DBusGProxy * proxy, GValue value, GError * error, gpointer userdata) +{ + /* Check for errors */ + if (error != NULL) { + g_warning("Unable to get updated icon name: %s", error->message); + return; + } + + /* Grab the icon and make sure we have one */ + const gchar * newicon = g_value_get_string(&value); + if (newicon == NULL) { + g_warning("Bad new icon :("); + return; + } + + Application * app = (Application *) userdata; + + if (g_strcmp0(newicon, app->aicon)) { + /* If the new icon is actually a new icon */ + if (app->aicon != NULL) g_free(app->aicon); + app->aicon = g_strdup(newicon); + + if (app->status == APP_STATUS_ATTENTION) { + ApplicationServiceAppstore * appstore = app->appstore; + ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(appstore); + + GList * applistitem = g_list_find(priv->applications, app); + if (applistitem == NULL) { + g_warning("Change the icon of an application that isn't in the application list?"); + return; + } + + gint position = g_list_position(priv->applications, applistitem); + + g_signal_emit(G_OBJECT(appstore), + signals[APPLICATION_ICON_CHANGED], 0, + position, newicon, TRUE); + } + } + + return; +} + /* Called when the Notification Item signals that it has a new icon. */ static void @@ -352,6 +444,11 @@ new_icon (DBusGProxy * proxy, gpointer data) Application * app = (Application *)data; if (!app->validated) return; + org_freedesktop_DBus_Properties_get_async(app->prop_proxy, + NOTIFICATION_ITEM_DBUS_IFACE, + NOTIFICATION_ITEM_PROP_ICON_NAME, + new_icon_cb, + app); return; } @@ -363,6 +460,12 @@ new_aicon (DBusGProxy * proxy, gpointer data) Application * app = (Application *)data; if (!app->validated) return; + org_freedesktop_DBus_Properties_get_async(app->prop_proxy, + NOTIFICATION_ITEM_DBUS_IFACE, + NOTIFICATION_ITEM_PROP_AICON_NAME, + new_aicon_cb, + app); + return; } @@ -374,6 +477,8 @@ new_status (DBusGProxy * proxy, const gchar * status, gpointer data) Application * app = (Application *)data; if (!app->validated) return; + apply_status(app, string_to_status(status)); + return; } -- cgit v1.2.3 From 2cc15ba2a7ce9f141068ee8e348906bfd867f9f5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 7 Jan 2010 16:55:31 -0600 Subject: A small refactoring of the code to get the position of an application. --- src/application-service-appstore.c | 62 ++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index 51bbca9..02b8faf 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -230,6 +230,22 @@ string_to_status(const gchar * status_string) return APP_STATUS_PASSIVE; } +/* A small helper function to get the position of an application + in the app list. */ +static gint +get_position (Application * app) { + ApplicationServiceAppstore * appstore = app->appstore; + ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(appstore); + + GList * applistitem = g_list_find(priv->applications, app); + if (applistitem == NULL) { + g_warning("Change the icon of an application that isn't in the application list?"); + return -1; + } + + return g_list_position(priv->applications, applistitem); +} + /* A simple global function for dealing with freeing the information in an Application structure */ static void @@ -287,13 +303,8 @@ apply_status (Application * app, ApplicationStatus status) /* This means we're going off line */ if (status == APP_STATUS_PASSIVE) { - GList * applistitem = g_list_find(priv->applications, app); - if (applistitem == NULL) { - g_warning("Removing an application that isn't in the application list?"); - return; - } - - gint position = g_list_position(priv->applications, applistitem); + gint position = get_position(app); + if (position == -1) return; g_signal_emit(G_OBJECT(appstore), signals[APPLICATION_REMOVED], 0, @@ -325,13 +336,8 @@ apply_status (Application * app, ApplicationStatus status) TRUE); } else { /* Icon update */ - GList * applistitem = g_list_find(priv->applications, app); - if (applistitem == NULL) { - g_warning("Change the icon of an application that isn't in the application list?"); - return; - } - - gint position = g_list_position(priv->applications, applistitem); + gint position = get_position(app); + if (position == -1) return; g_signal_emit(G_OBJECT(appstore), signals[APPLICATION_ICON_CHANGED], 0, @@ -370,18 +376,10 @@ new_icon_cb (DBusGProxy * proxy, GValue value, GError * error, gpointer userdata app->icon = g_strdup(newicon); if (app->status == APP_STATUS_ACTIVE) { - ApplicationServiceAppstore * appstore = app->appstore; - ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(appstore); - - GList * applistitem = g_list_find(priv->applications, app); - if (applistitem == NULL) { - g_warning("Change the icon of an application that isn't in the application list?"); - return; - } - - gint position = g_list_position(priv->applications, applistitem); + gint position = get_position(app); + if (position == -1) return; - g_signal_emit(G_OBJECT(appstore), + g_signal_emit(G_OBJECT(app->appstore), signals[APPLICATION_ICON_CHANGED], 0, position, newicon, TRUE); } @@ -416,18 +414,10 @@ new_aicon_cb (DBusGProxy * proxy, GValue value, GError * error, gpointer userdat app->aicon = g_strdup(newicon); if (app->status == APP_STATUS_ATTENTION) { - ApplicationServiceAppstore * appstore = app->appstore; - ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(appstore); + gint position = get_position(app); + if (position == -1) return; - GList * applistitem = g_list_find(priv->applications, app); - if (applistitem == NULL) { - g_warning("Change the icon of an application that isn't in the application list?"); - return; - } - - gint position = g_list_position(priv->applications, applistitem); - - g_signal_emit(G_OBJECT(appstore), + g_signal_emit(G_OBJECT(app->appstore), signals[APPLICATION_ICON_CHANGED], 0, position, newicon, TRUE); } -- cgit v1.2.3 From d1fbe4a73eb979b25bb0a063c621442a1ec06f3e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 7 Jan 2010 20:53:46 -0600 Subject: Changing dbus-properties header to be static and not built from the XML as it needs a fix. --- src/Makefile.am | 1 - src/dbus-properties-client.h | 139 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 src/dbus-properties-client.h diff --git a/src/Makefile.am b/src/Makefile.am index f101d12..d9b7963 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -101,7 +101,6 @@ libappindicator_la_LIBADD = \ DBUS_SPECS = \ application-service.xml \ - dbus-properties.xml \ notification-item.xml \ notification-watcher.xml diff --git a/src/dbus-properties-client.h b/src/dbus-properties-client.h new file mode 100644 index 0000000..dc9f299 --- /dev/null +++ b/src/dbus-properties-client.h @@ -0,0 +1,139 @@ +/* Generated by dbus-binding-tool; do not edit! */ + +#include +#include + +G_BEGIN_DECLS + +#ifndef _DBUS_GLIB_ASYNC_DATA_FREE +#define _DBUS_GLIB_ASYNC_DATA_FREE +static +#ifdef G_HAVE_INLINE +inline +#endif +void +_dbus_glib_async_data_free (gpointer stuff) +{ + g_slice_free (DBusGAsyncData, stuff); +} +#endif + +#ifndef DBUS_GLIB_CLIENT_WRAPPERS_org_freedesktop_DBus_Properties +#define DBUS_GLIB_CLIENT_WRAPPERS_org_freedesktop_DBus_Properties + +static +#ifdef G_HAVE_INLINE +inline +#endif +gboolean +org_freedesktop_DBus_Properties_get (DBusGProxy *proxy, const char * IN_Interface_Name, const char * IN_Property_Name, GValue* OUT_Value, GError **error) + +{ + return dbus_g_proxy_call (proxy, "Get", error, G_TYPE_STRING, IN_Interface_Name, G_TYPE_STRING, IN_Property_Name, G_TYPE_INVALID, G_TYPE_VALUE, OUT_Value, G_TYPE_INVALID); +} + +typedef void (*org_freedesktop_DBus_Properties_get_reply) (DBusGProxy *proxy, GValue OUT_Value, GError *error, gpointer userdata); + +static void +org_freedesktop_DBus_Properties_get_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data) +{ + DBusGAsyncData *data = (DBusGAsyncData*) user_data; + GError *error = NULL; + GValue OUT_Value = {0}; + dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_VALUE, &OUT_Value, G_TYPE_INVALID); + (*(org_freedesktop_DBus_Properties_get_reply)data->cb) (proxy, OUT_Value, error, data->userdata); + return; +} + +static +#ifdef G_HAVE_INLINE +inline +#endif +DBusGProxyCall* +org_freedesktop_DBus_Properties_get_async (DBusGProxy *proxy, const char * IN_Interface_Name, const char * IN_Property_Name, org_freedesktop_DBus_Properties_get_reply callback, gpointer userdata) + +{ + DBusGAsyncData *stuff; + stuff = g_slice_new (DBusGAsyncData); + stuff->cb = G_CALLBACK (callback); + stuff->userdata = userdata; + return dbus_g_proxy_begin_call (proxy, "Get", org_freedesktop_DBus_Properties_get_async_callback, stuff, _dbus_glib_async_data_free, G_TYPE_STRING, IN_Interface_Name, G_TYPE_STRING, IN_Property_Name, G_TYPE_INVALID); +} +static +#ifdef G_HAVE_INLINE +inline +#endif +gboolean +org_freedesktop_DBus_Properties_set (DBusGProxy *proxy, const char * IN_Interface_Name, const char * IN_Property_Name, const GValue* IN_Value, GError **error) + +{ + return dbus_g_proxy_call (proxy, "Set", error, G_TYPE_STRING, IN_Interface_Name, G_TYPE_STRING, IN_Property_Name, G_TYPE_VALUE, IN_Value, G_TYPE_INVALID, G_TYPE_INVALID); +} + +typedef void (*org_freedesktop_DBus_Properties_set_reply) (DBusGProxy *proxy, GError *error, gpointer userdata); + +static void +org_freedesktop_DBus_Properties_set_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data) +{ + DBusGAsyncData *data = (DBusGAsyncData*) user_data; + GError *error = NULL; + dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID); + (*(org_freedesktop_DBus_Properties_set_reply)data->cb) (proxy, error, data->userdata); + return; +} + +static +#ifdef G_HAVE_INLINE +inline +#endif +DBusGProxyCall* +org_freedesktop_DBus_Properties_set_async (DBusGProxy *proxy, const char * IN_Interface_Name, const char * IN_Property_Name, const GValue* IN_Value, org_freedesktop_DBus_Properties_set_reply callback, gpointer userdata) + +{ + DBusGAsyncData *stuff; + stuff = g_slice_new (DBusGAsyncData); + stuff->cb = G_CALLBACK (callback); + stuff->userdata = userdata; + return dbus_g_proxy_begin_call (proxy, "Set", org_freedesktop_DBus_Properties_set_async_callback, stuff, _dbus_glib_async_data_free, G_TYPE_STRING, IN_Interface_Name, G_TYPE_STRING, IN_Property_Name, G_TYPE_VALUE, IN_Value, G_TYPE_INVALID); +} +static +#ifdef G_HAVE_INLINE +inline +#endif +gboolean +org_freedesktop_DBus_Properties_get_all (DBusGProxy *proxy, const char * IN_Interface_Name, GHashTable** OUT_Properties, GError **error) + +{ + return dbus_g_proxy_call (proxy, "GetAll", error, G_TYPE_STRING, IN_Interface_Name, G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), OUT_Properties, G_TYPE_INVALID); +} + +typedef void (*org_freedesktop_DBus_Properties_get_all_reply) (DBusGProxy *proxy, GHashTable *OUT_Properties, GError *error, gpointer userdata); + +static void +org_freedesktop_DBus_Properties_get_all_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data) +{ + DBusGAsyncData *data = (DBusGAsyncData*) user_data; + GError *error = NULL; + GHashTable* OUT_Properties; + dbus_g_proxy_end_call (proxy, call, &error, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &OUT_Properties, G_TYPE_INVALID); + (*(org_freedesktop_DBus_Properties_get_all_reply)data->cb) (proxy, OUT_Properties, error, data->userdata); + return; +} + +static +#ifdef G_HAVE_INLINE +inline +#endif +DBusGProxyCall* +org_freedesktop_DBus_Properties_get_all_async (DBusGProxy *proxy, const char * IN_Interface_Name, org_freedesktop_DBus_Properties_get_all_reply callback, gpointer userdata) + +{ + DBusGAsyncData *stuff; + stuff = g_slice_new (DBusGAsyncData); + stuff->cb = G_CALLBACK (callback); + stuff->userdata = userdata; + return dbus_g_proxy_begin_call (proxy, "GetAll", org_freedesktop_DBus_Properties_get_all_async_callback, stuff, _dbus_glib_async_data_free, G_TYPE_STRING, IN_Interface_Name, G_TYPE_INVALID); +} +#endif /* defined DBUS_GLIB_CLIENT_WRAPPERS_org_freedesktop_DBus_Properties */ + +G_END_DECLS -- cgit v1.2.3 From cb14ba38535788494734b0a775148ec873231f07 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 7 Jan 2010 21:00:10 -0600 Subject: Pretty major cut and paste error. Wrong icon. --- src/libappindicator/app-indicator.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index d22161c..a17a46c 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -698,14 +698,14 @@ app_indicator_set_icon (AppIndicator *self, const gchar *icon_name) g_return_if_fail (IS_APP_INDICATOR (self)); g_return_if_fail (icon_name != NULL); - if (g_strcmp0 (self->priv->attention_icon_name, icon_name) != 0) + if (g_strcmp0 (self->priv->icon_name, icon_name) != 0) { - if (self->priv->attention_icon_name) - g_free (self->priv->attention_icon_name); + if (self->priv->icon_name) + g_free (self->priv->icon_name); - self->priv->attention_icon_name = g_strdup (icon_name); + self->priv->icon_name = g_strdup (icon_name); - g_signal_emit (self, signals[NEW_ATTENTION_ICON], 0, TRUE); + g_signal_emit (self, signals[NEW_ICON], 0, TRUE); } } -- cgit v1.2.3 From ad42e1044d1bc653a3df8ce76e6e74d79ea890cc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 8 Jan 2010 11:53:21 -0600 Subject: Fleshing out some of the remove function. For some reason the appstore is getting disposed, but that's the next thing to look at. --- src/application-service-appstore.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index ae9876e..3215b49 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -585,6 +585,8 @@ application_service_appstore_application_add (ApplicationServiceAppstore * appst return; } +/* Removes an application. Currently only works for the apps + that are shown. /TODO Need to fix that. */ void application_service_appstore_application_remove (ApplicationServiceAppstore * appstore, const gchar * dbus_name, const gchar * dbus_object) { @@ -592,6 +594,17 @@ application_service_appstore_application_remove (ApplicationServiceAppstore * ap g_return_if_fail(dbus_name != NULL && dbus_name[0] != '\0'); g_return_if_fail(dbus_object != NULL && dbus_object[0] != '\0'); + ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(appstore); + GList * listpntr; + + for (listpntr = priv->applications; listpntr != NULL; listpntr = g_list_next(listpntr)) { + Application * app = (Application *)listpntr->data; + + if (!g_strcmp0(app->dbus_name, dbus_name) && !g_strcmp0(app->dbus_object, dbus_object)) { + application_removed_cb(NULL, app); + break; /* NOTE: Must break as the list will become inconsistent */ + } + } return; } -- cgit v1.2.3 From 12aab9617cef451183373e16b70a7a168aa82114 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 8 Jan 2010 12:34:43 -0600 Subject: When destroying the application free all the proxies. --- src/application-service-appstore.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index 3215b49..de8d914 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -78,6 +78,7 @@ struct _Application { gchar * aicon; gchar * menu; gchar * icon_path; + gboolean currently_free; }; #define APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(o) \ @@ -261,6 +262,18 @@ static void application_free (Application * app) { if (app == NULL) return; + + /* Handle the case where this could be called by unref'ing one of + the proxy objects. */ + if (app->currently_free) return; + app->currently_free = TRUE; + + if (app->dbus_proxy) { + g_object_unref(app->dbus_proxy); + } + if (app->prop_proxy) { + g_object_unref(app->prop_proxy); + } if (app->dbus_name != NULL) { g_free(app->dbus_name); @@ -512,6 +525,7 @@ application_service_appstore_application_add (ApplicationServiceAppstore * appst app->aicon = NULL; app->menu = NULL; app->icon_path = NULL; + app->currently_free = FALSE; /* Get the DBus proxy for the NotificationItem interface */ GError * error = NULL; -- cgit v1.2.3 From 7970210755bb4523c02b122c8a5eaa0d4e83bde7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 8 Jan 2010 13:19:52 -0600 Subject: Fixing shutdown signal, but disabling for now --- src/application-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/application-service.c b/src/application-service.c index 45295a1..d21154f 100644 --- a/src/application-service.c +++ b/src/application-service.c @@ -43,7 +43,7 @@ service_disconnected (IndicatorService * service, gpointer data) { g_debug("Service disconnected"); if (mainloop != NULL) { - g_main_loop_quit(mainloop); + //g_main_loop_quit(mainloop); } return; } @@ -57,7 +57,7 @@ main (int argc, char ** argv) /* Bring us up as a basic indicator service */ service = indicator_service_new(INDICATOR_APPLICATION_DBUS_ADDR); - g_signal_connect(G_OBJECT(service), "disconnected", G_CALLBACK(service_disconnected), NULL); + g_signal_connect(G_OBJECT(service), INDICATOR_SERVICE_SIGNAL_SHUTDOWN, G_CALLBACK(service_disconnected), NULL); /* Building our app store */ appstore = APPLICATION_SERVICE_APPSTORE(g_object_new(APPLICATION_SERVICE_APPSTORE_TYPE, NULL)); -- cgit v1.2.3 From f8e9a51b9aeeadc89c7e60abca531ab076cacca5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 8 Jan 2010 13:20:06 -0600 Subject: Debug message cleanup. --- src/application-service-appstore.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index de8d914..4772e49 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -136,7 +136,6 @@ application_service_appstore_class_init (ApplicationServiceAppstoreClass *klass) _application_service_marshal_VOID__INT_STRING, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_STRING, G_TYPE_NONE); - dbus_g_object_type_install_info(APPLICATION_SERVICE_APPSTORE_TYPE, &dbus_glib__application_service_server_object_info); @@ -249,7 +248,6 @@ get_position (Application * app) { GList * applistitem = g_list_find(priv->applications, app); if (applistitem == NULL) { - g_warning("Change the icon of an application that isn't in the application list?"); return -1; } @@ -322,6 +320,7 @@ apply_status (Application * app, ApplicationStatus status) if (app->status == status) { return; } + g_debug("Changing app status to: %d", status); ApplicationServiceAppstore * appstore = app->appstore; ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(appstore); -- cgit v1.2.3 From 5f797d71ef38ddb421e9b26757df8d3e87b84bce Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 8 Jan 2010 14:10:45 -0600 Subject: Putting the signal on the Class instead of the Instance. --- src/application-service-appstore.c | 6 +++--- src/application-service-appstore.h | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index 4772e49..fa1b9d2 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -117,21 +117,21 @@ application_service_appstore_class_init (ApplicationServiceAppstoreClass *klass) signals[APPLICATION_ADDED] = g_signal_new ("application-added", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ApplicationServiceAppstore, application_added), + G_STRUCT_OFFSET (ApplicationServiceAppstoreClass, application_added), NULL, NULL, _application_service_marshal_VOID__STRING_INT_STRING_STRING_STRING, G_TYPE_NONE, 5, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_NONE); signals[APPLICATION_REMOVED] = g_signal_new ("application-removed", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ApplicationServiceAppstore, application_removed), + G_STRUCT_OFFSET (ApplicationServiceAppstoreClass, application_removed), NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT, G_TYPE_NONE); signals[APPLICATION_ICON_CHANGED] = g_signal_new ("application-icon-changed", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ApplicationServiceAppstore, application_icon_changed), + G_STRUCT_OFFSET (ApplicationServiceAppstoreClass, application_icon_changed), NULL, NULL, _application_service_marshal_VOID__INT_STRING, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_STRING, G_TYPE_NONE); diff --git a/src/application-service-appstore.h b/src/application-service-appstore.h index 7ab20c5..6bd7a01 100644 --- a/src/application-service-appstore.h +++ b/src/application-service-appstore.h @@ -40,16 +40,16 @@ typedef struct _ApplicationServiceAppstoreClass ApplicationServiceAppstoreClass; struct _ApplicationServiceAppstoreClass { GObjectClass parent_class; -}; - -struct _ApplicationServiceAppstore { - GObject parent; void (*application_added) (ApplicationServiceAppstore * appstore, gchar *, gint, gchar *, gchar *, gpointer); void (*application_removed) (ApplicationServiceAppstore * appstore, gint, gpointer); void (*application_icon_changed)(ApplicationServiceAppstore * appstore, gint, const gchar *, gpointer); }; +struct _ApplicationServiceAppstore { + GObject parent; +}; + GType application_service_appstore_get_type (void); void application_service_appstore_application_add (ApplicationServiceAppstore * appstore, const gchar * dbus_name, -- cgit v1.2.3