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

0001 /*
0002    SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "kmailplugineditorinitmanagerinterface.h"
0008 #include "kmail_debug.h"
0009 #include <MessageComposer/PluginEditorInit>
0010 #include <MessageComposer/PluginEditorInitInterface>
0011 #include <MessageComposer/PluginEditorInitManager>
0012 
0013 KMailPluginEditorInitManagerInterface::KMailPluginEditorInitManagerInterface(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 KPIMTextEdit::RichTextComposer *KMailPluginEditorInitManagerInterface::richTextEditor() const
0019 {
0020     return mRichTextEditor;
0021 }
0022 
0023 void KMailPluginEditorInitManagerInterface::setRichTextEditor(KPIMTextEdit::RichTextComposer *richTextEditor)
0024 {
0025     mRichTextEditor = richTextEditor;
0026 }
0027 
0028 QWidget *KMailPluginEditorInitManagerInterface::parentWidget() const
0029 {
0030     return mParentWidget;
0031 }
0032 
0033 void KMailPluginEditorInitManagerInterface::setParentWidget(QWidget *parentWidget)
0034 {
0035     mParentWidget = parentWidget;
0036 }
0037 
0038 void KMailPluginEditorInitManagerInterface::initializePlugins()
0039 {
0040     if (mWasInitialized) {
0041         qCDebug(KMAIL_LOG) << "KMailPluginEditorInitManagerInterface : Plugin was already initialized. This is a bug";
0042         return;
0043     }
0044     if (!mRichTextEditor) {
0045         qCDebug(KMAIL_LOG) << "KMailPluginEditorInitManagerInterface : Richtexteditor is null. This is a bug";
0046         return;
0047     }
0048     if (!mParentWidget) {
0049         qCDebug(KMAIL_LOG) << "KMailPluginEditorInitManagerInterface : Parent is null. This is a bug";
0050     }
0051 
0052     const QList<MessageComposer::PluginEditorInit *> lstPlugin = MessageComposer::PluginEditorInitManager::self()->pluginsList();
0053     for (MessageComposer::PluginEditorInit *plugin : lstPlugin) {
0054         if (plugin->isEnabled()) {
0055             MessageComposer::PluginEditorInitInterface *interface = plugin->createInterface(this);
0056             interface->setParentWidget(mParentWidget);
0057             interface->setRichTextEditor(mRichTextEditor);
0058             interface->reloadConfig();
0059             if (!interface->exec()) {
0060                 qCWarning(KMAIL_LOG) << "KMailPluginEditorInitManagerInterface::initializePlugins: error during execution of plugin:" << interface;
0061             }
0062         }
0063     }
0064     mWasInitialized = true;
0065 }
0066 
0067 #include "moc_kmailplugineditorinitmanagerinterface.cpp"