From 40e5a96fc8f277b74771d0bcc3173f4a7d68ffc3 Mon Sep 17 00:00:00 2001 From: Luciano Montanaro Date: Thu, 21 Jul 2011 00:54:34 +0200 Subject: [PATCH] Filled in setting class --- application/settings.cpp | 103 ++++++++++++++++++++++++++++++++++++++++++++++ application/settings.h | 61 +++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) diff --git a/application/settings.cpp b/application/settings.cpp index d19c1a0..29fd0bd 100644 --- a/application/settings.cpp +++ b/application/settings.cpp @@ -1,6 +1,109 @@ +/* + +Copyright (C) 2011 Luciano Montanaro + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +Boston, MA 02110-1301, USA. + +*/ + #include "settings.h" +#include +#include +#include + Settings::Settings(QObject *parent) : QObject(parent) { + load(); +} +Settings::~Settings() +{ + save(); +} + +void Settings::load() +{ + QSettings settings; + m_queryBaseUrl = settings.value("QueryURL", + "http://mobile.viaggiatreno.it/viaggiatreno/mobile/stazione").toString(); + + m_recentStations = settings.value("RecentStations").toString().split(","); + qDebug() << "RecentStations:" << m_recentStations; + + m_stationViewPreferred = settings.value("StationViewPreferred", false).toBool(); + qDebug() << "StationsViewPreferred:" << m_stationViewPreferred; + + m_checkingInterval = settings.value("CheckInterval", 0).toInt(); + qDebug() << "CheckInterval:" << m_checkingInterval; +} + +void Settings::save() +{ + QSettings settings; + + qDebug() << "Saving Settings to" << settings.fileName(); + + settings.setValue("QueryURL", m_queryBaseUrl); + settings.setValue("RecentStations", m_recentStations.join(",")); + settings.setValue("CheckInterval", m_checkingInterval); + settings.setValue("StationViewPreferred", m_stationViewPreferred); +} + +QString Settings::queryBaseUrl() +{ + return m_queryBaseUrl; +} + +void Settings::setQueryBaseUrl(const QString &url) +{ + m_queryBaseUrl = url; + emit queryBaseUrlChanged(m_queryBaseUrl); +} + +QStringList Settings::recentStations() +{ + return m_recentStations; +} + +void Settings::setRecentStations(const QStringList &stations) +{ + m_recentStations = stations; + emit recentStationsChanged(m_recentStations); +} + +int Settings::checkingInterval() +{ + return m_checkingInterval; +} + +void Settings::setCheckingInterval(int interval) +{ + m_checkingInterval = interval; + + emit checkingIntervalChanged(m_checkingInterval); +} + +bool Settings::stationViewPreferred() +{ + return m_stationViewPreferred; +} + +void Settings::setStationViewPreferred(bool preference) +{ + m_stationViewPreferred = preference; + emit stationViewPreferredChanged(m_stationViewPreferred); } diff --git a/application/settings.h b/application/settings.h index a9f0ea4..5b9fa5b 100644 --- a/application/settings.h +++ b/application/settings.h @@ -1,18 +1,79 @@ #ifndef SETTINGS_H #define SETTINGS_H +/* + +Copyright (C) 2011 Luciano Montanaro + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +Boston, MA 02110-1301, USA. + +*/ + #include +#include +#include class Settings : public QObject { Q_OBJECT + Q_PROPERTY(QString queryBaseUrl + READ queryBaseUrl WRITE setQueryBaseUrl + NOTIFY queryBaseUrlChanged) + Q_PROPERTY(QStringList recentStations + READ recentStations WRITE setRecentStations + NOTIFY recentStationsChanged) + Q_PROPERTY(int checkingInterval + READ checkingInterval WRITE setCheckingInterval + NOTIFY checkingIntervalChanged) + Q_PROPERTY(bool stationViewPreferred + READ stationViewPreferred WRITE setStationViewPreferred + NOTIFY stationViewPreferredChanged) + public: explicit Settings(QObject *parent = 0); + ~Settings(); + + Q_INVOKABLE void load(void); + Q_INVOKABLE void save(void); + + QString queryBaseUrl(); + void setQueryBaseUrl(const QString &url); + + QStringList recentStations(); + void setRecentStations(const QStringList &stations); + + int checkingInterval(); + void setCheckingInterval(int); + + bool stationViewPreferred(); + void setStationViewPreferred(bool); signals: + void queryBaseUrlChanged(const QString &); + void recentStationsChanged(const QStringList &); + void checkingIntervalChanged(int); + void stationViewPreferredChanged(bool); public slots: +private: + QString m_queryBaseUrl; + QStringList m_recentStations; + int m_checkingInterval; + bool m_stationViewPreferred; }; #endif // SETTINGS_H -- 1.7.9.5