[eog] Add code for migrating config and cache file to XDG folders



commit c92e86a6e9816ac5a5a1a97ac6786a06aed9cb81
Author: Sebastian Geiger <sbastig invisco de>
Date:   Sat Aug 21 12:44:48 2010 +0200

    Add code for migrating config and cache file to XDG folders
    
    Move files from old config dir into XDG-based config folder.
    Part of bug 522806.

 src/eog-application.c |   33 +++++++++++++++++++++++++--------
 src/eog-util.c        |   32 ++++++++++++++++++++++++++++----
 2 files changed, 53 insertions(+), 12 deletions(-)
---
diff --git a/src/eog-application.c b/src/eog-application.c
index 9dce772..bc291d5 100644
--- a/src/eog-application.c
+++ b/src/eog-application.c
@@ -39,6 +39,7 @@
 #include <string.h>
 #include <glib.h>
 #include <glib/gi18n.h>
+#include <glib/gstdio.h>
 #include <glib-object.h>
 #include <gtk/gtk.h>
 
@@ -543,22 +544,38 @@ eog_application_screensaver_disable (EogApplication *application)
 static void
 eog_application_load_accelerators (void)
 {
-	gchar *accelfile = g_build_filename (g_get_user_cache_dir (),
-                        "eog",
-					     "eog", NULL);
+	// compat with the previous version
+	gchar *old_filename = g_build_filename (g_get_home_dir (), ".gnome",
+						"accel", "eog", NULL);
+	gchar *path = g_build_filename (g_get_user_config_dir (), "eog", NULL);
+	gchar *accelfile = g_build_filename (path, "accels", NULL);
+
+	if (g_file_test (old_filename, G_FILE_TEST_IS_REGULAR)) {
+		if(!g_file_test (path, G_FILE_TEST_IS_DIR)) {
+			g_mkdir (path, 0700);
+		}
+		/* move file to ~/.config/eog/accels if its not already there */
+		if(!g_file_test (accelfile, G_FILE_TEST_EXISTS))
+			g_rename (old_filename, accelfile);
+	}
 	/* gtk_accel_map_load does nothing if the file does not exist */
 	gtk_accel_map_load (accelfile);
+
+	g_free(old_filename);
+	g_free(path);
 	g_free (accelfile);
 }
 
 static void
 eog_application_save_accelerators (void)
 {
-	gchar *path = g_build_filename(g_get_user_cache_dir (), "eog");
-    if(!g_file_test(path, G_FILE_TEST_IS_DIR))
- 	   g_mkdir(path, 0700);
-    gchar *accelfile = g_build_filename (path,
-					     "eog", NULL);
+	gchar *path = g_build_filename(g_get_user_config_dir (), "eog", NULL);
+
+	if(!g_file_test(path, G_FILE_TEST_IS_DIR))
+		g_mkdir(path, 0700);
+
+	/* save to XDG_CONFIG_HOME/eog/accels */
+	gchar *accelfile = g_build_filename (path, "accels", NULL);
 	gtk_accel_map_save (accelfile);
 	g_free (accelfile);
 }
diff --git a/src/eog-util.c b/src/eog-util.c
index 9e72c9d..1c08bdc 100644
--- a/src/eog-util.c
+++ b/src/eog-util.c
@@ -255,11 +255,35 @@ eog_util_dot_dir (void)
 		gboolean exists;
 
 		dot_dir = g_build_filename (g_get_user_config_dir (),
-					    "eog",
-					    NULL);
-
+					    "eog", NULL);
+		gchar* old_dir = g_build_filename (g_get_home_dir (), ".gnome2",
+						   "eog", NULL);
+
+		if(g_file_test (old_dir, G_FILE_TEST_IS_DIR)) {
+			/* new config directory does not exist yet */
+			if(!g_file_test (dot_dir, G_FILE_TEST_IS_DIR)) {
+			g_rename(old_dir, dot_dir);
+			} else {
+				//it exists we need to move files one by one
+				GDir* dir = g_dir_open (old_dir, 0, NULL);
+				if (dir != NULL) {
+					gchar* filename; //dont free this
+					while (filename = (gchar*) g_dir_read_name (dir))
+					{
+						gchar* old_filename = g_build_filename(old_dir, filename, NULL);
+						gchar* new_filename = g_build_filename(dot_dir, filename, NULL);
+						if(!g_file_test (new_filename, G_FILE_TEST_EXISTS))
+							g_rename (old_filename, new_filename);
+						else {} // maybe inform the user that there are duplicated files, show a dialog?
+						g_free (old_filename);
+						g_free (new_filename);
+					}
+					g_dir_close(dir);
+				}
+			}
+		}
+		g_free(old_dir);
 		exists = ensure_dir_exists (dot_dir);
-
 		if (G_UNLIKELY (!exists)) {
 			static gboolean printed_warning = FALSE;
 



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