e8f123dd1728db6debfe7ed8eef1ba2df6f72588
[harbour-pedalo.git] / src / harbour-pedalo.cpp
1 #include <QtQuick>
2 #ifdef QT_QML_DEBUG
3 #include <QDebug>
4 #endif
5
6 #include <sailfishapp.h>
7
8 #include "journey.h"
9 #include "journeymodel.h"
10 #include "status.h"
11 #include "settings.h"
12 #include "imageprovider.h"
13
14 #include "harbour-pedalo.h"
15
16 int main(int argc, char *argv[])
17 {
18 // SailfishApp::main() will display "qml/harbour-pedalo.qml", if you need more
19 // control over initialization, you can use:
20 //
21 // - SailfishApp::application(int, char *[]) to get the QGuiApplication *
22 // - SailfishApp::createView() to get a new QQuickView * instance
23 // - SailfishApp::pathTo(QString) to get a QUrl to a resource file
24 // - SailfishApp::pathToMainQml() to get a QUrl to the main QML file
25 //
26 // To display the view, call "show()" (will show fullscreen on device).
27
28 QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
29 // These values are used by QSettings to access the config file in
30 // /home/nemo/.local/share/flypig/harbour-pedalo.conf
31 //QCoreApplication::setOrganizationName("flypig");
32 QCoreApplication::setOrganizationDomain("www.flypig.co.uk");
33 QCoreApplication::setApplicationName(APP_NAME);
34
35 Settings::instantiate();
36 qmlRegisterSingletonType<Settings>("harbour.pedalo.settings", 1, 0, "Settings", Settings::provider);
37
38 JourneyModel journeys;
39 Status currentStatus(journeys);
40 Settings::getInstance().setMainStatus(currentStatus);
41 Settings::getInstance().loadSettings();
42
43 QFile file;
44 file.setFileName(Settings::getConfigDir() + "/journeys.csv");
45 journeys.importFromFile(file);
46 journeys.sort(JourneyModel::StartRole, Qt::DescendingOrder);
47
48 QScopedPointer<QQuickView> view(SailfishApp::createView());
49 view->engine()->addImageProvider(QLatin1String("pedalo"), new ImageProvider(Settings::getInstance()));
50 view->setSource(SailfishApp::pathTo("qml/harbour-pedalo.qml"));
51
52 QQmlContext *ctxt = view->rootContext();
53 ctxt->setContextProperty("version", VERSION);
54 qDebug() << "harbour-pedalo VERSION string: " << VERSION;
55 qDebug() << "VERSION_MAJOR: " << VERSION_MAJOR;
56 qDebug() << "VERSION_MINOR: " << VERSION_MINOR;
57 qDebug() << "VERSION_BUILD: " << VERSION_BUILD;
58
59 ctxt->setContextProperty("journeymodel", &journeys);
60 ctxt->setContextProperty("currentStatus", &currentStatus);
61
62 view->show();
63 int result = app->exec();
64
65 // Write out the journey data
66 QDir dir;
67 dir.mkpath(Settings::getConfigDir());
68 file.setFileName(Settings::getConfigDir() + "/journeys.csv");
69 qDebug() << "File saved as: " << file.fileName();
70 journeys.exportToFile(file);
71
72 Settings::getInstance().saveSettings();
73
74 return result;
75 }