f19a8fcc0dd56df91b931f93cf487a1af889fa72
6 #include <sailfishapp.h>
9 #include "journeymodel.h"
10 #include "statsmodel.h"
13 #include "imageprovider.h"
15 #include "statsweekdayave.h"
16 #include "statshourjourneys.h"
17 #include "statsweekdaycongestion.h"
18 #include "statshourcongestion.h"
20 #include "harbour-pedalo.h"
22 int main(int argc
, char *argv
[])
24 // SailfishApp::main() will display "qml/harbour-pedalo.qml", if you need more
25 // control over initialization, you can use:
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
32 // To display the view, call "show()" (will show fullscreen on device).
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
);
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");
46 JourneyModel journeys
;
47 Status
currentStatus(journeys
);
48 Settings::getInstance().setMainStatus(currentStatus
);
49 Settings::getInstance().loadSettings();
51 StatsModel statsmodel
;
53 StatsWeekdayAve
statsweekdayave(&journeys
);
54 statsmodel
.addStats(statsweekdayave
);
56 StatsHourJourneys
statshourjourneys(&journeys
);
57 statsmodel
.addStats(statshourjourneys
);
59 StatsWeekdayCongestion
statsweekdaycongestion(&journeys
);
60 statsmodel
.addStats(statsweekdaycongestion
);
62 StatsHourCongestion
statshourcongestion(&journeys
);
63 statsmodel
.addStats(statshourcongestion
);
66 file
.setFileName(Settings::getConfigDir() + "/journeys.csv");
67 journeys
.importFromFile(file
);
68 journeys
.sort(JourneyModel::StartRole
, Qt::DescendingOrder
);
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"));
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
;
81 ctxt
->setContextProperty("journeymodel", &journeys
);
82 ctxt
->setContextProperty("currentStatus", ¤tStatus
);
83 ctxt
->setContextProperty("statsmodel", &statsmodel
);
86 int result
= app
->exec();
88 // Write out the journey data
90 dir
.mkpath(Settings::getConfigDir());
91 file
.setFileName(Settings::getConfigDir() + "/journeys.csv");
92 qDebug() << "File saved as: " << file
.fileName();
93 journeys
.exportToFile(file
);
95 Settings::getInstance().saveSettings();