[evince/wip/gmenu: 1/6] Create "org.gnome.Evince" settings object in EvApplication



commit c100e1fd670e4cdca935c867b652bcda82360fde
Author: Lars Uebernickel <lars uebernickel canonical com>
Date:   Thu Jan 30 15:13:13 2014 +0100

    Create "org.gnome.Evince" settings object in EvApplication
    
    This will make it possible to use it from outside of EvWindow without
    having to reinstantiate it.

 shell/ev-application.c |   24 ++++++++++++++++++++++++
 shell/ev-application.h |    2 ++
 shell/ev-window.c      |   42 ++++++++++++++----------------------------
 3 files changed, 40 insertions(+), 28 deletions(-)
---
diff --git a/shell/ev-application.c b/shell/ev-application.c
index 2115596..3a842f9 100644
--- a/shell/ev-application.c
+++ b/shell/ev-application.c
@@ -54,6 +54,7 @@ struct _EvApplication {
        gchar *uri;
 
        gchar *dot_dir;
+       GSettings *settings;
 
 #ifdef ENABLE_DBUS
         EvEvinceApplication *skeleton;
@@ -1011,6 +1012,16 @@ app_help_cb (GSimpleAction *action,
 }
 
 static void
+ev_application_dispose (GObject *object)
+{
+       EvApplication *app = EV_APPLICATION (object);
+
+       g_clear_object (&app->settings);
+
+       G_OBJECT_CLASS (ev_application_parent_class)->dispose (object);
+}
+
+static void
 ev_application_startup (GApplication *gapplication)
 {
         const GActionEntry app_menu_actions[] = {
@@ -1138,8 +1149,11 @@ ev_application_dbus_unregister (GApplication    *gapplication,
 static void
 ev_application_class_init (EvApplicationClass *ev_application_class)
 {
+        GObjectClass *object_class = G_OBJECT_CLASS (ev_application_class);
         GApplicationClass *g_application_class = G_APPLICATION_CLASS (ev_application_class);
 
+        object_class->dispose = ev_application_dispose;
+
         g_application_class->startup = ev_application_startup;
         g_application_class->activate = ev_application_activate;
         g_application_class->shutdown = ev_application_shutdown;
@@ -1158,6 +1172,8 @@ ev_application_init (EvApplication *ev_application)
         if (!g_file_test (ev_application->dot_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
                 ev_application_migrate_config_dir (ev_application);
 
+       ev_application->settings = g_settings_new ("org.gnome.Evince");
+
        ev_application_init_session (ev_application);
 
        ev_application_accel_map_load (ev_application);
@@ -1257,3 +1273,11 @@ ev_application_show_help (EvApplication *application,
         gtk_show_uri (screen, uri, gtk_get_current_event_time (), NULL);
         g_free (uri);
 }
+
+GSettings *
+ev_application_get_settings (EvApplication *application)
+{
+       g_return_val_if_fail (EV_IS_APPLICATION (application), NULL);
+
+       return application->settings;
+}
diff --git a/shell/ev-application.h b/shell/ev-application.h
index 5ec870e..dadf1a7 100644
--- a/shell/ev-application.h
+++ b/shell/ev-application.h
@@ -76,6 +76,8 @@ void              ev_application_show_help           (EvApplication   *applicati
                                                       GdkScreen       *screen,
                                                       const char      *topic);
 
+GSettings *       ev_application_get_settings        (EvApplication   *application);
+
 G_END_DECLS
 
 #endif /* !EV_APPLICATION_H */
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 65ed151..5201980 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -1440,27 +1440,6 @@ lockdown_changed (GSettings   *lockdown,
 }
 #endif
 
-static GSettings *
-ev_window_ensure_settings (EvWindow *ev_window)
-{
-        EvWindowPrivate *priv = ev_window->priv;
-
-        if (priv->settings != NULL)
-                return priv->settings;
-
-        priv->settings = g_settings_new (GS_SCHEMA_NAME);
-        g_signal_connect (priv->settings,
-                          "changed::"GS_OVERRIDE_RESTRICTIONS,
-                          G_CALLBACK (override_restrictions_changed),
-                          ev_window);
-        g_signal_connect (priv->settings,
-                         "changed::"GS_PAGE_CACHE_SIZE,
-                         G_CALLBACK (page_cache_size_changed),
-                         ev_window);
-
-        return priv->settings;
-}
-
 static gboolean
 ev_window_setup_document (EvWindow *ev_window)
 {
@@ -1475,8 +1454,6 @@ ev_window_setup_document (EvWindow *ev_window)
        ev_window_title_set_document (ev_window->priv->title, document);
        ev_window_title_set_uri (ev_window->priv->title, ev_window->priv->uri);
 
-        ev_window_ensure_settings (ev_window);
-
 #ifdef HAVE_DESKTOP_SCHEMAS
        if (!ev_window->priv->lockdown_settings) {
                ev_window->priv->lockdown_settings = g_settings_new (GS_LOCKDOWN_SCHEMA_NAME);
@@ -2435,7 +2412,7 @@ ev_window_file_chooser_restore_folder (EvWindow       *window,
         const gchar *folder_uri, *dir;
         gchar *parent_uri = NULL;
 
-        g_settings_get (ev_window_ensure_settings (window),
+        g_settings_get (ev_application_get_settings (EV_APP),
                         get_settings_key_for_directory (directory),
                         "m&s", &folder_uri);
         if (folder_uri == NULL && uri != NULL) {
@@ -2477,7 +2454,7 @@ ev_window_file_chooser_save_folder (EvWindow       *window,
         }
         g_free (folder);
 
-        g_settings_set (ev_window_ensure_settings (window),
+        g_settings_set (ev_application_get_settings (EV_APP),
                         get_settings_key_for_directory (directory),
                         "ms", uri);
         g_free (uri);
@@ -5686,7 +5663,7 @@ ev_window_caret_navigation_message_area_response_cb (EvMessageArea *area,
 
        /* Turn the confirmation dialog off if the user has requested not to show it again */
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (window->priv->ask_caret_navigation_check))) {
-               g_settings_set_boolean (ev_window_ensure_settings (window), "show-caret-navigation-message", 
FALSE);
+               g_settings_set_boolean (ev_application_get_settings (EV_APP), 
"show-caret-navigation-message", FALSE);
                g_settings_apply (window->priv->settings);
        }
 
@@ -5707,7 +5684,7 @@ ev_window_cmd_view_toggle_caret_navigation (GtkAction *action,
        /* Don't ask for user confirmation to turn the caret navigation off when it is active,
         * or to turn it on when the confirmation dialog is not to be shown per settings */
        enabled = ev_view_is_caret_navigation_enabled (EV_VIEW (window->priv->view));
-       if (enabled || !g_settings_get_boolean (ev_window_ensure_settings (window), 
"show-caret-navigation-message")) {
+       if (enabled || !g_settings_get_boolean (ev_application_get_settings (EV_APP), 
"show-caret-navigation-message")) {
                ev_window_set_caret_navigation_enabled (window, !enabled);
                return;
        }
@@ -7578,8 +7555,17 @@ ev_window_init (EvWindow *ev_window)
                        ev_window->priv->view_box);
        gtk_widget_show (ev_window->priv->view_box);
 
+       g_signal_connect (ev_application_get_settings (EV_APP),
+                         "changed::"GS_OVERRIDE_RESTRICTIONS,
+                         G_CALLBACK (override_restrictions_changed),
+                         ev_window);
+       g_signal_connect (ev_application_get_settings (EV_APP),
+                         "changed::"GS_PAGE_CACHE_SIZE,
+                         G_CALLBACK (page_cache_size_changed),
+                         ev_window);
+
        ev_window->priv->view = ev_view_new ();
-       page_cache_mb = g_settings_get_uint (ev_window_ensure_settings (ev_window),
+       page_cache_mb = g_settings_get_uint (ev_application_get_settings (EV_APP),
                                             GS_PAGE_CACHE_SIZE);
        ev_view_set_page_cache_size (EV_VIEW (ev_window->priv->view),
                                     page_cache_mb * 1024 * 1024);


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