Ejemplo n.º 1
0
KDSoapGenerated::TNS__Name_value_list ContactsHandler::addresseeToNameValueList(const KContacts::Addressee &addressee, QList<KDSoapGenerated::TNS__Name_value> itemList)
{
    const AccessorHash accessors = accessorHash();
    AccessorHash::const_iterator it    = accessors.constBegin();
    AccessorHash::const_iterator endIt = accessors.constEnd();
    for (; it != endIt; ++it) {
        // check if this is a read-only field
        if ((*it).getter == nullptr) {
            continue;
        }
        KDSoapGenerated::TNS__Name_value field;
        field.setName(sugarFieldFromCrmField(it.key()));
        const QString value = KDCRMUtils::encodeXML((*it).getter(addressee));
        field.setValue(value);

        itemList << field;
    }

    // add custom sugar fields
    const QStringList customAddresseeFields = addressee.customs();

    const static QString customFieldPrefix("FATCRM-X-Custom-");

    QStringList customSugarFields;
    std::copy_if(customAddresseeFields.begin(), customAddresseeFields.end(), std::back_inserter(customSugarFields),
                 [](const QString &custom) { return custom.startsWith(customFieldPrefix); });

    for (const QString &custom : qAsConst(customSugarFields)) {
        const int pos = custom.indexOf(':');
        if (pos == -1)
            continue;

        const QString name = custom.mid(customFieldPrefix.size(), pos - customFieldPrefix.size());
        const QString value = custom.mid(pos + 1);

        KDSoapGenerated::TNS__Name_value field;
        field.setName(customSugarFieldFromCrmField(name));
        field.setValue(KDCRMUtils::encodeXML(value));

        itemList << field;
    }

    KDSoapGenerated::TNS__Name_value_list valueList;
    valueList.setItems(itemList);

    return  valueList;
}
Ejemplo n.º 2
0
bool TasksHandler::setEntry( const Akonadi::Item &item )
{
    if ( !item.hasPayload<KCalCore::Todo::Ptr>() ) {
        kError() << "item (id=" << item.id() << ", remoteId=" << item.remoteId()
                 << ", mime=" << item.mimeType() << ") is missing Todo payload";
        return false;
    }

    QList<TNS__Name_value> itemList;

    // if there is an id add it, otherwise skip this field
    // no id will result in the contact being added
    if ( !item.remoteId().isEmpty() ) {
        TNS__Name_value field;
        field.setName( QLatin1String( "id" ) );
        field.setValue( item.remoteId() );

        itemList << field;
    }

    const KCalCore::Todo::Ptr todo = item.payload<KCalCore::Todo::Ptr>();
    AccessorHash::const_iterator it    = mAccessors->constBegin();
    AccessorHash::const_iterator endIt = mAccessors->constEnd();
    for ( ; it != endIt; ++it ) {
        // check if this is a read-only field
        if ( (*it)->getter == 0 ) {
            continue;
        }
        TNS__Name_value field;
        field.setName( it.key() );
        field.setValue(KDCRMUtils::encodeXML((*it)->getter(*todo)));

        itemList << field;
    }

    TNS__Name_value_list valueList;
    valueList.setItems( itemList );
    soap()->asyncSet_entry( sessionId(), moduleName(), valueList );

    return true;
}
Ejemplo n.º 3
0
void ContactsHandler::compare(Akonadi::AbstractDifferencesReporter *reporter,
                              const Akonadi::Item &leftItem, const Akonadi::Item &rightItem)
{
    Q_ASSERT(leftItem.hasPayload<KContacts::Addressee>());
    Q_ASSERT(rightItem.hasPayload<KContacts::Addressee>());

    const KContacts::Addressee leftContact = leftItem.payload<KContacts::Addressee>();
    const KContacts::Addressee rightContact = rightItem.payload<KContacts::Addressee>();

    const QString modifiedBy = mSession->userName();
    const QString modifiedOn = formatDate(getDateModified(rightContact));

    reporter->setLeftPropertyValueTitle(i18nc("@title:column", "My Contact"));
    reporter->setRightPropertyValueTitle(
        i18nc("@title:column", "Their Contact: modified by %1 on %2",
              modifiedBy, modifiedOn));

    bool seenPrimaryAddress = false;
    bool seenOtherAddress = false;
    const AccessorHash accessors = accessorHash();
    AccessorHash::const_iterator it    = accessors.constBegin();
    AccessorHash::const_iterator endIt = accessors.constEnd();
    for (; it != endIt; ++it) {
        // check if this is a read-only field
        if ((*it).getter == nullptr) {
            continue;
        }

        QString leftValue = (*it).getter(leftContact);
        QString rightValue = (*it).getter(rightContact);

        QString diffName = (*it).diffName;
        if (diffName.isEmpty()) {
            // check for special fields
            if (isAddressValue(it.key())) {
                if (isPrimaryAddressValue(it.key())) {
                    if (!seenPrimaryAddress) {
                        diffName = i18nc("item:intable", "Primary Address");
                        seenPrimaryAddress = true;
                        const KContacts::Address leftAddress =
                            leftContact.address(KContacts::Address::Work | KContacts::Address::Pref);
                        const KContacts::Address rightAddress =
                            rightContact.address(KContacts::Address::Work | KContacts::Address::Pref);

                        leftValue = leftAddress.formattedAddress();
                        rightValue = rightAddress.formattedAddress();
                    } else {
                        // already printed, skip
                        continue;
                    }
                } else {
                    if (!seenOtherAddress) {
                        seenOtherAddress = true;
                        diffName = i18nc("item:intable", "Other Address");
                        const KContacts::Address leftAddress =
                            leftContact.address(KContacts::Address::Home);
                        const KContacts::Address rightAddress =
                            rightContact.address(KContacts::Address::Home);

                        leftValue = leftAddress.formattedAddress();
                        rightValue = rightAddress.formattedAddress();
                    } else {
                        // already printed, skip
                        continue;
                    }
                }
            } else if (it.key() == QLatin1String("do_not_call")) {
                diffName = i18nc("@item:intable", "Do Not Call");
                leftValue = getDoNotCall(leftContact) == QLatin1String("1")
                            ? QStringLiteral("Yes") : QStringLiteral("No");
                rightValue = getDoNotCall(rightContact) == QLatin1String("1")
                             ? QStringLiteral("Yes") : QStringLiteral("No");
            } else {
                // internal field, skip
                continue;
            }
        }

        if (leftValue.isEmpty() && rightValue.isEmpty()) {
            continue;
        }

        if (leftValue.isEmpty()) {
            reporter->addProperty(Akonadi::AbstractDifferencesReporter::AdditionalRightMode,
                                  diffName, leftValue, rightValue);
        } else if (rightValue.isEmpty()) {
            reporter->addProperty(Akonadi::AbstractDifferencesReporter::AdditionalLeftMode,
                                  diffName, leftValue, rightValue);
        } else if (leftValue != rightValue) {
            reporter->addProperty(Akonadi::AbstractDifferencesReporter::ConflictMode,
                                  diffName, leftValue, rightValue);
        }
    }
}