]> granicus.if.org Git - neomutt/commitdiff
add support for virtual folders, add sidebar-toggle command
authorKarel Zak <kzak@redhat.com>
Wed, 14 Mar 2012 14:19:43 +0000 (15:19 +0100)
committerRichard Russon <rich@flatcap.org>
Mon, 4 Apr 2016 15:30:05 +0000 (16:30 +0100)
 * add support for virtual folders
 * add sidebar-toggle function to toggle between virtual and normal
   folders in sudebar
 * virtual folders are used by default if 'virtual_spoolfile' is 'yes'

Signed-off-by: Karel Zak <kzak@redhat.com>
OPS.SIDEBAR
browser.c
buffy.c
curs_main.c
functions.h
mutt_notmuch.c
mutt_notmuch.h
sidebar.c
sidebar.h

index d09ec1f1ddaa6c724623de485aaa36c317580aea..9bcc319295052b8ff46b6ae87cfba249ea1a0327 100644 (file)
@@ -5,4 +5,5 @@ OP_SIDEBAR_PAGE_DOWN "Scroll the Sidebar down 1 page"
 OP_SIDEBAR_PAGE_UP "Scroll the Sidebar up 1 page"
 OP_SIDEBAR_PREV "Move the highlight to previous mailbox"
 OP_SIDEBAR_PREV_NEW "Move the highlight to previous mailbox with new mail"
+OP_SIDEBAR_TOGGLE "toggle between mailboxes and virtual mailboxes"
 OP_SIDEBAR_TOGGLE_VISIBLE "Make the Sidebar (in)visible"
index 12e6cf98325d68f328c8fa24d07b47c9f5f42102..11f1bc9c9bef999e35ec2dcd2dd1521db43fb0ae 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -522,9 +522,9 @@ static int examine_vfolders (MUTTMENU *menu, struct browser_state *state)
   {
     if (mx_is_notmuch (tmp->path))
     {
-      unsigned new = 0, all = 0;
-      nm_get_count(tmp->path, &all, &new);
-      add_folder (menu, state, tmp->path, tmp->desc, NULL, new, all);
+      nm_get_count(tmp->path, &tmp->msg_count, &tmp->msg_unread);
+      add_folder (menu, state, tmp->path, tmp->desc, NULL,
+                     tmp->msg_unread, tmp->msg_count);
       continue;
     }
   }
diff --git a/buffy.c b/buffy.c
index 03a20fc6dbe9592fd403fd7e4cdb1550da09de83..f2d33eb61fa7377dac0141be55d902d006b1aef8 100644 (file)
--- a/buffy.c
+++ b/buffy.c
 #include "imap.h"
 #endif
 
+#ifdef USE_NOTMUCH
+#include "mutt_notmuch.h"
+#endif
+
 #include <string.h>
 #include <sys/stat.h>
 #include <dirent.h>
@@ -590,51 +594,13 @@ buffy_mbox_update (BUFFY *mailbox, struct stat *sb)
 }
 #endif
 
-int mutt_buffy_check (int force)
-{
-  BUFFY *tmp;
-  struct stat sb;
-  struct stat contex_sb;
-  time_t t;
-
-  sb.st_size=0;
-  contex_sb.st_dev=0;
-  contex_sb.st_ino=0;
 
-#ifdef USE_IMAP
-  /* update postponed count as well, on force */
-  if (force)
-    mutt_update_num_postponed ();
-#endif
-
-  /* fastest return if there are no mailboxes */
-  if (!Incoming)
-    return 0;
-  t = time (NULL);
-  if (!force && (t - BuffyTime < BuffyTimeout))
-    return BuffyCount;
-  BuffyTime = t;
-  BuffyCount = 0;
-  BuffyNotify = 0;
+static void buffy_check(BUFFY *tmp, struct stat *contex_sb)
+{
+    struct stat sb;
 
-#ifdef USE_IMAP
-  BuffyCount += imap_buffy_check (force);
-#endif
+    sb.st_size=0;
 
-  /* check device ID and serial number instead of comparing paths */
-  if (!Context || Context->magic == M_IMAP || Context->magic == M_POP
-      || stat (Context->path, &contex_sb) != 0)
-  {
-    contex_sb.st_dev=0;
-    contex_sb.st_ino=0;
-  }
-  
-#ifdef USE_SIDEBAR
-  int should_refresh = sb_should_refresh();
-#endif
-  for (tmp = Incoming; tmp; tmp = tmp->next)
-  {
     if (tmp->magic != M_IMAP)
     {
       tmp->new = 0;
@@ -642,6 +608,11 @@ int mutt_buffy_check (int force)
       if (mx_is_pop (tmp->path))
        tmp->magic = M_POP;
       else
+#endif
+#ifdef USE_NOTMUCH
+      if (mx_is_notmuch (tmp->path))
+       tmp->magic = M_NOTMUCH;
+      else
 #endif
       if (stat (tmp->path, &sb) != 0 || (S_ISREG(sb.st_mode) && sb.st_size == 0) ||
          (!tmp->magic && (tmp->magic = mx_get_magic (tmp->path)) <= 0))
@@ -651,23 +622,23 @@ int mutt_buffy_check (int force)
        tmp->newly_created = 1;
        tmp->magic = 0;
        tmp->size = 0;
-       continue;
+       return;
       }
     }
 
     /* check to see if the folder is the currently selected folder
      * before polling */
     if (!Context || !Context->path ||
-       (( tmp->magic == M_IMAP || tmp->magic == M_POP )
+       (( tmp->magic == M_IMAP || tmp->magic == M_POP || tmp->magic == M_NOTMUCH)
            ? mutt_strcmp (tmp->path, Context->path) :
-             (sb.st_dev != contex_sb.st_dev || sb.st_ino != contex_sb.st_ino)))
+             (sb.st_dev != contex_sb->st_dev || sb.st_ino != contex_sb->st_ino)))
     {
       switch (tmp->magic)
       {
       case M_MBOX:
       case M_MMDF:
 #ifdef USE_SIDEBAR
-       if (should_refresh)
+       if (option(OPTSIDEBAR))
          buffy_mbox_update (tmp, &sb);
 #endif
        if (buffy_mbox_hasnew (tmp, &sb) > 0)
@@ -676,7 +647,7 @@ int mutt_buffy_check (int force)
 
       case M_MAILDIR:
 #ifdef USE_SIDEBAR
-       if (should_refresh)
+       if (option(OPTSIDEBAR))
          buffy_maildir_update (tmp);
 #endif
        if (buffy_maildir_hasnew (tmp) > 0)
@@ -685,15 +656,23 @@ int mutt_buffy_check (int force)
 
       case M_MH:
 #ifdef USE_SIDEBAR
-       if (sb_should_refresh()) {
+       if (option(OPTSIDEBAR))
          mh_buffy_update (tmp);
-         sb_set_update_time();
-       }
 #endif
        mh_buffy(tmp);
        if (tmp->new)
          BuffyCount++;
        break;
+#ifdef USE_NOTMUCH
+      case M_NOTMUCH:
+       tmp->msg_count = 0;
+       tmp->msg_unread = 0;
+       tmp->msg_flagged = 0;
+       nm_get_count(tmp->path, &tmp->msg_count, &tmp->msg_unread);
+       if (tmp->msg_unread > 0)
+         BuffyCount++;
+       break;
+#endif
       }
     }
     else if (option(OPTCHECKMBOXSIZE) && Context && Context->path)
@@ -703,12 +682,60 @@ int mutt_buffy_check (int force)
       tmp->notified = 0;
     else if (!tmp->notified)
       BuffyNotify++;
+}
+
+int mutt_buffy_check (int force)
+{
+  BUFFY *tmp;
+  struct stat contex_sb;
+  time_t t;
+
+  contex_sb.st_dev=0;
+  contex_sb.st_ino=0;
+
+#ifdef USE_IMAP
+  /* update postponed count as well, on force */
+  if (force)
+    mutt_update_num_postponed ();
+#endif
+
+  /* fastest return if there are no mailboxes */
+  if (!Incoming && !VirtIncoming)
+    return 0;
+  t = time (NULL);
+  if (!force && (t - BuffyTime < BuffyTimeout))
+    return BuffyCount;
+
+  BuffyTime = t;
+  BuffyCount = 0;
+  BuffyNotify = 0;
+
+#ifdef USE_IMAP
+  BuffyCount += imap_buffy_check (force);
+#endif
+
+  /* check device ID and serial number instead of comparing paths */
+  if (!Context || Context->magic == M_IMAP || Context->magic == M_POP
+      || stat (Context->path, &contex_sb) != 0)
+  {
+    contex_sb.st_dev=0;
+    contex_sb.st_ino=0;
   }
+
 #ifdef USE_SIDEBAR
-  if (should_refresh)
-         sb_set_update_time();
+  if (sb_should_refresh()) {
+    for (tmp = Incoming; tmp; tmp = tmp->next)
+      buffy_check(tmp, &contex_sb);
+    sb_set_update_time();
+  }
+#else
+  for (tmp = Incoming; tmp; tmp = tmp->next)
+    buffy_check(tmp, &contex_sb);
 #endif
 
+  for (tmp = VirtIncoming; tmp; tmp = tmp->next)
+    buffy_check(tmp, &contex_sb);
+
   BuffyDoneTime = BuffyTime;
   return (BuffyCount);
 }
index d0db61f2536ceb3916086b175e5427dd5e691c8d..0af13b54d61458ef9d528f01624fddc20455c7b0 100644 (file)
@@ -600,7 +600,7 @@ static int main_change_folder(MUTTMENU *menu, int op, char *buf, size_t bufsz,
   mutt_expand_path (buf, bufsz);
 #ifdef USE_SIDEBAR
   if (sb_set_open_buffy (buf) == NULL)
-    break;
+    return -1;
 #endif
   if (mx_get_magic (buf) <= 0)
   {
@@ -2606,6 +2606,10 @@ int mutt_index_menu (void)
        toggle_option (OPTSIDEBAR);
        menu->redraw = REDRAW_FULL;
        break;
+
+      case OP_SIDEBAR_TOGGLE:
+       toggle_sidebar(menu->menu);
+       break;
 #endif
       default:
        if (menu->menu == MENU_MAIN)
index ef64deb5c6b831e850abcce70ffe728b520faf41..8f4f90145726a1b20f53313174e1ca9b4048a3b3 100644 (file)
@@ -177,6 +177,7 @@ const struct binding_t OpMain[] = { /* map: index */
   { "sidebar-page-up",         OP_SIDEBAR_PAGE_UP,             NULL },
   { "sidebar-prev",            OP_SIDEBAR_PREV,                NULL },
   { "sidebar-prev-new",                OP_SIDEBAR_PREV_NEW,            NULL },
+  { "sidebar-toggle",          OP_SIDEBAR_TOGGLE,              NULL },
   { "sidebar-toggle-visible",  OP_SIDEBAR_TOGGLE_VISIBLE,      NULL },
 #endif
 
@@ -298,6 +299,7 @@ const struct binding_t OpPager[] = { /* map: pager */
   { "sidebar-page-up",         OP_SIDEBAR_PAGE_UP,             NULL },
   { "sidebar-prev",            OP_SIDEBAR_PREV,                NULL },
   { "sidebar-prev-new",                OP_SIDEBAR_PREV_NEW,            NULL },
+  { "sidebar-toggle",          OP_SIDEBAR_TOGGLE,              NULL },
   { "sidebar-toggle-visible",  OP_SIDEBAR_TOGGLE_VISIBLE,      NULL },
 #endif
 
index e77f547044eb6554e8b42db2cd34c0d2fddab5df..96cc48eb8533bebb7855f6d534fa3d827a3250eb 100644 (file)
@@ -837,7 +837,7 @@ static unsigned count_query(notmuch_database_t *db, const char *qstr)
        return res;
 }
 
-int nm_get_count(char *path, unsigned *all, unsigned *new)
+int nm_get_count(char *path, int *all, int *new)
 {
        struct uri_tag *query_items = NULL, *item;
        char *db_filename = NULL, *db_query = NULL;
index 82e8fdad604d6b93441d6729eb7343550eea1435..b52d4bf5190b6db372213c91c508526ce7a1dffb 100644 (file)
@@ -11,7 +11,7 @@ char *nm_header_get_folder(HEADER *h);
 int nm_header_get_magic(HEADER *h);
 char *nm_header_get_fullpath(HEADER *h, char *buf, size_t bufsz);
 char *nm_header_get_tags(HEADER *h);
-int nm_get_count(char *path, unsigned *all, unsigned *new);
+int nm_get_count(char *path, int *all, int *new);
 int nm_update_filename(CONTEXT *ctx, const char *old, const char *new);
 char *nm_uri_from_query(CONTEXT *ctx, char *buf, size_t bufsz);
 int nm_modify_message_tags(CONTEXT *ctx, HEADER *hdr, char *tags);
index 5a9cfcbf99e6c4e4ca1f7563d5d848ef32a1f032..ce4debe1484082c036df1c8980230ea2ba422301 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -26,6 +26,7 @@
 #include "keymap.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mx.h"
 #include "sort.h"
 
 /* Previous values for some sidebar config */
@@ -51,6 +52,36 @@ struct sidebar_entry {
        BUFFY       *buffy;
 };
 
+enum {
+       SB_SRC_NONE = 0,
+       SB_SRC_VIRT,
+       SB_SRC_INCOMING
+};
+static int sidebar_source = SB_SRC_NONE;
+
+static BUFFY *
+get_incoming (void)
+{
+       switch (sidebar_source) {
+       case SB_SRC_NONE:
+               sidebar_source = SB_SRC_INCOMING;
+
+               if (option (OPTVIRTSPOOLFILE) && VirtIncoming) {
+                       sidebar_source = SB_SRC_VIRT;
+                       return VirtIncoming;
+               }
+               break;
+       case SB_SRC_VIRT:
+               if (VirtIncoming) {
+                       return VirtIncoming;
+               }
+               break;
+       case SB_SRC_INCOMING:
+               break;
+       }
+
+       return Incoming;        /* default */
+}
 
 /**
  * find_next_new - Find the next folder that contains new mail
@@ -73,7 +104,7 @@ find_next_new (int wrap)
        do {
                b = b->next;
                if (!b && wrap) {
-                       b = Incoming;
+                       b = get_incoming();
                }
                if (!b || (b == HilBuffy)) {
                        break;
@@ -472,7 +503,7 @@ sort_buffy_array (BUFFY **arr, int arr_len)
 static int
 prepare_sidebar (int page_size)
 {
-       BUFFY *b = Incoming;
+       BUFFY *b = get_incoming();
        if (!b)
                return 0;
 
@@ -488,14 +519,15 @@ prepare_sidebar (int page_size)
                return 0;
 
        int i = 0;
-       for (b = Incoming; b; b = b->next, i++) {
+       for (b = get_incoming(); b; b = b->next, i++) {
                arr[i] = b;
        }
 
        update_buffy_visibility (arr, count);
        sort_buffy_array        (arr, count);
 
-       Incoming = arr[0];
+       if (sidebar_source == SB_SRC_INCOMING)
+               Incoming = arr[0];
 
        int top_index =  0;
        int opn_index = -1;
@@ -778,6 +810,10 @@ draw_sidebar (int first_row, int num_rows, int div_width)
                                strncat (sidebar_folder_name, tmp_folder_name, strlen (tmp_folder_name));
                        }
                }
+#ifdef USE_NOTMUCH
+               else if (b->magic == M_NOTMUCH)
+                       sidebar_folder_name = b->desc;
+#endif
                char str[SHORT_STRING];
                make_sidebar_entry (str, sizeof (str), w, sidebar_folder_name, b);
                printw ("%s", str);
@@ -836,7 +872,7 @@ sb_draw (void)
        if (div_width < 0)
                return;
 
-       if (!Incoming) {
+       if (!get_incoming()) {
                int w = MIN(COLS, (SidebarWidth - div_width));
                fill_empty_space (first_row, num_rows, w);
                return;
@@ -921,7 +957,7 @@ sb_change_mailbox (int op)
                        break;
                case OP_SIDEBAR_PAGE_UP:
                        HilBuffy = TopBuffy;
-                       if (HilBuffy != Incoming) {
+                       if (HilBuffy != get_incoming()) {
                                HilBuffy = HilBuffy->prev;
                        }
                        break;
@@ -958,7 +994,7 @@ sb_set_buffystats (const CONTEXT *ctx)
 {
        /* Even if the sidebar's hidden,
         * we should take note of the new data. */
-       BUFFY *b = Incoming;
+       BUFFY *b = get_incoming();
        if (!ctx || !b)
                return;
 
@@ -1005,7 +1041,7 @@ sb_set_open_buffy (const char *path)
 {
        /* Even if the sidebar is hidden */
 
-       BUFFY *b = Incoming;
+       BUFFY *b = get_incoming();
 
        if (!path || !b)
                return NULL;
@@ -1078,3 +1114,26 @@ sb_notify_mailbox (BUFFY *b, int created)
                        Outgoing = buffy_going (Outgoing);
        }
 }
+
+/* switch between regualar and virtual folders */
+void toggle_sidebar(int menu)
+{
+       if (sidebar_source == -1)
+               get_incoming();
+
+#ifdef USE_NOTMUCH
+       if (sidebar_source == SB_SRC_INCOMING && VirtIncoming)
+               sidebar_source = SB_SRC_VIRT;
+       else
+#endif
+               sidebar_source = SB_SRC_INCOMING;
+
+       TopBuffy = NULL;
+       OpnBuffy = NULL;
+       HilBuffy = NULL;
+       BotBuffy = NULL;
+       Outgoing = NULL;
+
+       sb_draw();
+}
+
index b203464f1be522c851603566783ca6a1c964b1d8..b61f90322bc88386144b0cf9c6984f190584a5fb 100644 (file)
--- a/sidebar.h
+++ b/sidebar.h
@@ -32,5 +32,6 @@ void         sb_set_buffystats (const CONTEXT *ctx);
 BUFFY *      sb_set_open_buffy (const char *path);
 void         sb_set_update_time (void);
 int          sb_should_refresh (void);
+void toggle_sidebar(int menu);
 
 #endif /* SIDEBAR_H */