PluginDialog.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6727 $                                                         *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 08:03:50 +0200 (Mi, 05. Aug 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 #include "PluginDialog.hh"
00044 #include <QtGui>
00045 #include <QMessageBox>
00046 #include <QFileDialog>
00047 
00048 #include <OpenFlipper/BasePlugin/BaseInterface.hh>
00049 #include <OpenFlipper/common/GlobalOptions.hh>
00050 
00051 
00052 PluginDialog::PluginDialog(std::vector<PluginInfo>& _plugins, QWidget *parent)
00053     : QDialog(parent),
00054       plugins_(_plugins)
00055 {
00056   setupUi(this);
00057 
00058   connect(closeButton, SIGNAL(clicked()), this, SLOT(accept()));
00059   connect(loadButton, SIGNAL(clicked()), this, SIGNAL(loadPlugin()));
00060   connect(loadButton, SIGNAL(clicked()), this, SLOT(reject()));
00061   connect(unloadButton, SIGNAL(clicked()), this, SLOT(slotUnload()));
00062 
00063   //set icons
00064   QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
00065 
00066   closeButton->setIcon( QIcon(iconPath + "window-close.png"));
00067   loadButton->setIcon( QIcon(iconPath + "network-connect.png"));
00068   unloadButton->setIcon( QIcon(iconPath + "network-disconnect.png"));
00069 
00070 }
00071 
00072 void PluginDialog::closeEvent(QCloseEvent *event)
00073 {
00074   event->accept();
00075   accept();
00076 }
00077 
00078 int PluginDialog::exec()
00079 {
00080 
00081   for (uint i = 0; i < plugins_.size(); i++){
00082     QFrame* frame = new QFrame();
00083     QHBoxLayout* hlayout = new QHBoxLayout;
00084     QLabel* name = new QLabel( plugins_[i].name );
00085     QFont font;
00086     font.setBold(true);
00087     font.setPointSize(10);
00088     name->setFont(font);
00089     QLabel* version = new QLabel( plugins_[i].version );
00090 //     QLabel* author = new QLabel( "RWTH Computer Graphics Group" );
00091 
00092     hlayout->addWidget(name);
00093     hlayout->addStretch();
00094     hlayout->addWidget(version);
00095 //     hlayout->addSpacing(10);
00096 //     hlayout->addWidget(author);
00097 
00098     QVBoxLayout* vlayout = new QVBoxLayout;
00099 
00100     QLabel* description = new QLabel( plugins_[i].description );
00101 
00102     vlayout->addLayout(hlayout,20);
00103     vlayout->addWidget(description);
00104     frame->setLayout(vlayout);
00105 
00106     QListWidgetItem *item = new QListWidgetItem("");
00107     frames_.push_back(frame);
00108     item->setSizeHint( QSize (100,50) );
00109     list->addItem(item);
00110     list->setItemWidget(item, frame);
00111   }
00112 
00113   int ret = QDialog::exec();
00114 
00115   for (int i=0; i < frames_.count(); i++)
00116     delete frames_[i];
00117 
00118   return ret;
00119 }
00120 
00121 void PluginDialog::slotUnload()
00122 {
00123   int buttonState = QMessageBox::No;
00124   QStringList dontLoad;
00125 
00126   for (int i=0; i < list->selectedItems().size(); i++){
00127 
00128     QString name = plugins_[ list->row( list->selectedItems()[i] ) ].rpcName;
00129     
00130     if (list->selectedItems().size() == 1){
00131       //show messageBox without YESTOALL / NOTOALL
00132       buttonState = QMessageBox::question(this, tr("Prevent Plugin Loading"),
00133                    tr("Do you want to prevent OpenFlipper from loading this plugin on the next start?"),
00134                    QMessageBox::Yes | QMessageBox::No,
00135                    QMessageBox::No);
00136     }else{
00137       //show messageBox with YESTOALL / NOTOALL
00138       if (buttonState == QMessageBox::Yes || buttonState == QMessageBox::No)
00139       buttonState = QMessageBox::question(this, tr("Prevent Plugin Loading"),
00140                    tr("Do you want to prevent OpenFlipper from loading this plugin on the next start?"),
00141                    QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll ,
00142                    QMessageBox::No);
00143     }
00144 
00145   if (buttonState == QMessageBox::Yes || buttonState == QMessageBox::YesToAll)
00146     dontLoad << name;
00147 
00148     //unload plugin
00149     emit unloadPlugin(name);
00150   }
00151 
00152   //prevent OpenFlipper from loading the plugin on the next start
00153   if (!dontLoad.isEmpty())
00154     emit dontLoadPlugins(dontLoad);
00155 
00156   reject();
00157 }

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .