[Xfce4-commits] <postler:master> Apply themed stylesheet in all different views

Christian Dywan noreply at xfce.org
Sat Apr 16 19:12:01 CEST 2011


Updating branch refs/heads/master
         to 4816e2a52719b47ff614d07128db5daf3894e3ff (commit)
       from de25f91572a1cae0ca0bdc6ec3ae61d754a8ec58 (commit)

commit 4816e2a52719b47ff614d07128db5daf3894e3ff
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sat Apr 16 19:08:43 2011 +0200

    Apply themed stylesheet in all different views
    
    This means the composer, error messages and source view.
    
    Toplevel windows have to be shown early so that theming
    information is available when the stylesheet's written.

 postler/postler-composer.vala |    2 +
 postler/postler-content.vala  |   45 +++++++++++++++++++++++----------
 postler/postler-reader.vala   |   54 ++++++++++++++++++----------------------
 3 files changed, 57 insertions(+), 44 deletions(-)

diff --git a/postler/postler-composer.vala b/postler/postler-composer.vala
index db3a9a7..86c8770 100644
--- a/postler/postler-composer.vala
+++ b/postler/postler-composer.vala
@@ -674,6 +674,7 @@ public class Postler.Composer : Gtk.Window {
         entry_subject = new Gtk.Entry ();
         box.pack_start (entry_subject, true, true, 12);
         content = new Postler.Content ();
+        content.set_no_show_all (true);
         var scrolled = new Postler.ScrolledWindow (content);
         scrolled.shadow_type = Gtk.ShadowType.IN;
         shelf.pack_start (scrolled, true, true, 0);
@@ -749,6 +750,7 @@ public class Postler.Composer : Gtk.Window {
         }
         content.prepare_reply (location, info, entry_to.text,
                                quote, part, body, is_bug_tracker);
+        content.show ();
         return true;
     }
 
diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index 475420b..4ba1f33 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -337,7 +337,9 @@ public class Postler.Content : WebKit.WebView {
         reply_to_all = null;
         message_parts = null;
         notify_property ("message-parts");
-        load_string ("", "text/plain", "UTF-8", "about:blank");
+        load_string ("<style text=\"text/css\">%s</style><body></body>"
+                     .printf (themed_style_sheet ()),
+                     "text/html", "UTF-8", "about:blank");
     }
 
     const EmoticonMapping[] emoticons = {
@@ -582,7 +584,13 @@ public class Postler.Content : WebKit.WebView {
             else if (signature != null)
                 body.append ("\n\n" + signature);
         }
-        load_string (body.str, "text/plain", "UTF-8", "about:blank");
+        load_string ("""
+            <style text=\"text/css">
+            %s * { white-space: pre-wrap !important; }</style>
+            <body>%s</body>
+            """.
+            printf (themed_style_sheet (), body.str),
+            "text/html", "UTF-8", "about:blank");
     }
 
     static void parse_content_type (string? content_type, ref string charset,
@@ -664,7 +672,9 @@ public class Postler.Content : WebKit.WebView {
         parse_content_type (content_type, ref charset, ref boundary,
                             ref mime_type, ref fname);
         set_view_source_mode (true);
-        load_string (body.str, "text/plain", charset, "about:blank");
+        load_string ("<style text=\"text/css\">%s</style><body>%s</body>"
+            .printf (themed_style_sheet (), body.str),
+            "text/plain", charset, "about:blank");
     }
 
     string selected_address () {
@@ -1067,10 +1077,24 @@ public class Postler.Content : WebKit.WebView {
         return new_body.str;
     }
 
-    string color_to_rgb (Gdk.Color color) {
+    string color_to_rgb (Gdk.Color? color) {
+        if (color == null)
+            return "inherit";
         return color.to_string ().substring (0, 7);
     }
 
+    string themed_style_sheet () {
+        /* Retrieve style from toplevel in case widget's not visible yet */
+        var widget = get_toplevel ();
+        /* Use void* with style_get to avoid Vala compiler error */
+        void* link_color;
+        widget.style_get ("link-color", out link_color);
+        return style_sheet.replace (
+            "WindowText", color_to_rgb (widget.style.fg[state])).replace (
+            "Window", color_to_rgb (widget.style.base[state])).replace (
+            "Link", color_to_rgb (*((Gdk.Color*)link_color)));
+    }
+
     public void display_part (MessagePart message_part) {
         if (current_part != message_part) {
             current_part = message_part;
@@ -1132,13 +1156,6 @@ public class Postler.Content : WebKit.WebView {
                 catch (GLib.RegexError error) { }
             }
 
-            /* Use void* with style_get to avoid Vala compiler error */
-            void* link_color;
-            style_get ("link-color", out link_color);
-            string themed_style_sheet = style_sheet.replace (
-                "WindowText", color_to_rgb (style.fg[state])).replace (
-                "Window", color_to_rgb (style.base[state])).replace (
-                "Link", color_to_rgb (*((Gdk.Color*)link_color)));
             load_string ("""
                 <style text="text/css">%s</style>
                 <span class="headers">
@@ -1158,7 +1175,7 @@ public class Postler.Content : WebKit.WebView {
                 </span>
                 <p class="body" style="%s">%s</p>
                 """.
-                printf (themed_style_sheet,
+                printf (themed_style_sheet (),
                         date,
                         _("From:"), sender,
                         format_header (_("To:"), recipient),
@@ -1186,13 +1203,13 @@ public class Postler.Content : WebKit.WebView {
 
     void display_error (string message) {
         load_string ("""
-            <title>%s</title>
+            <style text="text/css">%s</style>
             <body>
             <h1>%s</h1>
             <p>%s</p>
             </body>
             """.
-            printf (_("Error"), _("Error"), message),
+            printf (themed_style_sheet (), _("Error"), message),
             "text/html", "UTF-8", "about:blank");
         GLib.critical (message);
     }
diff --git a/postler/postler-reader.vala b/postler/postler-reader.vala
index 09ca34a..8ac4a38 100644
--- a/postler/postler-reader.vala
+++ b/postler/postler-reader.vala
@@ -129,16 +129,22 @@ public class Postler.Reader {
         Postler.App.register_stock_items ();
 
         if (module != "bureau") {
-            Gtk.Widget instance = null;
-            string icon_name = null;
-            string title = null;
-
             if (module == "content" || module == "source") {
-                instance = new Postler.Content ();
-                icon_name = module == "source" ? "text-html" : "emblem-mail";
-                title = _("(No subject)");
+                var window = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
+                window.set_icon_name (module == "source" ? "text-html" : "emblem-mail");
+                var screen = window.get_screen ();
+                Gdk.Rectangle monitor;
+                screen.get_monitor_geometry (0, out monitor);
+                double window_width = monitor.width / 2.2;
+                window.set_default_size ((int)window_width, (int)(monitor.height / 2.2));
+                window.show_all ();
+                /* Show toplevel early so stylesheets can be themed */
+                var shelf = new Gtk.VBox (false, 0);
+                window.add (shelf);
+                var content = new Postler.Content ();
+                shelf.add (new Postler.Viewer (content));
+
                 if (filenames != null && filenames[0] != null) {
-                    Postler.Content content = (Postler.Content)instance;
                     string filename;
                     try {
                        filename = Filename.from_uri (filenames[0], null);
@@ -149,12 +155,19 @@ public class Postler.Reader {
                         content.display_source (filename);
                     else
                         content.display (filename);
-                    title = content.subject;
+                    window.set_title (content.subject);
                 }
+
+                shelf.show_all ();
+                window.destroy.connect (Gtk.main_quit);
+                Gtk.main ();
+                return 0;
             }
             else if (module == "compose") {
                 Postler.Composer composer = new Postler.Composer ();
-                instance = composer;
+                /* Show toplevel early so stylesheets can be themed */
+                composer.show ();
+
                 string mailto = "";
                 if (filenames != null && filenames[0] != null)
                     mailto = filenames[0];
@@ -186,32 +199,13 @@ public class Postler.Reader {
                         composer.prepare_reply ();
                     }
 
-                instance.destroy.connect (Gtk.main_quit);
-                instance.show ();
+                composer.destroy.connect (Gtk.main_quit);
                 Gtk.main ();
                 return 0;
             }
             else
                 GLib.error ("Unknown module \"%s\". Valid modules are: %s",
                     module, "bureau content source compose service");
-
-            /* FIXME: Escape to close window */
-            var window = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
-            window.set_icon_name (icon_name);
-            window.set_title (title);
-            var screen = window.get_screen ();
-            Gdk.Rectangle monitor;
-            screen.get_monitor_geometry (0, out monitor);
-            double window_width = monitor.width / 2.2;
-            window.set_default_size ((int)window_width, (int)(monitor.height / 2.2));
-            var shelf = new Gtk.VBox (false, 0);
-            window.add (shelf);
-            /* TODO: menubar, toolbar */
-            shelf.add (new Postler.Viewer (instance as Postler.Content));
-            window.destroy.connect (Gtk.main_quit);
-            window.show_all ();
-            Gtk.main ();
-            return 0;
         }
 
         var app = new Postler.App ();



More information about the Xfce4-commits mailing list