[gnome-commander/get_rid_of_xml] Adds saving and loading of the search tool profiles to gSettings
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander/get_rid_of_xml] Adds saving and loading of the search tool profiles to gSettings
- Date: Sun, 30 Dec 2018 17:54:17 +0000 (UTC)
commit bfa94a6caaa276883e18f4bcf8c7ba8c9fba393b
Author: Uwe Scholz <u scholz83 gmx de>
Date: Sun Dec 23 13:33:14 2018 +0100
Adds saving and loading of the search tool profiles to gSettings
data/org.gnome.gnome-commander.gschema.xml | 7 ++
src/gnome-cmd-data.cc | 102 ++++++++++++++++++++++++++++-
src/gnome-cmd-data.h | 6 ++
3 files changed, 114 insertions(+), 1 deletion(-)
---
diff --git a/data/org.gnome.gnome-commander.gschema.xml b/data/org.gnome.gnome-commander.gschema.xml
index 1a797450..4c6144e3 100644
--- a/data/org.gnome.gnome-commander.gschema.xml
+++ b/data/org.gnome.gnome-commander.gschema.xml
@@ -507,6 +507,13 @@
This string array represents the history of regular expression searches in the search tool.
</description>
</key>
+ <key name="search-profiles" type="a(siisbbs)">
+ <default>[]</default>
+ <summary>List of search tool profiles</summary>
+ <description>
+ The entries in this array represent the profiles in the search tool with specific settings for
each profile.
+ </description>
+ </key>
</schema>
<schema gettext-domain="gnome-commander" id="org.gnome.gnome-commander.preferences.network"
path="/org/gnome/gnome-commander/preferences/network/">
<key name="quick-connect-uri" type="s">
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index 1413cef3..3226b2e8 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -1588,6 +1588,50 @@ static void write(XML::xstream &xml, GnomeCmdCon *con, const gchar *name)
xml << XML::endtag("Group");
}
+
+/**
+ * Save search profiles in gSettings.
+ * The first profile is the active profile, i.e. the one which is used currently.
+ * The others are profiles which can be choosen in the profile dialoge.
+ */
+void GnomeCmdData::save_search_profiles ()
+{
+ GVariantBuilder* gVariantBuilder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
+ add_search_profile_to_gvariant_builder(gVariantBuilder, search_defaults.default_profile);
+
+ for (auto profile : selections)
+ {
+ add_search_profile_to_gvariant_builder(gVariantBuilder, profile);
+ }
+
+ GVariant* profilesToStore = g_variant_new(GCMD_SETTINGS_SEARCH_PROFILES_FORMAT_STRING, gVariantBuilder);
+ g_settings_set_value(options.gcmd_settings->general, GCMD_SETTINGS_SEARCH_PROFILES, profilesToStore);
+ g_variant_builder_unref(gVariantBuilder);
+}
+
+
+void GnomeCmdData::add_search_profile_to_gvariant_builder(GVariantBuilder *builder, GnomeCmdData::Selection
profile)
+{
+ gchar *nameString = g_strescape (profile.name.c_str(), NULL);
+ gchar *filenamePattern = g_strescape (profile.filename_pattern.c_str(), NULL);
+ gchar *textPattern = g_strescape (profile.text_pattern.c_str(), NULL);
+
+ g_variant_builder_add(builder, GCMD_SETTINGS_SEARCH_PROFILE_FORMAT_STRING,
+ nameString,
+ profile.max_depth,
+ (gint) profile.syntax,
+ filenamePattern,
+ profile.content_search,
+ profile.match_case,
+ textPattern
+ );
+
+ g_free(nameString);
+ g_free(filenamePattern);
+ g_free(textPattern);
+}
+
+
/**
* Save advance rename tool profiles in gSettings.
* The first profile is the active profile, i.e. the one which is used currently.
@@ -1607,7 +1651,6 @@ void GnomeCmdData::save_advrename_profiles ()
GVariant* profilesToStore = g_variant_new(GCMD_SETTINGS_ADVRENAME_PROFILES_FORMAT_STRING,
gVariantBuilder);
g_settings_set_value(options.gcmd_settings->general, GCMD_SETTINGS_ADVRENAME_PROFILES, profilesToStore);
g_variant_builder_unref(gVariantBuilder);
-
}
@@ -1645,6 +1688,7 @@ void GnomeCmdData::add_advrename_profile_to_gvariant_builder(GVariantBuilder *bu
g_free(templateString);
}
+
/**
* Save devices in gSettings
*/
@@ -2275,6 +2319,58 @@ void GnomeCmdData::load_advrename_profiles ()
}
+/**
+ * This method reads the gsettings section of the search tool profiles
+ */
+void GnomeCmdData::load_search_profiles ()
+{
+ GVariant *profiles = g_settings_get_value (options.gcmd_settings->general,
GCMD_SETTINGS_SEARCH_PROFILES);
+
+ g_autoptr(GVariantIter) iter1 = nullptr;
+
+ g_variant_get (profiles, GCMD_SETTINGS_SEARCH_PROFILES_FORMAT_STRING, &iter1);
+
+ g_autofree gchar *name = nullptr;
+ gint maxDepth = 0;
+ gint syntax = 0;
+ gchar* filenamePattern = nullptr;
+ gboolean contentSearch = false;
+ gboolean matchCase = false;
+ gchar* textPattern = nullptr;
+ guint profileNumber = 0;
+
+ while (g_variant_iter_loop (iter1,
+ GCMD_SETTINGS_SEARCH_PROFILE_FORMAT_STRING,
+ &name,
+ &maxDepth,
+ &syntax,
+ &filenamePattern,
+ &contentSearch,
+ &matchCase,
+ &textPattern))
+ {
+ Selection selection;
+
+ selection.name = name;
+ selection.max_depth = maxDepth;
+ selection.syntax = syntax == 0 ? Filter::TYPE_REGEX : Filter::TYPE_FNMATCH;
+ selection.filename_pattern = filenamePattern;
+ selection.content_search = contentSearch;
+ selection.match_case = matchCase;
+ selection.text_pattern = textPattern;
+
+ if (profileNumber == 0)
+ search_defaults.default_profile = selection;
+ else
+ selections.push_back(selection);
+
+ ++profileNumber;
+ }
+
+ g_variant_unref(profiles);
+}
+
+
/**
* Loads devices from gSettings into gcmd options
*/
@@ -3352,6 +3448,7 @@ void GnomeCmdData::load()
// Convert xml to keyfiles by using the save methods.
save_advrename_profiles();
+ save_search_profiles();
// Convert directory history
save_directory_history();
@@ -3372,6 +3469,8 @@ void GnomeCmdData::load()
g_free (xml_cfg_path);
load_advrename_profiles ();
+ load_search_profiles ();
+
if (load_fav_apps_old(FAV_APPS_FILENAME) == FALSE)
load_fav_apps_from_gsettings();
else // This is done for migration to gSettings. Can be deleted in gcmd 1.9.
@@ -3727,6 +3826,7 @@ void GnomeCmdData::save()
save_cmdline_history ();
save_directory_history ();
save_search_history ();
+ save_search_profiles ();
save_advrename_profiles();
save_intviewer_defaults();
diff --git a/src/gnome-cmd-data.h b/src/gnome-cmd-data.h
index a7ce8a94..f57595f0 100644
--- a/src/gnome-cmd-data.h
+++ b/src/gnome-cmd-data.h
@@ -130,6 +130,9 @@ GcmdSettings *gcmd_settings_new (void);
#define GCMD_SETTINGS_SEARCH_WIN_HEIGHT "search-win-height"
#define GCMD_SETTINGS_SEARCH_PATTERN_HISTORY "search-pattern-history"
#define GCMD_SETTINGS_SEARCH_TEXT_HISTORY "search-text-history"
+#define GCMD_SETTINGS_SEARCH_PROFILES "search-profiles"
+#define GCMD_SETTINGS_SEARCH_PROFILE_FORMAT_STRING "(siisbbs)"
+#define GCMD_SETTINGS_SEARCH_PROFILES_FORMAT_STRING "a(siisbbs)"
#define GCMD_PREF_FILTER "org.gnome.gnome-commander.preferences.filter"
#define GCMD_SETTINGS_FILTER_HIDE_UNKNOWN "hide-unknown"
@@ -635,6 +638,7 @@ struct GnomeCmdData
void save_devices_via_gsettings();
void save_fav_apps_via_gsettings();
void add_advrename_profile_to_gvariant_builder(GVariantBuilder *builder, AdvrenameConfig::Profile
profile);
+ void add_search_profile_to_gvariant_builder(GVariantBuilder *builder, Selection profile);
inline gint get_int (const gchar *path, int def);
inline gchar* get_string (const gchar *path, const gchar *def);
inline void set_string (const gchar *path, const gchar *value);
@@ -701,6 +705,8 @@ struct GnomeCmdData
inline GList* load_string_history (const gchar *format, gint size);
void load_advrename_profiles ();
void save_advrename_profiles ();
+ void load_search_profiles ();
+ void save_search_profiles ();
void save();
void save_xml ();
gint gnome_cmd_data_get_int (const gchar *path, int def);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]