diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -240,6 +240,7 @@ KF5::PimCommonAkonadi KF5::Completion PRIVATE + KF5::AkonadiWidgets KF5::TextWidgets KF5::I18n KF5::LibkdepimAkonadi diff --git a/src/filter/autotests/filteractionaddtoaddressbooktest.cpp b/src/filter/autotests/filteractionaddtoaddressbooktest.cpp --- a/src/filter/autotests/filteractionaddtoaddressbooktest.cpp +++ b/src/filter/autotests/filteractionaddtoaddressbooktest.cpp @@ -22,8 +22,9 @@ #include #include #include -#include + #include +#include FilterActionAddToAddressBookTest::FilterActionAddToAddressBookTest(QObject *parent) : QObject(parent) @@ -45,7 +46,7 @@ QLabel *label = w->findChild(QStringLiteral("label_with_category")); QVERIFY(label); - KPIM::TagWidget *categoryEdit = w->findChild(QStringLiteral("CategoryEdit")); + auto categoryEdit = w->findChild(QStringLiteral("CategoryEdit")); QVERIFY(categoryEdit); label = w->findChild(QStringLiteral("label_in_addressbook")); diff --git a/src/filter/filteractions/filteractionaddtoaddressbook.cpp b/src/filter/filteractions/filteractionaddtoaddressbook.cpp --- a/src/filter/filteractions/filteractionaddtoaddressbook.cpp +++ b/src/filter/filteractions/filteractionaddtoaddressbook.cpp @@ -20,7 +20,9 @@ #include "filteractionaddtoaddressbook.h" #include -#include + +#include +#include #include #include @@ -30,6 +32,7 @@ #include #include +#include using namespace MailCommon; @@ -124,7 +127,7 @@ label->setObjectName(QStringLiteral("label_with_category")); layout->addWidget(label, 0, 1); - KPIM::TagWidget *categoryEdit = new KPIM::TagWidget(widget); + auto categoryEdit = new Akonadi::TagWidget(widget); categoryEdit->setObjectName(QStringLiteral("CategoryEdit")); layout->addWidget(categoryEdit, 0, 2); @@ -142,14 +145,35 @@ layout->addWidget(collectionComboBox, 1, 2); connect(headerCombo, QOverload::of(&KComboBox::currentIndexChanged), this, &FilterActionAddToAddressBook::filterActionModified); connect(collectionComboBox, QOverload::of(&Akonadi::CollectionComboBox::activated), this, &FilterActionAddToAddressBook::filterActionModified); - connect(categoryEdit, SIGNAL(selectionChanged(QStringList)), - this, SIGNAL(filterActionModified())); + connect(categoryEdit, &Akonadi::TagWidget::selectionChanged, this, &FilterActionAddToAddressBook::filterActionModified); setParamWidgetValue(widget); return widget; } +namespace { + +Akonadi::Tag::List namesToTags(const QStringList &names) +{ + Akonadi::Tag::List tags; + tags.reserve(names.size()); + std::transform(names.cbegin(), names.cend(), std::back_inserter(tags), + [](const QString &name) { return Akonadi::Tag{name}; }); + return tags; +} + +QStringList tagsToNames(const Akonadi::Tag::List &tags) +{ + QStringList names; + names.reserve(tags.size()); + std::transform(tags.cbegin(), tags.cend(), std::back_inserter(names), + std::bind(&Akonadi::Tag::name, std::placeholders::_1)); + return names; +} + +} + void FilterActionAddToAddressBook::setParamWidgetValue(QWidget *paramWidget) const { const auto headerCombo = paramWidget->findChild(QStringLiteral("HeaderComboBox")); @@ -162,9 +186,9 @@ headerCombo->setCurrentIndex(headerCombo->findData(mHeaderType)); - KPIM::TagWidget *categoryEdit = paramWidget->findChild(QStringLiteral("CategoryEdit")); + auto categoryEdit = paramWidget->findChild(QStringLiteral("CategoryEdit")); Q_ASSERT(categoryEdit); - categoryEdit->setSelection(mCategory.split(QLatin1Char(';'))); + categoryEdit->setSelection(namesToTags(mCategory.split(QLatin1Char(';')))); Akonadi::CollectionComboBox *collectionComboBox = paramWidget->findChild(QStringLiteral("AddressBookComboBox")); Q_ASSERT(collectionComboBox); @@ -178,9 +202,9 @@ Q_ASSERT(headerCombo); mHeaderType = static_cast(headerCombo->itemData(headerCombo->currentIndex()).toInt()); - const KPIM::TagWidget *categoryEdit = paramWidget->findChild(QStringLiteral("CategoryEdit")); + const auto categoryEdit = paramWidget->findChild(QStringLiteral("CategoryEdit")); Q_ASSERT(categoryEdit); - mCategory = categoryEdit->selection().join(QLatin1Char(';')); + mCategory = tagsToNames(categoryEdit->selection()).join(QLatin1Char(';')); const Akonadi::CollectionComboBox *collectionComboBox = paramWidget->findChild(QStringLiteral("AddressBookComboBox")); Q_ASSERT(collectionComboBox); @@ -205,9 +229,9 @@ Q_ASSERT(headerCombo); headerCombo->setCurrentIndex(0); - KPIM::TagWidget *categoryEdit = paramWidget->findChild(QStringLiteral("CategoryEdit")); + auto categoryEdit = paramWidget->findChild(QStringLiteral("CategoryEdit")); Q_ASSERT(categoryEdit); - categoryEdit->setSelection(mCategory.split(QLatin1Char(';'))); + categoryEdit->setSelection(namesToTags(mCategory.split(QLatin1Char(';')))); } QString FilterActionAddToAddressBook::argsAsString() const