OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / libs / extensionsystem / test / manual / pluginview / 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 (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "plugindialog.h"
34
35 #include <extensionsystem/plugindetailsview.h>
36 #include <extensionsystem/pluginerrorview.h>
37 #include <extensionsystem/pluginspec.h>
38
39 #include <QtGui/QVBoxLayout>
40 #include <QtGui/QHBoxLayout>
41 #include <QtGui/QDialog>
42 #include <QtGui/QDialogButtonBox>
43 #include <QtGui/QApplication>
44 #include <QtDebug>
45
46 PluginDialog::PluginDialog(ExtensionSystem::PluginManager *manager)
47     : m_view(new ExtensionSystem::PluginView(manager, this))
48 {
49     QVBoxLayout *vl = new QVBoxLayout(this);
50     vl->setMargin(0);
51     vl->setSpacing(0);
52     vl->addWidget(m_view);
53
54     QHBoxLayout *hl = new QHBoxLayout;
55     vl->addLayout(hl);
56     hl->setMargin(0);
57     hl->setSpacing(6);
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);
64     hl->addStretch(5);
65     resize(650, 300);
66     setWindowTitle(tr("Installed Plugins"));
67
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()));
74 }
75
76 void PluginDialog::updateButtons()
77 {
78     ExtensionSystem::PluginSpec *selectedSpec = m_view->currentPlugin();
79     if (selectedSpec) {
80         m_detailsButton->setEnabled(true);
81         m_errorDetailsButton->setEnabled(selectedSpec->hasError());
82     } else {
83         m_detailsButton->setEnabled(false);
84         m_errorDetailsButton->setEnabled(false);
85     }
86 }
87
88
89 void PluginDialog::openDetails()
90 {
91         openDetails(m_view->currentPlugin());
92 }
93
94 void PluginDialog::openDetails(ExtensionSystem::PluginSpec *spec)
95 {
96     if (!spec)
97         return;
98     QDialog dialog(this);
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);
110     dialog.exec();
111 }
112
113 void PluginDialog::openErrorDetails()
114 {
115     ExtensionSystem::PluginSpec *spec = m_view->currentPlugin();
116     if (!spec)
117         return;
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);
130     dialog.exec();
131 }
132
133 int main(int argc, char *argv[])
134 {
135     ExtensionSystem::PluginManager manager;
136     QApplication app(argc, argv);
137     PluginDialog dialog(&manager);
138     manager.setPluginPaths(QStringList() << "plugins");
139     manager.loadPlugins();
140     dialog.show();
141     app.exec();
142 }