From d93af5e7bb0f665161b21e008fd76e45907ecd94 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 5 Nov 2013 14:00:34 +1000 Subject: [PATCH] [libcontacts] Improve utility of avatarUrl role. Previously, no metadata preference was built into the default avatarUrl role logic. This commit changes the filteredAvatarUrl function to prefer local picture avatars over cover-type avatar images. --- src/seasidecache.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/seasidecache.cpp b/src/seasidecache.cpp index 2f5b45b..dbf295a 100644 --- a/src/seasidecache.cpp +++ b/src/seasidecache.cpp @@ -1151,11 +1151,12 @@ QString SeasideCache::generateDisplayLabelFromNonNameDetails(const QContact &con static bool avatarUrlWithMetadata(const QContact &contact, QUrl &matchingUrl, const QString &metadataFragment = QString()) { + static const QString coverMetadata(QString::fromLatin1("cover")); static const QString localMetadata(QString::fromLatin1("local")); static const QString fileScheme(QString::fromLatin1("file")); + int fallbackScore = 0; QUrl fallbackUrl; - QUrl remoteFallbackUrl; QList avatarDetails = contact.details(); for (int i = 0; i < avatarDetails.size(); ++i) { @@ -1174,11 +1175,18 @@ static bool avatarUrlWithMetadata(const QContact &contact, QUrl &matchingUrl, co matchingUrl = avatarImageUrl; return true; } else { - // queue it as fallback - prefer local file system images over remote, if possible + // queue it as fallback if its score is better than the best fallback seen so far. + // prefer local file system images over remote urls, and prefer normal avatars + // over "cover" (background image) type avatars. const bool remote(!avatarImageUrl.scheme().isEmpty() && avatarImageUrl.scheme() != fileScheme); - QUrl &url(remote ? remoteFallbackUrl : fallbackUrl); - if (url.isEmpty()) { - url = avatarImageUrl; + int score = remote ? 3 : 4; + if (metadata == coverMetadata) { + score -= 2; + } + + if (score > fallbackScore) { + fallbackUrl = avatarImageUrl; + fallbackScore = score; } } } @@ -1186,9 +1194,6 @@ static bool avatarUrlWithMetadata(const QContact &contact, QUrl &matchingUrl, co if (!fallbackUrl.isEmpty()) { matchingUrl = fallbackUrl; return true; - } else if (!remoteFallbackUrl.isEmpty()) { - matchingUrl = remoteFallbackUrl; - return true; } // no matching avatar image.