pixbufmanipulator: add avatar for temporary item

Replace the default avatar from 'R' to '?'
Change-Id: Ie8f9c295ad3081c1a9d5126153cd4c2122315f5f
Reviewed-by: Olivier Soldano <olivier.soldano@savoirfairelinux.com>
diff --git a/pixmaps/ic_search_black_48px.svg b/pixmaps/ic_search_black_48px.svg
new file mode 100644
index 0000000..d13f055
--- /dev/null
+++ b/pixmaps/ic_search_black_48px.svg
@@ -0,0 +1,4 @@
+<svg fill="#666" style="background-color: white;" height="48" viewBox="0 0 24 24" width="48" xmlns="http://www.w3.org/2000/svg">
+    <path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
+    <path d="M0 0h24v24H0z" fill="none"/>
+</svg>
diff --git a/pixmaps/pixmaps.gresource.xml b/pixmaps/pixmaps.gresource.xml
index 405408f..38671a5 100644
--- a/pixmaps/pixmaps.gresource.xml
+++ b/pixmaps/pixmaps.gresource.xml
@@ -29,7 +29,8 @@
   <file alias="add">add.svg</file>
   <file alias="reject">reject.svg</file>
 	<file alias="block">block.svg</file>
-	<file alias="invite">ic_person_add_black_24px.svg</file>
+  <file alias="invite">ic_person_add_black_24px.svg</file>
+	<file alias="temporary-item">ic_search_black_48px.svg</file>
 	<file alias="contact_requests_list_with_notification">ic_verified_user_black_24px_with_notification.svg</file>
   </gresource>
 </gresources>
diff --git a/src/native/pixbufmanipulator.cpp b/src/native/pixbufmanipulator.cpp
index bed4acb..a57d646 100644
--- a/src/native/pixbufmanipulator.cpp
+++ b/src/native/pixbufmanipulator.cpp
@@ -46,10 +46,27 @@
 }
 
 std::shared_ptr<GdkPixbuf>
+PixbufManipulator::temporaryItemAvatar() const
+{
+    GError *error = nullptr;
+    std::shared_ptr<GdkPixbuf> result(
+        gdk_pixbuf_new_from_resource("/cx/ring/RingGnome/temporary-item", &error),
+        g_object_unref
+    );
+
+    if (result == nullptr) {
+        g_debug("Could not load icon: %s", error->message);
+        g_clear_error(&error);
+        return generateAvatar("", "");
+    }
+    return result;
+}
+
+std::shared_ptr<GdkPixbuf>
 PixbufManipulator::generateAvatar(const ContactMethod* cm) const
 {
     auto cm_number = QString("0");
-    auto letter = QChar('R'); // R for ring
+    auto letter = QChar('?'); // R for ring
     if (cm) {
         auto hashName = cm->uri().userinfo();
         if (hashName.size() > 0) {
@@ -86,8 +103,13 @@
 {
     auto name = alias;
     std::transform(name.begin(), name.end(), name.begin(), ::toupper);
-    auto letter = name.length() > 0 ? name[0] : 'R';
-    auto color = uri.length() > 0 ? std::stoi(std::string(1, uri[0]), 0, 16) : 0;
+    auto letter = name.length() > 0 ? name[0] : '?';
+    auto color = 0;
+    try {
+        color = uri.length() > 0 ? std::stoi(std::string(1, uri[0]), 0, 16) : 0;
+    } catch (...) {
+        // uri[0] not in "0123456789abcdef"
+    }
 
     return std::shared_ptr<GdkPixbuf> {
         ring_draw_fallback_avatar(
@@ -246,7 +268,9 @@
         auto contactInfo = accountInfo.contactModel->getContact(contactUri);
         auto contactPhoto = contactInfo.profileInfo.avatar;
         auto bestName = contactInfo.profileInfo.alias.empty()? contactInfo.registeredName : contactInfo.profileInfo.alias;
-        if (contactInfo.profileInfo.type == lrc::api::profile::Type::SIP) {
+        if (contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY && contactInfo.profileInfo.uri.empty()) {
+            return QVariant::fromValue(scaleAndFrame(temporaryItemAvatar().get(), size, false, false));
+        } else if (contactInfo.profileInfo.type == lrc::api::profile::Type::SIP) {
             return QVariant::fromValue(scaleAndFrame(generateAvatar(bestName, "").get(), size, displayPresence, contactInfo.isPresent));
         } else if (!contactPhoto.empty()) {
             QByteArray byteArray(contactPhoto.c_str(), contactPhoto.length());
diff --git a/src/native/pixbufmanipulator.h b/src/native/pixbufmanipulator.h
index 858b054..3aa6a65 100644
--- a/src/native/pixbufmanipulator.h
+++ b/src/native/pixbufmanipulator.h
@@ -64,6 +64,7 @@
     QVariant   decorationRole(const Account* p) override;
 
 private:
+    std::shared_ptr<GdkPixbuf> temporaryItemAvatar() const;
     std::shared_ptr<GdkPixbuf> generateAvatar(const ContactMethod* cm) const;
     std::shared_ptr<GdkPixbuf> generateAvatar(const std::string& alias, const std::string& uri) const;