aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/vcsbase/commonvcssettings.cpp
blob: 45458efc02ff1703d9bcc480196f43d2c614d034 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/

#include "commonvcssettings.h"

#include "vcsbaseconstants.h"

#include <coreplugin/icore.h>
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/vcsmanager.h>

#include <utils/algorithm.h>
#include <utils/environment.h>
#include <utils/hostosinfo.h>
#include <utils/layoutbuilder.h>

#include <QDebug>
#include <QPushButton>

using namespace Utils;

namespace VcsBase {
namespace Internal {

// Return default for the ssh-askpass command (default to environment)
static QString sshPasswordPromptDefault()
{
    const QString envSetting = qtcEnvironmentVariable("SSH_ASKPASS");
    if (!envSetting.isEmpty())
        return envSetting;
    if (HostOsInfo::isWindowsHost())
        return QLatin1String("win-ssh-askpass");
    return QLatin1String("ssh-askpass");
}

CommonVcsSettings::CommonVcsSettings()
{
    setSettingsGroup("VCS");
    setAutoApply(false);

    registerAspect(&nickNameMailMap);
    nickNameMailMap.setSettingsKey("NickNameMailMap");
    nickNameMailMap.setDisplayStyle(StringAspect::PathChooserDisplay);
    nickNameMailMap.setExpectedKind(PathChooser::File);
    nickNameMailMap.setHistoryCompleter("Vcs.NickMap.History");
    nickNameMailMap.setLabelText(tr("User/&alias configuration file:"));
    nickNameMailMap.setToolTip(tr("A file listing nicknames in a 4-column mailmap format:\n"
        "'name <email> alias <email>'."));

    registerAspect(&nickNameFieldListFile);
    nickNameFieldListFile.setSettingsKey("NickNameFieldListFile");
    nickNameFieldListFile.setDisplayStyle(StringAspect::PathChooserDisplay);
    nickNameFieldListFile.setExpectedKind(PathChooser::File);
    nickNameFieldListFile.setHistoryCompleter("Vcs.NickFields.History");
    nickNameFieldListFile.setLabelText(tr("User &fields configuration file:"));
    nickNameFieldListFile.setToolTip(tr("A simple file containing lines with field names like "
        "\"Reviewed-By:\" which will be added below the submit editor."));

    registerAspect(&submitMessageCheckScript);
    submitMessageCheckScript.setSettingsKey("SubmitMessageCheckScript");
    submitMessageCheckScript.setDisplayStyle(StringAspect::PathChooserDisplay);
    submitMessageCheckScript.setExpectedKind(PathChooser::ExistingCommand);
    submitMessageCheckScript.setHistoryCompleter("Vcs.MessageCheckScript.History");
    submitMessageCheckScript.setLabelText(tr("Submit message &check script:"));
    submitMessageCheckScript.setToolTip(tr("An executable which is called with the submit message "
        "in a temporary file as first argument. It should return with an exit != 0 and a message "
        "on standard error to indicate failure."));

    registerAspect(&sshPasswordPrompt);
    sshPasswordPrompt.setSettingsKey("SshPasswordPrompt");
    sshPasswordPrompt.setDisplayStyle(StringAspect::PathChooserDisplay);
    sshPasswordPrompt.setExpectedKind(PathChooser::ExistingCommand);
    sshPasswordPrompt.setHistoryCompleter("Vcs.SshPrompt.History");
    sshPasswordPrompt.setDefaultValue(sshPasswordPromptDefault());
    sshPasswordPrompt.setLabelText(tr("&SSH prompt command:"));
    sshPasswordPrompt.setToolTip(tr("Specifies a command that is executed to graphically prompt "
        "for a password,\nshould a repository require SSH-authentication "
        "(see documentation on SSH and the environment variable SSH_ASKPASS)."));

    registerAspect(&lineWrap);
    lineWrap.setSettingsKey("LineWrap");
    lineWrap.setDefaultValue(true);
    lineWrap.setLabelText(tr("Wrap submit message at:"));

    registerAspect(&lineWrapWidth);
    lineWrapWidth.setSettingsKey("LineWrapWidth");
    lineWrapWidth.setSuffix(tr(" characters"));
    lineWrapWidth.setDefaultValue(72);
}

// CommonSettingsWidget

class CommonSettingsWidget final : public Core::IOptionsPageWidget
{
public:
    CommonSettingsWidget(CommonOptionsPage *page);

    void apply() final;

private:
    void updatePath();
    CommonOptionsPage *m_page;
};


CommonSettingsWidget::CommonSettingsWidget(CommonOptionsPage *page)
    : m_page(page)
{
    CommonVcsSettings &s = m_page->settings();

    auto cacheResetButton = new QPushButton(CommonVcsSettings::tr("Reset VCS Cache"));
    cacheResetButton->setToolTip(CommonVcsSettings::tr("Reset information about which "
        "version control system handles which directory."));

    updatePath();

    using namespace Layouting;
    Column {
        Row { s.lineWrap, s.lineWrapWidth, st },
        Form {
            s.submitMessageCheckScript,
            s.nickNameMailMap,
            s.nickNameFieldListFile,
            s.sshPasswordPrompt,
            {}, cacheResetButton
        }
    }.attachTo(this);

    connect(Core::VcsManager::instance(), &Core::VcsManager::configurationChanged,
            this, &CommonSettingsWidget::updatePath);
    connect(cacheResetButton, &QPushButton::clicked,
            Core::VcsManager::instance(), &Core::VcsManager::clearVersionControlCache);
}

void CommonSettingsWidget::updatePath()
{
    EnvironmentChange change;
    change.addAppendToPath(Core::VcsManager::additionalToolsPath());
    m_page->settings().sshPasswordPrompt.setEnvironmentChange(change);
}

void CommonSettingsWidget::apply()
{
    CommonVcsSettings &s = m_page->settings();
    if (s.isDirty()) {
        s.apply();
        s.writeSettings(Core::ICore::settings());
        emit m_page->settingsChanged();
    }
}

// CommonOptionsPage

CommonOptionsPage::CommonOptionsPage()
{
    m_settings.readSettings(Core::ICore::settings());

    setId(Constants::VCS_COMMON_SETTINGS_ID);
    setDisplayName(QCoreApplication::translate("VcsBase", Constants::VCS_COMMON_SETTINGS_NAME));
    setCategory(Constants::VCS_SETTINGS_CATEGORY);
    // The following act as blueprint for other pages in the same category:
    setDisplayCategory(QCoreApplication::translate("VcsBase", "Version Control"));
    setCategoryIconPath(":/vcsbase/images/settingscategory_vcs.png");
    setWidgetCreator([this] { return new CommonSettingsWidget(this); });
}

} // namespace Internal
} // namespace VcsBase