From: Javier Fernandez Garcia-Boente Date: Mon, 3 Sep 2007 11:30:20 +0000 (+0000) Subject: * Review dimming rules to detect when modest is sedning mails. X-Git-Tag: git_migration_finished~2436 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=a7decb707f783a7de18e83f4085a42d018b018c3 * Review dimming rules to detect when modest is sedning mails. * Use the new tinymail API function to add mails to send queue asynchronously. * Fixes: NB#61607, NB#61952, NB#64146, NB#64924 pmo-trunk-r3186 --- diff --git a/src/maemo/modest-main-window-ui-dimming.h b/src/maemo/modest-main-window-ui-dimming.h index 4c4cc4f..60a338f 100644 --- a/src/maemo/modest-main-window-ui-dimming.h +++ b/src/maemo/modest-main-window-ui-dimming.h @@ -99,7 +99,7 @@ static const ModestDimmingEntry modest_main_window_menu_dimming_entries [] = { { "/HeaderViewCSM/HeaderViewCSMCopy", NULL }, { "/HeaderViewCSM/HeaderViewCSMPaste", G_CALLBACK(modest_ui_dimming_rules_on_paste) }, { "/HeaderViewCSM/HeaderViewCSMDelete", G_CALLBACK(modest_ui_dimming_rules_on_delete_msg) }, - { "/HeaderViewCSM/HeaderViewCSMCancelSending", G_CALLBACK(modest_ui_dimming_rules_on_cancel_sending) }, + { "/HeaderViewCSM/HeaderViewCSMCancelSending", G_CALLBACK(modest_ui_dimming_rules_on_csm_cancel_sending) }, { "/HeaderViewCSM/HeaderViewCSMHelp", NULL }, /* Contextual Menus (Folder View) */ diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index d589f23..6d8e4e1 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -563,7 +563,10 @@ modest_mail_operation_send_mail (ModestMailOperation *self, /* TODO: connect to the msg-sent in order to know when the mail operation is finished */ - tny_send_queue_add (send_queue, msg, &(priv->error)); +/* tny_send_queue_add (send_queue, msg, &(priv->error)); */ + modest_tny_send_queue_add (MODEST_TNY_SEND_QUEUE(send_queue), + msg, + &(priv->error)); /* TODO: we're setting always success, do the check in the handler */ diff --git a/src/modest-tny-send-queue.c b/src/modest-tny-send-queue.c index 88bf044..aa30899 100644 --- a/src/modest-tny-send-queue.c +++ b/src/modest-tny-send-queue.c @@ -174,7 +174,7 @@ modest_tny_send_queue_cancel (TnySendQueue *self, gboolean remove, GError **err) } static void -modest_tny_send_queue_add (TnySendQueue *self, TnyMsg *msg, GError **err) +_on_added_to_outbox (TnySendQueue *self, gboolean cancelled, TnyMsg *msg, GError *err, gpointer user_data) { ModestTnySendQueuePrivate *priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE(self); TnyHeader *header = NULL; @@ -185,13 +185,9 @@ modest_tny_send_queue_add (TnySendQueue *self, TnyMsg *msg, GError **err) g_return_if_fail (TNY_IS_SEND_QUEUE(self)); g_return_if_fail (TNY_IS_CAMEL_MSG(msg)); - TNY_CAMEL_SEND_QUEUE_CLASS(parent_class)->add_func (self, msg, err); /* FIXME */ - - /* TODO: We cannot access the message ID of the message here because - * it might just have been created. Wait for it being added to outbox. */ - header = tny_msg_get_header (msg); - msg_id = tny_header_get_message_id (header); + msg_id = modest_tny_send_queue_get_msg_id (header); +/* msg_id = tny_header_get_message_id (header); */ g_return_if_fail(msg_id != NULL); /* Put newly added message in WAITING state */ @@ -219,6 +215,20 @@ modest_tny_send_queue_add (TnySendQueue *self, TnyMsg *msg, GError **err) g_object_unref(G_OBJECT(header)); } +void +modest_tny_send_queue_add (ModestTnySendQueue *self, TnyMsg *msg, GError **err) +{ + g_return_if_fail (MODEST_IS_TNY_SEND_QUEUE(self)); + g_return_if_fail (TNY_IS_CAMEL_MSG(msg)); + + tny_send_queue_add_async (TNY_SEND_QUEUE(self), + msg, + _on_added_to_outbox, + NULL, + NULL); +} + + static void _add_message (ModestTnySendQueue *self, TnyHeader *header) { @@ -353,7 +363,6 @@ modest_tny_send_queue_class_init (ModestTnySendQueueClass *klass) parent_class = g_type_class_peek_parent (klass); gobject_class->finalize = modest_tny_send_queue_finalize; - TNY_CAMEL_SEND_QUEUE_CLASS(klass)->add_func = modest_tny_send_queue_add; TNY_CAMEL_SEND_QUEUE_CLASS(klass)->get_outbox_func = modest_tny_send_queue_get_outbox; TNY_CAMEL_SEND_QUEUE_CLASS(klass)->get_sentbox_func = modest_tny_send_queue_get_sentbox; TNY_CAMEL_SEND_QUEUE_CLASS(klass)->cancel_func = modest_tny_send_queue_cancel; diff --git a/src/modest-tny-send-queue.h b/src/modest-tny-send-queue.h index 5688ebe..0179940 100644 --- a/src/modest-tny-send-queue.h +++ b/src/modest-tny-send-queue.h @@ -92,6 +92,16 @@ ModestTnySendQueue* modest_tny_send_queue_new (TnyCamelTransportAccoun /** + * modest_tny_send_queue_ADD: + * @self: a valid #ModestTnySendQueue instance + * @msg: a valid #TnyMsg instance to send + * + * Add @msg to outbox folder waiting to be sent by + * its account send queue. + */ +void modest_tny_send_queue_add (ModestTnySendQueue *self, TnyMsg *msg, GError **err); + +/** * modest_tny_send_queue_try_to_send: * @self: a valid #ModestTnySendQueue instance * diff --git a/src/modest-ui-dimming-rules.c b/src/modest-ui-dimming-rules.c index c5ad4b9..552a61a 100644 --- a/src/modest-ui-dimming-rules.c +++ b/src/modest-ui-dimming-rules.c @@ -62,10 +62,11 @@ static gboolean _header_view_is_all_selected (ModestMainWindow *win); static gboolean _selected_folder_is_empty (ModestMainWindow *win); static gboolean _folder_view_has_focus (ModestWindow *win); static gboolean _selected_folder_is_same_as_source (ModestWindow *win); -static gboolean _msg_download_in_progress (ModestMsgViewWindow *win); +static gboolean _msg_download_in_progress (ModestWindow *win); static gboolean _msg_download_completed (ModestMainWindow *win); static gboolean _selected_msg_sent_in_progress (ModestWindow *win); static gboolean _sending_in_progress (ModestWindow *win); +static gboolean _send_receive_in_progress (ModestWindow *win); static gboolean _invalid_folder_for_purge (ModestWindow *win, ModestDimmingRule *rule); static gboolean _transfer_mode_enabled (ModestWindow *win); static gboolean _selected_folder_has_subfolder_with_same_name (ModestWindow *win); @@ -328,7 +329,7 @@ modest_ui_dimming_rules_on_new_msg (ModestWindow *win, gpointer user_data) /* Check dimmed rule */ if (MODEST_IS_MSG_VIEW_WINDOW(win)) { if (!dimmed) { - dimmed = _msg_download_in_progress (MODEST_MSG_VIEW_WINDOW(win)); + dimmed = _msg_download_in_progress (win); if (dimmed) modest_dimming_rule_set_notification (rule, ""); } @@ -632,7 +633,7 @@ modest_ui_dimming_rules_on_reply_msg (ModestWindow *win, gpointer user_data) modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading")); } if (!dimmed) { - dimmed = _msg_download_in_progress (MODEST_MSG_VIEW_WINDOW (win)); + dimmed = _msg_download_in_progress (win); if (dimmed) modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_reply")); } @@ -796,6 +797,12 @@ modest_ui_dimming_rules_on_details (ModestWindow *win, gpointer user_data) g_object_unref (folder_store); } + if (!dimmed) { + dimmed = _msg_download_in_progress (win); + if (dimmed) + modest_dimming_rule_set_notification (rule, ""); + } + } } @@ -806,7 +813,7 @@ modest_ui_dimming_rules_on_details (ModestWindow *win, gpointer user_data) /* Check dimmed rule */ if (!dimmed) { if (MODEST_IS_MSG_VIEW_WINDOW (win)) - dimmed = _msg_download_in_progress (MODEST_MSG_VIEW_WINDOW (win)); + dimmed = _msg_download_in_progress (win); if (dimmed) modest_dimming_rule_set_notification (rule, ""); } @@ -1406,7 +1413,6 @@ modest_ui_dimming_rules_on_cancel_sending (ModestWindow *win, gpointer user_data { ModestDimmingRule *rule = NULL; TnyFolderType types[1]; - guint n_messages = 0; const DimmedState *state = NULL; gboolean dimmed = FALSE; @@ -1419,18 +1425,42 @@ modest_ui_dimming_rules_on_cancel_sending (ModestWindow *win, gpointer user_data /* Check dimmed rules */ if (!dimmed) { - dimmed = state->already_opened_msg; - n_messages = state->n_selected; + dimmed = !_selected_folder_is_any_of_type (win, types, 1); if (dimmed) - modest_dimming_rule_set_notification (rule, _("mcen_ib_message_unableto_cancel_send")); + modest_dimming_rule_set_notification (rule, ""); + } + if (!dimmed) { + dimmed = !_sending_in_progress (win); + if (dimmed) + modest_dimming_rule_set_notification (rule, ""); } + + return dimmed; +} + +gboolean +modest_ui_dimming_rules_on_csm_cancel_sending (ModestWindow *win, gpointer user_data) +{ + ModestDimmingRule *rule = NULL; + TnyFolderType types[1]; + const DimmedState *state = NULL; + gboolean dimmed = FALSE; + + g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE); + g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE); + rule = MODEST_DIMMING_RULE (user_data); + state = modest_window_get_dimming_state (win); + + types[0] = TNY_FOLDER_TYPE_OUTBOX; + + /* Check dimmed rules */ if (!dimmed) { dimmed = !_selected_folder_is_any_of_type (win, types, 1); if (dimmed) modest_dimming_rule_set_notification (rule, ""); - } + } if (!dimmed) { - dimmed = !_sending_in_progress (win); + dimmed = !_send_receive_in_progress (win); if (dimmed) modest_dimming_rule_set_notification (rule, ""); } @@ -2130,13 +2160,18 @@ _invalid_msg_selected (ModestMainWindow *win, static gboolean -_msg_download_in_progress (ModestMsgViewWindow *win) +_msg_download_in_progress (ModestWindow *win) { gboolean result = FALSE; - g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win), FALSE); + g_return_val_if_fail (MODEST_IS_WINDOW (win), FALSE); - result = modest_msg_view_window_toolbar_on_transfer_mode (win); + if (MODEST_IS_MSG_VIEW_WINDOW (win)) { + result = modest_msg_view_window_toolbar_on_transfer_mode (MODEST_MSG_VIEW_WINDOW(win)); + } + else if (MODEST_IS_MAIN_WINDOW (win)) { + result = modest_main_window_transfer_mode_enabled (MODEST_MAIN_WINDOW(win)); + } return result; } @@ -2166,6 +2201,34 @@ _selected_msg_sent_in_progress (ModestWindow *win) static gboolean _sending_in_progress (ModestWindow *win) { + GHashTable *send_queue_cache = NULL; + ModestCacheMgr *cache_mgr = NULL; + ModestTnySendQueue *send_queue = NULL; + GSList *send_queues = NULL, *node = NULL; + gboolean result = FALSE; + + g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (win), FALSE); + + /* Get send queue */ + cache_mgr = modest_runtime_get_cache_mgr (); + send_queue_cache = modest_cache_mgr_get_cache (cache_mgr, + MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE); + + g_hash_table_foreach (send_queue_cache, (GHFunc) fill_list_of_caches, &send_queues); + + for (node = send_queues; node != NULL && !result; node = g_slist_next (node)) { + send_queue = MODEST_TNY_SEND_QUEUE (node->data); + + /* Check if send operation is in progress */ + result = modest_tny_send_queue_sending_in_progress (send_queue); + } + + return result; +} + +static gboolean +_send_receive_in_progress (ModestWindow *win) +{ gboolean result = FALSE; g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (win), FALSE); diff --git a/src/modest-ui-dimming-rules.h b/src/modest-ui-dimming-rules.h index 36888c5..ada4bbf 100644 --- a/src/modest-ui-dimming-rules.h +++ b/src/modest-ui-dimming-rules.h @@ -70,6 +70,7 @@ gboolean modest_ui_dimming_rules_on_view_previous (ModestWindow *win, gpointer u gboolean modest_ui_dimming_rules_on_view_next (ModestWindow *win, gpointer user_data); gboolean modest_ui_dimming_rules_on_tools_smtp_servers (ModestWindow *win, gpointer user_data); gboolean modest_ui_dimming_rules_on_cancel_sending (ModestWindow *win, gpointer user_data); +gboolean modest_ui_dimming_rules_on_csm_cancel_sending (ModestWindow *win, gpointer user_data); gboolean modest_ui_dimming_rules_on_send_receive (ModestWindow *win, gpointer user_data); gboolean modest_ui_dimming_rules_on_add_to_contacts (ModestWindow *win, gpointer user_data); gboolean modest_ui_dimming_rules_on_find_msg (ModestWindow *win, gpointer user_data);