[PATCH] : new notif schema



	Hi all,
here is just the beginning of it. The only improvment is that now filters 
do not let deleted messages behind (ie now the index is cleaned depending 
on the user pref "hide deleted" and friends). This is done by adding a 
call to balsa_index_sync_backend to clean the index (and in fact all views 
attached to the mailbox).
In fact in the current context this patch does not make a lot if sense 
since it mostly simplifies the work when we'll have several views for one 
mailbox. Still we now have a basis of discussion.
Bye
Manu
diff -u /home/manu/prog/balsa-cvs/balsa/libbalsa/mailbox.c balsa-notif/libbalsa/mailbox.c
--- /home/manu/prog/balsa-cvs/balsa/libbalsa/mailbox.c	Sat May 18 14:29:06 2002
+++ balsa-notif/libbalsa/mailbox.c	Sun Jun  2 11:16:00 2002
@@ -750,8 +750,7 @@
     gdk_threads_enter();
 
     if(messages!=NULL){
-      gtk_signal_emit(GTK_OBJECT(mailbox),
-			libbalsa_mailbox_signals[MESSAGES_NEW], messages);
+      libbalsa_mailbox_messages_new(mailbox, messages);
       g_list_free(messages);
     }
 
@@ -922,14 +921,13 @@
 	}
     }
 
-    if(p){
-	gtk_signal_emit(GTK_OBJECT(mailbox),
-			libbalsa_mailbox_signals[MESSAGES_DELETE],
-			p);
-	g_list_free(p);
-    }
+    /* Here we notify the deletion (ie removing of messages from
+       the mailbox */
+    if (p)
+	libbalsa_mailbox_messages_delete(mailbox,p);
 
     if (delete) {
+
         for (list = q; list; list = g_list_next(list)) {
             message_list = list->data;
             current_message =
@@ -1004,4 +1002,50 @@
 		    message);
 }
 
+void libbalsa_mailbox_message_new(LibBalsaMailbox * mailbox,
+				  LibBalsaMessage * message)
+{
+    g_return_if_fail(mailbox!=NULL);
+    g_return_if_fail(message!=NULL);
+
+    gtk_signal_emit(GTK_OBJECT(mailbox),
+		    libbalsa_mailbox_signals[MESSAGE_NEW],
+		    message);
+}
+
+/* FIXME : for deletion notif, I think that we can't assume
+in the handler that the message is still valid (I'm pretty sure
+it could have been destroyed yet). So we must not use it.
+*/
+void libbalsa_mailbox_message_delete(LibBalsaMailbox * mailbox,
+				     LibBalsaMessage * message)
+{
+    g_return_if_fail(mailbox!=NULL);
+    g_return_if_fail(message!=NULL);
+
+    gtk_signal_emit(GTK_OBJECT(mailbox),
+		    libbalsa_mailbox_signals[MESSAGE_DELETE],
+		    message);
+}
+
+void libbalsa_mailbox_messages_new(LibBalsaMailbox * mailbox,
+				   GList * messages)
+{
+    g_return_if_fail(mailbox!=NULL);
+    g_return_if_fail(messages!=NULL);
+
+    gtk_signal_emit(GTK_OBJECT(mailbox),
+		    libbalsa_mailbox_signals[MESSAGES_NEW],
+		    messages);
+}
+
+void libbalsa_mailbox_messages_delete(LibBalsaMailbox * mailbox,
+				      GList * messages)
+{
+    g_return_if_fail(mailbox!=NULL);
+    g_return_if_fail(messages!=NULL);
 
+    gtk_signal_emit(GTK_OBJECT(mailbox),
+		    libbalsa_mailbox_signals[MESSAGES_DELETE],
+		    messages);
+}
diff -u /home/manu/prog/balsa-cvs/balsa/libbalsa/mailbox.h balsa-notif/libbalsa/mailbox.h
--- /home/manu/prog/balsa-cvs/balsa/libbalsa/mailbox.h	Sat May 18 14:29:07 2002
+++ balsa-notif/libbalsa/mailbox.h	Sun Jun  2 11:57:33 2002
@@ -166,6 +166,20 @@
 
 void libbalsa_mailbox_check(LibBalsaMailbox * mailbox);
 
+/* Notification-only signals (no datas are modified) */
+
+void libbalsa_mailbox_message_new(LibBalsaMailbox * mailbox,
+				  LibBalsaMessage * message);
+
+void libbalsa_mailbox_message_delete(LibBalsaMailbox * mailbox,
+				     LibBalsaMessage * message);
+
+void libbalsa_mailbox_messages_new(LibBalsaMailbox * mailbox,
+				   GList * messages);
+
+void libbalsa_mailbox_messages_delete(LibBalsaMailbox * mailbox,
+				      GList * messages);
+
 GHashTable*libbalsa_mailbox_get_matching(LibBalsaMailbox * mailbox,
                                          int op, GSList* conditions);
 
diff -u /home/manu/prog/balsa-cvs/balsa/src/balsa-index.c balsa-notif/src/balsa-index.c
--- /home/manu/prog/balsa-cvs/balsa/src/balsa-index.c	Sat May 18 14:29:09 2002
+++ balsa-notif/src/balsa-index.c	Mon Jun  3 17:45:29 2002
@@ -48,6 +48,16 @@
 #include "sendmsg-window.h"
 #include "store-address.h"
 
+/* FIXME : I needed LOCK/UNLOCK and CLIENT_CONTEXT_OPEN
+   for hide_deleted seems to be in a header we should
+   not include here. I guess that these hide_deleted function
+   should be somewhere else anyway */
+#ifdef BALSA_USE_THREADS
+#include <pthread.h>
+#include "threads.h"
+#endif /*BALSA_USE_THREADS*/
+#include "libbalsa_private.h"
+
 #include "filter.h"
 
 #define CLIST_WORKAROUND
@@ -152,7 +162,7 @@
                            gpointer user_data);
 static void tree_collapse_cb(GtkCTree * ctree, GList * node,
                            gpointer user_data);
-static void hide_deleted(BalsaIndex * bindex, gboolean hide);
+static void hide_deleted(GNode * mailbox_node, gpointer hide);
 
 /* Callbacks */
 static gint mru_search_cb(GNode *node, struct FolderMRUEntry *entry);
@@ -2360,6 +2370,7 @@
     
     for (list = mailbox->message_list; list; list = list->next)
 	balsa_index_add(bindex, LIBBALSA_MESSAGE(list->data));
+    balsa_index_sync_backend(bindex->mailbox_node->mailbox);
     /* do threading */
     balsa_index_threading(bindex);
     gtk_clist_sort(clist);
@@ -2619,43 +2630,48 @@
 
 /* balsa_index_hide_deleted:
  * called from pref manager when balsa_app.hide_deleted is changed.
+ * This will traverse the mailbox and sync (ie remove or hide deleted messages)
+ * or bring back hidden messages
  */
 void
 balsa_index_hide_deleted(gboolean hide)
 {
-    gint i;
-    GtkWidget *page;
-
-    for (i = 0; (page =
-                 gtk_notebook_get_nth_page(GTK_NOTEBOOK
-                                           (balsa_app.notebook),
-                                           i)) != NULL; ++i)
-        hide_deleted(BALSA_INDEX(page), hide);
+    g_node_children_foreach(balsa_app.mailbox_nodes, G_TRAVERSE_LEAFS,
+			    hide_deleted, GINT_TO_POINTER(hide));
 }
 
-/* hide_deleted:
- * hide (or show, if hide is FALSE) deleted messages.
- */
 static void
-hide_deleted(BalsaIndex * bindex, gboolean hide)
+hide_deleted(GNode * nd,gpointer data)
 {
-    LibBalsaMailbox *mailbox = bindex->mailbox_node->mailbox;
-    GList *list;
-    GList *messages = NULL;
+    gboolean hide = GPOINTER_TO_INT(data);
+    BalsaMailboxNode * mb_node = (BalsaMailboxNode *)nd->data;
 
-    for (list = mailbox->message_list; list; list = g_list_next(list)) {
-        LibBalsaMessage *message = LIBBALSA_MESSAGE(list->data);
-
-        if (message->flags & LIBBALSA_MESSAGE_FLAG_DELETED)
-            messages = g_list_prepend(messages, message);
-    }
+    /* Only opened mailboxes are concerned */
+    if (!BALSA_IS_MAILBOX_NODE(mb_node) || !CLIENT_CONTEXT_OPEN(mb_node->mailbox))
+	return;
 
     if (hide)
-        mailbox_messages_delete_cb(bindex, messages);
-    else
-        mailbox_messages_new_cb(bindex, messages);
-
-    g_list_free(messages);
+	balsa_index_sync_backend(mb_node->mailbox);
+    else {
+	LibBalsaMailbox * mailbox = mb_node->mailbox;
+	GList *list;
+	GList *messages = NULL;
+
+	LOCK_MAILBOX(mailbox);
+	for (list = mailbox->message_list; list; list = g_list_next(list)) {
+	    LibBalsaMessage *message = LIBBALSA_MESSAGE(list->data);
+	    
+	    if (message->flags & LIBBALSA_MESSAGE_FLAG_DELETED)
+		messages = g_list_prepend(messages, message);
+	}
+	UNLOCK_MAILBOX(mailbox);
+	if (messages) {
+	    /* Notification of brought back messages
+	       this will force all views to update */
+	    libbalsa_mailbox_messages_new(mailbox, messages);
+	    g_list_free(messages);
+	}
+    }
 }
 
 /* balsa_index_sync_backend:
diff -u /home/manu/prog/balsa-cvs/balsa/src/filter-run-callbacks.c balsa-notif/src/filter-run-callbacks.c
--- /home/manu/prog/balsa-cvs/balsa/src/filter-run-callbacks.c	Mon Jun  3 17:22:17 2002
+++ balsa-notif/src/filter-run-callbacks.c	Mon Jun  3 18:01:50 2002
@@ -95,11 +95,12 @@
     if (!filters) return TRUE;
     if (!filters_prepare_to_run(filters))
 	return FALSE;
-    gtk_clist_freeze(GTK_CLIST(balsa_app.mblist));
+    //    gtk_clist_freeze(GTK_CLIST(balsa_app.mblist));
     libbalsa_filter_match_mailbox(filters,mbox);
     if (libbalsa_filter_apply(filters))
 	enable_empty_trash(TRASH_FULL);
-    gtk_clist_thaw(GTK_CLIST(balsa_app.mblist));
+    balsa_index_sync_backend(mbox);
+    //    gtk_clist_thaw(GTK_CLIST(balsa_app.mblist));
     g_slist_free(filters);
     return TRUE;
 }


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