[Commits] [SCM] claws branch, master, updated. 3.17.0-20-g125f9ca

wwp at claws-mail.org wwp at claws-mail.org
Fri Aug 24 15:00:46 CEST 2018


The branch, master has been updated
       via  125f9caede475bb80ffa2e69c93ad2fd8d043068 (commit)
      from  1c18933cc27202dce348f39dacc8ff80c0d29fcb (commit)

Summary of changes:
 src/folderutils.c |  112 ++++++++++++++---------------------------------------
 src/folderutils.h |    6 +--
 src/folderview.c  |    8 ++--
 src/summaryview.c |   16 ++++----
 4 files changed, 43 insertions(+), 99 deletions(-)


- Log -----------------------------------------------------------------
commit 125f9caede475bb80ffa2e69c93ad2fd8d043068
Author: wwp <subscript at free.fr>
Date:   Fri Aug 24 14:59:13 2018 +0200

    Optimize (for speed) and factorize code related to marking folders
    as read/unread recursively. A bit of code format fixing too.

diff --git a/src/folderutils.c b/src/folderutils.c
index 355af85..9d71a51 100644
--- a/src/folderutils.c
+++ b/src/folderutils.c
@@ -27,6 +27,9 @@
 #include "mainwindow.h"
 #include "summaryview.h"
 
+static gboolean folderutils_mark_all_read_node_func(GNode *node, gpointer data);
+
+
 gint folderutils_delete_duplicates(FolderItem *item,
 				   DeleteDuplicatesMode mode)
 {
@@ -119,60 +122,23 @@ gint folderutils_delete_duplicates(FolderItem *item,
 	return dups;
 }
 
-void folderutils_mark_all_read(FolderItem *item)
+void folderutils_mark_all_read(FolderItem *item, gboolean mark_as_read)
 {
 	MsgInfoList *msglist, *cur;
 	MainWindow *mainwin = mainwindow_get_mainwindow();
 	int i = 0, m = 0;
-	debug_print("marking all read in item %s\n", (item==NULL)?"NULL":item->name);
-	cm_return_if_fail(item != NULL);
-
-
-	folder_item_update_freeze();
-	if (mainwin && mainwin->summaryview &&
-	    mainwin->summaryview->folder_item == item) {
-		debug_print("folder opened, using summary\n");
-		summary_mark_all_read(mainwin->summaryview, FALSE);
-	} else {
-		msglist = folder_item_get_msg_list(item);
-		debug_print("got msglist %p\n", msglist);
-		if (msglist == NULL) {
-			folder_item_update_thaw();
-			return;
-		}
-		folder_item_set_batch(item, TRUE);
-		for (cur = msglist; cur != NULL; cur = g_slist_next(cur)) {
-			MsgInfo *msginfo = cur->data;
-
-			if (msginfo->flags.perm_flags & (MSG_NEW | MSG_UNREAD)) {
-				procmsg_msginfo_unset_flags(msginfo, MSG_NEW | MSG_UNREAD, 0);
-				m++;
-			}
-			i++;
-			procmsg_msginfo_free(&msginfo);
-		}
-		folder_item_set_batch(item, FALSE);
-		folder_item_close(item);
-		debug_print("marked %d messages out of %d as read\n", m, i);
-		g_slist_free(msglist);
-	}
-	folder_item_update_thaw();
-}
+	gchar *msg = mark_as_read?"read":"unread";
+	void(*summary_mark_func)(SummaryView*, gboolean) =
+			mark_as_read?summary_mark_all_read:summary_mark_all_unread;
 
-void folderutils_mark_all_unread(FolderItem *item)
-{
-	MsgInfoList *msglist, *cur;
-	MainWindow *mainwin = mainwindow_get_mainwindow();
-	int i = 0, m = 0;
-	debug_print("marking all unread in item %s\n", (item==NULL)?"NULL":item->name);
+	debug_print("marking all %s in item %s\n", msg, (item==NULL)?"NULL":item->name);
 	cm_return_if_fail(item != NULL);
 
-
 	folder_item_update_freeze();
 	if (mainwin && mainwin->summaryview &&
 	    mainwin->summaryview->folder_item == item) {
 		debug_print("folder opened, using summary\n");
-		summary_mark_all_unread(mainwin->summaryview, FALSE);
+		summary_mark_func(mainwin->summaryview, FALSE);
 	} else {
 		msglist = folder_item_get_msg_list(item);
 		debug_print("got msglist %p\n", msglist);
@@ -184,65 +150,45 @@ void folderutils_mark_all_unread(FolderItem *item)
 		for (cur = msglist; cur != NULL; cur = g_slist_next(cur)) {
 			MsgInfo *msginfo = cur->data;
 
-			if (!(msginfo->flags.perm_flags & MSG_UNREAD)) {
-				procmsg_msginfo_set_flags(msginfo, MSG_UNREAD, 0);
-				m++;
+			if (mark_as_read) {
+				if (msginfo->flags.perm_flags & (MSG_NEW | MSG_UNREAD)) {
+					procmsg_msginfo_unset_flags(msginfo, MSG_NEW | MSG_UNREAD, 0);
+					m++;
+				}
+			} else {
+				if (!(msginfo->flags.perm_flags & MSG_UNREAD)) {
+					procmsg_msginfo_set_flags(msginfo, MSG_UNREAD, 0);
+					m++;
+				}
 			}
 			i++;
 			procmsg_msginfo_free(&msginfo);
 		}
 		folder_item_set_batch(item, FALSE);
 		folder_item_close(item);
-		debug_print("marked %d messages out of %d as unread\n", m, i);
+		debug_print("marked %d messages out of %d as %s\n", m, i, msg);
 		g_slist_free(msglist);
 	}
 	folder_item_update_thaw();
 }
 
-void folderutils_mark_all_read_recursive(FolderItem *item)
+static gboolean folderutils_mark_all_read_node_func(GNode *node, gpointer data)
 {
-	GNode *node;
-
-	cm_return_if_fail(item != NULL);
-
-	folderutils_mark_all_read(item);
-
-	cm_return_if_fail(item->folder != NULL);
-	cm_return_if_fail(item->folder->node != NULL);
-
-	node = item->folder->node;
-	node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, item);
-	node = node->children;
-
-	while (node != NULL) {
-		if (node->data != NULL) {
-			FolderItem *sub_item = (FolderItem *) node->data;
-			node = node->next;
-			folderutils_mark_all_read_recursive(sub_item);
-		}
+	if (node) {
+		FolderItem *sub_item = (FolderItem *) node->data;
+		folderutils_mark_all_read(sub_item, (gboolean) GPOINTER_TO_INT(data));
 	}
+	return(FALSE);
 }
 
-void folderutils_mark_all_unread_recursive(FolderItem *item)
+void folderutils_mark_all_read_recursive(FolderItem *item, gboolean mark_as_read)
 {
-	GNode *node;
-
 	cm_return_if_fail(item != NULL);
 
-	folderutils_mark_all_unread(item);
-
 	cm_return_if_fail(item->folder != NULL);
 	cm_return_if_fail(item->folder->node != NULL);
 
-	node = item->folder->node;
-	node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, item);
-	node = node->children;
-
-	while (node != NULL) {
-		if (node->data != NULL) {
-			FolderItem *sub_item = (FolderItem *) node->data;
-			node = node->next;
-			folderutils_mark_all_unread_recursive(sub_item);
-		}
-	}
+	g_node_traverse(item->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
+		folderutils_mark_all_read_node_func,
+		GINT_TO_POINTER(mark_as_read));
 }
diff --git a/src/folderutils.h b/src/folderutils.h
index 64a5c2e..9394d44 100644
--- a/src/folderutils.h
+++ b/src/folderutils.h
@@ -29,9 +29,7 @@ typedef enum {
 
 gint folderutils_delete_duplicates(FolderItem *item,
 				   DeleteDuplicatesMode mode);
-void folderutils_mark_all_read	  (FolderItem *item);
-void folderutils_mark_all_unread	  (FolderItem *item);
-void folderutils_mark_all_read_recursive	  (FolderItem *item);
-void folderutils_mark_all_unread_recursive	  (FolderItem *item);
+void folderutils_mark_all_read	  (FolderItem *item, gboolean read);
+void folderutils_mark_all_read_recursive	  (FolderItem *item, gboolean read);
 
 #endif /* FOLDERUTILS_H */
diff --git a/src/folderview.c b/src/folderview.c
index 8c19b19..d8526bf 100644
--- a/src/folderview.c
+++ b/src/folderview.c
@@ -894,14 +894,14 @@ static void mark_all_read_unread_handler(GtkAction *action, gpointer data,
 		
 	if (read) {
 		if (recursive)
-			folderutils_mark_all_read_recursive(item);
+			folderutils_mark_all_read_recursive(item, TRUE);
 		else
-			folderutils_mark_all_read(item);
+			folderutils_mark_all_read(item, TRUE);
 	} else {
 		if (recursive)
-			folderutils_mark_all_unread_recursive(item);
+			folderutils_mark_all_read_recursive(item, FALSE);
 		else
-			folderutils_mark_all_unread(item);
+			folderutils_mark_all_read(item, FALSE);
 	}
 	if (folderview->summaryview->folder_item != item && !recursive)
 		summary_unlock(folderview->summaryview);
diff --git a/src/summaryview.c b/src/summaryview.c
index d6f179e..1fd33a9 100644
--- a/src/summaryview.c
+++ b/src/summaryview.c
@@ -4251,7 +4251,7 @@ void summary_mark_all_read(SummaryView *summaryview, gboolean ask_if_needed)
 	GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
 	GtkCMCTreeNode *node;
 	gboolean froze = FALSE;
-	
+
 	if (summary_is_locked(summaryview))
 		return;
 
@@ -4261,16 +4261,16 @@ void summary_mark_all_read(SummaryView *summaryview, gboolean ask_if_needed)
 	START_LONG_OPERATION(summaryview, TRUE);
 	folder_item_set_batch(summaryview->folder_item, TRUE);
 	for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list); node != NULL;
-	     node = gtkut_ctree_node_next(ctree, node))
+		node = gtkut_ctree_node_next(ctree, node))
 		summary_mark_row_as_read(summaryview, node);
 	folder_item_set_batch(summaryview->folder_item, FALSE);
 	for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list); node != NULL;
-	     node = gtkut_ctree_node_next(ctree, node)) {
+		node = gtkut_ctree_node_next(ctree, node)) {
 		if (!GTK_CMCTREE_ROW(node)->expanded)
 			summary_set_row_marks(summaryview, node);
 	}
 	END_LONG_OPERATION(summaryview);
-	
+
 	summary_status_show(summaryview);
 }
 
@@ -4297,7 +4297,7 @@ void summary_mark_all_unread(SummaryView *summaryview, gboolean ask_if_needed)
 	GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
 	GtkCMCTreeNode *node;
 	gboolean froze = FALSE;
-	
+
 	if (summary_is_locked(summaryview))
 		return;
 
@@ -4307,16 +4307,16 @@ void summary_mark_all_unread(SummaryView *summaryview, gboolean ask_if_needed)
 	START_LONG_OPERATION(summaryview, TRUE);
 	folder_item_set_batch(summaryview->folder_item, TRUE);
 	for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list); node != NULL;
-	     node = gtkut_ctree_node_next(ctree, node))
+		node = gtkut_ctree_node_next(ctree, node))
 		summary_mark_row_as_unread(summaryview, node);
 	folder_item_set_batch(summaryview->folder_item, FALSE);
 	for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list); node != NULL;
-	     node = gtkut_ctree_node_next(ctree, node)) {
+		node = gtkut_ctree_node_next(ctree, node)) {
 		if (!GTK_CMCTREE_ROW(node)->expanded)
 			summary_set_row_marks(summaryview, node);
 	}
 	END_LONG_OPERATION(summaryview);
-	
+
 	summary_status_show(summaryview);
 }
 

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list