[epiphany/wip/tingping/profile-migration: 58/58] Store web extension settings in config dir



commit 55b6e27c3d069482b771c3c2db8d4ad6ade68690
Author: Patrick Griffis <pgriffis igalia com>
Date:   Mon Dec 24 09:38:17 2018 -0500

    Store web extension settings in config dir

 lib/ephy-file-helpers.c | 37 +++++++++++++++++++++++++++++++++++++
 lib/ephy-file-helpers.h |  2 ++
 lib/ephy-settings.c     |  2 +-
 3 files changed, 40 insertions(+), 1 deletion(-)
---
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index 06b88fddd..4dc88ede9 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -70,6 +70,7 @@ static GHashTable *mime_table;
 static gboolean keep_directory;
 static char *profile_dir_global;
 static char *cache_dir;
+static char *config_dir;
 static char *tmp_dir;
 static GList *del_on_exit;
 static EphyProfileDirType profile_dir_type;
@@ -234,6 +235,20 @@ ephy_profile_dir (void)
   return profile_dir_global;
 }
 
+/**
+ * ephy_config_dir:
+ *
+ * Gets Epiphany's configuration directory, usually .config/epiphany
+ * under user's homedir.
+ *
+ * Returns: the full path to Epiphany's configuration directory
+ **/
+const char *
+ephy_config_dir (void)
+{
+  return config_dir;
+}
+
 /**
  * ephy_cache_dir:
  *
@@ -306,6 +321,21 @@ ephy_default_cache_dir (void)
     g_build_filename (g_get_user_cache_dir (), "epiphany", NULL);
 }
 
+/**
+ * ephy_default_config_dir:
+ *
+ * Get the path to the default config directory found in ~/.config
+ *
+ * Returns: a new allocated string, free with g_free() when done.
+ */
+char *
+ephy_default_config_dir (void)
+{
+  return profile_dir_type == EPHY_PROFILE_DIR_TEST ?
+    g_build_filename (ephy_profile_dir (), "config", NULL) :
+    g_build_filename (g_get_user_config_dir (), "epiphany", NULL);
+}
+
 /**
  * ephy_file_helpers_init:
  * @profile_dir: directory to use as Epiphany's profile
@@ -350,6 +380,7 @@ ephy_file_helpers_init (const char          *profile_dir,
     if (g_file_test (app_file, G_FILE_TEST_EXISTS)) {
       const char *app_name = ephy_web_application_get_program_name_from_profile_directory 
(profile_dir_global);
       cache_dir = g_build_filename (g_get_user_cache_dir (), app_name, NULL);
+      config_dir = g_build_filename (g_get_user_config_dir (), app_name, NULL);
       profile_dir_type = EPHY_PROFILE_DIR_WEB_APP;
     }
   } else if (private_profile) {
@@ -366,6 +397,7 @@ ephy_file_helpers_init (const char          *profile_dir,
                                            "epiphany",
                                            NULL);
     cache_dir = g_build_filename (profile_dir_global, "cache", NULL);
+    config_dir = g_build_filename (profile_dir_global, "config", NULL);
     if (flags & EPHY_FILE_HELPERS_TESTING_MODE)
       profile_dir_type = EPHY_PROFILE_DIR_TEST;
   }
@@ -378,9 +410,13 @@ ephy_file_helpers_init (const char          *profile_dir,
   if (cache_dir == NULL)
     cache_dir = ephy_default_cache_dir ();
 
+  if (config_dir == NULL)
+    config_dir = ephy_default_config_dir ();
+
   if (flags & EPHY_FILE_HELPERS_ENSURE_EXISTS) {
     ret = ephy_ensure_dir_exists (ephy_profile_dir (), error);
     ephy_ensure_dir_exists (ephy_cache_dir (), NULL);
+    ephy_ensure_dir_exists (ephy_config_dir (), NULL);
   }
 
   if (steal_data_from_profile && profile_dir) {
@@ -452,6 +488,7 @@ ephy_file_helpers_shutdown (void)
 
   g_clear_pointer (&profile_dir_global, g_free);
   g_clear_pointer (&cache_dir, g_free);
+  g_clear_pointer (&config_dir, g_free);
 
   if (tmp_dir != NULL) {
     if (!keep_directory) {
diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h
index b91dda20b..40cfb2402 100644
--- a/lib/ephy-file-helpers.h
+++ b/lib/ephy-file-helpers.h
@@ -55,8 +55,10 @@ const char *       ephy_profile_dir                         (void);
 gboolean           ephy_profile_dir_is_default              (void);
 gboolean           ephy_profile_dir_is_web_application      (void);
 const char *       ephy_cache_dir                           (void);
+const char *       ephy_config_dir                          (void);
 char       *       ephy_default_profile_dir                 (void);
 char       *       ephy_default_cache_dir                   (void);
+char       *       ephy_default_config_dir                  (void);
 void               ephy_file_helpers_shutdown               (void);
 char       *       ephy_file_get_downloads_dir              (void);
 char       *       ephy_file_desktop_dir                    (void);
diff --git a/lib/ephy-settings.c b/lib/ephy-settings.c
index 917eabba8..e39b29b61 100644
--- a/lib/ephy-settings.c
+++ b/lib/ephy-settings.c
@@ -195,7 +195,7 @@ ephy_settings_get_for_web_extension (const char *schema)
       return gsettings;
     }
 
-    g_autofree char *keyfile_path = g_build_filename (ephy_profile_dir (), "web-extension-settings.ini", 
NULL);
+    g_autofree char *keyfile_path = g_build_filename (ephy_config_dir (), "web-extension-settings.ini", 
NULL);
     backend = g_keyfile_settings_backend_new (keyfile_path, "/", "/");
 
     GSettings *web_gsettings;


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