1
2
3
4
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
106
107
108
109
110
111
112
113
114
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
**
**************************************************************************/
#include "pluginview.h"
#include "pluginview_p.h"
#include "pluginmanager.h"
#include "pluginspec.h"
#include "ui_pluginview.h"
#include <QtCore/QDir>
#include <QtGui/QHeaderView>
#include <QtGui/QTreeWidgetItem>
#include <QtDebug>
/*!
\class ExtensionSystem::PluginView
\brief Widget that shows a list of all plugins and their state.
This can be embedded e.g. in a dialog in the application that
uses the plugin manager.
The class also provides notifications for interactions with the list.
\sa ExtensionSystem::PluginDetailsView
\sa ExtensionSystem::PluginErrorView
*/
/*!
\fn void PluginView::currentPluginChanged(ExtensionSystem::PluginSpec *spec)
The current selection in the plugin list has changed to the
plugin corresponding to \a spec.
*/
/*!
\fn void PluginView::pluginActivated(ExtensionSystem::PluginSpec *spec)
The plugin list entry corresponding to \a spec has been activated,
e.g. by a double-click.
*/
using namespace ExtensionSystem;
Q_DECLARE_METATYPE(ExtensionSystem::PluginSpec*);
/*!
\fn PluginView::PluginView(PluginManager *manager, QWidget *parent)
Constructs a PluginView that gets the list of plugins from the
given plugin \a manager with a given \a parent widget.
*/
PluginView::PluginView(PluginManager *manager, QWidget *parent)
: QWidget(parent),
m_ui(new Internal::Ui::PluginView),
p(new Internal::PluginViewPrivate)
{
m_ui->setupUi(this);
QHeaderView *header = m_ui->pluginWidget->header();
header->setResizeMode(0, QHeaderView::ResizeToContents);
header->setResizeMode(1, QHeaderView::ResizeToContents);
header->setResizeMode(2, QHeaderView::ResizeToContents);
m_ui->pluginWidget->sortItems(1, Qt::AscendingOrder);
p->manager = manager;
connect(p->manager, SIGNAL(pluginsChanged()), this, SLOT(updateList()));
connect(m_ui->pluginWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
this, SLOT(selectPlugin(QTreeWidgetItem*)));
connect(m_ui->pluginWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
this, SLOT(activatePlugin(QTreeWidgetItem*)));
updateList();
}
/*!
\fn PluginView::~PluginView()
\internal
*/
PluginView::~PluginView()
{
delete p;
delete m_ui;
}
/*!
\fn PluginSpec *PluginView::currentPlugin() const
Returns the current selection in the list of plugins.
*/
PluginSpec *PluginView::currentPlugin() const
{
if (!m_ui->pluginWidget->currentItem())
return 0;
return m_ui->pluginWidget->currentItem()->data(0, Qt::UserRole).value<PluginSpec *>();
}
void PluginView::updateList()
{
static QIcon okIcon(":/extensionsystem/images/ok.png");
static QIcon errorIcon(":/extensionsystem/images/error.png");
QList<QTreeWidgetItem *> items;
QTreeWidgetItem *currentItem = 0;
PluginSpec *currPlugin = currentPlugin();
foreach (PluginSpec *spec, p->manager->plugins()) {
QTreeWidgetItem *item = new QTreeWidgetItem(QStringList()
<< ""
<< spec->name()
<< QString("%1 (%2)").arg(spec->version()).arg(spec->compatVersion())
<< spec->vendor()
<< QDir::toNativeSeparators(spec->filePath()));
item->setToolTip(4, QDir::toNativeSeparators(spec->filePath()));
item->setIcon(0, spec->hasError() ? errorIcon : okIcon);
item->setData(0, Qt::UserRole, qVariantFromValue(spec));
items.append(item);
if (currPlugin == spec)
currentItem = item;
}
m_ui->pluginWidget->clear();
if (!items.isEmpty())
m_ui->pluginWidget->addTopLevelItems(items);
if (currentItem)
m_ui->pluginWidget->setCurrentItem(currentItem);
else if (!items.isEmpty())
m_ui->pluginWidget->setCurrentItem(items.first());
}
void PluginView::selectPlugin(QTreeWidgetItem *current)
{
if (!current)
emit currentPluginChanged(0);
else
emit currentPluginChanged(current->data(0, Qt::UserRole).value<PluginSpec *>());
}
void PluginView::activatePlugin(QTreeWidgetItem *item)
{
emit pluginActivated(item->data(0, Qt::UserRole).value<PluginSpec *>());
}
|