[Xfce4-commits] <postler:master> Display message columns lazily in render callbacks

Christian Dywan noreply at xfce.org
Sat Jun 5 20:48:01 CEST 2010


Updating branch refs/heads/master
         to 43696960ac253c24b6b061e0d6feaf032e43488a (commit)
       from 021bb94b348f3c2eb5573e1d320c84d174fbd4f5 (commit)

commit 43696960ac253c24b6b061e0d6feaf032e43488a
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sat Jun 5 18:09:55 2010 +0200

    Display message columns lazily in render callbacks

 postler/postler-messages.vala |  153 ++++++++++++++++++++++++++++-------------
 1 files changed, 104 insertions(+), 49 deletions(-)

diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index 00a1182..9fbefc6 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -28,8 +28,8 @@ public class Postler.Messages : Gtk.TreeView {
         STATUS,
         ATTACHMENT,
         SUBJECT,
+        WEIGHT,
         FROM,
-        DATE,
         SIZE,
         LOCATION,
         TIMESTAMP
@@ -47,10 +47,84 @@ public class Postler.Messages : Gtk.TreeView {
         selected_location = location;
     }
 
+    void render_subject (Gtk.TreeViewColumn column, Gtk.CellRenderer cell,
+        Gtk.TreeModel model, Gtk.TreeIter iter) {
+        string charset, subject;
+        int weight = Pango.Weight.NORMAL;
+        var renderer = cell as Gtk.CellRendererText;
+
+        if (!rich_rows) {
+            model.get (iter, Columns.SUBJECT, out subject,
+                             Columns.WEIGHT, out weight,
+                             -1);
+            renderer.text = parse_encoded (subject, out charset);
+            renderer.weight = weight;
+            return;
+        }
+
+        string from;
+        time_t timestamp;
+        int64 size;
+        model.get (iter, Columns.SUBJECT, out subject,
+                         Columns.WEIGHT, out weight,
+                         Columns.SIZE, out size,
+                         Columns.TIMESTAMP, out timestamp,
+                         Columns.FROM, out from,
+                         -1);
+
+        subject = Markup.escape_text (parse_encoded (subject, out charset));
+        renderer.markup = ("<span weight=\"%d\">%s</span> <small>%s</small>\n" +
+                           "<small><tt>%s      </tt></small> %s").printf (
+                           weight, subject,
+                           format_size_for_display (size),
+                           GLib.Time.local (timestamp).format ("%x %X"),
+                           parse_address (parse_encoded (from, out charset))[0]);
+    }
+
+    void render_from (Gtk.TreeViewColumn column, Gtk.CellRenderer cell,
+        Gtk.TreeModel model, Gtk.TreeIter iter) {
+        var renderer = cell as Gtk.CellRendererText;
+
+        if (rich_rows)
+            renderer.text = "";
+        else {
+            string from;
+            model.get (iter, Columns.FROM, out from, -1);
+            string charset;
+            renderer.text = parse_address (parse_encoded (from, out charset))[0];
+        }
+    }
+
+    void render_date (Gtk.TreeViewColumn column, Gtk.CellRenderer cell,
+        Gtk.TreeModel model, Gtk.TreeIter iter) {
+        var renderer = cell as Gtk.CellRendererText;
+
+        if (rich_rows)
+            renderer.text = "";
+        else {
+            time_t timestamp;
+            model.get (iter, Columns.TIMESTAMP, out timestamp, -1);
+            renderer.text = GLib.Time.local (timestamp).format ("%x %X");
+        }
+    }
+
+    void render_size (Gtk.TreeViewColumn column, Gtk.CellRenderer cell,
+        Gtk.TreeModel model, Gtk.TreeIter iter) {
+        var renderer = cell as Gtk.CellRendererText;
+
+        if (rich_rows)
+            renderer.text = "";
+        else {
+            int64 size;
+            model.get (iter, Columns.SIZE, out size, -1);
+            renderer.text = format_size_for_display (size);
+        }
+    }
+
     public Messages () {
         store = new Gtk.TreeStore (9, typeof (string), typeof (string),
-            typeof (string), typeof (string), typeof (string),
-            typeof (string), typeof (string), typeof (string), typeof (ulong));
+            typeof (string), typeof (string), typeof (int), typeof (string),
+            typeof (int64), typeof (string), typeof (ulong));
         sort = new Gtk.TreeModelSort.with_model (store);
         set_model (sort);
         set_search_column (Columns.SUBJECT); /* FIXME doesn't work atm */
@@ -62,14 +136,14 @@ public class Postler.Messages : Gtk.TreeView {
             new Gtk.CellRendererPixbuf (), "stock-id", Columns.STATUS, null);
         insert_column_with_attributes (-1, _("Attachment"),
             new Gtk.CellRendererPixbuf (), "stock-id", Columns.ATTACHMENT, null);
-        insert_column_with_attributes (-1, _("Subject"),
-            new Gtk.CellRendererText (), "markup", Columns.SUBJECT, null);
-        insert_column_with_attributes (-1, _("From"),
-            new Gtk.CellRendererText (), "text", Columns.FROM, null);
-        insert_column_with_attributes (-1, _("Date"),
-            new Gtk.CellRendererText (), "text", Columns.DATE, null);
-        insert_column_with_attributes (-1, _("Size"),
-            new Gtk.CellRendererText (), "text", Columns.SIZE, null);
+        insert_column_with_data_func (-1, _("Subject"),
+            new Gtk.CellRendererText (), render_subject);
+        insert_column_with_data_func (-1, _("From"),
+            new Gtk.CellRendererText (), render_from);
+        insert_column_with_data_func (-1, _("Date"),
+            new Gtk.CellRendererText (), render_date);
+        insert_column_with_data_func (-1, _("Size"),
+            new Gtk.CellRendererText (), render_size);
 
         unowned Gtk.BindingSet binding_set = Gtk.BindingSet.by_class (get_class ());
         Gtk.BindingEntry.add_signal (binding_set,
@@ -309,9 +383,8 @@ public class Postler.Messages : Gtk.TreeView {
                             continue;
                     }
 
-                    string subject = _("(No subject)");
-                    string from = _("(Unknown)");
-                    string date = _("(No date)");
+                    string subject = null;
+                    string from = null;
                     time_t timestamp = 0;
                     var contents = folder_dir.resolve_relative_path (name);
                     try {
@@ -330,14 +403,22 @@ public class Postler.Messages : Gtk.TreeView {
                                 skip = true;
                                 break;
                             }
-                            if (field == "subject")
+                            if (field == "subject") {
                                 subject = parts[1].strip ();
+                                if (from != null && timestamp != 0)
+                                    break;
+                            }
                             else if (field == to_or_from) {
-                                string from_charset = null;
-                                from = parse_encoded (parts[1], out from_charset);
+                                from = parts[1];
+                                if (subject != null && timestamp != 0)
+                                    break;
+                            }
+                            else if (field == "date") {
+                                var parsed = new Soup.Date.from_string (parts[1]);
+                                timestamp = parsed != null ? (time_t)parsed.to_time_t () : 0;
+                                if (subject != null && from != null)
+                                    break;
                             }
-                            else if (field == "date")
-                                date = format_date (parts[1], now, out timestamp);
                         }
                         if (skip)
                             continue;
@@ -346,41 +427,15 @@ public class Postler.Messages : Gtk.TreeView {
                             contents.get_path (), contents_error.message);
                     }
 
-                    string charset = null;
-                    string real_subject = parse_encoded (subject, out charset);
-                    real_subject = GLib.Markup.escape_text (real_subject);
-
-                    if (rich_rows) {
-                        store.insert_with_values (out account_iter, null, -1,
-                            Columns.FLAGGED, flagged,
-                            Columns.STATUS, status,
-                            Columns.ATTACHMENT, null,
-                            Columns.SUBJECT,
-                                ("<span weight=\"%d\">%s</span> <small>%s</small>\n" +
-                                 "<small><tt>%s      </tt></small> %s").printf (
-                                font_weight,
-                                real_subject,
-                                format_size_for_display (info.get_size ()),
-                                date,
-                                parse_address (from)[0]),
-                            Columns.FROM, null,
-                            Columns.DATE, null,
-                            Columns.TIMESTAMP, timestamp,
-                            Columns.LOCATION, contents.get_path (),
-                            -1);
-                        continue;
-                    }
-
                     store.insert_with_values (out account_iter, null, -1,
                         Columns.FLAGGED, flagged,
                         Columns.STATUS, status,
                         Columns.ATTACHMENT, null,
-                        Columns.SUBJECT, "<span weight=\"%d\">%s</span>".printf (
-                            font_weight, real_subject),
-                        Columns.FROM, parse_address (from)[0],
-                        Columns.DATE, date,
+                        Columns.SUBJECT, subject != null ? subject : _("No subject"),
+                        Columns.WEIGHT, font_weight,
+                        Columns.FROM, from != null ? from : _("Unknown"),
                         Columns.TIMESTAMP, timestamp,
-                        Columns.SIZE, format_size_for_display (info.get_size ()),
+                        Columns.SIZE, info.get_size (),
                         Columns.LOCATION, contents.get_path (),
                         -1);
                 }



More information about the Xfce4-commits mailing list