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 App::App(QObject *parent) :
39 accessManager(new QNetworkAccessManager(this)),
40 stationView(new StationView()),
41 stationListModel(new StationListModel(this)),
42 stationListView(new StationListView(stationListModel, stationView))
44 stationListModel->load("/opt/usr/share/apps/quandoparte/stations/stations.qpl");
46 connect(stationListView, SIGNAL(stationSelected(const QString &)),
47 SLOT(queryStation(const QString &)));
48 connect(stationListView, SIGNAL(aboutTriggered()),
49 SLOT(showAboutDialog()));
50 connect(stationView, SIGNAL(aboutTriggered()),
51 SLOT(showAboutDialog()));
52 connect(stationView, SIGNAL(stationListSelectTriggered()),
53 SLOT(showStationSelectView()));
55 connect(stationView, SIGNAL(showingArrivalsChanged(bool)),
56 SLOT(setShowingArrivals(bool)));
59 qDebug() << "found" << stationListModel->rowCount() << "stations";
61 stationView->showMaximized();
66 if (stationName.isEmpty()) {
68 stationListView->showMaximized();
70 stationListView->show();
81 void App::downloadFinished(void)
83 disconnect(stationQueryReply, SIGNAL(finished()),
84 this, SLOT(downloadFinished()));
85 stationView->updateView(stationQueryReply->readAll());
86 stationListView->hide();
87 stationQueryReply->deleteLater();
88 stationQueryReply = 0;
90 stationListView->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
94 void App::queryStation(const QString &station)
96 QNetworkRequest request;
97 request.setUrl(queryBaseUrl);
98 const QString queryString = "stazione=" + station;
99 const QByteArray query(queryString.toLocal8Bit());
100 stationQueryReply = accessManager->post(request, query);
101 connect(stationQueryReply, SIGNAL(finished()),
102 this, SLOT(downloadFinished()));
104 stationListView->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
108 void App::showSettingsDialog()
112 void App::showAboutDialog()
114 qDebug() << "About Dialog called";
115 QString name = QApplication::instance()->applicationName();
116 QString version = QApplication::instance()->applicationVersion();
117 QString aboutText = QString(
118 tr("<p>%1 version %2</p>"
119 "<p>Copyright (c) 2010</p>"
120 "<p>Luciano Montanaro (mikelima@cirulla.net)</p>"
121 "<p>Licensed under the GNU Public License v2 or above</p>")).arg(name).arg(version);
122 QMessageBox::about(stationView, name, aboutText);
125 void App::showStationSelectView(void)
127 stationListView->show();
130 void App::readSettings(void)
133 queryBaseUrl = settings.value("QueryURL",
134 "http://mobile.viaggiatreno.it/viaggiatreno/mobile/stazione").toString();
135 stationView->setBaseUrl(queryBaseUrl);
137 stationName = settings.value("CurrentStation").toString();
138 showingArrivals = settings.value("ShowingArrivals", false).toBool();
139 checkingInterval = settings.value("CheckInterval", 2000).toInt();
142 void App::saveSettings(void)
145 settings.setValue("QueryURL", queryBaseUrl);
146 settings.value("CurrentStation", stationName);
147 settings.value("ShowingArrivals", showingArrivals);
148 settings.value("CheckInterval", checkingInterval);
151 void App::setShowingArrivals(bool showArrivals)
153 showingArrivals = showArrivals;