[geary/wip/728002-webkit2: 97/105] Remove global GearyApplication instance from ClientWebView.



commit b91aa41c36d00e311088853e1cb6eac6793085d7
Author: Michael James Gratton <mike vee net>
Date:   Sun Jan 1 12:00:52 2017 +1100

    Remove global GearyApplication instance from ClientWebView.
    
    This is also needed to make the class and its subclasses unit testable.
    
    * src/client/components/client-web-view.vala
      (ClientWebView::ClientWebView): Replace use of
      GearyApplication.instance.config with a constructor parameter. Update
      all subclassess and call sites to ensure the parameter is passed in.

 src/client/accounts/add-edit-page.vala             |    4 +++-
 src/client/components/client-web-view.vala         |   13 ++++++++-----
 src/client/composer/composer-web-view.vala         |    4 ++--
 src/client/composer/composer-widget.vala           |    4 +++-
 .../conversation-viewer/conversation-email.vala    |    5 +++--
 .../conversation-viewer/conversation-list-box.vala |    6 ++++++
 .../conversation-viewer/conversation-message.vala  |    9 ++++-----
 .../conversation-viewer/conversation-viewer.vala   |    1 +
 .../conversation-viewer/conversation-web-view.vala |    4 ++--
 9 files changed, 32 insertions(+), 18 deletions(-)
---
diff --git a/src/client/accounts/add-edit-page.vala b/src/client/accounts/add-edit-page.vala
index 770ab39..a00be5b 100644
--- a/src/client/accounts/add-edit-page.vala
+++ b/src/client/accounts/add-edit-page.vala
@@ -178,7 +178,7 @@ public class AddEditPage : Gtk.Box {
     private Gtk.CheckButton check_use_email_signature;
     private Gtk.Stack signature_stack;
     private Gtk.TextView textview_email_signature;
-    private ClientWebView preview_webview = new ClientWebView(null);
+    private ClientWebView preview_webview;
 
     private Gtk.Alignment other_info;
     
@@ -272,6 +272,8 @@ public class AddEditPage : Gtk.Box {
         textview_email_signature = new Gtk.TextView();
         edit_window.add(textview_email_signature);
 
+        preview_webview = new ClientWebView(GearyApplication.instance.config);
+
         Gtk.ScrolledWindow preview_window = new Gtk.ScrolledWindow(null, null);
         preview_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
         preview_window.set_shadow_type(Gtk.ShadowType.IN);
diff --git a/src/client/components/client-web-view.vala b/src/client/components/client-web-view.vala
index fc10f41..a206964 100644
--- a/src/client/components/client-web-view.vala
+++ b/src/client/components/client-web-view.vala
@@ -206,7 +206,8 @@ public class ClientWebView : WebKit.WebView {
     public signal void remote_image_load_blocked();
 
 
-    public ClientWebView(WebKit.UserContentManager? custom_manager = null) {
+    public ClientWebView(Configuration config,
+                         WebKit.UserContentManager? custom_manager = null) {
         WebKit.Settings setts = new WebKit.Settings();
         setts.allow_modal_dialogs = false;
         setts.default_charset = "UTF-8";
@@ -267,12 +268,14 @@ public class ClientWebView : WebKit.WebView {
         register_message_handler(REMOTE_IMAGE_LOAD_BLOCKED_MESSAGE);
         register_message_handler(SELECTION_CHANGED_MESSAGE);
 
-        GearyApplication.instance.config.bind(Configuration.CONVERSATION_VIEWER_ZOOM_KEY, this, 
"zoom_level");
+        config.bind(Configuration.CONVERSATION_VIEWER_ZOOM_KEY, this, "zoom_level");
         this.scroll_event.connect(on_scroll_event);
 
-        Settings system_settings = GearyApplication.instance.config.gnome_interface;
-        system_settings.bind("document-font-name", this, "document-font", SettingsBindFlags.DEFAULT);
-        system_settings.bind("monospace-font-name", this, "monospace-font", SettingsBindFlags.DEFAULT);
+        Settings system_settings = config.gnome_interface;
+        system_settings.bind("document-font-name", this,
+                             "document-font", SettingsBindFlags.DEFAULT);
+        system_settings.bind("monospace-font-name", this,
+                             "monospace-font", SettingsBindFlags.DEFAULT);
     }
 
     /**
diff --git a/src/client/composer/composer-web-view.vala b/src/client/composer/composer-web-view.vala
index 6b19efa..b156733 100644
--- a/src/client/composer/composer-web-view.vala
+++ b/src/client/composer/composer-web-view.vala
@@ -71,8 +71,8 @@ public class ComposerWebView : ClientWebView {
     private bool is_shift_down = false;
 
 
-    public ComposerWebView() {
-        base();
+    public ComposerWebView(Configuration config) {
+        base(config);
         this.user_content_manager.add_script(ComposerWebView.app_script);
         // this.should_insert_text.connect(on_should_insert_text);
         this.key_press_event.connect(on_key_press_event);
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index f39836e..61ed8cb 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -214,7 +214,7 @@ public class ComposerWidget : Gtk.EventBox {
 
     public ComposerHeaderbar header { get; private set; }
 
-    public ComposerWebView editor { get; private set; default = new ComposerWebView(); }
+    public ComposerWebView editor { get; private set; }
 
     public string draft_save_text { get; private set; }
 
@@ -392,6 +392,8 @@ public class ComposerWidget : Gtk.EventBox {
 
         this.to_entry.margin_top = this.cc_entry.margin_top = this.bcc_entry.margin_top = 
this.reply_to_entry.margin_top = 6;
 
+        this.editor = new ComposerWebView(config);
+
         // Initialize menus
         Gtk.Builder builder = new Gtk.Builder.from_resource(
             "/org/gnome/Geary/composer-menus.ui"
diff --git a/src/client/conversation-viewer/conversation-email.vala 
b/src/client/conversation-viewer/conversation-email.vala
index b1dafd7..b588a4d 100644
--- a/src/client/conversation-viewer/conversation-email.vala
+++ b/src/client/conversation-viewer/conversation-email.vala
@@ -365,6 +365,7 @@ public class ConversationEmail : Gtk.Box {
      */
     public ConversationEmail(Geary.Email email,
                              Geary.ContactStore contact_store,
+                             Configuration config,
                              bool is_sent,
                              bool is_draft) {
         this.email = email;
@@ -451,7 +452,7 @@ public class ConversationEmail : Gtk.Box {
             load_images |= contact.always_load_remote_images();
         }
 
-        this.primary_message = new ConversationMessage(message, load_images);
+        this.primary_message = new ConversationMessage(message, config, load_images);
         this.primary_message.web_view.add_inline_resources(cid_resources);
         connect_message_view_signals(this.primary_message);
 
@@ -493,7 +494,7 @@ public class ConversationEmail : Gtk.Box {
         }
         foreach (Geary.RFC822.Message sub_message in sub_messages) {
             ConversationMessage attached_message =
-                new ConversationMessage(sub_message, false);
+                new ConversationMessage(sub_message, config, false);
             connect_message_view_signals(attached_message);
             attached_message.web_view.add_inline_resources(cid_resources);
             this.sub_messages.add(attached_message);
diff --git a/src/client/conversation-viewer/conversation-list-box.vala 
b/src/client/conversation-viewer/conversation-list-box.vala
index 67869be..2625d94 100644
--- a/src/client/conversation-viewer/conversation-list-box.vala
+++ b/src/client/conversation-viewer/conversation-list-box.vala
@@ -284,6 +284,9 @@ public class ConversationListBox : Gtk.ListBox {
     // Cancellable for this conversation's data loading.
     private Cancellable cancellable = new Cancellable();
 
+    // App config
+    private Configuration config;
+
     // Email view with selected text, if any
     private ConversationEmail? body_selected_view = null;
 
@@ -327,6 +330,7 @@ public class ConversationListBox : Gtk.ListBox {
                                Geary.ContactStore contact_store,
                                Geary.AccountInformation account_info,
                                bool is_draft_folder,
+                               Configuration config,
                                Gtk.Adjustment adjustment) {
         this.conversation = conversation;
         this.location = location;
@@ -334,6 +338,7 @@ public class ConversationListBox : Gtk.ListBox {
         this.contact_store = contact_store;
         this.account_info = account_info;
         this.is_draft_folder = is_draft_folder;
+        this.config = config;
 
         get_style_context().add_class("background");
         get_style_context().add_class("conversation-listbox");
@@ -762,6 +767,7 @@ public class ConversationListBox : Gtk.ListBox {
         ConversationEmail view = new ConversationEmail(
             email,
             this.contact_store,
+            this.config,
             is_sent,
             is_draft
         );
diff --git a/src/client/conversation-viewer/conversation-message.vala 
b/src/client/conversation-viewer/conversation-message.vala
index fe9629f..cc95abe 100644
--- a/src/client/conversation-viewer/conversation-message.vala
+++ b/src/client/conversation-viewer/conversation-message.vala
@@ -265,6 +265,7 @@ public class ConversationMessage : Gtk.Grid {
      * loading processes.
      */
     public ConversationMessage(Geary.RFC822.Message message,
+                               Configuration config,
                                bool load_remote_images) {
         this.message = message;
 
@@ -329,13 +330,11 @@ public class ConversationMessage : Gtk.Grid {
         string date_text = "";
         string date_tooltip = "";
         if (this.message.date != null) {
-            Date.ClockFormat clock_format =
-                GearyApplication.instance.config.clock_format;
             date_text = Date.pretty_print(
-                this.message.date.value, clock_format
+                this.message.date.value, config.clock_format
             );
             date_tooltip = Date.pretty_print_verbose(
-                this.message.date.value, clock_format
+                this.message.date.value, config.clock_format
             );
         }
         this.preview_date.set_text(date_text);
@@ -365,7 +364,7 @@ public class ConversationMessage : Gtk.Grid {
 
         // Web view
 
-        this.web_view = new ConversationWebView();
+        this.web_view = new ConversationWebView(config);
         if (load_remote_images) {
             this.web_view.allow_remote_image_loading();
         }
diff --git a/src/client/conversation-viewer/conversation-viewer.vala 
b/src/client/conversation-viewer/conversation-viewer.vala
index aba2442..61dd49a 100644
--- a/src/client/conversation-viewer/conversation-viewer.vala
+++ b/src/client/conversation-viewer/conversation-viewer.vala
@@ -191,6 +191,7 @@ public class ConversationViewer : Gtk.Stack {
             account.get_contact_store(),
             account.information,
             location.special_folder_type == Geary.SpecialFolderType.DRAFTS,
+            ((MainWindow) get_ancestor(typeof(MainWindow))).application.config,
             conversation_scroller.get_vadjustment()
         );
 
diff --git a/src/client/conversation-viewer/conversation-web-view.vala 
b/src/client/conversation-viewer/conversation-web-view.vala
index e9df54c..a8373cc 100644
--- a/src/client/conversation-viewer/conversation-web-view.vala
+++ b/src/client/conversation-viewer/conversation-web-view.vala
@@ -28,8 +28,8 @@ public class ConversationWebView : ClientWebView {
     }
 
 
-    public ConversationWebView() {
-        base();
+    public ConversationWebView(Configuration config) {
+        base(config);
         this.user_content_manager.add_script(ConversationWebView.app_script);
         this.user_content_manager.add_style_sheet(ConversationWebView.app_stylesheet);
         if (ConversationWebView.user_stylesheet != null) {


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