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

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 "mergecontactsplugininterface.h"
0008 
0009 #include <KActionCollection>
0010 #include <KLocalizedString>
0011 #include <QAction>
0012 
0013 #include "manualmerge/mergecontactsdialog.h"
0014 
0015 MergeContactsPluginInterface::MergeContactsPluginInterface(QObject *parent)
0016     : PimCommon::GenericPluginInterface(parent)
0017 {
0018 }
0019 
0020 MergeContactsPluginInterface::~MergeContactsPluginInterface() = default;
0021 
0022 void MergeContactsPluginInterface::createAction(KActionCollection *ac)
0023 {
0024     QAction *action = ac->addAction(QStringLiteral("merge_contacts"));
0025     action->setText(i18n("Merge Contacts..."));
0026     connect(action, &QAction::triggered, this, &MergeContactsPluginInterface::slotActivated);
0027     PimCommon::ActionType type(action, PimCommon::ActionType::Tools);
0028     addActionType(type);
0029 }
0030 
0031 void MergeContactsPluginInterface::slotActivated()
0032 {
0033     Q_EMIT emitPluginActivated(this);
0034 }
0035 
0036 void MergeContactsPluginInterface::setCurrentItems(const Akonadi::Item::List &items)
0037 {
0038     Akonadi::Item::List onlyContactList;
0039     for (const Akonadi::Item &item : items) {
0040         if (item.isValid() && item.hasPayload<KContacts::Addressee>()) {
0041             onlyContactList.append(item);
0042         }
0043     }
0044 
0045     mListItems = onlyContactList;
0046 }
0047 
0048 PimCommon::GenericPluginInterface::RequireTypes MergeContactsPluginInterface::requiresFeatures() const
0049 {
0050     return PimCommon::GenericPluginInterface::CurrentItems;
0051 }
0052 
0053 void MergeContactsPluginInterface::exec()
0054 {
0055     KABMergeContacts::MergeContactsDialog dlg(parentWidget());
0056     dlg.setContacts(mListItems);
0057     dlg.exec();
0058 }