LP-56 - Better txpid option namings, fix tabs-spaces, tooltips. headers, variable...
[librepilot.git] / ground / openpilotgcs / src / plugins / coreplugin / plugindialog.cpp
blob227d5d0249b23252f57386755378ee8cac9c03d5
1 /**
2 ******************************************************************************
4 * @file plugindialog.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @addtogroup GCSPlugins GCS Plugins
8 * @{
9 * @addtogroup CorePlugin Core Plugin
10 * @{
11 * @brief The Core GCS plugin
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
22 * for more details.
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 "plugindialog.h"
31 #include <extensionsystem/pluginmanager.h>
32 #include <extensionsystem/pluginview.h>
33 #include <extensionsystem/plugindetailsview.h>
34 #include <extensionsystem/pluginerrorview.h>
35 #include <extensionsystem/pluginspec.h>
37 #include <QVBoxLayout>
38 #include <QHBoxLayout>
39 #include <QDialog>
40 #include <QDialogButtonBox>
41 #include <QPushButton>
42 #include <QtDebug>
44 using namespace Core::Internal;
46 PluginDialog::PluginDialog(QWidget *parent)
47 : QDialog(parent),
48 m_view(new ExtensionSystem::PluginView(ExtensionSystem::PluginManager::instance(), this))
50 QVBoxLayout *vl = new QVBoxLayout(this);
52 vl->addWidget(m_view);
54 m_detailsButton = new QPushButton(tr("Details"), this);
55 m_errorDetailsButton = new QPushButton(tr("Error Details"), this);
56 m_closeButton = new QPushButton(tr("Close"), this);
57 m_detailsButton->setEnabled(false);
58 m_errorDetailsButton->setEnabled(false);
59 m_closeButton->setEnabled(true);
60 m_closeButton->setDefault(true);
62 QHBoxLayout *hl = new QHBoxLayout;
63 hl->addWidget(m_detailsButton);
64 hl->addWidget(m_errorDetailsButton);
65 hl->addStretch(5);
66 hl->addWidget(m_closeButton);
68 vl->addLayout(hl);
70 resize(650, 400);
71 setWindowTitle(tr("Installed Plugins"));
72 setWindowIcon(QIcon(":/core/images/pluginicon.png"));
74 connect(m_view, SIGNAL(currentPluginChanged(ExtensionSystem::PluginSpec *)),
75 this, SLOT(updateButtons()));
76 connect(m_view, SIGNAL(pluginActivated(ExtensionSystem::PluginSpec *)),
77 this, SLOT(openDetails(ExtensionSystem::PluginSpec *)));
78 connect(m_detailsButton, SIGNAL(clicked()), this, SLOT(openDetails()));
79 connect(m_errorDetailsButton, SIGNAL(clicked()), this, SLOT(openErrorDetails()));
80 connect(m_closeButton, SIGNAL(clicked()), this, SLOT(accept()));
81 updateButtons();
84 void PluginDialog::updateButtons()
86 ExtensionSystem::PluginSpec *selectedSpec = m_view->currentPlugin();
88 if (selectedSpec) {
89 m_detailsButton->setEnabled(true);
90 m_errorDetailsButton->setEnabled(selectedSpec->hasError());
91 } else {
92 m_detailsButton->setEnabled(false);
93 m_errorDetailsButton->setEnabled(false);
98 void PluginDialog::openDetails()
100 openDetails(m_view->currentPlugin());
103 void PluginDialog::openDetails(ExtensionSystem::PluginSpec *spec)
105 if (!spec) {
106 return;
108 QDialog dialog(this);
109 dialog.setWindowTitle(tr("Plugin Details of %1").arg(spec->name()));
110 QVBoxLayout *layout = new QVBoxLayout;
111 dialog.setLayout(layout);
112 ExtensionSystem::PluginDetailsView *details = new ExtensionSystem::PluginDetailsView(&dialog);
113 layout->addWidget(details);
114 details->update(spec);
115 QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, &dialog);
116 layout->addWidget(buttons);
117 connect(buttons, SIGNAL(accepted()), &dialog, SLOT(accept()));
118 connect(buttons, SIGNAL(rejected()), &dialog, SLOT(reject()));
119 dialog.resize(400, 500);
120 dialog.exec();
123 void PluginDialog::openErrorDetails()
125 ExtensionSystem::PluginSpec *spec = m_view->currentPlugin();
127 if (!spec) {
128 return;
130 QDialog dialog(this);
131 dialog.setWindowTitle(tr("Plugin Errors of %1").arg(spec->name()));
132 QVBoxLayout *layout = new QVBoxLayout;
133 dialog.setLayout(layout);
134 ExtensionSystem::PluginErrorView *errors = new ExtensionSystem::PluginErrorView(&dialog);
135 layout->addWidget(errors);
136 errors->update(spec);
137 QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, &dialog);
138 layout->addWidget(buttons);
139 connect(buttons, SIGNAL(accepted()), &dialog, SLOT(accept()));
140 connect(buttons, SIGNAL(rejected()), &dialog, SLOT(reject()));
141 dialog.resize(500, 300);
142 dialog.exec();