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"
19 #include "statsyearjourneys.h"
20 #include "statsyearduration.h"
22 #include "harbour-pedalo.h"
24 int main(int argc
, char *argv
[])
26 // SailfishApp::main() will display "qml/harbour-pedalo.qml", if you need more
27 // control over initialization, you can use:
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
34 // To display the view, call "show()" (will show fullscreen on device).
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
);
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");
48 JourneyModel journeys
;
49 Status
currentStatus(journeys
);
50 Settings::getInstance().setMainStatus(currentStatus
);
51 Settings::getInstance().loadSettings();
53 StatsModel statsmodel
;
55 StatsYearDuration
statsyearduration(&journeys
);
56 statsmodel
.addStats(statsyearduration
);
58 StatsYearJourneys
statsyearjourneys(&journeys
);
59 statsmodel
.addStats(statsyearjourneys
);
61 StatsWeekdayAve
statsweekdayave(&journeys
);
62 statsmodel
.addStats(statsweekdayave
);
64 StatsHourJourneys
statshourjourneys(&journeys
);
65 statsmodel
.addStats(statshourjourneys
);
67 StatsWeekdayCongestion
statsweekdaycongestion(&journeys
);
68 statsmodel
.addStats(statsweekdaycongestion
);
70 StatsHourCongestion
statshourcongestion(&journeys
);
71 statsmodel
.addStats(statshourcongestion
);
74 file
.setFileName(Settings::getConfigDir() + "/journeys.csv");
75 journeys
.importFromFile(file
);
76 journeys
.sort(JourneyModel::StartRole
, Qt::DescendingOrder
);
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"));
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
;
89 ctxt
->setContextProperty("journeymodel", &journeys
);
90 ctxt
->setContextProperty("currentStatus", ¤tStatus
);
91 ctxt
->setContextProperty("statsmodel", &statsmodel
);
94 int result
= app
->exec();
96 // Write out the journey data
98 dir
.mkpath(Settings::getConfigDir());
99 file
.setFileName(Settings::getConfigDir() + "/journeys.csv");
100 qDebug() << "File saved as: " << file
.fileName();
101 journeys
.exportToFile(file
);
103 Settings::getInstance().saveSettings();