<<< Date Index >>>     <<< Thread Index >>>

[PATCH] Sort the 'Incoming' buffy list



 buffy.c |  41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)


# HG changeset patch
# User Jan Larres <jan@xxxxxxxxxxxxxx>
# Date 1238600385 -7200
# Branch buffysort
# Node ID 102051634e013818d31d36f6d83542e0d4422619
# Parent  8205a12329d395b87eeb890cb86d28e761e83992
Sort the 'Incoming' buffy list

Sort the 'Incoming' buffy list with regard to the sort_browser option.
Sorting by date and size is unfortunately not possible since this data is
not present in the buffy structure, but alpha (and unsorted of course)
works fine.
This is primarily useful for the sidebar patch since it displays the
mailboxes in the 'Incoming' list order, but it doesn't depend on the
sidebar at all and might be useful in other cases, too.

diff -r 8205a12329d3 -r 102051634e01 buffy.c
--- a/buffy.c   Wed Apr 01 14:33:35 2009 +0200
+++ b/buffy.c   Wed Apr 01 17:39:45 2009 +0200
@@ -24,6 +24,7 @@
 #include "buffy.h"
 #include "mailbox.h"
 #include "mx.h"
+#include "sort.h"
 
 #include "mutt_curses.h"
 
@@ -134,6 +135,45 @@
   return rc;
 }
 
+static int buffy_compare_name(const void *a, const void *b) {
+  const BUFFY *b1 = * (BUFFY * const *) a;
+  const BUFFY *b2 = * (BUFFY * const *) b;
+
+  return mutt_strcoll(b1->path, b2->path);
+}
+
+static BUFFY *buffy_sort(BUFFY *b)
+{
+  BUFFY *tmp = b;
+  int buffycount = 0;
+  BUFFY **ary;
+  int i;
+
+  if ((BrowserSort & SORT_MASK) != SORT_ALPHA)
+    return b;
+
+  for (; tmp != NULL; tmp = tmp->next)
+    buffycount++;
+
+  ary = (BUFFY **) safe_calloc(buffycount, sizeof (*ary));
+
+  tmp = b;
+  for (i = 0; tmp != NULL; tmp = tmp->next, i++) {
+    ary[i] = tmp;
+  }
+
+  qsort(ary, buffycount, sizeof(*ary), buffy_compare_name);
+
+  for (i = 0; i < buffycount - 1; i++) {
+    ary[i]->next = ary[i+1];
+  }
+  ary[buffycount - 1]->next = NULL;
+
+  tmp = ary[0];
+  free(ary);
+  return tmp;
+}
+
 BUFFY *mutt_find_mailbox (const char *path)
 {
   BUFFY *tmp = NULL;
@@ -240,6 +280,7 @@
     else
       (*tmp)->size = 0;
   }
+  Incoming = buffy_sort(Incoming);
   return 0;
 }