gepetto-viewer 6.0.0
An user-friendly Graphical Interface
Loading...
Searching...
No Matches
pluginmanagerdialog.hh
Go to the documentation of this file.
1// Copyright (c) 2015-2018, LAAS-CNRS
2// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3//
4// This file is part of gepetto-viewer.
5// gepetto-viewer is free software: you can redistribute it
6// and/or modify it under the terms of the GNU Lesser General Public
7// License as published by the Free Software Foundation, either version
8// 3 of the License, or (at your option) any later version.
9//
10// gepetto-viewer is distributed in the hope that it will be
11// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13// General Lesser Public License for more details. You should have
14// received a copy of the GNU Lesser General Public License along with
15// gepetto-viewer not, see <http://www.gnu.org/licenses/>.
16
17#ifndef GEPETTO_GUI_PLUGINMANAGERDIALOG_HH
18#define GEPETTO_GUI_PLUGINMANAGERDIALOG_HH
19
20#include <QDialog>
21#include <QDir>
22#include <QMap>
23#include <QPluginLoader>
24#include <QSignalMapper>
25#include <QTableWidgetItem>
27
28namespace Ui {
29class PluginManagerDialog;
30}
31
32namespace gepetto {
33namespace gui {
35 public:
36 typedef QPair<QString, QPluginLoader*> Pair;
37 typedef QMap<QString, QPluginLoader*> Map;
38 typedef QPair<QString, QString> PyPair;
39 typedef QMap<QString, QString> PyMap;
40
41 ~PluginManager() { qDeleteAll(plugins_); }
42
43 const Map& plugins() const { return plugins_; }
44
45 const PyMap& pyplugins() const { return pyplugins_; }
46
47 template <typename Interface>
48 Interface* getFirstOf();
49
50 template <typename Interface>
51 QList<Interface*> get();
52
53 static QIcon icon(const QPluginLoader* pl);
54
55 static QString status(const QPluginLoader* pl);
56
57 static void addPluginDir(const QString& path);
58
59 void declareAllPlugins(QWidget* parent = NULL);
60
61 bool declarePlugin(const QString& name, QWidget* parent = NULL);
62
63 bool loadPlugin(const QString& name);
64
65 bool initPlugin(const QString& name);
66
67 bool unloadPlugin(const QString& name);
68
70
72
73 bool declarePyPlugin(const QString& name);
74
75 bool loadPyPlugin(const QString& name);
76
77 bool unloadPyPlugin(const QString& name);
78
79 bool isPyPluginLoaded(const QString& name);
80
82
83 private:
84 template <typename Interface>
85 static const Interface* const_instance_cast(const QPluginLoader* pl);
86
87 QMap<QString, QPluginLoader*> plugins_;
88 static QList<QDir> pluginDirs_;
89 QMap<QString, QString> pyplugins_;
90};
91
92class PluginManagerDialog : public QDialog {
93 Q_OBJECT
94
95 public:
96 explicit PluginManagerDialog(PluginManager* pm, QWidget* parent = 0);
98
99 public slots:
100 void onItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous);
101 void contextMenu(const QPoint& pos);
102 void load(const QString& name);
103 void unload(const QString& name);
104
105 // void pyOnItemChanged (QTableWidgetItem* current, QTableWidgetItem*
106 // previous);
107 void pyContextMenu(const QPoint& pos);
108 void pyLoad(const QString& name);
109 void pyUnload(const QString& name);
110
112 void save();
113
114 private:
115 static const int P_NAME;
116 static const int P_FILE;
117 static const int P_FULLPATH;
118 static const int P_VERSION;
119
120 void updateList();
121
122 ::Ui::PluginManagerDialog* ui_;
123
124 PluginManager* pm_;
125};
126
127template <typename Interface>
129 foreach (QPluginLoader* p, plugins_) {
130 if (p->isLoaded()) {
131 PluginInterface* check = qobject_cast<PluginInterface*>(p->instance());
132 if (check && check->isInit()) {
133 Interface* pi = qobject_cast<Interface*>(p->instance());
134 if (pi) return pi;
135 }
136 }
137 }
138 return NULL;
139}
140
141template <typename Interface>
142QList<Interface*> PluginManager::get() {
143 QList<Interface*> list;
144 foreach (QPluginLoader* p, plugins_) {
145 if (p->isLoaded()) {
146 PluginInterface* check = qobject_cast<PluginInterface*>(p->instance());
147 if (check && check->isInit()) {
148 Interface* pi = qobject_cast<Interface*>(p->instance());
149 if (pi) list.append(pi);
150 }
151 }
152 }
153 return list;
154}
155
156template <typename Interface>
157const Interface* PluginManager::const_instance_cast(const QPluginLoader* pl) {
158 return (const Interface*)qobject_cast<Interface*>(
159 const_cast<QPluginLoader*>(pl)->instance());
160}
161} // namespace gui
162} // namespace gepetto
163
164#endif // GEPETTO_GUI_PLUGINMANAGERDIALOG_HH
Definition plugin-interface.hh:34
bool isInit() const
Definition plugin-interface.hh:51
Definition pluginmanagerdialog.hh:92
PluginManagerDialog(PluginManager *pm, QWidget *parent=0)
void contextMenu(const QPoint &pos)
void pyUnload(const QString &name)
void pyContextMenu(const QPoint &pos)
void pyLoad(const QString &name)
void unload(const QString &name)
void onItemChanged(QTableWidgetItem *current, QTableWidgetItem *previous)
void load(const QString &name)
Definition pluginmanagerdialog.hh:34
bool initPlugin(const QString &name)
const Map & plugins() const
Definition pluginmanagerdialog.hh:43
bool unloadPyPlugin(const QString &name)
~PluginManager()
Definition pluginmanagerdialog.hh:41
bool unloadPlugin(const QString &name)
bool loadPlugin(const QString &name)
bool loadPyPlugin(const QString &name)
QPair< QString, QString > PyPair
Definition pluginmanagerdialog.hh:38
bool declarePlugin(const QString &name, QWidget *parent=NULL)
void declareAllPlugins(QWidget *parent=NULL)
QMap< QString, QPluginLoader * > Map
Definition pluginmanagerdialog.hh:37
bool declarePyPlugin(const QString &name)
Interface * getFirstOf()
Definition pluginmanagerdialog.hh:128
QPair< QString, QPluginLoader * > Pair
Definition pluginmanagerdialog.hh:36
static QString status(const QPluginLoader *pl)
static void addPluginDir(const QString &path)
bool isPyPluginLoaded(const QString &name)
QMap< QString, QString > PyMap
Definition pluginmanagerdialog.hh:39
const PyMap & pyplugins() const
Definition pluginmanagerdialog.hh:45
QList< Interface * > get()
Definition pluginmanagerdialog.hh:142
static QIcon icon(const QPluginLoader *pl)
Definition dialogloadenvironment.hh:23
Definition action-search-bar.hh:27