[gnome-commander/get_rid_of_xml] Store directory history via gSettings



commit 0bb11669d16637d88d7691f924991dcc3329ba37
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Tue Nov 20 07:58:21 2018 +0100

    Store directory history via gSettings

 data/org.gnome.gnome-commander.gschema.xml |  7 +++++
 src/gnome-cmd-data.cc                      | 46 ++++++++++++++++++++----------
 src/gnome-cmd-data.h                       |  3 ++
 3 files changed, 41 insertions(+), 15 deletions(-)
---
diff --git a/data/org.gnome.gnome-commander.gschema.xml b/data/org.gnome.gnome-commander.gschema.xml
index 4dc1ddb4..02d01ebe 100644
--- a/data/org.gnome.gnome-commander.gschema.xml
+++ b/data/org.gnome.gnome-commander.gschema.xml
@@ -47,6 +47,13 @@
           This string array represents the history of templates in the advance rename tool.
       </description>
     </key>
+    <key name="directory-history" type="as">
+      <default>[]</default>
+      <summary>History of visited directories</summary>
+      <description>
+          This string array represents the history of visited directories.
+      </description>
+    </key>
     <key name="use-default-font" type="b">
       <default>true</default>
       <summary>Use default font</summary>
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index 5158252b..d88ce79d 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -2566,6 +2566,18 @@ void GnomeCmdData::save_cmdline_history()
 }
 
 
+void GnomeCmdData::save_directory_history()
+{
+    if (!options.save_dir_history_on_exit)
+        return;
+
+    set_gsettings_string_array_from_glist(
+        options.gcmd_settings->general,
+        GCMD_SETTINGS_DIRECTORY_HISTORY,
+        gnome_cmd_con_get_dir_history (priv->con_list->get_home())->ents);
+}
+
+
 inline void GnomeCmdData::save_intviewer_defaults()
 {
     set_gsettings_string_array_from_glist(options.gcmd_settings->internalviewer, 
GCMD_SETTINGS_IV_SEARCH_PATTERN_TEXT, intviewer_defaults.text_patterns.ents);
@@ -2639,6 +2651,18 @@ inline void GnomeCmdData::load_cmdline_history()
 }
 
 
+inline void GnomeCmdData::load_directory_history()
+{
+    GList* directories = get_list_from_gsettings_string_array (options.gcmd_settings->general, 
GCMD_SETTINGS_DIRECTORY_HISTORY);
+
+    for (GList *i=directories; i; i=i->next)
+    {
+        gnome_cmd_con_get_dir_history (get_home_con())->add((const gchar *) i->data);
+    }
+    g_list_free(directories);
+}
+
+
 inline void GnomeCmdData::load_intviewer_defaults()
 {
     intviewer_defaults.text_patterns = get_list_from_gsettings_string_array 
(options.gcmd_settings->internalviewer, GCMD_SETTINGS_IV_SEARCH_PATTERN_TEXT);
@@ -3431,6 +3455,9 @@ void GnomeCmdData::load()
         // Convert xml to keyfiles by using the save methods.
         save_advrename_profiles(ADVRENAME_CONFIG_FILENAME);
 
+        // Convert directory history
+        save_directory_history();
+
         // Move gnome-commander.xml to gnome-commander.xml.deprecated
         gchar *xml_cfg_path_old = config_dir ? g_build_filename (config_dir, PACKAGE ".xml", NULL) : 
g_build_filename (g_get_home_dir (), "." PACKAGE, PACKAGE ".xml", NULL);
         gchar *xml_cfg_path_new = config_dir ? g_build_filename (config_dir, PACKAGE ".xml", NULL) : 
g_build_filename (g_get_home_dir (), "." PACKAGE, PACKAGE ".xml.deprecated", NULL);
@@ -3454,6 +3481,8 @@ void GnomeCmdData::load()
 
     priv->con_list->unlock();
 
+    load_directory_history();
+
     gchar *quick_connect_uri = g_settings_get_string(options.gcmd_settings->network, 
GCMD_SETTINGS_QUICK_CONNECT_URI);
     quick_connect = gnome_cmd_con_remote_new (NULL, quick_connect_uri);
     g_free (quick_connect_uri);
@@ -3560,20 +3589,6 @@ void GnomeCmdData::save_xml ()
 
     xml << *main_win;
 
-    xml << XML::tag("History");
-
-    if (options.save_dir_history_on_exit)
-    {
-        xml << XML::tag("Directories");
-
-        for (GList *i=gnome_cmd_con_get_dir_history (priv->con_list->get_home())->ents; i; i=i->next)
-            xml << XML::tag("Directory") << XML::attr("path") << XML::escape((const gchar *) i->data) << 
XML::endtag();
-
-        xml << XML::endtag("Directories");
-    }
-
-    xml << XML::endtag("History");
-
     xml << search_defaults;
     xml << bookmarks_defaults;
 
@@ -3809,8 +3824,9 @@ void GnomeCmdData::save()
     save_tabs_via_gsettings         (options.gcmd_settings->general, GCMD_SETTINGS_FILE_LIST_TABS);
     save_devices_via_gsettings      ();
     save_fav_apps_via_gsettings     ();
+    save_cmdline_history            ();
+    save_directory_history          ();
 
-    save_cmdline_history();
     save_advrename_profiles(ADVRENAME_CONFIG_FILENAME);
     save_intviewer_defaults();
 
diff --git a/src/gnome-cmd-data.h b/src/gnome-cmd-data.h
index 8614481b..de6a2bf3 100644
--- a/src/gnome-cmd-data.h
+++ b/src/gnome-cmd-data.h
@@ -122,6 +122,7 @@ GcmdSettings *gcmd_settings_new (void);
 #define GCMD_SETTINGS_DEVICES_FORMAT_STRING           "(ssss)"
 #define GCMD_SETTINGS_FAV_APPS                        "favorite-apps"
 #define GCMD_SETTINGS_FAV_APPS_FORMAT_STRING          "(ssssubbb)"
+#define GCMD_SETTINGS_DIRECTORY_HISTORY               "directory-history"
 
 #define GCMD_PREF_FILTER                              "org.gnome.gnome-commander.preferences.filter"
 #define GCMD_SETTINGS_FILTER_HIDE_UNKNOWN             "hide-unknown"
@@ -628,9 +629,11 @@ struct GnomeCmdData
 
     void load_auto_load_plugins();
     void load_cmdline_history();
+    void load_directory_history();
     void load_intviewer_defaults();
     gboolean save_auto_load_plugins();
     void save_cmdline_history();
+    void save_directory_history();
     void save_intviewer_defaults();
     void save_devices_via_gsettings();
     void save_fav_apps_via_gsettings();


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