Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
[libcontacts] Improve utility of avatarUrl role.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Chris Adams committed Nov 5, 2013
1 parent 9ca9394 commit d93af5e
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/seasidecache.cpp
Expand Up @@ -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<QContactAvatar> avatarDetails = contact.details<QContactAvatar>();
for (int i = 0; i < avatarDetails.size(); ++i) {
Expand All @@ -1174,21 +1175,25 @@ 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;
}
}
}

if (!fallbackUrl.isEmpty()) {
matchingUrl = fallbackUrl;
return true;
} else if (!remoteFallbackUrl.isEmpty()) {
matchingUrl = remoteFallbackUrl;
return true;
}

// no matching avatar image.
Expand Down

0 comments on commit d93af5e

Please sign in to comment.