Commit 7ab650d1 authored by Volker Krause's avatar Volker Krause

Add settings for live data auto-polling

parent 6c2c7919
......@@ -33,6 +33,11 @@ Kirigami.ScrollablePage {
Kirigami.FormLayout {
width: root.width
Kirigami.Separator {
Kirigami.FormData.isSection: true
Kirigami.FormData.label: i18n("Home")
}
QQC2.ComboBox {
Kirigami.FormData.label: i18n("Home Country")
model: countryModel
......@@ -41,6 +46,35 @@ Kirigami.ScrollablePage {
onActivated: _settings.homeCountryIsoCode = countryModel.isoCodeFromIndex(currentIndex)
}
Kirigami.Separator {
Kirigami.FormData.isSection: true
Kirigami.FormData.label: i18n("Online Services")
}
QQC2.Switch {
Kirigami.FormData.label: i18n("Query Traffic Data")
checked: _settings.queryLiveData
onToggled: _settings.queryLiveData = checked
}
QQC2.Label {
Kirigami.FormData.isSection: true
Layout.fillWidth: true
wrapMode: Text.WordWrap
text: i18n("When enabled, this will query transport provider online services for changes such as delays or gate and platform changes.")
}
QQC2.Switch {
Kirigami.FormData.label: i18n("Use insecure services")
checked: _settings.allowInsecureServices
onToggled: _settings.allowInsecureServices = checked
}
QQC2.Label {
Kirigami.FormData.isSection: true
Layout.fillWidth: true
wrapMode: Text.WordWrap
text: i18n("Enabling this will also use online services that do not offer transport encryption. This is not recommended, but might be unavoidable when relying on live data from certain providers.")
color: Kirigami.Theme.negativeTextColor
}
QQC2.Switch {
id: weatherSwitch
Kirigami.FormData.label: i18n("Weather Forecast")
......
......@@ -32,6 +32,9 @@ Settings::Settings(QObject *parent)
const auto currentCountry = KContacts::Address::countryToISO(QLocale::countryToString(QLocale().country())).toUpper();
m_homeCountry = s.value(QLatin1String("HomeCountry"), currentCountry).toString();
m_queryLiveData = s.value(QLatin1String("QueryLiveData"), false).toBool();
m_allowInsecureServices = s.value(QLatin1String("AllowInsecureServices"), false).toBool();
}
Settings::~Settings() = default;
......@@ -73,3 +76,42 @@ void Settings::setHomeCountryIsoCode(const QString& isoCode)
emit homeCountryIsoCodeChanged(isoCode);
}
bool Settings::queryLiveData() const
{
return m_queryLiveData;
}
void Settings::setQueryLiveData(bool queryLiveData)
{
if (m_queryLiveData == queryLiveData) {
return;
}
m_queryLiveData = queryLiveData;
QSettings s;
s.beginGroup(QLatin1String("Settings"));
s.setValue(QLatin1String("QueryLiveData"), queryLiveData);
emit queryLiveDataChanged();
}
bool Settings::allowInsecureServices() const
{
return m_allowInsecureServices;
}
void Settings::setAllowInsecureServices(bool allowInsecure)
{
if (m_allowInsecureServices == allowInsecure) {
return;
}
m_allowInsecureServices = allowInsecure;
QSettings s;
s.beginGroup(QLatin1String("Settings"));
s.setValue(QLatin1String("AllowInsecureServices"), allowInsecure);
emit allowInsecureServicesChanged();
}
......@@ -26,6 +26,8 @@ class Settings : public QObject
Q_OBJECT
Q_PROPERTY(bool weatherForecastEnabled READ weatherForecastEnabled WRITE setWeatherForecastEnabled NOTIFY weatherForecastEnabledChanged)
Q_PROPERTY(QString homeCountryIsoCode READ homeCountryIsoCode WRITE setHomeCountryIsoCode NOTIFY homeCountryIsoCodeChanged)
Q_PROPERTY(bool queryLiveData READ queryLiveData WRITE setQueryLiveData NOTIFY queryLiveDataChanged)
Q_PROPERTY(bool allowInsecureServices READ allowInsecureServices WRITE setAllowInsecureServices NOTIFY allowInsecureServicesChanged)
public:
explicit Settings(QObject *parent = nullptr);
~Settings();
......@@ -36,13 +38,22 @@ public:
QString homeCountryIsoCode() const;
void setHomeCountryIsoCode(const QString &isoCode);
bool queryLiveData() const;
void setQueryLiveData(bool queryLiveData);
bool allowInsecureServices() const;
void setAllowInsecureServices(bool allowInsecure);
signals:
void weatherForecastEnabledChanged(bool enabled);
void homeCountryIsoCodeChanged(const QString &isoCode);
void queryLiveDataChanged();
void allowInsecureServicesChanged();
private:
QString m_homeCountry;
bool m_weatherEnabled = false;
bool m_queryLiveData = false;
bool m_allowInsecureServices = false;
};
#endif // SETTINGS_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment