[grilo] test-ui: replace GConf with GKeyFile



commit 343b2d72553cf7196942cc7a575182fba48fde60
Author: Víctor Manuel Jáquez Leal <vjaquez igalia com>
Date:   Mon May 2 13:08:34 2011 +0200

    test-ui: replace GConf with GKeyFile
    
    GConf is a bloated and deprecated dependency to grilo-test-ui. This patch
    replace its usage with a simple GKeyFile.
    
    Signed-off-by: Víctor Manuel Jáquez Leal <vjaquez igalia com>

 configure.ac               |    2 +-
 tools/grilo-test-ui/main.c |   89 ++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 79 insertions(+), 12 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 6f1e865..5d2b33b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -107,7 +107,7 @@ AC_SUBST(GLIB_MKENUMS)
 gtkver="gtk+-3.0"
 PKG_CHECK_EXISTS([gtk+-3.0], [gtkver="gtk+-3.0"], [gtkver="gtk+-2.0"])
 
-PKG_CHECK_MODULES([GTU], [ ${gtkver} gconf-2.0 ],
+PKG_CHECK_MODULES([GTU], [ ${gtkver} ],
                        [ BUILD_GRILO_TEST_UI=yes ],
                        [ BUILD_GRILO_TEST_UI=no ])
 
diff --git a/tools/grilo-test-ui/main.c b/tools/grilo-test-ui/main.c
index a996325..37ac2fd 100644
--- a/tools/grilo-test-ui/main.c
+++ b/tools/grilo-test-ui/main.c
@@ -28,7 +28,6 @@
 #include <gtk/gtk.h>
 #include <gdk/gdk.h>
 #include <string.h>
-#include <gconf/gconf-client.h>
 
 #include "flickr-auth.h"
 
@@ -52,9 +51,6 @@ GRL_LOG_DOMAIN_STATIC(test_ui_log_domain);
   "If you do not authorize it, then you can not access your "           \
   "private photos."
 
-
-#define GCONF_GTU_FLICKR_TOKEN "/apps/grilo-test-ui/auth-token"
-
 /* ----- Youtube Config tokens ---- */
 
 #define YOUTUBE_KEY   "AI39si4EfscPllSfUy1IwexMf__kntTL_G5dfSr2iUEVN45RHGq92Aq0lX25OlnOkG6KTN-4soVAkAf67fWYXuHfVADZYr7S1A"
@@ -1293,25 +1289,96 @@ search_combo_setup (void)
 }
 
 static gchar *
+get_config_dir ()
+{
+  char *confdir;
+  GFile *dir;
+  GError *error = NULL;
+
+  confdir = g_build_filename (g_get_user_config_dir (),
+                              "grilo-test-ui",
+                              NULL);
+
+  /* create the configuration directory if needed */
+  if (g_file_test (confdir, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
+      return confdir;
+
+  dir = g_file_new_for_path (confdir);
+  g_file_make_directory_with_parents (dir, NULL, &error);
+  g_object_unref (dir);
+
+  if (error && error->code != G_IO_ERROR_EXISTS) {
+    g_critical ("Could not create config directory %s: %s",
+                confdir, error->message);
+    g_clear_error (&error);
+    return NULL;
+  }
+
+  return confdir;
+}
+
+static gchar *
 load_flickr_token (void)
 {
-  GConfClient *confclient;
-  gchar *token;
+  GKeyFile *keyfile;
+  gchar *path;
+  gchar *file = NULL;
+  gchar *token = NULL;
+
+  path = get_config_dir ();
+  if (path) {
+    file = g_build_filename (path, "tokens.conf", NULL);
+    g_free (path);
+  }
 
-  confclient = gconf_client_get_default ();
+  if (!file)
+    return NULL;
 
-  token = gconf_client_get_string (confclient, GCONF_GTU_FLICKR_TOKEN, NULL);
+  keyfile = g_key_file_new ();
+  if (!g_key_file_load_from_file (keyfile, file, G_KEY_FILE_NONE, NULL))
+    goto bailout;
 
+  token = g_key_file_get_value (keyfile, "flickr", "auth-token", NULL);
+
+bailout:
+  g_free (file);
+  g_key_file_free (keyfile);
   return token;
 }
 
 static void
 save_flickr_token (const gchar *token)
 {
-  GConfClient *confclient;
+  GKeyFile *keyfile;
+  gchar *path;
+  gchar *file = NULL;
+
+  path = get_config_dir ();
+  if (path) {
+    file = g_build_filename (path, "tokens.conf", NULL);
+    g_free (path);
+  }
+
+  if (!file)
+    return;
+
+  keyfile = g_key_file_new ();
+  g_key_file_load_from_file (keyfile, file, G_KEY_FILE_NONE, NULL);
+  g_key_file_set_value (keyfile, "flickr", "auth-token", token);
+
+  {
+    GError *error = NULL;
+    gchar *content = g_key_file_to_data (keyfile, NULL, NULL);
+    g_file_set_contents (file, content, -1, &error);
+    if (error) {
+      g_warning ("Could not write %s: %s", file, error->message);
+      g_clear_error (&error);
+    }
+    g_free (content);
+  }
 
-  confclient = gconf_client_get_default ();
-  gconf_client_set_string (confclient, GCONF_GTU_FLICKR_TOKEN, token, NULL);
+  g_free (file);
+  g_key_file_free (keyfile);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]