[gnome-commander/get_rid_of_xml] Save and loadn connections in gSettings
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander/get_rid_of_xml] Save and loadn connections in gSettings
- Date: Fri, 11 Jan 2019 22:32:17 +0000 (UTC)
commit 59cedfc5c6d2bff79669e5fff2033ddc7365433f
Author: Uwe Scholz <u scholz83 gmx de>
Date: Fri Jan 11 22:55:21 2019 +0100
Save and loadn connections in gSettings
data/org.gnome.gnome-commander.gschema.xml | 7 +++
src/gnome-cmd-data.cc | 85 +++++++++++++++++++++++++-----
src/gnome-cmd-data.h | 4 ++
3 files changed, 84 insertions(+), 12 deletions(-)
---
diff --git a/data/org.gnome.gnome-commander.gschema.xml b/data/org.gnome.gnome-commander.gschema.xml
index d9d77948..ea671af2 100644
--- a/data/org.gnome.gnome-commander.gschema.xml
+++ b/data/org.gnome.gnome-commander.gschema.xml
@@ -268,6 +268,13 @@
This option defines the height of the bookmarks window.
</description>
</key>
+ <key name="connections" type="a(ss)">
+ <default>[]</default>
+ <summary>List of connectionss</summary>
+ <description>
+ Each entry in this list represents a connection.
+ </description>
+ </key>
<key name="main-win-height" type="u">
<default>400</default>
<summary>Main window height</summary>
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index c3a1afd3..6edf6c7c 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -1926,6 +1926,37 @@ static void save_tabs_via_gsettings(GSettings *gSettings, const char *gSettingsK
}
+/**
+ * Save connections in gSettings
+ */
+void GnomeCmdData::save_connections()
+{
+ GVariant* connectionsToStore;
+ GVariantBuilder gVariantBuilder;
+ g_variant_builder_init (&gVariantBuilder, G_VARIANT_TYPE_ARRAY);
+
+ for (GList *i = gnome_cmd_con_list_get_all_remote (gnome_cmd_data.priv->con_list); i; i = i->next)
+ {
+ GnomeCmdCon *con = GNOME_CMD_CON (i->data);
+
+ if (con)
+ {
+ if (!con->alias || !*con->alias || !con->uri || !*con->uri)
+ continue;
+
+ g_autofree gchar *name = g_strescape (con->alias, nullptr);
+ g_autofree gchar *uri = g_strescape (con->uri, nullptr);
+
+ g_variant_builder_add (&gVariantBuilder, GCMD_SETTINGS_CONNECTION_FORMAT_STRING,
+ name,
+ uri);
+ }
+ }
+ connectionsToStore = g_variant_builder_end (&gVariantBuilder);
+ g_settings_set_value(options.gcmd_settings->general, GCMD_SETTINGS_CONNECTIONS, connectionsToStore);
+}
+
+
/**
* Save favourite applications in the given file by means of GKeyFile.
*/
@@ -2955,6 +2986,46 @@ void GnomeCmdData::load_devices_from_gsettings()
load_vfs_auto_devices ();
}
+/**
+ * Loads connections from gSettings into gcmd options
+ */
+void GnomeCmdData::load_connections()
+{
+ GVariant *gvConnections, *connection;
+ GVariantIter iter;
+
+ gvConnections = g_settings_get_value(options.gcmd_settings->general, GCMD_SETTINGS_CONNECTIONS);
+
+ g_variant_iter_init (&iter, gvConnections);
+
+ while ((connection = g_variant_iter_next_value (&iter)) != NULL)
+ {
+ g_autofree gchar *name, *nameDecompressed, *uri, *uriDecompressed;
+
+ g_assert (g_variant_is_of_type (connection, G_VARIANT_TYPE
(GCMD_SETTINGS_CONNECTION_FORMAT_STRING)));
+ g_variant_get(connection, GCMD_SETTINGS_CONNECTION_FORMAT_STRING, &name, &uri);
+
+ nameDecompressed = g_strcompress(name);
+ uriDecompressed = g_strcompress(uri);
+
+ if (gnome_cmd_con_list_get()->has_alias(nameDecompressed))
+ {
+ gnome_cmd_con_erase_bookmark (gnome_cmd_con_list_get()->find_alias(nameDecompressed));
+ }
+ else
+ {
+ GnomeCmdConRemote *server = gnome_cmd_con_remote_new (nameDecompressed, uriDecompressed);
+ if (server)
+ gnome_cmd_con_list_get()->add(server);
+ else
+ g_warning ("<Connection> invalid URI: '%s' - ignored", uriDecompressed);
+ }
+
+ g_variant_unref(connection);
+ }
+ g_variant_unref(gvConnections);
+}
+
void GnomeCmdData::load()
{
@@ -3590,6 +3661,7 @@ void GnomeCmdData::load()
load_advrename_profiles ();
load_search_profiles ();
+ load_connections ();
load_bookmarks ();
if (load_fav_apps_old(FAV_APPS_FILENAME) == FALSE)
@@ -3710,18 +3782,6 @@ void GnomeCmdData::save_xml ()
xml << search_defaults;
xml << bookmarks_defaults;
- xml << XML::tag("Connections");
-
- for (GList *i=gnome_cmd_con_list_get_all_remote (gnome_cmd_data.priv->con_list); i; i=i->next)
- {
- GnomeCmdCon *con = GNOME_CMD_CON (i->data);
-
- if (con)
- xml << *con;
- }
-
- xml << XML::endtag("Connections");
-
xml << XML::tag("Bookmarks");
write (xml, priv->con_list->get_home(), "Home");
@@ -3951,6 +4011,7 @@ void GnomeCmdData::save()
save_directory_history ();
save_search_history ();
save_search_profiles ();
+ save_connections ();
save_bookmarks ();
save_advrename_profiles();
diff --git a/src/gnome-cmd-data.h b/src/gnome-cmd-data.h
index 08770fe5..d02ce4d3 100644
--- a/src/gnome-cmd-data.h
+++ b/src/gnome-cmd-data.h
@@ -139,6 +139,8 @@ GcmdSettings *gcmd_settings_new (void);
#define GCMD_SETTINGS_BOOKMARKS_WINDOW_WIDTH "bookmarks-win-width"
#define GCMD_SETTINGS_BOOKMARKS_WINDOW_WIDTH "bookmarks-win-width"
#define GCMD_SETTINGS_BOOKMARKS_WINDOW_HEIGHT "bookmarks-win-height"
+#define GCMD_SETTINGS_CONNECTIONS "connections"
+#define GCMD_SETTINGS_CONNECTION_FORMAT_STRING "(ss)"
#define GCMD_PREF_FILTER "org.gnome.gnome-commander.preferences.filter"
#define GCMD_SETTINGS_FILTER_HIDE_UNKNOWN "hide-unknown"
@@ -641,6 +643,8 @@ struct GnomeCmdData
void load_intviewer_defaults();
gboolean save_auto_load_plugins();
void load_bookmarks();
+ void load_connections();
+ void save_connections();
void save_cmdline_history();
void save_directory_history();
void save_search_history();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]