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
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "gerritoptionspage.h"
#include "gerritparameters.h"
#include "gerritserver.h"
#include "../gittr.h"
#include <coreplugin/icore.h>
#include <utils/layoutbuilder.h>
#include <utils/pathchooser.h>
#include <vcsbase/vcsbaseconstants.h>
#include <QLineEdit>
#include <QSpinBox>
#include <QCheckBox>
#include <QFormLayout>
using namespace Utils;
namespace Gerrit::Internal {
class GerritOptionsWidget : public Core::IOptionsPageWidget
{
public:
GerritOptionsWidget(const std::function<void()> &onChanged)
{
const GerritParameters &s = gerritSettings();
auto hostLineEdit = new QLineEdit(s.server.host);
auto userLineEdit = new QLineEdit(s.server.user.userName);
auto sshChooser = new Utils::PathChooser;
sshChooser->setFilePath(s.ssh);
sshChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
sshChooser->setCommandVersionArguments({"-V"});
sshChooser->setHistoryCompleter("Git.SshCommand.History");
auto curlChooser = new Utils::PathChooser;
curlChooser->setFilePath(s.curl);
curlChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
curlChooser->setCommandVersionArguments({"-V"});
auto portSpinBox = new QSpinBox(this);
portSpinBox->setRange(1, 65535);
portSpinBox->setValue(s.server.port);
auto httpsCheckBox = new QCheckBox(Git::Tr::tr("HTTPS"));
httpsCheckBox->setChecked(s.https);
httpsCheckBox->setToolTip(Git::Tr::tr(
"Determines the protocol used to form a URL in case\n"
"\"canonicalWebUrl\" is not configured in the file\n"
"\"gerrit.config\"."));
using namespace Layouting;
Form {
Git::Tr::tr("&Host:"), hostLineEdit, br,
Git::Tr::tr("&User:"), userLineEdit, br,
Git::Tr::tr("&ssh:"), sshChooser, br,
Git::Tr::tr("cur&l:"), curlChooser, br,
Git::Tr::tr("SSH &Port:"), portSpinBox, br,
Git::Tr::tr("P&rotocol:"), httpsCheckBox
}.attachTo(this);
setOnApply([hostLineEdit,
userLineEdit,
sshChooser,
curlChooser,
portSpinBox,
httpsCheckBox,
onChanged] {
GerritParameters &s = gerritSettings();
GerritServer server(hostLineEdit->text().trimmed(),
static_cast<unsigned short>(portSpinBox->value()),
userLineEdit->text().trimmed(),
GerritServer::Ssh);
FilePath ssh = sshChooser->filePath();
FilePath curl = curlChooser->filePath();
bool https = httpsCheckBox->isChecked();
if (server == s.server && ssh == s.ssh && curl == s.curl && https == s.https)
return;
s.server = server;
s.ssh = ssh;
s.curl = curl;
s.https = https;
if (s.ssh != ssh)
s.setPortFlagBySshType();
s.toSettings();
emit onChanged();
});
}
};
// GerritOptionsPage
GerritOptionsPage::GerritOptionsPage(const std::function<void()> &onChanged)
{
setId("Gerrit");
setDisplayName(Git::Tr::tr("Gerrit"));
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
setWidgetCreator([onChanged] { return new GerritOptionsWidget(onChanged); });
}
} // Gerrit::Internal
|