OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / vcsbase / commonsettingspage.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 "commonsettingspage.h"
34 #include "vcsbaseconstants.h"
35 #include "nicknamedialog.h"
36
37 #include "ui_commonsettingspage.h"
38
39 #include <coreplugin/icore.h>
40 #include <extensionsystem/pluginmanager.h>
41
42 #include <QtCore/QDebug>
43 #include <QtCore/QCoreApplication>
44 #include <QtGui/QMessageBox>
45
46 namespace VCSBase {
47 namespace Internal {
48
49 // ------------------ VCSBaseSettingsWidget
50
51 CommonSettingsWidget::CommonSettingsWidget(QWidget *parent) :
52     QWidget(parent),
53     m_ui(new Ui::CommonSettingsPage)
54 {
55     m_ui->setupUi(this);
56     m_ui->submitMessageCheckScriptChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
57     m_ui->nickNameFieldsFileChooser->setExpectedKind(Utils::PathChooser::File);
58     m_ui->nickNameMailMapChooser->setExpectedKind(Utils::PathChooser::File);
59     m_ui->sshPromptChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
60 }
61
62 CommonSettingsWidget::~CommonSettingsWidget()
63 {
64     delete m_ui;
65 }
66
67 CommonVcsSettings CommonSettingsWidget::settings() const
68 {
69     CommonVcsSettings rc;
70     rc.nickNameMailMap = m_ui->nickNameMailMapChooser->path();
71     rc.nickNameFieldListFile = m_ui->nickNameFieldsFileChooser->path();
72     rc.submitMessageCheckScript = m_ui->submitMessageCheckScriptChooser->path();
73     rc.lineWrap= m_ui->lineWrapCheckBox->isChecked();
74     rc.lineWrapWidth = m_ui->lineWrapSpinBox->value();
75     rc.sshPasswordPrompt = m_ui->sshPromptChooser->path();
76     return rc;
77 }
78
79 void CommonSettingsWidget::setSettings(const CommonVcsSettings &s)
80 {
81     m_ui->nickNameMailMapChooser->setPath(s.nickNameMailMap);
82     m_ui->nickNameFieldsFileChooser->setPath(s.nickNameFieldListFile);
83     m_ui->submitMessageCheckScriptChooser->setPath(s.submitMessageCheckScript);
84     m_ui->lineWrapCheckBox->setChecked(s.lineWrap);
85     m_ui->lineWrapSpinBox->setValue(s.lineWrapWidth);
86     m_ui->sshPromptChooser->setPath(s.sshPasswordPrompt);
87 }
88
89 QString CommonSettingsWidget::searchKeyWordMatchString() const
90 {
91     const QChar blank = QLatin1Char(' ');
92     QString rc = m_ui->lineWrapCheckBox->text()
93             + blank + m_ui->submitMessageCheckScriptLabel->text()
94             + blank + m_ui->nickNameMailMapLabel->text()
95             + blank + m_ui->nickNameFieldsFileLabel->text()
96             + blank + m_ui->sshPromptLabel->text()
97             ;
98     rc.remove(QLatin1Char('&')); // Strip buddy markers.
99     return rc;
100 }
101
102 // --------------- VCSBaseSettingsPage
103 CommonOptionsPage::CommonOptionsPage(QObject *parent) :
104     VCSBaseOptionsPage(parent)
105 {
106     m_settings.fromSettings(Core::ICore::instance()->settings());
107 }
108
109 void CommonOptionsPage::updateNickNames()
110 {
111 }
112
113 CommonOptionsPage::~CommonOptionsPage()
114 {
115 }
116
117 QString CommonOptionsPage::id() const
118 {
119     return QLatin1String(Constants::VCS_COMMON_SETTINGS_ID);
120 }
121
122 QString CommonOptionsPage::displayName() const
123 {
124     return QCoreApplication::translate("VCSBase", Constants::VCS_COMMON_SETTINGS_NAME);
125 }
126
127 QWidget *CommonOptionsPage::createPage(QWidget *parent)
128 {
129     m_widget = new CommonSettingsWidget(parent);
130     m_widget->setSettings(m_settings);
131     if (m_searchKeyWords.isEmpty())
132         m_searchKeyWords = m_widget->searchKeyWordMatchString();
133     return m_widget;
134 }
135
136 void CommonOptionsPage::apply()
137 {
138     if (m_widget) {
139         const CommonVcsSettings newSettings = m_widget->settings();
140         if (newSettings != m_settings) {
141             m_settings = newSettings;
142             m_settings.toSettings(Core::ICore::instance()->settings());
143             emit settingsChanged(m_settings);
144         }
145     }
146 }
147
148 bool CommonOptionsPage::matches(const QString &key) const
149 {
150     return m_searchKeyWords.contains(key, Qt::CaseInsensitive);
151 }
152
153 } // namespace Internal
154 } // namespace VCSBase