]> git.0d.be Git - empathy.git/commitdiff
migrate configuration files to XDG config directory
authorFrédéric Péters <fpeters@0d.be>
Mon, 20 Jul 2009 17:13:37 +0000 (19:13 +0200)
committerFrédéric Péters <fpeters@0d.be>
Tue, 21 Jul 2009 15:37:22 +0000 (17:37 +0200)
src/empathy.c

index aef36105299befdf2b90079ea6217e08e3e28e35..ea14c4da907e8db03c00ba473164834659124851 100644 (file)
@@ -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 */