Add showArrivalsPreferred property to settings class
[quandoparte] / application / settings.cpp
1 /*
2
3 Copyright (C) 2011 Luciano Montanaro <mikelima@cirulla.net>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING.  If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19
20 */
21
22 #include "settings.h"
23
24 #include <QDebug>
25 #include <QSettings>
26 #include <QStringList>
27
28 Settings::Settings(QObject *parent) :
29     QObject(parent)
30 {
31     load();
32 }
33 Settings::~Settings()
34 {
35     save();
36 }
37
38 void Settings::load()
39 {
40     QSettings settings;
41     m_queryBaseUrl = settings.value("QueryURL",
42                                   "http://mobile.viaggiatreno.it/viaggiatreno/mobile/stazione").toString();
43
44     m_recentStations = settings.value("RecentStations").toString().split(",");
45     qDebug() << "RecentStations:" << m_recentStations;
46
47     m_stationViewPreferred = settings.value("StationViewPreferred", false).toBool();
48     qDebug() << "StationsViewPreferred:" << m_stationViewPreferred;
49
50     m_checkingInterval = settings.value("CheckInterval", 0).toInt();
51     qDebug() << "CheckInterval:" << m_checkingInterval;
52
53     m_showArrivalsPreferred = settings.value("StationView/ShowArrivals", false).toBool();
54     qDebug() << "ShowArrivalsPreferred:" << m_showArrivalsPreferred;
55 }
56
57 void Settings::save()
58 {
59     QSettings settings;
60
61     qDebug() << "Saving Settings to" << settings.fileName();
62
63     settings.setValue("QueryURL", m_queryBaseUrl);
64     settings.setValue("RecentStations", m_recentStations.join(","));
65     settings.setValue("CheckInterval", m_checkingInterval);
66     settings.setValue("StationViewPreferred", m_stationViewPreferred);
67     settings.setValue("StationView/ShowArrivals", m_stationViewPreferred);
68 }
69
70 QString Settings::queryBaseUrl()
71 {
72     return m_queryBaseUrl;
73 }
74
75 void Settings::setQueryBaseUrl(const QString &url)
76 {
77     m_queryBaseUrl = url;
78     emit queryBaseUrlChanged(m_queryBaseUrl);
79 }
80
81 QStringList Settings::recentStations()
82 {
83     return m_recentStations;
84 }
85
86 void Settings::setRecentStations(const QStringList &stations)
87 {
88     m_recentStations = stations;
89     emit recentStationsChanged(m_recentStations);
90 }
91
92 int Settings::checkingInterval()
93 {
94     return m_checkingInterval;
95 }
96
97 void Settings::setCheckingInterval(int interval)
98 {
99     m_checkingInterval = interval;
100
101     emit checkingIntervalChanged(m_checkingInterval);
102 }
103
104 bool Settings::stationViewPreferred()
105 {
106     return m_stationViewPreferred;
107 }
108
109 void Settings::setStationViewPreferred(bool preference)
110 {
111     m_stationViewPreferred = preference;
112     emit stationViewPreferredChanged(m_stationViewPreferred);
113 }
114
115 Settings *Settings::instance()
116 {
117     static Settings *settings = 0;
118
119     if (!settings)
120         settings = new Settings();
121     return settings;
122 }
123
124 bool Settings::showArrivalsPreferred()
125 {
126     return m_showArrivalsPreferred;
127 }
128
129 void Settings::setShowArrivalsPreferred(bool preference)
130 {
131     m_showArrivalsPreferred = preference;
132     emit showArrivalsPreferredChanged(m_showArrivalsPreferred);
133 }