7#include "plugininterface.h"
9#include "pimcommonakonadi_debug.h"
10#include <PimCommon/GenericPluginManager>
12#include <KActionCollection>
13#include <KXMLGUIClient>
16#include <PimCommon/GenericPlugin>
20class PimCommon::PluginInterfacePrivate
23 PluginInterfacePrivate() =
default;
27 QWidget *mParentWidget =
nullptr;
33PluginInterface::PluginInterface(
QObject *parent)
35 , d(new
PimCommon::PluginInterfacePrivate)
40PluginInterface::~PluginInterface() =
default;
44 d->mActionCollection = ac;
47void PluginInterface::initializePlugins()
49 d->mGenericPluginManager->setPluginName(d->mPluginName);
50 d->mGenericPluginManager->setPluginDirectory(d->mPluginDirectory);
51 if (!d->mGenericPluginManager->initializePlugins()) {
52 qCDebug(PIMCOMMONAKONADI_LOG) <<
" Impossible to initialize plugins";
56void PluginInterface::setPluginName(
const QString &name)
58 d->mPluginName =
name;
61void PluginInterface::setPluginDirectory(
const QString &name)
63 d->mPluginDirectory =
name;
66void PluginInterface::createPluginInterface()
68 if (!d->mActionCollection) {
69 qCWarning(PIMCOMMONAKONADI_LOG) <<
"Missing action collection";
72 const auto pluginsList = d->mGenericPluginManager->pluginsList();
74 if (plugin->isEnabled()) {
76 interface->setParentWidget(d->mParentWidget);
78 interface->createAction(d->mActionCollection);
79 interface->setPlugin(plugin);
80 connect(interface, &PimCommon::GenericPluginInterface::emitPluginActivated, this, &PluginInterface::slotPluginActivated);
81 d->mListGenericInterface.append(interface);
86bool PluginInterface::initializeInterfaceRequires(PimCommon::AbstractGenericPluginInterface *interface)
92QString PluginInterface::actionXmlExtension(ActionType::Type type)
95 case PimCommon::ActionType::Tools:
96 return QStringLiteral(
"_plugins_tools");
97 case PimCommon::ActionType::Edit:
98 return QStringLiteral(
"_plugins_edit");
99 case PimCommon::ActionType::File:
100 return QStringLiteral(
"_plugins_file");
101 case PimCommon::ActionType::Action:
102 return QStringLiteral(
"_plugins_actions");
103 case PimCommon::ActionType::PopupMenu:
104 return QStringLiteral(
"_popupmenu_actions");
105 case PimCommon::ActionType::ToolBar:
106 return QStringLiteral(
"_toolbar_actions");
107 case PimCommon::ActionType::Message:
108 return QStringLiteral(
"_plugins_message");
109 case PimCommon::ActionType::Folder:
110 return QStringLiteral(
"_plugins_folder");
115void PluginInterface::slotPluginActivated(PimCommon::AbstractGenericPluginInterface *interface)
118 if (initializeInterfaceRequires(interface)) {
124void PluginInterface::setParentWidget(
QWidget *widget)
126 d->mParentWidget = widget;
133 while (localActionsType.hasNext()) {
134 localActionsType.next();
137 const QString actionlistname = prefix + PimCommon::PluginInterface::actionXmlExtension(localActionsType.key());
148 while (localActionsType.hasNext()) {
149 localActionsType.next();
152 const QString actionlistname = prefix + PimCommon::PluginInterface::actionXmlExtension(localActionsType.key());
160void PluginInterface::updateActions(
int numberOfSelectedItems,
int numberOfSelectedCollections)
163 interface->updateActions(numberOfSelectedItems, numberOfSelectedCollections);
171 const auto actionTypes = interface->actionTypes();
173 PimCommon::ActionType::Type
type = actionType.type();
177 act->setSeparator(
true);
178 lst << act << actionType.action();
179 listType.
insert(type, lst);
183 if (interface->plugin()->hasPopupMenuSupport()) {
184 type = PimCommon::ActionType::PopupMenu;
185 lst = listType.
value(type);
188 act->setSeparator(
true);
189 lst << act << actionType.action();
190 listType.
insert(type, lst);
195 if (interface->plugin()->hasToolBarSupport()) {
196 type = PimCommon::ActionType::ToolBar;
197 lst = listType.
value(type);
200 act->setSeparator(
true);
201 lst << act << actionType.action();
202 listType.
insert(type, lst);
215 return d->mGenericPluginManager->pluginsDataList();
218QString PluginInterface::configGroupName()
const
220 return d->mGenericPluginManager->configGroupName();
223QString PluginInterface::configPrefixSettingKey()
const
225 return d->mGenericPluginManager->configPrefixSettingKey();
230 return d->mGenericPluginManager->pluginFromIdentifier(
id);
233#include "moc_plugininterface.cpp"
void unplugActionList(const QString &name)
void plugActionList(const QString &name, const QList< QAction * > &actionList)
KXMLGUIFactory * factory() const
The GenericPluginInterface class.
The GenericPluginManager class.
QString name(GameStandardAction id)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
iterator insert(const Key &key, const T &value)
T value(const Key &key) const const
bool isEmpty() const const
T value(qsizetype i) const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)