PluginDialog.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
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
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
00091
00092 hlayout->addWidget(name);
00093 hlayout->addStretch();
00094 hlayout->addWidget(version);
00095
00096
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
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
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
00149 emit unloadPlugin(name);
00150 }
00151
00152
00153 if (!dontLoad.isEmpty())
00154 emit dontLoadPlugins(dontLoad);
00155
00156 reject();
00157 }