Commit c1c2e0a9 authored by mvogt's avatar mvogt

[libcontacts] Allow online accounts to be imported for demo purposes

Although they won't work correctly, allow IM accounts to be imported.
parent 1ed988d6
......@@ -32,7 +32,7 @@
#include "seasideimport.h"
#include "seasidecache.h"
#include "seasidephotohandler.h"
#include "seasidepropertyhandler.h"
#include <QContactDetailFilter>
#include <QContactFetchHint>
......@@ -312,9 +312,9 @@ QList<QContact> SeasideImport::buildImportContacts(const QList<QVersitDocument>
*updatedCount = 0;
// Read the contacts from the import details
SeasidePhotoHandler photoHandler;
SeasidePropertyHandler propertyHandler;
QVersitContactImporter importer;
importer.setPropertyHandler(&photoHandler);
importer.setPropertyHandler(&propertyHandler);
importer.importDocuments(details);
QList<QContact> importedContacts(importer.contacts());
......
......@@ -30,36 +30,40 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/
#include "seasidephotohandler.h"
#include "seasidepropertyhandler.h"
#ifndef QT_VERSION_5
#include <QDesktopServices>
#include <QContactThumbnail>
#endif
#include <QContactAvatar>
#include <QContactOnlineAccount>
#include <QContactPresence>
#include <QCryptographicHash>
#include <QDir>
#include <QImage>
SeasidePhotoHandler::SeasidePhotoHandler()
#include <qtcontacts-extensions.h>
SeasidePropertyHandler::SeasidePropertyHandler()
{
}
SeasidePhotoHandler::~SeasidePhotoHandler()
SeasidePropertyHandler::~SeasidePropertyHandler()
{
}
void SeasidePhotoHandler::documentProcessed(const QVersitDocument &, QContact *)
void SeasidePropertyHandler::documentProcessed(const QVersitDocument &, QContact *)
{
// do nothing, have no state to clean.
}
void SeasidePhotoHandler::propertyProcessed(const QVersitDocument &, const QVersitProperty &property, const QContact &, bool *alreadyProcessed, QList<QContactDetail> * updatedDetails)
namespace {
void processPhoto(const QVersitProperty &property, bool *alreadyProcessed, QList<QContactDetail> * updatedDetails)
{
// if the property is a PHOTO property, store the data to disk
// and then create an avatar detail which points to it.
if (property.name().toLower() != QLatin1String("photo"))
return;
#ifndef QT_VERSION_5
// The Qt4 / QtMobility version has QContactThumbnail support.
......@@ -165,3 +169,50 @@ void SeasidePhotoHandler::propertyProcessed(const QVersitDocument &, const QVers
*alreadyProcessed = true;
}
void processOnlineAccount(const QVersitProperty &property, bool *alreadyProcessed, QList<QContactDetail> * updatedDetails)
{
// Create an online account instance for demo purposes; it will not be connected
// to a registered telepathy account, so it won't actually be able to converse
// Try to interpret the data as a stringlist
const QString detail(property.variantValue().toString());
// The format is: URI/path/display-name/icon-path/service-provider/service-provider-display-name
const QStringList details(detail.split(QLatin1Char(';'), QString::KeepEmptyParts));
if (details.count() == 6) {
QContactOnlineAccount qcoa;
qcoa.setValue(QContactOnlineAccount::FieldAccountUri, details.at(0));
qcoa.setValue(QContactOnlineAccount__FieldAccountPath, details.at(1));
qcoa.setValue(QContactOnlineAccount__FieldAccountDisplayName, details.at(2));
qcoa.setValue(QContactOnlineAccount__FieldAccountIconPath, details.at(3));
qcoa.setValue(QContactOnlineAccount::FieldServiceProvider, details.at(4));
qcoa.setValue(QContactOnlineAccount__FieldServiceProviderDisplayName, details.at(5));
qcoa.setDetailUri(QString::fromLatin1("%1:%2").arg(details.at(1)).arg(details.at(0)));
updatedDetails->append(qcoa);
// Since it is a demo account, give it a random presence state
const int state = (qrand() % 4);
QContactPresence presence;
presence.setPresenceState(state == 3 ? QContactPresence::PresenceBusy : (state == 2 ? QContactPresence::PresenceAway : QContactPresence::PresenceAvailable));
presence.setLinkedDetailUris(QStringList() << qcoa.detailUri());
updatedDetails->append(presence);
*alreadyProcessed = true;
} else {
qWarning() << "Invalid online account details:" << details;
}
}
}
void SeasidePropertyHandler::propertyProcessed(const QVersitDocument &, const QVersitProperty &property, const QContact &, bool *alreadyProcessed, QList<QContactDetail> * updatedDetails)
{
if (property.name().toLower() == QLatin1String("photo")) {
processPhoto(property, alreadyProcessed, updatedDetails);
} else if (property.name().toLower() == QLatin1String("x-nemomobile-onlineaccount-demo")) {
processOnlineAccount(property, alreadyProcessed, updatedDetails);
}
}
......@@ -30,8 +30,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/
#ifndef PHOTOHANDLER_H
#define PHOTOHANDLER_H
#ifndef PROPERTYHANDLER_H
#define PROPERTYHANDLER_H
#include "contactcacheexport.h"
......@@ -58,18 +58,21 @@ QTM_USE_NAMESPACE
#endif
/*
SeasidePhotoHandler
SeasidePropertyHandler
Some backends don't support saving PHOTO data directly.
Instead, the PHOTO data needs to be extracted, saved to
a file, and then the path to the file needs to be saved
to the backend as a contact avatar url detail.
Also support the X-NEMOMOBILE-ONLINEACCOUNT-DEMO property
for loading demo online account data.
*/
class CONTACTCACHE_EXPORT SeasidePhotoHandler : public QVersitContactImporterPropertyHandlerV2
class CONTACTCACHE_EXPORT SeasidePropertyHandler : public QVersitContactImporterPropertyHandlerV2
{
public:
SeasidePhotoHandler();
~SeasidePhotoHandler();
SeasidePropertyHandler();
~SeasidePropertyHandler();
// QVersitContactImporterPropertyHandlerV2
void documentProcessed(const QVersitDocument &, QContact *);
......@@ -77,4 +80,4 @@ public:
const QContact &, bool *alreadyProcessed, QList<QContactDetail> * updatedDetails);
};
#endif // PHOTOHANDLER_H
#endif // PROPERTYHANDLER_H
......@@ -39,7 +39,7 @@ DEFINES += CONTACTCACHE_BUILD
SOURCES += \
$$PWD/seasidecache.cpp \
$$PWD/seasideimport.cpp \
$$PWD/seasidephotohandler.cpp
$$PWD/seasidepropertyhandler.cpp
HEADERS += \
$$PWD/contactcacheexport.h \
......@@ -47,7 +47,7 @@ HEADERS += \
$$PWD/seasideimport.h \
$$PWD/synchronizelists.h \
$$PWD/seasidenamegrouper.h \
$$PWD/seasidephotohandler.h
$$PWD/seasidepropertyhandler.h
headers.files = \
$$PWD/contactcacheexport.h \
......@@ -55,6 +55,6 @@ headers.files = \
$$PWD/seasideimport.h \
$$PWD/synchronizelists.h \
$$PWD/seasidenamegrouper.h \
$$PWD/seasidephotohandler.h
$$PWD/seasidepropertyhandler.h
headers.path = $$PREFIX/include/$$TARGET
INSTALLS += headers
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