Re: New API function to remove n messages
- From: Javier Fernandez <jfernandez igalia com>
- To: tinymail-devel-list gnome org
- Subject: Re: New API function to remove n messages
- Date: Tue, 28 Aug 2007 12:54:33 +0200
El mar, 28-08-2007 a las 12:52 +0200, Javier Fernandez escribió:
> I have implemented a new API function to remove multiple messages
> in a single camel operation.
>
> Thanks for review it.
I forgot the attachment, sorry.
--
Index: libtinymail-camel/tny-camel-folder.c
===================================================================
--- libtinymail-camel/tny-camel-folder.c (revision 2651)
+++ libtinymail-camel/tny-camel-folder.c (working copy)
@@ -1102,7 +1102,77 @@
return;
}
+static void
+tny_camel_folder_remove_msgs (TnyFolder *self, TnyList *headers, GError **err)
+{
+ TNY_CAMEL_FOLDER_GET_CLASS (self)->remove_msgs_func (self, headers, err);
+ return;
+}
+static void
+tny_camel_folder_remove_msgs_default (TnyFolder *self, TnyList *headers, GError **err)
+{
+ TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (self);
+ TnyFolderChange *change = NULL;
+ TnyIterator *iter = NULL;
+ TnyHeader *header = NULL;
+
+ g_assert (TNY_IS_LIST (headers));
+
+ if (!_tny_session_check_operation (TNY_FOLDER_PRIV_GET_SESSION(priv),
+ priv->account, err, TNY_FOLDER_ERROR,
+ TNY_FOLDER_ERROR_REMOVE_MSGS))
+ return;
+
+ if (!priv->remove_strat) {
+ _tny_session_stop_operation (TNY_FOLDER_PRIV_GET_SESSION (priv));
+ return;
+ }
+
+ g_static_rec_mutex_lock (priv->folder_lock);
+
+ if (!priv->folder || !priv->loaded || !CAMEL_IS_FOLDER (priv->folder))
+ if (!load_folder_no_lock (priv))
+ {
+ _tny_session_stop_operation (TNY_FOLDER_PRIV_GET_SESSION (priv));
+ g_static_rec_mutex_unlock (priv->folder_lock);
+ return;
+ }
+
+ change = tny_folder_change_new (self);
+ iter = tny_list_create_iterator (headers);
+ while (!tny_iterator_is_done (iter)) {
+ header = TNY_HEADER(tny_iterator_get_current (iter));
+ g_assert(TNY_IS_HEADER(header));
+
+ /* Performs remove */
+ tny_msg_remove_strategy_perform_remove (priv->remove_strat, self, header, err);
+
+ /* Add expunged headers to change event */
+ tny_folder_change_add_expunged_header (change, header);
+
+ g_object_unref (header);
+ tny_iterator_next (iter);
+ }
+
+ /* Notify about unread count */
+ _tny_camel_folder_check_unread_count (TNY_CAMEL_FOLDER (self));
+
+ /* Notify header has been removed */
+ notify_folder_observers_about_in_idle (self, change);
+
+ /* Free */
+ g_object_unref (change);
+ g_object_unref (iter);
+
+ g_static_rec_mutex_unlock (priv->folder_lock);
+
+ _tny_session_stop_operation (TNY_FOLDER_PRIV_GET_SESSION (priv));
+
+ return;
+}
+
+
CamelFolder*
_tny_camel_folder_get_camel_folder (TnyCamelFolder *self)
{
@@ -5285,6 +5355,7 @@
klass->refresh_async_func = tny_camel_folder_refresh_async;
klass->refresh_func = tny_camel_folder_refresh;
klass->remove_msg_func = tny_camel_folder_remove_msg;
+ klass->remove_msgs_func = tny_camel_folder_remove_msgs;
klass->sync_func = tny_camel_folder_sync;
klass->sync_async_func = tny_camel_folder_sync_async;
klass->add_msg_func = tny_camel_folder_add_msg;
@@ -5348,6 +5419,7 @@
class->refresh_async_func = tny_camel_folder_refresh_async_default;
class->refresh_func = tny_camel_folder_refresh_default;
class->remove_msg_func = tny_camel_folder_remove_msg_default;
+ class->remove_msgs_func = tny_camel_folder_remove_msgs_default;
class->add_msg_func = tny_camel_folder_add_msg_default;
class->sync_func = tny_camel_folder_sync_default;
class->sync_async_func = tny_camel_folder_sync_async_default;
Index: libtinymail-camel/tny-camel-folder.h
===================================================================
--- libtinymail-camel/tny-camel-folder.h (revision 2651)
+++ libtinymail-camel/tny-camel-folder.h (working copy)
@@ -54,6 +54,7 @@
/* virtual methods */
void (*remove_msg_func) (TnyFolder *self, TnyHeader *header, GError **err);
+ void (*remove_msgs_func) (TnyFolder *self, TnyList *headers, GError **err);
void (*add_msg_func) (TnyFolder *self, TnyMsg *msg, GError **err);
void (*add_msg_async_func) (TnyFolder *self, TnyMsg *msg, TnyFolderCallback callback, TnyStatusCallback status_callback, gpointer user_data);
void (*sync_func) (TnyFolder *self, gboolean expunge, GError **err);
Index: libtinymail-camel/camel-lite/camel/camel-folder.c
===================================================================
--- libtinymail-camel/camel-lite/camel/camel-folder.c (revision 2651)
+++ libtinymail-camel/camel-lite/camel/camel-folder.c (working copy)
@@ -1458,6 +1458,9 @@
if (transferred_uids)
ret_uid = (char **)&((*transferred_uids)->pdata[i]);
transfer_message_to (source, uids->pdata[i], dest, ret_uid, delete_originals, ex);
+
+ printf ("debug: %s:\n progress changed (%i/%i) : %i\n", __FUNCTION__, i, uids->len);
+
camel_operation_progress(NULL, i , uids->len);
}
if (uids->len > 1) {
Index: libtinymail/tny-error.c
===================================================================
--- libtinymail/tny-error.c (revision 2651)
+++ libtinymail/tny-error.c (working copy)
@@ -69,6 +69,7 @@
{ TNY_ERROR_UNSPEC, "TNY_ERROR_UNSPEC", "error_unspec" },
{ TNY_FOLDER_ERROR_SYNC, "TNY_FOLDER_ERROR_SYNC", "folder_error_sync" },
{ TNY_FOLDER_ERROR_REMOVE_MSG, "TNY_FOLDER_ERROR_REMOVE_MSG", "folder_error_remove_msg" },
+ { TNY_FOLDER_ERROR_REMOVE_MSGS, "TNY_FOLDER_ERROR_REMOVE_MSGS", "folder_error_remove_msgs" },
{ TNY_FOLDER_ERROR_ADD_MSG, "TNY_FOLDER_ERROR_ADD_MSG", "folder_error_add_msg" },
{ TNY_FOLDER_ERROR_REFRESH, "TNY_FOLDER_ERROR_REFRESH", "folder_error_refresh" },
{ TNY_FOLDER_ERROR_GET_MSG, "TNY_FOLDER_ERROR_GET_MSG", "folder_error_get_msg" },
Index: libtinymail/tny-enums.h
===================================================================
--- libtinymail/tny-enums.h (revision 2651)
+++ libtinymail/tny-enums.h (working copy)
@@ -96,6 +96,8 @@
TNY_SEND_QUEUE_ERROR_ADD = 17,
TNY_ACCOUNT_STORE_ERROR_CANCEL_ALERT = 18,
+
+ TNY_FOLDER_ERROR_REMOVE_MSGS = 19,
} TnyError;
typedef enum {
Index: libtinymail/tny-error.h
===================================================================
--- libtinymail/tny-error.h (revision 2651)
+++ libtinymail/tny-error.h (working copy)
@@ -127,6 +127,7 @@
TNY_ACCOUNT_STORE_ERROR_CANCEL_ALERT = 18,
+ TNY_FOLDER_ERROR_REMOVE_MSGS = 19,
};
GType tny_error_domain_get_type (void);
Index: libtinymail/tny-folder.c
===================================================================
--- libtinymail/tny-folder.c (revision 2651)
+++ libtinymail/tny-folder.c (working copy)
@@ -711,7 +711,36 @@
return;
}
+/**
+ * tny_folder_remove_msgs:
+ * @self: a TnyFolder object
+ * @headers: the headers of the messages to remove
+ * @err: a #GError object or NULL
+ *
+ * Remove messages from a folder. It will use a #TnyMsgRemoveStrategy to
+ * perform the removal itself. For more details, check out the documentation
+ * of the #TnyMsgRemoveStrategy type and the implementation that you activated
+ * using tny_folder_set_msg_remove_strategy. The default implementation for
+ * libtinymail-camel is the #TnyCamelMsgRemoveStrategy.
+ *
+ * Folder observers of @self will get only one header-removed trigger caused by this
+ * action.
+ *
+ */
+void
+tny_folder_remove_msgs (TnyFolder *self, TnyList *headers, GError **err)
+{
+#ifdef DBC /* require */
+ g_assert (TNY_IS_FOLDER (self));
+ g_assert (headers);
+ g_assert (TNY_IS_LIST (headers));
+ g_assert (TNY_FOLDER_GET_IFACE (self)->remove_msgs_func != NULL);
+#endif
+ TNY_FOLDER_GET_IFACE (self)->remove_msgs_func (self, headers, err);
+ return;
+}
+
/**
* tny_folder_refresh_async:
* @self: a TnyFolder object
Index: libtinymail/tny-folder.h
===================================================================
--- libtinymail/tny-folder.h (revision 2651)
+++ libtinymail/tny-folder.h (working copy)
@@ -89,6 +89,7 @@
/* Methods */
void (*remove_msg_func) (TnyFolder *self, TnyHeader *header, GError **err);
+ void (*remove_msgs_func) (TnyFolder *self, TnyList *headers, GError **err);
void (*add_msg_func) (TnyFolder *self, TnyMsg *msg, GError **err);
void (*add_msg_async_func) (TnyFolder *self, TnyMsg *msg, TnyFolderCallback callback, TnyStatusCallback status_callback, gpointer user_data);
void (*sync_func) (TnyFolder *self, gboolean expunge, GError **err);
@@ -133,6 +134,7 @@
TnyMsgReceiveStrategy* tny_folder_get_msg_receive_strategy (TnyFolder *self);
void tny_folder_set_msg_receive_strategy (TnyFolder *self, TnyMsgReceiveStrategy *st);
void tny_folder_remove_msg (TnyFolder *self, TnyHeader *header, GError **err);
+void tny_folder_remove_msgs (TnyFolder *self, TnyList *headers, GError **err);
void tny_folder_remove_msg_async (TnyFolder *self, TnyHeader *header, GError **err);
void tny_folder_add_msg (TnyFolder *self, TnyMsg *msg, GError **err);
void tny_folder_add_msg_async (TnyFolder *self, TnyMsg *msg, TnyFolderCallback callback, TnyStatusCallback status_callback, gpointer user_data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]