[Xfce4-commits] <postler:master> Render conversations using Adium style if available

Christian Dywan noreply at xfce.org
Sun Jun 26 07:30:01 CEST 2011


Updating branch refs/heads/master
         to 175ca1b0e192c7f81a474b99d72c137d92eace02 (commit)
       from 7829bf3844f3c5d0fb5167324b167d8f3a04b07f (commit)

commit 175ca1b0e192c7f81a474b99d72c137d92eace02
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun Jun 26 07:27:03 2011 +0200

    Render conversations using Adium style if available

 postler/postler-content.vala  |   79 ++++++++++++++++++++++++++++------------
 postler/postler-index.vala    |    4 ++-
 postler/postler-message.vala  |    4 ++
 postler/postler-messages.vala |    5 ++-
 4 files changed, 65 insertions(+), 27 deletions(-)

diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index 50c671d..89b2904 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -53,12 +53,12 @@ public class Postler.Content : WebKit.WebView {
         }
         body {
             background-color: Window !important; color: WindowText !important;
-            padding: 1em;
+            padding: 1em; margin: 0 !important;
         }
         .body {
             font-size: 100% !important;
         }
-        .reply, .project_reply {
+        .reply {
             border-radius: 15px;
             border: 1px solid ButtonText;
             background-color: ButtonFace; color: ButtonText;
@@ -67,7 +67,10 @@ public class Postler.Content : WebKit.WebView {
         .sender {
             margin-bottom: 0.5em;
         }
-        .project_reply .signature {
+        .time {
+            float: right;
+        }
+        .no_signature .signature {
             display: none;
         }
         /* Quotations */
@@ -204,7 +207,7 @@ public class Postler.Content : WebKit.WebView {
                 continue;
             if (linkified.len > 0)
                linkified.append (", ");
-            linkified.append ("<a href=\"" + quoted + (arguments != null ? arguments : "") +
+            linkified.append ("<a href=\"mailto:" + quoted + (arguments != null ? arguments : "") +
                 "\" title=\"" + quoted + "\">" + name + "</a>");
             if (edit_icon != "")
                 linkified.append ((" <a href=\"contact:%s:%s\">%s</a>").printf (
@@ -617,6 +620,29 @@ public class Postler.Content : WebKit.WebView {
                 var client = new Postler.Client ();
                 thread = yield client.get_thread (the_message);
             }
+
+            /* Use Adium style if existant, otherwise fallback to internal */
+            string theme_name = "ubuntu.AdiumMessageStyle";
+            string template_path = "/usr/share/adium/message-styles/" +
+                                   theme_name + "/Contents/Resources/";
+            string content_template, content_stylesheet;
+            try {
+                FileUtils.get_contents (template_path + "Incoming/Content.html",
+                                        out content_template, null);
+                FileUtils.get_contents (template_path + "main.css",
+                                        out content_stylesheet, null);
+            }
+            catch (GLib.Error template_error) {
+                content_template = """
+                    <div class="reply">
+                    <div class="sender">%sender%<div class="time">%time{%X}%</div></div>
+                    %message%
+                    </div>
+                    </div>
+                    """;
+                content_stylesheet = "";
+            }
+
             var body_chunk = new StringBuilder ();
             foreach (var child in thread) {
                 MessagePart? html_part = null;
@@ -636,27 +662,19 @@ public class Postler.Content : WebKit.WebView {
                     text_part.body.append (parse_error.message);
                 }
 
-                string reply_class = "reply";
-                if (child.project != null)
-                    reply_class = "project_reply";
-                body_chunk.append_printf ("""
-                    <div class="%s"><div class="sender">%s<div style="float: right;">%s</div></div>
-                    """,
-                    reply_class, linkify_address (child.sender, null), format_date (child.date));
+                var reply_chunk = new StringBuilder ();
                 if (html_part != null)
-                    body_chunk.append (html_part.body.str);
+                    reply_chunk.append (html_part.body.str);
                 else if (text_part != null) {
-                    if (child.project != null)
-                         reply_class += " plain_text";
-                    body_chunk.append (render_plain_text (text_part.body.str));
+                    reply_chunk.append (render_plain_text (text_part.body.str, child.project));
                 }
                 else
-                    body_chunk.append (text_part.body.str);
+                    reply_chunk.append (text_part.body.str);
 
                 foreach (var attachment_part in child.parts) {
                     if (attachment_part != html_part && attachment_part != text_part
                      && !attachment_part.mime_type.has_prefix ("multipart/"))
-                        body_chunk.append_printf ("""<p>
+                        reply_chunk.append_printf ("""<p>
                             <b>%s</b>
                             <a href="message-part:open:%d">%s</a>
                             <a href="message-part:save:%d">%s</a></p>
@@ -668,7 +686,12 @@ public class Postler.Content : WebKit.WebView {
                             _("Save As..."));
                 }
 
-                body_chunk.append ("</div>");
+                string reply_markup;
+                reply_markup = content_template.replace ("%message%", reply_chunk.str);
+                reply_markup = reply_markup.replace ("\"%sender%\"", ("\"" + child.sender + "\""));
+                reply_markup = reply_markup.replace ("%sender%", linkify_address (child.sender, null));
+                reply_markup = reply_markup.replace ("%time{%X}%", format_date (child.date));
+                body_chunk.append (reply_markup);
             }
 
             message = thread.nth_data (0);
@@ -704,7 +727,8 @@ public class Postler.Content : WebKit.WebView {
 
             load_string (
                 """
-                <span class="headers">
+                <style text="text/css">%s</style>
+                <div class="headers">
                 <b>%s</b><br>
                 %s
                 <span style="float: right;"><a href="#more" id="more">%s</a></span>
@@ -714,10 +738,11 @@ public class Postler.Content : WebKit.WebView {
                 %s
                 %s
                 </span>
-                </span>
-                <style text="text/css">%s</style><p class="body">%s</p>
+                </div>
+                <div class="body">%s</div>
                 """
                 .printf (
+                         themed_style_sheet () + content_stylesheet,
                          message.subject,
                          /* FIXME: Merge all recipients here? */
                          linkify_address (message.recipients, arguments),
@@ -729,19 +754,21 @@ public class Postler.Content : WebKit.WebView {
                          format_header (_("Organization:"), message.organization),
                          format_header (_("Application:"), message.application),
                          format_header (_("Unsubscribe:"), list_unsubscribe),
-                         themed_style_sheet (), body_chunk.str),
-                "text/html", "UTF-8", "about:blank");
+                         body_chunk.str),
+                "text/html", "UTF-8", "file://" + template_path);
         } catch (GLib.Error error) {
             display_error (error.message);
         }
         return false;
     }
 
-    string render_plain_text (string body) {
+    string render_plain_text (string body, string? project) {
         bool in_signature = false;
         int in_quote = 0;
 
         var new_body = new StringBuilder ("");
+        if (project != null)
+            new_body.append ("<span class=\"plain_text no_signature\">");
         foreach (string line in body.split ("<br>")) {
             /* Looks like a signature */
             if (in_signature && line[0] == '\0') {
@@ -789,6 +816,8 @@ public class Postler.Content : WebKit.WebView {
                 line = line.substring (1);
             new_body.append (line + "<br>");
         }
+        if (project != null)
+            new_body.append ("</span");
 
         /* Linkify */
         try {
@@ -859,6 +888,8 @@ public class Postler.Content : WebKit.WebView {
 
         if (uri != null && uri.has_prefix ("about:"))
             return false;
+        if (uri.has_prefix ("file:///"))
+            return false;
 
         decision.ignore ();
         if (uri.has_prefix ("contact:")) {
diff --git a/postler/postler-index.vala b/postler/postler-index.vala
index db2ee44..0382a07 100644
--- a/postler/postler-index.vala
+++ b/postler/postler-index.vala
@@ -171,7 +171,9 @@ namespace Postler {
             if (statement_get == null) {
                 if (database.prepare_v2 ("""
                     SELECT subject, sender, recipients,
-                    unread, flagged, forwarded, replied, priority, date, uri FROM messages
+                    unread, flagged, forwarded, replied, priority, date, uri,
+                    (SELECT COUNT (*) FROM messages WHERE threads = ?1) AS replies
+                    FROM messages
                     WHERE id = ?1 GROUP BY id ORDER BY date ASC LIMIT 1
                     """,
                     -1, out statement_get) != Sqlite.OK)
diff --git a/postler/postler-message.vala b/postler/postler-message.vala
index 1d26cb3..a4cecad 100644
--- a/postler/postler-message.vala
+++ b/postler/postler-message.vala
@@ -87,6 +87,7 @@ namespace Postler {
         public string get_path () { return GLib.File.new_for_uri (uri).get_path (); }
         public string? id { public get; set; }
         public string? threads { public get; set; }
+        public int64 replies { public get; set; }
         string? charset = null;
         public string get_charset () { return charset ?? "ISO-8859-1"; }
         public GLib.DateTime? date { public get; set; }
@@ -123,6 +124,7 @@ namespace Postler {
             var message_data = new GLib.HashTable<string,Variant> (str_hash, str_equal);
             message_data.insert ("id", this.id);
             message_data.insert ("uri", this.uri ?? "");
+            message_data.insert ("replies", this.replies);
             message_data.insert ("subject", this.subject ?? "");
             message_data.insert ("sender", this.sender ?? "");
             message_data.insert ("recipients", this.recipients ?? "");
@@ -146,6 +148,7 @@ namespace Postler {
 
         public void from_hash_table (GLib.HashTable<string,Variant> message_data) {
             this.uri = message_data.lookup ("uri").get_string ();
+            this.replies = message_data.lookup ("replies").get_int64 ();
             this.subject = message_data.lookup ("subject").get_string ();
             this.sender = message_data.lookup ("sender").get_string ();
             this.recipients = message_data.lookup ("recipients").get_string ();
@@ -159,6 +162,7 @@ namespace Postler {
 
         public Message.from_statement (string id, Sqlite.Statement statement) {
             this.id = id;
+            this.replies = statement.column_int64 (10);
             this.subject = statement.column_text (0);
             this.sender = statement.column_text (1);
             this.recipients = statement.column_text (2);
diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index 0a4e702..61c93fd 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -160,8 +160,9 @@ public class Postler.Messages : Gtk.TreeView {
 
         renderer.ellipsize = Pango.EllipsizeMode.MIDDLE;
         renderer.markup = ("<span weight=\"%d\">%s</span>\n" +
-                           "<small><tt>%s      </tt></small> %s").printf (
-                           weight, from, date, subject);
+                           "<small><tt>%s      </tt></small> %s <b>%s</b>").printf (
+            weight, from, date, subject,
+            message.replies > 1 ? message.replies.to_string () : "");
     }
 
     void renderer_flag_toggled (Gtk.CellRendererToggle renderer,



More information about the Xfce4-commits mailing list