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