add QSettings for config parsing

This commit is contained in:
Anika Raemer 2021-09-25 15:11:02 +02:00
parent f9af4c662a
commit 893a2990af
5 changed files with 71 additions and 31 deletions

View file

@ -1,39 +1,46 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QSettings>
#include "controllers/NavigationController.h"
#include "MouseEventSpy.h"
#include "EnergySaver.h"
int main(int argc, char *argv[])
{
/**
/*
* @todo Add command line parser to specify a custom config file
* https://doc.qt.io/qt-5/qcommandlineparser.html
* Add config handling https://doc.qt.io/qt-5/qsettings.html#QSettings-4
* - set root path
* ui mode -> pass to NavigationController and store in UiStateModel
* - set mode
* -- RasPi -> no volumeControl or exit Button
* -- Desktop -> volumeControl and exit Button
* -- in future probably also MobileApp
* Energy saving options -> hand over to energy saver on initialization
* - enable energy saving
* - set energy saver timeout
* - set shutdown script path
*/
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
/* Read Settings */
QSettings settings("me", "LenaPi");
const auto rootPath = settings.value("rootPath", "/home/ar/source/lenaMusic/").toString(); // path to music files
const auto profile = settings.value("profile", "RasPiTouch").toString(); // known modes are "RasPiTouch" and "Desktop"
const auto isEnergySavingEnabled = settings.value("enableEnergySaver", true).toBool(); // enable/disable energy saver
const auto energySaverTimeout = settings.value("timeout", 60).toInt(); //timeout in seconds
const auto shutdownScript = settings.value("shutdownScript", "/usr/local/sbin/do_shutdown.sh").toString();
/* @todo Hand over profile to UiStateModel via NavigationController
* Add properties to UiStateModel for showing volume controls and close button.
* Set those properties according to profile and use them to hide/show elements in qml
*/
NavigationController navController;
navController.setContext(engine.rootContext());
navController.init("/home/ar/source/lenaMusic/");
navController.init(rootPath);
// install MouseEventSpy and energy saver used for auto
// shut down of RaspberryPi if not used for a predefined time.
MouseEventSpy::init();
EnergySaver::init(10);
QObject::connect(MouseEventSpy::instance(), &MouseEventSpy::mouseEventDetected,
EnergySaver::instance(), &EnergySaver::restartTimer);
if(isEnergySavingEnabled){
/* install MouseEventSpy and energy saver used for auto shut down of device
* if not used for a predefined time.
*/
MouseEventSpy::init();
EnergySaver::init(energySaverTimeout, shutdownScript);
QObject::connect(MouseEventSpy::instance(), &MouseEventSpy::mouseEventDetected,
EnergySaver::instance(), &EnergySaver::restartTimer);
}
// load GUI
engine.load(QUrl("qrc:/main.qml"));