diff options
author | Ted Gould <ted@gould.cx> | 2010-08-10 17:13:22 -0500 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2010-08-10 17:13:22 -0500 |
commit | de6c40d873a317a98d025cb094e7d89a646b4000 (patch) | |
tree | 55694a5e98b8986c8dc8749695fa6f85bbe84eee | |
parent | f4b22a7fa52695acc7e1e5abd20859f320e3895f (diff) | |
download | libayatana-appindicator-de6c40d873a317a98d025cb094e7d89a646b4000.tar.gz libayatana-appindicator-de6c40d873a317a98d025cb094e7d89a646b4000.tar.bz2 libayatana-appindicator-de6c40d873a317a98d025cb094e7d89a646b4000.zip |
Fleshing out the loading overrides function.
-rw-r--r-- | src/application-service-appstore.c | 38 |
1 files changed, 38 insertions, 0 deletions
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 |