]> granicus.if.org Git - neomutt/commitdiff
add: BUFFY notifications
authorRichard Russon <rich@flatcap.org>
Fri, 18 Dec 2015 17:34:17 +0000 (17:34 +0000)
committerRichard Russon <rich@flatcap.org>
Sun, 6 Mar 2016 00:44:22 +0000 (00:44 +0000)
buffy.c
sidebar.c
sidebar.h

diff --git a/buffy.c b/buffy.c
index 13ef731d08b4d3aee2ef05f7b2eaf55d1f041147..a902076616144d7c9b6d8c41e4c802731cd25b3a 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -276,14 +276,21 @@ int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *e
       if(*tmp)
       {
         tmp1=(*tmp)->next;
+#ifdef USE_SIDEBAR
+       sb_notify_mailbox (*tmp, 0);
+#endif
         buffy_free (tmp);
         *tmp=tmp1;
       }
       continue;
     }
 
-    if (!*tmp)
+    if (!*tmp) {
       *tmp = buffy_new (buf);
+#ifdef USE_SIDEBAR
+      sb_notify_mailbox (*tmp, 1);
+#endif
+    }
 
     (*tmp)->new = 0;
     (*tmp)->notified = 1;
index ddcdfdf49a6bb7107c0b28269405d04a62a819c4..2da7d00eef649f8ba27fc94a04d0837d3aa81ba6 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -361,6 +361,31 @@ cb_qsort_buffy (const void *a, const void *b)
        return result;
 }
 
+/**
+ * buffy_going - Prevent our pointers becoming invalid
+ * @b: BUFFY about to be deleted
+ *
+ * If we receive a delete-notification for a BUFFY, we need to change any
+ * pointers we have to reference a different BUFFY, or set them to NULL.
+ *
+ * We don't update the prev/next pointers, they'll be fixed on the next
+ * call to prepare_sidebar().
+ *
+ * Returns:
+ *     A valid alternative BUFFY, or NULL
+ */
+static BUFFY *
+buffy_going (const BUFFY *b)
+{
+       if (!b)
+               return NULL;
+
+       if (b->next)
+               return b->next;
+
+       return b->prev;
+}
+
 /**
  * sort_buffy_array - Sort an array of BUFFY pointers
  * @arr:     array of BUFFYs
@@ -772,3 +797,29 @@ sb_set_update_time (void)
        LastRefresh = time (NULL);
 }
 
+/**
+ * sb_notify_mailbox - The state of a BUFFY is about to change
+ *
+ * We receive a notification:
+ *     After a new BUFFY has been created
+ *     Before a BUFFY is deleted
+ *
+ * Before a deletion, check that our pointers won't be invalidated.
+ */
+void
+sb_notify_mailbox (BUFFY *b, int created)
+{
+       if (!b)
+               return;
+
+       /* Any new/deleted mailboxes will cause a refresh.  As long as
+        * they're valid, our pointers will be updated in prepare_sidebar() */
+
+       if (created) {
+       } else {
+               if (TopBuffy == b)
+                       TopBuffy = buffy_going (TopBuffy);
+               if (BotBuffy == b)
+                       BotBuffy = buffy_going (BotBuffy);
+       }
+}
index 9e3e635ee6124b84da11d14cd46ff62d0f405cea..811e922c9c7ce4ba5c44757d73154fffd703e747 100644 (file)
--- a/sidebar.h
+++ b/sidebar.h
 #define SIDEBAR_H
 
 typedef struct _context CONTEXT;
+typedef struct buffy_t  BUFFY;
 
 void         sb_change_mailbox (int op);
 void         sb_draw (void);
 void         sb_init (void);
+void         sb_notify_mailbox (BUFFY *b, int created);
 void         sb_set_buffystats (const CONTEXT *ctx);
 void         sb_set_open_buffy (char *path);
 void         sb_set_update_time (void);