File indexing completed on 2025-02-02 05:02:34
0001 /* 0002 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "config-itinerary.h" 0008 #include "settings.h" 0009 0010 #include <KCountry> 0011 0012 #include <QDebug> 0013 #include <QLocale> 0014 #include <QSettings> 0015 0016 Settings::Settings(QObject *parent) 0017 : QObject(parent) 0018 { 0019 QSettings s; 0020 s.beginGroup(QLatin1StringView("Settings")); 0021 m_weatherEnabled = s.value(QLatin1StringView("WeatherForecastEnabled"), false).toBool(); 0022 0023 const auto currentCountry = KCountry::fromQLocale(QLocale().country()).alpha2(); 0024 m_homeCountry = s.value(QLatin1StringView("HomeCountry"), currentCountry).toString(); 0025 0026 m_queryLiveData = s.value(QLatin1StringView("QueryLiveData"), false).toBool(); 0027 0028 m_preloadMapData = s.value(QLatin1StringView("PreloadMapData"), false).toBool(); 0029 0030 m_currencyConversion = s.value(QLatin1StringView("PerformCurrencyConversion"), false).toBool(); 0031 0032 m_autoAddTransfers = s.value(QLatin1StringView("AutoAddTransfers"), true).toBool(); 0033 m_autoFillTransfers = s.value(QLatin1StringView("AutoFillTransfers"), false).toBool() && m_queryLiveData && m_autoAddTransfers; 0034 0035 m_showNotificationOnLockScreen = s.value(QLatin1StringView("ShowNotificationOnLockScreen"), false).toBool(); 0036 0037 m_osmContributorMode = s.value(QLatin1StringView("OsmContributorMode"), false).toBool(); 0038 m_developmentMode = s.value(QLatin1StringView("DevelopmentMode"), false).toBool(); 0039 } 0040 0041 Settings::~Settings() = default; 0042 0043 QVariant Settings::read(const QString &key, const QVariant &defaultValue) const 0044 { 0045 QSettings s; 0046 return s.value(key, defaultValue); 0047 } 0048 0049 void Settings::write(const QString& key, const QVariant& value) 0050 { 0051 QSettings s; 0052 s.setValue(key, value); 0053 } 0054 0055 bool Settings::weatherForecastEnabled() const 0056 { 0057 return m_weatherEnabled; 0058 } 0059 0060 void Settings::setWeatherForecastEnabled(bool enabled) 0061 { 0062 if (m_weatherEnabled == enabled) { 0063 return; 0064 } 0065 0066 m_weatherEnabled = enabled; 0067 QSettings s; 0068 s.beginGroup(QLatin1StringView("Settings")); 0069 s.setValue(QLatin1StringView("WeatherForecastEnabled"), enabled); 0070 0071 Q_EMIT weatherForecastEnabledChanged(enabled); 0072 } 0073 0074 QString Settings::homeCountryIsoCode() const 0075 { 0076 return m_homeCountry; 0077 } 0078 0079 void Settings::setHomeCountryIsoCode(const QString& isoCode) 0080 { 0081 if (m_homeCountry == isoCode) { 0082 return; 0083 } 0084 0085 m_homeCountry = isoCode; 0086 QSettings s; 0087 s.beginGroup(QLatin1StringView("Settings")); 0088 s.setValue(QLatin1StringView("HomeCountry"), isoCode); 0089 0090 Q_EMIT homeCountryIsoCodeChanged(isoCode); 0091 } 0092 0093 bool Settings::queryLiveData() const 0094 { 0095 return m_queryLiveData; 0096 } 0097 0098 void Settings::setQueryLiveData(bool queryLiveData) 0099 { 0100 if (!queryLiveData) { 0101 setAutoFillTransfers(false); 0102 } 0103 0104 if (m_queryLiveData == queryLiveData) { 0105 return; 0106 } 0107 0108 m_queryLiveData = queryLiveData; 0109 QSettings s; 0110 s.beginGroup(QLatin1StringView("Settings")); 0111 s.setValue(QLatin1StringView("QueryLiveData"), queryLiveData); 0112 0113 Q_EMIT queryLiveDataChanged(queryLiveData); 0114 } 0115 0116 bool Settings::preloadMapData() const 0117 { 0118 return m_preloadMapData; 0119 } 0120 0121 void Settings::setPreloadMapData(bool preload) 0122 { 0123 if (m_preloadMapData == preload) { 0124 return; 0125 } 0126 0127 m_preloadMapData = preload; 0128 QSettings s; 0129 s.beginGroup(QLatin1StringView("Settings")); 0130 s.setValue(QLatin1StringView("PreloadMapData"), preload); 0131 0132 Q_EMIT preloadMapDataChanged(preload); 0133 } 0134 0135 bool Settings::performCurrencyConversion() const 0136 { 0137 return m_currencyConversion; 0138 } 0139 0140 void Settings::setPerformCurrencyConversion(bool enable) 0141 { 0142 if (m_currencyConversion == enable) { 0143 return; 0144 } 0145 0146 m_currencyConversion = enable; 0147 QSettings s; 0148 s.beginGroup(QLatin1StringView("Settings")); 0149 s.setValue(QLatin1StringView("PerformCurrencyConversion"), enable); 0150 0151 Q_EMIT performCurrencyConversionChanged(enable); 0152 } 0153 0154 bool Settings::autoAddTransfers() const 0155 { 0156 return m_autoAddTransfers; 0157 } 0158 0159 void Settings::setAutoAddTransfers(bool autoAdd) 0160 { 0161 if (!autoAdd) { 0162 setAutoFillTransfers(false); 0163 } 0164 0165 if (m_autoAddTransfers == autoAdd) { 0166 return; 0167 } 0168 0169 m_autoAddTransfers = autoAdd; 0170 QSettings s; 0171 s.beginGroup(QLatin1StringView("Settings")); 0172 s.setValue(QLatin1StringView("AutoAddTransfers"), autoAdd); 0173 0174 Q_EMIT autoAddTransfersChanged(autoAdd); 0175 } 0176 0177 bool Settings::autoFillTransfers() const 0178 { 0179 return m_autoFillTransfers && m_queryLiveData && m_autoAddTransfers; 0180 } 0181 0182 void Settings::setAutoFillTransfers(bool autoFill) 0183 { 0184 if (m_autoFillTransfers == autoFill) { 0185 return; 0186 } 0187 0188 m_autoFillTransfers = autoFill; 0189 QSettings s; 0190 s.beginGroup(QLatin1StringView("Settings")); 0191 s.setValue(QLatin1StringView("AutoFillTransfers"), autoFill); 0192 0193 Q_EMIT autoFillTransfersChanged(autoFill); 0194 } 0195 0196 bool Settings::showNotificationOnLockScreen() const 0197 { 0198 return m_showNotificationOnLockScreen; 0199 } 0200 0201 void Settings::setShowNotificationOnLockScreen(bool enabled) 0202 { 0203 if (m_showNotificationOnLockScreen == enabled) { 0204 return; 0205 } 0206 0207 m_showNotificationOnLockScreen = enabled; 0208 QSettings s; 0209 s.beginGroup(QLatin1StringView("Settings")); 0210 s.setValue(QLatin1StringView("ShowNotificationOnLockScreen"), m_showNotificationOnLockScreen); 0211 0212 Q_EMIT showNotificationOnLockScreenChanged(m_showNotificationOnLockScreen); 0213 } 0214 0215 void Settings::setOsmContributorMode(bool enabled) 0216 { 0217 if (m_osmContributorMode == enabled) { 0218 return; 0219 } 0220 0221 m_osmContributorMode = enabled; 0222 QSettings s; 0223 s.beginGroup(QLatin1StringView("Settings")); 0224 s.setValue(QLatin1StringView("OsmContributorMode"), m_osmContributorMode); 0225 0226 Q_EMIT osmContributorModeChanged(m_osmContributorMode); 0227 } 0228 0229 bool Settings::developmentMode() const 0230 { 0231 return m_developmentMode; 0232 } 0233 0234 void Settings::setDevelopmentMode(bool enabled) 0235 { 0236 if (m_developmentMode == enabled) { 0237 return; 0238 } 0239 0240 m_developmentMode = enabled; 0241 QSettings s; 0242 s.beginGroup(QLatin1StringView("Settings")); 0243 s.setValue(QLatin1StringView("DevelopmentMode"), m_developmentMode); 0244 Q_EMIT developmentModeChanged(m_developmentMode); 0245 } 0246 0247 #include "moc_settings.cpp"