Added periodic check feature.
authorLuciano Montanaro <mikelima@cirulla.net>
Sun, 26 Jun 2011 15:48:23 +0000 (17:48 +0200)
committerLuciano Montanaro <mikelima@cirulla.net>
Sun, 26 Jun 2011 15:48:23 +0000 (17:48 +0200)
application/app.cpp
application/app.h
application/resources/i18n/quandoparte_it.qm
application/resources/i18n/quandoparte_it.ts
application/settingsdialog.cpp
application/settingsdialog.h
application/settingsdialog.ui

index eea9dcd..2af0366 100644 (file)
@@ -32,6 +32,7 @@ Boston, MA 02110-1301, USA.
 #include <QNetworkRequest>
 #include <QObject>
 #include <QSettings>
+#include <QTimer>
 #include <QUrl>
 
 #include <QGeoPositionInfoSource>
@@ -44,6 +45,7 @@ QTM_USE_NAMESPACE
 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))
@@ -69,6 +71,8 @@ App::App(QObject *parent) :
     readSettings();
 
     qDebug() << "found" << stationListModel->rowCount() << "stations";
+
+    connect(checkingTimer, SIGNAL(timeout()), SLOT(updateStation()));
     stationView->show();
     if (recentStations.isEmpty() || !stationViewPreferred) {
         stationListView->show();
@@ -79,7 +83,9 @@ App::App(QObject *parent) :
 
 App::~App()
 {
+    disconnect();
     delete stationView;
+    delete stationListView;
     saveSettings();
 }
 
@@ -115,6 +121,14 @@ void App::queryStation(const QString &station)
 #endif
 }
 
+void App::updateStation()
+{
+    qDebug() << "updating station data";
+    if (!recentStations.isEmpty() && !stationListView->isVisible()) {
+        queryStation(recentStations.front());
+    }
+}
+
 void App::showSettingsDialog()
 {
     qDebug() << "Settings Dialog called";
@@ -152,8 +166,27 @@ void App::readSettings(void)
     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)
index 65f0889..35899a2 100644 (file)
@@ -27,6 +27,7 @@ Boston, MA 02110-1301, USA.
 
 class QNetworkAccessManager;
 class QNetworkReply;
+class QTimer;
 
 class StationView;
 class StationListView;
@@ -45,6 +46,7 @@ signals:
 
 public slots:
     void queryStation(const QString &station);
+    void updateStation();
     void downloadFinished(void);
     void showAboutDialog(void);
     void showSettingsDialog(void);
@@ -55,11 +57,11 @@ public:
 private:
     QNetworkAccessManager *accessManager;
     QNetworkReply *stationQueryReply;
+    QTimer *checkingTimer;
     StationView *stationView;
     StationListModel *stationListModel;
     StationListView *stationListView;
     QString queryBaseUrl;
-    QString stationName;
     QStringList recentStations;
     int checkingInterval;
     bool stationViewPreferred;
index 71f9d7e..2852b6c 100644 (file)
Binary files a/application/resources/i18n/quandoparte_it.qm and b/application/resources/i18n/quandoparte_it.qm differ
index 3a9fc22..b1f1ec4 100644 (file)
         <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&apos;ultima stazione all&apos;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>
index 0d9b8b5..f427be2 100644 (file)
@@ -43,6 +43,11 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
     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);
@@ -60,3 +65,9 @@ void SettingsDialog::showStationChanged(bool newValue)
     QSettings settings;
     settings.setValue("StationViewPreferred", newValue);
 }
+
+void SettingsDialog::periodicUpdateToggled(bool checked)
+{
+    QSettings settings;
+    settings.setValue("CheckInterval", checked ? 120000 : 0);
+}
index bfde246..cfee599 100644 (file)
@@ -22,6 +22,8 @@ public:
 private slots:
     void showStationChanged(bool);
 
+    void periodicUpdateToggled(bool checked);
+
 private:
 #ifdef Q_WS_MAEMO_5
     QMaemo5ValueButton *updateIntervalButton;
index 2c7f1db..1ecaed8 100644 (file)
@@ -6,39 +6,55 @@
    <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>