Fix error reporting in the station page
[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 <QApplication>
25 #include <QDebug>
26 #include <QSettings>
27 #include <QStringList>
28
29 Settings *Settings::instance()
30 {
31     static Settings *settings = 0;
32
33     if (!settings)
34         settings = new Settings();
35     return settings;
36 }
37
38 Settings::Settings(QObject *parent) :
39     QObject(parent)
40 {
41     qDebug() << "Settings constructor called";
42 }
43
44 Settings::~Settings()
45 {
46     qDebug() << "Settings destructor called";
47     save();
48 }
49
50 void Settings::save()
51 {
52     QSettings settings;
53
54     qDebug() << "Saving Settings to" << settings.fileName();
55     settings.sync();
56 }
57
58 QString Settings::queryBaseUrl()
59 {
60     QSettings settings;
61     return settings.value("QueryURL",
62                           "http://mobile.viaggiatreno.it/vt_pax_internet/mobile/").toString();
63 }
64
65 void Settings::setQueryBaseUrl(const QString &url)
66 {
67     QSettings settings;
68
69     settings.setValue("QueryURL", url);
70     emit queryBaseUrlChanged();
71 }
72
73 QStringList Settings::recentStations()
74 {
75     QSettings settings;
76
77     return settings.value("RecentStations").toString().split(",");
78 }
79
80 void Settings::setRecentStations(const QStringList &stations)
81 {
82     QSettings settings;
83
84     settings.setValue("RecentStations", stations.join(","));
85     emit recentStationsChanged();
86 }
87
88 int Settings::checkingInterval()
89 {
90     QSettings settings;
91
92     return settings.value("CheckInterval", 0).toInt();
93 }
94
95 void Settings::setCheckingInterval(int interval)
96 {
97     QSettings settings;
98
99     settings.setValue("CheckInterval", interval);
100     emit checkingIntervalChanged();
101 }
102
103 bool Settings::autoUpdate()
104 {
105     QSettings settings;
106
107     bool current = settings.value("AutoUpdate", false).toBool();
108     qDebug() << "AutoUpdate is" << current;
109     return current;
110 }
111
112 void Settings::setAutoUpdate(bool preference)
113 {
114     QSettings settings;
115
116     settings.setValue("AutoUpdate", preference);
117     qDebug() << "AutoUpdate set to" << preference;
118     emit autoUpdateChanged();
119 }
120
121 bool Settings::stationViewPreferred()
122 {
123     QSettings settings;
124
125     return settings.value("StationViewPreferred", false).toBool();
126 }
127
128 void Settings::setStationViewPreferred(bool preference)
129 {
130     QSettings settings;
131
132     settings.setValue("StationViewPreferred", preference);
133     emit stationViewPreferredChanged();
134 }
135
136 bool Settings::showArrivalsPreferred()
137 {
138     QSettings settings;
139
140     return settings.value("StationView/ShowArrivals", false).toBool();
141 }
142
143 void Settings::setShowArrivalsPreferred(bool preference)
144 {
145     QSettings settings;
146
147     settings.setValue("StationView/ShowArrivals", preference);
148     emit showArrivalsPreferredChanged();
149 }
150
151 StationListProxyModel::SortingMode Settings::stationListSortingMode()
152 {
153     QSettings settings;
154
155     int mode = settings.value("StationListView/SortingMode").toInt();
156     qDebug() << "StationListSortingMode is" << mode;
157     return (StationListProxyModel::SortingMode)mode;
158 }
159
160 void Settings::setStationListSortingMode(StationListProxyModel::SortingMode mode)
161 {
162     QSettings settings;
163
164     settings.setValue("StationListView/SortingMode", mode);
165     qDebug() << "StationListSortingMode set to" << mode;
166     emit stationListSortingModeChanged();
167 }
168
169 QString Settings::versionString()
170 {
171     return qApp->applicationVersion();
172 }