PluginDialog.cc 8.93 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2
3
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
Jan Möbius committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
33
34
35
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36
37
38
39
40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
41
42
\*===========================================================================*/

Dirk Wilden's avatar
Dirk Wilden committed
43
44
45
46
47
48
49
#include "PluginDialog.hh"
#include <QtGui>
#include <QMessageBox>

#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/common/GlobalOptions.hh>

50
51
52
53
54
const QColor PluginDialog::blockColor_  = QColor(228, 155, 18);
const QColor PluginDialog::unloadColor_ = QColor(172, 172, 172);
const QColor PluginDialog::loadedBuiltInColor_ = QColor(208, 240, 192);
const QColor PluginDialog::failColor_ = Qt::red;
const QColor PluginDialog::loadedExternalColor_ = QColor(152, 255, 152);
Dirk Wilden's avatar
Dirk Wilden committed
55
56
57
58
59
60
61

PluginDialog::PluginDialog(std::vector<PluginInfo>& _plugins, QWidget *parent)
    : QDialog(parent),
      plugins_(_plugins)
{
  setupUi(this);

62
63
  list->setContextMenuPolicy(Qt::CustomContextMenu);

Dirk Wilden's avatar
Dirk Wilden committed
64
65
66
  connect(closeButton, SIGNAL(clicked()), this, SLOT(accept()));
  connect(loadButton, SIGNAL(clicked()), this, SIGNAL(loadPlugin()));
  connect(loadButton, SIGNAL(clicked()), this, SLOT(reject()));
67
  connect(list,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(slotContextMenu(const QPoint&)));
Dirk Wilden's avatar
Dirk Wilden committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

  //set icons
  QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();

  closeButton->setIcon( QIcon(iconPath + "window-close.png"));
  loadButton->setIcon( QIcon(iconPath + "network-connect.png"));

}

void PluginDialog::closeEvent(QCloseEvent *event)
{
  event->accept();
  accept();
}

int PluginDialog::exec()
{

  for (uint i = 0; i < plugins_.size(); i++){
    QFrame* frame = new QFrame();
    QHBoxLayout* hlayout = new QHBoxLayout;
    QLabel* name = new QLabel( plugins_[i].name );
    QFont font;
    font.setBold(true);
    font.setPointSize(10);
    name->setFont(font);
    QLabel* version = new QLabel( plugins_[i].version );
//     QLabel* author = new QLabel( "RWTH Computer Graphics Group" );

    hlayout->addWidget(name);
    hlayout->addStretch();
    hlayout->addWidget(version);
//     hlayout->addSpacing(10);
//     hlayout->addWidget(author);

    QVBoxLayout* vlayout = new QVBoxLayout;

    QLabel* description = new QLabel( plugins_[i].description );
106
    descriptions_.push_back(description);
Dirk Wilden's avatar
Dirk Wilden committed
107
108
109
110
111
112
113
114

    vlayout->addLayout(hlayout,20);
    vlayout->addWidget(description);
    frame->setLayout(vlayout);

    QListWidgetItem *item = new QListWidgetItem("");
    frames_.push_back(frame);
    item->setSizeHint( QSize (100,50) );
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140

    //set color depending on the current status
    switch(plugins_[i].status)
    {
      case PluginInfo::LOADED:
        if (plugins_[i].buildIn)
          item->setBackground(loadedBuiltInColor_);
        else
        {
          item->setBackground(loadedExternalColor_);
          description->setText(description->text()+tr(" *EXTERNAL*"));
        }
        break;
      case PluginInfo::FAILED:
        item->setBackground(failColor_);
        description->setText(description->text()+tr(" *FAILED*"));
        break;
      case PluginInfo::BLOCKED:
        item->setBackground(blockColor_);
        description->setText(description->text()+tr(" *BLOCKED*"));
        break;
      case PluginInfo::UNLOADED:
        item->setBackground(unloadColor_);
        description->setText(description->text()+tr(" *UNLOADED*"));
        break;
    }
Dirk Wilden's avatar
Dirk Wilden committed
141
142
143
144
145
146
147
148
149
150
151
152
    list->addItem(item);
    list->setItemWidget(item, frame);
  }

  int ret = QDialog::exec();

  for (int i=0; i < frames_.count(); i++)
    delete frames_[i];

  return ret;
}

153
154
155
156
157
158
159
160
161
162
163
164
165
166
void PluginDialog::slotBlockPlugin()
{
  for (int i=0; i < list->selectedItems().size(); ++i)
  {
    QListWidgetItem* widget = list->selectedItems()[i];
    widget->setBackground(blockColor_);

    PluginInfo* plugin = &plugins_[ list->row( widget ) ];
    descriptions_[list->row( widget )]->setText(plugin->description + tr(" *BLOCKED*"));

    emit blockPlugin(plugin->name);
  }
}
void PluginDialog::slotUnBlockPlugin()
Dirk Wilden's avatar
Dirk Wilden committed
167
{
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
  for (int i=0; i < list->selectedItems().size(); ++i)
  {
    QListWidgetItem* widget = list->selectedItems()[i];
    widget->setBackground(unloadColor_);

    PluginInfo* plugin = &plugins_[ list->row( widget ) ];
    descriptions_[list->row( widget )]->setText(plugin->description);

    emit unBlockPlugin(plugin->name);
  }
}

void PluginDialog::slotLoadPlugin()
{
  for (int i=0; i < list->selectedItems().size(); ++i)
  {
    QListWidgetItem* widget = list->selectedItems()[i];

    PluginInfo* plugin = &plugins_[ list->row( widget ) ];

    if (plugin->status == PluginInfo::BLOCKED)
    {
      QMessageBox msgBox;
      msgBox.setText("Plugin is blocked. Unblock it?");
      msgBox.setWindowTitle("Plugin blocked");
      msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
      msgBox.setDefaultButton(QMessageBox::Yes);
      int rep = msgBox.exec();
      if ( rep == QMessageBox::Yes)
        emit unBlockPlugin(plugin->name);
Dirk Wilden's avatar
Dirk Wilden committed
198
199
    }

200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
    if (plugin->buildIn)
      widget->setBackground(loadedBuiltInColor_);
    else
      widget->setBackground(loadedExternalColor_);

    descriptions_[list->row( widget )]->setText(plugin->description);

    QString licenseErros;
    emit loadPlugin(plugin->path,false,licenseErros,plugin->plugin);

    if (plugin->status == PluginInfo::FAILED)
    {
      descriptions_[list->row( widget )]->setText(plugin->description + tr(" *FAILED*"));
      widget->setBackground(failColor_);
    }else
    {
      plugin->status = PluginInfo::LOADED;
217
    }
218
219
  }
}
Dirk Wilden's avatar
Dirk Wilden committed
220

221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
void PluginDialog::slotContextMenu(const QPoint& _point)
{
  if (!list->count())
    return;

  QMenu *menu = new QMenu(list);
  QAction* action = 0;

  PluginInfo* plugin = &plugins_[list->currentRow()];

  if ( plugin->status != PluginInfo::BLOCKED)//not blocked
  {
    action = menu->addAction(tr("Block Plugin"));
    connect(action,SIGNAL(triggered(bool)),this,SLOT(slotBlockPlugin()));
  }else//blocked
  {
    action = menu->addAction(tr("Unblock Plugin"));
    connect(action,SIGNAL(triggered(bool)),this,SLOT(slotUnBlockPlugin()));
Dirk Wilden's avatar
Dirk Wilden committed
239
240
  }

241
242
243
244
245
246
247
248
  if ( plugin->status != PluginInfo::LOADED)
  {
    action = menu->addAction(tr("Load Plugin"));
    connect(action,SIGNAL(triggered(bool)),this,SLOT(slotLoadPlugin()));
  }

  menu->exec(list->mapToGlobal(_point),0);

Dirk Wilden's avatar
Dirk Wilden committed
249
}