[epiphany] Allow to have different settings in web applications



commit 7f065b1ca5bcc551253744437649dc317b6d1f46
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Sat Feb 4 11:00:59 2017 +0100

    Allow to have different settings in web applications
    
    Make org.gnome.Epiphany.web schema relocatable to be used by web apps.
    Settings in org.gnome.Epiphany.web schema are now per web app, allowing
    users to have different settings in the main epiphany instance and in
    every web applications installed. Newly created web apps inherit the
    settings from the main instance. To make this possible I also had to
    move some of the settings:
    
     - user-agent, remember-passwords and enable-smooth-scrolling has been
       moved from the main schema to web. The profile migrator will copy the
       values from the main schema to the web one. Settings are not actually
       moved, but copied marking the old ones as deprecated.
    
     - adblock-filters has been moved from web to main schema, because it's
       actually shared, web apps use the default profile filters. This is
       not migrated because it's very recent setting and probably everybody
       is using the default value anyway since it's not exposed in the UI
       yet.
    
    When the profile migrator is run for the main ephy instance, we simply
    copy the values of the deprecated settings to its new location. When
    it's run for a web app we copy the settings from the main profile. If
    the migrator was not run for the main profile yet, we use the deprecated
    values instead. This way web apps will be ensured to have the same
    settings.
    The app menu for web applications includes now the preferences item to
    show the preferences dialog. The dialog is the same as the main one,
    but with with the global options hidden.
    This patch also removes ephy_settings_ensure_schema_for_path() and
    relocatable schemas are configured automatically based on the current
    profile dir, making it less error prone.

 data/org.gnome.epiphany.gschema.xml          |   42 ++++++++--
 embed/ephy-embed-prefs.c                     |    8 +-
 embed/web-extension/ephy-uri-tester.c        |    6 +-
 embed/web-extension/ephy-web-extension.c     |    2 +-
 lib/ephy-filters-manager.c                   |    4 +-
 lib/ephy-prefs.h                             |  116 ++++++++++++++++++--------
 lib/ephy-profile-utils.h                     |    3 +-
 lib/ephy-settings.c                          |   50 +++++++-----
 lib/ephy-settings.h                          |    3 -
 lib/ephy-web-app-utils.c                     |   48 +++++++++++
 lib/ephy-web-app-utils.h                     |    2 +
 src/ephy-main.c                              |   13 ---
 src/ephy-shell.c                             |    1 +
 src/prefs-dialog.c                           |   43 +++++++---
 src/profile-migrator/ephy-profile-migrator.c |   85 ++++++++++++++++++-
 src/resources/gtk/application-menu.ui        |    7 ++
 src/resources/gtk/prefs-dialog.ui            |   16 ++--
 tests/ephy-encodings-test.c                  |    2 -
 tests/ephy-file-helpers-test.c               |    2 -
 19 files changed, 337 insertions(+), 116 deletions(-)
---
diff --git a/data/org.gnome.epiphany.gschema.xml b/data/org.gnome.epiphany.gschema.xml
index 4c0208c..32ea34d 100644
--- a/data/org.gnome.epiphany.gschema.xml
+++ b/data/org.gnome.epiphany.gschema.xml
@@ -30,7 +30,11 @@
                <key type="s" name="user-agent">
                        <default>''</default>
                        <summary>User agent</summary>
-                       <description>String that will be used as user agent, to identify the browser to the 
web servers.</description>
+                       <description>
+                          String that will be used as user agent, to identify the browser to the web servers.
+
+                          DEPRECATED: This key is deprecated and ignored. Use 
/org/gnome/epiphany/web/user-agent instead.
+                        </description>
                </key>
                <key type="b" name="automatic-downloads">
                        <default>false</default>
@@ -45,7 +49,11 @@
                <key type="b" name="remember-passwords">
                        <default>true</default>
                        <summary>Remember passwords</summary>
-                       <description>Whether to store and prefill passwords in websites.</description>
+                       <description>
+                          Whether to store and prefill passwords in websites.
+
+                          DEPRECATED: This key is deprecated and ignored. Use 
/org/gnome/epiphany/web/remember-passwords instead.
+                        </description>
                </key>
                <key type="b" name="warn-on-close-unsubmitted-data">
                        <default>true</default>
@@ -53,6 +61,9 @@
                <key type="b" name="enable-smooth-scrolling">
                        <default>false</default>
                        <summary>Enable smooth scrolling</summary>
+                        <description>
+                          DEPRECATED: This key is deprecated and ignored. Use 
/org/gnome/epiphany/web/enable-smooth-scrolling instead.
+                        </description>
                </key>
                <key type="b" name="internal-view-source">
                        <default>true</default>
@@ -89,6 +100,11 @@
                        <summary>Sync timestamp</summary>
                        <description>The timestamp at which last we had the last sync</description>
                </key>
+                <key type="as" name="adblock-filters">
+                        <default>['https://easylist.to/easylist/easylist.txt', 
'https://easylist.to/easylist/easyprivacy.txt']</default>
+                        <summary>List of adblock filters</summary>
+                        <description>List of URLs with filter rules to be used by the adblock.</description>
+                </key>
        </schema>
        <schema path="/org/gnome/epiphany/ui/" id="org.gnome.Epiphany.ui">
                <key type="b" name="expand-tabs-bar">
@@ -107,7 +123,7 @@
                        <description>Controls when the tabs bar is shown. Possible values are “always” (the 
tabs bar is always shown), “more-than-one” (the tabs bar is only shown if there’s two or more tabs) and 
“never” (the tabs bar is never shown).</description>
                </key>
        </schema>
-       <schema path="/org/gnome/epiphany/web/" id="org.gnome.Epiphany.web">
+       <schema id="org.gnome.Epiphany.web">
                <key type="i" name="min-font-size">
                        <default>0</default>
                        <summary>Minimum font size</summary>
@@ -176,6 +192,16 @@
                        <summary>Enable WebAudio</summary>
                        <description>Whether to enable support for WebAudio.</description>
                </key>
+               <key type="b" name="enable-smooth-scrolling">
+                       <default>false</default>
+                       <summary>Enable smooth scrolling</summary>
+                        <description>Whether to enable smooth scrolling.</description>
+               </key>
+               <key type="s" name="user-agent">
+                       <default>''</default>
+                       <summary>User agent</summary>
+                       <description>String that will be used as user agent, to identify the browser to the 
web servers.</description>
+               </key>
                <key type="b" name="do-not-track">
                        <default>true</default>
                        <summary>Do Not Track</summary>
@@ -186,11 +212,11 @@
                        <summary>Enable adblock</summary>
                        <description>Whether to block the embedded advertisements that web pages might want 
to show.</description>
                </key>
-                <key type="as" name="adblock-filters">
-                        <default>['https://easylist.to/easylist/easylist.txt', 
'https://easylist.to/easylist/easyprivacy.txt']</default>
-                        <summary>List of adblock filters</summary>
-                        <description>List of URLs with filter rules to be used by the adblock.</description>
-                </key>
+               <key type="b" name="remember-passwords">
+                       <default>true</default>
+                       <summary>Remember passwords</summary>
+                       <description>Whether to store and prefill passwords in websites.</description>
+               </key>
        </schema>
        <schema id="org.gnome.Epiphany.state">
                <key type="s" name="download-dir">
diff --git a/embed/ephy-embed-prefs.c b/embed/ephy-embed-prefs.c
index 1f3b6fe..3db6ac8 100644
--- a/embed/ephy-embed-prefs.c
+++ b/embed/ephy-embed-prefs.c
@@ -542,8 +542,8 @@ static const PrefData webkit_pref_entries[] =
     EPHY_PREFS_WEB_LANGUAGE,
     "accept-language",
     webkit_pref_callback_accept_languages },
-  { EPHY_PREFS_SCHEMA,
-    EPHY_PREFS_USER_AGENT,
+  { EPHY_PREFS_WEB_SCHEMA,
+    EPHY_PREFS_WEB_USER_AGENT,
     "user-agent",
     webkit_pref_callback_user_agent },
   { EPHY_PREFS_WEB_SCHEMA,
@@ -617,8 +617,8 @@ ephy_embed_prefs_init (gpointer user_data)
                    EPHY_PREFS_WEB_ENABLE_WEBAUDIO,
                    webkit_settings, "enable-webaudio",
                    G_SETTINGS_BIND_GET);
-  g_settings_bind (EPHY_SETTINGS_MAIN,
-                   EPHY_PREFS_ENABLE_SMOOTH_SCROLLING,
+  g_settings_bind (EPHY_SETTINGS_WEB,
+                   EPHY_PREFS_WEB_ENABLE_SMOOTH_SCROLLING,
                    webkit_settings, "enable-smooth-scrolling",
                    G_SETTINGS_BIND_GET);
   return webkit_settings;
diff --git a/embed/web-extension/ephy-uri-tester.c b/embed/web-extension/ephy-uri-tester.c
index 6acfcc5..5415d51 100644
--- a/embed/web-extension/ephy-uri-tester.c
+++ b/embed/web-extension/ephy-uri-tester.c
@@ -683,7 +683,7 @@ ephy_uri_tester_begin_loading_adblock_filters (EphyUriTester  *tester,
 {
   char **filters;
 
-  filters = g_settings_get_strv (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_ADBLOCK_FILTERS);
+  filters = g_settings_get_strv (EPHY_SETTINGS_MAIN, EPHY_PREFS_ADBLOCK_FILTERS);
   tester->adblock_filters_to_load = g_strv_length (filters);
   for (guint i = 0; filters[i]; i++) {
     GFile *filter_file;
@@ -945,12 +945,12 @@ ephy_uri_tester_load (EphyUriTester *tester)
   g_task_run_in_thread_sync (task, (GTaskThreadFunc)ephy_uri_tester_load_sync);
   g_object_unref (task);
 
-  g_signal_connect (EPHY_SETTINGS_WEB, "changed::" EPHY_PREFS_WEB_ADBLOCK_FILTERS,
+  g_signal_connect (EPHY_SETTINGS_MAIN, "changed::" EPHY_PREFS_ADBLOCK_FILTERS,
                     G_CALLBACK (ephy_uri_tester_adblock_filters_changed_cb), tester);
   g_signal_connect (EPHY_SETTINGS_WEB, "changed::" EPHY_PREFS_WEB_ENABLE_ADBLOCK,
                     G_CALLBACK (ephy_uri_tester_enable_adblock_changed_cb), tester);
   /* GSettings never emits the changed signal until after we read the setting
    * the first time after connecting the handler... work around this.*/
-  trash = g_settings_get_strv (EPHY_SETTINGS_WEB, "adblock-filters");
+  trash = g_settings_get_strv (EPHY_SETTINGS_MAIN, EPHY_PREFS_ADBLOCK_FILTERS);
   g_strfreev (trash);
 }
diff --git a/embed/web-extension/ephy-web-extension.c b/embed/web-extension/ephy-web-extension.c
index e768ba0..ac0d1ff 100644
--- a/embed/web-extension/ephy-web-extension.c
+++ b/embed/web-extension/ephy-web-extension.c
@@ -1101,7 +1101,7 @@ web_page_form_controls_associated (WebKitWebPage    *web_page,
   guint i;
 
   if (!extension->form_auth_data_cache ||
-      !g_settings_get_boolean (EPHY_SETTINGS_MAIN, EPHY_PREFS_REMEMBER_PASSWORDS))
+      !g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_REMEMBER_PASSWORDS))
     return;
 
   document = webkit_web_page_get_dom_document (web_page);
diff --git a/lib/ephy-filters-manager.c b/lib/ephy-filters-manager.c
index 8067560..fcbcdc1 100644
--- a/lib/ephy-filters-manager.c
+++ b/lib/ephy-filters-manager.c
@@ -240,7 +240,7 @@ update_adblock_filter_files (EphyFiltersManager *manager)
   g_object_unref (manager->cancellable);
   manager->cancellable = g_cancellable_new ();
 
-  filters = g_settings_get_strv (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_ADBLOCK_FILTERS);
+  filters = g_settings_get_strv (EPHY_SETTINGS_MAIN, EPHY_PREFS_ADBLOCK_FILTERS);
   for (guint i = 0; filters[i]; i++) {
     GFile *filter_file;
 
@@ -303,7 +303,7 @@ ephy_filters_manager_constructed (GObject *object)
   G_OBJECT_CLASS (ephy_filters_manager_parent_class)->constructed (object);
 
   /* Note: up here because we must connect *before* reading the settings. */
-  g_signal_connect (EPHY_SETTINGS_WEB, "changed::" EPHY_PREFS_WEB_ADBLOCK_FILTERS,
+  g_signal_connect (EPHY_SETTINGS_MAIN, "changed::" EPHY_PREFS_ADBLOCK_FILTERS,
                     G_CALLBACK (adblock_filters_changed_cb), manager);
   g_signal_connect (EPHY_SETTINGS_WEB, "changed::" EPHY_PREFS_WEB_ENABLE_ADBLOCK,
                     G_CALLBACK (enable_adblock_changed_cb), manager);
diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h
index 12e3fc2..f3eb4e2 100644
--- a/lib/ephy-prefs.h
+++ b/lib/ephy-prefs.h
@@ -66,43 +66,79 @@ typedef enum
 #define EPHY_PREFS_STATE_SCHEMA                 "org.gnome.Epiphany.state"
 #define EPHY_PREFS_STATE_DOWNLOAD_DIR           "download-dir"
 #define EPHY_PREFS_STATE_RECENT_ENCODINGS       "recent-encodings"
+#define EPHY_PREFS_STATE_WINDOW_POSITION        "window-position"
+#define EPHY_PREFS_STATE_WINDOW_SIZE            "window-size"
+#define EPHY_PREFS_STATE_IS_MAXIMIZED           "is-maximized"
 
-#define EPHY_PREFS_WEB_SCHEMA                "org.gnome.Epiphany.web"
-#define EPHY_PREFS_WEB_FONT_MIN_SIZE         "min-font-size"
-#define EPHY_PREFS_WEB_LANGUAGE              "language"
-#define EPHY_PREFS_WEB_USE_GNOME_FONTS       "use-gnome-fonts"
-#define EPHY_PREFS_WEB_SANS_SERIF_FONT       "sans-serif-font"
-#define EPHY_PREFS_WEB_SERIF_FONT            "serif-font"
-#define EPHY_PREFS_WEB_MONOSPACE_FONT        "monospace-font"
-#define EPHY_PREFS_WEB_ENABLE_USER_CSS       "enable-user-css"
-#define EPHY_PREFS_WEB_ENABLE_POPUPS         "enable-popups"
-#define EPHY_PREFS_WEB_ENABLE_PLUGINS        "enable-plugins"
-#define EPHY_PREFS_WEB_ENABLE_SPELL_CHECKING "enable-spell-checking"
-#define EPHY_PREFS_WEB_ENABLE_WEBGL          "enable-webgl"
-#define EPHY_PREFS_WEB_ENABLE_WEBAUDIO       "enable-webaudio"
-#define EPHY_PREFS_WEB_COOKIES_POLICY        "cookies-policy"
-#define EPHY_PREFS_WEB_DEFAULT_ENCODING      "default-encoding"
-#define EPHY_PREFS_WEB_DO_NOT_TRACK          "do-not-track"
-#define EPHY_PREFS_WEB_ENABLE_ADBLOCK        "enable-adblock"
-#define EPHY_PREFS_WEB_ADBLOCK_FILTERS       "adblock-filters"
-
-#define EPHY_PREFS_SCHEMA                         "org.gnome.Epiphany"
-#define EPHY_PREFS_HOMEPAGE_URL                   "homepage-url"
-#define EPHY_PREFS_USER_AGENT                     "user-agent"
-#define EPHY_PREFS_NEW_WINDOWS_IN_TABS            "new-windows-in-tabs"
-#define EPHY_PREFS_AUTO_DOWNLOADS                 "automatic-downloads"
-#define EPHY_PREFS_WARN_ON_CLOSE_UNSUBMITTED_DATA "warn-on-close-unsubmitted-data"
-#define EPHY_PREFS_REMEMBER_PASSWORDS             "remember-passwords"
-#define EPHY_PREFS_KEYWORD_SEARCH_URL             "keyword-search-url"
-#define EPHY_PREFS_ENABLE_SMOOTH_SCROLLING        "enable-smooth-scrolling"
-#define EPHY_PREFS_ENABLE_CARET_BROWSING          "enable-caret-browsing"
-#define EPHY_PREFS_INTERNAL_VIEW_SOURCE           "internal-view-source"
-#define EPHY_PREFS_RESTORE_SESSION_POLICY         "restore-session-policy"
-#define EPHY_PREFS_RESTORE_SESSION_DELAYING_LOADS "restore-session-delaying-loads"
-#define EPHY_PREFS_PROCESS_MODEL                  "process-model"
-#define EPHY_PREFS_MAX_PROCESSES                  "max-processes"
-#define EPHY_PREFS_SYNC_USER                      "sync-user"
-#define EPHY_PREFS_SYNC_TIME                      "sync-time"
+static const char * const ephy_prefs_state_schema[] = {
+  EPHY_PREFS_STATE_DOWNLOAD_DIR,
+  EPHY_PREFS_STATE_RECENT_ENCODINGS,
+  EPHY_PREFS_STATE_WINDOW_POSITION,
+  EPHY_PREFS_STATE_WINDOW_SIZE,
+  EPHY_PREFS_STATE_IS_MAXIMIZED
+};
+
+#define EPHY_PREFS_WEB_SCHEMA                  "org.gnome.Epiphany.web"
+#define EPHY_PREFS_WEB_FONT_MIN_SIZE           "min-font-size"
+#define EPHY_PREFS_WEB_LANGUAGE                "language"
+#define EPHY_PREFS_WEB_USE_GNOME_FONTS         "use-gnome-fonts"
+#define EPHY_PREFS_WEB_SANS_SERIF_FONT         "sans-serif-font"
+#define EPHY_PREFS_WEB_SERIF_FONT              "serif-font"
+#define EPHY_PREFS_WEB_MONOSPACE_FONT          "monospace-font"
+#define EPHY_PREFS_WEB_ENABLE_USER_CSS         "enable-user-css"
+#define EPHY_PREFS_WEB_ENABLE_POPUPS           "enable-popups"
+#define EPHY_PREFS_WEB_ENABLE_PLUGINS          "enable-plugins"
+#define EPHY_PREFS_WEB_ENABLE_SPELL_CHECKING   "enable-spell-checking"
+#define EPHY_PREFS_WEB_ENABLE_WEBGL            "enable-webgl"
+#define EPHY_PREFS_WEB_ENABLE_WEBAUDIO         "enable-webaudio"
+#define EPHY_PREFS_WEB_ENABLE_SMOOTH_SCROLLING "enable-smooth-scrolling"
+#define EPHY_PREFS_WEB_USER_AGENT              "user-agent"
+#define EPHY_PREFS_WEB_COOKIES_POLICY          "cookies-policy"
+#define EPHY_PREFS_WEB_DEFAULT_ENCODING        "default-encoding"
+#define EPHY_PREFS_WEB_DO_NOT_TRACK            "do-not-track"
+#define EPHY_PREFS_WEB_ENABLE_ADBLOCK          "enable-adblock"
+#define EPHY_PREFS_WEB_REMEMBER_PASSWORDS      "remember-passwords"
+
+static const char * const ephy_prefs_web_schema[] = {
+  EPHY_PREFS_WEB_FONT_MIN_SIZE,
+  EPHY_PREFS_WEB_LANGUAGE,
+  EPHY_PREFS_WEB_USE_GNOME_FONTS,
+  EPHY_PREFS_WEB_SANS_SERIF_FONT,
+  EPHY_PREFS_WEB_SERIF_FONT,
+  EPHY_PREFS_WEB_MONOSPACE_FONT,
+  EPHY_PREFS_WEB_ENABLE_USER_CSS,
+  EPHY_PREFS_WEB_ENABLE_POPUPS,
+  EPHY_PREFS_WEB_ENABLE_PLUGINS,
+  EPHY_PREFS_WEB_ENABLE_SPELL_CHECKING,
+  EPHY_PREFS_WEB_ENABLE_WEBGL,
+  EPHY_PREFS_WEB_ENABLE_WEBAUDIO,
+  EPHY_PREFS_WEB_ENABLE_SMOOTH_SCROLLING,
+  EPHY_PREFS_WEB_USER_AGENT,
+  EPHY_PREFS_WEB_COOKIES_POLICY,
+  EPHY_PREFS_WEB_DEFAULT_ENCODING,
+  EPHY_PREFS_WEB_DO_NOT_TRACK,
+  EPHY_PREFS_WEB_ENABLE_ADBLOCK,
+  EPHY_PREFS_WEB_REMEMBER_PASSWORDS,
+};
+
+#define EPHY_PREFS_SCHEMA                             "org.gnome.Epiphany"
+#define EPHY_PREFS_HOMEPAGE_URL                       "homepage-url"
+#define EPHY_PREFS_DEPRECATED_USER_AGENT              "user-agent"
+#define EPHY_PREFS_NEW_WINDOWS_IN_TABS                "new-windows-in-tabs"
+#define EPHY_PREFS_AUTO_DOWNLOADS                     "automatic-downloads"
+#define EPHY_PREFS_WARN_ON_CLOSE_UNSUBMITTED_DATA     "warn-on-close-unsubmitted-data"
+#define EPHY_PREFS_DEPRECATED_REMEMBER_PASSWORDS      "remember-passwords"
+#define EPHY_PREFS_KEYWORD_SEARCH_URL                 "keyword-search-url"
+#define EPHY_PREFS_DEPRECATED_ENABLE_SMOOTH_SCROLLING "enable-smooth-scrolling"
+#define EPHY_PREFS_ENABLE_CARET_BROWSING              "enable-caret-browsing"
+#define EPHY_PREFS_INTERNAL_VIEW_SOURCE               "internal-view-source"
+#define EPHY_PREFS_RESTORE_SESSION_POLICY             "restore-session-policy"
+#define EPHY_PREFS_RESTORE_SESSION_DELAYING_LOADS     "restore-session-delaying-loads"
+#define EPHY_PREFS_PROCESS_MODEL                      "process-model"
+#define EPHY_PREFS_MAX_PROCESSES                      "max-processes"
+#define EPHY_PREFS_SYNC_USER                          "sync-user"
+#define EPHY_PREFS_SYNC_TIME                          "sync-time"
+#define EPHY_PREFS_ADBLOCK_FILTERS                    "adblock-filters"
 
 #define EPHY_PREFS_LOCKDOWN_SCHEMA            "org.gnome.Epiphany.lockdown"
 #define EPHY_PREFS_LOCKDOWN_FULLSCREEN        "disable-fullscreen"
@@ -113,4 +149,12 @@ typedef enum
 #define EPHY_PREFS_LOCKDOWN_PRINTING          "disable-printing"
 #define EPHY_PREFS_LOCKDOWN_QUIT              "disable-quit"
 
+static struct {
+  const char *schema;
+  const char *path;
+} const ephy_prefs_relocatable_schemas[] = {
+  { EPHY_PREFS_STATE_SCHEMA, "state/" },
+  { EPHY_PREFS_WEB_SCHEMA, "web/" },
+};
+
 G_END_DECLS
diff --git a/lib/ephy-profile-utils.h b/lib/ephy-profile-utils.h
index 9f00963..80a368a 100644
--- a/lib/ephy-profile-utils.h
+++ b/lib/ephy-profile-utils.h
@@ -24,8 +24,9 @@
 
 G_BEGIN_DECLS
 
-#define EPHY_PROFILE_MIGRATION_VERSION 15
+#define EPHY_PROFILE_MIGRATION_VERSION 16
 #define EPHY_INSECURE_PASSWORDS_MIGRATION_VERSION 11
+#define EPHY_SETTINGS_MIGRATION_VERSION 16
 
 #define EPHY_BOOKMARKS_FILE     "bookmarks.gvdb"
 #define EPHY_HISTORY_FILE       "ephy-history.db"
diff --git a/lib/ephy-settings.c b/lib/ephy-settings.c
index b8d4d27..0b84e08 100644
--- a/lib/ephy-settings.c
+++ b/lib/ephy-settings.c
@@ -19,10 +19,11 @@
  */
 
 #include "config.h"
-
 #include "ephy-settings.h"
 
 #include "ephy-debug.h"
+#include "ephy-file-helpers.h"
+#include "ephy-web-app-utils.h"
 
 #include <glib.h>
 #include <gio/gio.h>
@@ -30,14 +31,39 @@
 static GHashTable *settings = NULL;
 
 static void
-ensure_settings (void)
+ephy_settings_init (void)
 {
-  if (settings)
+  const char *profile_directory;
+  const char *web_app_name;
+  char *base_path;
+
+  if (settings != NULL)
     return;
 
+  profile_directory = ephy_dot_dir ();
+  if (!profile_directory)
+    g_error ("ephy-settings used before ephy_file_helpers_init");
+
   settings = g_hash_table_new_full (g_str_hash,
                                     g_str_equal, g_free,
                                     g_object_unref);
+
+  web_app_name = g_strrstr (profile_directory, EPHY_WEB_APP_PREFIX);
+  if (web_app_name)
+    base_path = g_build_path ("/", "/org/gnome/epiphany/web-apps/", web_app_name, NULL);
+  else
+    base_path = g_strdup ("/org/gnome/epiphany/");
+
+  for (guint i = 0; i < G_N_ELEMENTS (ephy_prefs_relocatable_schemas); i++) {
+    char *path;
+
+    path = g_build_path ("/", base_path, ephy_prefs_relocatable_schemas[i].path, NULL);
+    g_hash_table_insert (settings, g_strdup (ephy_prefs_relocatable_schemas[i].schema),
+                         g_settings_new_with_path (ephy_prefs_relocatable_schemas[i].schema, path));
+    g_free (path);
+  }
+
+  g_free (base_path);
 }
 
 void
@@ -54,7 +80,7 @@ ephy_settings_get (const char *schema)
 {
   GSettings *gsettings = NULL;
 
-  ensure_settings ();
+  ephy_settings_init ();
 
   gsettings = g_hash_table_lookup (settings, schema);
 
@@ -69,20 +95,4 @@ ephy_settings_get (const char *schema)
   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 397aef2..23d80d3 100644
--- a/lib/ephy-settings.h
+++ b/lib/ephy-settings.h
@@ -35,9 +35,6 @@ 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/lib/ephy-web-app-utils.c b/lib/ephy-web-app-utils.c
index 8287c8f..4e3b471 100644
--- a/lib/ephy-web-app-utils.c
+++ b/lib/ephy-web-app-utils.c
@@ -23,6 +23,7 @@
 
 #include "ephy-debug.h"
 #include "ephy-file-helpers.h"
+#include "ephy-prefs.h"
 
 #include <errno.h>
 #include <gio/gio.h>
@@ -290,6 +291,8 @@ ephy_web_application_create (const char *address, const char *name, GdkPixbuf *i
 
   /* Create the deskop file. */
   desktop_file_path = create_desktop_file (address, profile_dir, name, icon);
+  if (desktop_file_path)
+    ephy_web_application_initialize_settings (profile_dir);
 
  out:
   if (profile_dir)
@@ -567,3 +570,48 @@ ephy_web_application_exists (const char *name)
 
   return profile_exists;
 }
+
+void
+ephy_web_application_initialize_settings (const char *profile_directory)
+{
+  GSettings *settings;
+  GSettings *web_app_settings;
+  char *name;
+  char *path;
+
+  name = g_path_get_basename (profile_directory);
+  settings = g_settings_new_with_path (EPHY_PREFS_WEB_SCHEMA, "/org/gnome/epiphany/web/");
+
+  path = g_build_path ("/", "/org/gnome/epiphany/web-apps/", name, "web/", NULL);
+  web_app_settings = g_settings_new_with_path (EPHY_PREFS_WEB_SCHEMA, path);
+  g_free (path);
+
+  for (guint i = 0; i < G_N_ELEMENTS (ephy_prefs_web_schema); i++) {
+    GVariant *value;
+
+    value = g_settings_get_value (settings, ephy_prefs_web_schema[i]);
+    g_settings_set_value (web_app_settings, ephy_prefs_web_schema[i], value);
+    g_variant_unref (value);
+  }
+
+  g_object_unref (settings);
+  g_object_unref (web_app_settings);
+
+  settings = g_settings_new_with_path (EPHY_PREFS_STATE_SCHEMA, "/org/gnome/epiphany/state/");
+
+  path = g_build_path ("/", "/org/gnome/epiphany/web-apps/", name, "state/", NULL);
+  web_app_settings = g_settings_new_with_path (EPHY_PREFS_STATE_SCHEMA, path);
+  g_free (path);
+
+  for (guint i = 0; i < G_N_ELEMENTS (ephy_prefs_state_schema); i++) {
+    GVariant *value;
+
+    value = g_settings_get_value (settings, ephy_prefs_state_schema[i]);
+    g_settings_set_value (web_app_settings, ephy_prefs_state_schema[i], value);
+    g_variant_unref (value);
+  }
+
+  g_object_unref (settings);
+  g_object_unref (web_app_settings);
+  g_free (name);
+}
diff --git a/lib/ephy-web-app-utils.h b/lib/ephy-web-app-utils.h
index cd6b94f..79bdc96 100644
--- a/lib/ephy-web-app-utils.h
+++ b/lib/ephy-web-app-utils.h
@@ -56,4 +56,6 @@ void     ephy_web_application_free_application_list (GList *list);
 
 gboolean ephy_web_application_exists (const char *name);
 
+void     ephy_web_application_initialize_settings (const char *profile_directory);
+
 G_END_DECLS
diff --git a/src/ephy-main.c b/src/ephy-main.c
index 9a441e5..2d5f843 100644
--- a/src/ephy-main.c
+++ b/src/ephy-main.c
@@ -380,19 +380,6 @@ 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 */
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 92e85ca..ba20ee8 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -273,6 +273,7 @@ static GActionEntry app_entries[] = {
 };
 
 static GActionEntry app_mode_app_entries[] = {
+  { "preferences", show_preferences, NULL, NULL, NULL },
   { "about", show_about, NULL, NULL, NULL },
   { "quit", quit_application, NULL, NULL, NULL },
 };
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index d96e69f..8cf455c 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -68,6 +68,7 @@ struct _PrefsDialog {
   GtkDialog parent_instance;
 
   /* general */
+  GtkWidget *homepage_box;
   GtkWidget *new_tab_homepage_radiobutton;
   GtkWidget *blank_homepage_radiobutton;
   GtkWidget *custom_homepage_radiobutton;
@@ -75,7 +76,9 @@ struct _PrefsDialog {
   GtkWidget *download_button_hbox;
   GtkWidget *download_button_label;
   GtkWidget *automatic_downloads_checkbutton;
+  GtkWidget *search_box;
   GtkWidget *search_engine_combo;
+  GtkWidget *session_box;
   GtkWidget *restore_session_checkbutton;
   GtkWidget *popups_allow_checkbutton;
   GtkWidget *adblock_allow_checkbutton;
@@ -592,12 +595,15 @@ prefs_dialog_class_init (PrefsDialogClass *klass)
   gtk_widget_class_set_template_from_resource (widget_class,
                                                "/org/gnome/epiphany/gtk/prefs-dialog.ui");
   /* general */
+  gtk_widget_class_bind_template_child (widget_class, PrefsDialog, homepage_box);
   gtk_widget_class_bind_template_child (widget_class, PrefsDialog, new_tab_homepage_radiobutton);
   gtk_widget_class_bind_template_child (widget_class, PrefsDialog, blank_homepage_radiobutton);
   gtk_widget_class_bind_template_child (widget_class, PrefsDialog, custom_homepage_radiobutton);
   gtk_widget_class_bind_template_child (widget_class, PrefsDialog, custom_homepage_entry);
   gtk_widget_class_bind_template_child (widget_class, PrefsDialog, automatic_downloads_checkbutton);
+  gtk_widget_class_bind_template_child (widget_class, PrefsDialog, search_box);
   gtk_widget_class_bind_template_child (widget_class, PrefsDialog, search_engine_combo);
+  gtk_widget_class_bind_template_child (widget_class, PrefsDialog, session_box);
   gtk_widget_class_bind_template_child (widget_class, PrefsDialog, restore_session_checkbutton);
   gtk_widget_class_bind_template_child (widget_class, PrefsDialog, popups_allow_checkbutton);
   gtk_widget_class_bind_template_child (widget_class, PrefsDialog, adblock_allow_checkbutton);
@@ -1354,12 +1360,12 @@ do_not_track_button_clicked_cb (GtkWidget   *button,
   char **filters;
   char **new_filters;
 
-  filters = g_settings_get_strv (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_ADBLOCK_FILTERS);
+  filters = g_settings_get_strv (EPHY_SETTINGS_MAIN, EPHY_PREFS_ADBLOCK_FILTERS);
   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
     new_filters = ephy_strv_append ((const char * const *)filters, ADBLOCK_PRIVACY_FILTER_URL);
   else
     new_filters = ephy_strv_remove ((const char * const *)filters, ADBLOCK_PRIVACY_FILTER_URL);
-  g_settings_set_strv (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_ADBLOCK_FILTERS, (const char * const *)new_filters);
+  g_settings_set_strv (EPHY_SETTINGS_MAIN, EPHY_PREFS_ADBLOCK_FILTERS, (const char * const *)new_filters);
 
   g_strfreev (filters);
   g_strfreev (new_filters);
@@ -1807,10 +1813,8 @@ setup_fonts_page (PrefsDialog *dialog)
 static void
 setup_stored_data_page (PrefsDialog *dialog)
 {
-  GSettings *settings;
   GSettings *web_settings;
 
-  settings = ephy_settings_get (EPHY_PREFS_SCHEMA);
   web_settings = ephy_settings_get (EPHY_PREFS_WEB_SCHEMA);
 
   g_settings_bind_with_mapping (web_settings,
@@ -1840,8 +1844,8 @@ setup_stored_data_page (PrefsDialog *dialog)
                                 cookies_set_mapping,
                                 dialog->never,
                                 NULL);
-  g_settings_bind (settings,
-                   EPHY_PREFS_REMEMBER_PASSWORDS,
+  g_settings_bind (web_settings,
+                   EPHY_PREFS_WEB_REMEMBER_PASSWORDS,
                    dialog->remember_passwords_checkbutton,
                    "active",
                    G_SETTINGS_BIND_DEFAULT);
@@ -1909,18 +1913,35 @@ setup_sync_page (PrefsDialog *dialog)
 static void
 prefs_dialog_init (PrefsDialog *dialog)
 {
+  EphyEmbedShellMode mode;
+
   gtk_widget_init_template (GTK_WIDGET (dialog));
 
+  mode = ephy_embed_shell_get_mode (ephy_embed_shell_get_default ());
+  gtk_widget_set_visible (dialog->homepage_box,
+                          mode != EPHY_EMBED_SHELL_MODE_APPLICATION);
+  gtk_widget_set_visible (dialog->search_box,
+                          mode != EPHY_EMBED_SHELL_MODE_APPLICATION);
+  gtk_widget_set_visible (dialog->automatic_downloads_checkbutton,
+                          mode != EPHY_EMBED_SHELL_MODE_APPLICATION);
+  gtk_widget_set_visible (dialog->session_box,
+                          mode != EPHY_EMBED_SHELL_MODE_APPLICATION);
+  gtk_widget_set_visible (dialog->do_not_track_checkbutton,
+                          mode != EPHY_EMBED_SHELL_MODE_APPLICATION);
+
   setup_general_page (dialog);
   setup_fonts_page (dialog);
   setup_stored_data_page (dialog);
   setup_language_page (dialog);
 #ifdef ENABLE_SYNC
-  setup_sync_page (dialog);
-
-  /* TODO: Switch back to using a template callback in class_init once sync is unconditionally enabled. */
-  g_signal_connect (dialog->sync_sign_out_button, "clicked",
-                    G_CALLBACK (on_sync_sign_out_button_clicked), dialog);
+  if (mode != EPHY_EMBED_SHELL_MODE_APPLICATION) {
+    setup_sync_page (dialog);
+
+    /* TODO: Switch back to using a template callback in class_init once sync is unconditionally enabled. */
+    g_signal_connect (dialog->sync_sign_out_button, "clicked",
+                      G_CALLBACK (on_sync_sign_out_button_clicked), dialog);
+  } else
+    gtk_notebook_remove_page (GTK_NOTEBOOK (dialog->notebook), -1);
 #else
   gtk_notebook_remove_page (GTK_NOTEBOOK (dialog->notebook), -1);
 #endif
diff --git a/src/profile-migrator/ephy-profile-migrator.c b/src/profile-migrator/ephy-profile-migrator.c
index 96525bd..0be662e 100644
--- a/src/profile-migrator/ephy-profile-migrator.c
+++ b/src/profile-migrator/ephy-profile-migrator.c
@@ -36,6 +36,7 @@
 #include "ephy-file-helpers.h"
 #include "ephy-form-auth-data.h"
 #include "ephy-history-service.h"
+#include "ephy-prefs.h"
 #include "ephy-profile-utils.h"
 #include "ephy-settings.h"
 #include "ephy-sqlite-connection.h"
@@ -777,8 +778,8 @@ migrate_adblock_filters (void)
   }
 
   if (filters_array) {
-    g_settings_set_strv (EPHY_SETTINGS_WEB,
-                         EPHY_PREFS_WEB_ADBLOCK_FILTERS,
+    g_settings_set_strv (EPHY_SETTINGS_MAIN,
+                         EPHY_PREFS_ADBLOCK_FILTERS,
                          (const gchar * const *)filters_array->pdata);
     g_settings_sync ();
     g_ptr_array_free (filters_array, TRUE);
@@ -824,6 +825,85 @@ migrate_permissions (void)
   g_object_unref (file);
 }
 
+static const char * const deprecated_settings[] = {
+  EPHY_PREFS_DEPRECATED_USER_AGENT,
+  EPHY_PREFS_DEPRECATED_REMEMBER_PASSWORDS,
+  EPHY_PREFS_DEPRECATED_ENABLE_SMOOTH_SCROLLING,
+};
+
+static void
+migrate_deprecated_settings (void)
+{
+  for (guint i = 0; i < G_N_ELEMENTS (deprecated_settings); i++) {
+    GVariant *value;
+
+    value = g_settings_get_value (EPHY_SETTINGS_MAIN, deprecated_settings[i]);
+    g_settings_set_value (EPHY_SETTINGS_WEB, deprecated_settings[i], value);
+    g_variant_unref (value);
+  }
+
+  g_settings_sync ();
+}
+
+static gboolean
+is_deprecated_setting (const char *setting)
+{
+  for (guint i = 0; i < G_N_ELEMENTS (deprecated_settings); i++) {
+    if (g_str_equal (setting, deprecated_settings[i]))
+      return TRUE;
+  }
+
+  return FALSE;
+}
+
+static void
+migrate_settings (void)
+{
+  int default_profile_migration_version;
+
+  /* The migrator is only run for the main profile and web apps,
+   * so if the profile dir is not the default one, it's a web app.
+   * If not a web app, migrate deprecated settings.
+   */
+  if (ephy_dot_dir_is_default ()) {
+    migrate_deprecated_settings ();
+    return;
+  }
+
+  /* If it's a web app, inherit settings from the default profile. */
+  /* If the default profile hasn't been migrated yet, use the deprecated settings. */
+  default_profile_migration_version = ephy_profile_utils_get_migration_version_for_profile_dir 
(ephy_default_dot_dir ());
+  if (default_profile_migration_version < EPHY_SETTINGS_MIGRATION_VERSION) {
+    GSettings *settings;
+
+    settings = g_settings_new_with_path (EPHY_PREFS_WEB_SCHEMA, "/org/gnome/epiphany/web/");
+
+    for (guint i = 0; i < G_N_ELEMENTS (ephy_prefs_web_schema); i++) {
+      GVariant *value;
+
+      if (is_deprecated_setting (ephy_prefs_web_schema[i]))
+        continue;
+
+      value = g_settings_get_value (settings, ephy_prefs_web_schema[i]);
+      g_settings_set_value (EPHY_SETTINGS_WEB, ephy_prefs_web_schema[i], value);
+      g_variant_unref (value);
+    }
+
+    g_object_unref (settings);
+
+    for (guint i = 0; i < G_N_ELEMENTS (deprecated_settings); i++) {
+      GVariant *value;
+
+      value = g_settings_get_value (EPHY_SETTINGS_MAIN, deprecated_settings[i]);
+      g_settings_set_value (EPHY_SETTINGS_WEB, deprecated_settings[i], value);
+      g_variant_unref (value);
+    }
+  } else
+    ephy_web_application_initialize_settings (ephy_dot_dir ());
+
+  g_settings_sync ();
+}
+
 static void
 migrate_nothing (void)
 {
@@ -853,6 +933,7 @@ const EphyProfileMigrator migrators[] = {
   /* 13 */ migrate_adblock_filters,
   /* 14 */ migrate_initial_state,
   /* 15 */ migrate_permissions,
+  /* 16 */ migrate_settings,
 };
 
 static gboolean
diff --git a/src/resources/gtk/application-menu.ui b/src/resources/gtk/application-menu.ui
index 1ad6f24..8bbe7d1 100644
--- a/src/resources/gtk/application-menu.ui
+++ b/src/resources/gtk/application-menu.ui
@@ -72,6 +72,13 @@
   <menu id="app-mode-app-menu">
     <section>
       <item>
+        <attribute name="label" translatable="yes">Pr_eferences</attribute>
+        <attribute name="action">app.preferences</attribute>
+        <attribute name="accel">&lt;Primary&gt;e</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
         <attribute name="label" translatable="yes">_About</attribute>
         <attribute name="action">app.about</attribute>
       </item>
diff --git a/src/resources/gtk/prefs-dialog.ui b/src/resources/gtk/prefs-dialog.ui
index f48cd88..67405ba 100644
--- a/src/resources/gtk/prefs-dialog.ui
+++ b/src/resources/gtk/prefs-dialog.ui
@@ -41,8 +41,8 @@
                 <property name="orientation">vertical</property>
                 <property name="spacing">18</property>
                 <child>
-                  <object class="GtkBox">
-                    <property name="visible">True</property>
+                  <object class="GtkBox" id="homepage_box">
+                    <property name="visible">False</property>
                     <property name="orientation">vertical</property>
                     <property name="spacing">18</property>
                     <child>
@@ -153,7 +153,7 @@
                             <child>
                               <object class="GtkCheckButton" id="automatic_downloads_checkbutton">
                                 <property name="label" translatable="yes">A_utomatically open downloaded 
files</property>
-                                <property name="visible">True</property>
+                                <property name="visible">False</property>
                                 <property name="use-underline">True</property>
                               </object>
                             </child>
@@ -164,8 +164,8 @@
                   </object>
                 </child>
                 <child>
-                  <object class="GtkBox">
-                    <property name="visible">True</property>
+                  <object class="GtkBox" id="search_box">
+                    <property name="visible">False</property>
                     <property name="orientation">vertical</property>
                     <property name="spacing">6</property>
                     <child>
@@ -213,8 +213,8 @@
                   </object>
                 </child>
                 <child>
-                  <object class="GtkBox">
-                    <property name="visible">True</property>
+                  <object class="GtkBox" id="session_box">
+                    <property name="visible">False</property>
                     <property name="orientation">vertical</property>
                     <property name="spacing">6</property>
                     <child>
@@ -275,7 +275,7 @@
                         <child>
                           <object class="GtkCheckButton" id="do_not_track_checkbutton">
                             <property name="label" translatable="yes">Try to block web _trackers</property>
-                            <property name="visible">True</property>
+                            <property name="visible">False</property>
                             <property name="use-underline">True</property>
                             <property name="margin-start">12</property>
                           </object>
diff --git a/tests/ephy-encodings-test.c b/tests/ephy-encodings-test.c
index 197c988..590102e 100644
--- a/tests/ephy-encodings-test.c
+++ b/tests/ephy-encodings-test.c
@@ -97,8 +97,6 @@ main (int argc, char *argv[])
   g_test_add_func ("/src/ephy-encodings/get",
                    test_ephy_encodings_get);
 
-  ephy_settings_ensure_schema_for_path (EPHY_PREFS_STATE_SCHEMA, "/org/gnome/epiphany/state/");
-
   ret = g_test_run ();
 
   g_object_unref (ephy_shell_get_default ());
diff --git a/tests/ephy-file-helpers-test.c b/tests/ephy-file-helpers-test.c
index 7bb49b9..6b8c3d3 100644
--- a/tests/ephy-file-helpers-test.c
+++ b/tests/ephy-file-helpers-test.c
@@ -329,8 +329,6 @@ main (int argc, char *argv[])
 
   ephy_debug_init ();
 
-  ephy_settings_ensure_schema_for_path (EPHY_PREFS_STATE_SCHEMA, "/org/gnome/epiphany/state/");
-
   g_test_add_func ("/lib/ephy-file-helpers/init",
                    test_ephy_file_helpers_init);
 



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