[empathy] migrate configuration files to XDG config directory



commit 6fa59ef0e20828af6404821b198468ae3a9ef158
Author: Frédéric Péters <fpeters 0d be>
Date:   Mon Jul 20 19:13:37 2009 +0200

    migrate configuration files to XDG config directory

 src/empathy.c |   63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)
---
diff --git a/src/empathy.c b/src/empathy.c
index aef3610..ea14c4d 100644
--- a/src/empathy.c
+++ b/src/empathy.c
@@ -321,6 +321,67 @@ create_salut_account (void)
 	g_object_unref (book);
 }
 
+static void
+migrate_config_to_xdg_dir (void)
+{
+	gchar *xdg_dir, *old_dir, *xdg_filename, *old_filename;
+	int i;
+	GFile *xdg_file, *old_file;
+	static const gchar* filenames[] = {
+		"geometry.ini",
+		"irc-networks.xml",
+		"chatrooms.xml",
+		"contact-groups.xml",
+		"status-presets.xml",
+		"accels.txt",
+		NULL
+	};
+
+	xdg_dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
+	if (g_file_test (xdg_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
+		/* xdg config dir already exists */
+		g_free (xdg_dir);
+		return;
+	}
+
+	old_dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
+	if (!g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
+		/* old config dir didn't exist */
+		g_free (xdg_dir);
+		g_free (old_dir);
+		return;
+	}
+
+	if (g_mkdir_with_parents (xdg_dir, (S_IRUSR | S_IWUSR | S_IXUSR)) == -1) {
+		DEBUG ("Failed to create configuration directory; aborting migration");
+		g_free (xdg_dir);
+		g_free (old_dir);
+		return;
+	}
+
+	for (i = 0; filenames[i]; i++) {
+		old_filename = g_build_filename (old_dir, filenames[i], NULL);
+		if (!g_file_test (old_filename, G_FILE_TEST_EXISTS)) {
+			g_free (old_filename);
+			continue;
+		}
+		xdg_filename = g_build_filename (xdg_dir, filenames[i], NULL);
+		old_file = g_file_new_for_path (old_filename);
+		xdg_file = g_file_new_for_path (xdg_filename);
+		if (!g_file_move (old_file, xdg_file, G_FILE_COPY_NONE,
+				  NULL, NULL, NULL, NULL)) {
+			DEBUG ("Failed to migrate %s", filenames[i]);
+		}
+		g_free (old_filename);
+		g_free (xdg_filename);
+		g_object_unref (old_file);
+		g_object_unref (xdg_file);
+	}
+
+	g_free (xdg_dir);
+	g_free (old_dir);
+}
+
 /* The code that handles single-instance and startup notification is
  * copied from gedit.
  *
@@ -637,6 +698,8 @@ main (int argc, char *argv[])
 		empathy_idle_set_state (idle, MC_PRESENCE_AVAILABLE);
 	}
 
+	
+	migrate_config_to_xdg_dir ();
 	create_salut_account ();
 
 	/* Setting up UI */



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