From 47806177db55300ada6d5f6bf543eb77d765f0f3 Mon Sep 17 00:00:00 2001 From: C10uD Date: Thu, 22 Jul 2010 14:57:14 +0200 Subject: trying to implement runtime theme-path changing --- src/application-service-appstore.c | 75 +++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) (limited to 'src/application-service-appstore.c') diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index 311fcb1..6c11b7f 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -49,6 +49,7 @@ static gboolean _application_service_server_get_applications (ApplicationService #define NOTIFICATION_ITEM_SIG_NEW_ICON "NewIcon" #define NOTIFICATION_ITEM_SIG_NEW_AICON "NewAttentionIcon" #define NOTIFICATION_ITEM_SIG_NEW_STATUS "NewStatus" +#define NOTIFICATION_ITEM_SIG_NEW_ICON_PATH "NewIconPath" /* Private Stuff */ struct _ApplicationServiceAppstorePrivate { @@ -89,6 +90,7 @@ enum { APPLICATION_ADDED, APPLICATION_REMOVED, APPLICATION_ICON_CHANGED, + APPLICATION_ICON_PATH_CHANGED, LAST_SIGNAL }; @@ -138,6 +140,13 @@ application_service_appstore_class_init (ApplicationServiceAppstoreClass *klass) NULL, NULL, _application_service_marshal_VOID__INT_STRING, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_STRING, G_TYPE_NONE); + signals[APPLICATION_ICON_PATH_CHANGED] = g_signal_new ("application-icon-path-changed", + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (ApplicationServiceAppstoreClass, application_icon_path_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, &dbus_glib__application_service_server_object_info); @@ -540,6 +549,44 @@ new_aicon_cb (DBusGProxy * proxy, GValue value, GError * error, gpointer userdat return; } +/* Gets the data back on an updated icon signal. Hopefully + a new fun icon. */ +static void +new_path_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 * newpath = g_value_get_string(&value); + if (newpath == NULL) { + g_warning("Bad new path :("); + return; + } + + Application * app = (Application *) userdata; + + if (g_strcmp0(newpath, app->icon_path)) { + /* If the new path is actually a new path */ + if (app->icon_path != NULL) g_free(app->icon_path); + app->icon_path = g_strdup(newpath); + + if (app->status == APP_INDICATOR_STATUS_ACTIVE) { + gint position = get_position(app); + if (position == -1) return; + + g_signal_emit(G_OBJECT(app->appstore), + signals[APPLICATION_ICON_PATH_CHANGED], 0, + position, newpath, TRUE); + } + } + + return; +} + /* Called when the Notification Item signals that it has a new icon. */ static void @@ -586,6 +633,22 @@ new_status (DBusGProxy * proxy, const gchar * status, gpointer data) return; } +/* Called when the Notification Item signals that it + has a new icon. */ +static void +new_path (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_PATH, + new_path_cb, + app); + return; +} + /* Adding a new NotificationItem object from DBus in to the appstore. First, we need to get the information on it though. */ @@ -659,7 +722,10 @@ application_service_appstore_application_add (ApplicationServiceAppstore * appst NOTIFICATION_ITEM_SIG_NEW_STATUS, G_TYPE_STRING, G_TYPE_INVALID); - + dbus_g_proxy_add_signal(app->dbus_proxy, + NOTIFICATION_ITEM_SIG_NEW_ICON_PATH, + G_TYPE_INVALID); + dbus_g_proxy_connect_signal(app->dbus_proxy, NOTIFICATION_ITEM_SIG_NEW_ICON, G_CALLBACK(new_icon), @@ -675,7 +741,12 @@ application_service_appstore_application_add (ApplicationServiceAppstore * appst G_CALLBACK(new_status), app, NULL); - + dbus_g_proxy_connect_signal(app->dbus_proxy, + NOTIFICATION_ITEM_SIG_NEW_ICON_PATH, + G_CALLBACK(new_path), + 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 0bbee36d1c080b247d14c5131666c7436761ece6 Mon Sep 17 00:00:00 2001 From: Sense Hofstede Date: Thu, 22 Jul 2010 16:51:10 +0200 Subject: Clean-up and renaming variables and functions everywhere to use icon_theme_path for the sake of consistency. Doesn't seem to do antyhing, though. --- src/application-service-appstore.c | 70 ++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 37 deletions(-) (limited to 'src/application-service-appstore.c') diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index 6c11b7f..b75d11d 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -43,13 +43,13 @@ static gboolean _application_service_server_get_applications (ApplicationService #define NOTIFICATION_ITEM_PROP_STATUS "Status" #define NOTIFICATION_ITEM_PROP_ICON_NAME "IconName" #define NOTIFICATION_ITEM_PROP_AICON_NAME "AttentionIconName" -#define NOTIFICATION_ITEM_PROP_ICON_PATH "IconThemePath" +#define NOTIFICATION_ITEM_PROP_ICON_THEME_PATH "IconThemePath" #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" -#define NOTIFICATION_ITEM_SIG_NEW_ICON_PATH "NewIconPath" +#define NOTIFICATION_ITEM_SIG_NEW_ICON_THEME_PATH "NewIconPath" /* Private Stuff */ struct _ApplicationServiceAppstorePrivate { @@ -78,7 +78,7 @@ struct _Application { gchar * icon; gchar * aicon; gchar * menu; - gchar * icon_path; + gchar * icon_theme_path; gboolean currently_free; }; @@ -90,7 +90,7 @@ enum { APPLICATION_ADDED, APPLICATION_REMOVED, APPLICATION_ICON_CHANGED, - APPLICATION_ICON_PATH_CHANGED, + APPLICATION_ICON_THEME_PATH_CHANGED, LAST_SIGNAL }; @@ -140,10 +140,10 @@ application_service_appstore_class_init (ApplicationServiceAppstoreClass *klass) NULL, NULL, _application_service_marshal_VOID__INT_STRING, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_STRING, G_TYPE_NONE); - signals[APPLICATION_ICON_PATH_CHANGED] = g_signal_new ("application-icon-path-changed", + signals[APPLICATION_ICON_THEME_PATH_CHANGED] = g_signal_new ("application-icon-theme-path-changed", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ApplicationServiceAppstoreClass, application_icon_path_changed), + G_STRUCT_OFFSET (ApplicationServiceAppstoreClass, application_icon_theme_path_changed), NULL, NULL, _application_service_marshal_VOID__INT_STRING, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_STRING, G_TYPE_NONE); @@ -255,11 +255,11 @@ get_all_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError * err app->aicon = g_value_dup_string(g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_AICON_NAME)); } - gpointer icon_path_data = g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_ICON_PATH); - if (icon_path_data != NULL) { - app->icon_path = g_value_dup_string((GValue *)icon_path_data); + gpointer icon_theme_path_data = g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_ICON_THEME_PATH); + if (icon_theme_path_data != NULL) { + app->icon_theme_path = g_value_dup_string((GValue *)icon_theme_path_data); } else { - app->icon_path = g_strdup(""); + app->icon_theme_path = g_strdup(""); } /* TODO: Calling approvers, but we're ignoring the results. So, eh. */ @@ -355,8 +355,8 @@ application_free (Application * app) if (app->menu != NULL) { g_free(app->menu); } - if (app->icon_path != NULL) { - g_free(app->icon_path); + if (app->icon_theme_path != NULL) { + g_free(app->icon_theme_path); } g_free(app); @@ -454,7 +454,7 @@ apply_status (Application * app, AppIndicatorStatus status) g_list_index(priv->applications, app), /* Position */ app->dbus_name, app->menu, - app->icon_path, + app->icon_theme_path, TRUE); } } else { @@ -549,38 +549,34 @@ new_aicon_cb (DBusGProxy * proxy, GValue value, GError * error, gpointer userdat return; } -/* Gets the data back on an updated icon signal. Hopefully - a new fun icon. */ +/* Gets the data back on an updated icon theme path. + Maybe a new icon */ static void -new_path_cb (DBusGProxy * proxy, GValue value, GError * error, gpointer userdata) +new_icon_theme_path_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); + g_warning("Unable to get updated icon theme path: %s", error->message); return; } /* Grab the icon and make sure we have one */ - const gchar * newpath = g_value_get_string(&value); - if (newpath == NULL) { - g_warning("Bad new path :("); - return; - } + const gchar * new_icon_theme_path = g_value_get_string(&value); Application * app = (Application *) userdata; - if (g_strcmp0(newpath, app->icon_path)) { - /* If the new path is actually a new path */ - if (app->icon_path != NULL) g_free(app->icon_path); - app->icon_path = g_strdup(newpath); + if (g_strcmp0(new_icon_theme_path, app->icon_theme_path)) { + /* If the new icon theme path is actually a new icon theme path */ + if (app->icon_theme_path != NULL) g_free(app->icon_theme_path); + app->icon_theme_path = g_strdup(new_icon_theme_path); if (app->status == APP_INDICATOR_STATUS_ACTIVE) { gint position = get_position(app); if (position == -1) return; g_signal_emit(G_OBJECT(app->appstore), - signals[APPLICATION_ICON_PATH_CHANGED], 0, - position, newpath, TRUE); + signals[APPLICATION_ICON_THEME_PATH_CHANGED], 0, + position, new_icon_theme_path, TRUE); } } @@ -634,17 +630,17 @@ new_status (DBusGProxy * proxy, const gchar * status, gpointer data) } /* Called when the Notification Item signals that it - has a new icon. */ + has a new icon theme path. */ static void -new_path (DBusGProxy * proxy, gpointer data) +new_icon_theme_path (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_PATH, - new_path_cb, + NOTIFICATION_ITEM_PROP_ICON_THEME_PATH, + new_icon_theme_path_cb, app); return; } @@ -675,7 +671,7 @@ application_service_appstore_application_add (ApplicationServiceAppstore * appst app->icon = NULL; app->aicon = NULL; app->menu = NULL; - app->icon_path = NULL; + app->icon_theme_path = NULL; app->currently_free = FALSE; /* Get the DBus proxy for the NotificationItem interface */ @@ -723,7 +719,7 @@ application_service_appstore_application_add (ApplicationServiceAppstore * appst G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_add_signal(app->dbus_proxy, - NOTIFICATION_ITEM_SIG_NEW_ICON_PATH, + NOTIFICATION_ITEM_SIG_NEW_ICON_THEME_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal(app->dbus_proxy, @@ -742,8 +738,8 @@ application_service_appstore_application_add (ApplicationServiceAppstore * appst app, NULL); dbus_g_proxy_connect_signal(app->dbus_proxy, - NOTIFICATION_ITEM_SIG_NEW_ICON_PATH, - G_CALLBACK(new_path), + NOTIFICATION_ITEM_SIG_NEW_ICON_THEME_PATH, + G_CALLBACK(new_icon_theme_path), app, NULL); @@ -835,7 +831,7 @@ _application_service_server_get_applications (ApplicationServiceAppstore * appst /* Icon path */ g_value_init(&value, G_TYPE_STRING); - g_value_set_string(&value, ((Application *)listpntr->data)->icon_path); + g_value_set_string(&value, ((Application *)listpntr->data)->icon_theme_path); g_value_array_append(values, &value); g_value_unset(&value); -- cgit v1.2.3 From 0dbf34a46c0c39f4e4bcd6ac1de72523cb7e3b63 Mon Sep 17 00:00:00 2001 From: Sense Hofstede Date: Thu, 22 Jul 2010 16:57:29 +0200 Subject: Fix wrong naming that caused the signal to be missed --- src/application-service-appstore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/application-service-appstore.c') diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index b75d11d..c5997e9 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -49,7 +49,7 @@ static gboolean _application_service_server_get_applications (ApplicationService #define NOTIFICATION_ITEM_SIG_NEW_ICON "NewIcon" #define NOTIFICATION_ITEM_SIG_NEW_AICON "NewAttentionIcon" #define NOTIFICATION_ITEM_SIG_NEW_STATUS "NewStatus" -#define NOTIFICATION_ITEM_SIG_NEW_ICON_THEME_PATH "NewIconPath" +#define NOTIFICATION_ITEM_SIG_NEW_ICON_THEME_PATH "NewIconThemePath" /* Private Stuff */ struct _ApplicationServiceAppstorePrivate { -- cgit v1.2.3 From 247e5a1ac3f714f831bea27fa87170b0ac7fec64 Mon Sep 17 00:00:00 2001 From: Sense Egbert Hofstede Date: Thu, 5 Aug 2010 15:51:53 +0200 Subject: Passing the updated icon theme path along with the DBus signal, saving a DBus call. --- src/application-service-appstore.c | 57 ++++++++++++-------------------------- 1 file changed, 17 insertions(+), 40 deletions(-) (limited to 'src/application-service-appstore.c') diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index c5997e9..f18a89e 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -549,40 +549,6 @@ new_aicon_cb (DBusGProxy * proxy, GValue value, GError * error, gpointer userdat return; } -/* Gets the data back on an updated icon theme path. - Maybe a new icon */ -static void -new_icon_theme_path_cb (DBusGProxy * proxy, GValue value, GError * error, gpointer userdata) -{ - /* Check for errors */ - if (error != NULL) { - g_warning("Unable to get updated icon theme path: %s", error->message); - return; - } - - /* Grab the icon and make sure we have one */ - const gchar * new_icon_theme_path = g_value_get_string(&value); - - Application * app = (Application *) userdata; - - if (g_strcmp0(new_icon_theme_path, app->icon_theme_path)) { - /* If the new icon theme path is actually a new icon theme path */ - if (app->icon_theme_path != NULL) g_free(app->icon_theme_path); - app->icon_theme_path = g_strdup(new_icon_theme_path); - - if (app->status == APP_INDICATOR_STATUS_ACTIVE) { - gint position = get_position(app); - if (position == -1) return; - - g_signal_emit(G_OBJECT(app->appstore), - signals[APPLICATION_ICON_THEME_PATH_CHANGED], 0, - position, new_icon_theme_path, TRUE); - } - } - - return; -} - /* Called when the Notification Item signals that it has a new icon. */ static void @@ -632,16 +598,26 @@ new_status (DBusGProxy * proxy, const gchar * status, gpointer data) /* Called when the Notification Item signals that it has a new icon theme path. */ static void -new_icon_theme_path (DBusGProxy * proxy, gpointer data) +new_icon_theme_path (DBusGProxy * proxy, const gchar * icon_theme_path, 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_THEME_PATH, - new_icon_theme_path_cb, - app); + if (g_strcmp0(icon_theme_path, app->icon_theme_path)) { + /* If the new icon theme path is actually a new icon theme path */ + if (app->icon_theme_path != NULL) g_free(app->icon_theme_path); + app->icon_theme_path = g_strdup(icon_theme_path); + + if (app->status == APP_INDICATOR_STATUS_ACTIVE) { + gint position = get_position(app); + if (position == -1) return; + + g_signal_emit(G_OBJECT(app->appstore), + signals[APPLICATION_ICON_THEME_PATH_CHANGED], 0, + position, app->icon_theme_path, TRUE); + } + } + return; } @@ -720,6 +696,7 @@ application_service_appstore_application_add (ApplicationServiceAppstore * appst G_TYPE_INVALID); dbus_g_proxy_add_signal(app->dbus_proxy, NOTIFICATION_ITEM_SIG_NEW_ICON_THEME_PATH, + G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_connect_signal(app->dbus_proxy, -- cgit v1.2.3