File indexing completed on 2024-11-24 04:43:05

0001 /*
0002    SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "searchduplicatesplugininterface.h"
0008 #include "searchduplicate/searchandmergecontactduplicatecontactdialog.h"
0009 
0010 #include <KActionCollection>
0011 #include <KLocalizedString>
0012 #include <QAction>
0013 
0014 SearchDuplicatesPluginInterface::SearchDuplicatesPluginInterface(QObject *parent)
0015     : PimCommon::GenericPluginInterface(parent)
0016 {
0017 }
0018 
0019 SearchDuplicatesPluginInterface::~SearchDuplicatesPluginInterface() = default;
0020 
0021 void SearchDuplicatesPluginInterface::createAction(KActionCollection *ac)
0022 {
0023     QAction *action = ac->addAction(QStringLiteral("search_duplicate_contacts"));
0024     action->setText(i18n("Search Duplicate Contacts..."));
0025     connect(action, &QAction::triggered, this, &SearchDuplicatesPluginInterface::slotActivated);
0026     const PimCommon::ActionType type(action, PimCommon::ActionType::Tools);
0027     addActionType(type);
0028 }
0029 
0030 void SearchDuplicatesPluginInterface::slotActivated()
0031 {
0032     Q_EMIT emitPluginActivated(this);
0033 }
0034 
0035 void SearchDuplicatesPluginInterface::exec()
0036 {
0037     KABMergeContacts::SearchAndMergeContactDuplicateContactDialog dlg(parentWidget());
0038     dlg.searchPotentialDuplicateContacts(mListItems);
0039     dlg.exec();
0040 }
0041 
0042 void SearchDuplicatesPluginInterface::setItems(const Akonadi::Item::List &items)
0043 {
0044     Akonadi::Item::List onlyContactList;
0045     for (const Akonadi::Item &item : items) {
0046         if (item.isValid() && item.hasPayload<KContacts::Addressee>()) {
0047             onlyContactList.append(item);
0048         }
0049     }
0050 
0051     mListItems = onlyContactList;
0052 }
0053 
0054 PimCommon::GenericPluginInterface::RequireTypes SearchDuplicatesPluginInterface::requiresFeatures() const
0055 {
0056     return PimCommon::GenericPluginInterface::Items;
0057 }