LunchMealSettings error handling
This commit is contained in:
@@ -19,13 +19,25 @@ QString LunchMealSettings::url() const
|
||||
return m_settings.value(m_url, m_defaultUrl).toString();
|
||||
}
|
||||
|
||||
void LunchMealSettings::setUrl(const QString &url)
|
||||
bool LunchMealSettings::setUrl(const QString &url)
|
||||
{
|
||||
if(this->url() != url)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("LunchMealPlugin/url"), url);
|
||||
if(this->url() == url)
|
||||
return true;
|
||||
|
||||
m_settings.setValue(QStringLiteral("LunchMealPlugin/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;
|
||||
}
|
||||
|
||||
QString LunchMealSettings::dateFormat() const
|
||||
@@ -33,11 +45,23 @@ QString LunchMealSettings::dateFormat() const
|
||||
return m_settings.value(m_dateFormat, m_defaultDateFormat).toString();
|
||||
}
|
||||
|
||||
void LunchMealSettings::setDateFormat(const QString &dateFormat)
|
||||
bool LunchMealSettings::setDateFormat(const QString &dateFormat)
|
||||
{
|
||||
if(this->dateFormat() != dateFormat)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("LunchMealPlugin/dateFormat"), dateFormat);
|
||||
if(this->dateFormat() == dateFormat)
|
||||
return true;
|
||||
|
||||
m_settings.setValue(QStringLiteral("LunchMealPlugin/dateFormat"), dateFormat);
|
||||
|
||||
m_settings.sync();
|
||||
|
||||
const auto success = m_settings.status() == QSettings::NoError;
|
||||
if(success)
|
||||
Q_EMIT dateFormatChanged(dateFormat);
|
||||
else
|
||||
{
|
||||
Q_EMIT m_settings.saveErrorOccured();
|
||||
Q_EMIT saveErrorOccured();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
@@ -16,12 +16,14 @@ public:
|
||||
|
||||
// no QString becuase placeholder %0 encodes wrong in urls!
|
||||
QString url() const;
|
||||
void setUrl(const QString &url);
|
||||
bool setUrl(const QString &url);
|
||||
|
||||
QString dateFormat() const;
|
||||
void setDateFormat(const QString &dateFormat);
|
||||
bool setDateFormat(const QString &dateFormat);
|
||||
|
||||
Q_SIGNALS:
|
||||
void saveErrorOccured();
|
||||
|
||||
void urlChanged(const QString &url);
|
||||
void dateFormatChanged(const QString &dateFormat);
|
||||
|
||||
|
Reference in New Issue
Block a user