Added msg view window reload feature. Now we can force a message reload
[modest] / src / modest-ui-actions.c
index a3355c4..23967ab 100644 (file)
@@ -805,7 +805,8 @@ modest_ui_actions_compose_msg(ModestWindow *win,
                goto cleanup;
 
 #ifdef MODEST_TOOLKIT_HILDON2
-       account_name = g_strdup (modest_window_get_active_account(win));
+       if (win)
+               account_name = g_strdup (modest_window_get_active_account(win));
 #endif
        if (!account_name) {
                account_name = modest_account_mgr_get_default_account(mgr);
@@ -815,7 +816,10 @@ modest_ui_actions_compose_msg(ModestWindow *win,
                goto cleanup;
        }
 
-       mailbox = modest_window_get_active_mailbox (win);
+       if (win)
+               mailbox = modest_window_get_active_mailbox (win);
+       else
+               mailbox = NULL;
        account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
        if (!account) {
                g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
@@ -1234,10 +1238,11 @@ check_memory_full_error (GtkWidget *parent_window, GError *err)
        if (err == NULL)
                return FALSE;
 
-       if (is_memory_full_error (err, NULL))
-               modest_platform_information_banner (parent_window,
-                                                   NULL, _KR("cerm_device_memory_full"));
-       else if (err->code == TNY_SYSTEM_ERROR_MEMORY)
+       if (is_memory_full_error (err, NULL)) {
+               gchar *msg = g_strdup_printf (_KR("cerm_device_memory_full"), "");
+               modest_platform_information_banner (parent_window, NULL, msg);
+               g_free (msg);
+       } else if (err->code == TNY_SYSTEM_ERROR_MEMORY)
                /* If the account was created in memory full
                   conditions then tinymail won't be able to
                   connect so it'll return this error code */
@@ -1265,8 +1270,9 @@ modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op,
           don't show any message */
        if (status != MODEST_MAIL_OPERATION_STATUS_CANCELED) {
                if (is_memory_full_error ((GError *) error, mail_op)) {
-                       modest_platform_information_banner ((GtkWidget *) win,
-                                                           NULL, _KR("cerm_device_memory_full"));
+                       gchar *msg = g_strdup_printf (_KR("cerm_device_memory_full"), "");
+                       modest_platform_information_banner ((GtkWidget *) win, NULL, msg);
+                       g_free (msg);
                } else if (error->code == TNY_SYSTEM_ERROR_MEMORY) {
                        modest_platform_information_banner ((GtkWidget *) win,
                                                            NULL, _("emev_ui_imap_inbox_select_error"));
@@ -2574,7 +2580,7 @@ folder_refreshed_cb (ModestMailOperation *mail_op,
                     gpointer user_data)
 {
        ModestMainWindow *win = NULL;
-       GtkWidget *folder_view;
+       GtkWidget *folder_view, *header_view;
        const GError *error;
 
        g_return_if_fail (TNY_IS_FOLDER (folder));
@@ -2593,6 +2599,8 @@ folder_refreshed_cb (ModestMailOperation *mail_op,
 
        folder_view =
                modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+       header_view =
+               modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
 
        if (folder_view) {
                TnyFolderStore *current_folder;
@@ -2607,10 +2615,10 @@ folder_refreshed_cb (ModestMailOperation *mail_op,
        }
 
        /* Check if folder is empty and set headers view contents style */
-       if (tny_folder_get_all_count (folder) == 0)
+       if ((tny_folder_get_all_count (folder) == 0) ||
+           modest_header_view_is_empty (MODEST_HEADER_VIEW (header_view)))
                modest_main_window_set_contents_style (win,
                                                       MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
-
 }
 
 void
@@ -2843,9 +2851,10 @@ enough_space_for_message (ModestMsgEditWindow *edit_window,
        /* 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);
 
-               modest_platform_information_banner (NULL, NULL,
-                                                   _KR("cerm_device_memory_full"));
                return FALSE;
        }
 
@@ -3453,15 +3462,17 @@ modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
                                               gpointer user_data)
 {
        const GError *error = NULL;
-       const gchar *message = NULL;
+       gchar *message = NULL;
+       gboolean mem_full;
 
        /* Get error message */
        error = modest_mail_operation_get_error (mail_op);
        if (!error)
                g_return_if_reached ();
 
-       if (is_memory_full_error ((GError *) error, mail_op)) {
-               message = _KR("cerm_device_memory_full");
+       mem_full = is_memory_full_error ((GError *) error, mail_op);
+       if (mem_full) {
+               message = g_strdup_printf (_KR("cerm_device_memory_full"), "");
        } else if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
                   error->code == MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS) {
                message = _CS("ckdg_ib_folder_already_exists");
@@ -3477,6 +3488,9 @@ modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
        /* We don't set a parent for the dialog because the dialog
           will be destroyed so the banner won't appear */
        modest_platform_information_banner (NULL, NULL, message);
+
+       if (mem_full)
+               g_free (message);
 }
 
 typedef struct {
@@ -4586,7 +4600,18 @@ headers_action_show_details (TnyHeader *header,
                             gpointer user_data)
 
 {
-       modest_platform_run_header_details_dialog (GTK_WINDOW (window), header);
+       gboolean async_retrieval;
+       TnyMsg *msg = NULL;
+
+       if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
+               async_retrieval = TRUE;
+               msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (window));
+       } else {
+               async_retrieval = FALSE;
+       }
+       modest_platform_run_header_details_dialog (GTK_WINDOW (window), header, async_retrieval, msg);
+       if (msg)
+               g_object_unref (msg);
 }
 
 /*
@@ -5479,13 +5504,15 @@ xfer_messages_error_handler (ModestMailOperation *mail_op,
        win = modest_mail_operation_get_source (mail_op);
        error = modest_mail_operation_get_error (mail_op);
 
-       if (error && is_memory_full_error ((GError *) error, mail_op))
-               modest_platform_information_banner ((GtkWidget *) win,
-                                                   NULL, _KR("cerm_device_memory_full"));
-       else
+       if (error && is_memory_full_error ((GError *) error, mail_op)) {
+               gchar *msg = g_strdup_printf (_KR("cerm_device_memory_full"), "");
+               modest_platform_information_banner ((GtkWidget *) win, NULL, msg);
+               g_free (msg);
+       } else {
                modest_platform_run_information_dialog ((GtkWindow *) win,
                                                        _("mail_in_ui_folder_move_target_error"),
                                                        FALSE);
+       }
        if (win)
                g_object_unref (win);
 }
@@ -6666,3 +6693,31 @@ modest_ui_actions_on_delete_account (GtkWindow *parent_window,
        }
        return removed;
 }
+
+void 
+modest_ui_actions_on_fetch_images (GtkAction *action,
+                                  ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window));
+
+       modest_msg_view_window_fetch_images (MODEST_MSG_VIEW_WINDOW (window));
+
+}
+
+void
+modest_ui_actions_on_reload_message (const gchar *msg_id)
+{
+       ModestWindow *window = NULL;
+
+       g_return_if_fail (msg_id && msg_id[0] != '\0');
+       if (!modest_window_mgr_find_registered_message_uid (modest_runtime_get_window_mgr (),
+                                                           msg_id,
+                                                           &window))
+               return;
+
+
+       if (window == NULL || !MODEST_IS_MSG_VIEW_WINDOW (window))
+               return;
+
+       modest_msg_view_window_reload (MODEST_MSG_VIEW_WINDOW (window));
+}