File indexing completed on 2024-12-22 05:01:13

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "kmailplugincheckbeforedeletingmanagerinterface.h"
0008 #include "kmail_debug.h"
0009 #include <MessageViewer/MessageViewerCheckBeforeDeletingInterface>
0010 #include <MessageViewer/MessageViewerCheckBeforeDeletingPlugin>
0011 #include <MessageViewer/MessageViewerCheckBeforeDeletingPluginManager>
0012 
0013 KMailPluginCheckBeforeDeletingManagerInterface::KMailPluginCheckBeforeDeletingManagerInterface(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 KMailPluginCheckBeforeDeletingManagerInterface::~KMailPluginCheckBeforeDeletingManagerInterface() = default;
0019 
0020 void KMailPluginCheckBeforeDeletingManagerInterface::initializePlugins()
0021 {
0022     if (mWasInitialized) {
0023         qCDebug(KMAIL_LOG) << "KMailPluginCheckBeforeDeletingManagerInterface : Plugin was already initialized. This is a bug";
0024         return;
0025     }
0026     if (!mParentWidget) {
0027         qCDebug(KMAIL_LOG) << "KMailPluginCheckBeforeDeletingManagerInterface : Parent is null. This is a bug";
0028     }
0029     const QList<MessageViewer::MessageViewerCheckBeforeDeletingPlugin *> lstPlugin =
0030         MessageViewer::MessageViewerCheckBeforeDeletingPluginManager::self()->pluginsList();
0031     for (MessageViewer::MessageViewerCheckBeforeDeletingPlugin *plugin : lstPlugin) {
0032         if (plugin->isEnabled()) {
0033             auto interface = static_cast<MessageViewer::MessageViewerCheckBeforeDeletingInterface *>(plugin->createInterface(this));
0034             interface->setParentWidget(mParentWidget);
0035             interface->createActions(mActionCollection);
0036             mActions.append(interface->actions());
0037             mListPluginInterface.append(interface);
0038         }
0039     }
0040     mWasInitialized = true;
0041 }
0042 
0043 QWidget *KMailPluginCheckBeforeDeletingManagerInterface::parentWidget() const
0044 {
0045     return mParentWidget;
0046 }
0047 
0048 void KMailPluginCheckBeforeDeletingManagerInterface::setActionCollection(KActionCollection *ac)
0049 {
0050     mActionCollection = ac;
0051 }
0052 
0053 const QList<QAction *> KMailPluginCheckBeforeDeletingManagerInterface::actions() const
0054 {
0055     return mActions;
0056 }
0057 
0058 void KMailPluginCheckBeforeDeletingManagerInterface::setParentWidget(QWidget *newParentWidget)
0059 {
0060     mParentWidget = newParentWidget;
0061 }
0062 
0063 Akonadi::Item::List KMailPluginCheckBeforeDeletingManagerInterface::confirmBeforeDeleting(const Akonadi::Item::List &list)
0064 {
0065     Akonadi::Item::List currentList = list;
0066     for (MessageViewer::MessageViewerCheckBeforeDeletingInterface *interface : std::as_const(mListPluginInterface)) {
0067         currentList = interface->exec(currentList);
0068     }
0069     return currentList;
0070 }
0071 
0072 #include "moc_kmailplugincheckbeforedeletingmanagerinterface.cpp"