abbe2bef00d177350dac6ad105a1f149c7e62217
[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 "statsmodel.h"
11 #include "status.h"
12 #include "settings.h"
13 #include "imageprovider.h"
14 #include "graph.h"
15
16 #include "harbour-pedalo.h"
17
18 int main(int argc, char *argv[])
19 {
20 // SailfishApp::main() will display "qml/harbour-pedalo.qml", if you need more
21 // control over initialization, you can use:
22 //
23 // - SailfishApp::application(int, char *[]) to get the QGuiApplication *
24 // - SailfishApp::createView() to get a new QQuickView * instance
25 // - SailfishApp::pathTo(QString) to get a QUrl to a resource file
26 // - SailfishApp::pathToMainQml() to get a QUrl to the main QML file
27 //
28 // To display the view, call "show()" (will show fullscreen on device).
29
30 QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
31 // These values are used by QSettings to access the config file in
32 // /home/nemo/.local/share/flypig/harbour-pedalo.conf
33 //QCoreApplication::setOrganizationName("flypig");
34 QCoreApplication::setOrganizationDomain("www.flypig.co.uk");
35 QCoreApplication::setApplicationName(APP_NAME);
36
37 Settings::instantiate();
38 qmlRegisterSingletonType<Settings>("harbour.pedalo.settings", 1, 0, "Settings", Settings::provider);
39 qmlRegisterType<JourneyModel>("harbour.pedalo.journeymodel", 1, 0, "JourneyModel");
40 qmlRegisterType<Graph>("harbour.pedalo.graph", 1, 0, "Graph");
41
42 JourneyModel journeys;
43 Status currentStatus(journeys);
44 Settings::getInstance().setMainStatus(currentStatus);
45 Settings::getInstance().loadSettings();
46
47 StatsModel statsmodel;
48 Stats stats;
49 QList<float> data{0.1, 0.1, 0.2};
50 QStringList labels{"A", "B", "C"};
51 stats.setValues(data);
52 stats.setLabels(labels);
53 statsmodel.addStats(stats);
54
55 data = QList<float>{0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.5};
56 labels = QStringList{"M", "T", "W", "Th", "F", "S", "Su"};
57 stats.setValues(data);
58 stats.setLabels(labels);
59 statsmodel.addStats(stats);
60
61
62 QFile file;
63 file.setFileName(Settings::getConfigDir() + "/journeys.csv");
64 journeys.importFromFile(file);
65 journeys.sort(JourneyModel::StartRole, Qt::DescendingOrder);
66
67 QScopedPointer<QQuickView> view(SailfishApp::createView());
68 view->engine()->addImageProvider(QLatin1String("pedalo"), new ImageProvider(Settings::getInstance()));
69 view->setSource(SailfishApp::pathTo("qml/harbour-pedalo.qml"));
70
71 QQmlContext *ctxt = view->rootContext();
72 ctxt->setContextProperty("version", VERSION);
73 qDebug() << "harbour-pedalo VERSION string: " << VERSION;
74 qDebug() << "VERSION_MAJOR: " << VERSION_MAJOR;
75 qDebug() << "VERSION_MINOR: " << VERSION_MINOR;
76 qDebug() << "VERSION_BUILD: " << VERSION_BUILD;
77
78 ctxt->setContextProperty("journeymodel", &journeys);
79 ctxt->setContextProperty("currentStatus", &currentStatus);
80 ctxt->setContextProperty("statsmodel", &statsmodel);
81
82 view->show();
83 int result = app->exec();
84
85 // Write out the journey data
86 QDir dir;
87 dir.mkpath(Settings::getConfigDir());
88 file.setFileName(Settings::getConfigDir() + "/journeys.csv");
89 qDebug() << "File saved as: " << file.fileName();
90 journeys.exportToFile(file);
91
92 Settings::getInstance().saveSettings();
93
94 return result;
95 }