-
Notifications
You must be signed in to change notification settings - Fork 727
/
patch-regionandlang
322 lines (289 loc) · 11.9 KB
/
patch-regionandlang
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
From 6fff5ebf2eb9ec2def4f7b5f0569b48c36061844 Mon Sep 17 00:00:00 2001
From: Gleb Popov <6yearold@gmail.com>
Date: Fri, 28 Jul 2023 10:59:40 +0300
Subject: [PATCH 1/2] Rename REGION_LANG_GENERATE_LOCALE to
REGION_LANG_GENERATE_LOCALE_HELPER
(cherry picked from commit 09d0b42a9)
---
CMakeLists.txt | 6 +++---
kcms/region_language/CMakeLists.txt | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/CMakeLists.txt CMakeLists.txt
index afd3bdcf22..54da6be721 100644
--- a/CMakeLists.txt
+++ CMakeLists.txt
@@ -253,19 +253,19 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(GLIBC_LOCALE TRUE)
endif()
if(UBUNTU_PACKAGEKIT OR GLIBC_LOCALE_GEN)
- set(REGION_LANG_GENERATE_LOCALE TRUE)
+ set(REGION_LANG_GENERATE_LOCALE_HELPER TRUE)
endif()
option(GLIBC_LOCALE_GENERATED "Systems that don't require locale generation. Such as openSUSE or Fedora" OFF)
if(GLIBC_LOCALE_GENERATED)
set(LOCALE_GENERATED TRUE)
endif()
- if(REGION_LANG_GENERATE_LOCALE AND GLIBC_LOCALE_GENERATED)
+ if(REGION_LANG_GENERATE_LOCALE_HELPER AND GLIBC_LOCALE_GENERATED)
message(FATAL_ERROR "(UBUNTU_PACKAGEKIT || GLIBC_LOCALE_GEN) and GLIBC_LOCALE_GENERATED both enabled")
endif()
################## Find libraries ###################
- if(REGION_LANG_GENERATE_LOCALE)
+ if(REGION_LANG_GENERATE_LOCALE_HELPER)
find_package(PolkitQt${QT_MAJOR_VERSION}-1)
set_package_properties(PolkitQt${QT_MAJOR_VERSION}-1
PROPERTIES DESCRIPTION "DBus interface wrapper for Polkit"
diff --git a/kcms/region_language/CMakeLists.txt kcms/region_language/CMakeLists.txt
index d134937b77..56ccec7cba 100644
--- a/kcms/region_language/CMakeLists.txt
+++ kcms/region_language/CMakeLists.txt
@@ -47,7 +47,7 @@ ecm_qt_declare_logging_category(
)
################ Build helper and add additional source files #############
-if(REGION_LANG_GENERATE_LOCALE)
+if(REGION_LANG_GENERATE_LOCALE_HELPER)
add_subdirectory("localegenhelper")
qt_generate_dbus_interface(
${CMAKE_CURRENT_SOURCE_DIR}/localegenhelper/localegenhelper.h
--
GitLab
From 0d53975b637620cc7619a67df3397fd43f710eba Mon Sep 17 00:00:00 2001
From: Gleb Popov <6yearold@gmail.com>
Date: Mon, 26 Jun 2023 08:46:23 +0300
Subject: [PATCH 2/2] region_language KCM: Guard glibc-related code with
ifdefs.
This introduces GLIBC_LOCALE_AUTO and GLIBC_LOCALE_GENERATED to differentiate
between Linux distributions. The GLIBC_LOCALE define is set for both cases.
The change unbreaks the KCM on FreeBSD.
Sponsored by: Serenity Cybersecurity, LLC
(cherry picked from commit e8eabb689f82f99a362b6860915a8269b8e1268c)
---
CMakeLists.txt | 14 +++++++-------
config-workspace.h.cmake | 8 ++++++--
kcms/region_language/kcmregionandlang.cpp | 16 ++++++++++++++--
kcms/region_language/kcmregionandlang.h | 7 +++++++
kcms/region_language/languagelistmodel.cpp | 6 ++++++
kcms/region_language/localegenerator.cpp | 6 +++---
6 files changed, 43 insertions(+), 14 deletions(-)
diff --git a/CMakeLists.txt CMakeLists.txt
index 54da6be721..af371f8455 100644
--- a/CMakeLists.txt
+++ CMakeLists.txt
@@ -209,7 +209,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
#
# For Glibc systems that come with pre-generated locales, such as Fedora and openSUSE
# a note to let user install fonts themselves if required is displayed
- # You should enable GLIBC_LOCALE_GENERATED option
+ # You should enable GLIBC_LOCALE_PREGENERATED option
#
# For non-glibc systems such as VoidLinux and *BSD
# A warning of configure locale manually is displayed (although the relevant ENVs are set by Plasma)
@@ -250,18 +250,18 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
message(FATAL_ERROR "UBUNTU_PACKAGEKIT and GLIBC_LOCALE_GEN both enabled, only UBUNTU_PACKEGKIT will be used")
endif()
if(GLIBC_LOCALE_GEN)
- set(GLIBC_LOCALE TRUE)
+ set(GLIBC_LOCALE_AUTO TRUE)
endif()
if(UBUNTU_PACKAGEKIT OR GLIBC_LOCALE_GEN)
set(REGION_LANG_GENERATE_LOCALE_HELPER TRUE)
endif()
- option(GLIBC_LOCALE_GENERATED "Systems that don't require locale generation. Such as openSUSE or Fedora" OFF)
- if(GLIBC_LOCALE_GENERATED)
- set(LOCALE_GENERATED TRUE)
+ option(GLIBC_LOCALE_PREGENERATED "Systems that don't require locale generation. Such as openSUSE or Fedora" OFF)
+ if(GLIBC_LOCALE_PREGENERATED)
+ set(GLIBC_LOCALE_GENERATED TRUE)
endif()
- if(REGION_LANG_GENERATE_LOCALE_HELPER AND GLIBC_LOCALE_GENERATED)
- message(FATAL_ERROR "(UBUNTU_PACKAGEKIT || GLIBC_LOCALE_GEN) and GLIBC_LOCALE_GENERATED both enabled")
+ if(REGION_LANG_GENERATE_LOCALE_HELPER AND GLIBC_LOCALE_PREGENERATED)
+ message(FATAL_ERROR "(UBUNTU_PACKAGEKIT || GLIBC_LOCALE_GEN) and GLIBC_LOCALE_PREGENERATED both enabled")
endif()
################## Find libraries ###################
diff --git a/config-workspace.h.cmake config-workspace.h.cmake
index d7cf5fe7ed..b696cd8fa5 100644
--- a/config-workspace.h.cmake
+++ config-workspace.h.cmake
@@ -12,5 +12,9 @@
#define WORKSPACE_VERSION_STRING "${PROJECT_VERSION}"
#cmakedefine OS_UBUNTU 1
-#cmakedefine GLIBC_LOCALE 1
-#cmakedefine LOCALE_GENERATED 1
+#cmakedefine01 GLIBC_LOCALE_AUTO
+#cmakedefine01 GLIBC_LOCALE_GENERATED
+
+#if defined(GLIBC_LOCALE_AUTO) || defined(GLIBC_LOCALE_GENERATED)
+#define GLIBC_LOCALE
+#endif
diff --git a/kcms/region_language/kcmregionandlang.cpp kcms/region_language/kcmregionandlang.cpp
index 9e99466a40..364b8767cd 100644
--- a/kcms/region_language/kcmregionandlang.cpp
+++ kcms/region_language/kcmregionandlang.cpp
@@ -2,10 +2,11 @@
kcmregionandlang.cpp
SPDX-FileCopyrightText: 2014 Sebastian Kügler <sebas@kde.org>
SPDX-FileCopyrightText: 2021 Han Young <hanyoung@protonmail.com>
+ SPDX-FileCopyrightText: 2023 Serenity Cybersecurity, LLC <license@futurecrew.ru>
+ Author: Gleb Popov <arrowd@FreeBSD.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
-#include "config-workspace.h"
#include "kcmregionandlang.h"
@@ -60,6 +61,7 @@ KCMRegionAndLang::KCMRegionAndLang(QObject *parent, const KPluginMetaData &data,
qRegisterMetaType<KCM_RegionAndLang::SettingType>();
qmlRegisterUncreatableMetaObject(KCM_RegionAndLang::staticMetaObject, "kcmregionandlang", 1, 0, "SettingType", "Error: SettingType is an enum");
+#ifdef GLIBC_LOCALE_GENERATED
// fedora pre generate locales, fetch available locales from localectl. /usr/share/i18n/locales is empty in fedora
QDir glibcLocaleDir(localeFileDirPath());
if (glibcLocaleDir.isEmpty()) {
@@ -80,6 +82,9 @@ KCMRegionAndLang::KCMRegionAndLang(QObject *parent, const KPluginMetaData &data,
} else {
m_enabled = true;
}
+#else
+ m_enabled = true;
+#endif
}
QString KCMRegionAndLang::failedFindLocalesMessage()
@@ -124,6 +129,7 @@ void KCMRegionAndLang::save()
if (!settings()->isDefaultSetting(SettingType::PhoneNumbers)) {
locales.append(settings()->phoneNumbers());
}
+#ifdef GLIBC_LOCALE
if (!settings()->language().isEmpty()) {
QStringList languages = settings()->language().split(QLatin1Char(':'));
for (const QString &lang : languages) {
@@ -133,6 +139,7 @@ void KCMRegionAndLang::save()
}
}
}
+#endif
auto setLangCall = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.Accounts"),
QStringLiteral("/org/freedesktop/Accounts/User%1").arg(getuid()),
@@ -214,7 +221,7 @@ bool KCMRegionAndLang::isGlibc()
{
#ifdef OS_UBUNTU
return true;
-#elif GLIBC_LOCALE
+#elif defined(GLIBC_LOCALE)
return true;
#else
return false;
@@ -226,6 +233,7 @@ bool KCMRegionAndLang::enabled() const
return m_enabled;
}
+#ifdef GLIBC_LOCALE
std::optional<QString> KCMRegionAndLang::toGlibcLocale(const QString &lang)
{
static std::unordered_map<QString, QString> map = constructGlibcLocaleMap();
@@ -235,6 +243,7 @@ std::optional<QString> KCMRegionAndLang::toGlibcLocale(const QString &lang)
}
return std::nullopt;
}
+#endif
QString KCMRegionAndLang::toUTF8Locale(const QString &locale)
{
@@ -252,6 +261,7 @@ QString KCMRegionAndLang::toUTF8Locale(const QString &locale)
return locale + QLatin1String(".UTF-8");
}
+#ifdef GLIBC_LOCALE
std::unordered_map<QString, QString> KCMRegionAndLang::constructGlibcLocaleMap()
{
std::unordered_map<QString, QString> localeMap;
@@ -338,5 +348,7 @@ std::unordered_map<QString, QString> KCMRegionAndLang::constructGlibcLocaleMap()
}
return localeMap;
}
+#endif
+
#include "kcmregionandlang.moc"
#include "moc_kcmregionandlang.cpp"
diff --git a/kcms/region_language/kcmregionandlang.h kcms/region_language/kcmregionandlang.h
index bdf9d19dbb..4649983b03 100644
--- a/kcms/region_language/kcmregionandlang.h
+++ kcms/region_language/kcmregionandlang.h
@@ -2,6 +2,8 @@
kcmregionandlang.h
SPDX-FileCopyrightText: 2014 Sebastian Kügler <sebas@kde.org>
SPDX-FileCopyrightText: 2021 Han Young <hanyoung@protonmail.com>
+ SPDX-FileCopyrightText: 2023 Serenity Cybersecurity, LLC <license@futurecrew.ru>
+ Author: Gleb Popov <arrowd@FreeBSD.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
@@ -11,6 +13,7 @@
#include <optional>
#include <unordered_map>
+#include "config-workspace.h"
#include "settingtype.h"
#include <KConfigGroup>
@@ -36,7 +39,9 @@ public:
OptionsModel *optionsModel() const;
bool enabled() const;
static bool isGlibc();
+#ifdef GLIBC_LOCALE
std::optional<QString> toGlibcLocale(const QString &lang);
+#endif
Q_INVOKABLE void unset(KCM_RegionAndLang::SettingType setting);
Q_INVOKABLE void reboot();
Q_SIGNALS:
@@ -53,7 +58,9 @@ private Q_SLOTS:
void saveToConfigFile();
private:
+#ifdef GLIBC_LOCALE
std::unordered_map<QString, QString> constructGlibcLocaleMap();
+#endif
static QString failedFindLocalesMessage();
static QString localeFileDirPath();
static QString toUTF8Locale(const QString &locale);
diff --git a/kcms/region_language/languagelistmodel.cpp kcms/region_language/languagelistmodel.cpp
index d9846226da..cc73178f86 100644
--- a/kcms/region_language/languagelistmodel.cpp
+++ kcms/region_language/languagelistmodel.cpp
@@ -2,6 +2,8 @@
languagelistmodel.h
SPDX-FileCopyrightText: 2021 Han Young <hanyoung@protonmail.com>
SPDX-FileCopyrightText: 2019 Kevin Ottens <kevin.ottens@enioka.com>
+ SPDX-FileCopyrightText: 2023 Serenity Cybersecurity, LLC <license@futurecrew.ru>
+ Author: Gleb Popov <arrowd@FreeBSD.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
@@ -384,10 +386,14 @@ void SelectedLanguageModel::saveLanguages()
Q_EMIT unsupportedLanguageChanged();
}
+#ifdef GLIBC_LOCALE
auto glibcLang = m_kcm->toGlibcLocale(m_selectedLanguages.front());
if (glibcLang.has_value()) {
m_settings->setLang(glibcLang.value());
}
+#else
+ m_settings->setLang(m_selectedLanguages.front());
+#endif
}
QString languages;
for (auto i = m_selectedLanguages.cbegin(); i != m_selectedLanguages.cend(); i++) {
diff --git a/kcms/region_language/localegenerator.cpp kcms/region_language/localegenerator.cpp
index 2da02617a4..fb8033c95d 100644
--- a/kcms/region_language/localegenerator.cpp
+++ kcms/region_language/localegenerator.cpp
@@ -15,7 +15,7 @@
#ifdef OS_UBUNTU
#include "localegeneratorubuntu.h"
-#elif GLIBC_LOCALE
+#elif GLIBC_LOCALE_AUTO
#include "localegeneratorglibc.h"
#endif
@@ -23,9 +23,9 @@ LocaleGeneratorBase *LocaleGenerator::getGenerator()
{
#ifdef OS_UBUNTU
static LocaleGeneratorUbuntu singleton;
-#elif GLIBC_LOCALE
+#elif GLIBC_LOCALE_AUTO
static LocaleGeneratorGlibc singleton;
-#elif LOCALE_GENERATED
+#elif GLIBC_LOCALE_GENERATED
static LocaleGeneratorGeneratedGlibc singleton;
#else
static LocaleGeneratorBase singleton;
--
GitLab