OSDN Git Service

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