From b267362311d6c82f71987833ad14ddfaedc21390 Mon Sep 17 00:00:00 2001 From: Javier Fernandez Garcia-Boente Date: Fri, 4 May 2007 09:50:15 +0000 Subject: [PATCH] * Fixes: NB#55446 * Check folder type and open DRAFT headers into edit window * Change MailOperation design to add a new relation 'source' with object which creates the operation. * Change in toolbar mode management of ModestMsgView window to attend only their own operations progress. * Fix bug on modest-tny-msg.c: unref body at incorrect place. pmo-trunk-r1757 --- src/dbus_api/modest-dbus-callbacks.c | 2 +- src/maemo/modest-main-window.c | 6 ++-- src/maemo/modest-msg-view-window.c | 53 ++++++++++++++++++++++++++++------ src/modest-mail-operation.c | 28 +++++++++++++++--- src/modest-mail-operation.h | 27 +++++++++++++++-- src/modest-main.c | 2 +- src/modest-tny-msg.c | 6 ++-- src/modest-ui-actions.c | 53 +++++++++++++++++----------------- src/widgets/modest-folder-view.c | 4 +-- src/widgets/modest-header-view.c | 5 +++- 10 files changed, 133 insertions(+), 53 deletions(-) diff --git a/src/dbus_api/modest-dbus-callbacks.c b/src/dbus_api/modest-dbus-callbacks.c index 044978b..a8e1b22 100644 --- a/src/dbus_api/modest-dbus-callbacks.c +++ b/src/dbus_api/modest-dbus-callbacks.c @@ -79,7 +79,7 @@ on_idle_send_mail(gpointer user_data) if (!from) { g_printerr ("modest: no from address for account '%s'\n", account_name); } else { - ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND); + ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND, NULL); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation); modest_mail_operation_send_new_mail (mail_operation, diff --git a/src/maemo/modest-main-window.c b/src/maemo/modest-main-window.c index 06c3d37..2799be8 100644 --- a/src/maemo/modest-main-window.c +++ b/src/maemo/modest-main-window.c @@ -1208,7 +1208,7 @@ on_queue_changed (ModestMailOperationQueue *queue, switch (type) { case MODEST_MAIL_OPERATION_QUEUE_OPERATION_ADDED: if (mode_changed) - set_toolbar_mode (MODEST_MAIN_WINDOW(self), mode); + set_toolbar_mode (self, mode); if (mode == TOOLBAR_MODE_TRANSFER) { while (tmp) { modest_progress_object_add_operation (MODEST_PROGRESS_OBJECT (tmp->data), @@ -1226,8 +1226,8 @@ on_queue_changed (ModestMailOperationQueue *queue, } /* If no more operations are being observed, NORMAL mode is enabled again */ - if (observers_empty (MODEST_MAIN_WINDOW(self))) - set_toolbar_mode (MODEST_MAIN_WINDOW(self), TOOLBAR_MODE_NORMAL); + if (observers_empty (self)) + set_toolbar_mode (self, TOOLBAR_MODE_NORMAL); } break; } diff --git a/src/maemo/modest-msg-view-window.c b/src/maemo/modest-msg-view-window.c index c09c79a..c5b46d5 100644 --- a/src/maemo/modest-msg-view-window.c +++ b/src/maemo/modest-msg-view-window.c @@ -1186,6 +1186,28 @@ cancel_progressbar (GtkToolButton *toolbutton, tmp=g_slist_next(tmp); } } +static gboolean +observers_empty (ModestMsgViewWindow *self) +{ + GSList *tmp = NULL; + ModestMsgViewWindowPrivate *priv; + gboolean is_empty = TRUE; + guint pending_ops = 0; + + priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(self); + tmp = priv->progress_widgets; + + /* Check all observers */ + while (tmp && is_empty) { + pending_ops = modest_progress_object_num_pending_operations (MODEST_PROGRESS_OBJECT(tmp->data)); + is_empty = pending_ops == 0; + + tmp = g_slist_next(tmp); + } + + return is_empty; +} + static void on_queue_changed (ModestMailOperationQueue *queue, @@ -1201,6 +1223,10 @@ on_queue_changed (ModestMailOperationQueue *queue, g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (self)); priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(self); + /* If this operations was created by another window, do nothing */ + if (!modest_mail_operation_is_mine (mail_op, G_OBJECT(self))) + return; + /* Get toolbar mode from operation id*/ op_id = modest_mail_operation_get_id (mail_op); switch (op_id) { @@ -1217,21 +1243,30 @@ on_queue_changed (ModestMailOperationQueue *queue, tmp = priv->progress_widgets; switch (type) { case MODEST_MAIL_OPERATION_QUEUE_OPERATION_ADDED: - if (mode != TOOLBAR_MODE_NORMAL) + if (mode == TOOLBAR_MODE_TRANSFER) { + while (tmp) { + modest_progress_object_add_operation (MODEST_PROGRESS_OBJECT (tmp->data), + mail_op); + tmp = g_slist_next (tmp); + } + + /* Enable transfer toolbar mode */ set_toolbar_mode (MODEST_MSG_VIEW_WINDOW(self), mode); - while (tmp) { - modest_progress_object_add_operation (MODEST_PROGRESS_OBJECT (tmp->data), - mail_op); - tmp = g_slist_next (tmp); } break; case MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED: - if (mode != TOOLBAR_MODE_NORMAL) + if (mode == TOOLBAR_MODE_TRANSFER) { set_toolbar_mode (MODEST_MSG_VIEW_WINDOW(self), TOOLBAR_MODE_NORMAL); - while (tmp) { - modest_progress_object_remove_operation (MODEST_PROGRESS_OBJECT (tmp->data), + while (tmp) { + modest_progress_object_remove_operation (MODEST_PROGRESS_OBJECT (tmp->data), mail_op); - tmp = g_slist_next (tmp); + tmp = g_slist_next (tmp); + + } + + /* If no more operations are being observed, NORMAL mode is enabled again */ + if (observers_empty (self)) + set_toolbar_mode (self, TOOLBAR_MODE_NORMAL); } break; } diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index 114cb18..88e973b 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -81,6 +81,7 @@ struct _ModestMailOperationPrivate { guint total; ModestMailOperationStatus status; ModestMailOperationId id; + GObject *source; GError *error; }; @@ -179,6 +180,7 @@ modest_mail_operation_init (ModestMailOperation *obj) priv->error = NULL; priv->done = 0; priv->total = 0; + priv->source = NULL; } static void @@ -192,27 +194,32 @@ modest_mail_operation_finalize (GObject *obj) g_error_free (priv->error); priv->error = NULL; } + if (priv->source) { + g_object_unref (priv->source); + priv->source = NULL; + } G_OBJECT_CLASS(parent_class)->finalize (obj); } ModestMailOperation* -modest_mail_operation_new (ModestMailOperationId id) +modest_mail_operation_new (ModestMailOperationId id, + GObject *source) { ModestMailOperation *obj; ModestMailOperationPrivate *priv; - - + obj = MODEST_MAIL_OPERATION(g_object_new(MODEST_TYPE_MAIL_OPERATION, NULL)); priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj); priv->id = id; + if (source != NULL) + priv->source = g_object_ref(source); return obj; } - ModestMailOperationId modest_mail_operation_get_id (ModestMailOperation *self) { @@ -223,6 +230,19 @@ modest_mail_operation_get_id (ModestMailOperation *self) return priv->id; } +gboolean +modest_mail_operation_is_mine (ModestMailOperation *self, + GObject *me) +{ + ModestMailOperationPrivate *priv; + + priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self); + if (priv->source == NULL) return FALSE; + + return priv->source == me; +} + + void modest_mail_operation_send_mail (ModestMailOperation *self, TnyTransportAccount *transport_account, diff --git a/src/modest-mail-operation.h b/src/modest-mail-operation.h index d2f1760..809e744 100644 --- a/src/modest-mail-operation.h +++ b/src/modest-mail-operation.h @@ -90,8 +90,16 @@ struct _ModestMailOperationClass { /* member functions */ GType modest_mail_operation_get_type (void) G_GNUC_CONST; -/* typical parameter-less _new function */ -ModestMailOperation* modest_mail_operation_new (ModestMailOperationId id); +/** + * modest_mail_operation_new: + * @id: a #ModestMailOperationId identification of operation type. + * @source: a #GObject which creates this new operation. + * + * Creates a new instance of class #ModestMailOperation, using parameters + * to initialize its private structure. @source parameter may be NULL. + **/ +ModestMailOperation* modest_mail_operation_new (ModestMailOperationId id, + GObject *source); /** * modest_mail_operation_get_id @@ -99,10 +107,23 @@ ModestMailOperation* modest_mail_operation_new (ModestMailOperationId id) * * Gets the private id field of mail operation. This id identifies * the class/type of mail operation. - **/ + **/ ModestMailOperationId modest_mail_operation_get_id (ModestMailOperation *self); +/** + * modest_mail_operation_get_id + * @self: a #ModestMailOperation + * @source: a #GObject to check if it have created @self operation. + * + * Check if @source object its owner of @self mail operation. + * + * returns: TRUE if source its owner, FALSE otherwise. + **/ +gboolean +modest_mail_operation_is_mine (ModestMailOperation *self, + GObject *me); + /* fill in other public functions, eg.: */ /** diff --git a/src/modest-main.c b/src/modest-main.c index fde670b..4effe5c 100644 --- a/src/modest-main.c +++ b/src/modest-main.c @@ -283,7 +283,7 @@ send_mail (const gchar* account_name, from_string = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account_name); - mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND); + mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND, NULL); modest_mail_operation_send_new_mail (mail_operation, account, from_string, mailto, cc, bcc, subject, body, NULL, diff --git a/src/modest-tny-msg.c b/src/modest-tny-msg.c index ac45472..675fce3 100644 --- a/src/modest-tny-msg.c +++ b/src/modest-tny-msg.c @@ -253,9 +253,6 @@ modest_tny_msg_get_body (TnyMsg *msg, gboolean want_html) tny_stream_reset (stream); tny_mime_part_decode_to_stream (body, stream); tny_stream_reset (stream); - - g_object_unref (G_OBJECT(stream)); - g_object_unref (G_OBJECT(body)); gtk_text_buffer_get_bounds (buf, &start, &end); to_quote = gtk_text_buffer_get_text (buf, &start, &end, FALSE); @@ -264,7 +261,10 @@ modest_tny_msg_get_body (TnyMsg *msg, gboolean want_html) g_free (to_quote); to_quote = to_quote_converted; } + g_object_unref (buf); + g_object_unref (G_OBJECT(stream)); + g_object_unref (G_OBJECT(body)); return to_quote; } diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 2e65ece..4a7aeef 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -168,7 +168,7 @@ headers_action_delete (TnyHeader *header, ModestMailOperation *mail_op; /* TODO: add confirmation dialog */ - mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_DELETE); + mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_DELETE, G_OBJECT(win)); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); @@ -502,7 +502,6 @@ reply_forward (ReplyForwardAction action, ModestWindow *win) TnyList *header_list; guint reply_forward_type; TnyHeader *header; -/* TnyFolder *folder; */ GetMsgAsyncHelper *helper; ReplyForwardHelper *rf_helper; @@ -547,16 +546,8 @@ reply_forward (ReplyForwardAction action, ModestWindow *win) reply_forward_func (msg, helper); } else { header = TNY_HEADER (tny_iterator_get_current (helper->iter)); - -/* folder = tny_header_get_folder (header); */ -/* if (folder) { */ -/* /\* The callback will call it per each header *\/ */ -/* tny_folder_get_msg_async (folder, header, get_msg_cb, NULL, helper); */ -/* g_object_unref (G_OBJECT (folder)); */ -/* } else */ -/* g_printerr ("modest: no folder for header\n"); */ - helper->mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE); + helper->mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win)); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), helper->mail_op); modest_mail_operation_process_msg (helper->mail_op, header, helper->num_ops, get_msg_cb, helper); @@ -686,7 +677,8 @@ action_send (const gchar* account_name) static gboolean -action_receive (const gchar* account_name) +action_receive (const gchar* account_name, + ModestWindow *win) { TnyAccount *tny_account; ModestMailOperation *mail_op; @@ -704,7 +696,7 @@ action_receive (const gchar* account_name) /* Create the mail operation */ /* TODO: The spec wants us to first do any pending deletions, before receiving. */ - mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE); + mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win)); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); modest_mail_operation_update_account (mail_op, TNY_STORE_ACCOUNT(tny_account)); @@ -763,7 +755,7 @@ do_send_receive_current_or_default (ModestWindow *win) * for SMTP we should send, * first receiving, then sending: */ - if (!action_receive(account_name)) + if (!action_receive(account_name, win)) g_printerr ("modest: failed to receive\n"); if (!action_send(account_name)) g_printerr ("modest: failed to send\n"); @@ -794,7 +786,7 @@ do_send_receive_auto (ModestWindow *win) * for SMTP we should send, * first receiving, then sending: */ - if (!action_receive(account_name)) + if (!action_receive(account_name, win)) g_printerr ("modest: failed to receive for account %s\n", account_name); if (!action_send(account_name)) g_printerr ("modest: failed to send for account %s\n", account_name); @@ -908,6 +900,7 @@ get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err, gpointer user_data) headers = tny_iterator_get_list (helper->iter); g_object_unref (G_OBJECT (headers)); g_object_unref (G_OBJECT (helper->iter)); + g_object_unref (G_OBJECT (helper->mail_op)); if (rf_helper != NULL) { g_free (rf_helper->account_name); g_slice_free (ReplyForwardHelper, rf_helper); @@ -916,8 +909,6 @@ get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err, gpointer user_data) } else { TnyHeader *header; header = TNY_HEADER (tny_iterator_get_current (helper->iter)); -/* tny_folder_get_msg_async (folder, header, */ -/* get_msg_cb, NULL, helper); */ modest_mail_operation_process_msg (helper->mail_op, header, helper->num_ops, get_msg_cb, helper); g_object_unref (G_OBJECT(header)); @@ -954,6 +945,7 @@ modest_ui_actions_on_header_activated (ModestHeaderView *header_view, TnyHeader ModestWindow *win = NULL; TnyFolder *folder = NULL; TnyMsg *msg = NULL; + TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN; ModestWindowMgr *mgr; GtkTreeModel *model; GtkTreeIter iter; @@ -970,6 +962,8 @@ modest_ui_actions_on_header_activated (ModestHeaderView *header_view, TnyHeader g_printerr ("modest: cannot get folder for header\n"); return; } + if (modest_tny_folder_is_local_folder (folder)) + folder_type = modest_tny_folder_get_local_folder_type (folder); /* FIXME: make async?; check error */ msg = tny_folder_get_msg (folder, header, NULL); @@ -995,7 +989,14 @@ modest_ui_actions_on_header_activated (ModestHeaderView *header_view, TnyHeader if (sel_list != NULL) { gtk_tree_model_get_iter (model, &iter, (GtkTreePath *) sel_list->data); - win = modest_msg_view_window_new_with_header_model (msg, account, model, iter); + switch (folder_type) { + case TNY_FOLDER_TYPE_DRAFTS: + win = modest_msg_edit_window_new (msg, account); + break; + default: + win = modest_msg_view_window_new_with_header_model (msg, account, model, iter); + } + g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL); g_list_free (sel_list); } else { @@ -1175,7 +1176,7 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi from = modest_account_mgr_get_from_string (account_mgr, account_name); /* Create the mail operation */ - mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO); + mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(edit_window)); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation); modest_mail_operation_save_to_drafts (mail_operation, @@ -1241,7 +1242,7 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window) from = modest_account_mgr_get_from_string (account_mgr, account_name); /* Create the mail operation */ - mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND); + mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND, G_OBJECT(edit_window)); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation); modest_mail_operation_send_new_mail (mail_operation, @@ -1462,7 +1463,7 @@ modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_windo if (result == GTK_RESPONSE_REJECT) { finished = TRUE; } else { - ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO); + ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(main_window)); TnyFolder *new_folder = NULL; modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), @@ -1516,7 +1517,7 @@ modest_ui_actions_on_rename_folder (GtkAction *action, if (folder_name != NULL && strlen (folder_name) > 0) { ModestMailOperation *mail_op; - mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO); + mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(main_window)); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); @@ -1556,7 +1557,7 @@ delete_folder (ModestMainWindow *main_window, gboolean move_to_trash) g_free (message); if (response == GTK_RESPONSE_OK) { - ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_DELETE); + ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_DELETE, G_OBJECT(main_window)); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); @@ -2168,7 +2169,7 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action, src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)); if (TNY_IS_FOLDER (src_folder)) { - mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE); + mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win)); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); @@ -2198,7 +2199,7 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action, /* Transfer messages */ if (response == GTK_RESPONSE_OK) { - mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE); + mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win)); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); @@ -2265,7 +2266,7 @@ modest_ui_actions_on_msg_view_window_move_to (GtkAction *action, ModestMailOperation *mail_op; /* Create mail op */ - mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE); + mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win)); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); diff --git a/src/widgets/modest-folder-view.c b/src/widgets/modest-folder-view.c index ffe17cc..ba979f6 100644 --- a/src/widgets/modest-folder-view.c +++ b/src/widgets/modest-folder-view.c @@ -991,7 +991,7 @@ drag_and_drop_from_header_view (GtkTreeModel *source_model, &folder, -1); /* Transfer message */ - mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE); + mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, NULL); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); @@ -1051,7 +1051,7 @@ drag_and_drop_from_folder_view (GtkTreeModel *source_model, &folder, -1); /* Do the mail operation */ - mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE); + mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, NULL); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); g_signal_connect (G_OBJECT (mail_op), "progress-changed", diff --git a/src/widgets/modest-header-view.c b/src/widgets/modest-header-view.c index ca87c24..cb9b1e9 100644 --- a/src/widgets/modest-header-view.c +++ b/src/widgets/modest-header-view.c @@ -856,8 +856,11 @@ void modest_header_view_set_folder (ModestHeaderView *self, TnyFolder *folder) { ModestHeaderViewPrivate *priv; + ModestWindow *win = NULL; priv = MODEST_HEADER_VIEW_GET_PRIVATE(self); + win = MODEST_WINDOW(gtk_widget_get_toplevel (GTK_WIDGET(self))); + g_return_if_fail (MODEST_IS_WINDOW (win)); if (priv->folder) { g_object_unref (priv->folder); @@ -877,7 +880,7 @@ modest_header_view_set_folder (ModestHeaderView *self, TnyFolder *folder) g_signal_emit (G_OBJECT(self), signals[HEADER_SELECTED_SIGNAL], 0, NULL); /* Create the mail operation */ - mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE); + mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win)); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); -- 1.7.9.5