Messagelib

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

KDE's Doxygen guidelines are available online.