2 ******************************************************************************
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
8 * @see The GNU Public License (GPL) Version 3
12 *****************************************************************************/
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.
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
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "pluginview.h"
30 #include "pluginview_p.h"
31 #include "pluginmanager.h"
32 #include "pluginspec.h"
33 #include "ui_pluginview.h"
35 #include <QtCore/QDir>
36 #include <QHeaderView>
37 #include <QTreeWidgetItem>
41 \class ExtensionSystem::PluginView
42 \brief Widget that shows a list of all plugins and their state.
44 This can be embedded e.g. in a dialog in the application that
45 uses the plugin manager.
46 The class also provides notifications for interactions with the list.
48 \sa ExtensionSystem::PluginDetailsView
49 \sa ExtensionSystem::PluginErrorView
53 \fn void PluginView::currentPluginChanged(ExtensionSystem::PluginSpec *spec)
54 The current selection in the plugin list has changed to the
55 plugin corresponding to \a spec.
59 \fn void PluginView::pluginActivated(ExtensionSystem::PluginSpec *spec)
60 The plugin list entry corresponding to \a spec has been activated,
61 e.g. by a double-click.
64 using namespace ExtensionSystem
;
66 Q_DECLARE_METATYPE(ExtensionSystem::PluginSpec
*)
68 \fn PluginView::PluginView(PluginManager *manager, QWidget *parent)
69 Constructs a PluginView that gets the list of plugins from the
70 given plugin \a manager with a given \a parent widget.
72 PluginView::PluginView(PluginManager
*manager
, QWidget
*parent
)
74 m_ui(new Internal::Ui::PluginView
),
75 p(new Internal::PluginViewPrivate
)
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
);
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
*)));
93 \fn PluginView::~PluginView()
96 PluginView::~PluginView()
103 \fn PluginSpec *PluginView::currentPlugin() const
104 Returns the current selection in the list of plugins.
106 PluginSpec
*PluginView::currentPlugin() const
108 if (!m_ui
->pluginWidget
->currentItem()) {
111 return m_ui
->pluginWidget
->currentItem()->data(0, Qt::UserRole
).value
<PluginSpec
*>();
114 void PluginView::updateList()
116 static QIcon
okIcon(":/extensionsystem/images/ok.png");
117 static QIcon
errorIcon(":/extensionsystem/images/error.png");
119 QList
<QTreeWidgetItem
*> items
;
120 QTreeWidgetItem
*currentItem
= 0;
121 PluginSpec
*currPlugin
= currentPlugin();
122 foreach(PluginSpec
* spec
, p
->manager
->plugins()) {
123 QTreeWidgetItem
*item
= new QTreeWidgetItem(QStringList()
126 << QString("%1 (%2)").arg(spec
->version()).arg(spec
->compatVersion())
128 << QDir::toNativeSeparators(spec
->filePath()));
130 item
->setToolTip(4, QDir::toNativeSeparators(spec
->filePath()));
131 item
->setIcon(0, spec
->hasError() ? errorIcon
: okIcon
);
132 item
->setData(0, Qt::UserRole
, qVariantFromValue(spec
));
134 if (currPlugin
== spec
) {
138 m_ui
->pluginWidget
->clear();
139 if (!items
.isEmpty()) {
140 m_ui
->pluginWidget
->addTopLevelItems(items
);
143 m_ui
->pluginWidget
->setCurrentItem(currentItem
);
144 } else if (!items
.isEmpty()) {
145 m_ui
->pluginWidget
->setCurrentItem(items
.first());
149 void PluginView::selectPlugin(QTreeWidgetItem
*current
)
152 emit
currentPluginChanged(0);
154 emit
currentPluginChanged(current
->data(0, Qt::UserRole
).value
<PluginSpec
*>());
158 void PluginView::activatePlugin(QTreeWidgetItem
*item
)
160 emit
pluginActivated(item
->data(0, Qt::UserRole
).value
<PluginSpec
*>());