Commit 98d9c8ec authored by chriadam's avatar chriadam

[libcontacts] Add API to support PHOTO processing in client code

This commit adds API to allow clients to use libcontacts' standard
implementation of processPhoto() for handling PHOTO vCard properties
in their own vCard handling implementations.
parent 5b5c00d3
......@@ -44,7 +44,7 @@
namespace {
void processPhoto(const QVersitProperty &property, bool *alreadyProcessed, QList<QContactDetail> * updatedDetails)
QContactAvatar avatarFromPhotoProperty(const QVersitProperty &property)
{
// if the property is a PHOTO property, store the data to disk
// and then create an avatar detail which points to it.
......@@ -61,11 +61,9 @@ void processPhoto(const QVersitProperty &property, bool *alreadyProcessed, QList
if (!url.scheme().isEmpty() && !url.isLocalFile()) {
QContactAvatar newAvatar;
newAvatar.setImageUrl(url);
updatedDetails->append(newAvatar);
// we have successfully processed this PHOTO property.
*alreadyProcessed = true;
return;
return newAvatar;
}
}
......@@ -83,7 +81,7 @@ void processPhoto(const QVersitProperty &property, bool *alreadyProcessed, QList
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly)) {
qWarning() << "Unable to process photo data as file:" << path;
return;
return QContactAvatar();
} else {
photoData = file.readAll();
}
......@@ -95,7 +93,7 @@ void processPhoto(const QVersitProperty &property, bool *alreadyProcessed, QList
photoData = property.variantValue().toByteArray();
if (photoData.isEmpty()) {
qWarning() << "Failed to extract avatar data from vCard PHOTO property";
return;
return QContactAvatar();
}
}
......@@ -103,7 +101,7 @@ void processPhoto(const QVersitProperty &property, bool *alreadyProcessed, QList
bool loaded = img.loadFromData(photoData);
if (!loaded) {
qWarning() << "Failed to load avatar image from vCard PHOTO data";
return;
return QContactAvatar();
}
// We will save the avatar image to disk in the system's data location
......@@ -115,7 +113,7 @@ void processPhoto(const QVersitProperty &property, bool *alreadyProcessed, QList
QDir photoDir;
if (!photoDir.mkpath(photoDirPath)) {
qWarning() << "Failed to create avatar image directory when loading avatar image from vCard PHOTO data";
return;
return QContactAvatar();
}
// construct the filename of the new avatar image.
......@@ -126,7 +124,7 @@ void processPhoto(const QVersitProperty &property, bool *alreadyProcessed, QList
bool saved = img.save(photoFilePath);
if (!saved) {
qWarning() << "Failed to save avatar image from vCard PHOTO data to" << photoFilePath;
return;
return QContactAvatar();
}
qWarning() << "Successfully saved avatar image from vCard PHOTO data to" << photoFilePath;
......@@ -134,10 +132,18 @@ void processPhoto(const QVersitProperty &property, bool *alreadyProcessed, QList
// save the avatar detail - TODO: mark the avatar as "owned by the contact" (remove on delete)
QContactAvatar newAvatar;
newAvatar.setImageUrl(QUrl::fromLocalFile(photoFilePath));
updatedDetails->append(newAvatar);
// we have successfully processed this PHOTO property.
*alreadyProcessed = true;
return newAvatar;
}
void processPhoto(const QVersitProperty &property, bool *alreadyProcessed, QList<QContactDetail> * updatedDetails)
{
QContactAvatar newAvatar = avatarFromPhotoProperty(property);
if (!newAvatar.isEmpty()) {
updatedDetails->append(newAvatar);
*alreadyProcessed = true;
}
}
void processOnlineAccount(const QVersitProperty &property, bool *alreadyProcessed, QList<QContactDetail> * updatedDetails)
......@@ -286,3 +292,7 @@ void SeasidePropertyHandler::detailProcessed(const QContact &, const QContactDet
}
}
QContactAvatar SeasidePropertyHandler::avatarFromPhotoProperty(const QVersitProperty &property)
{
return ::avatarFromPhotoProperty(property);
}
......@@ -46,6 +46,8 @@
#include <QVersitDocument>
#include <QVersitProperty>
#include <QContactAvatar>
QTCONTACTS_USE_NAMESPACE
QTVERSIT_USE_NAMESPACE
......@@ -80,6 +82,8 @@ public:
void detailProcessed(const QContact &, const QContactDetail &detail,
const QVersitDocument &, QSet<int> * processedFields, QList<QVersitProperty> * toBeRemoved, QList<QVersitProperty> * toBeAdded);
static QContactAvatar avatarFromPhotoProperty(const QVersitProperty &property);
private:
SeasidePropertyHandlerPrivate *priv;
};
......
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