#include <QNetworkRequest>
#include <QObject>
#include <QSettings>
+#include <QTimer>
#include <QUrl>
#include <QGeoPositionInfoSource>
App::App(QObject *parent) :
QObject(parent),
accessManager(new QNetworkAccessManager(this)),
+ checkingTimer(new QTimer(this)),
stationView(new StationView()),
stationListModel(new StationListModel(this)),
stationListView(new StationListView(stationListModel, stationView))
readSettings();
qDebug() << "found" << stationListModel->rowCount() << "stations";
+
+ connect(checkingTimer, SIGNAL(timeout()), SLOT(updateStation()));
stationView->show();
if (recentStations.isEmpty() || !stationViewPreferred) {
stationListView->show();
App::~App()
{
+ disconnect();
delete stationView;
+ delete stationListView;
saveSettings();
}
#endif
}
+void App::updateStation()
+{
+ qDebug() << "updating station data";
+ if (!recentStations.isEmpty() && !stationListView->isVisible()) {
+ queryStation(recentStations.front());
+ }
+}
+
void App::showSettingsDialog()
{
qDebug() << "Settings Dialog called";
stationView->setBaseUrl(queryBaseUrl);
recentStations = settings.value("RecentStations").toString().split(",");
- checkingInterval = settings.value("CheckInterval", 2000).toInt();
+ qDebug() << "RecentStations:" << recentStations;
+
stationViewPreferred = settings.value("StationViewPreferred", false).toBool();
+ qDebug() << "StationsViewPreferred:" << stationViewPreferred;
+
+ checkingInterval = settings.value("CheckInterval", 0).toInt();
+ qDebug() << "CheckInterval:" << checkingInterval;
+
+ /*
+ I would use > 0 here, but people may have an old settings file with a 2
+ seconds timeout which is way too short.
+ As a workaround I consider anything less than 30 seconds as too short
+ and disable the timer.
+ */
+ if (checkingInterval > 30000) {
+ checkingTimer->setInterval(checkingInterval);
+ checkingTimer->start();
+ } else {
+ checkingTimer->setInterval(-1);
+ checkingTimer->stop();
+ }
}
void App::saveSettings(void)
class QNetworkAccessManager;
class QNetworkReply;
+class QTimer;
class StationView;
class StationListView;
public slots:
void queryStation(const QString &station);
+ void updateStation();
void downloadFinished(void);
void showAboutDialog(void);
void showSettingsDialog(void);
private:
QNetworkAccessManager *accessManager;
QNetworkReply *stationQueryReply;
+ QTimer *checkingTimer;
StationView *stationView;
StationListModel *stationListModel;
StationListView *stationListView;
QString queryBaseUrl;
- QString stationName;
QStringList recentStations;
int checkingInterval;
bool stationViewPreferred;
<translation></translation>
</message>
<message>
- <location filename="../../settingsdialog.ui" line="25"/>
+ <location filename="../../settingsdialog.ui" line="45"/>
<source>Show Last Station on Startup</source>
<translation>Mostra l'ultima stazione all'avvio</translation>
</message>
<message>
+ <location filename="../../settingsdialog.ui" line="52"/>
+ <source>Update Display Periodically</source>
+ <translation>Aggiorna stazione periodicamente</translation>
+ </message>
+ <message>
<source>Station:</source>
<translation type="obsolete">Stazione:</translation>
</message>
<translation>Elenco delle stazioni</translation>
</message>
<message>
- <location filename="../../stationlistview.ui" line="37"/>
+ <location filename="../../stationlistview.ui" line="65"/>
<source>View</source>
<translation>Vista</translation>
</message>
<message>
- <location filename="../../stationlistview.ui" line="53"/>
+ <location filename="../../stationlistview.ui" line="81"/>
<source>Near</source>
<translation>Vicine</translation>
</message>
<message>
- <location filename="../../stationlistview.ui" line="56"/>
+ <location filename="../../stationlistview.ui" line="84"/>
<source>Show near stations first</source>
<translation>Mostra per prime le stazioni vicine</translation>
</message>
<message>
- <location filename="../../stationlistview.ui" line="64"/>
+ <location filename="../../stationlistview.ui" line="92"/>
<source>ABC</source>
<translation>ABC</translation>
</message>
<message>
- <location filename="../../stationlistview.ui" line="67"/>
+ <location filename="../../stationlistview.ui" line="95"/>
<source>Sort stations by name</source>
<translation>Ordina le stazioni per nome</translation>
</message>
<message>
- <location filename="../../stationlistview.ui" line="72"/>
+ <location filename="../../stationlistview.ui" line="100"/>
<source>Settings</source>
<translation>Impostazioni</translation>
</message>
<message>
- <location filename="../../stationlistview.ui" line="77"/>
+ <location filename="../../stationlistview.ui" line="105"/>
<source>About</source>
<translation>Informazioni</translation>
</message>
<message>
- <location filename="../../stationlistview.ui" line="85"/>
+ <location filename="../../stationlistview.ui" line="113"/>
<source>Recent</source>
<translation>Recenti</translation>
</message>
<message>
- <location filename="../../stationlistview.ui" line="88"/>
+ <location filename="../../stationlistview.ui" line="116"/>
<source>Show recently checked stations first</source>
<translation>Mostra per prime le stazioni recenti</translation>
</message>
<context>
<name>StationView</name>
<message>
- <location filename="../../stationview.cpp" line="37"/>
+ <location filename="../../stationview.cpp" line="39"/>
<source>Arrivals</source>
<translation>Arrivi</translation>
</message>
<message>
- <location filename="../../stationview.cpp" line="38"/>
+ <location filename="../../stationview.cpp" line="40"/>
<source>Departures</source>
<translation>Partenze</translation>
</message>
<message>
- <location filename="../../stationview.cpp" line="39"/>
+ <location filename="../../stationview.cpp" line="41"/>
<source>Settings</source>
<translation>Impostazioni</translation>
</message>
<message>
- <location filename="../../stationview.cpp" line="40"/>
+ <location filename="../../stationview.cpp" line="42"/>
<source>Change Station</source>
<translation>Cambia stazione</translation>
</message>
<message>
- <location filename="../../stationview.cpp" line="41"/>
+ <location filename="../../stationview.cpp" line="43"/>
<source>About</source>
<translation>Informazioni</translation>
</message>
ui->showLastStationCheckBox->setChecked(showStationPreference);
connect(ui->showLastStationCheckBox, SIGNAL(toggled(bool)),
SLOT(showStationChanged(bool)));
+
+ bool checkingInterval = settings.value("CheckInterval", 0).toInt();
+ ui->periodicUpdateCheckBox->setChecked(checkingInterval > 30000);
+ connect(ui->periodicUpdateCheckBox, SIGNAL(toggled(bool)),
+ SLOT(periodicUpdateToggled(bool)));
#if 0
#ifdef Q_WS_MAEMO_5
ui->formLayout->addWidget(updateIntervalButton);
QSettings settings;
settings.setValue("StationViewPreferred", newValue);
}
+
+void SettingsDialog::periodicUpdateToggled(bool checked)
+{
+ QSettings settings;
+ settings.setValue("CheckInterval", checked ? 120000 : 0);
+}
private slots:
void showStationChanged(bool);
+ void periodicUpdateToggled(bool checked);
+
private:
#ifdef Q_WS_MAEMO_5
QMaemo5ValueButton *updateIntervalButton;
<rect>
<x>0</x>
<y>0</y>
- <width>611</width>
- <height>108</height>
+ <width>609</width>
+ <height>106</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
- <layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0">
- <layout class="QFormLayout" name="formLayout">
- <property name="fieldGrowthPolicy">
- <enum>QFormLayout::ExpandingFieldsGrow</enum>
- </property>
- <item row="0" column="0">
- <widget class="QCheckBox" name="showLastStationCheckBox">
- <property name="text">
- <string>Show Last Station on Startup</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item row="0" column="1">
- <widget class="QDialogButtonBox" name="buttonBox">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="standardButtons">
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
- </property>
- </widget>
- </item>
- </layout>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="geometry">
+ <rect>
+ <x>461</x>
+ <y>6</y>
+ <width>142</width>
+ <height>94</height>
+ </rect>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ <widget class="QWidget" name="">
+ <property name="geometry">
+ <rect>
+ <x>8</x>
+ <y>8</y>
+ <width>445</width>
+ <height>86</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QCheckBox" name="showLastStationCheckBox">
+ <property name="text">
+ <string>Show Last Station on Startup</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="periodicUpdateCheckBox">
+ <property name="text">
+ <string>Update Display Periodically</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
</widget>
<resources/>
<connections>