[balsa] remember previous sort field



commit 3405bbc0e1673c5458ad8145d2cfda32b8c86b78
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Wed Apr 29 18:34:10 2009 -0400

    remember previous sort field
---
 ChangeLog          |    9 +++++++++
 libbalsa/mailbox.c |   28 +++++++++++++++++++++++++++-
 libbalsa/mailbox.h |    1 +
 3 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 04bc309..c1f7dfa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-04-29  Peter Bloomfield
+
+	* libbalsa/mailbox.h: new member sort_field_prev in
+	LibBalsaMailboxView.
+	* libbalsa/mailbox.c (libbalsa_mailbox_set_sort_field,
+	mbox_compare_func, mbox_set_sort_column_id): use it to save
+	previous sort_field, and to resolve ties wrt current
+	sort_field--work around for lack of a stable mailbox sort.
+
 2009-04-23  Peter Bloomfield
 
 	bump version to 2.4.0, and require GMime-2.4, GLib-2.16, and
diff --git a/libbalsa/mailbox.c b/libbalsa/mailbox.c
index 9c6110a..f1378ef 100644
--- a/libbalsa/mailbox.c
+++ b/libbalsa/mailbox.c
@@ -2134,6 +2134,7 @@ static LibBalsaMailboxView libbalsa_mailbox_view_default = {
     0,				/* filter               */
     LB_MAILBOX_SORT_TYPE_ASC,	/* sort_type            */
     LB_MAILBOX_SORT_NO,         /* sort_field           */
+    LB_MAILBOX_SORT_NO,         /* sort_field_prev      */
     LB_MAILBOX_SHOW_UNSET,	/* show                 */
     LB_MAILBOX_SUBSCRIBE_UNSET,	/* subscribe            */
     0,				/* exposed              */
@@ -2247,6 +2248,7 @@ libbalsa_mailbox_set_sort_field(LibBalsaMailbox * mailbox,
     LibBalsaMailboxView *view = lbm_get_view(mailbox);
 
     if (!view->frozen && view->sort_field != sort_field) {
+	view->sort_field_prev = view->sort_field;
 	view->sort_field = sort_field;
 	if (mailbox)
 	    view->in_sync = 0;
@@ -3273,6 +3275,27 @@ mbox_compare_func(const SortTuple * a,
 	    retval = 0;
 	    break;
 	}
+
+        if (retval == 0) {
+            /* resolve ties using previous sort column */
+            switch (mbox->view->sort_field_prev) {
+            case LB_MAILBOX_SORT_SENDER:
+                retval = mbox_compare_from(message_a, message_b);
+                break;
+            case LB_MAILBOX_SORT_SUBJECT:
+                retval = mbox_compare_subject(message_a, message_b);
+                break;
+            case LB_MAILBOX_SORT_DATE:
+                retval = mbox_compare_date(message_a, message_b);
+                break;
+            case LB_MAILBOX_SORT_SIZE:
+                retval = mbox_compare_size(message_a, message_b);
+                break;
+            default:
+                retval = 0;
+                break;
+            }
+        }
     }
 
     if (mbox->view->sort_type == LB_MAILBOX_SORT_TYPE_DESC) {
@@ -3481,7 +3504,10 @@ mbox_set_sort_column_id(GtkTreeSortable * sortable,
     if (view->sort_field == new_field && view->sort_type == new_type)
         return;
 
-    view->sort_field = new_field;
+    if (view->sort_field != new_field) {
+        view->sort_field_prev = view->sort_field;
+        view->sort_field = new_field;
+    }
     view->sort_type = new_type;
     view->in_sync = 0;
 
diff --git a/libbalsa/mailbox.h b/libbalsa/mailbox.h
index 0c1e626..4b3f755 100644
--- a/libbalsa/mailbox.h
+++ b/libbalsa/mailbox.h
@@ -174,6 +174,7 @@ struct _LibBalsaMailboxView {
     int      filter; 
     LibBalsaMailboxSortType      sort_type;
     LibBalsaMailboxSortFields    sort_field;
+    LibBalsaMailboxSortFields    sort_field_prev;
     LibBalsaMailboxShow          show;
     LibBalsaMailboxSubscribe     subscribe;
     gboolean exposed;



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