void ReportGenerator::contactToTemplate( TextTemplate *tmpl, const QString& prefix, const KContacts::Addressee& contact ) { if( contact.isEmpty() ) return; tmpl->setValue( ADDRESS_TAG( prefix, "NAME" ), escapeTrml2pdfXML( contact.realName() ) ); QString co = contact.organization(); if( co.isEmpty() ) { co = contact.realName(); } tmpl->setValue( ADDRESS_TAG( prefix, "ORGANISATION" ), escapeTrml2pdfXML( co ) ); tmpl->setValue( ADDRESS_TAG( prefix, "URL" ), escapeTrml2pdfXML( contact.url().toString() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "EMAIL" ), escapeTrml2pdfXML( contact.preferredEmail() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "PHONE" ), escapeTrml2pdfXML( contact.phoneNumber( KContacts::PhoneNumber::Work ).number() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "FAX" ), escapeTrml2pdfXML( contact.phoneNumber( KContacts::PhoneNumber::Fax ).number() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "CELL" ), escapeTrml2pdfXML( contact.phoneNumber( KContacts::PhoneNumber::Cell ).number() ) ); KContacts::Address address; address = contact.address( KContacts::Address::Pref ); if( address.isEmpty() ) address = contact.address(KContacts::Address::Work ); if( address.isEmpty() ) address = contact.address(KContacts::Address::Home ); if( address.isEmpty() ) address = contact.address(KContacts::Address::Postal ); tmpl->setValue( ADDRESS_TAG( prefix, "POSTBOX" ), escapeTrml2pdfXML( address.postOfficeBox() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "EXTENDED" ), escapeTrml2pdfXML( address.extended() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "STREET" ), escapeTrml2pdfXML( address.street() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "LOCALITY" ), escapeTrml2pdfXML( address.locality() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "REGION" ), escapeTrml2pdfXML( address.region() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "POSTCODE" ), escapeTrml2pdfXML( address.postalCode() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "COUNTRY" ), escapeTrml2pdfXML( address.country() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "REGION" ), escapeTrml2pdfXML( address.region() ) ); tmpl->setValue( ADDRESS_TAG( prefix,"LABEL" ), escapeTrml2pdfXML( address.label() ) ); }
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); } } }
static QString getOtherPostalcode(const KContacts::Addressee &addressee) { return addressee.address(KContacts::Address::Home).postalCode(); }
static QString getOtherCountry(const KContacts::Addressee &addressee) { return addressee.address(KContacts::Address::Home).country(); }
static QString getOtherCity(const KContacts::Addressee &addressee) { return addressee.address(KContacts::Address::Home).locality(); }
static QString getOtherState(const KContacts::Addressee &addressee) { return addressee.address(KContacts::Address::Home).region(); }
static QString getOtherStreet(const KContacts::Addressee &addressee) { return addressee.address(KContacts::Address::Home).street(); }
static QString getPrimaryCountry(const KContacts::Addressee &addressee) { return addressee.address(KContacts::Address::Work | KContacts::Address::Pref).country(); }
static QString getPrimaryPostalcode(const KContacts::Addressee &addressee) { return addressee.address(KContacts::Address::Work | KContacts::Address::Pref).postalCode(); }
static QString getPrimaryState(const KContacts::Addressee &addressee) { return addressee.address(KContacts::Address::Work | KContacts::Address::Pref).region(); }
static QString getPrimaryStreet(const KContacts::Addressee &addressee) { return addressee.address(KContacts::Address::Work).street(); }