[gtk+] Migrate to XDG config dir for bookmarks



commit ceb3fecd117293387547c284e8294e4cddaa8f17
Author: William Jon McCann <jmccann redhat com>
Date:   Fri Apr 27 12:57:50 2012 -0400

    Migrate to XDG config dir for bookmarks
    
    Will read from old location if new location isn't found but will
    write it out to the new location.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=646631

 gtk/gtkfilesystem.c |   51 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 42 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkfilesystem.c b/gtk/gtkfilesystem.c
index ae2840c..05ab5a1 100644
--- a/gtk/gtkfilesystem.c
+++ b/gtk/gtkfilesystem.c
@@ -207,7 +207,7 @@ _gtk_file_system_class_init (GtkFileSystemClass *class)
 }
 
 static GFile *
-get_bookmarks_file (void)
+get_legacy_bookmarks_file (void)
 {
   GFile *file;
   gchar *filename;
@@ -219,6 +219,19 @@ get_bookmarks_file (void)
   return file;
 }
 
+static GFile *
+get_bookmarks_file (void)
+{
+  GFile *file;
+  gchar *filename;
+
+  filename = g_build_filename (g_get_user_config_dir (), "gtk-3.0", "bookmarks", NULL);
+  file = g_file_new_for_path (filename);
+  g_free (filename);
+
+  return file;
+}
+
 static GSList *
 read_bookmarks (GFile *file)
 {
@@ -269,6 +282,8 @@ save_bookmarks (GFile  *bookmarks_file,
   GError *error = NULL;
   GString *contents;
   GSList *l;
+  GFile *parent_file;
+  gchar *path;
 
   contents = g_string_new ("");
 
@@ -290,16 +305,22 @@ save_bookmarks (GFile  *bookmarks_file,
       g_free (uri);
     }
 
-  if (!g_file_replace_contents (bookmarks_file,
-				contents->str,
-				strlen (contents->str),
-				NULL, FALSE, 0, NULL,
-				NULL, &error))
+  parent_file = g_file_get_parent (bookmarks_file);
+  path = g_file_get_path (parent_file);
+  if (g_mkdir_with_parents (path, 0700) == 0)
     {
-      g_critical ("%s", error->message);
-      g_error_free (error);
+      if (!g_file_replace_contents (bookmarks_file,
+                                    contents->str,
+                                    strlen (contents->str),
+                                    NULL, FALSE, 0, NULL,
+                                    NULL, &error))
+        {
+          g_critical ("%s", error->message);
+          g_error_free (error);
+        }
     }
-
+  g_free (path);
+  g_object_unref (parent_file);
   g_string_free (contents, TRUE);
 }
 
@@ -547,6 +568,18 @@ _gtk_file_system_init (GtkFileSystem *file_system)
   /* Bookmarks */
   bookmarks_file = get_bookmarks_file ();
   priv->bookmarks = read_bookmarks (bookmarks_file);
+  if (!priv->bookmarks)
+    {
+      GFile *legacy_bookmarks_file;
+
+      /* Read the legacy one and write it to the new one */
+      legacy_bookmarks_file = get_legacy_bookmarks_file ();
+      priv->bookmarks = read_bookmarks (legacy_bookmarks_file);
+      save_bookmarks (bookmarks_file, priv->bookmarks);
+
+      g_object_unref (legacy_bookmarks_file);
+    }
+
   priv->bookmarks_monitor = g_file_monitor_file (bookmarks_file,
 						 G_FILE_MONITOR_NONE,
 						 NULL, &error);



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