52 #include "PluginDialog.hh" 54 const QColor PluginDialog::blockColor_ = QColor(228, 155, 18);
55 const QColor PluginDialog::unloadColor_ = QColor(172, 172, 172);
56 const QColor PluginDialog::loadedBuiltInColor_ = QColor(208, 240, 192);
57 const QColor PluginDialog::failColor_ = Qt::red;
58 const QColor PluginDialog::loadedExternalColor_ = QColor(152, 255, 152);
60 PluginDialog::PluginDialog(std::vector<PluginInfo>& _plugins, QWidget *parent)
66 list->setContextMenuPolicy(Qt::CustomContextMenu);
68 connect(closeButton, SIGNAL(clicked()),
this, SLOT(accept()));
69 connect(loadButton, SIGNAL(clicked()),
this, SIGNAL(loadPlugin()));
70 connect(loadButton, SIGNAL(clicked()),
this, SLOT(reject()));
71 connect(list,SIGNAL(customContextMenuRequested(
const QPoint&)),
this,SLOT(slotContextMenu(
const QPoint&)));
74 QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
76 closeButton->setIcon( QIcon(iconPath +
"window-close.png"));
77 loadButton->setIcon( QIcon(iconPath +
"network-connect.png"));
81 void PluginDialog::closeEvent(QCloseEvent *event)
87 int PluginDialog::exec()
90 for (uint i = 0; i < plugins_.size(); i++){
91 QFrame* frame =
new QFrame();
92 QHBoxLayout* hlayout =
new QHBoxLayout;
93 QLabel* name =
new QLabel( plugins_[i].name );
96 font.setPointSize(10);
98 QLabel* version =
new QLabel( plugins_[i].version );
101 hlayout->addWidget(name);
102 hlayout->addStretch();
103 hlayout->addWidget(version);
107 QVBoxLayout* vlayout =
new QVBoxLayout;
109 QLabel* description =
new QLabel( plugins_[i].description );
110 descriptions_.push_back(description);
112 vlayout->addLayout(hlayout,20);
113 vlayout->addWidget(description);
114 frame->setLayout(vlayout);
116 QListWidgetItem *item =
new QListWidgetItem(
"");
117 frames_.push_back(frame);
118 item->setSizeHint( QSize (100,50) );
121 switch(plugins_[i].status)
123 case PluginInfo::LOADED:
124 if (plugins_[i].buildIn)
125 item->setBackground(loadedBuiltInColor_);
128 item->setBackground(loadedExternalColor_);
129 description->setText(description->text()+tr(
" *EXTERNAL*"));
132 case PluginInfo::FAILED:
133 item->setBackground(failColor_);
134 description->setText(description->text()+tr(
" *FAILED*"));
136 case PluginInfo::BLOCKED:
137 item->setBackground(blockColor_);
138 description->setText(description->text()+tr(
" *BLOCKED*"));
140 case PluginInfo::UNLOADED:
141 item->setBackground(unloadColor_);
142 description->setText(description->text()+tr(
" *UNLOADED*"));
146 list->setItemWidget(item, frame);
149 int ret = QDialog::exec();
151 for (
int i=0; i < frames_.count(); i++)
157 void PluginDialog::slotBlockPlugin()
159 for (
int i=0; i < list->selectedItems().size(); ++i)
161 QListWidgetItem* widget = list->selectedItems()[i];
162 widget->setBackground(blockColor_);
164 PluginInfo* plugin = &plugins_[ list->row( widget ) ];
165 descriptions_[list->row( widget )]->setText(plugin->
description + tr(
" *BLOCKED*"));
167 emit blockPlugin(plugin->
name);
170 void PluginDialog::slotUnBlockPlugin()
172 for (
int i=0; i < list->selectedItems().size(); ++i)
174 QListWidgetItem* widget = list->selectedItems()[i];
175 widget->setBackground(unloadColor_);
177 PluginInfo* plugin = &plugins_[ list->row( widget ) ];
178 descriptions_[list->row( widget )]->setText(plugin->
description);
180 emit unBlockPlugin(plugin->
name);
184 void PluginDialog::slotLoadPlugin()
186 for (
int i=0; i < list->selectedItems().size(); ++i)
188 QListWidgetItem* widget = list->selectedItems()[i];
190 PluginInfo* plugin = &plugins_[ list->row( widget ) ];
192 if (plugin->status == PluginInfo::BLOCKED)
195 msgBox.setText(
"Plugin is blocked. Unblock it?");
196 msgBox.setWindowTitle(
"Plugin blocked");
197 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
198 msgBox.setDefaultButton(QMessageBox::Yes);
199 int rep = msgBox.exec();
200 if ( rep == QMessageBox::Yes)
201 emit unBlockPlugin(plugin->
name);
205 widget->setBackground(loadedBuiltInColor_);
207 widget->setBackground(loadedExternalColor_);
209 descriptions_[list->row( widget )]->setText(plugin->
description);
211 QString licenseErros;
212 emit loadPlugin(plugin->
path,
false,licenseErros,plugin->
plugin);
214 if (plugin->status == PluginInfo::FAILED)
216 descriptions_[list->row( widget )]->setText(plugin->
description + tr(
" *FAILED*"));
217 widget->setBackground(failColor_);
220 plugin->status = PluginInfo::LOADED;
225 void PluginDialog::slotContextMenu(
const QPoint& _point)
230 QMenu *menu =
new QMenu(list);
233 PluginInfo* plugin = &plugins_[list->currentRow()];
235 if ( plugin->status != PluginInfo::BLOCKED)
237 action = menu->addAction(tr(
"Block Plugin"));
238 connect(action,SIGNAL(triggered(
bool)),
this,SLOT(slotBlockPlugin()));
241 action = menu->addAction(tr(
"Unblock Plugin"));
242 connect(action,SIGNAL(triggered(
bool)),
this,SLOT(slotUnBlockPlugin()));
245 if ( plugin->status != PluginInfo::LOADED)
247 action = menu->addAction(tr(
"Load Plugin"));
248 connect(action,SIGNAL(triggered(
bool)),
this,SLOT(slotLoadPlugin()));
251 menu->exec(list->mapToGlobal(_point),0);
QString name
Name of the plugin ( requested from the plugin on load)
QString path
Path to the plugin ( set on load )
bool buildIn
Indicates, if the plugin is a built in Plugin (in Plugin directory)
QObject * plugin
Pointer to the loaded plugin (Already casted when loading it)
QString description
Description of the plugin ( requested from the plugin on load)