-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathhgconfig.cpp
134 lines (109 loc) · 3.01 KB
/
hgconfig.cpp
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
/*
SPDX-FileCopyrightText: 2011 Vishesh Yadav <[email protected]>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "hgconfig.h"
#include "hgwrapper.h"
#include <KConfig>
#include <KConfigGroup>
#include <QDebug>
#include <QDir>
HgConfig::HgConfig(ConfigType configType)
: m_configType(configType)
, m_config(nullptr)
{
getConfigFilePath();
loadConfig();
}
HgConfig::~HgConfig()
{
delete m_config;
}
QString HgConfig::configFilePath() const
{
return m_configFilePath;
}
bool HgConfig::getConfigFilePath()
{
switch (m_configType) {
case RepoConfig: {
m_configFilePath = HgWrapper::instance()->getBaseDir() + QLatin1String("/.hg/hgrc");
break;
}
case GlobalConfig: {
m_configFilePath = QDir::homePath() + QLatin1String("/.hgrc");
break;
}
case TempConfig:
break;
}
return true;
}
bool HgConfig::loadConfig()
{
m_config = new KConfig(m_configFilePath, KConfig::SimpleConfig);
return true;
}
QString HgConfig::property(const QString §ion, const QString &propertyName) const
{
KConfigGroup group(m_config, section);
return group.readEntry(propertyName, QString()).trimmed();
}
void HgConfig::setProperty(const QString §ion, const QString &propertyName, const QString &propertyValue)
{
KConfigGroup uiGroup(m_config, section);
if (propertyValue.isEmpty()) {
uiGroup.deleteEntry(propertyName, KConfigGroup::Normal);
return;
}
uiGroup.writeEntry(propertyName, propertyValue.trimmed());
}
/* User Interface [ui] Section */
QString HgConfig::username() const
{
return property(QStringLiteral("ui"), QStringLiteral("username"));
}
void HgConfig::setUsername(const QString &userName)
{
setProperty(QStringLiteral("ui"), QStringLiteral("username"), userName);
}
QString HgConfig::editor() const
{
return property(QStringLiteral("ui"), QStringLiteral("editor"));
}
void HgConfig::setEditor(const QString &pathToEditor)
{
setProperty(QStringLiteral("ui"), QStringLiteral("editor"), pathToEditor);
}
QString HgConfig::merge() const
{
return property(QStringLiteral("ui"), QStringLiteral("merge"));
}
void HgConfig::setMerge(const QString &pathToMergeTool)
{
setProperty(QStringLiteral("ui"), QStringLiteral("merge"), pathToMergeTool);
}
/* Repo specific */
void HgConfig::setRepoRemotePath(const QString &alias, const QString &url)
{
Q_ASSERT(m_configType == RepoConfig);
setProperty(QStringLiteral("paths"), alias, url);
}
void HgConfig::deleteRepoRemotePath(const QString &alias)
{
Q_ASSERT(m_configType == RepoConfig);
KConfigGroup group(m_config, QStringLiteral("paths"));
group.deleteEntry(alias);
}
QString HgConfig::repoRemotePath(const QString &alias) const
{
Q_ASSERT(m_configType == RepoConfig);
return property(QStringLiteral("paths"), alias);
}
QMap<QString, QString> HgConfig::repoRemotePathList() const
{
Q_ASSERT(m_configType == RepoConfig);
KConfigGroup group(m_config, QStringLiteral("paths"));
return group.entryMap();
}
//