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 connect(stationListView, SIGNAL(stationSelected(const QString &)),
45 SLOT(queryStation(const QString &)));
46 connect(stationListView, SIGNAL(aboutTriggered()),
47 SLOT(showAboutDialog()));
48 connect(stationView, SIGNAL(aboutTriggered()),
49 SLOT(showAboutDialog()));
50 connect(stationView, SIGNAL(stationListSelectTriggered()),
51 SLOT(showStationSelectView()));
53 connect(stationView, SIGNAL(showingArrivalsChanged(bool)),
54 SLOT(setShowingArrivals(bool)));
58 stationView->showMaximized();
63 if (stationName.isEmpty()) {
65 stationListView->showMaximized();
67 stationListView->show();
78 void App::downloadFinished(void)
80 disconnect(stationQueryReply, SIGNAL(finished()),
81 this, SLOT(downloadFinished()));
82 stationView->updateView(stationQueryReply->readAll());
83 stationListView->hide();
84 stationQueryReply->deleteLater();
85 stationQueryReply = 0;
87 stationListView->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
91 void App::queryStation(const QString &station)
93 QNetworkRequest request;
94 request.setUrl(queryBaseUrl);
95 const QString queryString = "stazione=" + station;
96 const QByteArray query(queryString.toLocal8Bit());
97 stationQueryReply = accessManager->post(request, query);
98 connect(stationQueryReply, SIGNAL(finished()),
99 this, SLOT(downloadFinished()));
101 stationListView->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
105 void App::showSettingsDialog()
109 void App::showAboutDialog()
111 qDebug() << "About Dialog called";
112 QString name = QApplication::instance()->applicationName();
113 QString version = QApplication::instance()->applicationVersion();
114 QString aboutText = QString(
115 tr("<p>%1 version %2</p>"
116 "<p>Copyright (c) 2010</p>"
117 "<p>Luciano Montanaro (mikelima@cirulla.net)</p>"
118 "<p>Licensed under the GNU Public License v2 or above</p>")).arg(name).arg(version);
119 QMessageBox::about(stationView, name, aboutText);
122 void App::showStationSelectView(void)
124 stationListView->show();
127 void App::readSettings(void)
130 queryBaseUrl = settings.value("QueryURL",
131 "http://mobile.viaggiatreno.it/viaggiatreno/mobile/stazione").toString();
132 stationView->setBaseUrl(queryBaseUrl);
134 stationName = settings.value("CurrentStation").toString();
135 showingArrivals = settings.value("ShowingArrivals", false).toBool();
136 checkingInterval = settings.value("CheckInterval", 2000).toInt();
139 void App::saveSettings(void)
142 settings.setValue("QueryURL", queryBaseUrl);
143 settings.value("CurrentStation", stationName);
144 settings.value("ShowingArrivals", showingArrivals);
145 settings.value("CheckInterval", checkingInterval);
148 void App::setShowingArrivals(bool showArrivals)
150 showingArrivals = showArrivals;