tny-merge-folder observer notification



Hi tinymail developers,

Currently, TnyMergeFolder observes its underlaying folders and
propagates any TnyFolderChanges to its own observers without
modification. However, since those observers actually observe the
TnyMergeFolder (and not necessarily the underlaying folders) it seems
more correct when the changed folder for the TnyFolderChange is set to
the TnyMergeFolder before propagating. Also, if an underlaying folder is
renamed it does not affect the merge folder itself.

I prepared a patch to change the behaviour as described. This also fixes
projects.maemo.org bug NB#59369.

Thanks,
Armin
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 2399)
+++ ChangeLog	(working copy)
@@ -1,3 +1,11 @@
+2007-07-05  Armin Burgmeier  <armin openismus com>
+
+	* libtinymail/tny-merge-folder.c: When propagating a TnyFolderChange
+	notified from one of the underlaying folders, do copy that
+	TnyFolderChange and set the changed folder of that copy to the merge
+	folder. Also, do not propagate folder renames because the merge folder
+	itself has not been renamed.
+
 2007-07-05  Philip Van Hoof  <pvanhoof gnome org>
 
 	* Fixes for the new headers after a transfer of messages happened
Index: libtinymail/tny-merge-folder.c
===================================================================
--- libtinymail/tny-merge-folder.c	(revision 2399)
+++ libtinymail/tny-merge-folder.c	(working copy)
@@ -970,7 +970,63 @@
 static void 
 tny_merge_folder_update (TnyFolderObserver *self, TnyFolderChange *change)
 {
-	notify_folder_observers_about (TNY_FOLDER (self), change);
+	/* Create a new folder change for the merge folder to propagate.
+	 * The new folder change has the merge folder instead of the
+	 * underlaying folder as changed folder (if someone is interested
+	 * in the actual underlaying folder she should rather observe that
+	 * particular folder). We also do not propagate folder renames
+	 * because these do not rename the merge folder. */
+	TnyFolderChange* new_change = tny_folder_change_new (self);
+	TnyList *list;
+	TnyIterator *iter;
+
+	if (tny_folder_change_get_changed (change) & TNY_FOLDER_CHANGE_CHANGED_ALL_COUNT)
+		tny_folder_change_set_new_all_count (new_change, tny_folder_change_get_new_all_count (change));
+
+	if (tny_folder_change_get_changed (change) & TNY_FOLDER_CHANGE_CHANGED_UNREAD_COUNT)
+		tny_folder_change_set_new_unread_count (new_change, tny_folder_change_get_new_unread_count (change));
+
+	if (tny_folder_change_get_changed (change) & TNY_FOLDER_CHANGE_CHANGED_ADDED_HEADERS)
+	{
+		list = tny_simple_list_new ();
+		tny_folder_change_get_added_headers (change, list);
+		iter = tny_list_create_iterator (list);
+		while (!tny_iterator_is_done (iter))
+		{
+			TnyHeader *header = tny_iterator_get_current (iter);
+			tny_folder_change_add_added_header (change, header);
+			g_object_unref (header);
+			tny_iterator_next (iter);
+		}
+		g_object_unref (iter);
+		g_object_unref (list);
+	}
+
+	if(tny_folder_change_get_changed (change) & TNY_FOLDER_CHANGE_CHANGED_EXPUNGED_HEADERS)
+	{
+		list = tny_simple_list_new ();
+		tny_folder_change_get_expunged_headers (change, list);
+		iter = tny_list_create_iterator (list);
+		while (!tny_iterator_is_done (iter))
+		{
+			TnyHeader *header = tny_iterator_get_current (iter);
+			tny_folder_change_add_expunged_header (change, header);
+			g_object_unref (header);
+			tny_iterator_next (iter);
+		}
+		g_object_unref (iter);
+		g_object_unref (list);
+	}
+
+	if(tny_folder_change_get_changed (change) & TNY_FOLDER_CHANGE_CHANGED_MSG_RECEIVED)
+	{
+		TnyMsg *msg = tny_folder_change_get_received_msg (change);
+		tny_folder_change_set_received_msg (change, msg);
+		g_object_unref (msg);
+	}
+
+	notify_folder_observers_about (TNY_FOLDER (self), new_change);
+	g_object_unref (new_change);
 }
 
 /**
@@ -991,6 +1047,7 @@
 	g_static_rec_mutex_lock (priv->lock);
 
 	tny_list_prepend (priv->mothers, G_OBJECT (folder));
+
 	tny_folder_add_observer (folder, TNY_FOLDER_OBSERVER (self));
 
 	g_static_rec_mutex_unlock (priv->lock);


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