46 #include "PluginDialog.hh" 48 #include <QMessageBox> 51 const QColor PluginDialog::blockColor_ = QColor(228, 155, 18);
52 const QColor PluginDialog::unloadColor_ = QColor(172, 172, 172);
53 const QColor PluginDialog::loadedBuiltInColor_ = QColor(208, 240, 192);
54 const QColor PluginDialog::failColor_ = Qt::red;
55 const QColor PluginDialog::loadedExternalColor_ = QColor(152, 255, 152);
57 PluginDialog::PluginDialog(std::vector<PluginInfo>& _plugins, QWidget *parent)
63 list->setContextMenuPolicy(Qt::CustomContextMenu);
65 connect(closeButton, SIGNAL(clicked()),
this, SLOT(accept()));
66 connect(loadButton, SIGNAL(clicked()),
this, SIGNAL(loadPlugin()));
67 connect(loadButton, SIGNAL(clicked()),
this, SLOT(reject()));
68 connect(list,SIGNAL(customContextMenuRequested(
const QPoint&)),
this,SLOT(slotContextMenu(
const QPoint&)));
71 QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
73 closeButton->setIcon( QIcon(iconPath +
"window-close.png"));
74 loadButton->setIcon( QIcon(iconPath +
"network-connect.png"));
78 void PluginDialog::closeEvent(QCloseEvent *event)
84 int PluginDialog::exec()
87 for (uint i = 0; i < plugins_.size(); i++){
88 QFrame* frame =
new QFrame();
89 QHBoxLayout* hlayout =
new QHBoxLayout;
90 QLabel* name =
new QLabel( plugins_[i].name );
93 font.setPointSize(10);
95 QLabel* version =
new QLabel( plugins_[i].version );
98 hlayout->addWidget(name);
99 hlayout->addStretch();
100 hlayout->addWidget(version);
104 QVBoxLayout* vlayout =
new QVBoxLayout;
106 QLabel* description =
new QLabel( plugins_[i].description );
107 descriptions_.push_back(description);
109 vlayout->addLayout(hlayout,20);
110 vlayout->addWidget(description);
111 frame->setLayout(vlayout);
113 QListWidgetItem *item =
new QListWidgetItem(
"");
114 frames_.push_back(frame);
115 item->setSizeHint( QSize (100,50) );
118 switch(plugins_[i].status)
120 case PluginInfo::LOADED:
121 if (plugins_[i].buildIn)
122 item->setBackground(loadedBuiltInColor_);
125 item->setBackground(loadedExternalColor_);
126 description->setText(description->text()+tr(
" *EXTERNAL*"));
129 case PluginInfo::FAILED:
130 item->setBackground(failColor_);
131 description->setText(description->text()+tr(
" *FAILED*"));
133 case PluginInfo::BLOCKED:
134 item->setBackground(blockColor_);
135 description->setText(description->text()+tr(
" *BLOCKED*"));
137 case PluginInfo::UNLOADED:
138 item->setBackground(unloadColor_);
139 description->setText(description->text()+tr(
" *UNLOADED*"));
143 list->setItemWidget(item, frame);
146 int ret = QDialog::exec();
148 for (
int i=0; i < frames_.count(); i++)
154 void PluginDialog::slotBlockPlugin()
156 for (
int i=0; i < list->selectedItems().size(); ++i)
158 QListWidgetItem* widget = list->selectedItems()[i];
159 widget->setBackground(blockColor_);
161 PluginInfo* plugin = &plugins_[ list->row( widget ) ];
162 descriptions_[list->row( widget )]->setText(plugin->
description + tr(
" *BLOCKED*"));
164 emit blockPlugin(plugin->
name);
167 void PluginDialog::slotUnBlockPlugin()
169 for (
int i=0; i < list->selectedItems().size(); ++i)
171 QListWidgetItem* widget = list->selectedItems()[i];
172 widget->setBackground(unloadColor_);
174 PluginInfo* plugin = &plugins_[ list->row( widget ) ];
175 descriptions_[list->row( widget )]->setText(plugin->
description);
177 emit unBlockPlugin(plugin->
name);
181 void PluginDialog::slotLoadPlugin()
183 for (
int i=0; i < list->selectedItems().size(); ++i)
185 QListWidgetItem* widget = list->selectedItems()[i];
187 PluginInfo* plugin = &plugins_[ list->row( widget ) ];
189 if (plugin->status == PluginInfo::BLOCKED)
192 msgBox.setText(
"Plugin is blocked. Unblock it?");
193 msgBox.setWindowTitle(
"Plugin blocked");
194 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
195 msgBox.setDefaultButton(QMessageBox::Yes);
196 int rep = msgBox.exec();
197 if ( rep == QMessageBox::Yes)
198 emit unBlockPlugin(plugin->
name);
202 widget->setBackground(loadedBuiltInColor_);
204 widget->setBackground(loadedExternalColor_);
206 descriptions_[list->row( widget )]->setText(plugin->
description);
208 QString licenseErros;
209 emit loadPlugin(plugin->
path,
false,licenseErros,plugin->
plugin);
211 if (plugin->status == PluginInfo::FAILED)
213 descriptions_[list->row( widget )]->setText(plugin->
description + tr(
" *FAILED*"));
214 widget->setBackground(failColor_);
217 plugin->status = PluginInfo::LOADED;
222 void PluginDialog::slotContextMenu(
const QPoint& _point)
227 QMenu *menu =
new QMenu(list);
230 PluginInfo* plugin = &plugins_[list->currentRow()];
232 if ( plugin->status != PluginInfo::BLOCKED)
234 action = menu->addAction(tr(
"Block Plugin"));
235 connect(action,SIGNAL(triggered(
bool)),
this,SLOT(slotBlockPlugin()));
238 action = menu->addAction(tr(
"Unblock Plugin"));
239 connect(action,SIGNAL(triggered(
bool)),
this,SLOT(slotUnBlockPlugin()));
242 if ( plugin->status != PluginInfo::LOADED)
244 action = menu->addAction(tr(
"Load Plugin"));
245 connect(action,SIGNAL(triggered(
bool)),
this,SLOT(slotLoadPlugin()));
248 menu->exec(list->mapToGlobal(_point),0);
QObject * plugin
Pointer to the loaded plugin (Already casted when loading it)
QString path
Path to the plugin ( set on load )
bool buildIn
Indicates, if the plugin is a built in Plugin (in Plugin directory)
QString description
Description of the plugin ( requested from the plugin on load)
QString name
Name of the plugin ( requested from the plugin on load)