From 1ea4748f05e4e7913383ab60e4d0718a8e0dd06b Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 <0xFEEDC0DE64@gmail.com> Date: Fri, 25 May 2018 19:28:13 +0200 Subject: [PATCH] WeatherSettings error handling --- plugins/weatherplugin/weathersettings.cpp | 20 ++++++++++++++++---- plugins/weatherplugin/weathersettings.h | 4 +++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/plugins/weatherplugin/weathersettings.cpp b/plugins/weatherplugin/weathersettings.cpp index fc9a99c..26463f0 100644 --- a/plugins/weatherplugin/weathersettings.cpp +++ b/plugins/weatherplugin/weathersettings.cpp @@ -17,11 +17,23 @@ QUrl WeatherSettings::url() const return m_settings.value(m_url, m_defaultUrl).toUrl(); } -void WeatherSettings::setUrl(const QUrl &url) +bool WeatherSettings::setUrl(const QUrl &url) { - if(this->url() != url) - { - m_settings.setValue(m_url, url); + if(this->url() == url) + return true; + + m_settings.setValue(m_url, url); + + m_settings.sync(); + + const auto success = m_settings.status() == QSettings::NoError; + if(success) Q_EMIT urlChanged(url); + else + { + Q_EMIT m_settings.saveErrorOccured(); + Q_EMIT saveErrorOccured(); } + + return success; } diff --git a/plugins/weatherplugin/weathersettings.h b/plugins/weatherplugin/weathersettings.h index c137b6f..aa9fb2f 100644 --- a/plugins/weatherplugin/weathersettings.h +++ b/plugins/weatherplugin/weathersettings.h @@ -14,9 +14,11 @@ public: WeatherSettings(ZeiterfassungSettings &settings, QObject *parent = Q_NULLPTR); QUrl url() const; - void setUrl(const QUrl &url); + bool setUrl(const QUrl &url); Q_SIGNALS: + void saveErrorOccured(); + void urlChanged(const QUrl &url); private: