aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-01-20 15:01:00 -0600
committerTed Gould <ted@gould.cx>2010-01-20 15:01:00 -0600
commitde659683ee9d60ed0fefa2d20c4ff1342f1b94e2 (patch)
tree7baf0e4813a473e2f533487f10fe944afea97ea5
parent72432728b161a54dfd711242e17cd2e55a011c2c (diff)
parent38e8cebe7b5a6190bb504af82f483057327c1d25 (diff)
downloadlibayatana-appindicator-de659683ee9d60ed0fefa2d20c4ff1342f1b94e2.tar.gz
libayatana-appindicator-de659683ee9d60ed0fefa2d20c4ff1342f1b94e2.tar.bz2
libayatana-appindicator-de659683ee9d60ed0fefa2d20c4ff1342f1b94e2.zip
Updating to trunk (surprisingly without conflict)
-rw-r--r--src/application-service-appstore.c49
-rw-r--r--src/application-service.xml2
-rw-r--r--src/indicator-application.c133
-rw-r--r--src/libappindicator/app-indicator.c2
4 files changed, 179 insertions, 7 deletions
diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c
index 4cb2ab6..5b0cc15 100644
--- a/src/application-service-appstore.c
+++ b/src/application-service-appstore.c
@@ -31,7 +31,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include "dbus-shared.h"
/* DBus Prototypes */
-static gboolean _application_service_server_get_applications (ApplicationServiceAppstore * appstore, GArray ** apps);
+static gboolean _application_service_server_get_applications (ApplicationServiceAppstore * appstore, GPtrArray ** apps, GError ** error);
#include "application-service-server.h"
@@ -684,9 +684,52 @@ application_service_appstore_new (AppLruFile * lrufile)
/* DBus Interface */
static gboolean
-_application_service_server_get_applications (ApplicationServiceAppstore * appstore, GArray ** apps)
+_application_service_server_get_applications (ApplicationServiceAppstore * appstore, GPtrArray ** apps, GError ** error)
{
+ ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(appstore);
+
+ *apps = g_ptr_array_new();
+ GList * listpntr;
+ gint position = 0;
+
+ for (listpntr = priv->applications; listpntr != NULL; listpntr = g_list_next(listpntr)) {
+ GValueArray * values = g_value_array_new(5);
+
+ GValue value = {0};
+
+ /* Icon name */
+ g_value_init(&value, G_TYPE_STRING);
+ g_value_set_string(&value, ((Application *)listpntr->data)->icon);
+ g_value_array_append(values, &value);
+ g_value_unset(&value);
+
+ /* Position */
+ g_value_init(&value, G_TYPE_INT);
+ g_value_set_int(&value, position++);
+ g_value_array_append(values, &value);
+ g_value_unset(&value);
+
+ /* DBus Address */
+ g_value_init(&value, G_TYPE_STRING);
+ g_value_set_string(&value, ((Application *)listpntr->data)->dbus_name);
+ g_value_array_append(values, &value);
+ g_value_unset(&value);
+
+ /* DBus Object */
+ g_value_init(&value, DBUS_TYPE_G_OBJECT_PATH);
+ g_value_set_static_boxed(&value, ((Application *)listpntr->data)->menu);
+ g_value_array_append(values, &value);
+ g_value_unset(&value);
+
+ /* Icon path */
+ g_value_init(&value, G_TYPE_STRING);
+ g_value_set_string(&value, ((Application *)listpntr->data)->icon_path);
+ g_value_array_append(values, &value);
+ g_value_unset(&value);
+
+ g_ptr_array_add(*apps, values);
+ }
- return FALSE;
+ return TRUE;
}
diff --git a/src/application-service.xml b/src/application-service.xml
index d74aaa9..0b2e959 100644
--- a/src/application-service.xml
+++ b/src/application-service.xml
@@ -26,7 +26,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
<!-- Methods -->
<method name="GetApplications">
- <arg type="a(siso)" name="applications" direction="out" />
+ <arg type="a(sisos)" name="applications" direction="out" />
</method>
<!-- Signals -->
diff --git a/src/indicator-application.c b/src/indicator-application.c
index c330645..5ed7a9e 100644
--- a/src/indicator-application.c
+++ b/src/indicator-application.c
@@ -75,6 +75,7 @@ struct _IndicatorApplicationPrivate {
DBusGConnection * bus;
DBusGProxy * service_proxy;
GList * applications;
+ GHashTable * theme_dirs;
};
typedef struct _ApplicationEntry ApplicationEntry;
@@ -96,6 +97,9 @@ static void application_added (DBusGProxy * proxy, const gchar * iconname, gint
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);
+static void get_applications_helper (gpointer data, gpointer user_data);
+static void theme_dir_unref(IndicatorApplication * ia, const gchar * dir);
+static void theme_dir_ref(IndicatorApplication * ia, const gchar * dir);
G_DEFINE_TYPE (IndicatorApplication, indicator_application, INDICATOR_OBJECT_TYPE);
@@ -138,12 +142,15 @@ indicator_application_init (IndicatorApplication *self)
/* These are built in the connection phase */
priv->bus = NULL;
priv->service_proxy = NULL;
+ priv->theme_dirs = NULL;
priv->sm = indicator_service_manager_new(INDICATOR_APPLICATION_DBUS_ADDR);
g_signal_connect(G_OBJECT(priv->sm), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connected), self);
priv->applications = NULL;
+ priv->theme_dirs = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+
return;
}
@@ -173,6 +180,15 @@ indicator_application_dispose (GObject *object)
priv->service_proxy = NULL;
}
+ if (priv->theme_dirs != NULL) {
+ while (g_hash_table_size(priv->theme_dirs)) {
+ GList * keys = g_hash_table_get_keys(priv->theme_dirs);
+ theme_dir_unref(INDICATOR_APPLICATION(object), (gchar *)keys->data);
+ }
+ g_hash_table_destroy(priv->theme_dirs);
+ priv->theme_dirs = NULL;
+ }
+
G_OBJECT_CLASS (indicator_application_parent_class)->dispose (object);
return;
}
@@ -295,14 +311,17 @@ application_added (DBusGProxy * proxy, const gchar * iconname, gint position, co
app->icon_path = NULL;
if (icon_path != NULL && icon_path[0] != '\0') {
app->icon_path = g_strdup(icon_path);
- g_debug("\tAppending search path: %s", app->icon_path);
- gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), app->icon_path);
+ theme_dir_ref(application, icon_path);
}
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));
+ /* Keep copies of these for ourself, just in case. */
+ g_object_ref(app->entry.image);
+ g_object_ref(app->entry.menu);
+
gtk_widget_show(GTK_WIDGET(app->entry.image));
priv->applications = g_list_insert(priv->applications, app, position);
@@ -329,6 +348,7 @@ application_removed (DBusGProxy * proxy, gint position, IndicatorApplication * a
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->entry.image != NULL) {
@@ -368,6 +388,115 @@ application_icon_changed (DBusGProxy * proxy, gint position, const gchar * iconn
static void
get_applications (DBusGProxy *proxy, GPtrArray *OUT_applications, GError *error, gpointer userdata)
{
+ if (error != NULL) {
+ g_warning("Unable to get application list: %s", error->message);
+ return;
+ }
+ g_ptr_array_foreach(OUT_applications, get_applications_helper, userdata);
return;
}
+
+/* A little helper that takes apart the DBus structure and calls
+ application_added on every entry in the list. */
+static void
+get_applications_helper (gpointer data, gpointer user_data)
+{
+ GValueArray * array = (GValueArray *)data;
+
+ g_return_if_fail(array->n_values == 5);
+
+ const gchar * icon_name = g_value_get_string(g_value_array_get_nth(array, 0));
+ 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));
+
+ return application_added(NULL, icon_name, position, dbus_address, dbus_object, icon_path, user_data);
+}
+
+/* Refs a theme directory, and it may add it to the search
+ path */
+static void
+theme_dir_unref(IndicatorApplication * ia, const gchar * dir)
+{
+ IndicatorApplicationPrivate * priv = INDICATOR_APPLICATION_GET_PRIVATE(ia);
+
+ /* Grab the count for this dir */
+ int count = GPOINTER_TO_INT(g_hash_table_lookup(priv->theme_dirs, dir));
+
+ /* Is this a simple deprecation, if so, we can just lower the
+ number and move on. */
+ if (count > 1) {
+ count--;
+ g_hash_table_insert(priv->theme_dirs, g_strdup(dir), GINT_TO_POINTER(count));
+ return;
+ }
+
+ /* Try to remove it from the hash table, this makes sure
+ that it existed */
+ if (!g_hash_table_remove(priv->theme_dirs, dir)) {
+ g_warning("Unref'd a directory that wasn't in the theme dir hash table.");
+ return;
+ }
+
+ GtkIconTheme * icon_theme = gtk_icon_theme_get_default();
+ gchar ** paths;
+ gint path_count;
+
+ gtk_icon_theme_get_search_path(icon_theme, &paths, &path_count);
+
+ gint i;
+ gboolean found = FALSE;
+ for (i = 0; i < path_count; i++) {
+ if (found) {
+ /* If we've already found the right entry */
+ paths[i - 1] = paths[i];
+ } else {
+ /* We're still looking, is this the one? */
+ if (!g_strcmp0(paths[i], dir)) {
+ found = TRUE;
+ /* We're freeing this here as it won't be captured by the
+ g_strfreev() below as it's out of the array. */
+ g_free(paths[i]);
+ }
+ }
+ }
+
+ /* If we found one we need to reset the path to
+ accomidate the changes */
+ if (found) {
+ paths[path_count - 1] = NULL; /* Clear the last one */
+ gtk_icon_theme_set_search_path(icon_theme, (const gchar **)paths, path_count - 1);
+ }
+
+ g_strfreev(paths);
+
+ return;
+}
+
+/* Unrefs a theme directory. This may involve removing it from
+ the search path. */
+static void
+theme_dir_ref(IndicatorApplication * ia, const gchar * dir)
+{
+ IndicatorApplicationPrivate * priv = INDICATOR_APPLICATION_GET_PRIVATE(ia);
+
+ int count = 0;
+ if ((count = GPOINTER_TO_INT(g_hash_table_lookup(priv->theme_dirs, dir))) != 0) {
+ /* It exists so what we need to do is increase the ref
+ count of this dir. */
+ count++;
+ } else {
+ /* It doesn't exist, so we need to add it to the table
+ and to the search path. */
+ gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), dir);
+ g_debug("\tAppending search path: %s", dir);
+ count = 1;
+ }
+
+ g_hash_table_insert(priv->theme_dirs, g_strdup(dir), GINT_TO_POINTER(count));
+
+ return;
+}
+
diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c
index 7fabef9..b0f721e 100644
--- a/src/libappindicator/app-indicator.c
+++ b/src/libappindicator/app-indicator.c
@@ -758,7 +758,7 @@ fallback (AppIndicator * self)
gtk_status_icon_set_title(icon, app_indicator_get_id(self));
g_signal_connect(G_OBJECT(self), APP_INDICATOR_SIGNAL_NEW_STATUS,
- G_CALLBACK(status_icon_changes), icon);
+ G_CALLBACK(status_icon_status_wrapper), icon);
g_signal_connect(G_OBJECT(self), APP_INDICATOR_SIGNAL_NEW_ICON,
G_CALLBACK(status_icon_changes), icon);
g_signal_connect(G_OBJECT(self), APP_INDICATOR_SIGNAL_NEW_ATTENTION_ICON,