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