Make LenaPi usable on Android devices

- 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
This commit is contained in:
Jan-Martin Raemer 2022-07-16 12:19:57 +02:00
parent 851b83a53a
commit 1f12d93300
19 changed files with 499 additions and 48 deletions

View file

@ -4,18 +4,20 @@
#include <QCommandLineParser>
#include <QFileInfo>
#include <QDebug>
#include <controllers/StyleController.h>
#include "controllers/NavigationController.h"
#include <controllers/StyleHandling.h>
#include <controllers/NavigationController.h>
#include <controllers/SettingsHandler.h>
#include "MouseEventSpy.h"
#include "EnergySaver.h"
#include "controllers/SettingsHandler.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
@ -25,6 +27,12 @@ int main(int argc, char *argv[])
// 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.
@ -35,23 +43,35 @@ int main(int argc, char *argv[])
}
}
if(!settings){
// default config
// create config from default location
settings = new QSettings(QSettings::Scope::UserScope, "MaleyanaSoft", "LenaPi");
}
/* Read Settings */
// Read Settings
const auto settingsHandler = SettingsHandler::createSettingsHandlerAndFillWithDefaultsIfMissing(settings);
// init style
StyleController styleController;
styleController.init(engine.rootContext());
// init main app
/****************************************************************************
* 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.
@ -60,9 +80,13 @@ int main(int argc, char *argv[])
EnergySaver::init(settingsHandler->getEnergySaverTimeout(), settingsHandler->getShutdownScript());
QObject::connect(MouseEventSpy::instance(), &MouseEventSpy::mouseEventDetected,
EnergySaver::instance(), &EnergySaver::restartTimer);
} else {
EnergySaver::init();
}
// load GUI
/****************************************************************************
* load view
****************************************************************************/
engine.load(QUrl("qrc:/main.qml"));
return app.exec();