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 "stationview.h"
24 #include "stationlistmodel.h"
25 #include "stationlistview.h"
26 #include "settingsdialog.h"
29 #include <QMessageBox>
30 #include <QNetworkAccessManager>
31 #include <QNetworkReply>
32 #include <QNetworkRequest>
37 #include <QGeoPositionInfoSource>
41 App::App(QObject *parent) :
43 accessManager(new QNetworkAccessManager(this)),
44 positionInfoSource(QGeoPositionInfoSource::createDefaultSource(this)),
45 stationView(new StationView()),
46 stationListModel(new StationListModel(this)),
47 stationListView(new StationListView(stationListModel, stationView))
49 stationListModel->load(dataDir() + "stations/stations.qpl");
51 connect(positionInfoSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
52 stationListView, SLOT(updatePosition(QGeoPositionInfo)));
53 connect(stationListView, SIGNAL(stationSelected(const QString &)),
54 SLOT(queryStation(const QString &)));
55 connect(stationListView, SIGNAL(aboutTriggered()),
56 SLOT(showAboutDialog()));
57 connect(stationView, SIGNAL(aboutTriggered()),
58 SLOT(showAboutDialog()));
59 connect(stationView, SIGNAL(stationListSelectTriggered()),
60 SLOT(showStationSelectView()));
62 connect(stationView, SIGNAL(showingArrivalsChanged(bool)),
63 SLOT(setShowingArrivals(bool)));
66 qDebug() << "found" << stationListModel->rowCount() << "stations";
68 stationView->showMaximized();
73 if (stationName.isEmpty()) {
75 stationListView->showMaximized();
77 stationListView->show();
81 // Testing only: start updates rigt away.
82 positionInfoSource->startUpdates();
91 void App::downloadFinished(void)
93 disconnect(stationQueryReply, SIGNAL(finished()),
94 this, SLOT(downloadFinished()));
95 stationView->updateView(stationQueryReply->readAll());
96 stationListView->hide();
97 stationQueryReply->deleteLater();
98 stationQueryReply = 0;
100 stationListView->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
104 void App::queryStation(const QString &station)
106 QNetworkRequest request;
107 request.setUrl(queryBaseUrl);
108 const QString queryString = "stazione=" + station;
109 const QByteArray query(queryString.toLocal8Bit());
110 stationQueryReply = accessManager->post(request, query);
111 connect(stationQueryReply, SIGNAL(finished()),
112 this, SLOT(downloadFinished()));
114 stationListView->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
118 void App::showSettingsDialog()
122 void App::showAboutDialog()
124 qDebug() << "About Dialog called";
125 QString name = QApplication::instance()->applicationName();
126 QString version = QApplication::instance()->applicationVersion();
127 QString aboutText = QString(
128 tr("<p>%1 version %2</p>"
129 "<p>Copyright (c) 2010, 2011</p>"
130 "<p>Luciano Montanaro (mikelima@cirulla.net)</p>"
131 "<p>Licensed under the GNU Public License v2 or above</p>")).arg(name).arg(version);
132 QMessageBox::about(stationView, name, aboutText);
135 void App::showStationSelectView(void)
137 stationListView->show();
140 void App::readSettings(void)
143 queryBaseUrl = settings.value("QueryURL",
144 "http://mobile.viaggiatreno.it/viaggiatreno/mobile/stazione").toString();
145 stationView->setBaseUrl(queryBaseUrl);
147 stationName = settings.value("CurrentStation").toString();
148 showingArrivals = settings.value("ShowingArrivals", false).toBool();
149 checkingInterval = settings.value("CheckInterval", 2000).toInt();
152 void App::saveSettings(void)
155 settings.setValue("QueryURL", queryBaseUrl);
156 settings.value("CurrentStation", stationName);
157 settings.value("ShowingArrivals", showingArrivals);
158 settings.value("CheckInterval", checkingInterval);
161 void App::setShowingArrivals(bool showArrivals)
163 showingArrivals = showArrivals;
166 QString App::dataDir(void)
169 return QString("/opt/usr/share/apps/quandoparte/");
171 return QString("/usr/share/apps/quandoparte/");