1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "plugindialog.h"
35 #include <extensionsystem/plugindetailsview.h>
36 #include <extensionsystem/pluginerrorview.h>
37 #include <extensionsystem/pluginspec.h>
39 #include <QtGui/QVBoxLayout>
40 #include <QtGui/QHBoxLayout>
41 #include <QtGui/QDialog>
42 #include <QtGui/QDialogButtonBox>
43 #include <QtGui/QApplication>
46 PluginDialog::PluginDialog(ExtensionSystem::PluginManager *manager)
47 : m_view(new ExtensionSystem::PluginView(manager, this))
49 QVBoxLayout *vl = new QVBoxLayout(this);
52 vl->addWidget(m_view);
54 QHBoxLayout *hl = new QHBoxLayout;
58 m_detailsButton = new QPushButton(tr("Details"), this);
59 m_errorDetailsButton = new QPushButton(tr("Error Details"), this);
60 m_detailsButton->setEnabled(false);
61 m_errorDetailsButton->setEnabled(false);
62 hl->addWidget(m_detailsButton);
63 hl->addWidget(m_errorDetailsButton);
66 setWindowTitle(tr("Installed Plugins"));
68 connect(m_view, SIGNAL(currentPluginChanged(ExtensionSystem::PluginSpec*)),
69 this, SLOT(updateButtons()));
70 connect(m_view, SIGNAL(pluginActivated(ExtensionSystem::PluginSpec*)),
71 this, SLOT(openDetails(ExtensionSystem::PluginSpec*)));
72 connect(m_detailsButton, SIGNAL(clicked()), this, SLOT(openDetails()));
73 connect(m_errorDetailsButton, SIGNAL(clicked()), this, SLOT(openErrorDetails()));
76 void PluginDialog::updateButtons()
78 ExtensionSystem::PluginSpec *selectedSpec = m_view->currentPlugin();
80 m_detailsButton->setEnabled(true);
81 m_errorDetailsButton->setEnabled(selectedSpec->hasError());
83 m_detailsButton->setEnabled(false);
84 m_errorDetailsButton->setEnabled(false);
89 void PluginDialog::openDetails()
91 openDetails(m_view->currentPlugin());
94 void PluginDialog::openDetails(ExtensionSystem::PluginSpec *spec)
99 dialog.setWindowTitle(tr("Plugin Details of %1").arg(spec->name()));
100 QVBoxLayout *layout = new QVBoxLayout;
101 dialog.setLayout(layout);
102 ExtensionSystem::PluginDetailsView *details = new ExtensionSystem::PluginDetailsView(&dialog);
103 layout->addWidget(details);
104 details->update(spec);
105 QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, &dialog);
106 layout->addWidget(buttons);
107 connect(buttons, SIGNAL(accepted()), &dialog, SLOT(accept()));
108 connect(buttons, SIGNAL(rejected()), &dialog, SLOT(reject()));
109 dialog.resize(400, 500);
113 void PluginDialog::openErrorDetails()
115 ExtensionSystem::PluginSpec *spec = m_view->currentPlugin();
118 QDialog dialog(this);
119 dialog.setWindowTitle(tr("Plugin Errors of %1").arg(spec->name()));
120 QVBoxLayout *layout = new QVBoxLayout;
121 dialog.setLayout(layout);
122 ExtensionSystem::PluginErrorView *errors = new ExtensionSystem::PluginErrorView(&dialog);
123 layout->addWidget(errors);
124 errors->update(spec);
125 QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, &dialog);
126 layout->addWidget(buttons);
127 connect(buttons, SIGNAL(accepted()), &dialog, SLOT(accept()));
128 connect(buttons, SIGNAL(rejected()), &dialog, SLOT(reject()));
129 dialog.resize(500, 300);
133 int main(int argc, char *argv[])
135 ExtensionSystem::PluginManager manager;
136 QApplication app(argc, argv);
137 PluginDialog dialog(&manager);
138 manager.setPluginPaths(QStringList() << "plugins");
139 manager.loadPlugins();