Example #1
0
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;
}
Example #2
0
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;
}
Example #3
0
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;
}
Example #4
0
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;
}