Commit 5101ab54 authored by Niels De Graef's avatar Niels De Graef

Avatar: load asynchronously.

This fixes [bug 657962](https://bugzilla.gnome.org/show_bug.cgi?id=657962).
parent 81ef5940
......@@ -85,10 +85,10 @@ public class Contacts.AvatarSelector : Dialog {
this.current_avatar = new Avatar (MAIN_SIZE);
if (contact != null) {
contact.keep_widget_uptodate (this.current_avatar, (w) => {
(w as Avatar).set_image (contact.individual, contact);
(w as Avatar).set_image.begin (contact.individual, contact);
});
} else {
this.current_avatar.set_image (null, null);
this.current_avatar.set_image.begin (null, null);
}
this.current_avatar.set_hexpand (false);
this.current_avatar.show ();
......
......@@ -25,8 +25,8 @@ using Gee;
*/
public class Contacts.Avatar : DrawingArea {
private int size;
private Gdk.Pixbuf? pixbuf;
private Contact? contact;
private Gdk.Pixbuf? pixbuf = null;
private Contact? contact = null;
// The background color used in case of a fallback avatar
private Gdk.RGBA? bg_color = null;
......@@ -47,21 +47,19 @@ public class Contacts.Avatar : DrawingArea {
queue_draw ();
}
public void set_image (AvatarDetails? details, Contact? contact = null) {
public async void set_image (AvatarDetails? details, Contact? contact = null) {
this.contact = contact;
// FIXME listen for changes in the Individual's avatar
Gdk.Pixbuf? a_pixbuf = null;
if (details != null && details.avatar != null) {
try {
var stream = details.avatar.load (size, null);
a_pixbuf = new Gdk.Pixbuf.from_stream_at_scale (stream, size, size, true);
var stream = yield details.avatar.load_async (size, null);
this.pixbuf = yield new Gdk.Pixbuf.from_stream_at_scale_async (stream, size, size, true);
queue_draw ();
} catch {
}
}
set_pixbuf (a_pixbuf);
}
public override bool draw (Cairo.Context cr) {
......
......@@ -951,10 +951,10 @@ public class Contacts.ContactEditor : Grid {
if (this.contact != null) {
this.contact.keep_widget_uptodate (this.avatar, (w) => {
this.avatar.set_image (this.contact.individual, this.contact);
this.avatar.set_image.begin (this.contact.individual, this.contact);
});
} else {
this.avatar.set_image (null, null);
this.avatar.set_image.begin (null, null);
}
this.container_grid.attach (button, 0, 0, 1, 3);
......
......@@ -67,7 +67,7 @@ public class Contacts.ContactList : ListBox {
// Update widgets
this.label.set_text (this.contact.display_name);
this.avatar.set_image (this.contact.individual, this.contact);
this.avatar.set_image.begin (this.contact.individual, this.contact);
}
}
......
......@@ -100,8 +100,8 @@ public class Contacts.ContactSheet : Grid {
image_frame.set_vexpand (false);
image_frame.set_valign (Align.START);
c.keep_widget_uptodate (image_frame, (w) => {
(w as Avatar).set_image (c.individual, c);
});
(w as Avatar).set_image.begin (c.individual, c);
});
attach (image_frame, 0, 0, 1, 3);
var name_label = new Label (null);
......
......@@ -47,7 +47,7 @@ public class Contacts.LinkSuggestionGrid : Grid {
image_frame.hexpand = false;
image_frame.margin = 12;
contact.keep_widget_uptodate (image_frame, (w) => {
(w as Avatar).set_image (contact.individual, contact);
(w as Avatar).set_image.begin (contact.individual, contact);
});
image_frame.show ();
attach (image_frame, 0, 0, 1, 2);
......
......@@ -85,7 +85,7 @@ public class Contacts.LinkedAccountsDialog : Dialog {
image_frame.margin = 6;
image_frame.margin_end = 12;
contact.keep_widget_uptodate (image_frame, (w) => {
(w as Avatar).set_image (contact.individual, contact);
(w as Avatar).set_image.begin (contact.individual, contact);
});
row_grid.attach (image_frame, 0, 0, 1, 2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment