From 6c0afe20ce75adbd12427ee2bffacbf6765d2bad Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 10 Aug 2010 16:21:08 -0500 Subject: Adding in an override keyfile --- data/Makefile.am | 10 ++++++++-- data/ordering-override.keyfile | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 data/ordering-override.keyfile diff --git a/data/Makefile.am b/data/Makefile.am index cc1961b..b9666af 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -5,7 +5,13 @@ dbus_services_DATA = indicator-application.service %.service: %.service.in sed -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@ -EXTRA_DIST = indicator-application.service.in +overridedir = $(datadir) +override_DATA = ordering-override.keyfile -CLEANFILES = indicator-application.service +EXTRA_DIST = \ + indicator-application.service.in \ + ordering-override.keyfile + +CLEANFILES = \ + indicator-application.service diff --git a/data/ordering-override.keyfile b/data/ordering-override.keyfile new file mode 100644 index 0000000..6665b7a --- /dev/null +++ b/data/ordering-override.keyfile @@ -0,0 +1,2 @@ +[Ordering Index Overides] +gnome-power-manager=1 -- cgit v1.2.3 From 73fb38c7e5695d4303c58fece8889dc8af0fdfe3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 10 Aug 2010 16:31:39 -0500 Subject: Installing the override file in the package specific data directory. --- data/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/Makefile.am b/data/Makefile.am index b9666af..c142c4e 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -5,7 +5,7 @@ dbus_services_DATA = indicator-application.service %.service: %.service.in sed -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@ -overridedir = $(datadir) +overridedir = $(pkgdatadir) override_DATA = ordering-override.keyfile EXTRA_DIST = \ -- cgit v1.2.3 From dad491a83573507401805d9782a02dec2bad743a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 10 Aug 2010 16:50:54 -0500 Subject: Adding an override hash table --- src/application-service-appstore.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index 5fc4f9b..47396bb 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -56,11 +56,14 @@ static gboolean _application_service_server_get_applications (ApplicationService #define NOTIFICATION_ITEM_SIG_NEW_LABEL "NewLabel" #define NOTIFICATION_ITEM_SIG_NEW_ICON_THEME_PATH "NewIconThemePath" +#define OVERRIDE_GROUP_NAME "Ordering Index Overrides" + /* Private Stuff */ struct _ApplicationServiceAppstorePrivate { DBusGConnection * bus; GList * applications; GList * approvers; + GHashTable * ordering_overrides; }; typedef struct _Approver Approver; @@ -183,6 +186,8 @@ application_service_appstore_init (ApplicationServiceAppstore *self) priv->applications = NULL; priv->approvers = NULL; + + priv->ordering_overrides = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); GError * error = NULL; priv->bus = dbus_g_bus_get(DBUS_BUS_STARTER, &error); @@ -225,6 +230,12 @@ application_service_appstore_dispose (GObject *object) static void application_service_appstore_finalize (GObject *object) { + ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE(object)->priv; + + if (priv->ordering_overrides != NULL) { + g_hash_table_destroy(priv->ordering_overrides); + priv->ordering_overrides = NULL; + } G_OBJECT_CLASS (application_service_appstore_parent_class)->finalize (object); return; -- cgit v1.2.3 From f4b22a7fa52695acc7e1e5abd20859f320e3895f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 10 Aug 2010 16:59:25 -0500 Subject: Putting together the pieces to look for override files --- src/Makefile.am | 1 + src/application-service-appstore.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index a7cfc0b..1c4e7ae 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -54,6 +54,7 @@ indicator_application_service_SOURCES = \ indicator_application_service_CFLAGS = \ $(INDICATOR_CFLAGS) \ + -DDATADIR="\"$(pkgdatadir)\"" \ -Wall -Werror \ -DG_LOG_DOMAIN=\"indicator-application-service\" diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index 47396bb..0df4dd5 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -57,6 +57,7 @@ static gboolean _application_service_server_get_applications (ApplicationService #define NOTIFICATION_ITEM_SIG_NEW_ICON_THEME_PATH "NewIconThemePath" #define OVERRIDE_GROUP_NAME "Ordering Index Overrides" +#define OVERRIDE_FILE_NAME "ordering-override.keyfile" /* Private Stuff */ struct _ApplicationServiceAppstorePrivate { @@ -112,6 +113,7 @@ 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 void load_override_file (GHashTable * hash, const gchar * filename); static AppIndicatorStatus string_to_status(const gchar * status_string); static void apply_status (Application * app, AppIndicatorStatus status); static void approver_free (gpointer papprover, gpointer user_data); @@ -188,6 +190,11 @@ application_service_appstore_init (ApplicationServiceAppstore *self) priv->approvers = NULL; priv->ordering_overrides = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + + load_override_file(priv->ordering_overrides, DATADIR "/" OVERRIDE_FILE_NAME); + gchar * userfile = g_build_filename(g_get_user_data_dir(), "indicators", "application", OVERRIDE_FILE_NAME, NULL); + load_override_file(priv->ordering_overrides, userfile); + g_free(userfile); GError * error = NULL; priv->bus = dbus_g_bus_get(DBUS_BUS_STARTER, &error); @@ -241,6 +248,15 @@ application_service_appstore_finalize (GObject *object) return; } +/* Loads the file and adds the override entries to the table + of overrides */ +static void +load_override_file (GHashTable * hash, const gchar * filename) +{ + + +} + /* 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. */ -- cgit v1.2.3 From de6c40d873a317a98d025cb094e7d89a646b4000 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 10 Aug 2010 17:13:22 -0500 Subject: Fleshing out the loading overrides function. --- src/application-service-appstore.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index 0df4dd5..4d21291 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -253,8 +253,46 @@ application_service_appstore_finalize (GObject *object) static void load_override_file (GHashTable * hash, const gchar * filename) { + g_return_if_fail(hash != NULL); + g_return_if_fail(filename != NULL); + if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { + return; + } + + g_debug("Loading overrides from: '%s'", filename); + + GError * error = NULL; + GKeyFile * keyfile = g_key_file_new(); + g_key_file_load_from_file(keyfile, filename, G_KEY_FILE_NONE, &error); + if (error != NULL) { + g_warning("Unable to load keyfile '%s' because: %s", filename, error->message); + g_error_free(error); + g_key_file_free(keyfile); + return; + } + + gchar ** keys = g_key_file_get_keys(keyfile, OVERRIDE_GROUP_NAME, NULL, NULL); + gchar * key = keys[0]; + gint i; + + for (i = 0; (key = keys[i]) != NULL; i++) { + GError * valerror = NULL; + gint val = g_key_file_get_integer(keyfile, OVERRIDE_GROUP_NAME, key, &valerror); + + if (valerror != NULL) { + g_warning("Unable to get key '%s' out of file '%s' because: %s", key, filename, valerror->message); + g_error_free(valerror); + continue; + } + g_debug("%s: override '%s' with value '%d'", filename, key, val); + + g_hash_table_insert(hash, g_strdup(key), GINT_TO_POINTER(val)); + } + g_key_file_free(keyfile); + + return; } /* Return from getting the properties from the item. We're looking at those -- cgit v1.2.3 From 51de4ced42e132fa3a66a2739e8a3ba861842467 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 10 Aug 2010 21:19:31 -0500 Subject: Checking for an override and applying it. --- src/application-service-appstore.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index 4d21291..d632456 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -346,11 +346,16 @@ get_all_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError * err app->icon_theme_path = g_strdup(""); } - gpointer ordering_index_data = g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_ORDERING_INDEX); - if (ordering_index_data == NULL || g_value_get_uint(ordering_index_data) == 0) { - app->ordering_index = generate_id(string_to_status(app->category), app->id); + gpointer ordering_index_over = g_hash_table_lookup(priv->ordering_overrides, app->id); + if (ordering_index_over == NULL) { + gpointer ordering_index_data = g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_ORDERING_INDEX); + if (ordering_index_data == NULL || g_value_get_uint(ordering_index_data) == 0) { + app->ordering_index = generate_id(string_to_status(app->category), app->id); + } else { + app->ordering_index = g_value_get_uint(ordering_index_data); + } } else { - app->ordering_index = g_value_get_uint(ordering_index_data); + app->ordering_index = GPOINTER_TO_UINT(ordering_index_over); } gpointer label_data = g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_LABEL); -- cgit v1.2.3