[tracker/gsettings-rebased: 2/8] libtracker-common: Add migration code to TrackerConfigFile
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/gsettings-rebased: 2/8] libtracker-common: Add migration code to TrackerConfigFile
- Date: Tue, 8 Mar 2011 15:11:53 +0000 (UTC)
commit bce4774b8b4bcab16f521dfd608488d38ab75ed0
Author: Carlos Garnacho <carlosg gnome org>
Date: Thu Feb 17 14:16:24 2011 +0100
libtracker-common: Add migration code to TrackerConfigFile
This is no longer an abstract object, and the
tracker_config_file_migrate() function may be used
to dump the configuration to GSettings and get rid
of the key file.
src/libtracker-common/tracker-config-file.c | 90 ++++++++++++++++++++++++++-
src/libtracker-common/tracker-config-file.h | 13 ++++
2 files changed, 102 insertions(+), 1 deletions(-)
---
diff --git a/src/libtracker-common/tracker-config-file.c b/src/libtracker-common/tracker-config-file.c
index fb75bed..7982ef6 100644
--- a/src/libtracker-common/tracker-config-file.c
+++ b/src/libtracker-common/tracker-config-file.c
@@ -67,7 +67,7 @@ enum {
static guint signals[LAST_SIGNAL] = { 0, };
-G_DEFINE_ABSTRACT_TYPE (TrackerConfigFile, tracker_config_file, G_TYPE_OBJECT);
+G_DEFINE_TYPE (TrackerConfigFile, tracker_config_file, G_TYPE_OBJECT);
static void
tracker_config_file_class_init (TrackerConfigFileClass *klass)
@@ -405,3 +405,91 @@ tracker_config_file_save (TrackerConfigFile *config)
return config_save (config);
}
+
+TrackerConfigFile *
+tracker_config_file_new (void)
+{
+ return g_object_new (TRACKER_TYPE_CONFIG_FILE,
+ NULL);
+}
+
+gboolean
+tracker_config_file_migrate (TrackerConfigFile *file,
+ GSettings *settings,
+ TrackerConfigMigrationEntry *entries)
+{
+ gint i;
+
+ g_return_val_if_fail (TRACKER_IS_CONFIG_FILE (file), FALSE);
+
+ if (!file->key_file || !file->file_exists) {
+ return TRUE;
+ }
+
+ g_message ("Migrating configuration to GSettings...");
+
+ for (i = 0; entries[i].type != G_TYPE_INVALID; i++) {
+ if (!g_key_file_has_key (file->key_file,
+ entries[i].file_section,
+ entries[i].file_key,
+ NULL)) {
+ continue;
+ }
+
+ switch (entries[i].type) {
+ case G_TYPE_INT:
+ case G_TYPE_ENUM:
+ {
+ gint val;
+ val = g_key_file_get_integer (file->key_file,
+ entries[i].file_section,
+ entries[i].file_key,
+ NULL);
+
+ if (entries[i].type == G_TYPE_INT) {
+ g_settings_set_int (settings, entries[i].settings_key, val);
+ } else {
+ g_settings_set_enum (settings, entries[i].settings_key, val);
+ }
+ break;
+ }
+ case G_TYPE_BOOLEAN:
+ {
+ gboolean val;
+
+ val = g_key_file_get_boolean (file->key_file,
+ entries[i].file_section,
+ entries[i].file_key,
+ NULL);
+ g_settings_set_boolean (settings, entries[i].settings_key, val);
+ break;
+ }
+ case G_TYPE_POINTER:
+ {
+ gchar **vals;
+
+ vals = g_key_file_get_string_list (file->key_file,
+ entries[i].file_section,
+ entries[i].file_key,
+ NULL, NULL);
+
+ if (vals) {
+ g_settings_set_strv (settings, entries[i].settings_key,
+ (const gchar * const *) vals);
+ g_strfreev (vals);
+ }
+
+ break;
+ }
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+ }
+
+ g_file_delete (file->file, NULL, NULL);
+ g_message ("Finished migration to GSettings.");
+
+ return TRUE;
+}
+
diff --git a/src/libtracker-common/tracker-config-file.h b/src/libtracker-common/tracker-config-file.h
index 0d40aa9..1737b8b 100644
--- a/src/libtracker-common/tracker-config-file.h
+++ b/src/libtracker-common/tracker-config-file.h
@@ -38,6 +38,7 @@ G_BEGIN_DECLS
typedef struct _TrackerConfigFile TrackerConfigFile;
typedef struct _TrackerConfigFileClass TrackerConfigFileClass;
+typedef struct _TrackerConfigMigrationEntry TrackerConfigMigrationEntry;
struct _TrackerConfigFile {
GObject parent;
@@ -56,8 +57,20 @@ struct _TrackerConfigFileClass {
void (* changed) (TrackerConfigFile *file);
};
+struct _TrackerConfigMigrationEntry {
+ GType type;
+ const gchar *file_section;
+ const gchar *file_key;
+ const gchar *settings_key;
+};
+
GType tracker_config_file_get_type (void) G_GNUC_CONST;
+TrackerConfigFile* tracker_config_file_new (void);
+gboolean tracker_config_file_migrate (TrackerConfigFile *config,
+ GSettings *settings,
+ TrackerConfigMigrationEntry *entries);
+
gboolean tracker_config_file_save (TrackerConfigFile *config);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]