Re: Patch that adds some API to the merge folder



Philip Van Hoof wrote:
> On Fri, 2007-08-31 at 12:51 +0200, Sergio Villar Senin wrote:
>> Philip Van Hoof wrote:
>>> On Fri, 2007-08-31 at 12:10 +0200, Sergio Villar Senin wrote:
>>>
>>>> I'd like to add two new functions to the TnyMergeFolder API. These two
>>>> ones are:
>>>>
>>>> void tny_merge_folder_remove_folder (TnyMergeFolder *self, TnyFolder
>>>> folder);
>>> This one sounds good
>>>
>>>> gint tny_merge_folder_get_num_folders (TnyMergeFolder *self);
>>> Either this and change tny_list_get_length to tny_list_get_num_items or
>>> change this to tny_merge_folder_get_length or something. This feels a
>>> little bit inconsistent in my opinion :-\
>> Sure, I was not very happy with the name. I was doubting between adding
>> this function or another one that just returns the list of folders, but
>> maybe we do not want to expose too much that list, not sure.
> 
> I would do that, indeed. Why not? The app developer had to add the
> items, so why not allow him to get them too?

Second version of the patch with Philip's suggestions

Br

Index: ../../tinymail/libtinymail/tny-merge-folder.c
===================================================================
--- ../../tinymail/libtinymail/tny-merge-folder.c	(revision 2653)
+++ ../../tinymail/libtinymail/tny-merge-folder.c	(working copy)
@@ -1359,6 +1359,70 @@
 }
 
 /**
+ * tny_merge_folder_remove_folder:
+ * @self: a #TnyMergeFolder object
+ * @folder: a #TnyFolder object 
+ *
+ * Removes @folder from the list of folders that will be merged by
+ * @self.
+ **/
+void 
+tny_merge_folder_remove_folder (TnyMergeFolder *self, TnyFolder *folder)
+{
+	TnyMergeFolderPriv *priv;
+
+	g_return_if_fail (TNY_IS_MERGE_FOLDER (self));
+	g_return_if_fail (TNY_IS_FOLDER (folder));
+
+	priv = TNY_MERGE_FOLDER_GET_PRIVATE (self);
+	
+	g_static_rec_mutex_lock (priv->lock);
+
+	tny_folder_remove_observer (folder, TNY_FOLDER_OBSERVER (self));
+
+	tny_list_remove (priv->mothers, G_OBJECT (folder));
+
+	g_static_rec_mutex_unlock (priv->lock);
+
+	return;
+}
+
+/**
+ * tny_merge_folder_get_folders:
+ * @self: a #TnyMergeFolder object
+ * @list: a #TnyList to fillup
+ *
+ * Returns the folders that are merged in the @self merge folder.
+ **/
+void 
+tny_merge_folder_get_folders (TnyMergeFolder *self, TnyList *list)
+{
+	TnyMergeFolderPriv *priv;
+	TnyIterator *iter;
+
+	g_return_if_fail (TNY_IS_MERGE_FOLDER (self));
+	g_return_if_fail (TNY_IS_LIST (list));
+
+	priv = TNY_MERGE_FOLDER_GET_PRIVATE (self);
+	
+	g_static_rec_mutex_lock (priv->lock);
+
+	iter = tny_list_create_iterator (priv->mothers);
+	while (!tny_iterator_is_done (iter)) {
+		GObject *folder;
+
+		folder = tny_iterator_get_current (iter);
+		tny_list_append (list, folder);
+		g_object_unref (folder);
+
+		tny_iterator_next (iter);
+	}
+	g_object_unref (iter);
+
+	g_static_rec_mutex_unlock (priv->lock);
+}
+
+/**
  * tny_merge_folder_new:
  * @folder_name: the name of the merged folder
  *
Index: ../../tinymail/libtinymail/tny-merge-folder.h
===================================================================
--- ../../tinymail/libtinymail/tny-merge-folder.h	(revision 2653)
+++ ../../tinymail/libtinymail/tny-merge-folder.h	(working copy)
@@ -58,7 +58,9 @@
 
 TnyFolder* tny_merge_folder_new (const gchar *folder_name);
 void tny_merge_folder_add_folder (TnyMergeFolder *self, TnyFolder *folder);
+void tny_merge_folder_remove_folder (TnyMergeFolder *self, TnyFolder *folder);
 void tny_merge_folder_set_folder_type (TnyMergeFolder *self, TnyFolderType folder_type);
+void tny_merge_folder_get_folders (TnyMergeFolder *self, TnyList *list);
 
 G_END_DECLS
 


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