Updated qmake file, bumped version
[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 <QCoreApplication>
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 QStringList Settings::favoriteStations()
89 {
90     QSettings settings;
91
92     return settings.value("FavoriteStations").toString().split(",");
93 }
94
95 void Settings::setFavoriteStations(const QStringList &stations)
96 {
97     QSettings settings;
98
99     settings.setValue("FavoriteStations", stations.join(","));
100     emit favoriteStationsChanged();
101 }
102
103 int Settings::checkingInterval()
104 {
105     QSettings settings;
106
107     return settings.value("CheckInterval", 0).toInt();
108 }
109
110 void Settings::setCheckingInterval(int interval)
111 {
112     QSettings settings;
113
114     settings.setValue("CheckInterval", interval);
115     emit checkingIntervalChanged();
116 }
117
118 bool Settings::autoUpdate()
119 {
120     QSettings settings;
121
122     bool current = settings.value("AutoUpdate", false).toBool();
123     qDebug() << "AutoUpdate is" << current;
124     return current;
125 }
126
127 void Settings::setAutoUpdate(bool preference)
128 {
129     QSettings settings;
130
131     settings.setValue("AutoUpdate", preference);
132     qDebug() << "AutoUpdate set to" << preference;
133     emit autoUpdateChanged();
134 }
135
136 bool Settings::stationViewPreferred()
137 {
138     QSettings settings;
139
140     return settings.value("StationViewPreferred", false).toBool();
141 }
142
143 void Settings::setStationViewPreferred(bool preference)
144 {
145     QSettings settings;
146
147     settings.setValue("StationViewPreferred", preference);
148     emit stationViewPreferredChanged();
149 }
150
151 bool Settings::darkThemePreferred()
152 {
153     QSettings settings;
154
155     return settings.value("DarkThemePreferred", false).toBool();
156 }
157
158 void Settings::setDarkThemePreferred(bool preference)
159 {
160     QSettings settings;
161
162     settings.setValue("DarkThemePreferred", preference);
163     emit stationViewPreferredChanged();
164 }
165
166 bool Settings::showArrivalsPreferred()
167 {
168     QSettings settings;
169
170     return settings.value("StationView/ShowArrivals", false).toBool();
171 }
172
173 void Settings::setShowArrivalsPreferred(bool preference)
174 {
175     QSettings settings;
176
177     settings.setValue("StationView/ShowArrivals", preference);
178     emit showArrivalsPreferredChanged();
179 }
180
181 StationListProxyModel::SortingMode Settings::stationListSortingMode()
182 {
183     QSettings settings;
184
185     int mode = settings.value("StationListView/SortingMode").toInt();
186     qDebug() << "StationListSortingMode is" << mode;
187     return (StationListProxyModel::SortingMode)mode;
188 }
189
190 void Settings::setStationListSortingMode(StationListProxyModel::SortingMode mode)
191 {
192     QSettings settings;
193
194     settings.setValue("StationListView/SortingMode", mode);
195     qDebug() << "StationListSortingMode set to" << mode;
196     emit stationListSortingModeChanged();
197 }
198
199 QString Settings::versionString()
200 {
201     return qApp->applicationVersion();
202 }