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

Commit

Permalink
Browse files Browse the repository at this point in the history
[libcontacts] Allow empty avatar to precede others
The method for clearing an avatar is to store a local avatar with
an empty URL, which takes precedence over existing avatars.
  • Loading branch information
matthewvogt committed Oct 6, 2013
1 parent 9f2a6e0 commit 14b0a44
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/seasidecache.cpp
Expand Up @@ -1023,35 +1023,41 @@ QString SeasideCache::generateDisplayLabelFromNonNameDetails(const QContact &con

static QUrl avatarUrlWithMetadata(const QContact &c, const QString &metadataFragment = QString())
{
QList<int> matchingIndices;
static const QString localMetadata(QString::fromLatin1("local"));
static const QString fileScheme(QString::fromLatin1("file"));

QUrl fallbackUrl;
QUrl remoteFallbackUrl;

QList<QContactAvatar> avatarDetails = c.details<QContactAvatar>();
for (int i = 0; i < avatarDetails.size(); ++i) {
const QContactAvatar &av(avatarDetails[i]);
QUrl avatarImageUrl = av.imageUrl();
if (avatarImageUrl.isEmpty()) {
// ignore empty avatars.

const QString metadata(av.value(QContactAvatar__FieldAvatarMetadata).toString());
if (!metadataFragment.isEmpty() && !metadata.startsWith(metadataFragment)) {
// this avatar doesn't match the metadata requirement. ignore it.
continue;
} else if (metadataFragment.isEmpty() && av.value(QContactAvatar__FieldAvatarMetadata).toString() == QString(QLatin1String("local"))) {
// prefer "local" avatars if no metadata filter is specified.
}

const QUrl avatarImageUrl = av.imageUrl();

if (metadata == localMetadata) {
// We have a local avatar record - use the image it specifies
return avatarImageUrl;
} else if (metadataFragment.isEmpty() || av.value(QContactAvatar__FieldAvatarMetadata).toString().startsWith(metadataFragment)) {
// prefer file system images if possible
if (!avatarImageUrl.scheme().isEmpty() && avatarImageUrl.scheme() != "file") {
// queue it as fallback.
matchingIndices.append(i);
} else {
// return this local file path image.
return avatarImageUrl;
}
} else {
// this avatar doesn't match the metadata requirement. ignore it.
continue;
// queue it as fallback - prefer local file system images over remote, if possible
const bool remote(!avatarImageUrl.scheme().isEmpty() && avatarImageUrl.scheme() != fileScheme);
QUrl &url(remote ? remoteFallbackUrl : fallbackUrl);
if (url.isEmpty()) {
url = avatarImageUrl;
}
}
}

// no local file path avatar image; use the first fallback.
if (matchingIndices.size()) {
return avatarDetails[matchingIndices[0]].imageUrl();
if (!fallbackUrl.isEmpty()) {
return fallbackUrl;
} else if (!remoteFallbackUrl.isEmpty()) {
return remoteFallbackUrl;
}

// no matching avatar image.
Expand Down

0 comments on commit 14b0a44

Please sign in to comment.