[geary/mjog/upgrade-dialog-cleanup] client: Clean up database upgrade dialog implementation




commit c331145fd368beedecb8ec3d09d1056a4ddcfda2
Author: Michael Gratton <mike vee net>
Date:   Tue Jan 19 23:50:29 2021 +1100

    client: Clean up database upgrade dialog implementation
    
    Rename `UpgradeDialog` to `DatabaseManager` since it's not actually a
    dialog, move it into the APplication package. Replace old Glade UI file
    with a custom built dialog since it's trivial and so we can make it
    modal for a main window.
    
    Fixes #1007

 po/POTFILES.in                                     |   3 +-
 src/client/application/application-controller.vala |   8 +-
 .../application/application-database-manager.vala  | 118 +++++++++++++++++++++
 src/client/dialogs/upgrade-dialog.vala             |  95 -----------------
 src/client/meson.build                             |   2 +-
 ui/geary.css                                       |  10 ++
 ui/org.gnome.Geary.gresource.xml                   |   1 -
 ui/upgrade_dialog.glade                            | 113 --------------------
 8 files changed, 134 insertions(+), 216 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1e476d676..a5804402b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -23,6 +23,7 @@ src/client/application/application-configuration.vala
 src/client/application/application-contact-store.vala
 src/client/application/application-contact.vala
 src/client/application/application-controller.vala
+src/client/application/application-database-manager.vala
 src/client/application/application-email-plugin-context.vala
 src/client/application/application-email-store-factory.vala
 src/client/application/application-folder-context.vala
@@ -85,7 +86,6 @@ src/client/dialogs/attachment-dialog.vala
 src/client/dialogs/certificate-warning-dialog.vala
 src/client/dialogs/dialogs-problem-details-dialog.vala
 src/client/dialogs/password-dialog.vala
-src/client/dialogs/upgrade-dialog.vala
 src/client/folder-list/folder-list-abstract-folder-entry.vala
 src/client/folder-list/folder-list-account-branch.vala
 src/client/folder-list/folder-list-folder-entry.vala
@@ -481,4 +481,3 @@ ui/main-toolbar.ui
 ui/main-toolbar-menus.ui
 ui/password-dialog.glade
 ui/problem-details-dialog.ui
-ui/upgrade_dialog.glade
diff --git a/src/client/application/application-controller.vala 
b/src/client/application/application-controller.vala
index 6aec77acf..203bbda3f 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -84,7 +84,7 @@ internal class Application.Controller :
     // Cancelled if the controller is closed
     private GLib.Cancellable controller_open;
 
-    private UpgradeDialog upgrade_dialog;
+    private DatabaseManager database_manager;
     private Folks.IndividualAggregator folks;
 
     // List composers that have not yet been closed
@@ -134,7 +134,7 @@ internal class Application.Controller :
         IconFactory.init(application.get_resource_directory());
 
         // Create DB upgrade dialog.
-        this.upgrade_dialog = new UpgradeDialog(application);
+        this.database_manager = new DatabaseManager(application);
 
         // Initialise WebKit and WebViews
         Components.WebView.init_web_context(
@@ -977,7 +977,7 @@ internal class Application.Controller :
         );
         this.accounts.set(account.information, context);
 
-        this.upgrade_dialog.add_account(account, this.controller_open);
+        this.database_manager.add_account(account, this.controller_open);
 
         account.information.authentication_failure.connect(
             on_authentication_failure
@@ -1058,7 +1058,7 @@ internal class Application.Controller :
             // Guard against trying to close the account twice
             this.accounts.unset(account.information);
 
-            this.upgrade_dialog.remove_account(account);
+            this.database_manager.remove_account(account);
 
             // Stop updating status and showing errors when closing
             // the account - the user doesn't care any more
diff --git a/src/client/application/application-database-manager.vala 
b/src/client/application/application-database-manager.vala
new file mode 100644
index 000000000..f559cbd99
--- /dev/null
+++ b/src/client/application/application-database-manager.vala
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2016 Software Freedom Conservancy Inc.
+ * Copyright 2020 Michael Gratton <mike vee net>
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+/** Manages progress when upgrading and rebuilding account databases. */
+internal class Application.DatabaseManager : Geary.BaseObject {
+
+
+    /* Progress monitor for database operations. */
+    public Geary.AggregateProgressMonitor monitor {
+        public get; private set;
+        default = new Geary.AggregateProgressMonitor();
+    }
+
+    /** Determines whether or not the database dialog is visible. */
+    public bool visible { get; set; }
+
+    private weak Application.Client application;
+
+    private Gtk.Dialog? dialog = null;
+    private Gee.Set<GLib.Cancellable> cancellables =
+        new Gee.HashSet<GLib.Cancellable>();
+
+    /**
+     * Creates a new manager for the given application.
+     */
+    public DatabaseManager(Application.Client application) {
+        this.application = application;
+
+        this.monitor.start.connect(on_start);
+        this.monitor.finish.connect(on_close);
+    }
+
+    /**
+     * Adds an account to be monitored for upgrades by the dialog.
+     *
+     * Accounts should be added before being opened.
+     */
+    public void add_account(Geary.Account account,
+                            GLib.Cancellable? cancellable = null) {
+        monitor.add(account.db_upgrade_monitor);
+        monitor.add(account.db_vacuum_monitor);
+        if (cancellable != null) {
+            cancellables.add(cancellable);
+        }
+    }
+
+    /**
+     * Stops an account from being monitored.
+     */
+    public void remove_account(Geary.Account account) {
+        monitor.remove(account.db_upgrade_monitor);
+        monitor.remove(account.db_vacuum_monitor);
+    }
+
+    private void on_start() {
+        // Disable main windows
+        foreach (Application.MainWindow window in this.application.get_main_windows()) {
+            window.sensitive = false;
+        }
+
+        var spinner = new Gtk.Spinner();
+        spinner.set_size_request(45, 45);
+        spinner.start();
+
+        var grid = new Gtk.Grid();
+        grid.orientation = VERTICAL;
+        grid.add(spinner);
+        /// Translators: Label for account database upgrade dialog
+        grid.add(new Gtk.Label(_("Account update in progress")));
+        grid.show_all();
+
+        this.dialog = new Gtk.Dialog.with_buttons(
+            /// Translators: Window title for account database upgrade
+            /// dialog
+            _("Account update"),
+            this.application.get_active_main_window(),
+            MODAL
+        );
+        this.dialog.get_style_context().add_class("geary-upgrade");
+        this.dialog.get_content_area().add(grid);
+        this.dialog.deletable = false;
+        this.dialog.delete_event.connect(this.on_delete_event);
+        this.dialog.close.connect(this.on_close);
+        this.dialog.show();
+    }
+
+    private bool on_delete_event() {
+        // Don't allow window to close until we're finished.
+        return !this.monitor.is_in_progress;
+    }
+
+    private void on_close() {
+        // If the user quit the dialog before the upgrade completed, cancel everything.
+        if (this.monitor.is_in_progress) {
+            foreach (var c in cancellables) {
+                c.cancel();
+            }
+        }
+
+        if (this.dialog != null &&
+            this.dialog.visible) {
+            this.dialog.hide();
+            this.dialog.destroy();
+            this.dialog = null;
+        }
+
+        // Enable main windows
+        foreach (Application.MainWindow window in this.application.get_main_windows()) {
+            window.sensitive = true;
+        }
+    }
+
+}
diff --git a/src/client/meson.build b/src/client/meson.build
index e4726cebb..f20fe5c83 100644
--- a/src/client/meson.build
+++ b/src/client/meson.build
@@ -22,6 +22,7 @@ client_vala_sources = files(
   'application/application-contact-store.vala',
   'application/application-contact.vala',
   'application/application-controller.vala',
+  'application/application-database-manager.vala',
   'application/application-email-plugin-context.vala',
   'application/application-email-store-factory.vala',
   'application/application-folder-context.vala',
@@ -104,7 +105,6 @@ client_vala_sources = files(
   'dialogs/certificate-warning-dialog.vala',
   'dialogs/dialogs-problem-details-dialog.vala',
   'dialogs/password-dialog.vala',
-  'dialogs/upgrade-dialog.vala',
 
   'folder-list/folder-list-abstract-folder-entry.vala',
   'folder-list/folder-list-account-branch.vala',
diff --git a/ui/geary.css b/ui/geary.css
index 03d856d8a..12f94d7d3 100644
--- a/ui/geary.css
+++ b/ui/geary.css
@@ -372,3 +372,13 @@ treeview.sidebar:drop(active).into {
 .geary-inspector-log-viewer .sidebar row > grid * {
   margin: 4px;
 }
+
+/* Upgrade dialog */
+
+dialog.geary-upgrade grid {
+  margin: 12px;
+}
+
+dialog.geary-upgrade label {
+  margin-top: 12px;
+}
diff --git a/ui/org.gnome.Geary.gresource.xml b/ui/org.gnome.Geary.gresource.xml
index 7fe9b8653..891ab1c8f 100644
--- a/ui/org.gnome.Geary.gresource.xml
+++ b/ui/org.gnome.Geary.gresource.xml
@@ -46,7 +46,6 @@
     <file compressed="true" preprocess="xml-stripblanks">password-dialog.glade</file>
     <file compressed="true" preprocess="xml-stripblanks">problem-details-dialog.ui</file>
     <file compressed="true">signature-web-view.js</file>
-    <file compressed="true" preprocess="xml-stripblanks">upgrade_dialog.glade</file>
     <file compressed="true">geary.css</file>
     <file compressed="true">single-key-shortcuts.css</file>
   </gresource>


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