Skip to content
Snippets Groups Projects
Commit 3587e495 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

drawing: fix SIP avatars and color

+ Use algorithm described here:
https://git.ring.cx/savoirfairelinux/ring-project/wikis/Identifiers


+ Fix purple color code
+ Move helpers to public to be available anywhere. No reason to make
it private.

Change-Id: I4f2814958970da275f8e1a815eefb536c5935cec
Reviewed-by: default avatarHugo Lefeuvre <hugo.lefeuvre@savoirfairelinux.com>
parent e0f0aaf7
No related branches found
No related tags found
No related merge requests found
...@@ -102,15 +102,15 @@ PixbufManipulator::generateAvatar(const ContactMethod* cm) const ...@@ -102,15 +102,15 @@ PixbufManipulator::generateAvatar(const ContactMethod* cm) const
std::shared_ptr<GdkPixbuf> std::shared_ptr<GdkPixbuf>
PixbufManipulator::generateAvatar(const std::string& alias, const std::string& uri) const PixbufManipulator::generateAvatar(const std::string& alias, const std::string& uri) const
{ {
auto name = alias;
std::string letter = {}; std::string letter = {};
if (!name.empty()) if (!alias.empty()) {
letter = QString(QString(name.c_str()).toUpper().at(0)).toStdString(); // Use QString for special characters like ø for example
auto color = 0; letter = QString(QString(alias.c_str()).toUpper().at(0)).toStdString();
try { }
color = uri.length() > 0 ? std::stoi(std::string(1, uri[0]), 0, 16) : 0; auto color = 10; // 10 = default color (light grey)
} catch (...) { if (uri.length() > 0) {
// uri[0] not in "0123456789abcdef" auto* md5 = g_compute_checksum_for_string(G_CHECKSUM_MD5, uri.c_str(), -1);
color = std::string("0123456789abcdef").find(md5[0]);
} }
return std::shared_ptr<GdkPixbuf> { return std::shared_ptr<GdkPixbuf> {
...@@ -281,16 +281,18 @@ PixbufManipulator::conversationPhoto(const lrc::api::conversation::Info& convers ...@@ -281,16 +281,18 @@ PixbufManipulator::conversationPhoto(const lrc::api::conversation::Info& convers
auto contactPhoto = contactInfo.profileInfo.avatar; auto contactPhoto = contactInfo.profileInfo.avatar;
auto bestName = contactInfo.profileInfo.alias.empty()? contactInfo.registeredName : contactInfo.profileInfo.alias; auto bestName = contactInfo.profileInfo.alias.empty()? contactInfo.registeredName : contactInfo.profileInfo.alias;
auto unreadMessages = conversationInfo.unreadMessages; auto unreadMessages = conversationInfo.unreadMessages;
if (contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY && contactInfo.profileInfo.uri.empty()) { if (accountInfo.profileInfo.type == lrc::api::profile::Type::SIP && contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY) {
return QVariant::fromValue(scaleAndFrame(generateAvatar("", "").get(), size, displayInformation, contactInfo.isPresent));
} else if (accountInfo.profileInfo.type == lrc::api::profile::Type::SIP) {
return QVariant::fromValue(scaleAndFrame(generateAvatar("", "sip:" + contactInfo.profileInfo.uri).get(), size, displayInformation, contactInfo.isPresent));
} else if (contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY && contactInfo.profileInfo.uri.empty()) {
return QVariant::fromValue(scaleAndFrame(temporaryItemAvatar().get(), size, false, false, unreadMessages)); return QVariant::fromValue(scaleAndFrame(temporaryItemAvatar().get(), size, false, false, unreadMessages));
} else if (contactInfo.profileInfo.type == lrc::api::profile::Type::SIP) {
return QVariant::fromValue(scaleAndFrame(generateAvatar(bestName, "").get(), size, displayInformation, contactInfo.isPresent));
} else if (!contactPhoto.empty()) { } else if (!contactPhoto.empty()) {
QByteArray byteArray(contactPhoto.c_str(), contactPhoto.length()); QByteArray byteArray(contactPhoto.c_str(), contactPhoto.length());
QVariant photo = personPhoto(byteArray); QVariant photo = personPhoto(byteArray);
return QVariant::fromValue(scaleAndFrame(photo.value<std::shared_ptr<GdkPixbuf>>().get(), size, displayInformation, contactInfo.isPresent, unreadMessages)); return QVariant::fromValue(scaleAndFrame(photo.value<std::shared_ptr<GdkPixbuf>>().get(), size, displayInformation, contactInfo.isPresent, unreadMessages));
} else { } else {
return QVariant::fromValue(scaleAndFrame(generateAvatar(bestName, contactInfo.profileInfo.uri).get(), size, displayInformation, contactInfo.isPresent, unreadMessages)); return QVariant::fromValue(scaleAndFrame(generateAvatar(bestName, "ring:" + contactInfo.profileInfo.uri).get(), size, displayInformation, contactInfo.isPresent, unreadMessages));
} }
} catch (...) {} } catch (...) {}
} }
......
...@@ -63,12 +63,14 @@ public: ...@@ -63,12 +63,14 @@ public:
const lrc::api::account::Info& accountInfo) override; const lrc::api::account::Info& accountInfo) override;
QVariant decorationRole(const Account* p) override; QVariant decorationRole(const Account* p) override;
private: // Helpers
std::shared_ptr<GdkPixbuf> temporaryItemAvatar() const; std::shared_ptr<GdkPixbuf> temporaryItemAvatar() const;
std::shared_ptr<GdkPixbuf> generateAvatar(const ContactMethod* cm) const; std::shared_ptr<GdkPixbuf> generateAvatar(const ContactMethod* cm) const;
std::shared_ptr<GdkPixbuf> generateAvatar(const std::string& alias, const std::string& uri) const; std::shared_ptr<GdkPixbuf> generateAvatar(const std::string& alias, const std::string& uri) const;
std::shared_ptr<GdkPixbuf> scaleAndFrame(const GdkPixbuf *photo, const QSize& size, bool displayInformation = false, bool is_present = false, uint unreadMessages = 0); std::shared_ptr<GdkPixbuf> scaleAndFrame(const GdkPixbuf *photo, const QSize& size, bool displayInformation = false, bool is_present = false, uint unreadMessages = 0);
private:
std::shared_ptr<GdkPixbuf> conferenceAvatar_; std::shared_ptr<GdkPixbuf> conferenceAvatar_;
}; };
......
...@@ -33,7 +33,7 @@ static constexpr GdkRGBA PRESENCE_ABSENT_BACKGROUND = {0.984, 0.282, 0.278, ...@@ -33,7 +33,7 @@ static constexpr GdkRGBA PRESENCE_ABSENT_BACKGROUND = {0.984, 0.282, 0.278,
static constexpr GdkRGBA COLOR_PALETTE[] = {{0.956862, 0.262745, 0.211764, 1.0}, // red 244, green 67, blue 54, 1 (red) static constexpr GdkRGBA COLOR_PALETTE[] = {{0.956862, 0.262745, 0.211764, 1.0}, // red 244, green 67, blue 54, 1 (red)
{0.913725, 0.117647, 0.388235, 1.0}, // red 233, green 30, blue 99, 1 (pink) {0.913725, 0.117647, 0.388235, 1.0}, // red 233, green 30, blue 99, 1 (pink)
{0.611764, 0.152941, 0.690196, 1.0}, // red 156, green 39, blue 176, 1 (purple) {0.611764, 0.152941, 0.690196, 1.0}, // red 156, green 39, blue 176, 1 (purple)
{0.956862, 0.262745, 0.211764, 1.0}, // red 244, green 67, blue 54, 1 (deep purple) {0.270588, 0.152941, 0.627450, 1.0}, // red 69, green 39, blue 160, 1 (deep purple)
{0.403921, 0.227450, 0.717647, 1.0}, // red 103, green 58, blue 183, 1 (indigo) {0.403921, 0.227450, 0.717647, 1.0}, // red 103, green 58, blue 183, 1 (indigo)
{0.247058, 0.317647, 0.211764, 1.0}, // red 63, green 81, blue 54, 1 (blue) {0.247058, 0.317647, 0.211764, 1.0}, // red 63, green 81, blue 54, 1 (blue)
{0, 0.737254, 0.831372, 1.0}, // red 0, green 188, blue 212, 1 (cyan) {0, 0.737254, 0.831372, 1.0}, // red 0, green 188, blue 212, 1 (cyan)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment