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 "stationlistview.h"
25 #include "settingsdialog.h"
28 #include <QMessageBox>
29 #include <QNetworkAccessManager>
30 #include <QNetworkReply>
31 #include <QNetworkRequest>
36 App::App(QObject *parent) :
38 accessManager(new QNetworkAccessManager(this)),
39 stationView(new StationView(NULL)),
40 stationListView(new StationListView(stationView))
42 connect(stationListView, SIGNAL(stationSelected(const QString &)),
43 SLOT(queryStation(const QString &)));
44 connect(stationListView, SIGNAL(aboutTriggered()),
45 SLOT(showAboutDialog()));
46 connect(stationView, SIGNAL(aboutTriggered()),
47 SLOT(showAboutDialog()));
48 connect(stationView, SIGNAL(stationListSelectTriggered()),
49 SLOT(showStationSelectView()));
51 connect(stationView, SIGNAL(showingArrivalsChanged(bool)),
52 SLOT(setShowingArrivals(bool)));
56 stationView->showMaximized();
61 if (stationName.isEmpty()) {
63 stationListView->showMaximized();
65 stationListView->show();
75 void App::downloadFinished(void)
77 disconnect(stationQueryReply, SIGNAL(finished()),
78 this, SLOT(downloadFinished()));
79 stationView->updateView(stationQueryReply->readAll());
80 stationListView->hide();
81 stationQueryReply->deleteLater();
82 stationQueryReply = 0;
84 stationListView->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
88 void App::queryStation(const QString &station)
90 QNetworkRequest request;
91 request.setUrl(queryBaseUrl);
92 const QString queryString = "stazione=" + station;
93 const QByteArray query(queryString.toLocal8Bit());
94 stationQueryReply = accessManager->post(request, query);
95 connect(stationQueryReply, SIGNAL(finished()),
96 this, SLOT(downloadFinished()));
98 stationListView->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
102 void App::showSettingsDialog()
106 void App::showAboutDialog()
108 qDebug() << "About Dialog called";
109 QString name = QApplication::instance()->applicationName();
110 QString version = QApplication::instance()->applicationVersion();
111 QString aboutText = QString(
112 tr("<p>%1 version %2</p>"
113 "<p>Copyright (c) 2010</p>"
114 "<p>Luciano Montanaro (mikelima@cirulla.net)</p>"
115 "<p>Licensed under the GNU Public License v2 or above</p>")).arg(name).arg(version);
116 QMessageBox::about(stationView, name, aboutText);
119 void App::showStationSelectView(void)
121 stationListView->show();
124 void App::readSettings(void)
127 queryBaseUrl = settings.value("QueryURL",
128 "http://mobile.viaggiatreno.it/viaggiatreno/mobile/stazione").toString();
129 stationView->setBaseUrl(queryBaseUrl);
131 stationName = settings.value("CurrentStation").toString();
132 showingArrivals = settings.value("ShowingArrivals", false).toBool();
133 checkingInterval = settings.value("CheckInterval", 2000).toInt();
136 void App::saveSettings(void)
139 settings.setValue("QueryURL", queryBaseUrl);
140 settings.value("CurrentStation", stationName);
141 settings.value("ShowingArrivals", showingArrivals);
142 settings.value("CheckInterval", checkingInterval);
145 void App::setShowingArrivals(bool showArrivals)
147 showingArrivals = showArrivals;