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