Do not update window title if the window is destroyed before the message is retrieved
[modest] / src / hildon2 / modest-msg-view-window.c
index 4747bb5..fca8093 100644 (file)
@@ -94,7 +94,7 @@ struct _ModestMsgViewWindowPrivate {
 
        /* Whether the message is in outbox */
        gboolean is_outbox;
-       
+
        /* A reference to the @model of the header view 
         * to allow selecting previous/next messages,
         * if the message is currently selected in the header view.
@@ -116,7 +116,7 @@ struct _ModestMsgViewWindowPrivate {
        GtkWidget *remove_attachment_banner;
 
        gchar *msg_uid;
-       
+
        GSList *sighandlers;
 };
 
@@ -533,7 +533,10 @@ init_window (ModestMsgViewWindow *obj)
        priv->find_toolbar = hildon_find_toolbar_new (NULL);
        hildon_window_add_toolbar (HILDON_WINDOW (obj), GTK_TOOLBAR (priv->find_toolbar));
        gtk_widget_set_no_show_all (priv->find_toolbar, TRUE);
-       
+
+       /* NULL-ize fields if the window is destroyed */
+       g_signal_connect (priv->msg_view, "destroy", G_CALLBACK (gtk_widget_destroyed), &(priv->msg_view));
+
        gtk_widget_show_all (GTK_WIDGET(main_vbox));
 }
 
@@ -1467,7 +1470,6 @@ modest_msg_view_window_find_toolbar_search (GtkWidget *widget,
                        g_free (priv->last_search);
                        priv->last_search = NULL;
                } else {
-                       modest_msg_view_grab_focus (MODEST_MSG_VIEW (priv->msg_view));
                        hildon_find_toolbar_highlight_entry (HILDON_FIND_TOOLBAR (priv->find_toolbar), TRUE);
                }
        } else {
@@ -1477,7 +1479,6 @@ modest_msg_view_window_find_toolbar_search (GtkWidget *widget,
                        g_free (priv->last_search);
                        priv->last_search = NULL;
                } else {
-                       modest_msg_view_grab_focus (MODEST_MSG_VIEW (priv->msg_view));
                        hildon_find_toolbar_highlight_entry (HILDON_FIND_TOOLBAR (priv->find_toolbar), TRUE);
                }
        }
@@ -2182,13 +2183,12 @@ toolbar_resize (ModestMsgViewWindow *self)
                gtk_tool_item_set_expand (GTK_TOOL_ITEM (widget), FALSE);
                gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (widget), FALSE);
                gtk_widget_set_size_request (GTK_WIDGET (widget), static_button_size, -1);
-               
+
                gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (priv->next_toolitem), TRUE);
                gtk_tool_item_set_expand (GTK_TOOL_ITEM (priv->next_toolitem), TRUE);
                gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (priv->prev_toolitem), TRUE);
                gtk_tool_item_set_expand (GTK_TOOL_ITEM (priv->prev_toolitem), TRUE);
        }
-               
 }
 
 static void
@@ -2325,7 +2325,7 @@ on_mail_operation_started (ModestMailOperation *mail_op,
        tmp = priv->progress_widgets;
        source = modest_mail_operation_get_source(mail_op);
        if (G_OBJECT (self) == source) {
-               if (op_type == MODEST_MAIL_OPERATION_TYPE_RECEIVE ) {
+               if (op_type == MODEST_MAIL_OPERATION_TYPE_RECEIVE) {
                        set_toolbar_transfer_mode(self);
                        while (tmp) {
                                modest_progress_object_add_operation (
@@ -2352,7 +2352,7 @@ on_mail_operation_finished (ModestMailOperation *mail_op,
        op_type = modest_mail_operation_get_type_operation (mail_op);
        tmp = priv->progress_widgets;
        
-       if (op_type == MODEST_MAIL_OPERATION_TYPE_RECEIVE ) {
+       if (op_type == MODEST_MAIL_OPERATION_TYPE_RECEIVE) {
                while (tmp) {
                        modest_progress_object_remove_operation (MODEST_PROGRESS_OBJECT (tmp->data),
                                                                 mail_op);
@@ -2363,15 +2363,15 @@ on_mail_operation_finished (ModestMailOperation *mail_op,
                if (observers_empty (self)) {
                        set_progress_hint (self, FALSE);
                }
-
-               /* Update dimming rules. We have to do this right here
-                  and not in view_msg_cb because at that point the
-                  transfer mode is still enabled so the dimming rule
-                  won't let the user delete the message that has been
-                  readed for example */
-               modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (self));
-               modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
        }
+
+       /* Update dimming rules. We have to do this right here
+          and not in view_msg_cb because at that point the
+          transfer mode is still enabled so the dimming rule
+          won't let the user delete the message that has been
+          readed for example */
+       check_dimming_rules_after_change (self);
+
 }
 
 static void
@@ -2572,7 +2572,6 @@ typedef struct
 typedef struct
 {
        GList *pairs;
-       GtkWidget *banner;
        GnomeVFSResult result;
 } SaveMimePartInfo;
 
@@ -2595,7 +2594,6 @@ save_mime_part_info_free (SaveMimePartInfo *info, gboolean with_struct)
        g_list_free (info->pairs);
        info->pairs = NULL;
        if (with_struct) {
-               gtk_widget_destroy (info->banner);
                g_slice_free (SaveMimePartInfo, info);
        }
 }
@@ -2688,9 +2686,6 @@ save_mime_parts_to_file_with_checks (SaveMimePartInfo *info)
        if (!is_ok) {
                save_mime_part_info_free (info, TRUE);
        } else {
-               GtkWidget *banner = hildon_banner_show_animation (NULL, NULL, 
-                                                                 _CS("sfil_ib_saving"));
-               info->banner = banner;
                g_thread_create ((GThreadFunc)save_mime_part_to_file, info, FALSE, NULL);
        }
 
@@ -2775,6 +2770,10 @@ modest_msg_view_window_save_attachments (ModestMsgViewWindow *window, TnyList *m
                /* In Hildon 2.2 save and delete operate over all the attachments as there's no
                 * selection available */
                mime_parts = modest_msg_view_get_attachments (MODEST_MSG_VIEW (priv->msg_view));
+               if (!modest_maemo_utils_select_attachments (GTK_WINDOW (window), mime_parts)) {
+                       g_object_unref (mime_parts);
+                       return;
+               }
                if (mime_parts == NULL || tny_list_get_length (mime_parts) == 0)
                        return;
        } else {
@@ -2803,7 +2802,7 @@ modest_msg_view_window_save_attachments (ModestMsgViewWindow *window, TnyList *m
                save_multiple_str = g_strdup_printf (_FM("sfil_va_number_of_objects_attachments"), 
                                                     tny_list_get_length (mime_parts));
        }
-       
+
        save_dialog = hildon_file_chooser_dialog_new (GTK_WINDOW (window), 
                                                      GTK_FILE_CHOOSER_ACTION_SAVE);
 
@@ -2887,7 +2886,8 @@ modest_msg_view_window_remove_attachments (ModestMsgViewWindow *window, gboolean
        }
        g_object_unref (iter);
 
-       if (tny_list_get_length (mime_parts) == 0) {
+       if (!modest_maemo_utils_select_attachments (GTK_WINDOW (window), mime_parts) ||
+           tny_list_get_length (mime_parts) == 0) {
                g_object_unref (mime_parts);
                return;
        }
@@ -2966,11 +2966,18 @@ modest_msg_view_window_remove_attachments (ModestMsgViewWindow *window, gboolean
 static void
 update_window_title (ModestMsgViewWindow *window)
 {
-       ModestMsgViewWindowPrivate *priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (window);
+       ModestMsgViewWindowPrivate *priv;
        TnyMsg *msg = NULL;
        TnyHeader *header = NULL;
        gchar *subject = NULL;
 
+       priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (window);
+
+       /* Note that if the window is closed while we're retrieving
+          the message, this widget could de deleted */
+       if (!priv->msg_view)
+               return;
+
        msg = tny_msg_view_get_msg (TNY_MSG_VIEW (priv->msg_view));
 
        if (msg != NULL) {
@@ -2989,9 +2996,10 @@ update_window_title (ModestMsgViewWindow *window)
 }
 
 
-static void on_move_focus (GtkWidget *widget,
-                          GtkDirectionType direction,
-                          gpointer userdata)
+static void
+on_move_focus (GtkWidget *widget,
+              GtkDirectionType direction,
+              gpointer userdata)
 {
        g_signal_stop_emission_by_name (G_OBJECT (widget), "move-focus");
 }
@@ -3107,7 +3115,7 @@ on_fetch_image (ModestMsgView *msgview,
                return FALSE;
        }
 
-       return TRUE;;
+       return TRUE;
 }
 
 static void