[gnome-commander/get_rid_of_xml] Add storage of bookmarks and bookmark tool window in gSettings
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander/get_rid_of_xml] Add storage of bookmarks and bookmark tool window in gSettings
- Date: Wed, 9 Jan 2019 21:39:57 +0000 (UTC)
commit f6caf034b7c2176c035996c46aa97cb4ae6086f7
Author: Uwe Scholz <u scholz83 gmx de>
Date: Wed Jan 9 22:17:29 2019 +0100
Add storage of bookmarks and bookmark tool window in gSettings
data/org.gnome.gnome-commander.gschema.xml | 21 ++++
src/dialogs/gnome-cmd-manage-bookmarks-dialog.cc | 4 +-
src/gnome-cmd-data.cc | 126 +++++++++++++++++++++++
src/gnome-cmd-data.h | 13 ++-
4 files changed, 159 insertions(+), 5 deletions(-)
---
diff --git a/data/org.gnome.gnome-commander.gschema.xml b/data/org.gnome.gnome-commander.gschema.xml
index 4c6144e3..d9d77948 100644
--- a/data/org.gnome.gnome-commander.gschema.xml
+++ b/data/org.gnome.gnome-commander.gschema.xml
@@ -247,6 +247,27 @@
This option defines the width of the main window.
</description>
</key>
+ <key name="bookmarks" type="a(bsss)">
+ <default>[]</default>
+ <summary>List of bookmarks</summary>
+ <description>
+ Each entry in this list represents a bookmark.
+ </description>
+ </key>
+ <key name="bookmarks-win-width" type="u">
+ <default>400</default>
+ <summary>Bookmarks window width</summary>
+ <description>
+ This option defines the width of the bookmarks window.
+ </description>
+ </key>
+ <key name="bookmarks-win-height" type="u">
+ <default>250</default>
+ <summary>Bookmarks window height</summary>
+ <description>
+ This option defines the height of the bookmarks window.
+ </description>
+ </key>
<key name="main-win-height" type="u">
<default>400</default>
<summary>Main window height</summary>
diff --git a/src/dialogs/gnome-cmd-manage-bookmarks-dialog.cc
b/src/dialogs/gnome-cmd-manage-bookmarks-dialog.cc
index 0b678047..6e1edf06 100644
--- a/src/dialogs/gnome-cmd-manage-bookmarks-dialog.cc
+++ b/src/dialogs/gnome-cmd-manage-bookmarks-dialog.cc
@@ -369,7 +369,7 @@ static void remove_clicked_callback (GtkButton *button, GtkWidget *bm_view)
main_win->update_bookmarks ();
- gnome_cmd_data.save_xml ();
+ gnome_cmd_data.save_bookmarks ();
}
}
}
@@ -563,7 +563,7 @@ void gnome_cmd_bookmark_add_current (GnomeCmdDir *dir)
main_win->update_bookmarks();
- gnome_cmd_data.save_xml ();
+ gnome_cmd_data.save_bookmarks ();
}
else
{
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index f9e5432d..2a2c85e6 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -1589,6 +1589,72 @@ static void write(XML::xstream &xml, GnomeCmdCon *con, const gchar *name)
}
+void GnomeCmdData::save_bookmarks()
+{
+ gboolean hasBookmarks = false;
+ GVariantBuilder* gVariantBuilder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
+ g_variant_builder_init (gVariantBuilder, G_VARIANT_TYPE_ARRAY);
+
+ // Home
+ auto *con = priv->con_list->get_home();
+ hasBookmarks |= add_bookmark_to_gvariant_builder(gVariantBuilder, "Home", con);
+
+ // Samba
+#ifdef HAVE_SAMBA
+ con = priv->con_list->get_smb();
+ hasBookmarks |= add_bookmark_to_gvariant_builder(gVariantBuilder, "SMB", con);
+#endif
+
+ // Others
+ for (GList *i = gnome_cmd_con_list_get_all_remote (gnome_cmd_data.priv->con_list); i; i=i->next)
+ {
+ con = GNOME_CMD_CON (i->data);
+ std::string bookmarkGroupName = XML::escape(gnome_cmd_con_get_alias (con));
+ hasBookmarks |= add_bookmark_to_gvariant_builder(gVariantBuilder, bookmarkGroupName, con);
+ }
+
+ if (!hasBookmarks)
+ {
+ GVariant* bookmarksToStore = g_settings_get_default_value (options.gcmd_settings->general,
GCMD_SETTINGS_BOOKMARKS);
+ g_settings_set_value(options.gcmd_settings->general, GCMD_SETTINGS_BOOKMARKS, bookmarksToStore);
+ }
+ else
+ {
+ GVariant* bookmarksToStore = g_variant_builder_end (gVariantBuilder);
+ g_settings_set_value(options.gcmd_settings->general, GCMD_SETTINGS_BOOKMARKS, bookmarksToStore);
+ }
+
+ g_variant_builder_unref(gVariantBuilder);
+}
+
+
+gboolean GnomeCmdData::add_bookmark_to_gvariant_builder(GVariantBuilder *gVariantBuilder, std::string
bookmarkGroupName, GnomeCmdCon *con)
+{
+ if (!con)
+ return FALSE;
+
+ GList *bookmarks = gnome_cmd_con_get_bookmarks (con)->bookmarks;
+
+ if (!bookmarks)
+ return FALSE;
+
+ gboolean isRemote = GNOME_CMD_IS_CON_REMOTE (con) ? TRUE : FALSE;
+
+ for (GList *i = bookmarks; i; i = i->next)
+ {
+ auto bookmark = (GnomeCmdBookmark *) (i->data);
+
+ g_variant_builder_add (gVariantBuilder, GCMD_SETTINGS_BOOKMARK_FORMAT_STRING,
+ isRemote,
+ bookmarkGroupName.c_str(),
+ bookmark->name,
+ bookmark->path
+ );
+ }
+ return TRUE;
+}
+
+
/**
* Save search profiles in gSettings.
* The first profile is the active profile, i.e. the one which is used currently.
@@ -2139,6 +2205,58 @@ static void load_vfs_auto_devices ()
}
+void GnomeCmdData::load_bookmarks()
+{
+ GnomeCmdCon *gnomeCmdCon {nullptr};
+
+ GVariant *gVariantBookmarks = g_settings_get_value (options.gcmd_settings->general,
GCMD_SETTINGS_BOOKMARKS);
+
+ g_autoptr(GVariantIter) iter1 {nullptr};
+
+ g_variant_get (gVariantBookmarks, GCMD_SETTINGS_BOOKMARKS_FORMAT_STRING, &iter1);
+
+ gboolean isRemote {false};
+ gchar *bookmarkGroupName {nullptr};
+ gchar *bookmarkName {nullptr};
+ gchar *bookmarkPath {nullptr};
+
+ while (g_variant_iter_loop (iter1,
+ GCMD_SETTINGS_BOOKMARK_FORMAT_STRING,
+ &isRemote,
+ &bookmarkGroupName,
+ &bookmarkName,
+ &bookmarkPath))
+ {
+ if (isRemote)
+ gnomeCmdCon = gnome_cmd_con_list_get()->find_alias(bookmarkGroupName);
+ else
+ {
+ if (strcmp(bookmarkGroupName, "Home") == 0)
+ {
+ gnomeCmdCon = gnome_cmd_con_list_get()->get_home();
+ }
+ else
+ {
+#ifdef HAVE_SAMBA
+ if (strcmp(bookmarkGroupName, "SMB") == 0)
+ {
+ gnomeCmdCon = gnome_cmd_con_list_get()->get_smb();
+ }
+ else
+#endif
+ gnomeCmdCon = NULL;
+ }
+ }
+ if (!gnomeCmdCon)
+ g_warning ("<Bookmarks> unknown connection: '%s' - ignored", bookmarkGroupName);
+ else
+ gnome_cmd_con_add_bookmark (gnomeCmdCon, g_strdup(bookmarkName), g_strdup(bookmarkPath));
+ }
+
+ g_variant_unref(gVariantBookmarks);
+}
+
+
/**
* This function reads the given file and sets up additional devices by
* means of GKeyFile.
@@ -2214,6 +2332,7 @@ static gboolean load_devices (const gchar *fname)
return TRUE;
}
+
/**
* This method reads the gsettings section of the advance rename tool
*/
@@ -3207,6 +3326,8 @@ void GnomeCmdData::load()
search_defaults.width = g_settings_get_uint(options.gcmd_settings->general,
GCMD_SETTINGS_SEARCH_WIN_WIDTH);
search_defaults.content_patterns.ents = get_list_from_gsettings_string_array
(options.gcmd_settings->general, GCMD_SETTINGS_SEARCH_TEXT_HISTORY);
search_defaults.name_patterns.ents = get_list_from_gsettings_string_array
(options.gcmd_settings->general, GCMD_SETTINGS_SEARCH_PATTERN_HISTORY);
+ bookmarks_defaults.width = g_settings_get_uint(options.gcmd_settings->general,
GCMD_SETTINGS_BOOKMARKS_WINDOW_WIDTH);
+ bookmarks_defaults.height = g_settings_get_uint(options.gcmd_settings->general,
GCMD_SETTINGS_BOOKMARKS_WINDOW_HEIGHT);
options.always_show_tabs = g_settings_get_boolean (options.gcmd_settings->general,
GCMD_SETTINGS_ALWAYS_SHOW_TABS);
options.tab_lock_indicator = (TabLockIndicator) g_settings_get_enum (options.gcmd_settings->general,
GCMD_SETTINGS_TAB_LOCK_INDICATOR);
@@ -3473,6 +3594,7 @@ void GnomeCmdData::load()
load_advrename_profiles ();
load_search_profiles ();
+ load_bookmarks ();
if (load_fav_apps_old(FAV_APPS_FILENAME) == FALSE)
load_fav_apps_from_gsettings();
@@ -3809,6 +3931,9 @@ void GnomeCmdData::save()
set_gsettings_when_changed (options.gcmd_settings->general,
GCMD_SETTINGS_SAVE_SEARCH_HISTORY_ON_EXIT, &(options.save_search_history_on_exit));
set_gsettings_when_changed (options.gcmd_settings->general, GCMD_SETTINGS_SEARCH_WIN_WIDTH,
&(search_defaults.width));
set_gsettings_when_changed (options.gcmd_settings->general, GCMD_SETTINGS_SEARCH_WIN_HEIGHT,
&(search_defaults.height));
+ set_gsettings_when_changed (options.gcmd_settings->general, GCMD_SETTINGS_BOOKMARKS_WINDOW_WIDTH,
&(bookmarks_defaults.width));
+ set_gsettings_when_changed (options.gcmd_settings->general, GCMD_SETTINGS_BOOKMARKS_WINDOW_HEIGHT,
&(bookmarks_defaults.height));
+
set_gsettings_when_changed (options.gcmd_settings->general, GCMD_SETTINGS_ALWAYS_SHOW_TABS,
&(options.always_show_tabs));
set_gsettings_enum_when_changed (options.gcmd_settings->general, GCMD_SETTINGS_TAB_LOCK_INDICATOR,
options.tab_lock_indicator);
@@ -3830,6 +3955,7 @@ void GnomeCmdData::save()
save_directory_history ();
save_search_history ();
save_search_profiles ();
+ save_bookmarks ();
save_advrename_profiles();
save_intviewer_defaults();
diff --git a/src/gnome-cmd-data.h b/src/gnome-cmd-data.h
index 6313758b..08770fe5 100644
--- a/src/gnome-cmd-data.h
+++ b/src/gnome-cmd-data.h
@@ -133,6 +133,12 @@ GcmdSettings *gcmd_settings_new (void);
#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_SETTINGS_BOOKMARKS "bookmarks"
+#define GCMD_SETTINGS_BOOKMARK_FORMAT_STRING "(bsss)"
+#define GCMD_SETTINGS_BOOKMARKS_FORMAT_STRING "a(bsss)"
+#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_PREF_FILTER "org.gnome.gnome-commander.preferences.filter"
#define GCMD_SETTINGS_FILTER_HIDE_UNKNOWN "hide-unknown"
@@ -612,9 +618,7 @@ struct GnomeCmdData
struct BookmarksConfig
{
- gint width, height;
-
- BookmarksConfig(): width(400), height(250) {}
+ gint width {400}, height {250};
friend XML::xstream &operator << (XML::xstream &xml, BookmarksConfig &cfg);
};
@@ -636,6 +640,7 @@ struct GnomeCmdData
void load_directory_history();
void load_intviewer_defaults();
gboolean save_auto_load_plugins();
+ void load_bookmarks();
void save_cmdline_history();
void save_directory_history();
void save_search_history();
@@ -643,6 +648,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);
+ gboolean add_bookmark_to_gvariant_builder(GVariantBuilder *builder, std::string bookmarkName,
GnomeCmdCon *con);
void add_search_profile_to_gvariant_builder(GVariantBuilder *builder, SearchProfile searchProfile);
inline gint get_int (const gchar *path, int def);
inline gchar* get_string (const gchar *path, const gchar *def);
@@ -710,6 +716,7 @@ struct GnomeCmdData
void save_advrename_profiles ();
void load_search_profiles ();
void save_search_profiles ();
+ void save_bookmarks();
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]