[Xfce4-commits] <postler:master> Implement account-specific signatures

Christian Dywan noreply at xfce.org
Wed Jan 12 03:42:01 CET 2011


Updating branch refs/heads/master
         to 3f61640a99d3fc4ad7bbe0b563d9ec5b843e72c6 (commit)
       from 13592c762d306bc3006f0e6ed99411177a89a58f (commit)

commit 3f61640a99d3fc4ad7bbe0b563d9ec5b843e72c6
Author: Christian Dywan <christian at twotoasts.de>
Date:   Tue Jan 11 23:41:19 2011 +0100

    Implement account-specific signatures
    
    Fixes: https://bugs.launchpad.net/postler/+bug/697808

 postler/postler-accounts.vala     |    6 ++++++
 postler/postler-accountsetup.vala |   31 +++++++++++++++++++++++++------
 postler/postler-composer.vala     |   19 ++++++++++++-------
 postler/postler-content.vala      |   14 ++++++--------
 4 files changed, 49 insertions(+), 21 deletions(-)

diff --git a/postler/postler-accounts.vala b/postler/postler-accounts.vala
index 6314ca4..509b073 100644
--- a/postler/postler-accounts.vala
+++ b/postler/postler-accounts.vala
@@ -88,6 +88,7 @@ namespace Postler {
         public string certificate;
         public string reply;
         public string organization;
+        public string? signature;
         public string hide = hide_folder_default;
         public string[]? folders = { null, null, null, null, null, null, null };
 
@@ -246,6 +247,9 @@ public class Postler.Accounts : GLib.Object {
                     if (account_info.organization != null)
                         keyfile.set_string (group, "organization",
                                             account_info.organization);
+                    if (account_info.signature != null)
+                        keyfile.set_string (group, "signature",
+                                            account_info.signature);
                     if (account_info.hide != null
                      && account_info.hide != hide_folder_default)
                         keyfile.set_string (group, "hide", account_info.hide);
@@ -329,6 +333,8 @@ public class Postler.Accounts : GLib.Object {
                         info.reply = keyfile.get_string (group, "reply");
                     if (keyfile.has_key (group, "organization"))
                         info.organization = keyfile.get_string (group, "organization");
+                    if (keyfile.has_key (group, "signature"))
+                        info.signature = keyfile.get_string (group, "signature");
                     if (keyfile.has_key (group, "hide"))
                         info.hide = keyfile.get_string (group, "hide");
                     for (int ftype = 0; ftype < FolderType.MAX; ftype++) {
diff --git a/postler/postler-accountsetup.vala b/postler/postler-accountsetup.vala
index a2f2db7..10c50f8 100644
--- a/postler/postler-accountsetup.vala
+++ b/postler/postler-accountsetup.vala
@@ -1,5 +1,5 @@
 /*
- Copyright (C) 2010 Christian Dywan <christian at twotoasts.de>
+ Copyright (C) 2011 Christian Dywan <christian at twotoasts.de>
 
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
@@ -18,6 +18,7 @@ public class Postler.AccountWidget : Gtk.VBox {
     public Gtk.Entry address;
     Gtk.Entry password;
     Gtk.Entry organization;
+    Gtk.TextView signature;
 
     Gtk.Entry receiver;
     Gtk.Entry username;
@@ -34,6 +35,11 @@ public class Postler.AccountWidget : Gtk.VBox {
             if (realname == "Unknown")
                 realname = "";
             info.realname = realname.locale_to_utf8 (-1, null, null, null);
+            try {
+                GLib.FileUtils.get_contents (
+                    Environment.get_home_dir () + "/.signature", out info.signature);
+                info.signature = info.signature.chomp ();
+            } catch (GLib.FileError error) { }
         } else {
             info = account_info;
         }
@@ -55,6 +61,12 @@ public class Postler.AccountWidget : Gtk.VBox {
         organization.text = info.organization ?? "";
         add_label_entry (_("Organization:"), organization);
 
+        signature = new Gtk.TextView ();
+        signature.buffer.text = info.signature ?? "";
+        signature.accepts_tab = false;
+        add_label_entry (_("Signature:"), new Postler.ScrolledWindow (signature));
+        (signature.parent as Gtk.ScrolledWindow).shadow_type = Gtk.ShadowType.ETCHED_OUT;
+
         var expander = new Gtk.Expander (_("Advanced"));
         content_area.pack_start (expander, false, false, 4);
         advanced_area = new Gtk.VBox (false, 4);
@@ -76,19 +88,25 @@ public class Postler.AccountWidget : Gtk.VBox {
         pack_end (content_area, true, true, 0);
     }
 
-    void add_label_entry (string text, Gtk.Entry entry, bool advanced=false) {
+    void add_label_entry (string text, Gtk.Widget editable, bool advanced=false) {
         var hbox = new Gtk.HBox (false, 0);
         if (advanced)
             advanced_area.pack_start (hbox, false, false, 0);
         else
             content_area.pack_start (hbox, false, false, 4);
         var label = new Gtk.Label.with_mnemonic (text);
-        label.xalign = 1.0f;
         sizegroup.add_widget (label);
         hbox.pack_start (label, false, false, 4);
-        entry.activate.connect ((entry) => {
-            apply (); });
-        hbox.pack_start (entry, false, false, 4);
+        if (editable is Gtk.Entry) {
+            label.xalign = 1.0f;
+            (editable as Gtk.Entry).activate.connect ((editable) => {
+                apply (); });
+        }
+        else {
+            hbox.set_orientation (Gtk.Orientation.VERTICAL);
+            label.xalign = 0.0f;
+        }
+        hbox.pack_start (editable, false, false, 4);
     }
 
     public void apply () {
@@ -111,6 +129,7 @@ public class Postler.AccountWidget : Gtk.VBox {
         info.password = password.text;
 
         info.organization = organization.text != "" ? organization.text : null;
+        info.signature = signature.buffer.text != "" ? signature.buffer.text : null;
         info.receive = receiver.text != "" ? receiver.text : null;
         info.username = username.text != "" ? username.text : null;
         info.prefix = prefix.text != "" ? prefix.text : null;
diff --git a/postler/postler-composer.vala b/postler/postler-composer.vala
index dbf3a7f..a009ece 100644
--- a/postler/postler-composer.vala
+++ b/postler/postler-composer.vala
@@ -67,6 +67,15 @@ public class Postler.Composer : Gtk.Window {
         </ui>
     """;
 
+    AccountInfo? selected_account_for_address (string address)
+    {
+        string[] from = Postler.Messages.parse_address (address);
+        foreach (var info in accounts.get_infos ())
+            if (info.address != null && from[1] in info.address)
+                return info;
+        return null;
+    }
+
     void action_mail_send () {
         if (entry_subject.text == "") {
             var dialog = new Gtk.MessageDialog (this, 0,
@@ -94,9 +103,7 @@ public class Postler.Composer : Gtk.Window {
             return;
         }
 
-        string[] from = Postler.Messages.parse_address (sender);
-        foreach (var info in accounts.get_infos ()) {
-            if (info.address != null && from[1] in info.address) {
+                var info = selected_account_for_address (sender);
                 string queue = info.path + "/" + info.get_folder (FolderType.QUEUE);
                 string sent = info.path + "/" + info.get_folder (FolderType.SENT);
                 if (queue.has_suffix ("/") || sent.has_suffix ("/")
@@ -241,9 +248,6 @@ public class Postler.Composer : Gtk.Window {
                 } catch (GLib.Error error) {
                     GLib.critical (_("Failed to send message: %s"), error.message);
                 }
-                break;
-            }
-        }
     }
 
     void action_close () {
@@ -554,7 +558,8 @@ public class Postler.Composer : Gtk.Window {
     }
 
     public bool prepare_reply (string? location=null, bool quote=false) {
-        return content.prepare_reply (location, entry_to.text, quote, part);
+        var info = selected_account_for_address (combo_from.get_active_text ());
+        return content.prepare_reply (location, info, entry_to.text, quote, part);
     }
 
     public bool add_field (string field, string data) {
diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index c120020..f60d191 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -372,7 +372,9 @@ public class Postler.Content : WebKit.WebView {
         return "";
     }
 
-    public bool prepare_reply (string? location, string recipient, bool quote, int part) {
+    public bool prepare_reply (string? location, AccountInfo account_info,
+        string recipient, bool quote, int part) {
+
         var body = new StringBuilder ();
 
         if (location != null) {
@@ -470,14 +472,10 @@ public class Postler.Content : WebKit.WebView {
             position--;
         } while (position > 0 && position < body.len);
 
-        string signature = "";
-        try {
-            GLib.FileUtils.get_contents (Environment.get_home_dir () + "/.signature",
-                                         out signature);
-        } catch (GLib.FileError error) { }
-        if (top_post)
+        unowned string? signature = account_info.signature;
+        if (signature != null && top_post)
             body.prepend ("\n\n--\n" + signature + "\n");
-        else
+        else if (signature != null)
             body.append ("\n\n--\n" + signature);
         load_string (body.str, "text/plain", "UTF-8", "about:blank");
         return true;



More information about the Xfce4-commits mailing list