[geary/wip/765516-gtk-widget-conversation-viewer: 162/174] Move conversation loading timout mgmt to ConversationListBox.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/765516-gtk-widget-conversation-viewer: 162/174] Move conversation loading timout mgmt to ConversationListBox.
- Date: Sun, 25 Sep 2016 13:19:40 +0000 (UTC)
commit f7230afca01976d1e8521553e5c32a45ed332fb0
Author: Michael James Gratton <mike vee net>
Date: Sun Sep 18 21:19:08 2016 +1000
Move conversation loading timout mgmt to ConversationListBox.
.../conversation-viewer/conversation-listbox.vala | 33 ++++++++++++++++++-
.../conversation-viewer/conversation-viewer.vala | 27 ++--------------
2 files changed, 35 insertions(+), 25 deletions(-)
---
diff --git a/src/client/conversation-viewer/conversation-listbox.vala
b/src/client/conversation-viewer/conversation-listbox.vala
index 87c1aad..b1a365d 100644
--- a/src/client/conversation-viewer/conversation-listbox.vala
+++ b/src/client/conversation-viewer/conversation-listbox.vala
@@ -40,6 +40,9 @@ public class ConversationListBox : Gtk.ListBox {
// account.
private const int EMAIL_TOP_OFFSET = 92;
+ // Loading spinner timeout
+ private const int LOADING_TIMEOUT_MSEC = 150;
+
// Custom class used to display ConversationEmail views in the
// conversation listbox.
@@ -180,6 +183,8 @@ public class ConversationListBox : Gtk.ListBox {
// Cached search terms to apply to new messages
private Gee.Set<string>? ordered_search_terms = null;
+ private uint loading_timeout_id = 0;
+
/** Fired when an email view is added to the conversation list. */
public signal void email_added(ConversationEmail email);
@@ -229,9 +234,23 @@ public class ConversationListBox : Gtk.ListBox {
this.conversation.appended.connect(on_conversation_appended);
this.conversation.trimmed.connect(on_conversation_trimmed);
this.conversation.email_flags_changed.connect(on_update_flags);
+
+ // If the load is taking too long, display a spinner
+ this.loading_timeout_id =
+ Timeout.add(LOADING_TIMEOUT_MSEC, () => {
+ if (this.loading_timeout_id != 0) {
+ debug("Loading timed out\n");
+ show_loading();
+ }
+ this.loading_timeout_id = 0;
+ return false;
+ });
}
public override void destroy() {
+ if (this.loading_timeout_id != 0) {
+ Source.remove(this.loading_timeout_id);
+ }
this.cancellable.cancel();
this.id_to_row.clear();
base.destroy();
@@ -252,7 +271,7 @@ public class ConversationListBox : Gtk.ListBox {
// Add them all
foreach (Geary.Email full_email in full_emails) {
if (this.cancellable.is_cancelled()) {
- return;
+ break;
}
if (!this.id_to_row.contains(full_email.id)) {
EmailRow row = add_email(full_email);
@@ -293,9 +312,12 @@ public class ConversationListBox : Gtk.ListBox {
}
}
});
-
+
debug("Conversation loading complete");
}
+
+ this.loading_timeout_id = 0;
+ set_placeholder(null);
}
/**
@@ -638,6 +660,13 @@ public class ConversationListBox : Gtk.ListBox {
}
}
+ private void show_loading() {
+ Gtk.Spinner spinner = new Gtk.Spinner();
+ spinner.start();
+ spinner.show();
+ set_placeholder(spinner);
+ }
+
private void scroll_to(EmailRow row) {
Gtk.Allocation? alloc = null;
row.get_allocation(out alloc);
diff --git a/src/client/conversation-viewer/conversation-viewer.vala
b/src/client/conversation-viewer/conversation-viewer.vala
index 7c1617c..a13d283 100644
--- a/src/client/conversation-viewer/conversation-viewer.vala
+++ b/src/client/conversation-viewer/conversation-viewer.vala
@@ -12,8 +12,6 @@
[GtkTemplate (ui = "/org/gnome/Geary/conversation-viewer.ui")]
public class ConversationViewer : Gtk.Stack {
- private const int SELECT_CONVERSATION_TIMEOUT_MSEC = 100;
-
/**
* The current conversation listbox, if any.
*/
@@ -59,8 +57,6 @@ public class ConversationViewer : Gtk.Stack {
[GtkChild]
private Gtk.Button conversation_find_prev;
- private uint conversation_timeout_id = 0;
-
/* Emitted when a new conversation list was added to this view. */
public signal void conversation_added(ConversationListBox list);
@@ -170,22 +166,6 @@ public class ConversationViewer : Gtk.Stack {
public async void load_conversation(Geary.App.Conversation conversation,
Geary.Folder location)
throws Error {
- // If the load is taking too long, display the spinner
- if (this.conversation_timeout_id != 0) {
- Source.remove(this.conversation_timeout_id);
- }
- this.conversation_timeout_id =
- Timeout.add(SELECT_CONVERSATION_TIMEOUT_MSEC, () => {
- if (this.conversation_timeout_id != 0) {
- debug("Loading timed out\n");
- // XXX should disable message buttons here, so
- // need to move this timer to the controller.
- show_loading();
- }
- this.conversation_timeout_id = 0;
- return false;
- });
-
Geary.Account account = location.account;
ConversationListBox new_list = new ConversationListBox(
conversation,
@@ -202,7 +182,6 @@ public class ConversationViewer : Gtk.Stack {
// during loading.
this.conversation_added(new_list);
- yield new_list.load_conversation();
// Also set up find infrastructure early so matching emails
// are expanded and highlighted as they are added.
this.conversation_find_next.set_sensitive(false);
@@ -219,7 +198,9 @@ public class ConversationViewer : Gtk.Stack {
remove_current_list();
add_new_list(new_list);
set_visible_child(this.conversation_page);
- this.conversation_timeout_id = 0;
+
+ yield new_list.load_conversation();
+
// Highlight matching terms from the search if it exists, but
// don't clobber any find terms.
if (find_terms == null && location is Geary.SearchFolder) {
@@ -270,7 +251,7 @@ public class ConversationViewer : Gtk.Stack {
}
base.set_visible_child(widget);
}
-
+
private Gee.Set<string>? get_find_search_terms() {
Gee.Set<string>? terms = null;
string search = this.conversation_find_entry.get_text().strip();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]