commonsettingspage.cpp 5.97 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29

30
#include "commonsettingspage.h"
31
32
#include "vcsbaseconstants.h"

33
#include "ui_commonsettingspage.h"
34
35

#include <coreplugin/icore.h>
36
37
38
39
#include <coreplugin/vcsmanager.h>

#include <utils/environment.h>
#include <utils/hostosinfo.h>
40

41
#include <QCoreApplication>
42

hjk's avatar
hjk committed
43
namespace VcsBase {
44
45
namespace Internal {

hjk's avatar
hjk committed
46
// ------------------ VcsBaseSettingsWidget
47

48
CommonSettingsWidget::CommonSettingsWidget(QWidget *parent) :
49
    QWidget(parent),
50
    m_ui(new Ui::CommonSettingsPage)
51
52
{
    m_ui->setupUi(this);
53
    m_ui->submitMessageCheckScriptChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
54
    m_ui->submitMessageCheckScriptChooser->setHistoryCompleter(QLatin1String("Vcs.MessageCheckScript.History"));
55
    m_ui->nickNameFieldsFileChooser->setExpectedKind(Utils::PathChooser::File);
56
    m_ui->nickNameFieldsFileChooser->setHistoryCompleter(QLatin1String("Vcs.NickFields.History"));
57
    m_ui->nickNameMailMapChooser->setExpectedKind(Utils::PathChooser::File);
58
    m_ui->nickNameMailMapChooser->setHistoryCompleter(QLatin1String("Vcs.NickMap.History"));
59
    m_ui->sshPromptChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
60
    m_ui->sshPromptChooser->setHistoryCompleter(QLatin1String("Vcs.SshPrompt.History"));
61
62
63
64
    const QString patchToolTip = tr("Command used for reverting diff chunks");
    m_ui->patchCommandLabel->setToolTip(patchToolTip);
    m_ui->patchChooser->setToolTip(patchToolTip);
    m_ui->patchChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
65
    m_ui->patchChooser->setHistoryCompleter(QLatin1String("Vcs.PatchCommand.History"));
66
67
68
69
70

    updatePath();

    connect(Core::VcsManager::instance(), SIGNAL(configurationChanged(const IVersionControl*)),
            this, SLOT(updatePath()));
71
72
}

73
CommonSettingsWidget::~CommonSettingsWidget()
74
75
76
77
{
    delete m_ui;
}

78
CommonVcsSettings CommonSettingsWidget::settings() const
79
{
80
    CommonVcsSettings rc;
81
82
83
    rc.nickNameMailMap = m_ui->nickNameMailMapChooser->path();
    rc.nickNameFieldListFile = m_ui->nickNameFieldsFileChooser->path();
    rc.submitMessageCheckScript = m_ui->submitMessageCheckScriptChooser->path();
84
85
    rc.lineWrap= m_ui->lineWrapCheckBox->isChecked();
    rc.lineWrapWidth = m_ui->lineWrapSpinBox->value();
86
    rc.sshPasswordPrompt = m_ui->sshPromptChooser->path();
87
    rc.patchCommand = m_ui->patchChooser->path();
88
89
90
    return rc;
}

91
void CommonSettingsWidget::setSettings(const CommonVcsSettings &s)
92
93
94
95
{
    m_ui->nickNameMailMapChooser->setPath(s.nickNameMailMap);
    m_ui->nickNameFieldsFileChooser->setPath(s.nickNameFieldListFile);
    m_ui->submitMessageCheckScriptChooser->setPath(s.submitMessageCheckScript);
96
97
    m_ui->lineWrapCheckBox->setChecked(s.lineWrap);
    m_ui->lineWrapSpinBox->setValue(s.lineWrapWidth);
98
    m_ui->sshPromptChooser->setPath(s.sshPasswordPrompt);
99
    m_ui->patchChooser->setPath(s.patchCommand);
100
101
}

102
QString CommonSettingsWidget::searchKeyWordMatchString() const
103
104
{
    const QChar blank = QLatin1Char(' ');
105
106
107
108
109
    QString rc = m_ui->lineWrapCheckBox->text()
            + blank + m_ui->submitMessageCheckScriptLabel->text()
            + blank + m_ui->nickNameMailMapLabel->text()
            + blank + m_ui->nickNameFieldsFileLabel->text()
            + blank + m_ui->sshPromptLabel->text()
110
            + blank + m_ui->patchCommandLabel->text()
111
            ;
112
    rc.remove(QLatin1Char('&')); // Strip buddy markers.
113
114
115
    return rc;
}

116
117
118
119
120
121
122
123
124
void CommonSettingsWidget::updatePath()
{
    Utils::Environment env = Utils::Environment::systemEnvironment();
    QStringList toAdd = Core::VcsManager::additionalToolsPath();
    env.appendOrSetPath(toAdd.join(QString(Utils::HostOsInfo::pathListSeparator())));
    m_ui->patchChooser->setEnvironment(env);
    m_ui->sshPromptChooser->setEnvironment(env);
}

hjk's avatar
hjk committed
125
// --------------- VcsBaseSettingsPage
126
CommonOptionsPage::CommonOptionsPage(QObject *parent) :
hjk's avatar
hjk committed
127
    VcsBaseOptionsPage(parent)
128
{
hjk's avatar
hjk committed
129
    m_settings.fromSettings(Core::ICore::settings());
130

hjk's avatar
hjk committed
131
    setId(Constants::VCS_COMMON_SETTINGS_ID);
132
    setDisplayName(QCoreApplication::translate("VcsBase", Constants::VCS_COMMON_SETTINGS_NAME));
133
134
}

135
QWidget *CommonOptionsPage::widget()
136
{
137
138
139
140
    if (!m_widget) {
        m_widget = new CommonSettingsWidget;
        m_widget->setSettings(m_settings);
    }
141
142
143
    return m_widget;
}

144
void CommonOptionsPage::apply()
145
146
{
    if (m_widget) {
147
        const CommonVcsSettings newSettings = m_widget->settings();
148
149
        if (newSettings != m_settings) {
            m_settings = newSettings;
hjk's avatar
hjk committed
150
            m_settings.toSettings(Core::ICore::settings());
151
            emit settingsChanged(m_settings);
152
153
154
155
        }
    }
}

156
void CommonOptionsPage::finish()
157
{
158
    delete m_widget;
159
160
}

161
} // namespace Internal
hjk's avatar
hjk committed
162
} // namespace VcsBase