* Removed an invalid g_object_unref in a mail operation
authorSergio Villar Senin <svillar@igalia.com>
Wed, 30 May 2007 12:50:39 +0000 (12:50 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Wed, 30 May 2007 12:50:39 +0000 (12:50 +0000)
* Rewritten the dimming rules for the "new folder" action
* Removed some invalid comments
* Fixed some errors in mail_operation_create_folder

pmo-trunk-r1997

src/modest-mail-operation-queue.c
src/modest-mail-operation.c
src/modest-runtime.c
src/modest-ui-actions.c
src/modest-ui-dimming-rules.c

index 9330c0e..98a6c65 100644 (file)
@@ -216,7 +216,7 @@ modest_mail_operation_queue_remove (ModestMailOperationQueue *self,
                                g_warning ("%s: operation canceled \n", __FUNCTION__);
                        else
                                g_warning ("%s: possible error in a mail operation " \
-                                          "implementation. The status is not succesful" \
+                                          "implementation. The status is not successful " \
                                           "but the mail operation does not have any " \
                                           "error set\n", __FUNCTION__);
                }
index d3e1402..ce936b2 100644 (file)
@@ -179,7 +179,7 @@ modest_mail_operation_init (ModestMailOperation *obj)
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj);
 
-       priv->account  = NULL;
+       priv->account        = NULL;
        priv->status         = MODEST_MAIL_OPERATION_STATUS_INVALID;
        priv->op_type        = MODEST_MAIL_OPERATION_TYPE_UNKNOWN;
        priv->error          = NULL;
@@ -774,6 +774,7 @@ update_account_thread (gpointer thr_user_data)
        TnyIterator *iter = NULL;
        TnyFolderStoreQuery *query = NULL;
        ModestMailOperationPrivate *priv;
+       ModestTnySendQueue *send_queue;
 
        info = (UpdateAccountInfo *) thr_user_data;
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(info->mail_op);
@@ -899,14 +900,18 @@ update_account_thread (gpointer thr_user_data)
                g_object_unref (priv->account);
        priv->account = g_object_ref (info->transport_account);
        
-       ModestTnySendQueue *send_queue = modest_runtime_get_send_queue
-               (info->transport_account);
-
-       timeout = g_timeout_add (250, idle_notify_progress, info->mail_op);
-       modest_tny_send_queue_try_to_send (send_queue);
-       g_source_remove (timeout);
-
-       g_object_unref (G_OBJECT(send_queue));
+       send_queue = modest_runtime_get_send_queue (info->transport_account);
+       if (send_queue) {
+               timeout = g_timeout_add (250, idle_notify_progress, info->mail_op);
+               modest_tny_send_queue_try_to_send (send_queue);
+               g_source_remove (timeout);
+       } else {
+               g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
+                            MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED,
+                            "cannot create a send queue for %s\n", 
+                            tny_account_get_name (TNY_ACCOUNT (info->transport_account)));
+               priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
+       }
        
        /* Check if the operation was a success */
        if (!priv->error) {
@@ -1028,44 +1033,33 @@ modest_mail_operation_create_folder (ModestMailOperation *self,
                                     TnyFolderStore *parent,
                                     const gchar *name)
 {
-       ModestTnyFolderRules rules;
        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);
 
-       /* Get account and set it into mail_operation */
-       priv->account = tny_folder_get_account (TNY_FOLDER(parent));
-
        /* Check parent */
-       if (!TNY_IS_FOLDER (parent)) {
-               /* Set status failed and set an error */
-               priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
-               g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
-                            MODEST_MAIL_OPERATION_ERROR_BAD_PARAMETER,
-                            _("mail_in_ui_folder_create_error"));
-       } else {
+       if (TNY_IS_FOLDER (parent)) {
                /* Check folder rules */
-               rules = modest_tny_folder_get_rules (TNY_FOLDER (parent));
+               ModestTnyFolderRules rules = modest_tny_folder_get_rules (TNY_FOLDER (parent));
                if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
                        /* Set status failed and set an error */
                        priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
                        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) {
+       if (!priv->error) {
                /* Create the folder */
                new_folder = tny_folder_store_create_folder (parent, name, &(priv->error));
                CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED);
+               if (!priv->error)
+                       priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
        }
 
        /* Notify about operation end */
index 24fe87b..ed4cf76 100644 (file)
@@ -144,7 +144,6 @@ modest_runtime_get_platform_factory  (void)
 ModestTnySendQueue*
 modest_runtime_get_send_queue  (TnyTransportAccount *account)
 {
-       /* printf ("DEBUG: %s: transport account id=%s\n", __FUNCTION__, tny_account_get_id (TNY_ACCOUNT(account))); */
        ModestCacheMgr *cache_mgr;
        GHashTable     *send_queue_cache;
        gpointer       orig_key, send_queue;
index d44cd5a..d5bd712 100644 (file)
@@ -1650,26 +1650,20 @@ modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_windo
                        if (result == GTK_RESPONSE_REJECT) {
                                finished = TRUE;
                        } else {
-                               ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO, G_OBJECT(main_window));
+                               ModestMailOperation *mail_op;
                                TnyFolder *new_folder = NULL;
 
+                               mail_op  = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO, 
+                                                                     G_OBJECT(main_window));
                                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
                                                                 mail_op);
-               
                                new_folder = modest_mail_operation_create_folder (mail_op,
                                                                                  parent_folder,
                                                                                  (const gchar *) folder_name);
                                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), */
-/*                                                                             _("mail_in_ui_folder_create_error")); */
-/*                             } */
+                               }
                                g_object_unref (mail_op);
                        }
                        g_free (folder_name);
index 13bc3f2..d9819b7 100644 (file)
@@ -31,6 +31,7 @@
 #include <config.h>
 #endif /*HAVE_CONFIG_H*/
 
+#include <string.h>
 #include "modest-ui-dimming-rules.h"
 #include "modest-tny-folder.h"
 #include <modest-runtime.h>
@@ -64,12 +65,38 @@ gboolean
 modest_ui_dimming_rules_on_new_folder (ModestWindow *win, gpointer user_data)
 {
        gboolean dimmed = FALSE;
+       GtkWidget *folder_view = NULL;
+       TnyFolderStore *parent_folder = NULL;
 
        g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
-               
-       /* Check dimmed rule */ 
-       if (!dimmed)
+
+
+       folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
+                                                          MODEST_WIDGET_TYPE_FOLDER_VIEW);
+       /* Get selected folder as parent of new folder to create */
+       parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
+       if (!parent_folder)
+               return TRUE;
+       
+       /* If it's the local account do not dimm */
+       if (modest_tny_folder_store_is_virtual_local_folders (parent_folder)) {
+               return FALSE;
+       } else if (TNY_IS_ACCOUNT (parent_folder)) {
+               /* If it's the MMC root folder then dimm it */
+               if (!strcmp (tny_account_get_id (TNY_ACCOUNT (parent_folder)), MODEST_MMC_ACCOUNT_ID)) {
+                       dimmed = TRUE;
+               } else {
+                       const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (parent_folder));
+                       /* If it's POP then dimm */
+                       dimmed = (modest_protocol_info_get_transport_store_protocol (proto_str) == 
+                                 MODEST_PROTOCOL_STORE_POP) ? TRUE : FALSE;
+               }
+       } else {
+               /* TODO: the specs say that only one level of subfolder is allowed, is this true ? */
+
+               /* Apply folder rules */        
                dimmed = _selected_folder_not_writeable (MODEST_MAIN_WINDOW(win));
+       }
 
        return dimmed;
 }