diff --git a/src/seasideimport.cpp b/src/seasideimport.cpp index 7418a1c..32fd8bf 100644 --- a/src/seasideimport.cpp +++ b/src/seasideimport.cpp @@ -32,7 +32,7 @@ #include "seasideimport.h" #include "seasidecache.h" -#include "seasidephotohandler.h" +#include "seasidepropertyhandler.h" #include #include @@ -312,9 +312,9 @@ QList SeasideImport::buildImportContacts(const QList *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 importedContacts(importer.contacts()); diff --git a/src/seasidephotohandler.cpp b/src/seasidepropertyhandler.cpp similarity index 67% rename from src/seasidephotohandler.cpp rename to src/seasidepropertyhandler.cpp index 8c3a770..0784c52 100644 --- a/src/seasidephotohandler.cpp +++ b/src/seasidepropertyhandler.cpp @@ -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 #include #endif #include +#include +#include #include #include #include -SeasidePhotoHandler::SeasidePhotoHandler() +#include + +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 * updatedDetails) +namespace { + +void processPhoto(const QVersitProperty &property, bool *alreadyProcessed, QList * 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 * 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 * 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); + } +} + diff --git a/src/seasidephotohandler.h b/src/seasidepropertyhandler.h similarity index 87% rename from src/seasidephotohandler.h rename to src/seasidepropertyhandler.h index d532919..7becf26 100644 --- a/src/seasidephotohandler.h +++ b/src/seasidepropertyhandler.h @@ -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 @@ class CONTACTCACHE_EXPORT SeasidePhotoHandler : public QVersitContactImporterPro const QContact &, bool *alreadyProcessed, QList * updatedDetails); }; -#endif // PHOTOHANDLER_H +#endif // PROPERTYHANDLER_H diff --git a/src/src.pro b/src/src.pro index 4c9fa53..bec7f55 100644 --- a/src/src.pro +++ b/src/src.pro @@ -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