Commit 18af343f authored by Dirk Wilden's avatar Dirk Wilden

added new plugin dialog

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5123 383ad7c9-94d9-4d36-a494-682f7c89f535
parent a06b85bc
......@@ -203,8 +203,7 @@ Core::init() {
connect(coreWidget_, SIGNAL(recentOpen(QAction*)) , this, SLOT(slotRecentOpen(QAction*)));
connect(coreWidget_, SIGNAL(exit()) , this, SLOT(slotExit()));
connect(coreWidget_, SIGNAL(loadPlugin()) , this, SLOT(slotLoadPlugin()));
connect(coreWidget_, SIGNAL(unloadPlugin()) , this, SLOT(slotUnloadPlugin()));
connect(coreWidget_, SIGNAL(showPlugins()) , this, SLOT(slotShowPlugins()));
connect(coreWidget_, SIGNAL(call(QString,bool&)), this, SLOT(slotCall(QString,bool&)));
......
......@@ -575,8 +575,8 @@ private:
/// Load all plugins from default plugin directory and from INI-File
void loadPlugins();
private slots:
/// Unload Plugins from menu
void slotUnloadPlugin();
/// Show Plugins Dialog
void slotShowPlugins();
/// Function for unloading Plugins
void unloadPlugin(QString name);
......
......@@ -80,7 +80,7 @@
#include <QtScript/QScriptValueIterator>
#include <ACG/QtWidgets/QtFileDialog.hh>
#include "OpenFlipper/widgets/unloadPluginsWidget/unloadPluginsWidget.hh"
#include "OpenFlipper/widgets/PluginDialog/PluginDialog.hh"
//== IMPLEMENTATION ==========================================================
......@@ -290,26 +290,29 @@ void Core::slotLoadPlugin(){
loadPlugin(filename,false);
}
/** @brief slot for unloading Plugins
/** @brief slot for showing loaded Plugins
*/
void Core::slotUnloadPlugin(){
static unloadPluginsWidget* widget = 0;
void Core::slotShowPlugins(){
//make a list of pluginNames
QStringList pluginNames;
for (uint i=0; i < plugins.size(); i++)
pluginNames << plugins[i].name;
//init and show the widget
if (!widget){
widget = new unloadPluginsWidget(pluginNames);
widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
connect( widget, SIGNAL(unload(QString)), this, SLOT(unloadPlugin(QString)));
connect( widget, SIGNAL(dontLoadPlugins(QStringList)), this, SLOT(dontLoadPlugins(QStringList)));
}else
widget->setPlugins(pluginNames);
if ( OpenFlipper::Options::gui() ){
int ret = 0;
while (ret == 0){
PluginDialog* dialog = new PluginDialog(plugins, coreWidget_);
widget->show();
//connect signals
connect(dialog, SIGNAL(unloadPlugin(QString)), this, SLOT(unloadPlugin(QString)));
connect(dialog, SIGNAL(dontLoadPlugins(QStringList)), this, SLOT(dontLoadPlugins(QStringList)));
connect(dialog, SIGNAL( loadPlugin() ), this, SLOT( slotLoadPlugin() ));
//if a plugin was deleted/loaded the dialog returns 0 and it needs to be loaded again
ret = dialog->exec();
delete dialog;
}
}
}
/** @brief Unload a Plugin with given name (slot)
......@@ -317,7 +320,7 @@ void Core::slotUnloadPlugin(){
*/
void Core::unloadPlugin(QString name){
for (uint i=0; i < plugins.size(); i++)
if (plugins[i].name == name){
if (plugins[i].rpcName == name){
if ( checkSlot( plugins[i].plugin , "exit()" ) )
QMetaObject::invokeMethod(plugins[i].plugin, "exit", Qt::DirectConnection);
......
......@@ -17,7 +17,7 @@ DIRECTORIES = ../ ../Core ../Logging \
../Scripting ../Scripting/scriptPrototypes ../Scripting/scriptWrappers ../SimpleOpt \
../widgets/aboutWidget ../widgets/addEmptyWidget ../widgets/loggerWidget \
../widgets/coreWidget ../widgets/helpBrowser \
../widgets/loadWidget ../widgets/optionsWidget ../widgets/unloadPluginsWidget \
../widgets/loadWidget ../widgets/optionsWidget ../widgets/PluginDialog \
../widgets/viewModeWidget
QMAKE_LIBDIR += $${TOPDIR}/OpenFlipper/PluginLib/lib/$${BUILDDIRECTORY}
......
#include "PluginDialog.hh"
#include <QtGui>
#include <QMessageBox>
#include <QFileDialog>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
PluginDialog::PluginDialog(std::vector<PluginInfo>& _plugins, QWidget *parent)
: QDialog(parent),
plugins_(_plugins)
{
setupUi(this);
connect(closeButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(loadButton, SIGNAL(clicked()), this, SIGNAL(loadPlugin()));
connect(loadButton, SIGNAL(clicked()), this, SLOT(reject()));
connect(unloadButton, SIGNAL(clicked()), this, SLOT(slotUnload()));
//set icons
QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
closeButton->setIcon( QIcon(iconPath + "window-close.png"));
loadButton->setIcon( QIcon(iconPath + "network-connect.png"));
unloadButton->setIcon( QIcon(iconPath + "network-disconnect.png"));
}
void PluginDialog::closeEvent(QCloseEvent *event)
{
event->accept();
accept();
}
int PluginDialog::exec()
{
for (uint i = 0; i < plugins_.size(); i++){
QFrame* frame = new QFrame();
QHBoxLayout* hlayout = new QHBoxLayout;
QLabel* name = new QLabel( plugins_[i].name );
QFont font;
font.setBold(true);
font.setPointSize(10);
name->setFont(font);
QLabel* version = new QLabel( plugins_[i].version );
// QLabel* author = new QLabel( "RWTH Computer Graphics Group" );
hlayout->addWidget(name);
hlayout->addStretch();
hlayout->addWidget(version);
// hlayout->addSpacing(10);
// hlayout->addWidget(author);
QVBoxLayout* vlayout = new QVBoxLayout;
QLabel* description = new QLabel( plugins_[i].description );
vlayout->addLayout(hlayout,20);
vlayout->addWidget(description);
frame->setLayout(vlayout);
QListWidgetItem *item = new QListWidgetItem("");
frames_.push_back(frame);
item->setSizeHint( QSize (100,50) );
list->addItem(item);
list->setItemWidget(item, frame);
}
int ret = QDialog::exec();
for (int i=0; i < frames_.count(); i++)
delete frames_[i];
return ret;
}
void PluginDialog::slotUnload()
{
int buttonState = QMessageBox::No;
QStringList dontLoad;
for (int i=0; i < list->selectedItems().size(); i++){
QString name = plugins_[ list->row( list->selectedItems()[i] ) ].rpcName;
if (list->selectedItems().size() == 1){
//show messageBox without YESTOALL / NOTOALL
buttonState = QMessageBox::question(this, tr("Prevent Plugin Loading"),
tr("Do you want to prevent OpenFlipper from loading this plugin on the next start?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
}else{
//show messageBox with YESTOALL / NOTOALL
if (buttonState == QMessageBox::Yes || buttonState == QMessageBox::No)
buttonState = QMessageBox::question(this, tr("Prevent Plugin Loading"),
tr("Do you want to prevent OpenFlipper from loading this plugin on the next start?"),
QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll ,
QMessageBox::No);
}
if (buttonState == QMessageBox::Yes || buttonState == QMessageBox::YesToAll)
dontLoad << name;
//unload plugin
emit unloadPlugin(name);
}
//prevent OpenFlipper from loading the plugin on the next start
if (!dontLoad.isEmpty())
emit dontLoadPlugins(dontLoad);
reject();
}
#include "ui_pluginDialog.hh"
#include <QtGui>
#include <OpenFlipper/Core/PluginInfo.hh>
class PluginDialog : public QDialog, public Ui::PluginDialog
{
Q_OBJECT
public:
PluginDialog(std::vector<PluginInfo>& _plugins, QWidget *parent = 0);
int exec();
private:
std::vector<PluginInfo>& plugins_;
QVector< QFrame* > frames_;
private slots:
void slotUnload();
protected:
void closeEvent(QCloseEvent *event);
signals:
void unloadPlugin(QString _name);
void dontLoadPlugins(QStringList _dontLoad);
void loadPlugin();
};
<ui version="4.0" >
<class>PluginDialog</class>
<widget class="QDialog" name="PluginDialog" >
<property name="windowModality" >
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>480</width>
<height>316</height>
</rect>
</property>
<property name="windowTitle" >
<string>Plugins</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<widget class="QFrame" name="frame_3" >
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>40</height>
</size>
</property>
<property name="autoFillBackground" >
<bool>false</bool>
</property>
<property name="frameShape" >
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow" >
<enum>QFrame::Raised</enum>
</property>
<property name="midLineWidth" >
<number>0</number>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2" >
<item>
<widget class="QLabel" name="label_2" >
<property name="minimumSize" >
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="font" >
<font>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text" >
<string>Loaded Plugins</string>
</property>
<property name="alignment" >
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QListWidget" name="list" >
<property name="editTriggers" >
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="alternatingRowColors" >
<bool>true</bool>
</property>
<property name="selectionMode" >
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="selectionBehavior" >
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="viewMode" >
<enum>QListView::ListMode</enum>
</property>
<property name="selectionRectVisible" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QPushButton" name="loadButton" >
<property name="text" >
<string>Load Plugin</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="unloadButton" >
<property name="text" >
<string>Unload Plugin</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="closeButton" >
<property name="text" >
<string>Close</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../../../resources.qrc" />
</resources>
<connections/>
</ui>
......@@ -75,7 +75,6 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
splitter_(0),
logWidget_(0),
recentFilesMenu_(0),
pluginsMenu_(0),
helpMenu_(0),
sceneGraphDialog_(0),
fileMenu_(0),
......
......@@ -138,7 +138,7 @@ public:
void exit();
void loadPlugin();
void unloadPlugin();
void showPlugins();
private slots:
......@@ -395,9 +395,6 @@ public:
/// QMenu containing the recently opened files
QMenu* recentFilesMenu_;
/// Plugins Menu
QMenu* pluginsMenu_;
/// Help Menu
QMenu* helpMenu_;
......
......@@ -204,32 +204,6 @@ void CoreWidget::setupMenuBar()
connect(AC_exit, SIGNAL(triggered()), this, SIGNAL(exit()));
fileMenu_->addAction(AC_exit);
// ======================================================================
// Plugins Menu
// ======================================================================
pluginsMenu_ = new QMenu(tr("&Plugins"));
menuBar()->addMenu(pluginsMenu_);
//Load Plugin
QAction* AC_LoadPlug = new QAction(tr("&Load Plugin"), this);
AC_LoadPlug->setStatusTip(tr("Load an additional plugin"));
AC_LoadPlug->setWhatsThis("Load an additional plugin from file");
icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"network-connect.png");
AC_LoadPlug->setIcon(icon);
connect(AC_LoadPlug, SIGNAL(triggered()), this, SIGNAL(loadPlugin()));
pluginsMenu_->addAction(AC_LoadPlug);
//Unload plugin
QAction* AC_UnloadPlug = new QAction(tr("&Unload Plugin"), this);
AC_UnloadPlug->setStatusTip(tr("Unload a plugin"));
AC_UnloadPlug->setWhatsThis("Close a currently loaded plugin");
icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"network-disconnect.png");
AC_UnloadPlug->setIcon(icon);
connect(AC_UnloadPlug, SIGNAL(triggered()), this, SIGNAL(unloadPlugin()));
pluginsMenu_->addAction(AC_UnloadPlug);
pluginsMenu_->addSeparator();
// ======================================================================
// help Menu
// ======================================================================
......@@ -262,6 +236,17 @@ void CoreWidget::setupMenuBar()
helpMenu_->addSeparator();
//show plugins
QAction* AC_Plugins = new QAction(tr("&Plugins"), this);
AC_Plugins->setStatusTip(tr("Show loaded plugins"));
AC_Plugins->setWhatsThis("Show loaded plugins");
icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"network-connect.png");
AC_Plugins->setIcon(icon);
connect(AC_Plugins, SIGNAL(triggered()), this, SIGNAL(showPlugins()));
helpMenu_->addAction(AC_Plugins);
helpMenu_->addSeparator();
//About Action
QAction* AC_About = new QAction(tr("&About"), this);
AC_About->setStatusTip(tr("About OpenFlipper"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment