[file-roller] use g_get_user_config_dir instead of using .gnome2



commit 7fd220a834f16b260da8f5ddc1250c43b9dbefd8
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Nov 1 19:52:04 2010 +0100

    use g_get_user_config_dir instead of using .gnome2
    
    ...and provide an automatic migration mechanism.
    
    [bug #522812]

 src/dlg-add-folder.c |    8 ++++----
 src/file-utils.c     |   23 +++++++++++++++++++++++
 src/file-utils.h     |    2 ++
 src/main.c           |   42 +++++++++++++++++++++++++++---------------
 src/typedefs.h       |    9 +--------
 5 files changed, 57 insertions(+), 27 deletions(-)
---
diff --git a/src/dlg-add-folder.c b/src/dlg-add-folder.c
index 258466e..528370c 100644
--- a/src/dlg-add-folder.c
+++ b/src/dlg-add-folder.c
@@ -444,7 +444,7 @@ dlg_add_folder_load_options (DialogData *data,
 	gboolean   recursive;
 	gboolean   no_symlinks;
 
-	options_dir = get_home_relative_file (RC_OPTIONS_DIR);
+	options_dir = get_user_config_subdirectory (ADD_FOLDER_OPTIONS_DIR, TRUE);
 	options_file = g_file_get_child (options_dir, name);
 	file_path = g_file_get_path (options_file);
 	key_file = g_key_file_new ();
@@ -705,7 +705,7 @@ aod_update_option_list (LoadOptionsDialogData *aod_data)
 
 	gtk_list_store_clear (list_store);
 
-	options_dir = get_home_relative_file (RC_OPTIONS_DIR);
+	options_dir = get_user_config_subdirectory (ADD_FOLDER_OPTIONS_DIR, TRUE);
 	make_directory_tree (options_dir, 0700, NULL);
 
 	file_enum = g_file_enumerate_children (options_dir, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &err);
@@ -767,7 +767,7 @@ aod_remove_cb (GtkWidget             *widget,
 	gtk_tree_model_get (aod_data->aod_model, &iter, 1, &filename, -1);
 	gtk_list_store_remove (GTK_LIST_STORE (aod_data->aod_model), &iter);
 
-	options_dir = get_home_relative_file (RC_OPTIONS_DIR);
+	options_dir = get_user_config_subdirectory (ADD_FOLDER_OPTIONS_DIR, TRUE);
 	options_file = g_file_get_child (options_dir, filename);
 	if (! g_file_delete (options_file, NULL, &error)) {
 		g_warning ("could not delete the options: %s", error->message);
@@ -874,7 +874,7 @@ save_options_cb (GtkWidget  *w,
 	GFile *options_file;
 	char  *opt_filename;
 
-	options_dir = get_home_relative_file (RC_OPTIONS_DIR);
+	options_dir = get_user_config_subdirectory (ADD_FOLDER_OPTIONS_DIR, TRUE);
 	make_directory_tree (options_dir, 0700, NULL);
 
 	opt_filename = _gtk_request_dialog_run (
diff --git a/src/file-utils.c b/src/file-utils.c
index 8140ad9..db98d88 100644
--- a/src/file-utils.c
+++ b/src/file-utils.c
@@ -1233,6 +1233,29 @@ get_home_relative_file (const char *partial_uri)
 }
 
 
+GFile *
+get_user_config_subdirectory (const char *child_name,
+			      gboolean    create_child)
+{
+	char   *full_path;
+	GFile  *file;
+	GError *error = NULL;
+
+	full_path = g_strconcat (g_get_user_config_dir (), "/", child_name, NULL);
+	file = g_file_new_for_path (full_path);
+	g_free (full_path);
+
+	if  (create_child && ! make_directory_tree (file, 0700, &error)) {
+		g_warning ("%s", error->message);
+		g_error_free (error);
+		g_object_unref (file);
+		file = NULL;
+	}
+
+	return file;
+}
+
+
 const char *
 remove_host_from_uri (const char *uri)
 {
diff --git a/src/file-utils.h b/src/file-utils.h
index 160af8a..7d38ff8 100644
--- a/src/file-utils.h
+++ b/src/file-utils.h
@@ -109,6 +109,8 @@ gboolean 	    is_program_available	 (const char *filename,
 const char *        get_home_uri                 (void);
 char *              get_home_relative_uri        (const char *partial_uri);
 GFile *             get_home_relative_file       (const char *partial_uri);
+GFile *             get_user_config_subdirectory (const char *child_name,
+						  gboolean    create_);
 const char *        remove_host_from_uri         (const char *uri);
 char *              get_uri_host                 (const char *uri);
 char *              get_uri_root                 (const char *uri);
diff --git a/src/main.c b/src/main.c
index 32a46e5..37d3000 100644
--- a/src/main.c
+++ b/src/main.c
@@ -824,29 +824,41 @@ fr_restore_session (EggSMClient *client)
 	}
 }
 
+
 static void
-prepare_app (void)
+migrate_options_directory (void)
 {
-	char        *uri;
-	char        *extract_to_uri = NULL;
-	char        *add_to_uri = NULL;
-	EggSMClient *client = NULL;
-
-	/* create the config dir if necessary. */
+	char *old_directory_path;
+	GFile *old_directory;
+	GFile *new_directory;
 
-	uri = get_home_relative_uri (RC_DIR);
+	old_directory_path = get_home_relative_path (".gnome2/file-roller/options");
+	old_directory = g_file_new_for_path (old_directory_path);
+	new_directory = get_user_config_subdirectory (ADD_FOLDER_OPTIONS_DIR, FALSE);
+	if (g_file_query_exists (old_directory, NULL) && ! g_file_query_exists (new_directory, NULL)) {
+		GFile *parent;
 
-	if (uri_is_file (uri)) { /* before the GConf port this was a file, now it's folder. */
-		GFile *file;
+		parent = g_file_get_parent (new_directory);
+		if (make_directory_tree (parent, 0700, NULL))
+			g_file_move (old_directory, new_directory, 0, NULL, NULL, NULL, NULL);
 
-		file = g_file_new_for_uri (uri);
-		g_file_delete (file, NULL, NULL);
-		g_object_unref (file);
+		g_object_unref (parent);
 	}
 
-	ensure_dir_exists (uri, 0700, NULL);
-	g_free (uri);
+	g_object_unref (new_directory);
+	g_object_unref (old_directory);
+	g_free (old_directory_path);
+}
+
+
+static void
+prepare_app (void)
+{
+	char        *extract_to_uri = NULL;
+	char        *add_to_uri = NULL;
+	EggSMClient *client = NULL;
 
+	migrate_options_directory ();
 	register_commands ();
 	compute_supported_archive_types ();
 
diff --git a/src/typedefs.h b/src/typedefs.h
index 0f7bb51..bfc6908 100644
--- a/src/typedefs.h
+++ b/src/typedefs.h
@@ -28,14 +28,7 @@
 
 #define MEGABYTE (1024 * 1024)
 
-#define RC_DIR              ".gnome2/file-roller"
-#define RC_BOOKMARKS_FILE   ".gnome2/file-roller/bookmarks"
-#define RC_RECENT_FILE      ".gnome2/file-roller/recents"
-#define RC_OPTIONS_DIR      ".gnome2/file-roller/options"
-
-#define OLD_RC_BOOKMARKS_FILE   ".file-roller/bookmarks"
-#define OLD_RC_RECENT_FILE      ".file-roller/recents"
-#define OLD_RC_OPTIONS_DIR      ".file-roller/options"
+#define ADD_FOLDER_OPTIONS_DIR  "file-roller/options"
 
 typedef enum { /*< skip >*/
 	FR_WINDOW_SORT_BY_NAME = 0,



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