[gnome-commander/GSettings] Adds an initial source file for migration methods of config settings



commit 8b35185742982a6b8468f8c70715cade8e0dfe42
Author: Uwe Scholz <uwescholz src gnome org>
Date:   Tue Apr 19 22:45:42 2016 +0200

    Adds an initial source file for migration methods of config settings

 src/Makefile.am                   |    1 +
 src/gnome-cmd-settings-migrate.cc |   80 +++++++++++++++++++++++++++++++++++++
 src/gnome-cmd-settings-migrate.h  |   37 +++++++++++++++++
 3 files changed, 118 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 79f67ee..9c16b4d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -62,6 +62,7 @@ gnome_commander_SOURCES = \
        gnome-cmd-quicksearch-popup.h gnome-cmd-quicksearch-popup.cc \
        gnome-cmd-selection-profile-component.h gnome-cmd-selection-profile-component.cc \
        gnome-cmd-settings.h gnome-cmd-settings.cc \
+       gnome-cmd-settings-migrate.h gnome-cmd-settings-migrate.cc \
        gnome-cmd-style.h gnome-cmd-style.cc \
        gnome-cmd-treeview.h gnome-cmd-treeview.cc \
        gnome-cmd-types.h \
diff --git a/src/gnome-cmd-settings-migrate.cc b/src/gnome-cmd-settings-migrate.cc
new file mode 100644
index 0000000..7e47ad5
--- /dev/null
+++ b/src/gnome-cmd-settings-migrate.cc
@@ -0,0 +1,80 @@
+/**
+ * @file gnome-cmd-settings-migrate.cc
+ * @brief Here are functions stored for migrating xml settings to Gnomes GSettings
+ * @copyright (C) 2013-2016 Uwe Scholz\n
+ *
+ * @copyright This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * @copyright This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * @copyright You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include "gnome-cmd-settings-migrate.h"
+
+/**
+ * Hier sollte folgendes passieren:
+ * - Prüfen, ob ~/.gnome-commander/gnome-commander.xml existiert
+ * - Wenn ja
+ *   - dortige Einstellungen laden und in GSettings speichern
+ *   - umbenennen der xml-Datei in *.bak
+ *   - Rückgabewert TRUE
+ * - wenn nein:
+ *   - Rückgabewert: FALSE
+ */
+
+/**
+ * @note This function returns FALSE if ~/.gnome-commander/gnome-commander.xml
+ * does not exist. If it exists, the function loads most of the settings
+ * into the GSettings path org.gnome.gnome-commander.preferences.
+ * (See gnome-cmd-settings.cc for more info.) When the migration of the
+ * old data is completed, the xml file is renamed into
+ * ~/.gnome-commander/gnome-commander.xml.backup and TRUE is returned.
+ *
+ * @note Beginning with gcmd-v1.6 GSettings is used for storing and
+ * loading gcmd settings. For compatibility reasons, this
+ * functions tries to load settings from the 'old' xml file.
+ *
+ * @note In later versions of gcmd (later than v1.6), this function
+ * might be removed, because when saving the settings, GSettings is used.
+ *
+ * @returns FALSE if ~/.gnome-commander/gnome-commander.xml is not existing
+ * and TRUE if it is existing and most of the settings inside have been moved
+ * into the GSettings path org.gnome.gnome-commander.preferences.
+ */
+gboolean load_xml_into_gsettings (const gchar *fname)
+{
+    gboolean xml_was_there;
+    gchar *xml_cfg_path = config_dir ? g_build_filename (config_dir, PACKAGE ".xml", NULL) : 
g_build_filename (g_get_home_dir (), "." PACKAGE, PACKAGE ".xml", NULL);
+
+    FILE *fd = fopen (xml_cfg_path, "r");
+
+    if (fd)
+    {
+        // ToDo: Data migration
+
+        fclose (fd);
+        xml_was_there = TRUE;
+        // ToDo: Move old xml-file to ~/.gnome-commander/gnome-commander.xml.backup
+        //       à la save_devices_old ("devices.backup");
+    }
+    else
+    {
+        g_warning ("Failed to open the file %s for reading, skipping data migration", xml_cfg_path);
+        xml_was_there = FALSE;
+    }
+
+    g_free (xml_cfg_path);
+
+    return xml_was_there;
+}
diff --git a/src/gnome-cmd-settings-migrate.h b/src/gnome-cmd-settings-migrate.h
new file mode 100644
index 0000000..e8a237e
--- /dev/null
+++ b/src/gnome-cmd-settings-migrate.h
@@ -0,0 +1,37 @@
+/**
+ * @file gnome-cmd-settings-migrate.h
+ * @brief Header file for functions and other stuff for migrating xml
+ * settings to Gnomes GSettings
+ * @copyright (C) 2013-2016 Uwe Scholz\n
+ *
+ * @copyright This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * @copyright This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * @copyright You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __GNOME_CMD_SETTINGS_MIGRATE_H__
+#define __GNOME_CMD_SETTINGS_MIGRATE_H__
+
+#include <glib-object.h>
+#include <glib.h>
+#include "gnome-cmd-settings.h"
+
+G_BEGIN_DECLS
+
+extern gchar *config_dir;
+
+gboolean load_xml_into_gsettings (const gchar *fname);
+
+G_END_DECLS
+
+#endif // __GNOME_CMD_SETTINGS_H__


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