+/*
+
+Copyright (C) 2011 Luciano Montanaro <mikelima@cirulla.net>
+
+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 <QDebug>
+#include <QSettings>
+#include <QStringList>
+
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);
}
#ifndef SETTINGS_H
#define SETTINGS_H
+/*
+
+Copyright (C) 2011 Luciano Montanaro <mikelima@cirulla.net>
+
+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 <QObject>
+#include <QString>
+#include <QStringList>
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