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/indicator-application.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/indicator-application.c') diff --git a/src/indicator-application.c b/src/indicator-application.c index 16c3a9f..66913df 100644 --- a/src/indicator-application.c +++ b/src/indicator-application.c @@ -108,6 +108,7 @@ static void disconnected_kill_helper (gpointer data, gpointer user_data); static void application_added (DBusGProxy * proxy, const gchar * iconname, gint position, const gchar * dbusaddress, const gchar * dbusobject, const gchar * icon_path, 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 application_icon_path_changed (DBusGProxy * proxy, gint position, const gchar * iconpath, IndicatorApplication * application); static void get_applications (DBusGProxy *proxy, GPtrArray *OUT_applications, GError *error, gpointer userdata); static void get_applications_helper (gpointer data, gpointer user_data); static void theme_dir_unref(IndicatorApplication * ia, const gchar * dir); @@ -280,6 +281,11 @@ connected (IndicatorApplication * application) G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_proxy_add_signal(priv->service_proxy, + "ApplicationIconPathChanged", + G_TYPE_INT, + G_TYPE_STRING, + G_TYPE_INVALID); /* Connect to them */ g_debug("Connect to them."); @@ -298,6 +304,11 @@ connected (IndicatorApplication * application) G_CALLBACK(application_icon_changed), application, NULL /* Disconnection Signal */); + dbus_g_proxy_connect_signal(priv->service_proxy, + "ApplicationIconPathChanged", + G_CALLBACK(application_icon_path_changed), + application, + NULL /* Disconnection Signal */); } /* Query it for existing applications */ @@ -537,6 +548,29 @@ application_icon_changed (DBusGProxy * proxy, gint position, const gchar * iconn return; } +/* The callback for the signal that the icon path for an application + has changed. */ +static void +application_icon_path_changed (DBusGProxy * proxy, gint position, const gchar * iconpath, 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; + } + + g_free(app->icon_path); + app->icon_path = NULL; + if (iconpath != NULL && iconpath[0] != '\0') { + app->icon_path = g_strdup(iconpath); + theme_dir_ref(application, iconpath); + } + + 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 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/indicator-application.c | 67 +++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 27 deletions(-) (limited to 'src/indicator-application.c') diff --git a/src/indicator-application.c b/src/indicator-application.c index 66913df..1a7467d 100644 --- a/src/indicator-application.c +++ b/src/indicator-application.c @@ -84,7 +84,8 @@ struct _IndicatorApplicationPrivate { typedef struct _ApplicationEntry ApplicationEntry; struct _ApplicationEntry { IndicatorObjectEntry entry; - gchar * icon_path; + gchar * icon_theme_path; + gchar * icon_name; gboolean old_service; gchar * dbusobject; gchar * dbusaddress; @@ -105,10 +106,10 @@ static void disconnected (IndicatorApplication * application); static void disconnected_helper (gpointer data, gpointer user_data); static gboolean disconnected_kill (gpointer user_data); static void disconnected_kill_helper (gpointer data, gpointer user_data); -static void application_added (DBusGProxy * proxy, const gchar * iconname, gint position, const gchar * dbusaddress, const gchar * dbusobject, const gchar * icon_path, IndicatorApplication * application); +static void application_added (DBusGProxy * proxy, const gchar * iconname, gint position, const gchar * dbusaddress, const gchar * dbusobject, const gchar * icon_theme_path, 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 application_icon_path_changed (DBusGProxy * proxy, gint position, const gchar * iconpath, IndicatorApplication * application); +static void application_icon_theme_path_changed (DBusGProxy * proxy, gint position, const gchar * icon_theme_path, IndicatorApplication * application); static void get_applications (DBusGProxy *proxy, GPtrArray *OUT_applications, GError *error, gpointer userdata); static void get_applications_helper (gpointer data, gpointer user_data); static void theme_dir_unref(IndicatorApplication * ia, const gchar * dir); @@ -282,7 +283,7 @@ connected (IndicatorApplication * application) G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_add_signal(priv->service_proxy, - "ApplicationIconPathChanged", + "ApplicationIconThemePathChanged", G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID); @@ -305,8 +306,8 @@ connected (IndicatorApplication * application) application, NULL /* Disconnection Signal */); dbus_g_proxy_connect_signal(priv->service_proxy, - "ApplicationIconPathChanged", - G_CALLBACK(application_icon_path_changed), + "ApplicationIconThemePathChanged", + G_CALLBACK(application_icon_theme_path_changed), application, NULL /* Disconnection Signal */); } @@ -424,7 +425,7 @@ application_added_search (gconstpointer a, gconstpointer b) ApplicationEntry and signaling the indicator host that we've got a new indicator. */ static void -application_added (DBusGProxy * proxy, const gchar * iconname, gint position, const gchar * dbusaddress, const gchar * dbusobject, const gchar * icon_path, IndicatorApplication * application) +application_added (DBusGProxy * proxy, const gchar * iconname, gint position, const gchar * dbusaddress, const gchar * dbusobject, const gchar * icon_theme_path, IndicatorApplication * application) { g_return_if_fail(IS_INDICATOR_APPLICATION(application)); g_debug("Building new application entry: %s with icon: %s", dbusaddress, iconname); @@ -446,15 +447,16 @@ application_added (DBusGProxy * proxy, const gchar * iconname, gint position, co ApplicationEntry * app = g_new(ApplicationEntry, 1); app->old_service = FALSE; - app->icon_path = NULL; - if (icon_path != NULL && icon_path[0] != '\0') { - app->icon_path = g_strdup(icon_path); - theme_dir_ref(application, icon_path); + app->icon_theme_path = NULL; + if (icon_theme_path != NULL && icon_theme_path[0] != '\0') { + app->icon_theme_path = g_strdup(icon_theme_path); + theme_dir_ref(application, icon_theme_path); } app->dbusaddress = g_strdup(dbusaddress); app->dbusobject = g_strdup(dbusobject); + app->icon_name = g_strdup(iconname); /* We make a long name using the suffix, and if that icon is available we want to use it. Otherwise we'll just use the name we were given. */ @@ -500,9 +502,9 @@ application_removed (DBusGProxy * proxy, gint position, IndicatorApplication * a priv->applications = g_list_remove(priv->applications, app); g_signal_emit(G_OBJECT(application), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID, 0, &(app->entry), TRUE); - if (app->icon_path != NULL) { - theme_dir_unref(application, app->icon_path); - g_free(app->icon_path); + if (app->icon_theme_path != NULL) { + theme_dir_unref(application, app->icon_theme_path); + g_free(app->icon_theme_path); } if (app->dbusaddress != NULL) { g_free(app->dbusaddress); @@ -510,6 +512,9 @@ application_removed (DBusGProxy * proxy, gint position, IndicatorApplication * a if (app->dbusobject != NULL) { g_free(app->dbusobject); } + if (app->icon_name != NULL) { + g_free(app->icon_name); + } if (app->entry.image != NULL) { g_object_unref(G_OBJECT(app->entry.image)); } @@ -544,14 +549,16 @@ application_icon_changed (DBusGProxy * proxy, gint position, const gchar * iconn gchar * longname = g_strdup_printf("%s-%s", iconname, PANEL_ICON_SUFFIX); indicator_image_helper_update(app->entry.image, longname); g_free(longname); + + app->icon_name = g_strdup(iconname); return; } -/* The callback for the signal that the icon path for an application +/* The callback for the signal that the icon theme path for an application has changed. */ static void -application_icon_path_changed (DBusGProxy * proxy, gint position, const gchar * iconpath, IndicatorApplication * application) +application_icon_theme_path_changed (DBusGProxy * proxy, gint position, const gchar * icon_theme_path, IndicatorApplication * application) { IndicatorApplicationPrivate * priv = INDICATOR_APPLICATION_GET_PRIVATE(application); ApplicationEntry * app = (ApplicationEntry *)g_list_nth_data(priv->applications, position); @@ -561,11 +568,17 @@ application_icon_path_changed (DBusGProxy * proxy, gint position, const gchar * return; } - g_free(app->icon_path); - app->icon_path = NULL; - if (iconpath != NULL && iconpath[0] != '\0') { - app->icon_path = g_strdup(iconpath); - theme_dir_ref(application, iconpath); + if (icon_theme_path[0] != '\0' && g_strcmp0(icon_theme_path, app->icon_theme_path) != 0) { + if(app->icon_theme_path != NULL) { + theme_dir_unref(application, app->icon_theme_path); + g_free(app->icon_theme_path); + app->icon_theme_path = NULL; + } + if (icon_theme_path != NULL ) { + app->icon_theme_path = g_strdup(icon_theme_path); + theme_dir_ref(application, app->icon_theme_path); + } + indicator_image_helper_update(app->entry.image, app->icon_name); } return; @@ -598,13 +611,13 @@ get_applications_helper (gpointer data, gpointer user_data) gint position = g_value_get_int(g_value_array_get_nth(array, 1)); const gchar * dbus_address = g_value_get_string(g_value_array_get_nth(array, 2)); const gchar * dbus_object = g_value_get_boxed(g_value_array_get_nth(array, 3)); - const gchar * icon_path = g_value_get_string(g_value_array_get_nth(array, 4)); + const gchar * icon_theme_path = g_value_get_string(g_value_array_get_nth(array, 4)); - return application_added(NULL, icon_name, position, dbus_address, dbus_object, icon_path, user_data); + return application_added(NULL, icon_name, position, dbus_address, dbus_object, icon_theme_path, user_data); } -/* Refs a theme directory, and it may add it to the search - path */ +/* Unrefs a theme directory. This may involve removing it from + the search path. */ static void theme_dir_unref(IndicatorApplication * ia, const gchar * dir) { @@ -663,8 +676,8 @@ theme_dir_unref(IndicatorApplication * ia, const gchar * dir) return; } -/* Unrefs a theme directory. This may involve removing it from - the search path. */ +/* Refs a theme directory, and it may add it to the search + path */ static void theme_dir_ref(IndicatorApplication * ia, const gchar * dir) { -- cgit v1.2.3 From 0a8c09e4f8ce284788845f465dcc826a67602cd0 Mon Sep 17 00:00:00 2001 From: Sense Hofstede Date: Thu, 22 Jul 2010 17:36:12 +0200 Subject: Fixed two G_PARAM_SPECS and made it even more possible to remove the custom icon theme path. --- src/indicator-application.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/indicator-application.c') diff --git a/src/indicator-application.c b/src/indicator-application.c index 1a7467d..066ea63 100644 --- a/src/indicator-application.c +++ b/src/indicator-application.c @@ -568,13 +568,13 @@ application_icon_theme_path_changed (DBusGProxy * proxy, gint position, const gc return; } - if (icon_theme_path[0] != '\0' && g_strcmp0(icon_theme_path, app->icon_theme_path) != 0) { + if (g_strcmp0(icon_theme_path, app->icon_theme_path) != 0) { if(app->icon_theme_path != NULL) { theme_dir_unref(application, app->icon_theme_path); g_free(app->icon_theme_path); app->icon_theme_path = NULL; } - if (icon_theme_path != NULL ) { + if (icon_theme_path != NULL && icon_theme_path[0] != '\0') { app->icon_theme_path = g_strdup(icon_theme_path); theme_dir_ref(application, app->icon_theme_path); } -- cgit v1.2.3