* src/widgets/modest-msg-view.[ch]:
authorJose Dapena Paz <jdapena@igalia.com>
Fri, 22 Jun 2007 15:11:11 +0000 (15:11 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Fri, 22 Jun 2007 15:11:11 +0000 (15:11 +0000)
        * Remove an attachment mime part from view.
* src/widgets/modest-msg-view-window.[ch]:
        * Implemented dialog for removing attachments, but dropped
          any remove attachment implementation until we know how to
          remove attachments only from cache.

pmo-trunk-r2379

src/maemo/modest-main-window-ui.h
src/maemo/modest-msg-view-window.c
src/modest-ui-actions.c
src/widgets/modest-msg-view-window.h
src/widgets/modest-msg-view.c
src/widgets/modest-msg-view.h

index 22f1865..a00a8a3 100644 (file)
@@ -89,7 +89,7 @@ static const GtkActionEntry modest_action_entries [] = {
        /* Attachments */
        { "ViewAttachment", NULL, N_("mcen_me_viewer_view_attachment"), NULL, NULL, G_CALLBACK (modest_ui_actions_view_attachment) },
        { "SaveAttachment", NULL, N_("mcen_me_viewer_save_attachments"), NULL, NULL, G_CALLBACK (modest_ui_actions_save_attachments) },
-       { "RemoveAttachment", NULL, N_("mcen_me_viewer_remove_attachments"), NULL, NULL, G_CALLBACK (modest_ui_actions_remove_attachments) },
+       { "RemoveAttachment", NULL, N_("mcen_me_inbox_remove_attachments"), NULL, NULL, G_CALLBACK (modest_ui_actions_remove_attachments) },
        
        /* Tools */
        { "ToolsSettings",        NULL,      N_("mcen_me_inbox_options"),                     NULL, NULL, G_CALLBACK (modest_ui_actions_on_settings) },
index 4346050..85f2822 100644 (file)
@@ -1735,9 +1735,53 @@ modest_msg_view_window_save_attachments (ModestMsgViewWindow *window, GList *mim
 }
 
 void
-modest_msg_view_window_remove_attachments (ModestMsgViewWindow *window, GList *mime_parts)
+modest_msg_view_window_remove_attachments (ModestMsgViewWindow *window)
 {
-/*     g_message ("not implemented %s", __FUNCTION__); */
+       ModestMsgViewWindowPrivate *priv;
+       GList *mime_parts = NULL, *node;
+       gchar *confirmation_message;
+       gint response;
+       gint n_attachments;
+
+       g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window));
+       priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (window);
+
+       mime_parts = modest_msg_view_get_selected_attachments (MODEST_MSG_VIEW (priv->msg_view));
+       if (mime_parts == NULL)
+               return;
+
+       n_attachments = g_list_length (mime_parts);
+       if (n_attachments == 1) {
+               const gchar *filename;
+
+               if (TNY_IS_MSG (mime_parts->data)) {
+                       TnyHeader *header;
+                       header = tny_msg_get_header (TNY_MSG (mime_parts->data));
+                       filename = tny_header_get_subject (header);
+                       g_object_unref (header);
+                       if (filename == NULL)
+                               filename = _("mail_va_no_subject");
+               } else {
+                       filename = tny_mime_part_get_filename (TNY_MIME_PART (mime_parts->data));
+               }
+               confirmation_message = g_strdup_printf (_("mcen_nc_purge_file_text"), filename);
+       } else {
+               confirmation_message = g_strdup_printf (ngettext("mcen_nc_purge_file_text", 
+                                                                "mcen_nc_purge_files_text", 
+                                                                n_attachments), n_attachments);
+       }
+       response = modest_platform_run_confirmation_dialog (GTK_WINDOW (window),
+                                                           confirmation_message);
+       g_free (confirmation_message);
+
+       if (response != GTK_RESPONSE_OK)
+               return;
+
+       for (node = mime_parts; node != NULL; node = g_list_next (node)) {
+               modest_msg_view_remove_attachment (MODEST_MSG_VIEW (priv->msg_view), node->data);
+       }
+       g_list_foreach (mime_parts, (GFunc) g_object_unref, NULL);
+       g_list_free (mime_parts);
 }
 
 
index fb93013..ee23878 100644 (file)
@@ -3046,7 +3046,7 @@ modest_ui_actions_remove_attachments (GtkAction *action,
                                      ModestWindow *window)
 {
        if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
-               modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
+               modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window));
        } else {
                /* not supported window for this action */
                g_return_if_reached ();
index 5d9ee6c..de89996 100644 (file)
@@ -209,13 +209,10 @@ void            modest_msg_view_window_save_attachments (ModestMsgViewWindow *wi
 /**
  * modest_msg_view_window_remove_attachments:
  * @window: a #ModestMsgViewWindow
- * @mime_parts: a #GList of #TnyMimePart
  *
- * Removes the attachments in @mime_parts, or currently selected attachments
- * if @mime_parts is %NULL, from local storage.
+ * Removes selected attachments.
  */
-void            modest_msg_view_window_remove_attachments (ModestMsgViewWindow *window,
-                                                          GList *mime_parts);
+void            modest_msg_view_window_remove_attachments (ModestMsgViewWindow *window);
 
 
 /**
index 696e268..24bfebb 100644 (file)
@@ -1543,3 +1543,19 @@ modest_msg_view_grab_focus (ModestMsgView *view)
 
        gtk_widget_grab_focus (priv->gtkhtml);
 }
+
+void
+modest_msg_view_remove_attachment (ModestMsgView *view, TnyMimePart *attachment)
+{
+       TnyMsg *msg;
+       ModestMsgViewPrivate *priv;
+
+       g_return_if_fail (MODEST_IS_MSG_VIEW (view));
+       g_return_if_fail (TNY_IS_MIME_PART (attachment));
+       priv = MODEST_MSG_VIEW_GET_PRIVATE (view);
+
+       msg = modest_msg_view_get_message (view);
+       modest_attachments_view_remove_attachment (MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
+                                                  attachment);
+       tny_mime_part_del_part (TNY_MIME_PART (msg), attachment);
+}
index 29596af..e496bab 100644 (file)
@@ -135,6 +135,7 @@ TnyHeaderFlags modest_msg_view_get_priority (ModestMsgView *self);
 void modest_msg_view_set_priority (ModestMsgView *self, TnyHeaderFlags flags);
 GList *modest_msg_view_get_selected_attachments (ModestMsgView *self);
 void modest_msg_view_grab_focus (ModestMsgView *self);
+void modest_msg_view_remove_attachment (ModestMsgView *view, TnyMimePart *attachment);
 
 
 G_END_DECLS