* Removed some unused errors
authorSergio Villar Senin <svillar@igalia.com>
Thu, 26 Apr 2007 11:18:28 +0000 (11:18 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Thu, 26 Apr 2007 11:18:28 +0000 (11:18 +0000)
* Removed error handling code froms Queues
* Added ModestFolderRules to mail operations

pmo-trunk-r1677

src/maemo/modest-platform.c
src/modest-error.h
src/modest-mail-operation-queue.c
src/modest-mail-operation.c
src/modest-tny-folder.c
src/modest-ui-actions.c

index a4965a6..2659506 100644 (file)
@@ -506,5 +506,4 @@ modest_platform_run_information_dialog (GtkWindow *parent_window,
        gtk_dialog_run (GTK_DIALOG (dialog));
 
        gtk_widget_destroy (GTK_WIDGET (dialog));
        gtk_dialog_run (GTK_DIALOG (dialog));
 
        gtk_widget_destroy (GTK_WIDGET (dialog));
-       g_free (message);
 }
 }
index 092eee1..c219685 100644 (file)
@@ -40,11 +40,10 @@ typedef enum _ModestErrorDomain {
 } ModestErrorDomain;
 
 typedef enum _ModestErrorCode {
 } ModestErrorDomain;
 
 typedef enum _ModestErrorCode {
-        MODEST_MAIL_OPERATION_ERROR_BAD_ACCOUNT,
-        MODEST_MAIL_OPERATION_ERROR_MISSING_PARAMETER,
+        MODEST_MAIL_OPERATION_ERROR_BAD_PARAMETER,
        MODEST_MAIL_OPERATION_ERROR_OPERATION_CANCELED,
        MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
        MODEST_MAIL_OPERATION_ERROR_OPERATION_CANCELED,
        MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
-       MODEST_MAIL_OPERATION_ERROR_INTERNAL,
+       MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
        
 } ModestErrorCode;
 
        
 } ModestErrorCode;
 
index 6f46a4e..26c2888 100644 (file)
@@ -202,13 +202,6 @@ modest_mail_operation_queue_remove (ModestMailOperationQueue *self,
        g_signal_emit (self, signals[QUEUE_CHANGED_SIGNAL], 0,
                       mail_op, MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED);
 
        g_signal_emit (self, signals[QUEUE_CHANGED_SIGNAL], 0,
                       mail_op, MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED);
 
-       /* TODO: errors? */
-       {
-               const GError *err = modest_mail_operation_get_error (mail_op);
-               if (err)
-                       g_warning (err->message);
-       }
-
        /* Free object */
        g_object_unref (G_OBJECT (mail_op));
        modest_runtime_verify_object_death (mail_op, "");
        /* Free object */
        g_object_unref (G_OBJECT (mail_op));
        modest_runtime_verify_object_death (mail_op, "");
index 2bfd135..a9f9e5a 100644 (file)
@@ -45,6 +45,7 @@
 #include <modest-runtime.h>
 #include "modest-text-utils.h"
 #include "modest-tny-msg.h"
 #include <modest-runtime.h>
 #include "modest-text-utils.h"
 #include "modest-tny-msg.h"
+#include "modest-tny-folder.h"
 #include "modest-tny-platform-factory.h"
 #include "modest-marshal.h"
 #include "modest-error.h"
 #include "modest-tny-platform-factory.h"
 #include "modest-marshal.h"
 #include "modest-error.h"
@@ -78,9 +79,8 @@ struct _ModestMailOperationPrivate {
                                                    MODEST_TYPE_MAIL_OPERATION, \
                                                    ModestMailOperationPrivate))
 
                                                    MODEST_TYPE_MAIL_OPERATION, \
                                                    ModestMailOperationPrivate))
 
-#define CHECK_EXCEPTION(priv, new_status, op)  if (priv->error) {\
+#define CHECK_EXCEPTION(priv, new_status)  if (priv->error) {\
                                                    priv->status = new_status;\
                                                    priv->status = new_status;\
-                                                   op;\
                                                }
 
 typedef struct _RefreshFolderAsyncHelper
                                                }
 
 typedef struct _RefreshFolderAsyncHelper
@@ -244,7 +244,7 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
        /* Check parametters */
        if (to == NULL) {
                g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
        /* Check parametters */
        if (to == NULL) {
                g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
-                            MODEST_MAIL_OPERATION_ERROR_MISSING_PARAMETER,
+                            MODEST_MAIL_OPERATION_ERROR_BAD_PARAMETER,
                             _("Error trying to send a mail. You need to set at least one recipient"));
                return;
        }
                             _("Error trying to send a mail. You need to set at least one recipient"));
                return;
        }
@@ -482,17 +482,37 @@ modest_mail_operation_create_folder (ModestMailOperation *self,
                                     TnyFolderStore *parent,
                                     const gchar *name)
 {
                                     TnyFolderStore *parent,
                                     const gchar *name)
 {
+       ModestTnyFolderRules rules;
        ModestMailOperationPrivate *priv;
        TnyFolder *new_folder = NULL;
        ModestMailOperationPrivate *priv;
        TnyFolder *new_folder = NULL;
+       gboolean can_create = FALSE;
 
        g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), NULL);
        g_return_val_if_fail (name, NULL);
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
 
 
        g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), NULL);
        g_return_val_if_fail (name, NULL);
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
 
-       /* Create the folder */
-       new_folder = tny_folder_store_create_folder (parent, name, &(priv->error));
-       CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED, return NULL);
+       /* Check parent */
+       if (!TNY_IS_FOLDER (parent)) {
+               g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
+                            MODEST_MAIL_OPERATION_ERROR_BAD_PARAMETER,
+                            _("mail_in_ui_folder_create_error"));
+       } else {
+               /* Check folder rules */
+               rules = modest_tny_folder_get_rules (TNY_FOLDER (parent));
+               if (rules | MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE)
+                       g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
+                                    MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
+                                    _("mail_in_ui_folder_create_error"));
+               else
+                       can_create = TRUE;              
+       }
+
+       if (can_create) {
+               /* Create the folder */
+               new_folder = tny_folder_store_create_folder (parent, name, &(priv->error));
+               CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED);
+       }
 
        /* Notify the queue */
        modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
 
        /* Notify the queue */
        modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
@@ -508,12 +528,22 @@ modest_mail_operation_remove_folder (ModestMailOperation *self,
        TnyFolderStore *parent;
        TnyAccount *account;
        ModestMailOperationPrivate *priv;
        TnyFolderStore *parent;
        TnyAccount *account;
        ModestMailOperationPrivate *priv;
+       ModestTnyFolderRules rules;
 
        g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
        g_return_if_fail (TNY_IS_FOLDER (folder));
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
 
 
        g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
        g_return_if_fail (TNY_IS_FOLDER (folder));
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
 
+       /* Check folder rules */
+       rules = modest_tny_folder_get_rules (TNY_FOLDER (parent));
+       if (rules | MODEST_FOLDER_RULES_FOLDER_NON_DELETABLE) {
+               g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
+                            MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
+                            _("mail_in_ui_folder_delete_error"));
+               goto end;
+       }
+
        /* Get the account */
        account = tny_folder_get_account (folder);
 
        /* Get the account */
        account = tny_folder_get_account (folder);
 
@@ -530,13 +560,14 @@ modest_mail_operation_remove_folder (ModestMailOperation *self,
                parent = tny_folder_get_folder_store (folder);
 
                tny_folder_store_remove_folder (parent, folder, &(priv->error));
                parent = tny_folder_get_folder_store (folder);
 
                tny_folder_store_remove_folder (parent, folder, &(priv->error));
-               CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED, );
+               CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED);
 
                if (parent)
                        g_object_unref (G_OBJECT (parent));
        }
        g_object_unref (G_OBJECT (account));
 
 
                if (parent)
                        g_object_unref (G_OBJECT (parent));
        }
        g_object_unref (G_OBJECT (account));
 
+ end:
        /* Notify the queue */
        modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
 }
        /* Notify the queue */
        modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
 }
@@ -547,6 +578,7 @@ modest_mail_operation_rename_folder (ModestMailOperation *self,
                                     const gchar *name)
 {
        ModestMailOperationPrivate *priv;
                                     const gchar *name)
 {
        ModestMailOperationPrivate *priv;
+       ModestTnyFolderRules rules;
 
        g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
        g_return_if_fail (TNY_IS_FOLDER_STORE (folder));
 
        g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
        g_return_if_fail (TNY_IS_FOLDER_STORE (folder));
@@ -554,15 +586,18 @@ modest_mail_operation_rename_folder (ModestMailOperation *self,
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
 
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
 
-       /* FIXME: better error handling */
-       if (strrchr (name, '/') != NULL)
-               goto out;
-
-       /* Rename. Camel handles folder subscription/unsubscription */
-       tny_folder_set_name (folder, name, &(priv->error));
-       CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED, goto out);
+       /* Check folder rules */
+       rules = modest_tny_folder_get_rules (TNY_FOLDER (folder));
+       if (rules | MODEST_FOLDER_RULES_FOLDER_NON_RENAMEABLE) {
+               g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
+                            MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
+                            _("FIXME: unable to rename"));
+       } else {
+               /* Rename. Camel handles folder subscription/unsubscription */
+               tny_folder_set_name (folder, name, &(priv->error));
+               CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED);
+       }
 
 
- out:
        /* Notify the queue */
        modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
  }
        /* Notify the queue */
        modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
  }
@@ -574,7 +609,8 @@ modest_mail_operation_xfer_folder (ModestMailOperation *self,
                                   gboolean delete_original)
 {
        ModestMailOperationPrivate *priv;
                                   gboolean delete_original)
 {
        ModestMailOperationPrivate *priv;
-       TnyFolder *new_folder;
+       TnyFolder *new_folder = NULL;
+       ModestTnyFolderRules rules;
 
        g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), NULL);
        g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), NULL);
 
        g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), NULL);
        g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), NULL);
@@ -582,11 +618,20 @@ modest_mail_operation_xfer_folder (ModestMailOperation *self,
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
 
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
 
-       new_folder = tny_folder_copy (folder,
-                                     parent,
-                                     tny_folder_get_name (folder),
-                                     delete_original, 
-                                     &(priv->error));
+       /* The moveable restriction is applied also to copy operation */
+       rules = modest_tny_folder_get_rules (TNY_FOLDER (parent));
+       if (rules | MODEST_FOLDER_RULES_FOLDER_NON_MOVEABLE) {
+               g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
+                            MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
+                            _("FIXME: unable to rename"));
+       } else {
+               /* Move/Copy folder */
+               new_folder = tny_folder_copy (folder,
+                                             parent,
+                                             tny_folder_get_name (folder),
+                                             delete_original, 
+                                             &(priv->error));
+       }
 
        /* Notify the queue */
        modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
 
        /* Notify the queue */
        modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
index 1090461..14474d2 100644 (file)
@@ -106,7 +106,7 @@ modest_tny_folder_guess_folder_type (const TnyFolder *folder)
 
 /* FIXME: encode all folder rules here */
 ModestTnyFolderRules
 
 /* FIXME: encode all folder rules here */
 ModestTnyFolderRules
-modest_tny_folder_get_folder_rules   (const TnyFolder *folder)
+modest_tny_folder_get_rules   (const TnyFolder *folder)
 {
        ModestTnyFolderRules rules = 0;
        TnyFolderType type;
 {
        ModestTnyFolderRules rules = 0;
        TnyFolderType type;
index 0771fd2..469e313 100644 (file)
@@ -1297,13 +1297,14 @@ modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_windo
                                if (new_folder) {
                                        g_object_unref (new_folder);
                                        finished = TRUE;
                                if (new_folder) {
                                        g_object_unref (new_folder);
                                        finished = TRUE;
-                               } else {
-                                       /* TODO: check error and follow proper actions */
-/*                                     suggested_name = X; */
-                                       /* Show error to the user */
-                                       modest_platform_run_information_dialog (GTK_WINDOW (main_window),
-                                                                               MODEST_INFORMATION_CREATE_FOLDER);
-                               }
+                               } 
+/*                             else { */
+/*                                     /\* TODO: check error and follow proper actions *\/ */
+/* /\*                                         suggested_name = X; *\/ */
+/*                                     /\* Show error to the user *\/ */
+/*                                     modest_platform_run_information_dialog (GTK_WINDOW (main_window), */
+/*                                                                             MODEST_INFORMATION_CREATE_FOLDER); */
+/*                             } */
                                g_object_unref (mail_op);
                        }
                        g_free (folder_name);
                                g_object_unref (mail_op);
                        }
                        g_free (folder_name);