Add journey model and list
[harbour-pedalo.git] / src / harbour-pedalo.cpp
index 4cec530..acdcc2e 100644 (file)
@@ -1,9 +1,13 @@
 #ifdef QT_QML_DEBUG
 #include <QtQuick>
+#include <QDebug>
 #endif
 
 #include <sailfishapp.h>
 
+#include "journey.h"
+#include "journeymodel.h"
+
 int main(int argc, char *argv[])
 {
     // SailfishApp::main() will display "qml/harbour-pedalo.qml", if you need more
@@ -16,5 +20,29 @@ int main(int argc, char *argv[])
     //
     // To display the view, call "show()" (will show fullscreen on device).
 
-    return SailfishApp::main(argc, argv);
+    QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
+
+    JourneyModel journeys;
+
+    QFile file;
+    file.setFileName(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/journeys.csv");
+    journeys.importFromFile(file);
+
+    QScopedPointer<QQuickView> view(SailfishApp::createView());
+    view->setSource(SailfishApp::pathTo("qml/harbour-pedalo.qml"));
+
+    QQmlContext *ctxt = view->rootContext();
+    ctxt->setContextProperty("journeymodel", &journeys);
+
+    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");
+    qDebug() << "File saved as: " << file.fileName();
+    journeys.exportToFile(file);
+
+    return result;
 }