[geary/wip/765516-gtk-widget-conversation-viewer: 76/174] Go back to using the same size avatar for expanded/collapsed messages.



commit 741ff9955722144ee002197bc104ebf5ff5170f6
Author: Michael James Gratton <mike vee net>
Date:   Fri Jul 8 12:20:57 2016 +1000

    Go back to using the same size avatar for expanded/collapsed messages.

 .../conversation-viewer/conversation-message.vala  |   41 ++++++---------
 ui/conversation-message.ui                         |   54 +++++++-------------
 2 files changed, 35 insertions(+), 60 deletions(-)
---
diff --git a/src/client/conversation-viewer/conversation-message.vala 
b/src/client/conversation-viewer/conversation-message.vala
index efae476..7c443b1 100644
--- a/src/client/conversation-viewer/conversation-message.vala
+++ b/src/client/conversation-viewer/conversation-message.vala
@@ -77,9 +77,10 @@ public class ConversationMessage : Gtk.Box {
     internal ConversationWebView web_view { get; private set; }
 
     [GtkChild]
-    private Gtk.Revealer preview_revealer;
+    private Gtk.Image avatar;
+
     [GtkChild]
-    private Gtk.Image preview_avatar;
+    private Gtk.Revealer preview_revealer;
     [GtkChild]
     private Gtk.Label preview_from;
     [GtkChild]
@@ -90,8 +91,6 @@ public class ConversationMessage : Gtk.Box {
     [GtkChild]
     private Gtk.Revealer header_revealer;
     [GtkChild]
-    private Gtk.Image header_avatar;
-    [GtkChild]
     private Gtk.FlowBox from;
     [GtkChild]
     private Gtk.Label subject;
@@ -289,7 +288,7 @@ public class ConversationMessage : Gtk.Box {
     }
 
     /**
-     * Starts loading the avatar for the sender of the message.
+     * Starts loading the avatar for the message's sender.
      */
     public async void load_avatar(Soup.Session session, Cancellable load_cancellable) {
         // Queued messages are cancelled in ConversationViewer.clear()
@@ -299,7 +298,7 @@ public class ConversationMessage : Gtk.Box {
         Geary.RFC822.MailboxAddress? primary = message.get_primary_originator();
         if (primary != null) {
             int window_scale = get_scale_factor();
-            int pixel_size = header_avatar.get_pixel_size();
+            int pixel_size = this.avatar.get_pixel_size();
             Soup.Message message = new Soup.Message(
                 "GET",
                 Gravatar.get_image_uri(
@@ -541,36 +540,28 @@ public class ConversationMessage : Gtk.Box {
     }
 
     private void set_avatar(uint8[] image_data) {
-        Gdk.Pixbuf avatar = null;
+        Gdk.Pixbuf avatar_buf = null;
         Gdk.PixbufLoader loader = new Gdk.PixbufLoader();
         try {
             loader.write(image_data);
             loader.close();
-            avatar = loader.get_pixbuf();
+            avatar_buf = loader.get_pixbuf();
         } catch (Error err) {
             debug("Error loading Gravatar response: %s", err.message);
         }
 
-        if (avatar != null) {
-            Gdk.Window window = get_window();
+        if (avatar_buf != null) {
             int window_scale = get_scale_factor();
-            int preview_size = preview_avatar.pixel_size * window_scale;
-            preview_avatar.set_from_surface(
-                Gdk.cairo_surface_create_from_pixbuf(
-                    avatar.scale_simple(
-                        preview_size, preview_size, Gdk.InterpType.BILINEAR
-                    ),
-                    window_scale,
-                    window)
-            );
-            int header_size = header_avatar.pixel_size * window_scale;
-            if (avatar.width != header_size) {
-                avatar = avatar.scale_simple(
-                    header_size, header_size, Gdk.InterpType.BILINEAR
+            int avatar_size = this.avatar.pixel_size * window_scale;
+            if (avatar_buf.width != avatar_size) {
+                avatar_buf = avatar_buf.scale_simple(
+                    avatar_size, avatar_size, Gdk.InterpType.BILINEAR
                 );
             }
-            header_avatar.set_from_surface(
-                Gdk.cairo_surface_create_from_pixbuf(avatar, window_scale, window)
+            this.avatar.set_from_surface(
+                Gdk.cairo_surface_create_from_pixbuf(
+                    avatar_buf, window_scale, get_window()
+                )
             );
         }
     }
diff --git a/ui/conversation-message.ui b/ui/conversation-message.ui
index 59e4e1b..92a92e1 100644
--- a/ui/conversation-message.ui
+++ b/ui/conversation-message.ui
@@ -12,6 +12,22 @@
         <property name="can_focus">False</property>
         <property name="spacing">6</property>
         <child>
+          <object class="GtkImage" id="avatar">
+            <property name="width_request">18</property>
+            <property name="height_request">18</property>
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="valign">start</property>
+            <property name="pixel_size">32</property>
+            <property name="icon_name">avatar-default-symbolic</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
           <object class="GtkBox">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
@@ -28,22 +44,6 @@
                     <property name="can_focus">False</property>
                     <property name="spacing">6</property>
                     <child>
-                      <object class="GtkImage" id="preview_avatar">
-                        <property name="width_request">18</property>
-                        <property name="height_request">18</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="valign">start</property>
-                        <property name="pixel_size">32</property>
-                        <property name="icon_name">avatar-default-symbolic</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">False</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
                       <object class="GtkBox" id="preview_bod">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
@@ -106,7 +106,7 @@
                       <packing>
                         <property name="expand">True</property>
                         <property name="fill">True</property>
-                        <property name="position">1</property>
+                        <property name="position">0</property>
                       </packing>
                     </child>
                   </object>
@@ -129,22 +129,6 @@
                     <property name="can_focus">False</property>
                     <property name="spacing">6</property>
                     <child>
-                      <object class="GtkImage" id="header_avatar">
-                        <property name="width_request">18</property>
-                        <property name="height_request">18</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="valign">start</property>
-                        <property name="pixel_size">48</property>
-                        <property name="icon_name">avatar-default-symbolic</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">False</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
                       <object class="GtkBox" id="headers">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
@@ -352,7 +336,7 @@
                       <packing>
                         <property name="expand">True</property>
                         <property name="fill">True</property>
-                        <property name="position">1</property>
+                        <property name="position">0</property>
                       </packing>
                     </child>
                   </object>
@@ -368,7 +352,7 @@
           <packing>
             <property name="expand">True</property>
             <property name="fill">True</property>
-            <property name="position">0</property>
+            <property name="position">1</property>
           </packing>
         </child>
         <style>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]