[geary] Remove use of global application and engine instance vars in MainWindow.



commit 440d1bff20530078c9709d288cc9ce17f49e0785
Author: Michael James Gratton <mike vee net>
Date:   Sat Dec 17 12:24:41 2016 +1100

    Remove use of global application and engine instance vars in MainWindow.
    
    * src/client/application/geary-application.vala (GearyApplication):
      Deprecate 'instance' and add 'engine' prop, clean up slightly.
    
    * src/client/components/main-window.vala (MainWindow): Override
      'application' property to return an instance of GearyApplication, use
      that to replace use of global instance vars.

 src/client/application/geary-application.vala |   56 ++++++++++++++++++-------
 src/client/components/main-window.vala        |   35 +++++++++------
 2 files changed, 62 insertions(+), 29 deletions(-)
---
diff --git a/src/client/application/geary-application.vala b/src/client/application/geary-application.vala
index c2563d9..5f5f7b5 100644
--- a/src/client/application/geary-application.vala
+++ b/src/client/application/geary-application.vala
@@ -58,7 +58,9 @@ public class GearyApplication : Gtk.Application {
 
     private const int64 USEC_PER_SEC = 1000000;
     private const int64 FORCE_SHUTDOWN_USEC = 5 * USEC_PER_SEC;
-    
+
+
+    [Version(deprecated = true)]
     public static GearyApplication instance {
         get { return _instance; }
         private set {
@@ -67,19 +69,35 @@ public class GearyApplication : Gtk.Application {
             _instance = value;
         }
     }
-    
+    private static GearyApplication _instance = null;
+
+
     /**
-     * Signal that is activated when 'exit' is called, but before the application actually exits.
-     *
-     * To cancel an exit, a callback should return GearyApplication.cancel_exit(). To procede with
-     * an exit, a callback should return true.
+     * The global UI controller for this app instance.
      */
-    public virtual signal bool exiting(bool panicked) {
-        return true;
+    public GearyController controller {
+        get;
+        private set;
+        default = new GearyController(this);
     }
-    
-    public GearyController controller { get; private set; default = new GearyController(this); }
-    
+
+    /**
+     * The global email subsystem controller for this app instance.
+     */
+    public Geary.Engine engine {
+        get {
+            // XXX We should be managing the engine's lifecycle here,
+            // but until that happens provide this property to
+            // encourage access via the application anyway
+            return Geary.Engine.instance;
+        }
+    }
+
+    /**
+     * The user's desktop-wide settings for the application.
+     */
+    public Configuration config { get; private set; }
+
     public Gtk.ActionGroup actions {
         get; private set; default = new Gtk.ActionGroup("GearyActionGroup");
     }
@@ -87,10 +105,6 @@ public class GearyApplication : Gtk.Application {
     public Gtk.UIManager ui_manager {
         get; private set; default = new Gtk.UIManager();
     }
-    
-    public Configuration config { get; private set; }
-
-    private static GearyApplication _instance = null;
 
     private string bin;
     private File exec_dir;
@@ -98,6 +112,18 @@ public class GearyApplication : Gtk.Application {
     private int exitcode = 0;
     private bool is_destroyed = false;
 
+
+    /**
+     * Signal that is activated when 'exit' is called, but before the application actually exits.
+     *
+     * To cancel an exit, a callback should return GearyApplication.cancel_exit(). To procede with
+     * an exit, a callback should return true.
+     */
+    public virtual signal bool exiting(bool panicked) {
+        return true;
+    }
+
+
     public GearyApplication() {
         Object(
             application_id: APP_ID
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index 908b2ff..9f9e723 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -10,8 +10,10 @@
 public class MainWindow : Gtk.ApplicationWindow {
     private const int STATUS_BAR_HEIGHT = 18;
 
-    /** Fired when the shift key is pressed or released. */
-    public signal void on_shift_key(bool pressed);
+    public new GearyApplication application {
+        get { return (GearyApplication) base.get_application(); }
+        set { base.set_application(value); }
+    }
 
     public Geary.Folder? current_folder { get; private set; default = null; }
 
@@ -48,6 +50,11 @@ public class MainWindow : Gtk.ApplicationWindow {
     [GtkChild]
     private Gtk.ScrolledWindow conversation_list_scrolled;
 
+
+    /** Fired when the shift key is pressed or released. */
+    public signal void on_shift_key(bool pressed);
+
+
     public MainWindow(GearyApplication application) {
         Object(application: application);
 
@@ -64,8 +71,8 @@ public class MainWindow : Gtk.ApplicationWindow {
         application.controller.notify[GearyController.PROP_CURRENT_CONVERSATION]
             .connect(on_conversation_monitor_changed);
         application.controller.folder_selected.connect(on_folder_selected);
-        Geary.Engine.instance.account_available.connect(on_account_available);
-        Geary.Engine.instance.account_unavailable.connect(on_account_unavailable);
+        this.application.engine.account_available.connect(on_account_available);
+        this.application.engine.account_unavailable.connect(on_account_unavailable);
 
         set_styling();
         setup_layout(application.config);
@@ -216,7 +223,7 @@ public class MainWindow : Gtk.ApplicationWindow {
         }
 
         Geary.App.ConversationMonitor? conversations =
-            GearyApplication.instance.controller.current_conversations;
+            this.application.controller.current_conversations;
 
         if (conversations != null) {
             ConversationListStore new_model =
@@ -259,8 +266,8 @@ public class MainWindow : Gtk.ApplicationWindow {
 
     private void on_account_available(Geary.AccountInformation account) {
         try {
-            this.progress_monitor.add(Geary.Engine.instance.get_account_instance(account).opening_monitor);
-            this.progress_monitor.add(Geary.Engine.instance.get_account_instance(account).sending_monitor);
+            this.progress_monitor.add(this.application.engine.get_account_instance(account).opening_monitor);
+            this.progress_monitor.add(this.application.engine.get_account_instance(account).sending_monitor);
         } catch (Error e) {
             debug("Could not access account progress monitors: %s", e.message);
         }
@@ -268,15 +275,15 @@ public class MainWindow : Gtk.ApplicationWindow {
 
     private void on_account_unavailable(Geary.AccountInformation account) {
         try {
-            
this.progress_monitor.remove(Geary.Engine.instance.get_account_instance(account).opening_monitor);
-            
this.progress_monitor.remove(Geary.Engine.instance.get_account_instance(account).sending_monitor);
+            
this.progress_monitor.remove(this.application.engine.get_account_instance(account).opening_monitor);
+            
this.progress_monitor.remove(this.application.engine.get_account_instance(account).sending_monitor);
         } catch (Error e) {
             debug("Could not access account progress monitors: %s", e.message);
         }
     }
 
     private void on_change_orientation() {
-        bool horizontal = GearyApplication.instance.config.folder_list_pane_horizontal;
+        bool horizontal = this.application.config.folder_list_pane_horizontal;
         bool initial = true;
 
         if (this.status_bar.parent != null) {
@@ -289,7 +296,7 @@ public class MainWindow : Gtk.ApplicationWindow {
             Gtk.Orientation.VERTICAL;
 
         int folder_list_width =
-            GearyApplication.instance.config.folder_list_pane_position_horizontal;
+            this.application.config.folder_list_pane_position_horizontal;
         if (horizontal) {
             if (!initial)
                 this.conversations_paned.position += folder_list_width;
@@ -300,7 +307,7 @@ public class MainWindow : Gtk.ApplicationWindow {
             this.conversation_box.pack_start(status_bar, false, false);
         }
 
-        GearyApplication.instance.config.bind(
+        this.application.config.bind(
             horizontal ? Configuration.FOLDER_LIST_PANE_POSITION_HORIZONTAL_KEY
             : Configuration.FOLDER_LIST_PANE_POSITION_VERTICAL_KEY,
             this.folder_paned, "position");
@@ -368,10 +375,10 @@ public class MainWindow : Gtk.ApplicationWindow {
 
     [GtkCallback]
     private bool on_delete_event() {
-        if (Args.hidden_startup || GearyApplication.instance.config.startup_notifications)
+        if (Args.hidden_startup || this.application.config.startup_notifications)
             return hide_on_delete();
 
-        GearyApplication.instance.exit();
+        this.application.exit();
 
         return true;
     }


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