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(stationView, SIGNAL(aboutTriggered()),
45 SLOT(showAboutDialog()));
46 connect(stationView, SIGNAL(stationListSelectTriggered()),
47 SLOT(showStationSelectView()));
49 connect(stationView, SIGNAL(showingArrivalsChanged(bool)),
50 SLOT(setShowingArrivals(bool)));
54 stationView->showMaximized();
59 if (stationName.isEmpty()) {
61 stationListView->showMaximized();
63 stationListView->show();
73 void App::downloadFinished(void)
75 disconnect(stationQueryReply, SIGNAL(finished()),
76 this, SLOT(downloadFinished()));
77 stationView->updateView(stationQueryReply->readAll());
78 stationListView->hide();
79 stationQueryReply->deleteLater();
80 stationQueryReply = 0;
83 void App::queryStation(const QString &station)
85 QNetworkRequest request;
86 request.setUrl(queryBaseUrl);
87 const QString queryString = "stazione=" + station;
88 const QByteArray query(queryString.toLocal8Bit());
89 stationQueryReply = accessManager->post(request, query);
90 connect(stationQueryReply, SIGNAL(finished()),
91 this, SLOT(downloadFinished()));
94 void App::showSettingsDialog()
98 void App::showAboutDialog()
100 qDebug() << "About Dialog called";
101 QString name = QApplication::instance()->applicationName();
102 QString aboutText = QString(
104 "<p>Copyright (c) 2010</p>"
105 "<p>Luciano Montanaro (mikelima@cirulla.net)</p>"
106 "<p>Licensed under the GNU Public License v2 or above</p>")).arg(name);
107 QMessageBox::about(stationView, name, aboutText);
110 void App::showStationSelectView(void)
112 stationListView->show();
115 void App::readSettings(void)
118 queryBaseUrl = settings.value("QueryURL",
119 "http://mobile.viaggiatreno.it/viaggiatreno/mobile/stazione").toString();
120 stationView->setBaseUrl(queryBaseUrl);
122 stationName = settings.value("CurrentStation").toString();
123 showingArrivals = settings.value("ShowingArrivals", false).toBool();
124 checkingInterval = settings.value("CheckInterval", 2000).toInt();
127 void App::saveSettings(void)
130 settings.setValue("QueryURL", queryBaseUrl);
131 settings.value("CurrentStation", stationName);
132 settings.value("ShowingArrivals", showingArrivals);
133 settings.value("CheckInterval", checkingInterval);
136 void App::setShowingArrivals(bool showArrivals)
138 showingArrivals = showArrivals;