[Xfce4-commits] <postler:master> Define POSTLER_MOCKUP to open in mockup mode

Christian Dywan noreply at xfce.org
Sun Jul 3 21:04:05 CEST 2011


Updating branch refs/heads/master
         to 58cec092d0de1122e1a4d2d9f890dac60ed91bb3 (commit)
       from ee924f9d29c60b031be960c93b58490e27ce7e6d (commit)

commit 58cec092d0de1122e1a4d2d9f890dac60ed91bb3
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun Jul 3 17:10:43 2011 +0200

    Define POSTLER_MOCKUP to open in mockup mode

 postler/postler-bureau.vala  |   35 +++++++++++++++++++++++++++++++++++
 postler/postler-content.vala |    6 +++---
 postler/postler-message.vala |   23 ++++++++++++++++++-----
 3 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index 11f1246..60c9384 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -884,6 +884,41 @@ public class Postler.Bureau : Gtk.Window {
             messages.grab_focus ();
             folders.select_folder ("file://%/INBOX/%");
         }
+
+        if (Environment.get_variable ("POSTLER_MOCKUP") != null) {
+            progressbar.fraction = 0.7;
+            statuslabel.label = "Receiving 4 of 7 - Inbox";
+            statusitem.child.show ();
+            search.set_text ("elementary");
+            search.activate ();
+            messages.notify["selected-message"].connect_after ((object, pspec) => {
+                var infobar = show_fetch_error_infobar ("elementary", "Everything's working as expected");
+                infobar.set_message_type (Gtk.MessageType.WARNING);
+            });
+            messages.notify["location"].connect_after ((object, pspec) => {
+                ulong now = new Soup.Date.from_now (0).to_time_t ();
+                string date = GLib.Time.local ((time_t)now).format ("%x %X");
+                try {
+                    var message = new Message.from_stream (new GLib.DataInputStream (
+                        new GLib.MemoryInputStream.from_data ((
+                    "From: Zeus\nTo: You, Hera <a at a>, Ares <a at a>, Aphrodite <a at a>,"
+                  + "Artemis <a at a>, Hephaistos <a at a>, Poseidon <a at a>, Dionisos <a at a>,"
+                  + "Apollo <a at a>, Hermes <a at a>, Athena <a at a>, Demeter <a@@>, "
+                  + "Hestia <a at a>\nCC: Hades <a at a>, Herkules <a at a>, Uranus <a at a>, Nyx <a at a>\n"
+                  + "Subject: Regarding nudity on the Olympus\n"
+                  + "Date: Fri, 28 May 2010 23:27:35 +0200\n"
+                  + "Content-Type: text/plain; charset=UTF-8\n"
+                  + "Message-Id: <1234567890 at localhost>\n\n"
+                  + "On %s, Jupiter wrote:\n"
+                  + "> Lorem ipsum dolor sit amet\n"
+                  + "Δεν υπάρχει κανείς που να αγαπάει τον ίδιο τον πόνο").printf (date),
+                    -1, null)));
+                    viewer.show ();
+                    content.display (message);
+                }
+                catch (GLib.Error error) { GLib.error ("Failed to render mockup"); }
+            });
+        }
     }
 }
 
diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index 9d06144..9afb4b4 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -645,10 +645,10 @@ public class Postler.Content : WebKit.WebView {
                 }
             }
         }
-        if (the_message.uri != null) {
-            var account_info = the_message.get_account (accounts);
+
+        var account_info = the_message.get_account (accounts);
+        if (account_info != null)
             return account_info.address.split (",")[0];
-        }
 
         return null;
     }
diff --git a/postler/postler-message.vala b/postler/postler-message.vala
index eda8159..b9f43fb 100644
--- a/postler/postler-message.vala
+++ b/postler/postler-message.vala
@@ -229,7 +229,9 @@ namespace Postler {
         }
 
         public AccountInfo? get_account (Accounts accounts) {
-            return_val_if_fail (uri != null, null);
+            if (!(uri != null && uri.has_prefix ("file://")))
+                return null;
+
             /* Look for the account belonging to the message */
             string folder = uri.substring (0, uri.pointer_to_offset (uri.rstr ("/")));
             return_val_if_fail (folder.has_suffix ("/new") || folder.has_suffix ("/cur"), null);
@@ -250,11 +252,21 @@ namespace Postler {
 
         void read_from_file (GLib.File file,
             GLib.Cancellable? cancellable = null) throws GLib.Error {
-
             uri = file.get_uri ();
             read_flags (file.get_path ());
+            read_from_stream (new DataInputStream (file.read (cancellable)));
+        }
 
-            stream = new DataInputStream (file.read (cancellable));
+        public Message.from_stream (GLib.DataInputStream stream,
+            GLib.Cancellable? cancellable = null) throws GLib.Error {
+            uri = "memory:";
+            read_from_stream (stream);
+        }
+
+        void read_from_stream (GLib.DataInputStream stream,
+            GLib.Cancellable? cancellable = null) throws GLib.Error {
+
+            this.stream = stream;
             string line;
             string previous_line = "";
             while ((line = stream.read_line (null, cancellable)) != null) {
@@ -355,8 +367,6 @@ namespace Postler {
                     fields.insert (field, parts[1]);
             }
 
-            if (id == null)
-                throw new GLib.FileError.FAILED (_("Failed to find valid message ID"));
             /* Treat top-levels like replies to themselves */
             if (threads == null)
                 threads = id;
@@ -375,6 +385,9 @@ namespace Postler {
                 else if (Postler.Contact.equal (canonical, sender))
                     reply_to = null;
             }
+
+            if (id == null)
+                throw new GLib.FileError.FAILED (_("Failed to find valid message ID"));
         }
 
         public static void parse_content_type (string? content_type, ref string charset,



More information about the Xfce4-commits mailing list