Commit fbcb2299 authored by Sébastien Blin's avatar Sébastien Blin Committed by Olivier SOLDANO

pixbufmanipulator: add avatar for temporary item

Replace the default avatar from 'R' to '?'
Change-Id: Ie8f9c295ad3081c1a9d5126153cd4c2122315f5f
Reviewed-by: default avatarOlivier Soldano <olivier.soldano@savoirfairelinux.com>
parent f717def1
<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>
......@@ -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>
......@@ -45,11 +45,28 @@ PixbufManipulator::PixbufManipulator()
{
}
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 @@ PixbufManipulator::generateAvatar(const std::string& alias, const std::string& u
{
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 @@ PixbufManipulator::conversationPhoto(const lrc::api::conversation::Info& convers
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());
......
......@@ -64,6 +64,7 @@ public:
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;
......
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