From 396450773800287cd1a6353be9c837ffabdd98b6 Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Wed, 20 Dec 2006 18:52:22 +0000 Subject: [PATCH] * Modified the API of the message window * Replaced the old _new method by a new one * Added some error support to the ModestMailOperation pmo-trunk-r572 --- src/gtk/modest-edit-msg-window.c | 86 +++++++++++++++++++++++--------------- src/gtk/modest-edit-msg-window.h | 11 ++++- src/gtk/modest-main-window.c | 8 ++-- src/modest-mail-operation.c | 8 +++- 4 files changed, 73 insertions(+), 40 deletions(-) diff --git a/src/gtk/modest-edit-msg-window.c b/src/gtk/modest-edit-msg-window.c index 3316f8e..acc3095 100644 --- a/src/gtk/modest-edit-msg-window.c +++ b/src/gtk/modest-edit-msg-window.c @@ -266,10 +266,9 @@ send_mail (ModestEditMsgWindow *self) body = gtk_text_buffer_get_text (buf, &b, &e, FALSE); /* free this one */ - /* FIXME: Code added just for testing. The transport_account - should be provided by the account manager, maybe using - _get_current_account () or _get_default_account - (TRANSPORT_ACCOUNT). These methods do not exist currently. */ + /* FIXME: Code added just for testing. The final version will + use the send queue provided by tinymail and some + classifier */ { TnyList *accounts; TnyIterator *iter; @@ -289,6 +288,11 @@ send_mail (ModestEditMsgWindow *self) return; } transport_account = TNY_TRANSPORT_ACCOUNT (tny_iterator_get_current(iter)); + g_object_ref (transport_account); + + tny_list_foreach (accounts, (GFunc) g_object_unref, NULL); + g_object_unref (G_OBJECT (accounts)); + g_object_unref (G_OBJECT (iter)); } mail_operation = modest_mail_operation_new (); @@ -298,7 +302,8 @@ send_mail (ModestEditMsgWindow *self) from, to, cc, bcc, subject, body, NULL); /* Clean up */ - g_object_unref (mail_operation); + g_object_unref (G_OBJECT (mail_operation)); + g_object_unref (G_OBJECT (transport_account)); g_free (from); g_free (body); } @@ -439,15 +444,14 @@ on_delete_event (GtkWidget *widget, GdkEvent *event, ModestEditMsgWindow *self) GtkWidget* modest_edit_msg_window_new (ModestWidgetFactory *factory, - ModestEditType type, TnyMsg *msg) + ModestEditType type) { GObject *obj; ModestEditMsgWindowPrivate *priv; g_return_val_if_fail (factory, NULL); g_return_val_if_fail (type < MODEST_EDIT_TYPE_NUM, NULL); - g_return_val_if_fail (!(type==MODEST_EDIT_TYPE_NEW && msg), NULL); - g_return_val_if_fail (!(type!=MODEST_EDIT_TYPE_NEW && !msg), NULL); +/* g_return_val_if_fail (!(type!=MODEST_EDIT_TYPE_NEW && !msg), NULL); */ obj = g_object_new(MODEST_TYPE_EDIT_MSG_WINDOW, NULL); priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE(obj); @@ -465,32 +469,46 @@ modest_edit_msg_window_new (ModestWidgetFactory *factory, g_signal_connect (G_OBJECT(obj), "delete-event", G_CALLBACK(on_delete_event), obj); - - if (msg) { - /* Testing code. Should be into a set_msg method */ - TnyHeader *header; - GtkTextBuffer *buf; - - header = tny_msg_get_header (msg); - gtk_entry_set_text (GTK_ENTRY(priv->to_field), - tny_header_get_to (header)); - gtk_entry_set_text (GTK_ENTRY(priv->cc_field), - tny_header_get_cc (header)); - gtk_entry_set_text (GTK_ENTRY(priv->bcc_field), - tny_header_get_bcc (header)); - gtk_entry_set_text (GTK_ENTRY(priv->subject_field), - tny_header_get_subject (header)); - - buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW(priv->msg_body)); - gtk_text_buffer_set_text (buf, - (const gchar *) modest_tny_msg_actions_find_body (msg, TRUE), - -1); - - /* TODO: lower priority, select in the From: combo to - the value that comes from msg */ - - /* TODO: set attachments */ - } return GTK_WIDGET (obj); } + +void +modest_edit_msg_window_set_msg (ModestEditMsgWindow *self, TnyMsg *msg) +{ + TnyHeader *header; + GtkTextBuffer *buf; + const gchar *to, *cc, *bcc, *subject; + ModestEditMsgWindowPrivate *priv; + + g_return_if_fail (MODEST_IS_EDIT_MSG_WINDOW (self)); + g_return_if_fail (TNY_IS_MSG (msg)); + + priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE (self); + + header = tny_msg_get_header (msg); + to = tny_header_get_to (header); + cc = tny_header_get_cc (header); + bcc = tny_header_get_bcc (header); + subject = tny_header_get_subject (header); + + if (to) + gtk_entry_set_text (GTK_ENTRY(priv->to_field), to); + if (cc) + gtk_entry_set_text (GTK_ENTRY(priv->cc_field), cc); + if (bcc) + gtk_entry_set_text (GTK_ENTRY(priv->bcc_field), bcc); + if (subject) + gtk_entry_set_text (GTK_ENTRY(priv->subject_field), subject); + + buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW(priv->msg_body)); + gtk_text_buffer_set_text (buf, + (const gchar *) modest_tny_msg_actions_find_body (msg, TRUE), + -1); + + /* TODO: lower priority, select in the From: combo to the + value that comes from msg <- not sure, should it be + allowed? */ + + /* TODO: set attachments */ +} diff --git a/src/gtk/modest-edit-msg-window.h b/src/gtk/modest-edit-msg-window.h index 1aa27c2..63cf77e 100644 --- a/src/gtk/modest-edit-msg-window.h +++ b/src/gtk/modest-edit-msg-window.h @@ -75,7 +75,16 @@ typedef enum _ModestEditType { GType modest_edit_msg_window_get_type (void) G_GNUC_CONST; GtkWidget* modest_edit_msg_window_new (ModestWidgetFactory *factory, - ModestEditType type, + ModestEditType type); + +/** + * modest_edit_msg_window_set_msg: + * @self: a #ModestEditMsgWindow + * @msg: a #TnyMsg + * + * shows the message @msg in a #ModestEditMsgWindow + **/ +void modest_edit_msg_window_set_msg (ModestEditMsgWindow *self, TnyMsg *msg); G_END_DECLS diff --git a/src/gtk/modest-main-window.c b/src/gtk/modest-main-window.c index 164286f..3d6d8b1 100644 --- a/src/gtk/modest-main-window.c +++ b/src/gtk/modest-main-window.c @@ -223,8 +223,7 @@ on_menu_new_message (ModestMainWindow *self, guint action, GtkWidget *widget) priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self); msg_win = modest_edit_msg_window_new (priv->widget_factory, - MODEST_EDIT_TYPE_NEW, - NULL); + MODEST_EDIT_TYPE_NEW); gtk_widget_show (msg_win); } @@ -273,8 +272,9 @@ get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err, gpointer user_data) /* Show edit window */ msg_win = modest_edit_msg_window_new (priv->widget_factory, - edit_type, - new_msg); + edit_type); + modest_edit_msg_window_set_msg (MODEST_EDIT_MSG_WINDOW (msg_win), + new_msg); gtk_widget_show (msg_win); /* Clean and go on */ diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index a0ce714..89a58e4 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -484,7 +484,7 @@ folder_refresh_cb (TnyFolder *folder, gboolean canceled, GError **err, gpointer g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR, MODEST_MAIL_OPERATION_ERROR_OPERATION_CANCELED, _("Error trying to refresh folder %s. Operation canceled"), - tny_folder_get_name (folder)); + tny_folder_get_name (folder)); } else { priv->done++; } @@ -527,6 +527,12 @@ update_folders_cb (TnyFolderStore *self, TnyList *list, GError **err, gpointer u mail_op = MODEST_MAIL_OPERATION (user_data); priv = MODEST_MAIL_OPERATION_GET_PRIVATE (mail_op); + if (*err) { + priv->error = g_error_copy (*err); + priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED; + return; + } + priv->total = tny_list_get_length (list); priv->done = 0; priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS; -- 1.7.9.5