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

This commit is contained in:
Michael James Gratton 2016-07-08 12:20:57 +10:00
parent f93fb43d64
commit 911e81a907
2 changed files with 35 additions and 60 deletions

View file

@ -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()
)
);
}
}

View file

@ -11,6 +11,22 @@
<property name="visible">True</property>
<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>
@ -27,22 +43,6 @@
<property name="visible">True</property>
<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>
@ -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>
@ -128,22 +128,6 @@
<property name="visible">True</property>
<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>
@ -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>