diff --git a/src/akonadi-contacts/autotests/contactmetadataattributetest.cpp b/src/akonadi-contacts/autotests/contactmetadataattributetest.cpp index bb4da3a8..3f2250de 100644 --- a/src/akonadi-contacts/autotests/contactmetadataattributetest.cpp +++ b/src/akonadi-contacts/autotests/contactmetadataattributetest.cpp @@ -1,74 +1,74 @@ /* This file is part of Akonadi Contact. Copyright (c) 2009 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "contactmetadataattributetest.h" #include "attributes/contactmetadataattribute_p.h" -#include +#include QTEST_MAIN(ContactMetaDataAttributeTest) static QVariantMap testData() { QVariantMap data; data.insert(QStringLiteral("key1"), QStringLiteral("value1")); data.insert(QStringLiteral("key2"), QStringLiteral("value2")); return data; } void ContactMetaDataAttributeTest::type() { Akonadi::ContactMetaDataAttribute attribute; QVERIFY(attribute.type() == "contactmetadata"); } void ContactMetaDataAttributeTest::clone() { const QVariantMap content1 = testData(); Akonadi::ContactMetaDataAttribute attribute1; attribute1.setMetaData(content1); Akonadi::ContactMetaDataAttribute *attribute2 = static_cast(attribute1.clone()); const QVariantMap content2 = attribute2->metaData(); QVERIFY(content1 == content2); } void ContactMetaDataAttributeTest::serialization() { const QVariantMap content1 = testData(); Akonadi::ContactMetaDataAttribute attribute1; attribute1.setMetaData(content1); const QByteArray data = attribute1.serialized(); Akonadi::ContactMetaDataAttribute attribute2; attribute2.deserialize(data); const QVariantMap content2 = attribute2.metaData(); QVERIFY(content1 == content2); } diff --git a/src/akonadi-contacts/tests/emailaddressselectiondialogtest.cpp b/src/akonadi-contacts/tests/emailaddressselectiondialogtest.cpp index b08d3e1e..765a8dc9 100644 --- a/src/akonadi-contacts/tests/emailaddressselectiondialogtest.cpp +++ b/src/akonadi-contacts/tests/emailaddressselectiondialogtest.cpp @@ -1,36 +1,36 @@ /* Copyright (c) 2010 KDAB Author: Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "emailaddressselectiondialog.h" -#include +#include int main(int argc, char **argv) { QApplication app(argc, argv); Akonadi::EmailAddressSelectionDialog dlg; if (dlg.exec()) { for (const Akonadi::EmailAddressSelection &selection : dlg.selectedAddresses()) { qDebug("%s: %s", qPrintable(selection.name()), qPrintable(selection.email())); } } return 0; } diff --git a/src/akonadi-contacts/tests/emailaddressselectionmodeltest.cpp b/src/akonadi-contacts/tests/emailaddressselectionmodeltest.cpp index 04b20168..4299657c 100644 --- a/src/akonadi-contacts/tests/emailaddressselectionmodeltest.cpp +++ b/src/akonadi-contacts/tests/emailaddressselectionmodeltest.cpp @@ -1,36 +1,36 @@ /* Copyright (c) 2017 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "emailaddressselectionmodel.h" #include #include -#include +#include int main(int argc, char **argv) { QApplication app(argc, argv); Akonadi::EmailAddressSelectionModel model; QTreeView view; view.setModel(model.model()); view.show(); return app.exec(); } diff --git a/src/akonadi-contacts/tests/emailaddressselectionwidgettest.cpp b/src/akonadi-contacts/tests/emailaddressselectionwidgettest.cpp index d8d2797a..8df122d1 100644 --- a/src/akonadi-contacts/tests/emailaddressselectionwidgettest.cpp +++ b/src/akonadi-contacts/tests/emailaddressselectionwidgettest.cpp @@ -1,76 +1,76 @@ /* Copyright (c) 2010 KDAB Author: Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "emailaddressselectionwidgettest.h" -#include +#include #include -#include +#include #include #include #include MainWidget::MainWidget() : QWidget(nullptr) { QGridLayout *layout = new QGridLayout(this); mAddressesWidget = new Akonadi::EmailAddressSelectionWidget; layout->addWidget(mAddressesWidget, 0, 0); mInfo = new QTextBrowser; layout->addWidget(mInfo, 0, 1); KComboBox *box = new KComboBox; box->addItem(QStringLiteral("Single Selection")); box->addItem(QStringLiteral("Multi Selection")); connect(box, QOverload::of(&KComboBox::activated), this, &MainWidget::selectionModeChanged); layout->addWidget(box, 1, 0); QPushButton *button = new QPushButton(QStringLiteral("Show Selection")); connect(button, &QPushButton::clicked, this, &MainWidget::showSelection); layout->addWidget(button, 1, 1); } void MainWidget::selectionModeChanged(int index) { mAddressesWidget->view()->setSelectionMode(index == 0 ? QTreeView::SingleSelection : QTreeView::MultiSelection); } void MainWidget::showSelection() { mInfo->append(QStringLiteral("===========================\n")); mInfo->append(QStringLiteral("Current selection:\n")); for (const Akonadi::EmailAddressSelection &selection : mAddressesWidget->selectedAddresses()) { mInfo->append(QStringLiteral("%1: %2\n").arg(selection.name()).arg(selection.email())); } } int main(int argc, char **argv) { QApplication app(argc, argv); MainWidget wdg; wdg.show(); return app.exec(); } diff --git a/src/contact-editor/editor/contacteditorwidget.cpp b/src/contact-editor/editor/contacteditorwidget.cpp index c3442006..ec2e5c85 100644 --- a/src/contact-editor/editor/contacteditorwidget.cpp +++ b/src/contact-editor/editor/contacteditorwidget.cpp @@ -1,286 +1,286 @@ /* This file is part of Contact Editor. Copyright (c) 2009 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "contacteditorwidget.h" #include "config-contact-editor.h" #include "personaleditor/personaleditorwidget.h" #include "contacteditorpageplugin.h" #include "contactmetadatabase_p.h" #include #include #include -#include +#include #include #include #include #include #include "addresseditor/addresseslocationwidget.h" #include "customfieldeditor/customfieldswidget.h" #include "businesseditor/businesseditorwidget.h" #include "generalinfoeditor/generalinfowidget.h" class Q_DECL_HIDDEN ContactEditorWidget::Private { public: Private(ContactEditorWidget::DisplayMode displayMode, ContactEditorWidget *parent) : mDisplayMode(displayMode) , mParent(parent) , mCustomFieldsWidget(nullptr) { } void initGui(); void initGuiContactTab(); void initGuiLocationTab(); void initGuiBusinessTab(); void initGuiPersonalTab(); void initGuiNotesTab(); void initGuiCustomFieldsTab(); void loadCustomPages(); QString loadCustom(const KContacts::Addressee &contact, const QString &key) const; void storeCustom(KContacts::Addressee &contact, const QString &key, const QString &value) const; ContactEditorWidget::DisplayMode mDisplayMode; ContactEditorWidget *mParent = nullptr; QTabWidget *mTabWidget = nullptr; ContactEditor::GeneralInfoWidget *mGeneralInfoWidget = nullptr; // widgets from addresses group ContactEditor::AddressesLocationWidget *mAddressesLocationWidget = nullptr; ContactEditor::BusinessEditorWidget *mBusinessEditorWidget = nullptr; // widgets from notes group KTextEdit *mNotesWidget = nullptr; ContactEditor::PersonalEditorWidget *mPersonalEditorWidget = nullptr; // widgets from custom fields group ContactEditor::CustomFieldsWidget *mCustomFieldsWidget = nullptr; // custom editor pages QList mCustomPages; }; void ContactEditorWidget::Private::initGui() { QVBoxLayout *layout = new QVBoxLayout(mParent); layout->setContentsMargins(0, 0, 0, 0); mTabWidget = new QTabWidget(mParent); layout->addWidget(mTabWidget); initGuiContactTab(); initGuiLocationTab(); initGuiBusinessTab(); initGuiPersonalTab(); initGuiNotesTab(); if (mDisplayMode == FullMode) { initGuiCustomFieldsTab(); loadCustomPages(); } } void ContactEditorWidget::Private::initGuiContactTab() { mGeneralInfoWidget = new ContactEditor::GeneralInfoWidget; mTabWidget->addTab(mGeneralInfoWidget, i18nc("@title:tab", "Contact")); } void ContactEditorWidget::Private::initGuiLocationTab() { mAddressesLocationWidget = new ContactEditor::AddressesLocationWidget; mTabWidget->addTab(mAddressesLocationWidget, i18nc("@title:tab", "Location")); } void ContactEditorWidget::Private::initGuiBusinessTab() { mBusinessEditorWidget = new ContactEditor::BusinessEditorWidget(); mTabWidget->addTab(mBusinessEditorWidget, i18nc("@title:tab", "Business")); } void ContactEditorWidget::Private::initGuiPersonalTab() { mPersonalEditorWidget = new ContactEditor::PersonalEditorWidget; mTabWidget->addTab(mPersonalEditorWidget, i18nc("@title:tab Personal properties of a contact", "Personal")); } void ContactEditorWidget::Private::initGuiNotesTab() { QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout(widget); mTabWidget->addTab(widget, i18nc("@title:tab", "Notes")); mNotesWidget = new KTextEdit; mNotesWidget->setAcceptRichText(false); layout->addWidget(mNotesWidget); } void ContactEditorWidget::Private::initGuiCustomFieldsTab() { mCustomFieldsWidget = new ContactEditor::CustomFieldsWidget(mParent); mTabWidget->addTab(mCustomFieldsWidget, i18nc("@title:tab", "Custom Fields")); } void ContactEditorWidget::Private::loadCustomPages() { qDeleteAll(mCustomPages); mCustomPages.clear(); const QString pluginDirectory = QStringLiteral("%1/contacteditor/editorpageplugins/").arg(QStringLiteral(EDITOR_CONTACT_LIB)); QDirIterator it(pluginDirectory, QDir::Files); while (it.hasNext()) { QPluginLoader loader(it.next()); if (!loader.load()) { continue; } ContactEditor::ContactEditorPagePlugin *plugin = qobject_cast(loader.instance()); if (!plugin) { continue; } mCustomPages.append(plugin); } for (ContactEditor::ContactEditorPagePlugin *plugin : qAsConst(mCustomPages)) { mTabWidget->addTab(plugin, plugin->title()); } } QString ContactEditorWidget::Private::loadCustom(const KContacts::Addressee &contact, const QString &key) const { return contact.custom(QStringLiteral("KADDRESSBOOK"), key); } void ContactEditorWidget::Private::storeCustom(KContacts::Addressee &contact, const QString &key, const QString &value) const { if (value.isEmpty()) { contact.removeCustom(QStringLiteral("KADDRESSBOOK"), key); } else { contact.insertCustom(QStringLiteral("KADDRESSBOOK"), key, value); } } ContactEditorWidget::ContactEditorWidget(QWidget *parent) : d(new Private(FullMode, this)) { Q_UNUSED(parent) d->initGui(); } ContactEditorWidget::ContactEditorWidget(ContactEditorWidget::DisplayMode displayMode, QWidget *parent) : d(new Private(displayMode, this)) { Q_UNUSED(parent) d->initGui(); } ContactEditorWidget::~ContactEditorWidget() { delete d; } void ContactEditorWidget::loadContact(const KContacts::Addressee &contact, const ContactEditor::ContactMetaDataBase &metaData) { d->mGeneralInfoWidget->loadContact(contact); // address group d->mAddressesLocationWidget->loadContact(contact); // general group d->mBusinessEditorWidget->loadContact(contact); // notes group d->mNotesWidget->setPlainText(contact.note()); d->mPersonalEditorWidget->loadContact(contact); d->mGeneralInfoWidget->setDisplayType((DisplayNameEditWidget::DisplayType)metaData.displayNameMode()); if (d->mDisplayMode == FullMode) { // custom fields group d->mCustomFieldsWidget->setLocalCustomFieldDescriptions(metaData.customFieldDescriptions()); d->mCustomFieldsWidget->loadContact(contact); // custom pages for (ContactEditor::ContactEditorPagePlugin *plugin : qAsConst(d->mCustomPages)) { plugin->loadContact(contact); } } } void ContactEditorWidget::storeContact(KContacts::Addressee &contact, ContactEditor::ContactMetaDataBase &metaData) const { d->mGeneralInfoWidget->storeContact(contact); // address group d->mAddressesLocationWidget->storeContact(contact); // general group d->mBusinessEditorWidget->storeContact(contact); // notes group contact.setNote(d->mNotesWidget->toPlainText()); d->mPersonalEditorWidget->storeContact(contact); if (d->mDisplayMode == FullMode) { // custom fields group d->mCustomFieldsWidget->storeContact(contact); metaData.setCustomFieldDescriptions(d->mCustomFieldsWidget->localCustomFieldDescriptions()); metaData.setDisplayNameMode(d->mGeneralInfoWidget->displayType()); // custom pages for (ContactEditor::ContactEditorPagePlugin *plugin : qAsConst(d->mCustomPages)) { plugin->storeContact(contact); } } } void ContactEditorWidget::setReadOnly(bool readOnly) { d->mGeneralInfoWidget->setReadOnly(readOnly); // widgets from addresses group d->mAddressesLocationWidget->setReadOnly(readOnly); // widgets from general group d->mBusinessEditorWidget->setReadOnly(readOnly); // widgets from notes group d->mNotesWidget->setReadOnly(readOnly); d->mPersonalEditorWidget->setReadOnly(readOnly); if (d->mDisplayMode == FullMode) { // widgets from custom fields group d->mCustomFieldsWidget->setReadOnly(readOnly); // custom pages for (ContactEditor::ContactEditorPagePlugin *plugin : qAsConst(d->mCustomPages)) { plugin->setReadOnly(readOnly); } } }