3 Copyright (C) 2011 Luciano Montanaro <mikelima@cirulla.net>
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.
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.
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.
23 #include "dataprovider.h"
24 #include "stationview.h"
25 #include "stationlistmodel.h"
26 #include "stationlistview.h"
27 #include "settingsdialog.h"
31 #include <QMessageBox>
32 #include <QNetworkAccessManager>
33 #include <QNetworkReply>
34 #include <QNetworkRequest>
40 #include <QGeoPositionInfoSource>
43 static const int RECENT_STATIONS_MAX_COUNT = 10;
47 App::App(QObject *parent) :
49 dataProvider(new DataProvider(this)),
50 checkingTimer(new QTimer(this)),
51 stationView(new StationView()),
52 stationListModel(new StationListModel(this)),
53 stationListView(new StationListView(stationListModel, stationView))
55 stationListModel->load("stations:stations.qpl");
57 connect(dataProvider, SIGNAL(stationScheduleReady(QByteArray, QUrl)),
58 SLOT(downloadFinished(QByteArray)));
60 connect(stationListView, SIGNAL(stationSelected(QString)),
61 SLOT(queryStation(QString)));
63 connect(stationListView, SIGNAL(aboutTriggered()),
64 SLOT(showAboutDialog()));
65 connect(stationView, SIGNAL(aboutTriggered()),
66 SLOT(showAboutDialog()));
68 connect(stationListView, SIGNAL(settingsChangeRequested()),
69 SLOT(showSettingsDialog()));
70 connect(stationView, SIGNAL(settingsChangeRequested()),
71 SLOT(showSettingsDialog()));
73 connect(stationView, SIGNAL(stationListSelectTriggered()),
74 SLOT(showStationSelectView()));
78 qDebug() << "found" << stationListModel->rowCount() << "stations";
80 connect(checkingTimer, SIGNAL(timeout()), SLOT(updateStation()));
82 Settings *settings = Settings::instance();
83 if (settings->recentStations().isEmpty() || !settings->stationViewPreferred()) {
84 stationListView->show();
97 void App::downloadFinished(const QByteArray &data)
99 stationView->updateView(data);
100 stationListView->hide();
102 stationListView->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
106 void App::queryStation(const QString &station)
108 dataProvider->stationSchedule(station);
110 stationListView->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
114 void App::updateStation()
116 if (!stationListView->isVisible()) {
117 dataProvider->updateStation();
121 void App::showSettingsDialog()
123 qDebug() << "Settings Dialog called";
125 SettingsDialog *dialog = new SettingsDialog(stationView);
126 if (dialog->exec() == QDialog::Accepted) {
132 void App::showAboutDialog()
134 qDebug() << "About Dialog called";
135 QString name = QApplication::instance()->applicationName();
136 QString version = QApplication::instance()->applicationVersion();
137 QString aboutText = QString(
139 "<a href='http://quandoparte.garage.maemo.org'>%1</a> version %2"
141 "<p>Copyright (c) 2010, 2011</p>"
142 "<p>Luciano Montanaro (mikelima@cirulla.net)</p>"
143 "<p>Licensed under the GNU Public License v2 or above</p>"
144 "<p>Station geolocation data from "
145 "<a href='http://www.openstreetmap.org'>OpenStreetMap</a>"
147 "<p>Realtime train data from "
148 "<a href='http://mobile.viaggiatreno.it'>Viaggiatreno</a>"
149 "</p>")).arg(name).arg(version);
150 QMessageBox::about(stationView, name, aboutText);
153 void App::showStationSelectView(void)
155 stationListView->show();
158 void App::readSettings(void)
160 Settings *settings = Settings::instance();
161 stationView->setBaseUrl(settings->queryBaseUrl() + "stazione");
164 I would use > 0 here, but people may have an old settings file with a 2
165 seconds timeout which is way too short.
166 As a workaround I consider anything less than 30 seconds as too short
167 and disable the timer.
169 if (settings->checkingInterval() > 30000) {
170 checkingTimer->setInterval(settings->checkingInterval());
171 checkingTimer->start();
173 checkingTimer->setInterval(-1);
174 checkingTimer->stop();
178 void App::saveSettings(void)
180 Settings::instance()->save();
183 QString App::dataDir(void)
185 return QString(DATADIR);