Merge branch 'mjog/upgrade-dialog-cleanup' into 'mainline'

client: Clean up database upgrade dialog implementation

Closes #1007

See merge request GNOME/geary!634
This commit is contained in:
Michael Gratton 2021-01-19 13:43:02 +00:00
commit 851f13d47f
8 changed files with 134 additions and 216 deletions

View file

@ -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

View file

@ -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

View file

@ -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;
}
}
}

View file

@ -1,95 +0,0 @@
/* Copyright 2016 Software Freedom Conservancy Inc.
*
* This software is licensed under the GNU Lesser General Public License
* (version 2.1 or later). See the COPYING file in this distribution.
*/
public class UpgradeDialog : Object {
public const string PROP_VISIBLE_NAME = "visible";
// Progress monitor associated with the upgrade.
public Geary.AggregateProgressMonitor monitor { public get; private set;
default = new Geary.AggregateProgressMonitor(); }
// Whether or not this dialog is visible.
public bool visible { get; set; }
private weak Application.Client application;
private Gtk.Dialog? dialog = null;
private Gee.HashSet<Cancellable> cancellables = new Gee.HashSet<Cancellable>();
/**
* Creates and loads the upgrade progress dialog.
*/
public UpgradeDialog(Application.Client application) {
this.application = application;
// Load UI.
// Hook up signals.
monitor.start.connect(on_start);
monitor.finish.connect(on_close);
}
private void on_start() {
// Disable main windows
foreach (Application.MainWindow window in this.application.get_main_windows()) {
window.sensitive = false;
}
Gtk.Builder builder = GioUtil.create_builder("upgrade_dialog.glade");
this.dialog = (Gtk.Dialog) builder.get_object("dialog");
this.dialog.set_transient_for(
this.application.get_active_main_window()
);
this.dialog.delete_event.connect(on_delete_event);
this.dialog.show();
}
private bool on_delete_event() {
// Don't allow window to close until we're finished.
return !monitor.is_in_progress;
}
private void on_close() {
// If the user quit the dialog before the upgrade completed, cancel everything.
if (monitor.is_in_progress) {
foreach(Cancellable c in cancellables)
c.cancel();
}
if (this.dialog != null &&
this.dialog.visible) {
this.dialog.hide();
this.dialog = null;
}
// Enable main windows
foreach (Application.MainWindow window in this.application.get_main_windows()) {
window.sensitive = true;
}
}
/**
* 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);
}
}

View file

@ -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',

View file

@ -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;
}

View file

@ -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>

View file

@ -1,113 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.14 -->
<object class="GtkDialog" id="dialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="resizable">False</property>
<property name="window_position">center</property>
<property name="type_hint">dialog</property>
<property name="deletable">False</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area1">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="grid1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">8</property>
<property name="margin_end">8</property>
<property name="margin_top">8</property>
<property name="margin_bottom">8</property>
<property name="row_spacing">8</property>
<property name="column_spacing">8</property>
<child>
<object class="GtkSpinner" id="spinner1">
<property name="width_request">45</property>
<property name="height_request">45</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="active">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="text_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Geary update in progress…</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">2</property>
</packing>
</child>
<child>
<object class="GtkAlignment" id="alignment2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>