Messagelib

viewerplugintoolmanager.cpp
1 /*
2  SPDX-FileCopyrightText: 2015-2021 Laurent Montel <[email protected]>
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 <QVector>
12 
13 using namespace MessageViewer;
14 
15 class MessageViewer::ViewerPluginToolManagerPrivate
16 {
17 public:
18  ViewerPluginToolManagerPrivate(ViewerPluginToolManager *qq, QWidget *parentWidget)
19  : mParentWidget(parentWidget)
20  , q(qq)
21  {
22  }
23 
24  void setPluginName(const QString &pluginName);
25  Q_REQUIRED_RESULT QString pluginDirectory() const;
26  Q_REQUIRED_RESULT 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  Q_REQUIRED_RESULT QList<QAction *> actionList(ViewerPluginInterface::SpecificFeatureTypes features) const;
34  KActionCollection *mActionCollection = nullptr;
35  QWidget *mParentWidget = nullptr;
36  ViewerPluginToolManager *const q;
37  void setPluginDirectory(const QString &directory);
38 };
39 
40 void ViewerPluginToolManagerPrivate::setPluginDirectory(const QString &directory)
41 {
42  MessageViewer::ViewerPluginManager::self()->setPluginDirectory(directory);
43 }
44 
45 QString ViewerPluginToolManagerPrivate::pluginDirectory() const
46 {
47  return MessageViewer::ViewerPluginManager::self()->pluginDirectory();
48 }
49 
50 void ViewerPluginToolManagerPrivate::setPluginName(const QString &pluginName)
51 {
52  MessageViewer::ViewerPluginManager::self()->setPluginName(pluginName);
53 }
54 
55 QString ViewerPluginToolManagerPrivate::pluginName() const
56 {
57  return MessageViewer::ViewerPluginManager::self()->pluginName();
58 }
59 
60 void ViewerPluginToolManagerPrivate::refreshActionList()
61 {
62  for (MessageViewer::ViewerPluginInterface *interface : std::as_const(mListInterface)) {
63  interface->refreshActionList(mActionCollection);
64  }
65 }
66 
67 void ViewerPluginToolManagerPrivate::createView()
68 {
69  const QVector<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 
80 void ViewerPluginToolManagerPrivate::closeAllTools()
81 {
82  for (MessageViewer::ViewerPluginInterface *interface : std::as_const(mListInterface)) {
83  interface->closePlugin();
84  }
85 }
86 
87 void ViewerPluginToolManagerPrivate::setActionCollection(KActionCollection *ac)
88 {
89  mActionCollection = ac;
90 }
91 
92 QList<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 
107 void ViewerPluginToolManagerPrivate::updateActions(const Akonadi::Item &messageItem)
108 {
109  for (MessageViewer::ViewerPluginInterface *interface : std::as_const(mListInterface)) {
110  interface->updateAction(messageItem);
111  }
112 }
113 
114 ViewerPluginToolManager::ViewerPluginToolManager(QWidget *parentWidget, QObject *parent)
115  : QObject(parent)
116  , d(new MessageViewer::ViewerPluginToolManagerPrivate(this, parentWidget))
117 {
118 }
119 
120 ViewerPluginToolManager::~ViewerPluginToolManager() = default;
121 
122 void ViewerPluginToolManager::closeAllTools()
123 {
124  d->closeAllTools();
125 }
126 
128 {
129  d->refreshActionList();
130 }
131 
132 void ViewerPluginToolManager::createView()
133 {
134  d->createView();
135 }
136 
137 void ViewerPluginToolManager::setActionCollection(KActionCollection *ac)
138 {
139  d->setActionCollection(ac);
140 }
141 
142 void ViewerPluginToolManager::setPluginDirectory(const QString &directory)
143 {
144  d->setPluginDirectory(directory);
145 }
146 
147 QString ViewerPluginToolManager::pluginDirectory() const
148 {
149  return d->pluginDirectory();
150 }
151 
152 void ViewerPluginToolManager::setPluginName(const QString &pluginName)
153 {
154  d->setPluginName(pluginName);
155 }
156 
157 QString ViewerPluginToolManager::pluginName() const
158 {
159  return d->pluginName();
160 }
161 
162 bool ViewerPluginToolManager::initializePluginList()
163 {
164  return MessageViewer::ViewerPluginManager::self()->initializePluginList();
165 }
166 
167 QList<QAction *> ViewerPluginToolManager::viewerPluginActionList(ViewerPluginInterface::SpecificFeatureTypes features) const
168 {
169  return d->actionList(features);
170 }
171 
172 void ViewerPluginToolManager::updateActions(const Akonadi::Item &messageItem)
173 {
174  d->updateActions(messageItem);
175 }
The ViewerPlugin class.
Definition: viewerplugin.h:22
void append(const T &value)
The ViewerPluginToolManager class.
void refreshActionList()
refreshActionList Refresh the list of action menu.
The ViewerPluginInterface class.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Nov 30 2021 23:05:48 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.