File indexing completed on 2024-10-27 04:50:58

0001 /*
0002    SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "kmailplugineditorcheckbeforesendmanagerinterface.h"
0008 #include "kmail_debug.h"
0009 
0010 #include <MessageComposer/PluginEditorCheckBeforeSend>
0011 #include <MessageComposer/PluginEditorCheckBeforeSendInterface>
0012 #include <MessageComposer/PluginEditorCheckBeforeSendManager>
0013 
0014 KMailPluginEditorCheckBeforeSendManagerInterface::KMailPluginEditorCheckBeforeSendManagerInterface(QObject *parent)
0015     : QObject(parent)
0016 {
0017 }
0018 
0019 KMailPluginEditorCheckBeforeSendManagerInterface::~KMailPluginEditorCheckBeforeSendManagerInterface() = default;
0020 
0021 QWidget *KMailPluginEditorCheckBeforeSendManagerInterface::parentWidget() const
0022 {
0023     return mParentWidget;
0024 }
0025 
0026 void KMailPluginEditorCheckBeforeSendManagerInterface::setParentWidget(QWidget *parentWidget)
0027 {
0028     mParentWidget = parentWidget;
0029 }
0030 
0031 void KMailPluginEditorCheckBeforeSendManagerInterface::initializePlugins()
0032 {
0033     if (!mListPluginInterface.isEmpty()) {
0034         qCWarning(KMAIL_LOG) << "Plugin was already initialized. This is a bug";
0035         return;
0036     }
0037     if (!mParentWidget) {
0038         qCWarning(KMAIL_LOG) << "KMailPluginEditorCheckBeforeSendManagerInterface : Parent is null. This is a bug";
0039     }
0040 
0041     const QList<MessageComposer::PluginEditorCheckBeforeSend *> lstPlugin = MessageComposer::PluginEditorCheckBeforeSendManager::self()->pluginsList();
0042     for (MessageComposer::PluginEditorCheckBeforeSend *plugin : lstPlugin) {
0043         if (plugin->isEnabled()) {
0044             MessageComposer::PluginEditorCheckBeforeSendInterface *interface = plugin->createInterface(this);
0045             interface->setParentWidget(mParentWidget);
0046             interface->reloadConfig();
0047             mListPluginInterface.append(interface);
0048         }
0049     }
0050 }
0051 
0052 bool KMailPluginEditorCheckBeforeSendManagerInterface::execute(const MessageComposer::PluginEditorCheckBeforeSendParams &params) const
0053 {
0054     for (MessageComposer::PluginEditorCheckBeforeSendInterface *interface : std::as_const(mListPluginInterface)) {
0055         if (!interface->exec(params)) {
0056             return false;
0057         }
0058     }
0059     return true;
0060 }
0061 
0062 #include "moc_kmailplugineditorcheckbeforesendmanagerinterface.cpp"