Close the edit mode after running move to dialog, not before.
[modest] / src / modest-ui-actions.c
index 20cff0a..4512dbe 100644 (file)
@@ -769,6 +769,54 @@ modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
 #endif /* !MODEST_TOOLKIT_GTK */
 }
 
+static guint64
+count_part_size (const gchar *part)
+{
+       GnomeVFSURI *vfs_uri;
+       gchar *escaped_filename;
+       gchar *filename;
+       GnomeVFSFileInfo *info;
+       guint64 result;
+
+       /* Estimation of attachment size if we cannot get it from file info */
+       result = 32768;
+
+       vfs_uri = gnome_vfs_uri_new (part);
+
+       escaped_filename = g_path_get_basename (gnome_vfs_uri_get_path (vfs_uri));
+       filename = gnome_vfs_unescape_string_for_display (escaped_filename);
+       g_free (escaped_filename);
+       gnome_vfs_uri_unref (vfs_uri);
+
+       info = gnome_vfs_file_info_new ();
+       
+       if (gnome_vfs_get_file_info (part, 
+                                    info, 
+                                    GNOME_VFS_FILE_INFO_GET_MIME_TYPE)
+           == GNOME_VFS_OK) {
+               if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) {
+                       result = info->size;
+               }
+       }
+       g_free (filename);
+       gnome_vfs_file_info_unref (info);
+
+       return result;
+}
+
+static guint64 
+count_parts_size (GSList *parts)
+{
+       GSList *node;
+       guint64 result = 0;
+
+       for (node = parts; node != NULL; node = g_slist_next (node)) {
+               result += count_part_size ((const gchar *) node->data);
+       }
+
+       return result;
+}
+
 void
 modest_ui_actions_compose_msg(ModestWindow *win,
                              const gchar *to_str,
@@ -791,11 +839,37 @@ modest_ui_actions_compose_msg(ModestWindow *win,
        ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
        ModestTnyAccountStore *store = modest_runtime_get_account_store();
        GnomeVFSFileSize total_size, allowed_size;
+       guint64 available_disk, expected_size, parts_size;
+       guint parts_count;
 
        /* we check for low-mem */
        if (modest_platform_check_memory_low (win, TRUE))
                goto cleanup;
 
+       available_disk = modest_utils_get_available_space (NULL);
+       parts_count = g_slist_length (attachments);
+       parts_size = count_parts_size (attachments);
+       expected_size = modest_tny_msg_estimate_size (body, NULL, parts_count, parts_size);
+
+       /* Double check: memory full condition or message too big */
+       if (available_disk < MIN_FREE_SPACE ||
+           expected_size > available_disk) {
+               gchar *msg = g_strdup_printf (_KR("cerm_device_memory_full"), "");
+               modest_platform_information_banner (NULL, NULL, msg);
+               g_free (msg);
+
+               return;
+       }
+
+       if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
+               modest_platform_run_information_dialog (
+                       GTK_WINDOW(win),
+                       _KR("memr_ib_operation_disabled"),
+                       TRUE);
+               return;
+       }
+
+
 #ifdef MODEST_TOOLKIT_HILDON2
        if (win)
                account_name = g_strdup (modest_window_get_active_account(win));
@@ -857,16 +931,18 @@ modest_ui_actions_compose_msg(ModestWindow *win,
        gtk_widget_show_all (GTK_WIDGET (msg_win));
 
        while (attachments) {
-               total_size +=
+               GnomeVFSFileSize att_size;
+               att_size =
                        modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win,
                                                               attachments->data, allowed_size);
+               total_size += att_size;
 
-               if (total_size > allowed_size) {
+               if (att_size > allowed_size) {
                        g_warning ("%s: total size: %u",
                                   __FUNCTION__, (unsigned int)total_size);
                        break;
                }
-               allowed_size -= total_size;
+               allowed_size -= att_size;
 
                attachments = g_slist_next(attachments);
        }
@@ -2708,7 +2784,8 @@ modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
 #ifdef MODEST_TOOLKIT_GTK
                        if (modest_main_window_get_contents_style (main_window) ==
                            MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
-                               modest_widget_memory_save (conf, G_OBJECT (header_view),
+                               modest_widget_memory_save (modest_runtime_get_conf (), 
+                                                          G_OBJECT (header_view),
                                                           MODEST_CONF_HEADER_VIEW_KEY);
 #endif
                        modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
@@ -4955,6 +5032,7 @@ on_move_to_dialog_response (GtkDialog *dialog,
        GtkWidget *parent_win;
        MoveToInfo *helper = NULL;
        ModestFolderView *folder_view;
+       gboolean unset_edit_mode = FALSE;
 
        helper = (MoveToInfo *) user_data;
 
@@ -5016,6 +5094,7 @@ on_move_to_dialog_response (GtkDialog *dialog,
                if (dst_folder)
                        g_object_unref (dst_folder);
 
+               unset_edit_mode = TRUE;
                break;
        default:
                g_warning ("%s unexpected response id %d", __FUNCTION__, response);
@@ -5024,6 +5103,11 @@ on_move_to_dialog_response (GtkDialog *dialog,
        /* Free the helper and exit */
        if (helper->list)
                g_object_unref (helper->list);
+       if (unset_edit_mode) {
+#ifdef MODEST_TOOLKIT_HILDON2
+               modest_hildon2_window_unset_edit_mode (MODEST_HILDON2_WINDOW (helper->win));
+#endif
+       }
        g_slice_free (MoveToInfo, helper);
        gtk_widget_destroy (GTK_WIDGET (dialog));
 }
@@ -5983,7 +6067,7 @@ modest_ui_actions_on_edit_mode_move_to (ModestWindow *win)
        /* Show the dialog */
        gtk_widget_show (dialog);
 
-       return TRUE;
+       return FALSE;
 }
 
 /*