Commit 0c1bfadc authored by Julian Sparber's avatar Julian Sparber

contact-editor: cache avatar and resize based on available space

parent b85a8543
......@@ -24,6 +24,7 @@ using Gee;
* avatar, or a fallback if it's not available.
*/
public class Contacts.Avatar : DrawingArea {
private int display_size;
private int size;
private Gdk.Pixbuf? pixbuf = null;
private Gdk.Pixbuf? cache = null;
......@@ -42,6 +43,7 @@ public class Contacts.Avatar : DrawingArea {
}
this.size = size;
this.display_size = size;
set_size_request (size, size);
// If we don't have an avatar, don't try to load it later
......@@ -59,6 +61,14 @@ public class Contacts.Avatar : DrawingArea {
queue_draw ();
}
/* Set the actual size we want the avatar to be, this must be smaller or eq then the initial size set */
public void set_display_size (int display_size) {
if (display_size != this.display_size) {
this.display_size = display_size;
set_size_request (display_size, display_size);
}
}
private async void load_avatar () {
assert (this.contact != null);
......
......@@ -118,6 +118,16 @@ public class Contacts.ContactEditor : ContactForm {
construct {
this.writable_personas = new HashMap<string, HashMap<string, Field?>> ();
this.container_grid.size_allocate.connect(on_container_grid_size_allocate);
size_allocate.connect(() => {
Allocation size;
get_allocation(out size);
if (size.width < 400) {
this.avatar.set_display_size (PROFILE_SMALL_SIZE);
} else {
this.avatar.set_display_size (PROFILE_SIZE);
}
});
}
public ContactEditor (Contact? contact, Store store, GLib.ActionGroup editor_actions) {
......@@ -909,6 +919,7 @@ public class Contacts.ContactEditor : ContactForm {
button.get_accessible ().set_name (_("Change avatar"));
button.image = this.avatar;
button.clicked.connect (on_avatar_button_clicked);
button.set_redraw_on_allocate (true);
this.container_grid.attach (button, 0, 0, 1, 3);
}
......
......@@ -20,6 +20,7 @@ using Folks;
using Gee;
const int PROFILE_SIZE = 128;
const int PROFILE_SMALL_SIZE = 95;
/**
* The ContactPage is the right pane. It consists of 3 possible pages:
......@@ -72,7 +73,6 @@ public class Contacts.ContactPane : Stack {
*/
public signal void display_name_changed (string new_display_name);
public ContactPane (Window parent_window, Store contacts_store) {
this.parent_window = parent_window;
this.store = contacts_store;
......
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