diff --git a/androidservice/controlviews/devicecontrolapplication.cpp b/androidservice/controlviews/devicecontrolapplication.cpp index 168abf8a..a1c0297d 100644 --- a/androidservice/controlviews/devicecontrolapplication.cpp +++ b/androidservice/controlviews/devicecontrolapplication.cpp @@ -45,7 +45,7 @@ DeviceControlApplication::DeviceControlApplication(int argc, char *argv[]) : QAp qmlRegisterType("Nymea", 1, 0, "NfcThingActionWriter"); qmlRegisterSingletonType("Nymea", 1, 0, "NfcHelper", NfcHelper::nfcHelperProvider); - StyleController *styleController = new StyleController(this); + StyleController *styleController = new StyleController("light", this); QQmlFileSelector *styleSelector = new QQmlFileSelector(m_qmlEngine); styleSelector->setExtraSelectors({styleController->currentStyle()}); diff --git a/nymea-app/main.cpp b/nymea-app/main.cpp index 4d325b56..d7df2877 100644 --- a/nymea-app/main.cpp +++ b/nymea-app/main.cpp @@ -91,12 +91,17 @@ int main(int argc, char *argv[]) QCommandLineParser parser; parser.addHelpOption(); - QCommandLineOption kioskOption = QCommandLineOption({"k", "kiosk"}, "Start the application in kiosk mode."); - parser.addOption(kioskOption); QCommandLineOption connectOption = QCommandLineOption({"c", "connect"}, "Connect to nymea:core without discovery.", "host"); parser.addOption(connectOption); +#ifndef BRANDING QCommandLineOption styleOption = QCommandLineOption({"s", "style"}, "Override the style. Style in settings will be disabled.", "style"); parser.addOption(styleOption); + QCommandLineOption defaultStyleOption = QCommandLineOption({"d", "default-style"}, "The default style to be used if there is no style explicitly selected by the user yet.", "style"); + defaultStyleOption.setDefaultValue("light"); + parser.addOption(defaultStyleOption); +#endif + QCommandLineOption kioskOption = QCommandLineOption({"k", "kiosk"}, "Start the application in kiosk mode."); + parser.addOption(kioskOption); parser.process(application); // Initialize app log controller as early as possible, but after setting app name etc @@ -122,11 +127,16 @@ int main(int argc, char *argv[]) QQmlApplicationEngine *engine = new QQmlApplicationEngine(); - StyleController styleController; +#if defined BRANDING + StyleController styleController(BRANDING); + styleController.lockToStyle(BRANDING); +#else + StyleController styleController(parser.value(defaultStyleOption)); if (parser.isSet(styleOption)) { qDebug() << "Setting style to" << parser.value(styleOption); - styleController.setCurrentStyle(parser.value(styleOption)); + styleController.lockToStyle(parser.value(styleOption)); } +#endif QQmlFileSelector *styleSelector = new QQmlFileSelector(engine); styleSelector->setExtraSelectors({styleController.currentStyle()}); @@ -151,11 +161,6 @@ int main(int argc, char *argv[]) qmlRegisterSingletonType("Nymea", 1, 0, "AppLogController", AppLogController::appLogControllerProvider); qmlRegisterSingletonType(QUrl("qrc:///ui/utils/NymeaUtils.qml"), "Nymea", 1, 0, "NymeaUtils" ); -#ifdef BRANDING - engine->rootContext()->setContextProperty("appBranding", BRANDING); -#else - engine->rootContext()->setContextProperty("appBranding", ""); -#endif engine->rootContext()->setContextProperty("appVersion", APP_VERSION); engine->rootContext()->setContextProperty("qtBuildVersion", QT_VERSION_STR); engine->rootContext()->setContextProperty("qtVersion", qVersion()); diff --git a/nymea-app/stylecontroller.cpp b/nymea-app/stylecontroller.cpp index 03ab3ff6..2427d0eb 100644 --- a/nymea-app/stylecontroller.cpp +++ b/nymea-app/stylecontroller.cpp @@ -36,22 +36,16 @@ #include "stylecontroller.h" -StyleController::StyleController(QObject *parent) : QObject(parent) +StyleController::StyleController(const QString &defaultStyle, QObject *parent) : QObject(parent), + m_defaultStyle(defaultStyle) { -#ifdef BRANDING - QQuickStyle::setStyle(QString(":/styles/%1").arg(BRANDING)); -#else QQuickStyle::setStyle(QString(":/styles/%1").arg(currentStyle())); -#endif } QString StyleController::currentStyle() const { -#ifdef BRANDING - return BRANDING; -#endif QSettings settings; - QString currentSetting = settings.value("style", "light").toString(); + QString currentSetting = settings.value("style", m_defaultStyle).toString(); // ensure style is available if (allStyles().contains(currentSetting)) { return currentSetting; @@ -61,6 +55,10 @@ QString StyleController::currentStyle() const void StyleController::setCurrentStyle(const QString ¤tStyle) { + if (m_locked) { + qDebug() << "Ignoring style change request. Style is locked to" << this->currentStyle(); + return; + } if (!allStyles().contains(currentStyle)) { qWarning().nospace() << "No style named: " << currentStyle << ". Available styles are: " << allStyles().join(", "); return; @@ -73,6 +71,12 @@ void StyleController::setCurrentStyle(const QString ¤tStyle) } } +void StyleController::lockToStyle(const QString &style) +{ + setCurrentStyle(style); + m_locked = true; +} + QStringList StyleController::allStyles() const { QDir dir(":/styles/"); @@ -80,6 +84,11 @@ QStringList StyleController::allStyles() const return dir.entryList(QDir::Dirs); } +bool StyleController::locked() const +{ + return m_locked; +} + void StyleController::setSystemFont(const QFont &font) { QApplication::setFont(font); diff --git a/nymea-app/stylecontroller.h b/nymea-app/stylecontroller.h index 70293ad3..d5eb8699 100644 --- a/nymea-app/stylecontroller.h +++ b/nymea-app/stylecontroller.h @@ -38,19 +38,26 @@ class StyleController : public QObject Q_OBJECT Q_PROPERTY(QString currentStyle READ currentStyle WRITE setCurrentStyle NOTIFY currentStyleChanged) Q_PROPERTY(QStringList allStyles READ allStyles CONSTANT) + Q_PROPERTY(bool locked READ locked CONSTANT) public: - explicit StyleController(QObject *parent = nullptr); + explicit StyleController(const QString &defaultStyle, QObject *parent = nullptr); QString currentStyle() const; void setCurrentStyle(const QString ¤tStyle); + void lockToStyle(const QString &style); QStringList allStyles() const; + bool locked() const; Q_INVOKABLE void setSystemFont(const QFont &font); signals: void currentStyleChanged(); + +private: + QString m_defaultStyle; + bool m_locked = false; }; #endif // STYLECONTROLLER_H diff --git a/nymea-app/ui/Nymea.qml b/nymea-app/ui/Nymea.qml index 9e55234d..2d500aad 100644 --- a/nymea-app/ui/Nymea.qml +++ b/nymea-app/ui/Nymea.qml @@ -85,7 +85,6 @@ ApplicationWindow { property alias windowHeight: app.height property bool returnToHome: false property string graphStyle: "bars" - property string style: "light" property bool showHiddenOptions: false property string cloudEnvironment: "Community" property bool showConnectionTabs: false diff --git a/nymea-app/ui/RootItem.qml b/nymea-app/ui/RootItem.qml index dc610b44..5c994eb5 100644 --- a/nymea-app/ui/RootItem.qml +++ b/nymea-app/ui/RootItem.qml @@ -282,10 +282,15 @@ Item { PlatformHelper.requestPermissions(); } } else { + var clientId = PlatformHelper.deviceSerial + "+io.guh.nymeaapp"; + if ("branding" in app) { + clientId += "-" + app.branding; + } + AWSClient.registerPushNotificationEndpoint( PushNotifications.token, PlatformHelper.machineHostname, - PlatformHelper.deviceSerial + "+io.guh.nymeaapp" + (appBranding.length > 0 ? "-" + appBranding : ""), + clientId, PlatformHelper.deviceManufacturer, PlatformHelper.deviceModel); } diff --git a/nymea-app/ui/appsettings/LookAndFeelSettingsPage.qml b/nymea-app/ui/appsettings/LookAndFeelSettingsPage.qml index 66d6a1d5..e9c1ae44 100644 --- a/nymea-app/ui/appsettings/LookAndFeelSettingsPage.qml +++ b/nymea-app/ui/appsettings/LookAndFeelSettingsPage.qml @@ -47,7 +47,7 @@ SettingsPageBase { Layout.fillWidth: true Layout.leftMargin: app.margins Layout.rightMargin: app.margins - visible: appBranding.length === 0 + visible: !styleController.locked Label { Layout.fillWidth: true text: "Style"