* check for a valid foldername
[modest] / src / modest-mail-operation.h
index 4aba37b..ee25fa1 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <tny-transport-account.h>
 #include <tny-folder-store.h>
+#include <widgets/modest-msg-edit-window.h>
 
 G_BEGIN_DECLS
 
@@ -60,6 +61,116 @@ typedef enum _ModestMailOperationStatus {
        MODEST_MAIL_OPERATION_STATUS_CANCELED
 } ModestMailOperationStatus;
 
+/**
+ * ModestMailOperationId:
+ *
+ * The id for identifying the type of mail operation
+ */
+typedef enum {
+       MODEST_MAIL_OPERATION_TYPE_SEND,
+       MODEST_MAIL_OPERATION_TYPE_RECEIVE,
+       MODEST_MAIL_OPERATION_TYPE_OPEN,
+       MODEST_MAIL_OPERATION_TYPE_DELETE,
+       MODEST_MAIL_OPERATION_TYPE_INFO,
+       MODEST_MAIL_OPERATION_TYPE_UNKNOWN,
+} ModestMailOperationTypeOperation;
+
+/**
+ * ErrorCheckingAsyncUserCallback:
+ *
+ * @mail_op: the current mail operation.
+ * @user_data: generic data passed to user defined function.
+ *
+ * This function implements required actions to performs under error
+ * states.  
+ */
+typedef void (*ErrorCheckingUserCallback) (ModestMailOperation *mail_op, gpointer user_data);
+
+/**
+ * GetMsgAsyncUserCallback:
+ *
+ * @mail_op: the current #ModestMailOperation.
+ * @header: a #TnyHeader summary item.
+ * @msg: a #TnyMsg message retrieved by async operation.
+ * @user_data: generic data passed to user defined function.
+ *
+ * This function will be called after get_msg_cb private function, which is
+ * used as tinymail operation callback. The private function fills private 
+ * fields of mail operation and calls user defined callback if it exists.
+ */
+typedef void (*GetMsgAsyncUserCallback) (ModestMailOperation *mail_op, 
+                                        TnyHeader *header, 
+                                        TnyMsg *msg, 
+                                        gpointer user_data);
+
+/**
+ * GetMimePartSizeCallback:
+ *
+ * @mail_op: the current #ModestMailOperation.
+ * @size: size of the attachment
+ * @user_data: generic data passed to user defined function.
+ *
+ */
+typedef void (*GetMimePartSizeCallback) (ModestMailOperation *mail_op, 
+                                        gssize size,
+                                        gpointer user_data);
+
+/**
+ * XferMsgAsynUserCallback:
+ *
+ * @obj: a #GObject generic object which has created current mail operation.
+ * @user_data: generic data passed to user defined function.
+ *
+ * This function will be called after transfer_msgs_cb private function, which is
+ * used as tinymail operation callback. The private function fills private 
+ * fields of mail operation and calls user defined callback if it exists.
+ */
+typedef void (*XferMsgsAsynUserCallback) (const GObject *obj, gpointer user_data);
+
+
+/**
+ * RefreshAsyncUserCallback:
+ *
+ * @mail_op: the current #ModestMailOperation.
+ * @folder: a #TnyFolder which has been refreshed .
+ * @user_data: generic data passed to user defined function.
+ *
+ * This function will be called after refresh_folder_async_cb private function, which is
+ * used as tinymail operation callback. The private function fills private 
+ * fields of mail operation and calls user defined callback if it exists.
+ */
+typedef void (*RefreshAsyncUserCallback) (ModestMailOperation *mail_op, 
+                                         TnyFolder *folder, 
+                                         gpointer user_data);
+
+/**
+ * UpdateAccountCallback:
+ *
+ * @obj: a #GObject generic object which has created current mail operation.
+ * @new_messages: the amount of new messages received
+ * @user_data: generic data passed to user defined function.
+ *
+ * This is the callback of the update_account operation. It informs
+ * the caller about the amount of new messages that have been
+ * downloaded
+ */
+typedef void (*UpdateAccountCallback) (ModestMailOperation *self, 
+                                      gint new_messages,
+                                      gpointer user_data);
+
+/* This struct represents the internal state of a mail operation in a
+   given time */
+typedef struct {
+       guint      done;
+       guint      total;
+       gdouble    bytes_done;
+       gdouble    bytes_total;
+       gboolean   finished;
+       ModestMailOperationStatus        status;
+       ModestMailOperationTypeOperation op_type;
+} ModestMailOperationState;
+
+
 struct _ModestMailOperation {
         GObject parent;
        /* insert public members, if any */
@@ -69,14 +180,83 @@ struct _ModestMailOperationClass {
        GObjectClass parent_class;
 
        /* Signals */
-       void (*progress_changed) (ModestMailOperation *self, gpointer user_data);
+       void (*progress_changed) (ModestMailOperation *self, ModestMailOperationState *state, gpointer user_data);
 };
 
 /* member functions */
 GType        modest_mail_operation_get_type    (void) G_GNUC_CONST;
 
-/* typical parameter-less _new function */
-ModestMailOperation*    modest_mail_operation_new         (void);
+/**
+ * modest_mail_operation_new:
+ * @id: a #ModestMailOperationId identification of operation type.
+ * @source: a #GObject which creates this new operation.
+ * 
+ * Creates a new instance of class #ModestMailOperation, using parameters
+ * to initialize its private structure. @source parameter may be NULL.
+ **/
+ModestMailOperation*    modest_mail_operation_new     (ModestMailOperationTypeOperation type,
+                                                      GObject *source);
+
+/**
+ * modest_mail_operation_new_with_error_handling:
+ * @id: a #ModestMailOperationId identification of operation type.
+ * @source: a #GObject which creates this new operation.
+ * @error_handler: a #ErrorCheckingUserCallback function to performs operations when 
+ * an error occurs.
+ * 
+ * Creates a new instance of class #ModestMailOperation, using parameters
+ * to initialize its private structure. @source parameter may be NULL. 
+ * @error_handler can not be NULL, but it will be returned an mail operation
+ * object without error handling capability.
+ **/
+ModestMailOperation*    modest_mail_operation_new_with_error_handling     (ModestMailOperationTypeOperation op_type,
+                                                                          GObject *source,
+                                                                          ErrorCheckingUserCallback error_handler,
+                                                                          gpointer user_data);
+/**
+ * modest_mail_operation_execute_error_handler
+ * @self: a #ModestMailOperation
+ * 
+ * Executes error handler if exists. The error handler is the one that
+ * MUST free the user data passed to the
+ * modest_mail_operation_new_with_error_handling constructor
+ **/
+void
+modest_mail_operation_execute_error_handler (ModestMailOperation *self);
+
+/**
+ * modest_mail_operation_get_type_operation
+ * @self: a #ModestMailOperation
+ * 
+ * Gets the private op_type field of mail operation. This op_type
+ * identifies the class/type of mail operation.
+ **/
+ModestMailOperationTypeOperation
+modest_mail_operation_get_type_operation (ModestMailOperation *self);
+
+/**
+ * modest_mail_operation_is_mine
+ * @self: a #ModestMailOperation
+ * @source: a #GObject to check if it have created @self operation.
+ * 
+ * Check if @source object its owner of @self mail operation.
+ *
+ * returns: TRUE if source its owner, FALSE otherwise.
+ **/
+gboolean 
+modest_mail_operation_is_mine (ModestMailOperation *self, 
+                              GObject *me);
+
+/**
+ * modest_mail_operation_get_source
+ * @self: a #ModestMailOperation
+ *
+ * returns a new reference to the object that created the mail
+ * operation passed to the constructor, or NULL if none. The caller
+ * must free the new reference
+ **/
+GObject *
+modest_mail_operation_get_source (ModestMailOperation *self);
 
 /* fill in other public functions, eg.: */
 
@@ -99,6 +279,7 @@ void    modest_mail_operation_send_mail       (ModestMailOperation *self,
  * modest_mail_operation_send_new_mail:
  * @self: a #ModestMailOperation
  * @transport_account: a non-NULL #TnyTransportAccount
+ * @draft_msg: a #TnyMsg of the origin draft message, if any
  * @from: the email address of the mail sender
  * @to: a non-NULL email address of the mail receiver
  * @cc: a comma-separated list of email addresses where to send a carbon copy
@@ -116,6 +297,7 @@ void    modest_mail_operation_send_mail       (ModestMailOperation *self,
   **/
 void    modest_mail_operation_send_new_mail   (ModestMailOperation *self,
                                               TnyTransportAccount *transport_account,
+                                              TnyMsg *draft_msg,
                                               const gchar *from,
                                               const gchar *to,
                                               const gchar *cc,
@@ -126,10 +308,46 @@ void    modest_mail_operation_send_new_mail   (ModestMailOperation *self,
                                               const GList *attachments_list,
                                               TnyHeaderFlags priority_flags);
 
+
+/**
+ * modest_mail_operation_save_to_drafts:
+ * @self: a #ModestMailOperation
+ * @transport_account: a non-NULL #TnyTransportAccount
+ * @draft_msg: the previous draft message, in case it's an update
+ * to an existing draft.
+ * @from: the email address of the mail sender
+ * @to: a non-NULL email address of the mail receiver
+ * @cc: a comma-separated list of email addresses where to send a carbon copy
+ * @bcc: a comma-separated list of email addresses where to send a blind carbon copy
+ * @subject: the subject of the new mail
+ * @plain_body: the plain text body of the new mail.
+ * @html_body: the html version of the body of the new mail. If NULL, the mail will
+ *             be sent with the plain body only.
+ * @attachments_list: a #GList of attachments, each attachment must be a #TnyMimePart
+ * 
+ * Save a mail message to drafts using the provided
+ * #TnyTransportAccount. This operation is synchronous, so the
+ * #ModestMailOperation should not be added to any
+ * #ModestMailOperationQueue
+ *
+  **/
+void modest_mail_operation_save_to_drafts   (ModestMailOperation *self,
+                                            TnyTransportAccount *transport_account,
+                                            TnyMsg *draft_msg,
+                                            ModestMsgEditWindow *edit_window,
+                                            const gchar *from,
+                                            const gchar *to,
+                                            const gchar *cc,
+                                            const gchar *bcc,
+                                            const gchar *subject,
+                                            const gchar *plain_body,
+                                            const gchar *html_body,
+                                            const GList *attachments_list,
+                                            TnyHeaderFlags priority_flags);
 /**
  * modest_mail_operation_update_account:
  * @self: a #ModestMailOperation
- * @store_account: a #TnyStoreAccount
+ * @account_name: the id of a Modest account
  * 
  * Asynchronously refreshes the root folders of the given store
  * account. The caller should add the #ModestMailOperation to a
@@ -137,23 +355,25 @@ void    modest_mail_operation_send_new_mail   (ModestMailOperation *self,
  * notified by the "progress_changed" signal each time the progress of
  * the operation changes.
  *
- * Note that the store account passed as parametter will be freed by
- * the mail operation so you must pass a new reference
- *
  * Example
  * <informalexample><programlisting>
  * queue = modest_tny_platform_factory_get_modest_mail_operation_queue_instance (fact)
  * mail_op = modest_mail_operation_new ();
  * g_signal_connect (G_OBJECT (mail_op), "progress_changed", G_CALLBACK(on_progress_changed), NULL);
  * modest_mail_operation_queue_add (queue, mail_op);
- * modest_mail_operation_update_account (mail_op, account)
+ * modest_mail_operation_update_account (mail_op, account_name)
  * g_object_unref (G_OBJECT (mail_op));
  * </programlisting></informalexample>
+ *
+ * Note that the account_name *MUST* be a modest account name, not a
+ * tinymail store account name
  * 
  * Returns: TRUE if the mail operation could be started, or FALSE otherwise
  **/
 gboolean      modest_mail_operation_update_account (ModestMailOperation *self,
-                                                   TnyStoreAccount *store_account);
+                                                   const gchar *account_name,
+                                                   UpdateAccountCallback callback,
+                                                   gpointer user_data);
 
 /* Functions that perform store operations */
 
@@ -210,6 +430,8 @@ void          modest_mail_operation_rename_folder  (ModestMailOperation *self,
  * @folder: a #TnyFolder
  * @parent: the new parent of the folder as #TnyFolderStore
  * @delete_original: wheter or not delete the original folder
+ * @user_callback: a #XferMsgsAsynUserCallback function to call after tinymail callback execution.
+ * @user_data: generic user data which will be passed to @user_callback function.
  * 
  * Sets the given @folder as child of a provided #TnyFolderStore. This
  * operation also transfers all the messages contained in the folder
@@ -220,13 +442,14 @@ void          modest_mail_operation_rename_folder  (ModestMailOperation *self,
  * If @delete_original is TRUE this function moves the original
  * folder, if it is FALSE the it just copies it
  *
- * Returns: the newly transfered folder
  **/
-TnyFolder*    modest_mail_operation_xfer_folder    (ModestMailOperation *self,
-                                                   TnyFolder *folder, 
+void          modest_mail_operation_xfer_folder    (ModestMailOperation *self,
+                                                   TnyFolder *folder,
                                                    TnyFolderStore *parent,
-                                                   gboolean delete_original);
-
+                                                   gboolean delete_original,
+                                                   XferMsgsAsynUserCallback user_callback,
+                                                   gpointer user_data);
+                                                   
 
 /* Functions that performs msg operations */
 
@@ -236,6 +459,8 @@ TnyFolder*    modest_mail_operation_xfer_folder    (ModestMailOperation *self,
  * @header_list: a #TnyList of #TnyHeader to transfer
  * @folder: the #TnyFolder where the messages will be transferred
  * @delete_original: whether or not delete the source messages
+ * @user_callback: a #XferMsgsAsynUserCallback function to call after tinymail callback execution.
+ * @user_data: generic user data which will be passed to @user_callback function.
  * 
  * Asynchronously transfers messages from their current folder to
  * another one. The caller should add the #ModestMailOperation to a
@@ -261,7 +486,9 @@ TnyFolder*    modest_mail_operation_xfer_folder    (ModestMailOperation *self,
 void          modest_mail_operation_xfer_msgs      (ModestMailOperation *self,
                                                    TnyList *header_list, 
                                                    TnyFolder *folder,
-                                                   gboolean delete_original);
+                                                   gboolean delete_original,
+                                                   XferMsgsAsynUserCallback user_callback,
+                                                   gpointer user_data);
 
 /**
  * modest_mail_operation_remove_msg:
@@ -278,6 +505,38 @@ void          modest_mail_operation_remove_msg     (ModestMailOperation *self,
                                                    TnyHeader *header,
                                                    gboolean remove_to_trash);
 
+/**
+ * modest_mail_operation_get_msg:
+ * @self: a #ModestMailOperation
+ * @header_list: the #TnyHeader of the message to get
+ * @user_callback: a #GetMsgAsyncUserCallback function to call after tinymail callback execution.
+ * @user_data: generic user data which will be passed to @user_callback function.
+ * 
+ * Gets a message from header using an user defined @callback function
+ * pased as argument. This operation is asynchronous, so the
+ * #ModestMailOperation should be added to #ModestMailOperationQueue
+ **/
+void          modest_mail_operation_get_msg     (ModestMailOperation *self,
+                                                TnyHeader *header, 
+                                                GetMsgAsyncUserCallback user_callback,
+                                                gpointer user_data);
+/**
+ * modest_mail_operation_get_msgs_full:
+ * @self: a #ModestMailOperation
+ * @header_list: a #TnyList of #TnyHeader objects to get and process
+ * @user_callback: a #TnyGetMsgCallback function to call after tinymail operation execution.
+ * @user_data: user data passed to both, user_callback and update_status_callback.
+ * 
+ * Gets messages from headers list and process hem using @callback function
+ * pased as argument. This operation is asynchronous, so the
+ * #ModestMailOperation should be added to #ModestMailOperationQueue
+ **/
+void          modest_mail_operation_get_msgs_full   (ModestMailOperation *self,
+                                                    TnyList *headers_list,
+                                                    GetMsgAsyncUserCallback user_callback,
+                                                    gpointer user_data,
+                                                    GDestroyNotify notify);
+
 /* Functions to control mail operations */
 /**
  * modest_mail_operation_get_task_done:
@@ -352,23 +611,23 @@ gboolean  modest_mail_operation_cancel          (ModestMailOperation *self);
  * modest_mail_operation_refresh_folder
  * @self: a #ModestMailOperation
  * @folder: the #TnyFolder to refresh
+ * @user_callback: the #RefreshAsyncUserCallback function to be called
+ * after internal refresh async callback was being executed.
  * 
- * Refreshes the contents of a folder
+ * Refreshes the contents of a folder. After internal callback was executed, 
+ * and all interna mail operation field were filled, if exists, it calls an 
+ * user callback function to make UI operations which must be done after folder
+ * was refreshed.
  */
 void      modest_mail_operation_refresh_folder  (ModestMailOperation *self,
-                                                TnyFolder *folder);
+                                                TnyFolder *folder,
+                                                RefreshAsyncUserCallback user_callback,
+                                                gpointer user_data);
 
-/**
- *
- * This function is a workarround. It emits the progress-changed
- * signal. It's used by the mail operation queue to notify the
- * observers attached to that signal that the operation finished. We
- * need to use that for the moment because tinymail does not give us
- * the progress of a given operation very well. So we must delete it
- * when tinymail has that functionality and remove the call to it in
- * the queue as well.
- */
-void _modest_mail_operation_notify_end (ModestMailOperation *self);
+guint     modest_mail_operation_get_id          (ModestMailOperation *self);
+
+guint     modest_mail_operation_set_id          (ModestMailOperation *self,
+                                                guint id);
 
 G_END_DECLS