OSDN Git Service

12907fec4e0c0661294201740e8e1ae6e7cbcb6f
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / plugindialog.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "plugindialog.h"
35
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>
41
42 #include <QtGui/QVBoxLayout>
43 #include <QtGui/QHBoxLayout>
44 #include <QtGui/QDialog>
45 #include <QtGui/QDialogButtonBox>
46 #include <QtGui/QPushButton>
47 #include <QtGui/QLabel>
48 #include <QtDebug>
49
50 using namespace Core::Internal;
51
52 bool PluginDialog::m_isRestartRequired = false;
53
54 PluginDialog::PluginDialog(QWidget *parent)
55     : QDialog(parent),
56       m_view(new ExtensionSystem::PluginView(ExtensionSystem::PluginManager::instance(), this))
57 {
58     QVBoxLayout *vl = new QVBoxLayout(this);
59     vl->addWidget(m_view);
60
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);
68
69     m_restartRequired = new QLabel(tr("Restart required."), this);
70     if (!m_isRestartRequired)
71         m_restartRequired->setVisible(false);
72
73     QHBoxLayout *hl = new QHBoxLayout;
74     hl->addWidget(m_detailsButton);
75     hl->addWidget(m_errorDetailsButton);
76     hl->addSpacing(10);
77     hl->addWidget(m_restartRequired);
78     hl->addStretch(5);
79     hl->addWidget(m_closeButton);
80
81     vl->addLayout(hl);
82
83
84     resize(650, 400);
85     setWindowTitle(tr("Installed Plugins"));
86
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()));
96     updateButtons();
97 }
98
99 void PluginDialog::closeDialog()
100 {
101     ExtensionSystem::PluginManager::instance()->writeSettings();
102     accept();
103 }
104
105 void PluginDialog::updateRestartRequired()
106 {
107     // just display the notice all the time after once changing something
108     m_isRestartRequired = true;
109     m_restartRequired->setVisible(true);
110 }
111
112 void PluginDialog::updateButtons()
113 {
114     ExtensionSystem::PluginSpec *selectedSpec = m_view->currentPlugin();
115     if (selectedSpec) {
116         m_detailsButton->setEnabled(true);
117         m_errorDetailsButton->setEnabled(selectedSpec->hasError()
118                                          || selectedSpec->isDisabledIndirectly()
119                                          || !selectedSpec->isEnabled());
120     } else {
121         m_detailsButton->setEnabled(false);
122         m_errorDetailsButton->setEnabled(false);
123     }
124 }
125
126
127 void PluginDialog::openDetails()
128 {
129     openDetails(m_view->currentPlugin());
130 }
131
132 void PluginDialog::openDetails(ExtensionSystem::PluginSpec *spec)
133 {
134     if (!spec)
135         return;
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);
148     dialog.exec();
149 }
150
151 void PluginDialog::openErrorDetails()
152 {
153     ExtensionSystem::PluginSpec *spec = m_view->currentPlugin();
154     if (!spec)
155         return;
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);
168     dialog.exec();
169 }
170