Add journey model and list
[harbour-pedalo.git] / src / harbour-pedalo.cpp
1 #ifdef QT_QML_DEBUG
2 #include <QtQuick>
3 #include <QDebug>
4 #endif
5
6 #include <sailfishapp.h>
7
8 #include "journey.h"
9 #include "journeymodel.h"
10
11 int main(int argc, char *argv[])
12 {
13 // SailfishApp::main() will display "qml/harbour-pedalo.qml", if you need more
14 // control over initialization, you can use:
15 //
16 // - SailfishApp::application(int, char *[]) to get the QGuiApplication *
17 // - SailfishApp::createView() to get a new QQuickView * instance
18 // - SailfishApp::pathTo(QString) to get a QUrl to a resource file
19 // - SailfishApp::pathToMainQml() to get a QUrl to the main QML file
20 //
21 // To display the view, call "show()" (will show fullscreen on device).
22
23 QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
24
25 JourneyModel journeys;
26
27 QFile file;
28 file.setFileName(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/journeys.csv");
29 journeys.importFromFile(file);
30
31 QScopedPointer<QQuickView> view(SailfishApp::createView());
32 view->setSource(SailfishApp::pathTo("qml/harbour-pedalo.qml"));
33
34 QQmlContext *ctxt = view->rootContext();
35 ctxt->setContextProperty("journeymodel", &journeys);
36
37 view->show();
38 int result = app->exec();
39
40 // Write out the journey data
41 QDir dir;
42 dir.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
43 file.setFileName(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/journeys.csv");
44 qDebug() << "File saved as: " << file.fileName();
45 journeys.exportToFile(file);
46
47 return result;
48 }