[gnome-maps] placeListRow: Use HdyAvatar for contact places



commit 6e38a8a74097f13b9cb2b201b7d2d5bab934f8d9
Author: James Westman <james flyingpimonster net>
Date:   Tue Sep 29 12:42:13 2020 -0500

    placeListRow: Use HdyAvatar for contact places
    
    Looks nicer and matches the new contact bubbles.

 data/ui/place-list-row.ui | 20 +++++++++++++++++---
 src/mapBubble.js          | 19 +------------------
 src/placeListRow.js       | 21 ++++++++++++++++++++-
 src/utils.js              | 16 ++++++++++++++++
 4 files changed, 54 insertions(+), 22 deletions(-)
---
diff --git a/data/ui/place-list-row.ui b/data/ui/place-list-row.ui
index f3d2bf09..9164f52c 100644
--- a/data/ui/place-list-row.ui
+++ b/data/ui/place-list-row.ui
@@ -12,13 +12,27 @@
         <property name="row-homogeneous">True</property>
         <property name="margin">5</property>
         <child>
-          <object class="GtkImage" id="icon">
+          <object class="GtkStack" id="iconStack">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="halign">start</property>
             <property name="valign">center</property>
-            <property name="margin_end">10</property>
-            <property name="pixel_size">32</property>
+            <property name="margin_end">12</property>
+            <child>
+              <object class="GtkImage" id="icon">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="pixel_size">32</property>
+              </object>
+            </child>
+            <child>
+              <object class="HdyAvatar" id="contactAvatar">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="show_initials">True</property>
+                <property name="size">32</property>
+              </object>
+            </child>
           </object>
           <packing>
             <property name="left_attach">0</property>
diff --git a/src/mapBubble.js b/src/mapBubble.js
index de41238c..5dfad9cf 100644
--- a/src/mapBubble.js
+++ b/src/mapBubble.js
@@ -124,7 +124,7 @@ class MapBubble extends Gtk.Popover {
         if (this.place instanceof ContactPlace.ContactPlace) {
             this._contactAvatar.visible = true;
             Utils.load_icon(this.place.icon, 32, (pixbuf) => {
-                this._contactAvatar.set_image_load_func(this._avatarImageLoadFunc.bind(this, pixbuf));
+                this._contactAvatar.set_image_load_func((size) => Utils.loadAvatar(pixbuf, size));
             });
         }
 
@@ -287,21 +287,4 @@ class MapBubble extends Gtk.Popover {
             }
         });
     }
-
-    // Loads the HdyAvatar image for contact places
-    _avatarImageLoadFunc(pixbuf, size) {
-        let width = pixbuf.get_width();
-        let height = pixbuf.get_height();
-        let croppedThumbnail;
-
-        if (width > height) {
-            let x = (width - height) / 2;
-            croppedThumbnail = pixbuf.new_subpixbuf(x, 0, height, height);
-        } else {
-            let y = (height - width) / 2;
-            croppedThumbnail = pixbuf.new_subpixbuf(0, y, width, width);
-        }
-
-        return croppedThumbnail.scale_simple(size, size, GdkPixbuf.InterpType.BILINEAR);
-    }
 });
diff --git a/src/placeListRow.js b/src/placeListRow.js
index 68ed931c..abb40b7d 100644
--- a/src/placeListRow.js
+++ b/src/placeListRow.js
@@ -21,6 +21,7 @@ const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
 
+const ContactPlace = imports.contactPlace;
 const PlaceFormatter = imports.placeFormatter;
 const PlaceStore = imports.placeStore;
 const Utils = imports.utils;
@@ -30,6 +31,8 @@ var ROW_HEIGHT = 55;
 var PlaceListRow = GObject.registerClass({
     Template: 'resource:///org/gnome/Maps/ui/place-list-row.ui',
     InternalChildren: [ 'icon',
+                        'iconStack',
+                        'contactAvatar',
                         'name',
                         'details',
                         'typeIcon' ],
@@ -58,7 +61,23 @@ var PlaceListRow = GObject.registerClass({
 
         this._name.label = this._boldMatch(markup, searchString);
         this._details.label = GLib.markup_escape_text(formatter.getDetailsString(),-1);
-        this._icon.gicon = place.icon;
+
+        if (place instanceof ContactPlace.ContactPlace) {
+            this._iconStack.set_visible_child(this._contactAvatar);
+
+            this._contactAvatar.text = formatter.title;
+
+            if (place.icon) {
+                Utils.load_icon(place.icon, 32, (pixbuf) => {
+                    this._contactAvatar.set_image_load_func((size) => Utils.loadAvatar(pixbuf, size));
+                });
+            } else {
+                this._contactAvatar.set_image_load_func(null);
+            }
+        } else if (place.icon) {
+            this._iconStack.set_visible_child(this._icon);
+            this._icon.gicon = place.icon;
+        }
 
         if (type === PlaceStore.PlaceType.RECENT ||
             type === PlaceStore.PlaceType.RECENT_ROUTE)
diff --git a/src/utils.js b/src/utils.js
index fd4a2266..8ab7b263 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -254,6 +254,22 @@ function getAccuracyDescription(accuracy) {
     }
 }
 
+function loadAvatar(pixbuf, size) {
+    let width = pixbuf.get_width();
+    let height = pixbuf.get_height();
+    let croppedThumbnail;
+
+    if (width > height) {
+        let x = (width - height) / 2;
+        croppedThumbnail = pixbuf.new_subpixbuf(x, 0, height, height);
+    } else {
+        let y = (height - width) / 2;
+        croppedThumbnail = pixbuf.new_subpixbuf(0, y, width, width);
+    }
+
+    return croppedThumbnail.scale_simple(size, size, GdkPixbuf.InterpType.BILINEAR);
+}
+
 function load_icon(icon, size, loadCompleteCallback) {
     if (icon instanceof Gio.FileIcon || icon instanceof Gio.BytesIcon) {
         _load_icon(icon, loadCompleteCallback);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]