Messagelib

viewerplugintoolmanager.cpp
1/*
2 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "viewerplugintoolmanager.h"
8#include "viewerplugin.h"
9#include "viewerpluginmanager.h"
10
11#include <QList>
12
13using namespace MessageViewer;
14
15class MessageViewer::ViewerPluginToolManagerPrivate
16{
17public:
18 ViewerPluginToolManagerPrivate(ViewerPluginToolManager *qq, QWidget *parentWidget)
19 : mParentWidget(parentWidget)
20 , q(qq)
21 {
22 }
23
24 void setPluginName(const QString &pluginName);
25 [[nodiscard]] QString pluginDirectory() const;
26 [[nodiscard]] QString pluginName() const;
27 void createView();
28 void refreshActionList();
29 void closeAllTools();
30 void setActionCollection(KActionCollection *ac);
31 void updateActions(const Akonadi::Item &messageItem);
32 [[nodiscard]] QList<QAction *> actionList(ViewerPluginInterface::SpecificFeatureTypes features) const;
34 KActionCollection *mActionCollection = nullptr;
35 QWidget *mParentWidget = nullptr;
37 void setPluginDirectory(const QString &directory);
38};
39
40void ViewerPluginToolManagerPrivate::setPluginDirectory(const QString &directory)
41{
42 MessageViewer::ViewerPluginManager::self()->setPluginDirectory(directory);
43}
44
45QString ViewerPluginToolManagerPrivate::pluginDirectory() const
46{
47 return MessageViewer::ViewerPluginManager::self()->pluginDirectory();
48}
49
50void ViewerPluginToolManagerPrivate::setPluginName(const QString &pluginName)
51{
52 MessageViewer::ViewerPluginManager::self()->setPluginName(pluginName);
53}
54
55QString ViewerPluginToolManagerPrivate::pluginName() const
56{
57 return MessageViewer::ViewerPluginManager::self()->pluginName();
58}
59
60void ViewerPluginToolManagerPrivate::refreshActionList()
61{
62 for (MessageViewer::ViewerPluginInterface *interface : std::as_const(mListInterface)) {
63 interface->refreshActionList(mActionCollection);
64 }
65}
66
67void ViewerPluginToolManagerPrivate::createView()
68{
69 const QList<MessageViewer::ViewerPlugin *> listPlugin = MessageViewer::ViewerPluginManager::self()->pluginsList();
70 for (MessageViewer::ViewerPlugin *plugin : listPlugin) {
71 if (plugin->isEnabled()) {
72 MessageViewer::ViewerPluginInterface *interface = plugin->createView(mParentWidget, mActionCollection);
73 q->connect(interface, &MessageViewer::ViewerPluginInterface::activatePlugin, q, &ViewerPluginToolManager::activatePlugin);
74 q->connect(plugin, &ViewerPlugin::configChanged, q, &ViewerPluginToolManager::refreshActionList);
75 mListInterface.append(interface);
76 }
77 }
78}
79
80void ViewerPluginToolManagerPrivate::closeAllTools()
81{
82 for (MessageViewer::ViewerPluginInterface *interface : std::as_const(mListInterface)) {
83 interface->closePlugin();
84 }
85}
86
87void ViewerPluginToolManagerPrivate::setActionCollection(KActionCollection *ac)
88{
89 mActionCollection = ac;
90}
91
92QList<QAction *> ViewerPluginToolManagerPrivate::actionList(ViewerPluginInterface::SpecificFeatureTypes features) const
93{
94 QList<QAction *> lstAction;
95 for (MessageViewer::ViewerPluginInterface *interface : std::as_const(mListInterface)) {
96 if (features & ViewerPluginInterface::All) {
97 lstAction.append(interface->actions());
98 } else {
99 if (interface->featureTypes() & features) {
100 lstAction.append(interface->actions());
101 }
102 }
103 }
104 return lstAction;
105}
106
107void ViewerPluginToolManagerPrivate::updateActions(const Akonadi::Item &messageItem)
108{
109 for (MessageViewer::ViewerPluginInterface *interface : std::as_const(mListInterface)) {
110 interface->updateAction(messageItem);
111 }
112}
113
114ViewerPluginToolManager::ViewerPluginToolManager(QWidget *parentWidget, QObject *parent)
115 : QObject(parent)
116 , d(new MessageViewer::ViewerPluginToolManagerPrivate(this, parentWidget))
117{
118}
119
120ViewerPluginToolManager::~ViewerPluginToolManager() = default;
121
122void ViewerPluginToolManager::closeAllTools()
123{
124 d->closeAllTools();
125}
126
128{
129 d->refreshActionList();
130}
131
132void ViewerPluginToolManager::createView()
133{
134 d->createView();
135}
136
137void ViewerPluginToolManager::setActionCollection(KActionCollection *ac)
138{
139 d->setActionCollection(ac);
140}
141
142void ViewerPluginToolManager::setPluginDirectory(const QString &directory)
143{
144 d->setPluginDirectory(directory);
145}
146
147QString ViewerPluginToolManager::pluginDirectory() const
148{
149 return d->pluginDirectory();
150}
151
152void ViewerPluginToolManager::setPluginName(const QString &pluginName)
153{
154 d->setPluginName(pluginName);
155}
156
157QString ViewerPluginToolManager::pluginName() const
158{
159 return d->pluginName();
160}
161
162bool ViewerPluginToolManager::initializePluginList()
163{
164 return MessageViewer::ViewerPluginManager::self()->initializePluginList();
165}
166
167QList<QAction *> ViewerPluginToolManager::viewerPluginActionList(ViewerPluginInterface::SpecificFeatureTypes features) const
168{
169 return d->actionList(features);
170}
171
172void ViewerPluginToolManager::updateActions(const Akonadi::Item &messageItem)
173{
174 d->updateActions(messageItem);
175}
176
177#include "moc_viewerplugintoolmanager.cpp"
The ViewerPluginInterface class.
The ViewerPluginToolManager class.
void refreshActionList()
refreshActionList Refresh the list of action menu.
The ViewerPlugin class.
void append(QList< T > &&value)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.