Commit a2546b52 authored by Eric Gregory's avatar Eric Gregory

Fixes #4644 Spinner fix, part deux

parent a1e7604a
......@@ -5,7 +5,7 @@
*/
// Primary controller object for Geary.
public class GearyController {
public class GearyController : Geary.BaseObject {
// Named actions.
public const string ACTION_HELP = "GearyHelp";
public const string ACTION_ABOUT = "GearyAbout";
......@@ -32,7 +32,9 @@ public class GearyController {
public const string ACTION_COPY_MENU = "GearyCopyMenuButton";
public const string ACTION_MOVE_MENU = "GearyMoveMenuButton";
public const string ACTION_GEAR_MENU = "GearyGearMenuButton";
public const string PROP_CURRENT_CONVERSATION ="current-conversations";
public const int MIN_CONVERSATION_COUNT = 50;
private const string DELETE_MESSAGE_LABEL = _("_Delete");
......@@ -62,11 +64,12 @@ public class GearyController {
public MainWindow main_window { get; private set; }
public Geary.App.ConversationMonitor? current_conversations { get; private set; default = null; }
private Geary.Account? current_account = null;
private Gee.HashMap<Geary.Account, Geary.Folder> inboxes
= new Gee.HashMap<Geary.Account, Geary.Folder>();
private Geary.Folder? current_folder = null;
private Geary.App.ConversationMonitor? current_conversations = null;
private Cancellable cancellable_folder = new Cancellable();
private Cancellable cancellable_message = new Cancellable();
private Cancellable cancellable_search = new Cancellable();
......@@ -758,7 +761,6 @@ public class GearyController {
if (current_conversations != null) {
yield current_conversations.stop_monitoring_async(!current_is_inbox, null);
current_conversations = null;
main_window.set_progress_monitor(null);
} else if (current_folder != null && !current_is_inbox) {
yield current_folder.close_async();
}
......@@ -800,10 +802,6 @@ public class GearyController {
current_conversations.scan_error.connect(on_scan_error);
current_conversations.seed_completed.connect(on_seed_completed);
main_window.conversation_list_store.set_conversation_monitor(current_conversations);
main_window.conversation_list_view.set_conversation_monitor(current_conversations);
main_window.set_progress_monitor(current_conversations.progress_monitor);
if (!current_conversations.is_monitoring)
yield current_conversations.start_monitoring_async(conversation_cancellable);
......
......@@ -36,6 +36,8 @@ public class ConversationListStore : Gtk.ListStore {
}
public string? account_owner_email { get; set; default = null; }
public Geary.ProgressMonitor preview_monitor { get; private set; default =
new Geary.SimpleProgressMonitor(Geary.ProgressType.ACTIVITY); }
private Geary.App.ConversationMonitor conversation_monitor;
private Geary.Folder? current_folder = null;
......@@ -56,16 +58,17 @@ public class ConversationListStore : Gtk.ListStore {
GearyApplication.instance.config.display_preview_changed.connect(on_display_preview_changed);
update_id = Timeout.add_seconds_full(Priority.LOW, 60, update_date_strings);
GearyApplication.instance.controller.notify[GearyController.PROP_CURRENT_CONVERSATION].
connect(on_conversation_monitor_changed);
}
~ConversationListStore() {
set_conversation_monitor(null);
if (update_id != 0)
Source.remove(update_id);
}
public void set_conversation_monitor(Geary.App.ConversationMonitor? new_conversation_monitor) {
private void on_conversation_monitor_changed() {
if (conversation_monitor != null) {
conversation_monitor.scan_completed.disconnect(on_scan_completed);
conversation_monitor.conversations_added.disconnect(on_conversations_added);
......@@ -76,7 +79,7 @@ public class ConversationListStore : Gtk.ListStore {
}
clear();
conversation_monitor = new_conversation_monitor;
conversation_monitor = GearyApplication.instance.controller.current_conversations;
if (conversation_monitor != null) {
// add all existing conversations
......@@ -148,8 +151,12 @@ public class ConversationListStore : Gtk.ListStore {
return;
}
preview_monitor.notify_start();
yield do_refresh_previews_async(conversation_monitor);
preview_monitor.notify_finish();
try {
refresh_mutex.release(ref token);
} catch (Error err) {
......
......@@ -23,6 +23,8 @@ public class MainWindow : Gtk.Window {
private Gtk.ScrolledWindow conversation_list_scrolled;
private MonitoredSpinner spinner = new MonitoredSpinner();
private Geary.AggregateProgressMonitor progress_monitor = new Geary.AggregateProgressMonitor();
private Geary.ProgressMonitor? conversation_monitor_progress = null;
public MainWindow() {
title = GearyApplication.NAME;
......@@ -42,12 +44,19 @@ public class MainWindow : Gtk.Window {
add_accel_group(GearyApplication.instance.ui_manager.get_accel_group());
spinner.set_progress_monitor(progress_monitor);
progress_monitor.add(conversation_list_store.preview_monitor);
GLib.List<Gdk.Pixbuf> pixbuf_list = new GLib.List<Gdk.Pixbuf>();
pixbuf_list.append(IconFactory.instance.application_icon);
set_default_icon_list(pixbuf_list);
delete_event.connect(on_delete_event);
key_press_event.connect(on_key_press_event);
GearyApplication.instance.controller.notify[GearyController.PROP_CURRENT_CONVERSATION].
connect(on_conversation_monitor_changed);
Geary.Engine.instance.account_available.connect(on_account_available);
Geary.Engine.instance.account_unavailable.connect(on_account_unavailable);
create_layout();
}
......@@ -82,13 +91,6 @@ public class MainWindow : Gtk.Window {
return base.configure_event(event);
}
/**
* Sets the progress monitor to display in the status bar.
*/
public void set_progress_monitor(Geary.ProgressMonitor? monitor) {
spinner.set_progress_monitor(monitor);
}
private void create_layout() {
Gtk.Box main_layout = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
......@@ -146,5 +148,38 @@ public class MainWindow : Gtk.Window {
// via the default handling
return propagate_key_event(event);
}
private void on_conversation_monitor_changed() {
Geary.App.ConversationMonitor? conversation_monitor =
GearyApplication.instance.controller.current_conversations;
// Remove existing progress monitor.
if (conversation_monitor_progress != null) {
progress_monitor.remove(conversation_monitor_progress);
conversation_monitor_progress = null;
}
// Add new one.
if (conversation_monitor != null) {
conversation_monitor_progress = conversation_monitor.progress_monitor;
progress_monitor.add(conversation_monitor_progress);
}
}
private void on_account_available(Geary.AccountInformation account) {
try {
progress_monitor.add(Geary.Engine.instance.get_account_instance(account).opening_monitor);
} catch (Error e) {
debug("Could not access account opening progress monitor: %s", e.message);
}
}
private void on_account_unavailable(Geary.AccountInformation account) {
try {
progress_monitor.remove(Geary.Engine.instance.get_account_instance(account).opening_monitor);
} catch (Error e) {
debug("Could not access account opening progress monitor: %s", e.message);
}
}
}
......@@ -64,16 +64,18 @@ public class ConversationListView : Gtk.TreeView {
Gdk.DragAction.COPY | Gdk.DragAction.MOVE);
GearyApplication.instance.config.display_preview_changed.connect(on_display_preview_changed);
GearyApplication.instance.controller.notify[GearyController.PROP_CURRENT_CONVERSATION].
connect(on_conversation_monitor_changed);
}
public void set_conversation_monitor(Geary.App.ConversationMonitor? new_conversation_monitor) {
private void on_conversation_monitor_changed() {
if (conversation_monitor != null) {
conversation_monitor.scan_started.disconnect(on_scan_started);
conversation_monitor.scan_completed.disconnect(on_scan_completed);
conversation_monitor.conversation_removed.disconnect(on_conversation_removed);
}
conversation_monitor = new_conversation_monitor;
conversation_monitor = GearyApplication.instance.controller.current_conversations;
if (conversation_monitor != null) {
conversation_monitor.scan_started.connect(on_scan_started);
......
......@@ -8,6 +8,7 @@ public abstract class Geary.AbstractAccount : BaseObject, Geary.Account {
public Geary.AccountInformation information { get; protected set; }
public Geary.ProgressMonitor search_upgrade_monitor { get; protected set; }
public Geary.ProgressMonitor db_upgrade_monitor { get; protected set; }
public Geary.ProgressMonitor opening_monitor { get; protected set; }
private string name;
......
......@@ -17,6 +17,7 @@ public interface Geary.Account : BaseObject {
public abstract Geary.ProgressMonitor search_upgrade_monitor { get; protected set; }
public abstract Geary.ProgressMonitor db_upgrade_monitor { get; protected set; }
public abstract Geary.ProgressMonitor opening_monitor { get; protected set; }
public signal void opened();
......
......@@ -172,6 +172,28 @@ public class Geary.AggregateProgressMonitor : Geary.ProgressMonitor {
pm.finish.connect(on_finish);
}
public void remove(Geary.ProgressMonitor pm) {
// TODO: Handle the case where we remove a new monitor during progress.
monitors.remove(pm);
pm.start.disconnect(on_start);
pm.update.disconnect(on_update);
pm.finish.disconnect(on_finish);
if (pm.is_in_progress) {
// If no other PMs are in progress, we must issue a finish signal.
bool issue_signal = true;
foreach(ProgressMonitor p in monitors) {
if (p.is_in_progress) {
issue_signal = false;
break;
}
}
if (issue_signal)
notify_finish();
}
}
private void on_start() {
if (!is_in_progress)
notify_start();
......
......@@ -33,6 +33,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
search_upgrade_monitor = local.search_index_monitor;
db_upgrade_monitor = local.upgrade_monitor;
opening_monitor = new Geary.SimpleProgressMonitor(Geary.ProgressType.ACTIVITY);
if (outbox_path == null) {
outbox_path = new SmtpOutboxFolderRoot();
......@@ -245,6 +246,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
private bool on_refresh_folders() {
in_refresh_enumerate = true;
opening_monitor.notify_start();
enumerate_folders_async.begin(refresh_cancellable, on_refresh_completed);
refresh_folder_timeout_id = 0;
......@@ -253,6 +255,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
}
private void on_refresh_completed(Object? source, AsyncResult result) {
opening_monitor.notify_finish();
try {
enumerate_folders_async.end(result);
} catch (Error err) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment