summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Borelli <[email protected]>2017-04-25 19:09:42 +0200
committerraveit65 <[email protected]>2017-04-25 19:11:06 +0200
commit2d8dc45d586f21fe82dd706abc50f27103b75005 (patch)
tree10e4c8aa979987b8ae6049f268bc6615a89b6219
parent947da76491a293717a5e94346a1193f6b17d9c0b (diff)
downloadpluma-2d8dc45d586f21fe82dd706abc50f27103b75005.tar.bz2
pluma-2d8dc45d586f21fe82dd706abc50f27103b75005.tar.xz
Support new location of gtk bookmarks file
The gtk bookmarks file is now in XDG dir, so let's first try there and otherwise fall back to the old location
-rw-r--r--plugins/filebrowser/pluma-file-bookmarks-store.c133
1 files changed, 85 insertions, 48 deletions
diff --git a/plugins/filebrowser/pluma-file-bookmarks-store.c b/plugins/filebrowser/pluma-file-bookmarks-store.c
index 073d6bb3..bcd550a2 100644
--- a/plugins/filebrowser/pluma-file-bookmarks-store.c
+++ b/plugins/filebrowser/pluma-file-bookmarks-store.c
@@ -494,66 +494,103 @@ add_bookmark (PlumaFileBookmarksStore * model,
return ret;
}
-static void
-init_bookmarks (PlumaFileBookmarksStore * model)
+static gchar *
+get_bookmarks_file (void)
+{
+ return g_build_filename (g_get_user_config_dir (), "gtk-3.0", "bookmarks", NULL);
+}
+
+static gchar *
+get_legacy_bookmarks_file (void)
+{
+ return g_build_filename (g_get_home_dir (), ".gtk-bookmarks", NULL);
+}
+
+static gboolean
+parse_bookmarks_file (PlumaFileBookmarksStore *model,
+ const gchar *bookmarks,
+ gboolean *added)
{
- gchar *bookmarks;
GError *error = NULL;
gchar *contents;
gchar **lines;
gchar **line;
- gboolean added = FALSE;
- /* Read the bookmarks file */
- bookmarks = g_build_filename (g_get_home_dir (),
- ".gtk-bookmarks",
- NULL);
-
- if (g_file_get_contents (bookmarks, &contents, NULL, &error)) {
- lines = g_strsplit (contents, "\n", 0);
-
- for (line = lines; *line; ++line) {
- if (**line) {
- gchar *pos;
- gchar *name;
-
- /* CHECK: is this really utf8? */
- pos = g_utf8_strchr (*line, -1, ' ');
-
- if (pos != NULL) {
- *pos = '\0';
- name = pos + 1;
- } else {
- name = NULL;
- }
-
- /* the bookmarks file should contain valid
- * URIs, but paranoia is good */
- if (pluma_utils_is_valid_uri (*line)) {
- added |= add_bookmark (model, name, *line);
- }
+ if (!g_file_get_contents (bookmarks, &contents, NULL, &error))
+ {
+ /* The bookmarks file doesn't exist (which is perfectly fine) */
+ g_error_free (error);
+
+ return FALSE;
+ }
+
+ lines = g_strsplit (contents, "\n", 0);
+
+ for (line = lines; *line; ++line)
+ {
+ if (**line)
+ {
+ gchar *pos;
+ gchar *name;
+
+ /* CHECK: is this really utf8? */
+ pos = g_utf8_strchr (*line, -1, ' ');
+
+ if (pos != NULL)
+ {
+ *pos = '\0';
+ name = pos + 1;
+ }
+ else
+ {
+ name = NULL;
+ }
+
+ /* the bookmarks file should contain valid
+ * URIs, but paranoia is good */
+ if (pluma_utils_is_valid_uri (*line))
+ {
+ *added |= add_bookmark (model, name, *line);
}
}
+ }
+
+ g_strfreev (lines);
+ g_free (contents);
- g_strfreev (lines);
- g_free (contents);
+ /* Add a watch */
+ if (model->priv->bookmarks_monitor == NULL)
+ {
+ GFile *file;
- /* Add a watch */
- if (model->priv->bookmarks_monitor == NULL) {
- GFile * file;
+ file = g_file_new_for_path (bookmarks);
+ model->priv->bookmarks_monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL);
+ g_object_unref (file);
- file = g_file_new_for_path (bookmarks);
- model->priv->bookmarks_monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL);
- g_object_unref (file);
+ g_signal_connect (model->priv->bookmarks_monitor,
+ "changed",
+ G_CALLBACK (on_bookmarks_file_changed),
+ model);
+ }
- g_signal_connect (model->priv->bookmarks_monitor,
- "changed",
- (GCallback)on_bookmarks_file_changed,
- model);
- }
- } else {
- /* The bookmarks file doesn't exist (which is perfectly fine) */
- g_error_free (error);
+ return TRUE;
+}
+
+static void
+init_bookmarks (PlumaFileBookmarksStore *model)
+{
+ gchar *bookmarks;
+ gboolean added = FALSE;
+
+ bookmarks = get_bookmarks_file ();
+
+ if (!parse_bookmarks_file (model, bookmarks, &added))
+ {
+ g_free (bookmarks);
+
+ /* try the old location (gtk <= 3.4) */
+ bookmarks = get_legacy_bookmarks_file ();
+ parse_bookmarks_file (model, bookmarks, &added);
}
if (added) {