List journeys in descending order of time
[harbour-pedalo.git] / src / harbour-pedalo.cpp
index acdcc2e..e8f123d 100644 (file)
@@ -1,5 +1,5 @@
-#ifdef QT_QML_DEBUG
 #include <QtQuick>
+#ifdef QT_QML_DEBUG
 #include <QDebug>
 #endif
 
@@ -7,6 +7,11 @@
 
 #include "journey.h"
 #include "journeymodel.h"
+#include "status.h"
+#include "settings.h"
+#include "imageprovider.h"
+
+#include "harbour-pedalo.h"
 
 int main(int argc, char *argv[])
 {
@@ -21,28 +26,50 @@ int main(int argc, char *argv[])
     // To display the view, call "show()" (will show fullscreen on device).
 
     QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
+    // These values are used by QSettings to access the config file in
+    // /home/nemo/.local/share/flypig/harbour-pedalo.conf
+    //QCoreApplication::setOrganizationName("flypig");
+    QCoreApplication::setOrganizationDomain("www.flypig.co.uk");
+    QCoreApplication::setApplicationName(APP_NAME);
+
+    Settings::instantiate();
+    qmlRegisterSingletonType<Settings>("harbour.pedalo.settings", 1, 0, "Settings", Settings::provider);
 
     JourneyModel journeys;
+    Status currentStatus(journeys);
+    Settings::getInstance().setMainStatus(currentStatus);
+    Settings::getInstance().loadSettings();
 
     QFile file;
-    file.setFileName(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/journeys.csv");
+    file.setFileName(Settings::getConfigDir() + "/journeys.csv");
     journeys.importFromFile(file);
+    journeys.sort(JourneyModel::StartRole, Qt::DescendingOrder);
 
     QScopedPointer<QQuickView> view(SailfishApp::createView());
+    view->engine()->addImageProvider(QLatin1String("pedalo"), new ImageProvider(Settings::getInstance()));
     view->setSource(SailfishApp::pathTo("qml/harbour-pedalo.qml"));
 
     QQmlContext *ctxt = view->rootContext();
+    ctxt->setContextProperty("version", VERSION);
+    qDebug() << "harbour-pedalo VERSION string: " << VERSION;
+    qDebug() << "VERSION_MAJOR: " << VERSION_MAJOR;
+    qDebug() << "VERSION_MINOR: " << VERSION_MINOR;
+    qDebug() << "VERSION_BUILD: " << VERSION_BUILD;
+
     ctxt->setContextProperty("journeymodel", &journeys);
+    ctxt->setContextProperty("currentStatus", &currentStatus);
 
     view->show();
     int result = app->exec();
 
     // Write out the journey data
     QDir dir;
-    dir.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
-    file.setFileName(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/journeys.csv");
+    dir.mkpath(Settings::getConfigDir());
+    file.setFileName(Settings::getConfigDir() + "/journeys.csv");
     qDebug() << "File saved as: " << file.fileName();
     journeys.exportToFile(file);
 
+    Settings::getInstance().saveSettings();
+
     return result;
 }