From 10d6972d37355198a63309142ae9875fdcc222f6 Mon Sep 17 00:00:00 2001 From: infirit Date: Wed, 19 Nov 2014 15:20:34 +0100 Subject: use g_get_user_config_dir instead of using .config/mate Also provide an automatic migration mechanism. Based on FR commit: 7fd220a834f16b260da8f5ddc1250c43b9dbefd8 From: Paolo Bacchilega --- src/dlg-add-folder.c | 8 ++++---- src/file-utils.c | 23 +++++++++++++++++++++++ src/file-utils.h | 2 ++ src/main.c | 40 +++++++++++++++++++++++++--------------- src/typedefs.h | 9 +-------- 5 files changed, 55 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/dlg-add-folder.c b/src/dlg-add-folder.c index cac8c7f..3eb4e91 100644 --- a/src/dlg-add-folder.c +++ b/src/dlg-add-folder.c @@ -451,7 +451,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 (); @@ -712,7 +712,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); @@ -774,7 +774,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); @@ -881,7 +881,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 3b33480..7e1f170 100644 --- a/src/file-utils.c +++ b/src/file-utils.c @@ -1232,6 +1232,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 65b4beb..0c91199 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 94729a5..520f3df 100644 --- a/src/main.c +++ b/src/main.c @@ -833,28 +833,38 @@ 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; + char *old_directory_path; + GFile *old_directory; + GFile *new_directory; - /* create the config dir if necessary. */ + old_directory_path = get_home_relative_path (".config/mate/engrampa/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; - uri = get_home_relative_uri (RC_DIR); + 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); - if (uri_is_file (uri)) { /* before the MateConf port this was a file, now it's folder. */ - GFile *file; - - 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 56660b5..8e687de 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -28,14 +28,7 @@ #define MEGABYTE (1024 * 1024) -#define RC_DIR ".config/mate/engrampa" -#define RC_BOOKMARKS_FILE ".config/mate/engrampa/bookmarks" -#define RC_RECENT_FILE ".config/mate/engrampa/recents" -#define RC_OPTIONS_DIR ".config/mate/engrampa/options" - -#define OLD_RC_BOOKMARKS_FILE ".engrampa/bookmarks" -#define OLD_RC_RECENT_FILE ".engrampa/recents" -#define OLD_RC_OPTIONS_DIR ".engrampa/options" +#define ADD_FOLDER_OPTIONS_DIR "engrampa/options" typedef enum { /*< skip >*/ FR_WINDOW_SORT_BY_NAME = 0, -- cgit v1.2.1