File indexing completed on 2024-05-26 16:53:40
0001 /* 0002 kcmregionandlang.h 0003 SPDX-FileCopyrightText: 2014 Sebastian Kügler <sebas@kde.org> 0004 SPDX-FileCopyrightText: 2021 Han Young <hanyoung@protonmail.com> 0005 SPDX-FileCopyrightText: 2023 Serenity Cybersecurity, LLC <license@futurecrew.ru> 0006 Author: Gleb Popov <arrowd@FreeBSD.org> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #pragma once 0012 0013 #include <optional> 0014 #include <unordered_map> 0015 0016 #include "config-workspace.h" 0017 #include "settingtype.h" 0018 0019 #include <KConfigGroup> 0020 #include <KQuickAddons/ManagedConfigModule> 0021 0022 class RegionAndLangSettings; 0023 class OptionsModel; 0024 class LocaleGeneratorBase; 0025 0026 class KCMRegionAndLang : public KQuickAddons::ManagedConfigModule 0027 { 0028 Q_OBJECT 0029 Q_PROPERTY(RegionAndLangSettings *settings READ settings CONSTANT) 0030 Q_PROPERTY(OptionsModel *optionsModel READ optionsModel CONSTANT) 0031 Q_PROPERTY(bool enabled READ enabled NOTIFY enabledChanged) 0032 0033 public: 0034 explicit KCMRegionAndLang(QObject *parent, const KPluginMetaData &data, const QVariantList &list = QVariantList()); 0035 void save() override; 0036 0037 RegionAndLangSettings *settings() const; 0038 0039 OptionsModel *optionsModel() const; 0040 bool enabled() const; 0041 static bool isGlibc(); 0042 #ifdef GLIBC_LOCALE 0043 std::optional<QString> toGlibcLocale(const QString &lang); 0044 #endif 0045 Q_INVOKABLE void unset(KCM_RegionAndLang::SettingType setting); 0046 Q_INVOKABLE void reboot(); 0047 Q_SIGNALS: 0048 void saveClicked(); 0049 void takeEffectNextTime(); 0050 void startGenerateLocale(); 0051 void generateFinished(); 0052 void requireInstallFont(); 0053 void enabledChanged(); 0054 void encountedError(const QString &reason); 0055 void userHasToGenerateManually(const QString &reason); 0056 0057 private Q_SLOTS: 0058 void saveToConfigFile(); 0059 0060 private: 0061 #ifdef GLIBC_LOCALE 0062 std::unordered_map<QString, QString> constructGlibcLocaleMap(); 0063 #endif 0064 static QString failedFindLocalesMessage(); 0065 static QString localeFileDirPath(); 0066 static QString toUTF8Locale(const QString &locale); 0067 0068 QHash<QString, QString> m_cachedFlags; 0069 0070 RegionAndLangSettings *m_settings; 0071 OptionsModel *m_optionsModel; 0072 LocaleGeneratorBase *m_generator = nullptr; 0073 QProcess *m_localectl = nullptr; 0074 bool m_enabled = false; 0075 };