1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "plugindialog.h"
36 #include <extensionsystem/pluginmanager.h>
37 #include <extensionsystem/pluginview.h>
38 #include <extensionsystem/plugindetailsview.h>
39 #include <extensionsystem/pluginerrorview.h>
40 #include <extensionsystem/pluginspec.h>
42 #include <QtGui/QVBoxLayout>
43 #include <QtGui/QHBoxLayout>
44 #include <QtGui/QDialog>
45 #include <QtGui/QDialogButtonBox>
46 #include <QtGui/QPushButton>
47 #include <QtGui/QLabel>
50 using namespace Core::Internal;
52 bool PluginDialog::m_isRestartRequired = false;
54 PluginDialog::PluginDialog(QWidget *parent)
56 m_view(new ExtensionSystem::PluginView(ExtensionSystem::PluginManager::instance(), this))
58 QVBoxLayout *vl = new QVBoxLayout(this);
59 vl->addWidget(m_view);
61 m_detailsButton = new QPushButton(tr("Details"), this);
62 m_errorDetailsButton = new QPushButton(tr("Error Details"), this);
63 m_closeButton = new QPushButton(tr("Close"), this);
64 m_detailsButton->setEnabled(false);
65 m_errorDetailsButton->setEnabled(false);
66 m_closeButton->setEnabled(true);
67 m_closeButton->setDefault(true);
69 m_restartRequired = new QLabel(tr("Restart required."), this);
70 if (!m_isRestartRequired)
71 m_restartRequired->setVisible(false);
73 QHBoxLayout *hl = new QHBoxLayout;
74 hl->addWidget(m_detailsButton);
75 hl->addWidget(m_errorDetailsButton);
77 hl->addWidget(m_restartRequired);
79 hl->addWidget(m_closeButton);
85 setWindowTitle(tr("Installed Plugins"));
87 connect(m_view, SIGNAL(currentPluginChanged(ExtensionSystem::PluginSpec*)),
88 this, SLOT(updateButtons()));
89 connect(m_view, SIGNAL(pluginActivated(ExtensionSystem::PluginSpec*)),
90 this, SLOT(openDetails(ExtensionSystem::PluginSpec*)));
91 connect(m_view, SIGNAL(pluginSettingsChanged(ExtensionSystem::PluginSpec*)),
92 this, SLOT(updateRestartRequired()));
93 connect(m_detailsButton, SIGNAL(clicked()), this, SLOT(openDetails()));
94 connect(m_errorDetailsButton, SIGNAL(clicked()), this, SLOT(openErrorDetails()));
95 connect(m_closeButton, SIGNAL(clicked()), this, SLOT(closeDialog()));
99 void PluginDialog::closeDialog()
101 ExtensionSystem::PluginManager::instance()->writeSettings();
105 void PluginDialog::updateRestartRequired()
107 // just display the notice all the time after once changing something
108 m_isRestartRequired = true;
109 m_restartRequired->setVisible(true);
112 void PluginDialog::updateButtons()
114 ExtensionSystem::PluginSpec *selectedSpec = m_view->currentPlugin();
116 m_detailsButton->setEnabled(true);
117 m_errorDetailsButton->setEnabled(selectedSpec->hasError()
118 || selectedSpec->isDisabledIndirectly()
119 || !selectedSpec->isEnabled());
121 m_detailsButton->setEnabled(false);
122 m_errorDetailsButton->setEnabled(false);
127 void PluginDialog::openDetails()
129 openDetails(m_view->currentPlugin());
132 void PluginDialog::openDetails(ExtensionSystem::PluginSpec *spec)
136 QDialog dialog(this);
137 dialog.setWindowTitle(tr("Plugin Details of %1").arg(spec->name()));
138 QVBoxLayout *layout = new QVBoxLayout;
139 dialog.setLayout(layout);
140 ExtensionSystem::PluginDetailsView *details = new ExtensionSystem::PluginDetailsView(&dialog);
141 layout->addWidget(details);
142 details->update(spec);
143 QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, &dialog);
144 layout->addWidget(buttons);
145 connect(buttons, SIGNAL(accepted()), &dialog, SLOT(accept()));
146 connect(buttons, SIGNAL(rejected()), &dialog, SLOT(reject()));
147 dialog.resize(400, 500);
151 void PluginDialog::openErrorDetails()
153 ExtensionSystem::PluginSpec *spec = m_view->currentPlugin();
156 QDialog dialog(this);
157 dialog.setWindowTitle(tr("Plugin Errors of %1").arg(spec->name()));
158 QVBoxLayout *layout = new QVBoxLayout;
159 dialog.setLayout(layout);
160 ExtensionSystem::PluginErrorView *errors = new ExtensionSystem::PluginErrorView(&dialog);
161 layout->addWidget(errors);
162 errors->update(spec);
163 QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, &dialog);
164 layout->addWidget(buttons);
165 connect(buttons, SIGNAL(accepted()), &dialog, SLOT(accept()));
166 connect(buttons, SIGNAL(rejected()), &dialog, SLOT(reject()));
167 dialog.resize(500, 300);