NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
sort.c File Reference

Sidebar sort functions. More...

#include "config.h"
#include <stdbool.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "sort.h"
#include "muttlib.h"
+ Include dependency graph for sort.c:

Go to the source code of this file.

Functions

static int sb_sort_count (const void *a, const void *b)
 Sort Sidebar entries by count - Implements sort_t. More...
 
static int sb_sort_desc (const void *a, const void *b)
 Sort Sidebar entries by description - Implements sort_t. More...
 
static int sb_sort_flagged (const void *a, const void *b)
 Sort Sidebar entries by flagged - Implements sort_t. More...
 
static int sb_sort_path (const void *a, const void *b)
 Sort Sidebar entries by path - Implements sort_t. More...
 
static int sb_sort_unread (const void *a, const void *b)
 Sort Sidebar entries by unread - Implements sort_t. More...
 
static int sb_sort_order (const void *a, const void *b)
 Sort Sidebar entries by order of creation - Implements sort_t. More...
 
static int sb_sort_unsorted (const void *a, const void *b)
 Sort Sidebar entries into their original order - Implements sort_t. More...
 
void sb_sort_entries (struct SidebarWindowData *wdata, enum SortType sort)
 Sort the Sidebar entries. More...
 

Variables

static bool sb_sort_reverse = false
 An extra parameter to control sort order. More...
 

Detailed Description

Sidebar sort functions.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file sort.c.

Function Documentation

◆ sb_sort_count()

static int sb_sort_count ( const void *  a,
const void *  b 
)
static

Sort Sidebar entries by count - Implements sort_t.

Definition at line 44 of file sort.c.

45 {
46  const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
47  const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
48  const struct Mailbox *m1 = sbe1->mailbox;
49  const struct Mailbox *m2 = sbe2->mailbox;
50 
51  int rc = 0;
52  if (m1->msg_count == m2->msg_count)
54  else
55  rc = (m2->msg_count - m1->msg_count);
56 
57  if (sb_sort_reverse)
58  rc = -rc;
59  return rc;
60 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:215
int msg_count
Total number of messages.
Definition: mailbox.h:91
Info about folders in the sidebar.
Definition: private.h:39
int mutt_str_coll(const char *a, const char *b)
Collate two strings (compare using locale), safely.
Definition: string.c:677
struct Mailbox * mailbox
Mailbox this represents.
Definition: private.h:44
A mailbox.
Definition: mailbox.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_sort_desc()

static int sb_sort_desc ( const void *  a,
const void *  b 
)
static

Sort Sidebar entries by description - Implements sort_t.

Definition at line 65 of file sort.c.

66 {
67  const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
68  const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
69  const struct Mailbox *m1 = sbe1->mailbox;
70  const struct Mailbox *m2 = sbe2->mailbox;
71 
72  int rc = mutt_str_cmp(m1->name, m2->name);
73 
74  if (sb_sort_reverse)
75  rc = -rc;
76  return rc;
77 }
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:567
Info about folders in the sidebar.
Definition: private.h:39
struct Mailbox * mailbox
Mailbox this represents.
Definition: private.h:44
char * name
A short name for the Mailbox.
Definition: mailbox.h:85
A mailbox.
Definition: mailbox.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_sort_flagged()

static int sb_sort_flagged ( const void *  a,
const void *  b 
)
static

Sort Sidebar entries by flagged - Implements sort_t.

Definition at line 82 of file sort.c.

83 {
84  const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
85  const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
86  const struct Mailbox *m1 = sbe1->mailbox;
87  const struct Mailbox *m2 = sbe2->mailbox;
88 
89  int rc = 0;
90  if (m1->msg_flagged == m2->msg_flagged)
92  else
93  rc = (m2->msg_flagged - m1->msg_flagged);
94 
95  if (sb_sort_reverse)
96  rc = -rc;
97  return rc;
98 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:215
int msg_flagged
Number of flagged messages.
Definition: mailbox.h:93
Info about folders in the sidebar.
Definition: private.h:39
int mutt_str_coll(const char *a, const char *b)
Collate two strings (compare using locale), safely.
Definition: string.c:677
struct Mailbox * mailbox
Mailbox this represents.
Definition: private.h:44
A mailbox.
Definition: mailbox.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_sort_path()

static int sb_sort_path ( const void *  a,
const void *  b 
)
static

Sort Sidebar entries by path - Implements sort_t.

Definition at line 103 of file sort.c.

104 {
105  const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
106  const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
107  const struct Mailbox *m1 = sbe1->mailbox;
108  const struct Mailbox *m2 = sbe2->mailbox;
109 
110  int rc = 0;
112  if (rc == 0)
113  rc = mutt_str_coll(mailbox_path(m1), mailbox_path(m2));
114 
115  if (sb_sort_reverse)
116  rc = -rc;
117  return rc;
118 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:215
Info about folders in the sidebar.
Definition: private.h:39
int mutt_str_coll(const char *a, const char *b)
Collate two strings (compare using locale), safely.
Definition: string.c:677
struct Mailbox * mailbox
Mailbox this represents.
Definition: private.h:44
A mailbox.
Definition: mailbox.h:81
int mutt_inbox_cmp(const char *a, const char *b)
do two folders share the same path and one is an inbox
Definition: muttlib.c:1611
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_sort_unread()

static int sb_sort_unread ( const void *  a,
const void *  b 
)
static

Sort Sidebar entries by unread - Implements sort_t.

Definition at line 123 of file sort.c.

124 {
125  const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
126  const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
127  const struct Mailbox *m1 = sbe1->mailbox;
128  const struct Mailbox *m2 = sbe2->mailbox;
129 
130  int rc = 0;
131  if (m1->msg_unread == m2->msg_unread)
132  rc = mutt_str_coll(mailbox_path(m1), mailbox_path(m2));
133  else
134  rc = (m2->msg_unread - m1->msg_unread);
135 
136  if (sb_sort_reverse)
137  rc = -rc;
138  return rc;
139 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:215
int msg_unread
Number of unread messages.
Definition: mailbox.h:92
Info about folders in the sidebar.
Definition: private.h:39
int mutt_str_coll(const char *a, const char *b)
Collate two strings (compare using locale), safely.
Definition: string.c:677
struct Mailbox * mailbox
Mailbox this represents.
Definition: private.h:44
A mailbox.
Definition: mailbox.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_sort_order()

static int sb_sort_order ( const void *  a,
const void *  b 
)
static

Sort Sidebar entries by order of creation - Implements sort_t.

Definition at line 144 of file sort.c.

145 {
146  const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
147  const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
148  const struct Mailbox *m1 = sbe1->mailbox;
149  const struct Mailbox *m2 = sbe2->mailbox;
150 
151  return (sb_sort_reverse ? -1 : 1) * (m1->gen - m2->gen);
152 }
Info about folders in the sidebar.
Definition: private.h:39
struct Mailbox * mailbox
Mailbox this represents.
Definition: private.h:44
A mailbox.
Definition: mailbox.h:81
int gen
Generation number, for sorting.
Definition: mailbox.h:150
+ Here is the caller graph for this function:

◆ sb_sort_unsorted()

static int sb_sort_unsorted ( const void *  a,
const void *  b 
)
static

Sort Sidebar entries into their original order - Implements sort_t.

Definition at line 157 of file sort.c.

158 {
159  const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
160  const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
161 
162  // This sort method isn't affected by the reverse flag
163  return (sbe1->mailbox->gen - sbe2->mailbox->gen);
164 }
Info about folders in the sidebar.
Definition: private.h:39
struct Mailbox * mailbox
Mailbox this represents.
Definition: private.h:44
int gen
Generation number, for sorting.
Definition: mailbox.h:150
+ Here is the caller graph for this function:

◆ sb_sort_entries()

void sb_sort_entries ( struct SidebarWindowData wdata,
enum SortType  sort 
)

Sort the Sidebar entries.

Parameters
wdataSidebar data
sortSort order, e.g. SORT_PATH

Sort the wdata->entries array according to the current sort config option $sidebar_sort_method. This calls qsort to do the work which calls our callback function "cb_qsort_sbe".

Once sorted, the prev/next links will be reconstructed.

Definition at line 177 of file sort.c.

178 {
180 
181  switch (sort & SORT_MASK)
182  {
183  case SORT_COUNT:
184  fn = sb_sort_count;
185  break;
186  case SORT_DESC:
187  fn = sb_sort_desc;
188  break;
189  case SORT_FLAGGED:
190  fn = sb_sort_flagged;
191  break;
192  case SORT_PATH:
193  fn = sb_sort_path;
194  break;
195  case SORT_UNREAD:
196  fn = sb_sort_unread;
197  break;
198  case SORT_ORDER:
199  fn = sb_sort_order;
200  default:
201  break;
202  }
203 
204  sb_sort_reverse = (sort & SORT_REVERSE);
205  ARRAY_SORT(&wdata->entries, fn);
206 }
Sort by the number of flagged emails.
Definition: sort2.h:60
Sort by the folder&#39;s path.
Definition: sort2.h:61
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:48
int(* sort_t)(const void *a, const void *b)
Prototype for generic comparison function, compatible with qsort.
Definition: sort.h:44
Sort by the number of unread emails.
Definition: sort2.h:59
Sort by the folder&#39;s description.
Definition: sort2.h:63
#define ARRAY_SORT(head, fn)
Sort an array.
Definition: array.h:271
Sort by number of emails in a folder.
Definition: sort2.h:58
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:79
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ sb_sort_reverse

bool sb_sort_reverse = false
static

An extra parameter to control sort order.

Definition at line 39 of file sort.c.