Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PluginDialog.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
51 
52 #include "PluginDialog.hh"
53 
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);
59 
60 PluginDialog::PluginDialog(std::vector<PluginInfo>& _plugins, QWidget *parent)
61  : QDialog(parent),
62  plugins_(_plugins)
63 {
64  setupUi(this);
65 
66  list->setContextMenuPolicy(Qt::CustomContextMenu);
67 
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&)));
72 
73  //set icons
74  QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
75 
76  closeButton->setIcon( QIcon(iconPath + "window-close.png"));
77  loadButton->setIcon( QIcon(iconPath + "network-connect.png"));
78 
79 }
80 
81 void PluginDialog::closeEvent(QCloseEvent *event)
82 {
83  event->accept();
84  accept();
85 }
86 
87 int PluginDialog::exec()
88 {
89 
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 );
94  QFont font;
95  font.setBold(true);
96  font.setPointSize(10);
97  name->setFont(font);
98  QLabel* version = new QLabel( plugins_[i].version );
99 // QLabel* author = new QLabel( "RWTH Computer Graphics Group" );
100 
101  hlayout->addWidget(name);
102  hlayout->addStretch();
103  hlayout->addWidget(version);
104 // hlayout->addSpacing(10);
105 // hlayout->addWidget(author);
106 
107  QVBoxLayout* vlayout = new QVBoxLayout;
108 
109  QLabel* description = new QLabel( plugins_[i].description );
110  descriptions_.push_back(description);
111 
112  vlayout->addLayout(hlayout,20);
113  vlayout->addWidget(description);
114  frame->setLayout(vlayout);
115 
116  QListWidgetItem *item = new QListWidgetItem("");
117  frames_.push_back(frame);
118  item->setSizeHint( QSize (100,50) );
119 
120  //set color depending on the current status
121  switch(plugins_[i].status)
122  {
123  case PluginInfo::LOADED:
124  if (plugins_[i].buildIn)
125  item->setBackground(loadedBuiltInColor_);
126  else
127  {
128  item->setBackground(loadedExternalColor_);
129  description->setText(description->text()+tr(" *EXTERNAL*"));
130  }
131  break;
132  case PluginInfo::FAILED:
133  item->setBackground(failColor_);
134  description->setText(description->text()+tr(" *FAILED*"));
135  break;
136  case PluginInfo::BLOCKED:
137  item->setBackground(blockColor_);
138  description->setText(description->text()+tr(" *BLOCKED*"));
139  break;
140  case PluginInfo::UNLOADED:
141  item->setBackground(unloadColor_);
142  description->setText(description->text()+tr(" *UNLOADED*"));
143  break;
144  }
145  list->addItem(item);
146  list->setItemWidget(item, frame);
147  }
148 
149  int ret = QDialog::exec();
150 
151  for (int i=0; i < frames_.count(); i++)
152  delete frames_[i];
153 
154  return ret;
155 }
156 
157 void PluginDialog::slotBlockPlugin()
158 {
159  for (int i=0; i < list->selectedItems().size(); ++i)
160  {
161  QListWidgetItem* widget = list->selectedItems()[i];
162  widget->setBackground(blockColor_);
163 
164  PluginInfo* plugin = &plugins_[ list->row( widget ) ];
165  descriptions_[list->row( widget )]->setText(plugin->description + tr(" *BLOCKED*"));
166 
167  emit blockPlugin(plugin->name);
168  }
169 }
170 void PluginDialog::slotUnBlockPlugin()
171 {
172  for (int i=0; i < list->selectedItems().size(); ++i)
173  {
174  QListWidgetItem* widget = list->selectedItems()[i];
175  widget->setBackground(unloadColor_);
176 
177  PluginInfo* plugin = &plugins_[ list->row( widget ) ];
178  descriptions_[list->row( widget )]->setText(plugin->description);
179 
180  emit unBlockPlugin(plugin->name);
181  }
182 }
183 
184 void PluginDialog::slotLoadPlugin()
185 {
186  for (int i=0; i < list->selectedItems().size(); ++i)
187  {
188  QListWidgetItem* widget = list->selectedItems()[i];
189 
190  PluginInfo* plugin = &plugins_[ list->row( widget ) ];
191 
192  if (plugin->status == PluginInfo::BLOCKED)
193  {
194  QMessageBox msgBox;
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);
202  }
203 
204  if (plugin->buildIn)
205  widget->setBackground(loadedBuiltInColor_);
206  else
207  widget->setBackground(loadedExternalColor_);
208 
209  descriptions_[list->row( widget )]->setText(plugin->description);
210 
211  QString licenseErros;
212  emit loadPlugin(plugin->path,false,licenseErros,plugin->plugin);
213 
214  if (plugin->status == PluginInfo::FAILED)
215  {
216  descriptions_[list->row( widget )]->setText(plugin->description + tr(" *FAILED*"));
217  widget->setBackground(failColor_);
218  }else
219  {
220  plugin->status = PluginInfo::LOADED;
221  }
222  }
223 }
224 
225 void PluginDialog::slotContextMenu(const QPoint& _point)
226 {
227  if (!list->count())
228  return;
229 
230  QMenu *menu = new QMenu(list);
231  QAction* action = 0;
232 
233  PluginInfo* plugin = &plugins_[list->currentRow()];
234 
235  if ( plugin->status != PluginInfo::BLOCKED)//not blocked
236  {
237  action = menu->addAction(tr("Block Plugin"));
238  connect(action,SIGNAL(triggered(bool)),this,SLOT(slotBlockPlugin()));
239  }else//blocked
240  {
241  action = menu->addAction(tr("Unblock Plugin"));
242  connect(action,SIGNAL(triggered(bool)),this,SLOT(slotUnBlockPlugin()));
243  }
244 
245  if ( plugin->status != PluginInfo::LOADED)
246  {
247  action = menu->addAction(tr("Load Plugin"));
248  connect(action,SIGNAL(triggered(bool)),this,SLOT(slotLoadPlugin()));
249  }
250 
251  menu->exec(list->mapToGlobal(_point),0);
252 
253 }
QString description
Description of the plugin ( requested from the plugin on load)
Definition: PluginInfo.hh:133
QObject * plugin
Pointer to the loaded plugin (Already casted when loading it)
Definition: PluginInfo.hh:127
bool buildIn
Indicates, if the plugin is a built in Plugin (in Plugin directory)
Definition: PluginInfo.hh:172
QString name
Name of the plugin ( requested from the plugin on load)
Definition: PluginInfo.hh:130
QString path
Path to the plugin ( set on load )
Definition: PluginInfo.hh:139