Akonadi::Item TasksHandler::itemFromEntry( const TNS__Entry_value &entry, const Akonadi::Collection &parentCollection ) { Akonadi::Item item; const QList<TNS__Name_value> valueList = entry.name_value_list().items(); if ( valueList.isEmpty() ) { kWarning() << "Tasks entry for id=" << entry.id() << "has no values"; return item; } item.setRemoteId( entry.id() ); item.setParentCollection( parentCollection ); item.setMimeType( KCalCore::Todo::todoMimeType() ); KCalCore::Todo::Ptr todo( new KCalCore::Todo ); todo->setUid( entry.id() ); Q_FOREACH( const TNS__Name_value &namedValue, valueList ) { const AccessorHash::const_iterator accessIt = mAccessors->constFind( namedValue.name() ); if ( accessIt == mAccessors->constEnd() ) { // no accessor for field continue; } (*accessIt)->setter(KDCRMUtils::decodeXML(namedValue.value()), *todo ); } item.setPayload<KCalCore::Todo::Ptr>( todo ); item.setRemoteRevision( getDateModified( *todo ) ); return item; }
Akonadi::Item ContactsHandler::itemFromEntry(const KDSoapGenerated::TNS__Entry_value &entry, const Akonadi::Collection &parentCollection, bool &deleted) { Akonadi::Item item; const QList<KDSoapGenerated::TNS__Name_value> valueList = entry.name_value_list().items(); if (valueList.isEmpty()) { qCWarning(FATCRM_SUGARCRMRESOURCE_LOG) << "Contacts entry for id=" << entry.id() << "has no values"; return item; } item.setRemoteId(entry.id()); item.setParentCollection(parentCollection); item.setMimeType(KContacts::Addressee::mimeType()); KContacts::Addressee addressee; addressee.setUid(entry.id()); KContacts::Address workAddress, homeAddress; workAddress.setType(KContacts::Address::Work | KContacts::Address::Pref); homeAddress.setType(KContacts::Address::Home); const AccessorHash accessors = accessorHash(); Q_FOREACH (const KDSoapGenerated::TNS__Name_value &namedValue, valueList) { const QString crmFieldName = sugarFieldToCrmField(namedValue.name()); const AccessorHash::const_iterator accessIt = accessors.constFind(crmFieldName); if (accessIt == accessors.constEnd()) { // no accessor for regular field const QString customCrmFieldName = customSugarFieldToCrmField(namedValue.name()); addressee.insertCustom(QStringLiteral("FATCRM"), QStringLiteral("X-Custom-%1").arg(customCrmFieldName), KDCRMUtils::decodeXML(namedValue.value())); continue; } const QString value = KDCRMUtils::decodeXML(namedValue.value()); if (isAddressValue(crmFieldName)) { KContacts::Address &address = isPrimaryAddressValue(crmFieldName) ? workAddress : homeAddress; (*accessIt).setter.aSetter(value, address); } else { (*accessIt).setter.vSetter(value, addressee); } } addressee.insertAddress(workAddress); addressee.insertAddress(homeAddress); item.setPayload<KContacts::Addressee>(addressee); item.setRemoteRevision(getDateModified(addressee)); deleted = getDeleted(addressee) == QLatin1String("1"); return item; }
Akonadi::Item ContactsHandler::itemFromEntry(const KDSoapGenerated::TNS__Entry_value &entry, const Akonadi::Collection &parentCollection) { Akonadi::Item item; const QList<KDSoapGenerated::TNS__Name_value> valueList = entry.name_value_list().items(); if (valueList.isEmpty()) { kWarning() << "Contacts entry for id=" << entry.id() << "has no values"; return item; } item.setRemoteId(entry.id()); item.setParentCollection(parentCollection); item.setMimeType(KABC::Addressee::mimeType()); KABC::Addressee addressee; addressee.setUid(entry.id()); KABC::Address workAddress, homeAddress; workAddress.setType(KABC::Address::Work | KABC::Address::Pref); homeAddress.setType(KABC::Address::Home); Q_FOREACH (const KDSoapGenerated::TNS__Name_value &namedValue, valueList) { const ContactAccessorHash::const_iterator accessIt = mAccessors->constFind(namedValue.name()); if (accessIt == mAccessors->constEnd()) { // no accessor for field continue; } const QString value = KDCRMUtils::decodeXML(namedValue.value()); if (isAddressValue(namedValue.name())) { KABC::Address &address = isPrimaryAddressValue(namedValue.name()) ? workAddress : homeAddress; (*accessIt)->setter.aSetter(value, address); } else { (*accessIt)->setter.vSetter(value, addressee); } } addressee.insertAddress(workAddress); addressee.insertAddress(homeAddress); item.setPayload<KABC::Addressee>(addressee); item.setRemoteRevision(getDateModified(addressee)); return item; }
Akonadi::Item::List SalesforceContactsHandler::itemsFromListEntriesResponse(const TNS__QueryResult &queryResult, const Akonadi::Collection &parentCollection) { Akonadi::Item::List items; Q_FOREACH (const ENS__SObject &entry, queryResult.records()) { const QList<KDSoapValue> valueList = entry.any(); if (valueList.isEmpty()) { kWarning() << "Contacts entry for id=" << entry.id().value() << "has no values"; kDebug() << "fieldsToNull:" << entry.fieldsToNull(); continue; } Akonadi::Item item; item.setRemoteId(entry.id().value()); item.setParentCollection(parentCollection); item.setMimeType(KABC::Addressee::mimeType()); KABC::Addressee addressee; addressee.setUid(entry.id().value()); QList<KDSoapValue>::const_iterator it = valueList.constBegin(); QList<KDSoapValue>::const_iterator endIt = valueList.constEnd(); for (; it != endIt; ++it) { ContactAccessorHash::const_iterator accessorIt = mAccessors->constFind(it->name()); if (accessorIt != mAccessors->constEnd()) { if (accessorIt->isAvailable) { accessorIt->setter(it->value().value<QString>(), addressee); } } else { kWarning() << "Contacts entry for id=" << entry.id().value() << "has unknown value named" << it->name(); } } item.setPayload<KABC::Addressee>(addressee); items << item; } kDebug() << "Query result had" << items.count() << "valid contact items"; return items; }
Item Serializer::createItemFromProject(Domain::Project::Ptr project) { auto todo = KCalCore::Todo::Ptr::create(); todo->setSummary(project->name()); todo->setCustomProperty("Zanshin", "Project", "1"); if (project->property("todoUid").isValid()) { todo->setUid(project->property("todoUid").toString()); } Akonadi::Item item; if (project->property("itemId").isValid()) { item.setId(project->property("itemId").value<Akonadi::Item::Id>()); } if (project->property("parentCollectionId").isValid()) { auto parentId = project->property("parentCollectionId").value<Akonadi::Collection::Id>(); item.setParentCollection(Akonadi::Collection(parentId)); } item.setMimeType(KCalCore::Todo::todoMimeType()); item.setPayload(todo); return item; }
Akonadi::Item DocumentsHandler::itemFromEntry(const KDSoapGenerated::TNS__Entry_value &entry, const Akonadi::Collection &parentCollection, bool &deleted) { Akonadi::Item item; const QList<KDSoapGenerated::TNS__Name_value> valueList = entry.name_value_list().items(); if (valueList.isEmpty()) { qCWarning(FATCRM_SUGARCRMRESOURCE_LOG) << "Documents entry for id=" << entry.id() << "has no values"; return item; } item.setRemoteId(entry.id()); item.setParentCollection(parentCollection); item.setMimeType(SugarDocument::mimeType()); SugarDocument document; document.setId(entry.id()); const SugarDocument::AccessorHash accessors = SugarDocument::accessorHash(); Q_FOREACH (const KDSoapGenerated::TNS__Name_value &namedValue, valueList) { const QString crmFieldName = sugarFieldToCrmField(namedValue.name()); const QString value = KDCRMUtils::decodeXML(namedValue.value()); const SugarDocument::AccessorHash::const_iterator accessIt = accessors.constFind(crmFieldName); if (accessIt == accessors.constEnd()) { const QString crmCustomFieldName = customSugarFieldToCrmField(namedValue.name()); document.setCustomField(crmCustomFieldName, value); continue; } (document.*(accessIt.value().setter))(KDCRMUtils::decodeXML(value)); } item.setPayload<SugarDocument>(document); item.setRemoteRevision(document.dateModifiedRaw()); deleted = document.deleted() == QLatin1String("1"); return item; }