- Add app icon - prevend android device from shutting down cpu while playing music - fix scaling bug - fix energy saver for RasPi by reconnecting to music player - minor refactorings and renaming
93 lines
3.9 KiB
C++
93 lines
3.9 KiB
C++
#include <QGuiApplication>
|
|
#include <QQmlApplicationEngine>
|
|
#include <QSettings>
|
|
#include <QCommandLineParser>
|
|
#include <QFileInfo>
|
|
#include <QDebug>
|
|
#include <controllers/StyleHandling.h>
|
|
#include <controllers/NavigationController.h>
|
|
#include <controllers/SettingsHandler.h>
|
|
#include "MouseEventSpy.h"
|
|
#include "EnergySaver.h"
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
QGuiApplication app(argc, argv);
|
|
QQmlApplicationEngine engine;
|
|
|
|
/****************************************************************************
|
|
* Configure and parse commandline arguments
|
|
****************************************************************************/
|
|
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);
|
|
|
|
/****************************************************************************
|
|
* Find and read settings
|
|
* If a config file is handed over via commandline arguments, it is preferred.
|
|
* Otherwise, the config in the standard location is used. If none exists yet,
|
|
* a default config is created.
|
|
****************************************************************************/
|
|
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){
|
|
// create config from default location
|
|
settings = new QSettings(QSettings::Scope::UserScope, "MaleyanaSoft", "LenaPi");
|
|
}
|
|
|
|
// Read Settings
|
|
const auto settingsHandler = SettingsHandler::createSettingsHandlerAndFillWithDefaultsIfMissing(settings);
|
|
|
|
|
|
/****************************************************************************
|
|
* init style
|
|
* Sets default sizes for ui elements. The element size is scaled according
|
|
* to the device's display size.
|
|
****************************************************************************/
|
|
StyleHandling styleHandler;
|
|
styleHandler.init(engine.rootContext());
|
|
|
|
/****************************************************************************
|
|
* init main app
|
|
****************************************************************************/
|
|
NavigationController navController;
|
|
navController.setContext(engine.rootContext());
|
|
navController.init(settingsHandler->getRootPath());
|
|
navController.setUiProfile(settingsHandler->getProfile());
|
|
|
|
/****************************************************************************
|
|
* init energy saver
|
|
* Prevents sleep on android devices and shuts down other device if inactive
|
|
* (no music or mouse events) for a certain time intervall
|
|
****************************************************************************/
|
|
if(settingsHandler->isEnergySaverEnabled()){
|
|
/* install MouseEventSpy and energy saver used for auto shut down of device
|
|
* if not used for a predefined time.
|
|
*/
|
|
MouseEventSpy::init();
|
|
EnergySaver::init(settingsHandler->getEnergySaverTimeout(), settingsHandler->getShutdownScript());
|
|
QObject::connect(MouseEventSpy::instance(), &MouseEventSpy::mouseEventDetected,
|
|
EnergySaver::instance(), &EnergySaver::restartTimer);
|
|
} else {
|
|
EnergySaver::init();
|
|
}
|
|
|
|
/****************************************************************************
|
|
* load view
|
|
****************************************************************************/
|
|
engine.load(QUrl("qrc:/main.qml"));
|
|
|
|
return app.exec();
|
|
}
|