Beispiel #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;
}
Beispiel #2
0
Akonadi::Item getErrorItem(Kolab::FolderType folderType, const QString &remoteId)
{
    //TODO set title, text and icon
    Akonadi::Item item;
    item.setRemoteId(remoteId);
    switch (folderType) {
    case Kolab::EventType: {
        KCalCore::Event::Ptr event(new KCalCore::Event);
        //FIXME Use message creation date time
        event->setDtStart(KDateTime::currentUtcDateTime());
        event->setSummary(i18n("Corrupt Event"));
        event->setDescription(i18n("Event could not be read. Delete this event to remove it from the server."));
        item.setMimeType(KCalCore::Event::eventMimeType());
        item.setPayload(event);
    }
    break;
    case Kolab::TaskType: {
        KCalCore::Todo::Ptr task(new KCalCore::Todo);
        //FIXME Use message creation date time
        task->setDtStart(KDateTime::currentUtcDateTime());
        task->setSummary(i18n("Corrupt Task"));
        task->setDescription(i18n("Task could not be read. Delete this task to remove it from the server."));
        item.setMimeType(KCalCore::Todo::todoMimeType());
        item.setPayload(task);
    }
    break;
    case Kolab::JournalType: {
        KCalCore::Journal::Ptr journal(new KCalCore::Journal);
        //FIXME Use message creation date time
        journal->setDtStart(KDateTime::currentUtcDateTime());
        journal->setSummary(i18n("Corrupt journal"));
        journal->setDescription(i18n("Journal could not be read. Delete this journal to remove it from the server."));
        item.setMimeType(KCalCore::Journal::journalMimeType());
        item.setPayload(journal);
    }
    break;
    case Kolab::ContactType: {
        KContacts::Addressee addressee;
        addressee.setName(i18n("Corrupt Contact"));
        addressee.setNote(i18n("Contact could not be read. Delete this contact to remove it from the server."));
        item.setMimeType(KContacts::Addressee::mimeType());
        item.setPayload(addressee);
    }
    break;
    case Kolab::NoteType: {
        Akonadi::NoteUtils::NoteMessageWrapper note;
        note.setTitle(i18n("Corrupt Note"));
        note.setText(i18n("Note could not be read. Delete this note to remove it from the server."));
        item.setPayload(Akonadi::NoteUtils::noteMimeType());
        item.setPayload(note.message());
    }
    break;
    case Kolab::MailType:
    //We don't convert mails, so that should never fail.
    default:
        qCWarning(KOLABRESOURCE_LOG) << "unhandled folder type: " << folderType;
    }
    return item;
}
Beispiel #3
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;
}
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;
}
Beispiel #6
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;
}