added config
This commit is contained in:
parent
893a2990af
commit
f02f439790
7 changed files with 168 additions and 17 deletions
|
|
@ -1,34 +1,56 @@
|
|||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QSettings>
|
||||
#include <QCommandLineParser>
|
||||
#include <QFileInfo>
|
||||
#include <QDebug>
|
||||
#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
|
||||
*/
|
||||
|
||||
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
|
||||
/* Add command line parser to specify a custom config file
|
||||
* https://doc.qt.io/qt-5/qcommandlineparser.html
|
||||
*/
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription("Lena's music app");
|
||||
// Define a custom config file using -c or --config
|
||||
QCommandLineOption configOption(QStringList() << "c" << "config", "Optional: Define custom config file");
|
||||
parser.addOption(configOption);
|
||||
|
||||
// process commandline arguments
|
||||
parser.process(app);
|
||||
|
||||
QSettings* settings = nullptr;
|
||||
if(!parser.value(configOption).isEmpty()){
|
||||
// config was handed over via commandline argument. Use this config if file exists.
|
||||
QString configFilePath = parser.value(configOption);
|
||||
QFileInfo configInfo(configFilePath);
|
||||
if(configInfo.exists()){
|
||||
settings = new QSettings(configFilePath, QSettings::Format::NativeFormat);
|
||||
}
|
||||
}
|
||||
if(!settings){
|
||||
// default config
|
||||
settings = new QSettings(QSettings::Scope::UserScope, "MaleyanaSoft", "LenaPi");
|
||||
}
|
||||
/* Read Settings */
|
||||
|
||||
const auto rootPath = settings->value("rootPath", "/home/ar/source/lenaMusic/").toString(); // path to music files
|
||||
const auto profile = settings->value("profile", "RasPiTouch").toString(); // known profiles 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();
|
||||
|
||||
NavigationController navController;
|
||||
navController.setContext(engine.rootContext());
|
||||
navController.init(rootPath);
|
||||
navController.setUiProfile(profile);
|
||||
|
||||
if(isEnergySavingEnabled){
|
||||
/* install MouseEventSpy and energy saver used for auto shut down of device
|
||||
|
|
@ -43,6 +65,5 @@ int main(int argc, char *argv[])
|
|||
// load GUI
|
||||
engine.load(QUrl("qrc:/main.qml"));
|
||||
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue