aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@0d.be>2009-07-21 01:13:37 +0800
committerFrédéric Péters <fpeters@0d.be>2009-07-21 23:37:22 +0800
commit6fa59ef0e20828af6404821b198468ae3a9ef158 (patch)
treee4ac34ed861221b429a64dc4e0365b6019384016
parente1fa17399fc137a508f195aa6976b5f32189de96 (diff)
downloadgsoc2013-empathy-6fa59ef0e20828af6404821b198468ae3a9ef158.tar
gsoc2013-empathy-6fa59ef0e20828af6404821b198468ae3a9ef158.tar.gz
gsoc2013-empathy-6fa59ef0e20828af6404821b198468ae3a9ef158.tar.bz2
gsoc2013-empathy-6fa59ef0e20828af6404821b198468ae3a9ef158.tar.lz
gsoc2013-empathy-6fa59ef0e20828af6404821b198468ae3a9ef158.tar.xz
gsoc2013-empathy-6fa59ef0e20828af6404821b198468ae3a9ef158.tar.zst
gsoc2013-empathy-6fa59ef0e20828af6404821b198468ae3a9ef158.zip
migrate configuration files to XDG config directory
-rw-r--r--src/empathy.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/empathy.c b/src/empathy.c
index aef361052..ea14c4da9 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 */