dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
pluginview.cpp
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #include "pluginview.h"
29 #include "pluginview_p.h"
30 #include "pluginmanager.h"
31 #include "pluginspec.h"
32 #include "ui_pluginview.h"
33 
34 #include <QtCore/QDir>
35 #include <QHeaderView>
36 #include <QTreeWidgetItem>
37 #include <QtDebug>
38 
63 using namespace ExtensionSystem;
64 
66 
67 
72 PluginView::PluginView(PluginManager *manager, QWidget *parent)
73  : QWidget(parent),
74  m_ui(new Internal::Ui::PluginView),
75  p(new Internal::PluginViewPrivate)
76 {
77  m_ui->setupUi(this);
78  QHeaderView *header = m_ui->pluginWidget->header();
79  header->setSectionResizeMode(0, QHeaderView::ResizeToContents);
80  header->setSectionResizeMode(1, QHeaderView::ResizeToContents);
81  header->setSectionResizeMode(2, QHeaderView::ResizeToContents);
82  m_ui->pluginWidget->sortItems(1, Qt::AscendingOrder);
83  p->manager = manager;
84  connect(p->manager, SIGNAL(pluginsChanged()), this, SLOT(updateList()));
85  connect(m_ui->pluginWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
86  this, SLOT(selectPlugin(QTreeWidgetItem*)));
87  connect(m_ui->pluginWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
88  this, SLOT(activatePlugin(QTreeWidgetItem*)));
89  updateList();
90 }
91 
97 {
98  delete p;
99  delete m_ui;
100 }
101 
107 {
108  if (!m_ui->pluginWidget->currentItem())
109  return nullptr;
110  return m_ui->pluginWidget->currentItem()->data(0, Qt::UserRole).value<PluginSpec *>();
111 }
112 
113 void PluginView::updateList()
114 {
115  static QIcon okIcon(":/extensionsystem/images/ok.png");
116  static QIcon errorIcon(":/extensionsystem/images/error.png");
118  QTreeWidgetItem *currentItem = nullptr;
119  PluginSpec *currPlugin = currentPlugin();
120  foreach (PluginSpec *spec, p->manager->plugins()) {
121  QTreeWidgetItem *item = new QTreeWidgetItem(QStringList()
122  << ""
123  << spec->name()
124  << QString("%1 (%2)").arg(spec->version()).arg(spec->compatVersion())
125  << spec->vendor()
126  << QDir::toNativeSeparators(spec->filePath()));
127  item->setToolTip(4, QDir::toNativeSeparators(spec->filePath()));
128  item->setIcon(0, spec->hasError() ? errorIcon : okIcon);
129  item->setData(0, Qt::UserRole, qVariantFromValue(spec));
130  items.append(item);
131  if (currPlugin == spec)
132  currentItem = item;
133  }
134  m_ui->pluginWidget->clear();
135  if (!items.isEmpty())
136  m_ui->pluginWidget->addTopLevelItems(items);
137  if (currentItem)
138  m_ui->pluginWidget->setCurrentItem(currentItem);
139  else if (!items.isEmpty())
140  m_ui->pluginWidget->setCurrentItem(items.first());
141 }
142 
143 void PluginView::selectPlugin(QTreeWidgetItem *current)
144 {
145  if (!current)
146  emit currentPluginChanged(nullptr);
147  else
148  emit currentPluginChanged(current->data(0, Qt::UserRole).value<PluginSpec *>());
149 }
150 
151 void PluginView::activatePlugin(QTreeWidgetItem *item)
152 {
153  emit pluginActivated(item->data(0, Qt::UserRole).value<PluginSpec *>());
154 }
155 
PluginSpec * currentPlugin() const
Definition: pluginview.cpp:106
Widget that shows a list of all plugins and their state.
Definition: pluginview.h:51
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
QString filePath() const
Definition: pluginspec.cpp:260
QString compatVersion() const
Definition: pluginspec.cpp:176
void currentPluginChanged(ExtensionSystem::PluginSpec *spec)
Q_DECLARE_METATYPE(Core::Internal::MenuActionContainer *) using namespace Core
Contains the information of the plugins xml description file and information about the plugin's curre...
Definition: pluginspec.h:63
Definition: icore.h:39
void pluginActivated(ExtensionSystem::PluginSpec *spec)
QString version() const
Definition: pluginspec.cpp:167