70 lines
2.6 KiB
C++
70 lines
2.6 KiB
C++
#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[])
|
|
{
|
|
|
|
QGuiApplication app(argc, argv);
|
|
QQmlApplicationEngine engine;
|
|
|
|
/* 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();
|
|
|
|
// init main app
|
|
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
|
|
* 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"));
|
|
|
|
return app.exec();
|
|
}
|