[geary/wip/713150-conversations] Load more was broken. Fixed by adding signals.



commit cdd7e10bf086f0d817c854758608bc33c8fd8ff8
Author: Jim Nelson <jim yorba org>
Date:   Wed Mar 18 18:40:10 2015 -0700

    Load more was broken.  Fixed by adding signals.
    
    Also, load more now accurately loads a percentage of the conversation
    list view's height instead of a constant number.

 src/client/application/geary-controller.vala |   17 +++++---
 src/engine/app/app-conversation-monitor.vala |   52 +++++++++++++++-----------
 2 files changed, 41 insertions(+), 28 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index db5cc7b..72cd066 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -57,8 +57,7 @@ public class GearyController : Geary.BaseObject {
     
     public const string PROP_CURRENT_CONVERSATION ="current-conversations";
     
-    private const int INITIAL_CONVERSATION_COUNT = 0;
-    private const int LOAD_MORE_CONVERSATION_COUNT = 10;
+    private const double LOAD_MORE_PERCENTAGE = 0.40;
     
     private const string DELETE_MESSAGE_TOOLTIP_SINGLE = _("Delete conversation (Shift+Delete)");
     private const string DELETE_MESSAGE_TOOLTIP_MULTIPLE = _("Delete conversations (Shift+Delete)");
@@ -1454,7 +1453,7 @@ public class GearyController : Geary.BaseObject {
         update_ui();
         
         current_conversations = new Geary.App.ConversationMonitor(current_folder, 
Geary.Folder.OpenFlags.NO_DELAY,
-            ConversationListStore.REQUIRED_FIELDS, INITIAL_CONVERSATION_COUNT);
+            ConversationListStore.REQUIRED_FIELDS, 0);
         
         if (inboxes.values.contains(current_folder)) {
             // Inbox selected, clear new messages if visible
@@ -1581,17 +1580,23 @@ public class GearyController : Geary.BaseObject {
     }
     
     private void on_load_more() {
-        if (current_conversations == null || current_conversations.all_mail_loaded)
+        if (current_conversations == null || current_conversations.all_mail_loaded || !cell_dimensions.valid)
             return;
         
+        // load in enough conversations to fill a fraction of the conversation list's height
+        double list_height = main_window.conversation_list_view.get_allocated_height();
+        double cell_height = cell_dimensions.cell_height;
+        double fraction = Math.round((list_height / cell_height) * LOAD_MORE_PERCENTAGE);
+        int load_more = Geary.Numeric.int_floor((int) fraction, 2);
+        
         int orig = current_conversations.min_window_count;
         
         // It's possible for the conversation count to be any value above or below the min_window_count,
         // so ensure *some* increase happens to trigger loading more conversations
         current_conversations.min_window_count =
-            current_conversations.get_conversation_count() + LOAD_MORE_CONVERSATION_COUNT;
+            current_conversations.get_conversation_count() + load_more;
         if (current_conversations.min_window_count <= orig)
-            current_conversations.min_window_count = orig + LOAD_MORE_CONVERSATION_COUNT;
+            current_conversations.min_window_count = orig + load_more;
     }
     
     private void on_select_folder_completed(Object? source, AsyncResult result) {
diff --git a/src/engine/app/app-conversation-monitor.vala b/src/engine/app/app-conversation-monitor.vala
index 425f46e..7a16496 100644
--- a/src/engine/app/app-conversation-monitor.vala
+++ b/src/engine/app/app-conversation-monitor.vala
@@ -477,6 +477,33 @@ public class Geary.App.ConversationMonitor : BaseObject {
         }
     }
     
+    private async void load_associations_async(FolderSupport.Associations supports_associations,
+        Geary.EmailIdentifier? low_id, int count, Cancellable? cancellable) {
+        int start_conversations = get_conversation_count();
+        
+        notify_scan_started();
+        
+        SearchPredicateInstance predicate_instance = new SearchPredicateInstance(folder, required_fields);
+        
+        Gee.Collection<AssociatedEmails>? associations = null;
+        Gee.Collection<EmailIdentifier> primary_email_ids = new Gee.HashSet<EmailIdentifier>();
+        try {
+            associations = yield supports_associations.local_list_associated_emails_async(
+                low_id, count, predicate_instance.search_predicate, primary_email_ids, cancellable);
+        } catch (Error err) {
+            debug("Unable to load associated emails from %s: %s", supports_associations.to_string(),
+                err.message);
+            notify_scan_error(err);
+        }
+        
+        if (associations != null && associations.size > 0) {
+            yield process_associations_async(supports_associations.path, associations, primary_email_ids,
+                cancellable);
+        }
+        
+        notify_scan_completed(start_conversations < get_conversation_count());
+    }
+    
     private async void process_email_async(FolderPath path, Gee.Collection<Geary.Email>? emails,
         Cancellable? cancellable) {
         if (emails == null || emails.size == 0)
@@ -518,27 +545,6 @@ public class Geary.App.ConversationMonitor : BaseObject {
             folder.to_string(), email_ids.size);
     }
     
-    private async void load_associations_async(FolderSupport.Associations supports_associations,
-        Geary.EmailIdentifier? low_id, int count, Cancellable? cancellable) {
-        SearchPredicateInstance predicate_instance = new SearchPredicateInstance(folder, required_fields);
-        
-        Gee.Collection<AssociatedEmails>? associations = null;
-        Gee.Collection<EmailIdentifier> primary_email_ids = new Gee.HashSet<EmailIdentifier>();
-        try {
-            associations = yield supports_associations.local_list_associated_emails_async(
-                low_id, count, predicate_instance.search_predicate, primary_email_ids, cancellable);
-        } catch (Error err) {
-            debug("Unable to load associated emails from %s: %s", supports_associations.to_string(),
-                err.message);
-        }
-        
-        if (associations == null || associations.size == 0)
-            return;
-        
-        yield process_associations_async(supports_associations.path, associations, primary_email_ids,
-            cancellable);
-    }
-    
     private async void process_associations_async(FolderPath path, Gee.Collection<AssociatedEmails> 
associations,
         Gee.Collection<Geary.EmailIdentifier> original_email_ids, Cancellable? cancellable) {
         Gee.HashSet<Conversation> added = new Gee.HashSet<Conversation>();
@@ -869,7 +875,9 @@ public class Geary.App.ConversationMonitor : BaseObject {
         
         if (!is_insert && supports_associations != null) {
             // easy case: just load in the Associations straight from the folder; this is (almost)
-            // guaranteed to fill to the right amount every time
+            // guaranteed to fill to the right amount every time -- the exception is when it
+            // returns associations for existing conversations (i.e. the primary email id was
+            // loaded earlier as an association and is now being loaded as a primary)
             yield load_associations_async(supports_associations, low_id,
                 min_window_count - conversations.size, cancellable_monitor);
             


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