OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / cpaster / codepastersettings.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 "codepastersettings.h"
35 #include "cpasterconstants.h"
36
37 #include <coreplugin/icore.h>
38
39 #include <QtCore/QSettings>
40 #include <QtCore/QCoreApplication>
41 #include <QtGui/QLineEdit>
42 #include <QtGui/QFileDialog>
43 #include <QtGui/QGroupBox>
44 #include <QtGui/QFormLayout>
45 #include <QtGui/QVBoxLayout>
46 #include <QtGui/QLabel>
47 #include <QtCore/QDebug>
48 #include <QtCore/QVariant>
49
50 static const char settingsGroupC[] = "CodePasterSettings";
51 static const char serverKeyC[] = "Server";
52
53 namespace CodePaster {
54
55 CodePasterSettingsPage::CodePasterSettingsPage()
56 {
57     m_settings = Core::ICore::instance()->settings();
58     if (m_settings) {
59         const QString keyRoot = QLatin1String(settingsGroupC) + QLatin1Char('/');
60         m_host = m_settings->value(keyRoot + QLatin1String(serverKeyC), QString()).toString();
61     }
62 }
63
64 QString CodePasterSettingsPage::id() const
65 {
66     return QLatin1String("C.CodePaster");
67 }
68
69 QString CodePasterSettingsPage::displayName() const
70 {
71     return tr("CodePaster");
72 }
73
74 QString CodePasterSettingsPage::category() const
75 {
76     return QLatin1String(Constants::CPASTER_SETTINGS_CATEGORY);
77 }
78
79 QString CodePasterSettingsPage::displayCategory() const
80 {
81     return QCoreApplication::translate("CodePaster", Constants::CPASTER_SETTINGS_TR_CATEGORY);
82 }
83
84 QIcon CodePasterSettingsPage::categoryIcon() const
85 {
86     return QIcon();
87 }
88
89 QWidget *CodePasterSettingsPage::createPage(QWidget *parent)
90 {
91     QWidget *outerWidget = new QWidget(parent);
92     QVBoxLayout *outerLayout = new QVBoxLayout(outerWidget);
93
94     QFormLayout *formLayout = new QFormLayout;
95     formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
96     QLineEdit *lineEdit = new QLineEdit(m_host);
97     connect(lineEdit, SIGNAL(textChanged(QString)), this, SLOT(serverChanged(QString)));
98     formLayout->addRow(tr("Server:"), lineEdit);
99     outerLayout->addLayout(formLayout);
100     outerLayout->addSpacerItem(new QSpacerItem(0, 30, QSizePolicy::Ignored, QSizePolicy::Fixed));
101
102     QLabel *noteLabel = new QLabel(tr("Note: Specify the host name for the CodePaster service "
103                                       "without any protocol prepended (e.g. codepaster.mycompany.com)."));
104     noteLabel->setWordWrap(true);
105     outerLayout->addWidget(noteLabel);
106
107     outerLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
108     return outerWidget;
109 }
110
111 void CodePasterSettingsPage::apply()
112 {
113     if (!m_settings)
114         return;
115
116     m_settings->beginGroup(QLatin1String(settingsGroupC));
117     m_settings->setValue(QLatin1String(serverKeyC), m_host);
118     m_settings->endGroup();
119 }
120
121 void CodePasterSettingsPage::serverChanged(const QString &host)
122 {
123     m_host = host;
124 }
125
126 QString CodePasterSettingsPage::hostName() const
127 {
128     return m_host;
129 }
130 } // namespace CodePaster