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