From: Felipe Erias Morandeira Date: Fri, 14 Dec 2007 12:05:20 +0000 (+0000) Subject: Fixes NB#78602 X-Git-Tag: git_migration_finished~1921 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=f19d5b6e2df7fb9cea5db37287802d1245a7b796 Fixes NB#78602 * modest-mail-operation-queue.[hc]: (modest_mail_operation_queue_get_by_source): returns the mail operations in the queue associated with a given source * widgets/modest-window-mgr.c: (modest_window_mgr_unregister_window): if the window that is being closed is a ModestMsgViewWindow, it cancels "open" and "receive" operations that have it as their source * maemo/modest-main-window.c: (on_mail_operation_started): only goes to transfer mode if it is the source of the operation whose start has been notified * maemo/modest-msg-view-window.c: (on_mail_operation_started): only goes to transfer mode if it is the source of the operation whose start has been notified (view_msg_cb): added checks for cancelled operations and empty fields pmo-trunk-r3917 --- diff --git a/src/maemo/modest-main-window.c b/src/maemo/modest-main-window.c index b65c551..e827044 100644 --- a/src/maemo/modest-main-window.c +++ b/src/maemo/modest-main-window.c @@ -2216,7 +2216,7 @@ on_mail_operation_started (ModestMailOperation *mail_op, /* Add operation observers and change toolbar if neccessary*/ tmp = priv->progress_widgets; if (mode == TOOLBAR_MODE_TRANSFER) { - if (mode_changed) + if (mode_changed && (G_OBJECT (self) == modest_mail_operation_get_source(mail_op))) set_toolbar_transfer_mode(self); while (tmp) { diff --git a/src/maemo/modest-msg-view-window.c b/src/maemo/modest-msg-view-window.c index 0360e2d..7246417 100644 --- a/src/maemo/modest-msg-view-window.c +++ b/src/maemo/modest-msg-view-window.c @@ -1810,6 +1810,11 @@ view_msg_cb (ModestMailOperation *mail_op, ModestMsgViewWindowPrivate *priv = NULL; GtkTreeRowReference *row_reference = NULL; + if (canceled) { + g_object_unref (self); + return; + } + /* If there was any error */ row_reference = (GtkTreeRowReference *) user_data; if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) { @@ -1823,21 +1828,25 @@ view_msg_cb (ModestMailOperation *mail_op, priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self); /* Update the row reference */ - gtk_tree_row_reference_free (priv->row_reference); - priv->row_reference = gtk_tree_row_reference_copy (row_reference); - priv->next_row_reference = gtk_tree_row_reference_copy (priv->row_reference); - select_next_valid_row (priv->header_model, &(priv->next_row_reference), TRUE); - gtk_tree_row_reference_free (row_reference); + if (priv->row_reference != NULL) { + gtk_tree_row_reference_free (priv->row_reference); + priv->row_reference = gtk_tree_row_reference_copy (row_reference); + priv->next_row_reference = gtk_tree_row_reference_copy (priv->row_reference); + select_next_valid_row (priv->header_model, &(priv->next_row_reference), TRUE); + gtk_tree_row_reference_free (row_reference); + } /* Mark header as read */ if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_SEEN)) tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN); /* Set new message */ - tny_msg_view_set_msg (TNY_MSG_VIEW (priv->msg_view), msg); - modest_msg_view_window_update_priority (self); - update_window_title (MODEST_MSG_VIEW_WINDOW (self)); - modest_msg_view_grab_focus (MODEST_MSG_VIEW (priv->msg_view)); + if (priv->msg_view != NULL && TNY_IS_MSG_VIEW (priv->msg_view)) { + tny_msg_view_set_msg (TNY_MSG_VIEW (priv->msg_view), msg); + modest_msg_view_window_update_priority (self); + update_window_title (MODEST_MSG_VIEW_WINDOW (self)); + modest_msg_view_grab_focus (MODEST_MSG_VIEW (priv->msg_view)); + } /* Set the new message uid of the window */ if (priv->msg_uid) { @@ -2175,14 +2184,15 @@ on_mail_operation_started (ModestMailOperation *mail_op, priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self); op_type = modest_mail_operation_get_type_operation (mail_op); tmp = priv->progress_widgets; - - if (op_type == MODEST_MAIL_OPERATION_TYPE_RECEIVE || op_type == MODEST_MAIL_OPERATION_TYPE_OPEN ) { - set_toolbar_transfer_mode(self); - while (tmp) { - modest_progress_object_add_operation ( - MODEST_PROGRESS_OBJECT (tmp->data), - mail_op); - tmp = g_slist_next (tmp); + if (G_OBJECT (self) == modest_mail_operation_get_source(mail_op)) { + if (op_type == MODEST_MAIL_OPERATION_TYPE_RECEIVE || op_type == MODEST_MAIL_OPERATION_TYPE_OPEN ) { + set_toolbar_transfer_mode(self); + while (tmp) { + modest_progress_object_add_operation ( + MODEST_PROGRESS_OBJECT (tmp->data), + mail_op); + tmp = g_slist_next (tmp); + } } } } diff --git a/src/modest-mail-operation-queue.c b/src/modest-mail-operation-queue.c index e730712..19cb4ed 100644 --- a/src/modest-mail-operation-queue.c +++ b/src/modest-mail-operation-queue.c @@ -372,3 +372,45 @@ modest_mail_operation_queue_cancel_all (ModestMailOperationQueue *self) g_slist_free(operations_to_cancel); } + +typedef struct +{ + GSList **new_list; + GObject *source; +} FindBySourceInfo; + +static void +on_find_by_source_foreach (gpointer op, gpointer data) +{ + FindBySourceInfo *info = (FindBySourceInfo*) data; + + if ( info->source == modest_mail_operation_get_source (MODEST_MAIL_OPERATION (op))) { + *(info->new_list) = g_slist_prepend (*(info->new_list), MODEST_MAIL_OPERATION (op)); + } +} + +GSList* +modest_mail_operation_queue_get_by_source ( + ModestMailOperationQueue *self, + GObject *source) +{ + ModestMailOperationQueuePrivate *priv; + GSList* found_operations= NULL; + FindBySourceInfo *info = g_new0 (FindBySourceInfo, 1); + + g_return_val_if_fail (MODEST_IS_MAIL_OPERATION_QUEUE (self), NULL); + g_return_val_if_fail (source != NULL, NULL); + + priv = MODEST_MAIL_OPERATION_QUEUE_GET_PRIVATE(self); + + info->new_list = &found_operations; + info->source = source; + + g_mutex_lock (priv->queue_lock); + g_queue_foreach (priv->op_queue, (GFunc) on_find_by_source_foreach, info); + g_mutex_unlock (priv->queue_lock); + + g_free (info); + + return found_operations; +} diff --git a/src/modest-mail-operation-queue.h b/src/modest-mail-operation-queue.h index 7f45317..2d9d6c1 100644 --- a/src/modest-mail-operation-queue.h +++ b/src/modest-mail-operation-queue.h @@ -121,6 +121,16 @@ void modest_mail_operation_queue_cancel (ModestMailOperationQueue *op_que **/ void modest_mail_operation_queue_cancel_all (ModestMailOperationQueue *op_queue); +/** + * modest_mail_operation_queue_get_by_source: + * @op_queue: a #ModestMailOperationQueue + * @source: the source of the operations + * + * Returns a list with the #ModestMailOperation that have the given source + **/ +GSList* +modest_mail_operation_queue_get_by_source (ModestMailOperationQueue *op_queue, GObject *source); + G_END_DECLS #endif /* __MODEST_MAIL_OPERATION_QUEUE_H__ */ diff --git a/src/widgets/modest-window-mgr.c b/src/widgets/modest-window-mgr.c index 536b230..80731e7 100644 --- a/src/widgets/modest-window-mgr.c +++ b/src/widgets/modest-window-mgr.c @@ -783,6 +783,25 @@ modest_window_mgr_unregister_window (ModestWindowMgr *self, handler_id = *tmp; g_hash_table_remove (priv->destroy_handlers, window); + /* cancel open and receive operations */ + if (MODEST_IS_MSG_VIEW_WINDOW (window)) { + ModestMailOperationTypeOperation type; + GSList* pending_ops = NULL; + GSList* tmp_list = NULL; + pending_ops = modest_mail_operation_queue_get_by_source ( + modest_runtime_get_mail_operation_queue (), + G_OBJECT (window)); + while (pending_ops != NULL) { + type = modest_mail_operation_get_type_operation (MODEST_MAIL_OPERATION (pending_ops->data)); + if (type == MODEST_MAIL_OPERATION_TYPE_RECEIVE || type == MODEST_MAIL_OPERATION_TYPE_OPEN) { + modest_mail_operation_cancel (pending_ops->data); + } + tmp_list = pending_ops; + pending_ops = g_slist_next (pending_ops); + g_slist_free_1 (tmp_list); + } + } + /* Disconnect the "delete-event" handler, we won't need it anymore */ g_signal_handler_disconnect (window, handler_id);