| Line |
Branch |
Exec |
Source |
| 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> |
| 26 |
|
|
#include <gepetto/gui/plugin-interface.hh> |
| 27 |
|
|
|
| 28 |
|
|
namespace Ui { |
| 29 |
|
|
class PluginManagerDialog; |
| 30 |
|
|
} |
| 31 |
|
|
|
| 32 |
|
|
namespace gepetto { |
| 33 |
|
|
namespace gui { |
| 34 |
|
|
class PluginManager { |
| 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 |
|
|
|
| 69 |
|
|
void clearPlugins(); |
| 70 |
|
|
|
| 71 |
|
|
void declareAllPyPlugins(); |
| 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 |
|
|
|
| 81 |
|
|
void clearPyPlugins(); |
| 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 |
|
|
|
| 92 |
|
|
class PluginManagerDialog : public QDialog { |
| 93 |
|
✗ |
Q_OBJECT |
| 94 |
|
|
|
| 95 |
|
|
public: |
| 96 |
|
|
explicit PluginManagerDialog(PluginManager* pm, QWidget* parent = 0); |
| 97 |
|
|
~PluginManagerDialog(); |
| 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 |
|
|
|
| 111 |
|
|
void declareAll(); |
| 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 |
|
|
|
| 127 |
|
|
template <typename Interface> |
| 128 |
|
|
Interface* PluginManager::getFirstOf() { |
| 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 |
|
|
|
| 141 |
|
|
template <typename Interface> |
| 142 |
|
✗ |
QList<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 |
|
|
|
| 156 |
|
|
template <typename Interface> |
| 157 |
|
✗ |
const 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 |
| 165 |
|
|
|