[Xfce4-commits] <postler:master> Offer saving attachments to a chosen folder

Christian Dywan noreply at xfce.org
Sat Nov 27 04:34:07 CET 2010


Updating branch refs/heads/master
         to 9ff36f55d09219797c87050f1a90d1680ac80839 (commit)
       from a88775195787209ff6187c1b32ae92d0a115161e (commit)

commit 9ff36f55d09219797c87050f1a90d1680ac80839
Author: Bernd Prünster <bernd.pruenster at gmail.com>
Date:   Sat Nov 27 02:12:20 2010 +0100

    Offer saving attachments to a chosen folder

 postler/postler-content.vala |   26 +++++++++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index 41c7a17..003fefa 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -787,11 +787,14 @@ public class Postler.Content : WebKit.WebView {
             body_chunk = """
                 <b>%s</b>
                 <p><a href="message-part:open:%d">%s</a>
+                <p><a href="message-part:save:%d">%s</a>
                 """.
                 printf (
                 message_part.filename ?? message_part.mime_type,
                 message_parts.position (message_parts.find (message_part)),
-                _("Open file"));
+                _("Open file"),
+                message_parts.position (message_parts.find (message_part)),
+                _("Save As..."));
         }
 
         try {
@@ -886,6 +889,8 @@ public class Postler.Content : WebKit.WebView {
             int index;
             if (uri.has_prefix ("message-part:open:"))
                 index = uri.substring (18, -1).to_int ();
+            else if (uri.has_prefix ("message-part:save:"))
+                index = uri.substring (18, -1).to_int ();
             else {
                 /* FIXME: Show error dialogue */
                 GLib.message (_("Erroneous attachment: %s"), uri);
@@ -893,6 +898,7 @@ public class Postler.Content : WebKit.WebView {
             }
             var message_part = message_parts.nth_data (index);
             string filename;
+            bool should_open = true;
             if (uri.has_prefix ("message-part:open:")) {
                 filename = "/tmp/%sXXXXXX".printf (message_part.filename ?? "");
                 if (FileUtils.mkstemp (filename) == -1) {
@@ -900,6 +906,22 @@ public class Postler.Content : WebKit.WebView {
                     GLib.message (_("Failed to create temporary file: %s"), filename);
                     return false;
                 }
+            } else if (uri.has_prefix ("message-part:save:")) {
+                var filechooser = new Gtk.FileChooserDialog (_("Save As..."),
+                    null, Gtk.FileChooserAction.SAVE,
+                    Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
+                    Gtk.STOCK_SAVE, Gtk.ResponseType.ACCEPT);
+                filechooser.do_overwrite_confirmation = true;
+                filechooser.set_current_folder (Environment.get_home_dir ());
+                filechooser.set_current_name (message_part.filename ?? "");
+                if (filechooser.run () == Gtk.ResponseType.ACCEPT)
+                    filename = filechooser.get_filename ();
+                else
+                    filename = null;
+                filechooser.destroy ();
+                if (filename == null)
+                    return true;
+                should_open = false;
             } else
                 assert_not_reached ();
             try {
@@ -910,6 +932,8 @@ public class Postler.Content : WebKit.WebView {
                 GLib.message (_("Failed to write file: %s"), filename);
                 return false;
             }
+            if (!should_open)
+                return true;
         }
 
         return Postler.App.show_uri (get_screen (), uri);



More information about the Xfce4-commits mailing list