diff --git a/src/View/Contact.vala b/src/View/Contact.vala index ab2a694..0f2eac0 100644 --- a/src/View/Contact.vala +++ b/src/View/Contact.vala @@ -52,11 +52,8 @@ namespace View { private signal void has_icon (bool has); private signal void make_bottom_section_unavailable (bool not_available); - private Granite.Widgets.Avatar icon = - new Granite.Widgets.Avatar.from_file ( - Constants.DATADIR + "/avatars/64/contacts-avatar-default.svg", 64 - ); - private bool icon_is_set = false; + public Gdk.Pixbuf? default_image; + public Image icon_image { get; private set; default = new Image (); } private EditableTitle name_label = new EditableTitle (""); @@ -132,8 +129,11 @@ namespace View { ); if (handler.icon != null) { - icon.pixbuf = handler.icon; + icon_image.pixbuf = handler.icon; has_icon (true); + } else { + icon_image.pixbuf = default_image; + has_icon (false); } handler.contact_error.connect ((contact_error) => show_error (contact_error.message)); @@ -148,15 +148,23 @@ namespace View { construct { hscrollbar_policy = Gtk.PolicyType.NEVER; + var icon_theme = IconTheme.get_default (); + try { + default_image = icon_theme.load_icon ("avatar-default", 64, 0); + } + catch (Error err) { + error (err.message); + } + icon_image.pixbuf = default_image; + var icon_button = new Gtk.Button (); icon_button.set_tooltip_text (_("Change the icon")); icon_button.get_style_context ().add_class ("flat"); - icon_button.add (icon); + icon_button.add (icon_image); var popup = new IconPopup (icon_button); has_icon.connect ((has) => { popup.can_delete = has; - icon_is_set = has; }); popup.change_image.connect (() => { @@ -166,6 +174,11 @@ namespace View { print ("You canceled the operation\n"); } }); + popup.remove_image.connect (() => { + handler.icon = null; + icon_image.pixbuf = default_image; + has_icon (false); + }); var title_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12); title_box.pack_start (icon_button, false, false, 0); @@ -284,7 +297,7 @@ namespace View { public void set_image_path (string path) { try { handler.icon = new Gdk.Pixbuf.from_file_at_scale (path, 64, 64, true); - icon.pixbuf = handler.icon; + icon_image.pixbuf = handler.icon; has_icon (true); } catch (Error e) { error (e.message); diff --git a/src/View/Widgets/SidebarRow.vala b/src/View/Widgets/SidebarRow.vala index cc032f0..c2e84e0 100644 --- a/src/View/Widgets/SidebarRow.vala +++ b/src/View/Widgets/SidebarRow.vala @@ -47,11 +47,8 @@ using ViewModel; namespace View.Widgets { private class SidebarRow : Gtk.ListBoxRow { - public Avatar display_widget { get; private set; - default = new Granite.Widgets.Avatar.from_file ( - Constants.DATADIR + "/avatars/32/contacts-avatar-default.svg", 32 - ); - } + public Gdk.Pixbuf? default_image; + public Image icon_image { get; private set; default = new Image (); } public string? header { get; set; } @@ -98,7 +95,16 @@ namespace View.Widgets { var overlay = new Gtk.Overlay (); overlay.width_request = 38; - overlay.add (display_widget); + overlay.add (icon_image); + + var icon_theme = IconTheme.get_default (); + try { + default_image = icon_theme.load_icon ("avatar-default", 32, 0); + } + catch (Error err) { + error (err.message); + } + icon_image.pixbuf = default_image; var grid = new Gtk.Grid (); grid.margin = 6; @@ -118,12 +124,17 @@ namespace View.Widgets { public void on_info_changed () { this.title = handler.name; - if (handler.icon != null) - this.display_widget.pixbuf = handler.icon.scale_simple (32, 32, Gdk.InterpType.HYPER); + if (handler.icon != null) { + this.icon_image.pixbuf = handler.icon.scale_simple (32, 32, Gdk.InterpType.HYPER); + } else { + this.icon_image.pixbuf = default_image; + } if (handler.phones != null && handler.phones.length () != 0) { var phone = handler.phones.nth_data (0).data; this.status = phone.locale_to_utf8 (-1, null, null); + } else { + this.status = ""; } } } diff --git a/src/ViewModel/ContactHandler.vala b/src/ViewModel/ContactHandler.vala index 08041e8..5f4b8ae 100644 --- a/src/ViewModel/ContactHandler.vala +++ b/src/ViewModel/ContactHandler.vala @@ -62,24 +62,25 @@ namespace ViewModel { } } - public Pixbuf icon { + public Pixbuf? icon { get { return contact.icon; } set { var image = value; - if (image.width < image.height) { - int y = image.height / 2 - image.width / 2; - image = new Gdk.Pixbuf.subpixbuf (image, 0, y, image.width, image.width); - } else if (image.width > image.height) { - int x = image.width / 2 - image.height / 2; - image = new Gdk.Pixbuf.subpixbuf (image, x, 0, image.height, image.height); + if (image != null) { + if (image.width < image.height) { + int y = image.height / 2 - image.width / 2; + image = new Gdk.Pixbuf.subpixbuf (image, 0, y, image.width, image.width); + } else if (image.width > image.height) { + int x = image.width / 2 - image.height / 2; + image = new Gdk.Pixbuf.subpixbuf (image, x, 0, image.height, image.height); + } + if (image.width != 64) + image = image.scale_simple (64, 64, Gdk.InterpType.HYPER); } - if (image.width != 64) - image = image.scale_simple (64, 64, Gdk.InterpType.HYPER); - contact.icon = image; changed (); }