[epiphany] Save state of web apps in their own gsettings path



commit 9e305eb9b9dfb59f450d15438a9bbf8c6a3c8639
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Tue Jan 31 15:24:46 2017 +0100

    Save state of web apps in their own gsettings path
    
    Make the org.gnome.Epiphany.state schema relocatable and set a specific
    path for web apps, or use the default one otherwise. This ensures that
    web apps don't write their window geometry to the general settings and
    every web app can have its own geometry no matter what window was last
    closed.

 data/org.gnome.epiphany.gschema.xml |    2 +-
 lib/ephy-settings.c                 |   38 ++++++++++++++++++++++++++++------
 lib/ephy-settings.h                 |    3 ++
 src/ephy-main.c                     |   13 ++++++++++++
 4 files changed, 48 insertions(+), 8 deletions(-)
---
diff --git a/data/org.gnome.epiphany.gschema.xml b/data/org.gnome.epiphany.gschema.xml
index 6654dad..36d0eaf 100644
--- a/data/org.gnome.epiphany.gschema.xml
+++ b/data/org.gnome.epiphany.gschema.xml
@@ -191,7 +191,7 @@
                         <description>List of URLs with filter rules to be used by the adblock.</description>
                 </key>
        </schema>
-       <schema path="/org/gnome/epiphany/state/" id="org.gnome.Epiphany.state">
+       <schema id="org.gnome.Epiphany.state">
                <key type="s" name="download-dir">
                        <default>'Downloads'</default>
                        <summary>The downloads folder</summary>
diff --git a/lib/ephy-settings.c b/lib/ephy-settings.c
index f8bfad7..b8d4d27 100644
--- a/lib/ephy-settings.c
+++ b/lib/ephy-settings.c
@@ -29,6 +29,17 @@
 
 static GHashTable *settings = NULL;
 
+static void
+ensure_settings (void)
+{
+  if (settings)
+    return;
+
+  settings = g_hash_table_new_full (g_str_hash,
+                                    g_str_equal, g_free,
+                                    g_object_unref);
+}
+
 void
 ephy_settings_shutdown (void)
 {
@@ -43,22 +54,35 @@ ephy_settings_get (const char *schema)
 {
   GSettings *gsettings = NULL;
 
-  if (settings == NULL) {
-    settings = g_hash_table_new_full (g_str_hash,
-                                      g_str_equal, g_free,
-                                      g_object_unref);
-  }
+  ensure_settings ();
 
   gsettings = g_hash_table_lookup (settings, schema);
 
   if (gsettings == NULL) {
     gsettings = g_settings_new (schema);
-
     if (gsettings == NULL)
-      g_warning ("Invalid schema requested");
+      g_warning ("Invalid schema %s requested", schema);
     else
       g_hash_table_insert (settings, g_strdup (schema), gsettings);
   }
 
   return gsettings;
 }
+
+void
+ephy_settings_ensure_schema_for_path (const char *schema,
+                                      const char *path)
+{
+  GSettings *gsettings;
+
+  ensure_settings ();
+
+  if (g_hash_table_lookup (settings, schema))
+    return;
+
+  gsettings = g_settings_new_with_path (schema, path);
+  if (gsettings == NULL)
+    g_warning ("Invalid schema %s requested for path %s", schema, path);
+  else
+    g_hash_table_insert (settings, g_strdup (schema), gsettings);
+}
diff --git a/lib/ephy-settings.h b/lib/ephy-settings.h
index 23d80d3..397aef2 100644
--- a/lib/ephy-settings.h
+++ b/lib/ephy-settings.h
@@ -35,6 +35,9 @@ G_BEGIN_DECLS
 
 GSettings *ephy_settings_get (const char *schema);
 
+void ephy_settings_ensure_schema_for_path (const char *schema,
+                                           const char *path);
+
 void ephy_settings_shutdown (void);
 
 G_END_DECLS
diff --git a/src/ephy-main.c b/src/ephy-main.c
index 2d5f843..9a441e5 100644
--- a/src/ephy-main.c
+++ b/src/ephy-main.c
@@ -380,6 +380,19 @@ main (int   argc,
     exit (0);
   }
 
+  /* Setup relocatable schemas */
+  if (application_mode) {
+    char *web_app_name;
+    char *path;
+
+    web_app_name = g_path_get_basename (profile_directory);
+    path = g_build_path ("/", "/org/gnome/epiphany/web-apps/", web_app_name, "state/", NULL);
+    ephy_settings_ensure_schema_for_path (EPHY_PREFS_STATE_SCHEMA, path);
+    g_free (web_app_name);
+    g_free (path);
+  } else
+    ephy_settings_ensure_schema_for_path (EPHY_PREFS_STATE_SCHEMA, "/org/gnome/epiphany/state/");
+
   startup_flags = get_startup_flags ();
 
   /* Now create the shell */


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