void CalendarUrlTest::shouldGenerateVCardWithParameter() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("*****@*****.**")); addr.setUid(QStringLiteral("testuid")); CalendarUrl url; url.setType(CalendarUrl::CALUri); url.setUrl(QUrl(QStringLiteral("https://sherlockholmes.com/calendar/sherlockholmes"))); QMap<QString, QStringList> params; params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); url.setParameters(params); addr.insertCalendarUrl(url); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QByteArray expected = QByteArray("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "CALURI;FOO2=bla2,blo2:https://sherlockholmes.com/calendar/sherlockholmes\r\n" "EMAIL:[email protected]\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); }
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; }
void ImageWidget::storeContact(KContacts::Addressee &contact) const { if (mType == Photo) { contact.setPhoto(mPicture); } else { contact.setLogo(mPicture); } }
void AddresseeTest::nameFromStringTest() { KContacts::Addressee a; a.setNameFromString(QStringLiteral("Firstname Lastname")); QCOMPARE(a.givenName(), QStringLiteral("Firstname")); QCOMPARE(a.familyName(), QStringLiteral("Lastname")); QCOMPARE(a.formattedName(), QStringLiteral("Firstname Lastname")); }
void AddresseeTest::emptyTest() { KContacts::Addressee addressee; QVERIFY(addressee.isEmpty()); KContacts::Addressee addresseeWithMail; addresseeWithMail.insertEmail(QStringLiteral("*****@*****.**")); QVERIFY(!addresseeWithMail.isEmpty()); }
void AddresseeTest::fullEmailTest() { KContacts::Addressee a; QStringList emails; emails << QStringLiteral("*****@*****.**"); a.setEmails(emails); a.setFormattedName(QStringLiteral("firstname \"nickname\" lastname")); QCOMPARE(a.fullEmail(), QStringLiteral("\"firstname \\\"nickname\\\" lastname\" <*****@*****.**>")); }
void ImageWidget::loadContact(const KContacts::Addressee &contact) { mPicture = (mType == Photo ? contact.photo() : contact.logo()); if (mPicture.isIntern() && !mPicture.data().isNull()) { mHasImage = true; } else if (!mPicture.isIntern() && !mPicture.url().isEmpty()) { mHasImage = true; } updateView(); }
void GenderTest::shouldExportEmptyGender() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("*****@*****.**")); addr.setUid(QStringLiteral("testuid")); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QByteArray expected = createCard(QByteArray()); QCOMPARE(ba, expected); }
static QString getEmail2(const KContacts::Addressee &addressee) { // preferred might not be the first one, so remove it and take the first of // the remaining instead of always taking the second one QStringList emails = addressee.emails(); emails.removeAll(addressee.preferredEmail()); if (!emails.isEmpty()) { return emails.at( 0 ); } return QString(); }
QString MergeContactWidgetList::itemName(const KContacts::Addressee &address) const { const QString realName = address.realName(); if (!realName.isEmpty()) { return realName; } const QString name = address.name(); if (!name.isEmpty()) { return name; } return address.fullEmail(); }
void EmailEditWidgetTest::shouldSelectFirstEmail() { EmailEditWidget widget; QLineEdit *lineedit = widget.findChild<QLineEdit *>(QStringLiteral("emailedit")); KContacts::Addressee addr; KContacts::Email::List lst; const QString firstEmail(QStringLiteral("*****@*****.**")); lst << KContacts::Email(firstEmail); lst << KContacts::Email(QStringLiteral("*****@*****.**")); addr.setEmailList(lst); widget.loadContact(addr); QCOMPARE(lineedit->text(), firstEmail); }
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; }
void BusinessEditorWidget::loadContact(const KContacts::Addressee &contact) { mLogoWidget->loadContact(contact); mOrganizationWidget->setText(contact.organization()); mProfessionWidget->setText(Akonadi::Utils::loadCustom(contact, QStringLiteral("X-Profession"))); mTitleWidget->setText(contact.title()); mDepartmentWidget->setText(contact.department()); mOfficeWidget->setText(Akonadi::Utils::loadCustom(contact, QStringLiteral("X-Office"))); mManagerWidget->setText(Akonadi::Utils::loadCustom(contact, QStringLiteral("X-ManagersName"))); mAssistantWidget->setText(Akonadi::Utils::loadCustom(contact, QStringLiteral("X-AssistantsName"))); // groupware group mFreeBusyWidget->loadContact(contact); }
void GenderTest::shouldExportOnlyGenderWithoutTypeCommentGender() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("*****@*****.**")); addr.setUid(QStringLiteral("testuid")); KContacts::Gender gender; gender.setComment(QStringLiteral("comment")); addr.setGender(gender); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QByteArray expected = createCard(QByteArray("GENDER:;comment")); QCOMPARE(ba, expected); }
void BusinessEditorWidget::storeContact(KContacts::Addressee &contact) { // general group mLogoWidget->storeContact(contact); contact.setOrganization(mOrganizationWidget->text()); Akonadi::Utils::storeCustom(contact, QStringLiteral("X-Profession"), mProfessionWidget->text().trimmed()); contact.setTitle(mTitleWidget->text().trimmed()); contact.setDepartment(mDepartmentWidget->text().trimmed()); Akonadi::Utils::storeCustom(contact, QStringLiteral("X-Office"), mOfficeWidget->text().trimmed()); Akonadi::Utils::storeCustom(contact, QStringLiteral("X-ManagersName"), mManagerWidget->text().trimmed()); Akonadi::Utils::storeCustom(contact, QStringLiteral("X-AssistantsName"), mAssistantWidget->text().trimmed()); // groupware group mFreeBusyWidget->storeContact(contact); }
void SecrecyEditWidget::storeContact(KContacts::Addressee &contact) const { KContacts::Secrecy secrecy; secrecy.setType((KContacts::Secrecy::Type)mSecrecyCombo->currentIndex()); contact.setSecrecy(secrecy); }
void CheckGravatarPluginInterface::exec() { if (mListItems.isEmpty()) { KMessageBox::sorry(parentWidget(), i18n("You have not selected any contacts.")); } else { if (mListItems.count() == 1) { Akonadi::Item item = mListItems.first(); if (item.hasPayload<KContacts::Addressee>()) { KContacts::Addressee address = item.payload<KContacts::Addressee>(); const QString email = address.preferredEmail(); if (email.isEmpty()) { KMessageBox::error(parentWidget(), i18n("No email found for this contact.")); return; } QPointer<KABGravatar::GravatarUpdateDialog> dlg = new KABGravatar::GravatarUpdateDialog(parentWidget()); dlg->setEmail(email); if (!address.photo().isEmpty()) { if (address.photo().isIntern()) { const QPixmap pix = QPixmap::fromImage(address.photo().data()); dlg->setOriginalPixmap(pix); } else { dlg->setOriginalUrl(QUrl(address.photo().url())); } } if (dlg->exec()) { KContacts::Picture picture = address.photo(); bool needToSave = false; if (dlg->saveUrl()) { const QUrl url = dlg->resolvedUrl(); if (!url.isEmpty()) { picture.setUrl(url.toString()); needToSave = true; } } else { const QPixmap pix = dlg->pixmap(); if (!pix.isNull()) { picture.setData(pix.toImage()); needToSave = true; } } if (needToSave) { address.setPhoto(picture); item.setPayload<KContacts::Addressee>(address); Akonadi::ItemModifyJob *modifyJob = new Akonadi::ItemModifyJob(item, this); connect(modifyJob, &Akonadi::ItemModifyJob::result, this, &CheckGravatarPluginInterface::slotModifyContactFinished); } } delete dlg; } else { KMessageBox::information(parentWidget(), i18n("A contact group was selected.")); } } else { KMessageBox::information(parentWidget(), i18n("Too many contacts selected.")); } } }
void CustomFieldsListWidget::storeContact(KContacts::Addressee &contact) const { const CustomField::List customFields = mModel->customFields(); for (const CustomField &customField : customFields) { // write back values for local and global scope, leave external untouched if (customField.scope() != CustomField::ExternalScope) { if (!customField.value().isEmpty()) { contact.insertCustom(QStringLiteral("KADDRESSBOOK"), customField.key(), customField.value()); } else { contact.removeCustom(QStringLiteral("KADDRESSBOOK"), customField.key()); } } } // Now remove all fields that were available in loadContact (these are stored in mLocalCustomFields) // but are not part of customFields now, which means they have been removed or renamed by the user // in the editor dialog. for (const CustomField &oldCustomField : qAsConst(mLocalCustomFields)) { if (oldCustomField.scope() != CustomField::ExternalScope) { bool fieldStillExists = false; for (const CustomField &newCustomField : qAsConst(customFields)) { if (newCustomField.scope() != CustomField::ExternalScope) { if (newCustomField.key() == oldCustomField.key()) { fieldStillExists = true; break; } } } if (!fieldStillExists) { contact.removeCustom(QStringLiteral("KADDRESSBOOK"), oldCustomField.key()); } } } // And store the global custom fields descriptions as well CustomField::List globalCustomFields; for (const CustomField &customField : qAsConst(customFields)) { if (customField.scope() == CustomField::GlobalScope) { globalCustomFields << customField; } } CustomFieldManager::setGlobalCustomFieldDescriptions(globalCustomFields); }
void EmailEditWidgetTest::shouldChangeEmail() { EmailEditWidget widget; QLineEdit *lineedit = widget.findChild<QLineEdit *>(QStringLiteral("emailedit")); KContacts::Addressee addr; KContacts::Email::List lst; const QString firstEmail(QStringLiteral("*****@*****.**")); lst << KContacts::Email(firstEmail); lst << KContacts::Email(QStringLiteral("*****@*****.**")); addr.setEmailList(lst); widget.loadContact(addr); const QString changedEmail(QStringLiteral("*****@*****.**")); lineedit->setText(changedEmail); KContacts::Addressee result; widget.storeContact(result); QVERIFY(!result.emailList().isEmpty()); QCOMPARE(result.emailList().first().mail(), changedEmail); }
void CategoriesEditWidget::loadContact(const KContacts::Addressee &contact) { Akonadi::Tag::List tags; const QStringList categories = contact.categories(); tags.reserve(categories.count()); foreach (const QString &category, categories) { tags.append(Akonadi::Tag::fromUrl(QUrl(category))); }
void SoundEditWidget::loadContact(const KContacts::Addressee &contact) { const KContacts::Sound sound = contact.sound(); if (sound.isIntern() && !sound.data().isEmpty()) { mHasSound = true; mSound = sound.data(); } updateView(); }
void AddEmailToExistingContactJob::start() { if (mItem.hasPayload<KContacts::Addressee>()) { KContacts::Addressee address = mItem.payload<KContacts::Addressee>(); QStringList emails = address.emails(); if (emails.contains(mEmail)) { Q_EMIT emitResult(); } else { emails.append(mEmail); address.setEmails(emails); mItem.setPayload<KContacts::Addressee>(address); Akonadi::ItemModifyJob *job = new Akonadi::ItemModifyJob(mItem); connect(job, &Akonadi::ItemModifyJob::result, this, &AddEmailToExistingContactJob::slotAddEmailDone); } } else { qCDebug(KMAIL_LOG) << " not a KContacts::Addressee item "; //TODO add error Q_EMIT emitResult(); } }
void GenderTest::shouldNotExportInVcard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("*****@*****.**")); addr.setUid(QStringLiteral("testuid")); KContacts::Gender gender; gender.setComment(QStringLiteral("comment")); addr.setGender(gender); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0); QByteArray expected("BEGIN:VCARD\r\n" "VERSION:3.0\r\n" "EMAIL:[email protected]\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); }
static bool contactMatchesFilter(const KContacts::Addressee& contact, const QString &filter) { if (contact.assembledName().contains(filter, Qt::CaseInsensitive)) { return true; } if (contact.organization().contains(filter, Qt::CaseInsensitive)) { return true; } if (contact.preferredEmail().contains(filter, Qt::CaseInsensitive)) { return true; } if (contact.phoneNumber(KContacts::PhoneNumber::Work).number().contains(filter, Qt::CaseInsensitive)) { return true; } if (contact.phoneNumber(KContacts::PhoneNumber::Cell).number().contains(filter, Qt::CaseInsensitive)) { return true; } if (contact.givenName().contains(filter, Qt::CaseInsensitive)) { return true; } if (ItemsTreeModel::countryForContact(contact).contains(filter, Qt::CaseInsensitive)) { return true; } return false; }
void PhoneWidgetLister::storeContact(KContacts::Addressee &contact) const { KContacts::PhoneNumber::List phoneNumbers; const QList<QWidget *> widgetList = widgets(); for (QWidget *widget : widgetList) { PhoneWidget *w = qobject_cast<PhoneWidget *>(widget); KContacts::PhoneNumber number = w->storePhone(); if (!number.isEmpty()) { phoneNumbers << number; } } contact.setPhoneNumbers(phoneNumbers); }
void BirthDayTest::shouldExportVcard3WithoutTimeAndWithoutYear() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("*****@*****.**") << QStringLiteral("*****@*****.**")); addr.setUid(QStringLiteral("testuid")); const QDate d(-1, 5, 5); addr.setBirthday(d); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0); QByteArray expected("BEGIN:VCARD\r\n" "VERSION:3.0\r\n" "BDAY:--05-05\r\n" "EMAIL:[email protected]\r\n" "EMAIL:[email protected]\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); }
void BirthDayTest::shouldExportVcard4() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("*****@*****.**") << QStringLiteral("*****@*****.**")); addr.setUid(QStringLiteral("testuid")); const QDateTime dt(QDate(1976, 5, 5), QTime(12, 5, 5)); addr.setBirthday(dt); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QByteArray expected("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "BDAY:19760505T120505\r\n" "EMAIL:[email protected]\r\n" "EMAIL:[email protected]\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); }
void CalendarUrlTest::shouldGenerateVCard() { QFETCH(KContacts::CalendarUrl::CalendarType, type); QFETCH(QByteArray, value); KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("*****@*****.**")); addr.setUid(QStringLiteral("testuid")); CalendarUrl url; url.setType(type); url.setUrl(QUrl(QStringLiteral("https://sherlockholmes.com/calendar/sherlockholmes"))); addr.insertCalendarUrl(url); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QByteArray expected; // Different order if (type == KContacts::CalendarUrl::FBUrl) { expected = QByteArray("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "EMAIL:[email protected]\r\n"); expected += value + QByteArray(":https://sherlockholmes.com/calendar/sherlockholmes\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); } else { expected = QByteArray("BEGIN:VCARD\r\n" "VERSION:4.0\r\n"); expected += value + QByteArray(":https://sherlockholmes.com/calendar/sherlockholmes\r\n" "EMAIL:[email protected]\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); } QCOMPARE(ba, expected); }
void MailWidgetLister::storeContact(KContacts::Addressee &contact) const { const QList<QWidget *> widgetList = widgets(); KContacts::Email::List emailList; emailList.reserve(widgetList.count()); for (QWidget *widget : widgetList) { MailWidget *w = qobject_cast<MailWidget *>(widget); KContacts::Email newEmail = w->email(); if (newEmail.isValid()) { emailList << newEmail; } } contact.setEmailList(emailList); }
void MailWidgetLister::loadContact(const KContacts::Addressee &contact) { KContacts::Email::List mailList = contact.emailList(); if (mailList.isEmpty()) { setNumberOfShownWidgetsTo(1); } else { setNumberOfShownWidgetsTo(mailList.count()); const QList<QWidget *> widgetList = widgets(); auto wIt = widgetList.constBegin(); auto wEnd = widgetList.constEnd(); for (int i = 0; wIt != wEnd; ++wIt, ++i) { MailWidget *w = qobject_cast<MailWidget *>(*wIt); w->setMail(mailList.at(i)); } } }