* some bugs fixed
authorArne Zellentin <arne@kernelconcepts.de>
Tue, 13 Jun 2006 17:20:32 +0000 (17:20 +0000)
committerArne Zellentin <arne@kernelconcepts.de>
Tue, 13 Jun 2006 17:20:32 +0000 (17:20 +0000)
* forwarding now forwards the attachments as well

* new menu->message->forward attached item in main window, will work on the implementation of that tomorrow

pmo-trunk-r266

src/gtk-glade/modest-ui-main-view.c
src/gtk-glade/modest-ui-message-editor.c
src/gtk-glade/modest-ui-message-editor.h
src/modest-editor-window.c
src/modest-editor-window.h
src/modest-tny-attachment.c
src/modest-tny-attachment.h
src/modest-tny-transport-actions.c

index 8aeae4b..80d883c 100644 (file)
@@ -61,6 +61,8 @@ static void on_view_attachments_toggled(GtkWidget *widget, gpointer user_data);
 
 static void on_sendreceive_button_clicked (GtkWidget *widget, gpointer user_data);
 
+static void on_forward_attached_activated (GtkWidget *widget, gpointer user_data);
+
 static void register_toolbar_callbacks (ModestUI *modest_ui);
 
 
@@ -90,6 +92,7 @@ modest_ui_show_main_window (ModestUI *modest_ui)
        GtkWidget     *folder_view, *header_view;
        GtkWidget     *message_view;
        GtkWidget     *account_settings_item;
+       GtkWidget     *forward_attached_menu_item;
        GtkWidget     *delete_item;
        GtkWidget     *open_item;
        GtkWidget     *view_attachments_item;
@@ -196,6 +199,14 @@ modest_ui_show_main_window (ModestUI *modest_ui)
                return FALSE;
        }
 
+       forward_attached_menu_item = glade_xml_get_widget (priv->glade_xml, "forward_attached");
+       if (!forward_attached_menu_item) {
+               g_warning ("The forward_attached_menu_item isn't available!");
+               return FALSE;
+       }
+       g_signal_connect (forward_attached_menu_item, "activate", G_CALLBACK(on_forward_attached_activated),
+                         modest_ui);
+
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(view_attachments_item),
                                        modest_conf_get_bool(priv->modest_conf,
                                        MODEST_CONF_MSG_VIEW_SHOW_ATTACHMENTS_INLINE,
@@ -544,3 +555,10 @@ on_sendreceive_button_clicked (GtkWidget *widget, gpointer user_data)
        }
        // g_object_unref (store_actions);
 }
+static void
+on_forward_attached_activated (GtkWidget *widget, gpointer user_data)
+{
+       ModestUI *modest_ui = (ModestUI *)user_data;
+
+       quoted_send_msg (modest_ui, QUOTED_SEND_FORWARD_ATTACHED);
+}
index c8b5173..ce4734d 100644 (file)
@@ -257,7 +257,8 @@ void on_editor_buffer_changed (GtkTextBuffer *textbuffer,
 static void
 new_editor_with_presets (ModestUI *modest_ui, const gchar *to_header,
                                                        const gchar *cc_header, const gchar *bcc_header,
-                                                       const gchar *subject_header, const gchar *body)
+                                                       const gchar *subject_header, const gchar *body,
+                            const GList *attachments)
 {
        GtkWidget *edit_win;
        GladeXML *glade_xml;
@@ -315,6 +316,7 @@ new_editor_with_presets (ModestUI *modest_ui, const gchar *to_header,
        modest_editor_window_set_bcc_header(MODEST_EDITOR_WINDOW(edit_win), bcc_header);
        modest_editor_window_set_subject_header(MODEST_EDITOR_WINDOW(edit_win), subject_header);
        modest_editor_window_set_body(MODEST_EDITOR_WINDOW(edit_win), body);
+       modest_editor_window_set_attachments(MODEST_EDITOR_WINDOW(edit_win), attachments);
 
        modest_editor_window_set_modified(MODEST_EDITOR_WINDOW(edit_win), FALSE);
 
@@ -327,7 +329,7 @@ on_new_mail_clicked (GtkWidget *widget, gpointer user_data)
 {
        ModestUI *modest_ui = (ModestUI *) modest_ui;
 
-       new_editor_with_presets(modest_ui, "", "", "", "", "");
+       new_editor_with_presets(modest_ui, "", "", "", "", "", NULL);
 }
 
 
@@ -353,6 +355,8 @@ quoted_send_msg (ModestUI *modest_ui, quoted_send_type qstype)
        gchar *unquoted, *quoted;
        time_t sent_date;
        gint line_limit = 76;
+       
+       GList *attachments = NULL;
 
        g_return_if_fail (modest_ui);
 
@@ -411,11 +415,17 @@ quoted_send_msg (ModestUI *modest_ui, quoted_send_type qstype)
        switch (qstype) {
                case QUOTED_SEND_REPLY:
                        g_string_prepend(re_sub, _("Re: "));
-                       new_editor_with_presets(modest_ui, from, /* cc */ "", /* bcc */ "", re_sub->str, quoted);
+                       new_editor_with_presets(modest_ui, from, /* cc */ "", /* bcc */ "", re_sub->str, quoted, attachments);
                        break;
                case QUOTED_SEND_FORWARD:
+                       attachments = modest_tny_attachment_new_list_from_msg(msg, FALSE);
+                       g_string_prepend(re_sub, _("Fwd: "));
+                       new_editor_with_presets(modest_ui, /* from */ "", /* cc */ "", /* bcc */ "", re_sub->str, quoted, attachments);
+                       break;
+               case QUOTED_SEND_FORWARD_ATTACHED:
+                       attachments = modest_tny_attachment_new_list_from_msg(msg, TRUE);
                        g_string_prepend(re_sub, _("Fwd: "));
-                       new_editor_with_presets(modest_ui, /* from */ "", /* cc */ "", /* bcc */ "", re_sub->str, quoted);
+                       new_editor_with_presets(modest_ui, /* from */ "", /* cc */ "", /* bcc */ "", re_sub->str, "", attachments);
                        break;
                default:
                        break;
@@ -518,10 +528,6 @@ on_send_button_clicked (GtkWidget *widget, ModestEditorWindow *modest_editwin)
                                                             MODEST_IDENTITY_DEFAULT_IDENTITY,
                                                             MODEST_IDENTITY_EMAIL, NULL);
        attachments = modest_editor_window_get_attachments(modest_editwin);
-       /* while (attachments) {
-               printf("att: %s\n", (gchar *) attachments->data);
-               attachments = attachments->next;
-       } */
        if (!email_from)
                email_from = "";
        
@@ -534,6 +540,7 @@ on_send_button_clicked (GtkWidget *widget, ModestEditorWindow *modest_editwin)
                                                   body,
                                                   attachments);
 
+       modest_tny_attachment_free_list(attachments);
        g_free (body);
        g_object_unref (G_OBJECT(actions));
 
index de859b8..39ca412 100644 (file)
@@ -4,7 +4,8 @@
 typedef enum {
        QUOTED_SEND_REPLY,
        QUOTED_SEND_REPLY_ALL,
-       QUOTED_SEND_FORWARD
+       QUOTED_SEND_FORWARD,
+       QUOTED_SEND_FORWARD_ATTACHED
 } quoted_send_type;
 
 /**
index b232c88..c0809c1 100644 (file)
@@ -248,15 +248,19 @@ gboolean modest_editor_window_attach_file(ModestEditorWindow *edit_win, ModestTn
        return modest_ui_editor_window_update_attachments(priv->user_data);
 }
 
-GList * modest_editor_window_set_attachments(ModestEditorWindow *edit_win, GList* attachments)
+GList * modest_editor_window_set_attachments(ModestEditorWindow *edit_win, const GList* attachments)
 {
        ModestEditorWindowPrivate *priv;
+       GList *pos;
 
        g_return_val_if_fail(edit_win, NULL);
        
        priv = MODEST_EDITOR_WINDOW_GET_PRIVATE(edit_win);
 
-       priv->attachments = attachments;
+       modest_tny_attachment_free_list(priv->attachments);
+       priv->attachments = g_list_copy((GList *)attachments);
+       for (pos = priv->attachments ; pos ; pos = pos->next )
+               g_object_ref(pos->data);
        return priv->attachments;
 }
 
index a2cad64..9ec902b 100644 (file)
@@ -159,11 +159,11 @@ gboolean modest_editor_window_attach_file(ModestEditorWindow *edit_win, ModestTn
  * @edit_win: a ModestEditorWindow instance
  * @attachments: a list of attachments
  *
- * Sets the list of attachments to *attachments
+ * Frees the current attachments, then sets the list of attachments to *attachments
  *
  * Returns: The new GList* of attachments.
  */
-GList * modest_editor_window_set_attachments(ModestEditorWindow *edit_win, GList* attachments);
+GList * modest_editor_window_set_attachments(ModestEditorWindow *edit_win, const GList* attachments);
 
 /**
  * modest_editor_window_get_attachments:
index 33e1b10..4759121 100644 (file)
@@ -3,9 +3,8 @@
 /* insert (c)/licensing information) */
 
 #include "modest-tny-attachment.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
+#include "modest-tny-msg-actions.h"
+
 #include <tny-stream-camel.h>
 #include <tny-fs-stream.h>
 #include <camel/camel.h>
@@ -108,7 +107,8 @@ modest_tny_attachment_finalize (GObject *obj)
        g_free(priv->mime_type);
        g_free(priv->disposition);
        g_free(priv->content_id);
-       g_object_unref(G_OBJECT(priv->stream));
+       if (priv->stream)
+               g_object_unref(G_OBJECT(priv->stream));
 }
 
 ModestTnyAttachment *
@@ -134,6 +134,9 @@ modest_tny_attachment_get_name (ModestTnyAttachment *self)
        ModestTnyAttachmentPrivate *priv;
        
        priv = MODEST_TNY_ATTACHMENT_GET_PRIVATE(self);
+       if (!priv->name)
+               if (priv->filename)
+                       priv->name = g_path_get_basename(priv->filename);
        return priv->name;
 }
 
@@ -198,7 +201,7 @@ modest_tny_attachment_guess_mime_type (ModestTnyAttachment *self)
        
        g_free(priv->mime_type);
        if (suffixes[pos])
-               priv->mime_type = types[pos];
+               priv->mime_type = g_strdup(types[pos]);
        else
                priv->mime_type = NULL;
 }
@@ -215,6 +218,17 @@ make_stream_from_file(const gchar * filename)
        return TNY_STREAM_IFACE(tny_stream_camel_new(camel_stream_fs_new_with_fd(file)));
 }
 
+void
+modest_tny_attachment_set_stream(ModestTnyAttachment *self, TnyStreamIface *thing)
+{
+       ModestTnyAttachmentPrivate *priv;
+       
+       priv = MODEST_TNY_ATTACHMENT_GET_PRIVATE(self);
+       if (priv->stream)
+               g_object_unref(G_OBJECT(priv->stream));
+       priv->stream = thing;
+}
+
 TnyStreamIface *
 modest_tny_attachment_get_stream (ModestTnyAttachment *self)
 {
@@ -226,3 +240,68 @@ modest_tny_attachment_get_stream (ModestTnyAttachment *self)
                        priv->stream = make_stream_from_file(priv->filename);
        return priv->stream;
 }
+
+
+void
+modest_tny_attachment_free_list(GList *list)
+{
+       GList *pos;
+       
+       for (pos = list; pos; pos = pos->next)
+               if (pos->data)
+                       g_object_unref(pos->data);
+       g_list_free(list);
+       return;
+}
+
+
+ModestTnyAttachment *
+modest_tny_attachment_new_from_mime_part(TnyMsgMimePartIface *part)
+{
+       TnyStreamIface *mem_stream;
+       ModestTnyAttachment *self;
+       
+       mem_stream = TNY_STREAM_IFACE(tny_stream_camel_new(camel_stream_mem_new()));
+       self = modest_tny_attachment_new();
+       tny_msg_mime_part_iface_decode_to_stream(part, mem_stream);
+       tny_stream_iface_reset(mem_stream);
+       modest_tny_attachment_set_stream(self, mem_stream);
+       modest_tny_attachment_set_mime_type(self,
+                                           tny_msg_mime_part_iface_get_content_type(part));
+       modest_tny_attachment_set_name(self,
+                                           tny_msg_mime_part_iface_get_filename(part));
+       return self;
+}
+
+
+GList *
+modest_tny_attachment_new_list_from_msg(const TnyMsgIface *msg, gboolean with_body)
+{
+       GList *list = NULL;
+       const GList *attachments;
+       TnyMsgMimePartIface *part;
+       ModestTnyAttachment *att;
+       
+       if (with_body) {
+               /* TODO: make plain over html configurable */
+               part = modest_tny_msg_actions_find_body_part ((TnyMsgIface *)msg, "text/plain");
+               if (!part) 
+                       part = modest_tny_msg_actions_find_body_part ((TnyMsgIface *)msg, "text/html");
+               if (part) {
+                       att = modest_tny_attachment_new_from_mime_part(part);
+                       /* TODO: i18n */
+                       modest_tny_attachment_set_name(att, "original message");
+                       list = g_list_append(list, att);
+               }
+       }
+       attachments = tny_msg_iface_get_parts((TnyMsgIface *)msg);
+       while (attachments) {
+               part = attachments->data;
+               if (tny_msg_mime_part_iface_is_attachment(part)) {
+                       att = modest_tny_attachment_new_from_mime_part(part);
+                       list = g_list_append(list, att);
+               }
+               attachments = attachments->next;
+       }
+       return list;
+}
index 3855f66..1224165 100644 (file)
@@ -6,6 +6,8 @@
 
 #include <glib-object.h>
 #include <tny-stream-iface.h>
+#include <tny-msg-iface.h>
+#include <tny-msg-mime-part-iface.h>
 /* other include files */
 
 G_BEGIN_DECLS
@@ -57,6 +59,10 @@ void modest_tny_attachment_guess_mime_type (ModestTnyAttachment *self);
 
 TnyStreamIface * modest_tny_attachment_get_stream (ModestTnyAttachment *self);
 
+void modest_tny_attachment_free_list(GList *list);
+
+GList *modest_tny_attachment_new_list_from_msg(const TnyMsgIface *msg, gboolean with_body);
+
 G_END_DECLS
 
 #endif /* __MODEST_TNY_ATTACHMENT_H__ */
index eee55b3..ed9b27e 100644 (file)
@@ -164,7 +164,7 @@ modest_tny_transport_actions_send_message (ModestTnyTransportActions *self,
        GList *pos;
        gchar *content_type;
        const gchar *attachment_content_type;
-       gchar *attachment_filename;
+       const gchar *attachment_filename;
        
        new_msg          = TNY_MSG_IFACE(tny_msg_new ());
        headers          = TNY_MSG_HEADER_IFACE(tny_msg_header_new ());
@@ -200,16 +200,16 @@ modest_tny_transport_actions_send_message (ModestTnyTransportActions *self,
        }
        
        for (    pos = (GList *)attachments_list;
-                    pos;
+                pos;
                 pos = pos->next    ) {
                attachment = pos->data;
-               attachment_filename = g_path_get_basename(
-                                                         modest_tny_attachment_get_filename(attachment));
+               attachment_filename = modest_tny_attachment_get_name(attachment);
                attachment_stream = modest_tny_attachment_get_stream(attachment);
                attachment_part = TNY_MSG_MIME_PART_IFACE (tny_msg_mime_part_new (
                                                                camel_mime_part_new()));
                
                attachment_content_type = modest_tny_attachment_get_mime_type(attachment);
+                                
                tny_msg_mime_part_iface_construct_from_stream (attachment_part,
                                                               attachment_stream,
                                                               attachment_content_type);
@@ -218,9 +218,7 @@ modest_tny_transport_actions_send_message (ModestTnyTransportActions *self,
                tny_msg_mime_part_iface_set_filename(attachment_part, attachment_filename);
                
                tny_msg_iface_add_part (new_msg, attachment_part);
-               g_object_unref(G_OBJECT(attachment_stream));
                //g_object_unref(G_OBJECT(attachment_part));
-               g_free(attachment_filename);
                //close(file);
        }