[Xfce4-commits] <postler:master> Refactor message part box into a new Viewer class

Christian Dywan noreply at xfce.org
Tue Jul 13 00:54:08 CEST 2010


Updating branch refs/heads/master
         to 3f4ea1695f22f979a70802ab97fdc5bc13c99102 (commit)
       from a2fe7de7f165147719ca7422367cd9132e35d968 (commit)

commit 3f4ea1695f22f979a70802ab97fdc5bc13c99102
Author: Christian Dywan <christian at twotoasts.de>
Date:   Mon Jul 5 21:46:23 2010 +0200

    Refactor message part box into a new Viewer class

 postler/postler-bureau.vala |   58 +-------------------------------
 postler/postler-viewer.vala |   78 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 56 deletions(-)

diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index 65ab73a..cdb982c 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -22,7 +22,6 @@ public class Postler.Bureau : Gtk.Window {
     Postler.Folders folders;
     public Postler.Messages messages;
     Postler.Content content;
-    Gtk.VBox message_parts;
 
     const string ui_markup = """
         <ui>
@@ -357,24 +356,6 @@ public class Postler.Bureau : Gtk.Window {
           N_("Search the full message text"), 3}
     };
 
-    static string icon_name_for_mime_type (string mime_type, Gtk.Widget widget) {
-        var icon_theme = Gtk.IconTheme.get_for_screen (widget.get_screen ());
-        var parts = mime_type.split ("/", 2);
-        string icon_name = parts[0] + "-" + parts[1];
-        if (icon_theme.has_icon (icon_name))
-            return icon_name;
-        icon_name = "gnome-mime-" + parts[0] + "-" + parts[1];
-        if (icon_theme.has_icon (icon_name))
-            return icon_name;
-        icon_name = parts[0] + "-x-generic";
-        if (icon_theme.has_icon (icon_name))
-            return icon_name;
-        icon_name = "gnome-mime-" + parts[0] + "-x-generic";
-        if (icon_theme.has_icon (icon_name))
-            return icon_name;
-        return "application-x-executable";
-    }
-
     public Bureau () {
         GLib.Object (icon_name: STOCK_INTERNET_MAIL,
                      title: GLib.Environment.get_application_name ());
@@ -497,45 +478,10 @@ public class Postler.Bureau : Gtk.Window {
             bool state = content.last_location != null;
             actions.get_action ("ViewSource").sensitive = state;
         });
-        var content_box = new Gtk.HBox (false, 0);
-        vpaned.pack2 (content_box, false, true);
-        scrolled = new Postler.ScrolledWindow (content);
-        content_box.pack_start (scrolled, true, true, 0);
-        message_parts = new Gtk.VBox (false, 0);
-        content.notify["n-parts"].connect ((object, pspec) => {
-            var scrollable = message_parts.parent.parent;
-            if (content.n_parts == 1) {
-                scrollable.hide ();
-                return;
-            }
-
-            var children = message_parts.get_children ();
-            foreach (var child in children)
-                child.destroy ();
-            var parts = content.get_parts ();
-            uint index = 0;
-            foreach (var part in parts) {
-                string icon_name = icon_name_for_mime_type (part, this);
-                var icon = new Gtk.Image.from_icon_name (icon_name,
-                                                         Gtk.IconSize.BUTTON);
-                var button = new Gtk.Button ();
-                button.relief = Gtk.ReliefStyle.NONE;
-                button.add (icon);
-                button.set_tooltip_text (part);
-                button.set_data ("index", index);
-                button.clicked.connect ((button) => {
-                    content.display_part (button.get_data ("index"));  });
-                message_parts.pack_start (button, false, false, 0);
-                index++;
-            }
-            scrollable.show_all ();
-        });
-        scrolled = new Postler.ScrolledWindow (message_parts);
-        content_box.pack_start (scrolled, false, false, 0);
-        shelf.show_all ();
 
+        vpaned.pack2 (new Postler.Viewer (content), false, true);
+        shelf.show_all ();
         search_options.hide ();
-        message_parts.parent.parent.hide ();
 
         folders.set_headers_visible (false);
         messages.set_headers_visible (false);
diff --git a/postler/postler-viewer.vala b/postler/postler-viewer.vala
new file mode 100644
index 0000000..30f0174
--- /dev/null
+++ b/postler/postler-viewer.vala
@@ -0,0 +1,78 @@
+/*
+ Copyright (C) 2010 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
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ See the file COPYING for the full license text.
+*/
+
+public class Postler.Viewer : Gtk.VBox {
+    Postler.Content content;
+    Gtk.VBox message_parts;
+
+    public Viewer (Postler.Content content) {
+        this.content = content;
+
+        var content_box = new Gtk.HBox (false, 0);
+        pack_start (content_box, true, true, 0);
+        var scrolled = new Postler.ScrolledWindow (content);
+        content_box.pack_start (scrolled, true, true, 0);
+        message_parts = new Gtk.VBox (false, 0);
+        content.notify["n-parts"].connect (notify_n_parts);
+        scrolled = new Postler.ScrolledWindow (message_parts);
+        content_box.pack_start (scrolled, false, false, 0);
+        message_parts.parent.parent.set_no_show_all (true);
+    }
+
+    static string icon_name_for_mime_type (string mime_type, Gtk.Widget widget) {
+        var icon_theme = Gtk.IconTheme.get_for_screen (widget.get_screen ());
+        var parts = mime_type.split ("/", 2);
+        string icon_name = parts[0] + "-" + parts[1];
+        if (icon_theme.has_icon (icon_name))
+            return icon_name;
+        icon_name = "gnome-mime-" + parts[0] + "-" + parts[1];
+        if (icon_theme.has_icon (icon_name))
+            return icon_name;
+        icon_name = parts[0] + "-x-generic";
+        if (icon_theme.has_icon (icon_name))
+            return icon_name;
+        icon_name = "gnome-mime-" + parts[0] + "-x-generic";
+        if (icon_theme.has_icon (icon_name))
+            return icon_name;
+        return "application-x-executable";
+    }
+
+    void notify_n_parts (GLib.Object object, GLib.ParamSpec pspec) {
+        var scrollable = message_parts.parent.parent;
+        if (content.n_parts == 1) {
+            scrollable.hide ();
+            return;
+        }
+
+        var children = message_parts.get_children ();
+        foreach (var child in children)
+            child.destroy ();
+        var parts = content.get_parts ();
+        uint index = 0;
+        foreach (var part in parts) {
+            string icon_name = icon_name_for_mime_type (part, this);
+            var icon = new Gtk.Image.from_icon_name (icon_name,
+                                                     Gtk.IconSize.BUTTON);
+            var button = new Gtk.Button ();
+            button.relief = Gtk.ReliefStyle.NONE;
+            button.add (icon);
+            button.set_tooltip_text (part);
+            button.set_data ("index", index);
+            button.clicked.connect ((button) => {
+                content.display_part (button.get_data ("index")); });
+            message_parts.pack_start (button, false, false, 0);
+            index++;
+        }
+        message_parts.parent.parent.set_no_show_all (false);
+        scrollable.show_all ();
+    }
+}
+



More information about the Xfce4-commits mailing list