Support multiple graphs
[harbour-pedalo.git] / src / harbour-pedalo.cpp
index 4cec530..abbe2be 100644 (file)
@@ -1,9 +1,20 @@
-#ifdef QT_QML_DEBUG
 #include <QtQuick>
+#ifdef QT_QML_DEBUG
+#include <QDebug>
 #endif
 
 #include <sailfishapp.h>
 
+#include "journey.h"
+#include "journeymodel.h"
+#include "statsmodel.h"
+#include "status.h"
+#include "settings.h"
+#include "imageprovider.h"
+#include "graph.h"
+
+#include "harbour-pedalo.h"
+
 int main(int argc, char *argv[])
 {
     // SailfishApp::main() will display "qml/harbour-pedalo.qml", if you need more
@@ -16,5 +27,69 @@ int main(int argc, char *argv[])
     //
     // To display the view, call "show()" (will show fullscreen on device).
 
-    return SailfishApp::main(argc, argv);
+    QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
+    // These values are used by QSettings to access the config file in
+    // /home/nemo/.local/share/flypig/harbour-pedalo.conf
+    //QCoreApplication::setOrganizationName("flypig");
+    QCoreApplication::setOrganizationDomain("www.flypig.co.uk");
+    QCoreApplication::setApplicationName(APP_NAME);
+
+    Settings::instantiate();
+    qmlRegisterSingletonType<Settings>("harbour.pedalo.settings", 1, 0, "Settings", Settings::provider);
+    qmlRegisterType<JourneyModel>("harbour.pedalo.journeymodel", 1, 0, "JourneyModel");
+    qmlRegisterType<Graph>("harbour.pedalo.graph", 1, 0, "Graph");
+
+    JourneyModel journeys;
+    Status currentStatus(journeys);
+    Settings::getInstance().setMainStatus(currentStatus);
+    Settings::getInstance().loadSettings();
+
+    StatsModel statsmodel;
+    Stats stats;
+    QList<float> data{0.1, 0.1, 0.2};
+    QStringList labels{"A", "B", "C"};
+    stats.setValues(data);
+    stats.setLabels(labels);
+    statsmodel.addStats(stats);
+
+    data = QList<float>{0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.5};
+    labels = QStringList{"M", "T", "W", "Th", "F", "S", "Su"};
+    stats.setValues(data);
+    stats.setLabels(labels);
+    statsmodel.addStats(stats);
+
+
+    QFile file;
+    file.setFileName(Settings::getConfigDir() + "/journeys.csv");
+    journeys.importFromFile(file);
+    journeys.sort(JourneyModel::StartRole, Qt::DescendingOrder);
+
+    QScopedPointer<QQuickView> view(SailfishApp::createView());
+    view->engine()->addImageProvider(QLatin1String("pedalo"), new ImageProvider(Settings::getInstance()));
+    view->setSource(SailfishApp::pathTo("qml/harbour-pedalo.qml"));
+
+    QQmlContext *ctxt = view->rootContext();
+    ctxt->setContextProperty("version", VERSION);
+    qDebug() << "harbour-pedalo VERSION string: " << VERSION;
+    qDebug() << "VERSION_MAJOR: " << VERSION_MAJOR;
+    qDebug() << "VERSION_MINOR: " << VERSION_MINOR;
+    qDebug() << "VERSION_BUILD: " << VERSION_BUILD;
+
+    ctxt->setContextProperty("journeymodel", &journeys);
+    ctxt->setContextProperty("currentStatus", &currentStatus);
+    ctxt->setContextProperty("statsmodel", &statsmodel);
+
+    view->show();
+    int result = app->exec();
+
+    // Write out the journey data
+    QDir dir;
+    dir.mkpath(Settings::getConfigDir());
+    file.setFileName(Settings::getConfigDir() + "/journeys.csv");
+    qDebug() << "File saved as: " << file.fileName();
+    journeys.exportToFile(file);
+
+    Settings::getInstance().saveSettings();
+
+    return result;
 }