File indexing completed on 2024-10-27 04:50:59
0001 /* 0002 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kmailplugingrammareditormanagerinterface.h" 0008 #include "kmail_debug.h" 0009 #include <MessageComposer/PluginEditorGrammarCustomToolsViewInterface> 0010 #include <MessageComposer/PluginEditorGrammarManager> 0011 #include <PimCommon/CustomToolsPlugin> 0012 #include <PimCommon/CustomToolsWidgetng> 0013 0014 KMailPluginGrammarEditorManagerInterface::KMailPluginGrammarEditorManagerInterface(QObject *parent) 0015 : QObject(parent) 0016 { 0017 } 0018 0019 KPIMTextEdit::RichTextComposer *KMailPluginGrammarEditorManagerInterface::richTextEditor() const 0020 { 0021 return mRichTextEditor; 0022 } 0023 0024 void KMailPluginGrammarEditorManagerInterface::setRichTextEditor(KPIMTextEdit::RichTextComposer *richTextEditor) 0025 { 0026 mRichTextEditor = richTextEditor; 0027 } 0028 0029 QWidget *KMailPluginGrammarEditorManagerInterface::parentWidget() const 0030 { 0031 return mParentWidget; 0032 } 0033 0034 void KMailPluginGrammarEditorManagerInterface::setParentWidget(QWidget *parentWidget) 0035 { 0036 mParentWidget = parentWidget; 0037 } 0038 0039 KActionCollection *KMailPluginGrammarEditorManagerInterface::actionCollection() const 0040 { 0041 return mActionCollection; 0042 } 0043 0044 void KMailPluginGrammarEditorManagerInterface::setActionCollection(KActionCollection *actionCollection) 0045 { 0046 mActionCollection = actionCollection; 0047 } 0048 0049 PimCommon::CustomToolsWidgetNg *KMailPluginGrammarEditorManagerInterface::customToolsWidget() const 0050 { 0051 return mCustomToolsWidget; 0052 } 0053 0054 void KMailPluginGrammarEditorManagerInterface::setCustomToolsWidget(PimCommon::CustomToolsWidgetNg *customToolsWidget) 0055 { 0056 mCustomToolsWidget = customToolsWidget; 0057 } 0058 0059 void KMailPluginGrammarEditorManagerInterface::initializePlugins() 0060 { 0061 if (mWasInitialized) { 0062 qCDebug(KMAIL_LOG) << "KMailPluginGrammarEditorManagerInterface : Plugin was already initialized. This is a bug"; 0063 return; 0064 } 0065 if (!mRichTextEditor) { 0066 qCDebug(KMAIL_LOG) << "KMailPluginGrammarEditorManagerInterface : Richtexteditor is null. This is a bug"; 0067 return; 0068 } 0069 if (!mParentWidget) { 0070 qCDebug(KMAIL_LOG) << "KMailPluginGrammarEditorManagerInterface : Parent is null. This is a bug"; 0071 } 0072 if (!mCustomToolsWidget) { 0073 qCDebug(KMAIL_LOG) << "KMailPluginGrammarEditorManagerInterface : mCustomToolsWidget is null. This is a bug"; 0074 return; 0075 } 0076 0077 const QList<PimCommon::CustomToolsPlugin *> lstPlugin = MessageComposer::PluginEditorGrammarManager::self()->pluginsList(); 0078 for (PimCommon::CustomToolsPlugin *plugin : lstPlugin) { 0079 if (plugin->isEnabled()) { 0080 auto interface = 0081 static_cast<MessageComposer::PluginEditorGrammarCustomToolsViewInterface *>(plugin->createView(mActionCollection, mCustomToolsWidget)); 0082 mCustomToolsWidget->addCustomToolViewInterface(interface); 0083 interface->setParentWidget(mParentWidget); 0084 interface->setRichTextEditor(mRichTextEditor); 0085 } 0086 } 0087 mWasInitialized = true; 0088 } 0089 0090 #include "moc_kmailplugingrammareditormanagerinterface.cpp"