Save/restore settings properly
authorLuciano Montanaro <mikelima@cirulla.net>
Sat, 11 Jun 2011 15:30:06 +0000 (17:30 +0200)
committerLuciano Montanaro <mikelima@cirulla.net>
Sat, 11 Jun 2011 15:30:06 +0000 (17:30 +0200)
The save restore settings code was not working, updated it.
Also added a recentStations list, and switched to using it as the source
of the last-visited station.

Quando Parte now starts up with the last visited station displaying, if
present.

application/app.cpp
application/app.h
application/application.pro
application/main.cpp

index 96a7e98..1ba9e61 100644 (file)
@@ -36,6 +36,9 @@ Boston, MA 02110-1301, USA.
 
 #include <QGeoPositionInfoSource>
 
+// Constants
+static const int RECENT_STATIONS_MAX_COUNT = 10;
+
 QTM_USE_NAMESPACE
 
 App::App(QObject *parent) :
@@ -70,12 +73,14 @@ App::App(QObject *parent) :
     stationView->show();
 #endif
 
-    if (stationName.isEmpty()) {
+    if (recentStations.isEmpty()) {
 #if defined(Q_WS_S60)
         stationListView->showMaximized();
 #else
         stationListView->show();
 #endif
+    } else {
+        queryStation(recentStations.front());
     }
 
     // Testing only: start updates rigt away.
@@ -110,6 +115,11 @@ void App::queryStation(const QString &station)
     stationQueryReply = accessManager->post(request, query);
     connect(stationQueryReply, SIGNAL(finished()),
             this, SLOT(downloadFinished()));
+    recentStations.push_front(station);
+    recentStations.removeDuplicates();
+    if (recentStations.count() > RECENT_STATIONS_MAX_COUNT) {
+        recentStations.pop_back();
+    }
 #ifdef Q_WS_MAEMO_5
     stationListView->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
 #endif
@@ -144,7 +154,7 @@ void App::readSettings(void)
                                   "http://mobile.viaggiatreno.it/viaggiatreno/mobile/stazione").toString();
     stationView->setBaseUrl(queryBaseUrl);
 
-    stationName = settings.value("CurrentStation").toString();
+    recentStations = settings.value("RecentStations").toString().split(",");
     showingArrivals = settings.value("ShowingArrivals", false).toBool();
     checkingInterval = settings.value("CheckInterval", 2000).toInt();
 }
@@ -152,10 +162,13 @@ void App::readSettings(void)
 void App::saveSettings(void)
 {
     QSettings settings;
+
+    qDebug() << "Saving Settings to" << settings.fileName();
+
     settings.setValue("QueryURL", queryBaseUrl);
-    settings.value("CurrentStation", stationName);
-    settings.value("ShowingArrivals", showingArrivals);
-    settings.value("CheckInterval", checkingInterval);
+    settings.setValue("RecentStations", recentStations.join(","));
+    settings.setValue("ShowingArrivals", showingArrivals);
+    settings.setValue("CheckInterval", checkingInterval);
 }
 
 void App::setShowingArrivals(bool showArrivals)
index 99d61eb..bdd9c67 100644 (file)
@@ -23,6 +23,7 @@ Boston, MA 02110-1301, USA.
 */
 
 #include <QApplication>
+#include <QStringList>
 
 #include <QGeoPositionInfoSource>
 
@@ -65,6 +66,7 @@ private:
     StationListView *stationListView;
     QString queryBaseUrl;
     QString stationName;
+    QStringList recentStations;
     bool showingArrivals;
     int checkingInterval;
 };
index 34d6f55..5c20293 100644 (file)
@@ -8,8 +8,7 @@ QT += webkit network maemo5
 
 TARGET = quandoparte
 TEMPLATE = app
-VERSION = 0.1.90
-
+VERSION = 0.2.2
 VERSION_STRING = '\\"$${VERSION}\\"'
 DEFINES += QP_VERSION=\"$${VERSION_STRING}\"
 
index ad84523..1a88b2e 100644 (file)
@@ -53,4 +53,6 @@ int main(int argc, char *argv[])
     App theApp;
 
     return a.exec();
+
+    theApp.saveSettings();
 }