[gnome-contacts] Slight cleanup of avatar handling
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Slight cleanup of avatar handling
- Date: Thu, 18 Aug 2011 20:50:35 +0000 (UTC)
commit 4576f2aa119f7b26661e11d97c3706670fd70953
Author: Alexander Larsson <alexl redhat com>
Date: Thu Aug 18 22:50:11 2011 +0200
Slight cleanup of avatar handling
configure.ac | 1 +
src/Makefile.am | 2 +-
src/contacts-contact-pane.vala | 12 ++++----
src/contacts-contact.vala | 52 +++++++++++++++++++++------------------
src/contacts-view.vala | 2 +-
5 files changed, 37 insertions(+), 32 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index fbca619..f242b1c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,6 +31,7 @@ pkg_modules="gtk+-3.0
folks >= 0.6.0
folks-telepathy
libnotify
+ librobohash
"
PKG_CHECK_MODULES(CONTACTS, [$pkg_modules])
CONTACTS_PACKAGES="--pkg gtk+-3.0 --pkg gio-2.0 --pkg folks --pkg folks-telepathy --pkg libnotify"
diff --git a/src/Makefile.am b/src/Makefile.am
index 1e042d5..84f57f0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,7 +9,7 @@ AM_CPPFLAGS = \
$(NULL)
AM_VALAFLAGS = \
- --vapidir=$(srcdir)/../vapi --pkg config \
+ --vapidir=$(srcdir)/../vapi --pkg config --pkg librobohash \
@CONTACTS_PACKAGES@ \
$(NULL)
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index 7ad5b45..63f9411 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -193,7 +193,7 @@ public class Contacts.ContactFrame : Frame {
set_shadow_type (ShadowType.OUT);
}
- public void set_image (AvatarDetails? details) {
+ public void set_image (AvatarDetails? details, Contact? contact = null) {
pixbuf = null;
if (details != null &&
details.avatar != null) {
@@ -206,7 +206,7 @@ public class Contacts.ContactFrame : Frame {
}
if (pixbuf == null) {
- pixbuf = Contact.draw_fallback_avatar (size);
+ pixbuf = Contact.draw_fallback_avatar (size, contact);
}
}
@@ -276,7 +276,7 @@ public class Contacts.ContactPane : EventBox {
private signal void save_data ();
- private Widget create_image (AvatarDetails? details, int size) {
+ private Widget create_image (AvatarDetails? details, Contact? contact, int size) {
var image = new Image ();
image.set_size_request (size, size);
@@ -292,7 +292,7 @@ public class Contacts.ContactPane : EventBox {
}
if (pixbuf == null) {
- pixbuf = Contact.draw_fallback_avatar (size);
+ pixbuf = Contact.draw_fallback_avatar (size, contact);
}
if (pixbuf != null) {
@@ -589,7 +589,7 @@ public class Contacts.ContactPane : EventBox {
private void display_card (Contact contact) {
var image_frame = new ContactFrame (PROFILE_SIZE);
- image_frame.set_image (contact.individual);
+ image_frame.set_image (contact.individual, contact);
// Put the frame in a grid so its not expanded by the size-group
var ig = new Grid ();
ig.add (image_frame);
@@ -796,7 +796,7 @@ public class Contacts.ContactPane : EventBox {
button = new RadioButton.from_widget (button);
button.get_style_context ().add_class ("contact-button");
button.set_can_default (false);
- var image = create_image (p as AvatarDetails, 48);
+ var image = create_image (p as AvatarDetails, null, 48);
button.add (image);
button.set_mode (false);
personas.add (button);
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index eb51c48..34e3d75 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -112,17 +112,19 @@ public class Contacts.Contact : GLib.Object {
}
private ContactDataRef[] refs;
- static Gdk.Pixbuf fallback_avatar;
-
public Individual individual;
uint changed_id;
- private Gdk.Pixbuf? _avatar;
- public Gdk.Pixbuf avatar {
+ private Gdk.Pixbuf? _small_avatar;
+ public Gdk.Pixbuf small_avatar {
get {
- if (_avatar == null)
- _avatar = frame_icon (load_icon (individual.avatar));
- return _avatar;
+ if (_small_avatar == null) {
+ var pixbuf = load_icon (individual.avatar, 48);
+ if (pixbuf == null)
+ pixbuf = draw_fallback_avatar (48, this);
+ _small_avatar = frame_icon (pixbuf);
+ }
+ return _small_avatar;
}
}
@@ -193,10 +195,6 @@ public class Contacts.Contact : GLib.Object {
return i.get_data ("contact");
}
- static construct {
- fallback_avatar = draw_fallback_avatar (48);
- }
-
private void persona_notify_cb (ParamSpec pspec) {
queue_changed ();
}
@@ -582,7 +580,7 @@ public class Contacts.Contact : GLib.Object {
private void notify_cb (ParamSpec pspec) {
if (pspec.get_name () == "avatar")
- _avatar = null;
+ _small_avatar = null;
queue_changed ();
}
@@ -663,16 +661,17 @@ public class Contacts.Contact : GLib.Object {
}
// TODO: This should be async, but the vala bindings are broken (bug #649875)
- private Gdk.Pixbuf load_icon (LoadableIcon ?file) {
- Gdk.Pixbuf? res = fallback_avatar;
+ private Gdk.Pixbuf load_icon (LoadableIcon ?file, int size) {
+ Gdk.Pixbuf? res = null;
if (file != null) {
try {
Cancellable c = new Cancellable ();
- var stream = file.load (48, null, c);
- res = new Gdk.Pixbuf.from_stream_at_scale (stream, 48, 48, true, c);
+ var stream = file.load (size, null, c);
+ res = new Gdk.Pixbuf.from_stream_at_scale (stream, size, size, true, c);
} catch (Error e) {
}
}
+
return res;
}
@@ -749,20 +748,25 @@ public class Contacts.Contact : GLib.Object {
return Gdk.pixbuf_get_from_surface (cst, 0, 0, 52, 52);
}
- public static Gdk.Pixbuf draw_fallback_avatar (int size) {
- var cst = new Cairo.ImageSurface (Cairo.Format.ARGB32, size, size);
- var cr = new Cairo.Context (cst);
+ private static Gdk.Pixbuf? fallback_pixbuf_48;
+ public static Gdk.Pixbuf draw_fallback_avatar (int size, Contact? contact) {
+ if (size == 48 && fallback_pixbuf_48 != null)
+ return fallback_pixbuf_48;
+ Gdk.Pixbuf pixbuf = null;
try {
var icon_info = IconTheme.get_default ().lookup_icon ("avatar-default", size, IconLookupFlags.GENERIC_FALLBACK);
- var image = icon_info.load_icon ();
- if (image != null) {
- Gdk.cairo_set_source_pixbuf (cr, image, 0, 0);
- cr.paint();
- }
+ pixbuf = icon_info.load_icon ();
} catch {
}
+ if (size == 48)
+ fallback_pixbuf_48 = pixbuf;
+
+ if (pixbuf != null)
+ return pixbuf;
+
+ var cst = new Cairo.ImageSurface (Cairo.Format.ARGB32, size, size);
return Gdk.pixbuf_get_from_surface (cst, 0, 0, size, size);
}
diff --git a/src/contacts-view.vala b/src/contacts-view.vala
index e12314f..7503eef 100644
--- a/src/contacts-view.vala
+++ b/src/contacts-view.vala
@@ -280,7 +280,7 @@ public class Contacts.ViewWidget : TreeView {
model.get (iter, 0, out contact);
- cell.set ("pixbuf", contact.avatar);
+ cell.set ("pixbuf", contact.small_avatar);
});
append_column (column);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]