From 5443c573e24174e5ddb29119f1e87547e9d5e821 Mon Sep 17 00:00:00 2001 From: "Denis V. Dedkov" Date: Sat, 18 May 2024 13:40:15 +0200 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA?= =?UTF-8?q?=D0=B8=20login=20=D0=B8=20password?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 8 ++++ resources/qml/LightGroup.qml | 2 +- resources/qml/SettingsForm.qml | 25 +++++++++--- resources/qml/SubtitledItemDelegate.qml | 24 ----------- resources/qml/main.qml | 12 ++---- resources/resources.qrc | 1 - src/settings.cpp | 54 +++++++++++++++++++++++++ src/settings.h | 37 +++++++++++++++++ 8 files changed, 122 insertions(+), 41 deletions(-) delete mode 100644 resources/qml/SubtitledItemDelegate.qml create mode 100644 src/settings.cpp create mode 100644 src/settings.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c6b5fc6..e2b63d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ project(nooLight VERSION 1.0 LANGUAGES CXX) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_AUTORCC ON) +include_directories(src) find_package(Qt6 6.5 REQUIRED COMPONENTS Quick) @@ -15,6 +16,13 @@ qt_add_executable(appnooLight resources/resources.qrc ) +qt_add_qml_module(appnooLight + URI ru.ded.noolight + VERSION 1.0 + SOURCES + src/settings.h src/settings.cpp +) + if (ANDROID) set_property(TARGET appnooLight APPEND PROPERTY QT_ANDROID_EXTRA_LIBS ${QT_ANDROID_SSL_DIR}/no-asm/ssl_3/${ANDROID_ABI}/libcrypto_3.so diff --git a/resources/qml/LightGroup.qml b/resources/qml/LightGroup.qml index 382f5db..c05bd6d 100644 --- a/resources/qml/LightGroup.qml +++ b/resources/qml/LightGroup.qml @@ -69,7 +69,7 @@ Item { Label { anchors.horizontalCenter: parent.horizontalCenter - horizontalAlignment: Text.horizontalCenter + horizontalAlignment: Qt.horizontalCenter text: name } } diff --git a/resources/qml/SettingsForm.qml b/resources/qml/SettingsForm.qml index f4bb193..e1c8362 100644 --- a/resources/qml/SettingsForm.qml +++ b/resources/qml/SettingsForm.qml @@ -1,6 +1,9 @@ import QtQuick 2.0 import QtQuick.Controls 2.2 +import ru.ded.noolight 1.0 +import ru.ded.components 1.0 + Page { id: root @@ -14,6 +17,16 @@ Page { title: qsTr("nooLite service URL") inputMethodHint: Qt.ImhUrlCharactersOnly } + ListElement { + name: "login" + title: qsTr("Login") + inputMethodHint: Qt.ImhLatinOnly + } + ListElement { + name: "password" + title: qsTr("Password") + hideText: true + } } ListView { @@ -24,15 +37,14 @@ Page { delegate: SubtitledItemDelegate { width: parent.width text: model.title - subtitle: settings[model.name] + subtitle: model.hideText && Settings[model.name] ? qsTr("Hidden") : Settings[model.name] onClicked: inputDialog.open() Dialog { id: inputDialog - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 + anchors.centerIn: parent parent: ApplicationWindow.overlay focus: true @@ -49,14 +61,15 @@ Page { width: parent.width focus: true - inputMethodHints: Qt.ImhNoAutoUppercase | model.inputMethodHint + inputMethodHints: model.inputMethodHint + echoMode: model.hideText ? TextInput.Password : TextInput.Normal placeholderText: model.title - text: settings[model.name] + text: Settings[model.name] } } onAccepted: { - settings[model.name] = textField.text + Settings[model.name] = textField.text } } } diff --git a/resources/qml/SubtitledItemDelegate.qml b/resources/qml/SubtitledItemDelegate.qml deleted file mode 100644 index 8942433..0000000 --- a/resources/qml/SubtitledItemDelegate.qml +++ /dev/null @@ -1,24 +0,0 @@ -import QtQuick 2.0 -import QtQuick.Controls 2.2 - -ItemDelegate { - id: root - - property string subtitle: "" - - contentItem: Column { - Label { - id: titleLabel - - width: parent.width - text: root.text - } - - Label { - width: parent.width - font.pixelSize: titleLabel.font.pixelSize - 2 - text: root.subtitle ? root.subtitle : qsTr("undefined") - opacity: 0.8 - } - } -} diff --git a/resources/qml/main.qml b/resources/qml/main.qml index 28098f0..9945644 100644 --- a/resources/qml/main.qml +++ b/resources/qml/main.qml @@ -1,7 +1,7 @@ import QtQuick 2.9 import QtQuick.Controls 2.2 -import Qt.labs.settings 1.0 +import ru.ded.noolight 1.0 import ru.ded.components 1.0 ApplicationWindow { @@ -12,16 +12,10 @@ ApplicationWindow { height: 480 title: qsTr("Stack") - Settings { - id: settings - - property string serviceUrl: "" - } - LightsModel { id: lightsModel - serviceUrl: settings.serviceUrl + serviceUrl: Settings.serviceUrl onError: (text) => stackView.showError(text) } @@ -102,7 +96,7 @@ ApplicationWindow { } } - onClosing: { + onClosing: (close) => { if (stackView.depth > 1) { close.accepted = false stackView.pop() diff --git a/resources/resources.qrc b/resources/resources.qrc index c11ceba..db336df 100644 --- a/resources/resources.qrc +++ b/resources/resources.qrc @@ -4,7 +4,6 @@ qtquickcontrols2.conf qml/HomeForm.qml qml/SettingsForm.qml - qml/SubtitledItemDelegate.qml qml/LightsModel.qml qml/LightGroup.qml qml/GradientButton.qml diff --git a/src/settings.cpp b/src/settings.cpp new file mode 100644 index 0000000..0c8e2b8 --- /dev/null +++ b/src/settings.cpp @@ -0,0 +1,54 @@ +#include "settings.h" + +namespace Keys { + +constexpr auto ServiceUrl = "serviceUrl"; +constexpr auto Login = "login"; +constexpr auto Password = "password"; + +} + +QString Settings::serviceUrl() const +{ + return m_settings.value(Keys::ServiceUrl, "https://mynoolightservice.org").toString(); +} + +void Settings::setServiceUrl(const QString &newServiceUrl) +{ + if (serviceUrl() == newServiceUrl) { + return; + } + + m_settings.setValue(Keys::ServiceUrl, newServiceUrl); + emit serviceUrlChanged(); +} + +QString Settings::login() const +{ + return m_settings.value(Keys::Login).toString(); +} + +void Settings::setLogin(const QString &newLogin) +{ + if (login() == newLogin) { + return; + } + + m_settings.setValue(Keys::Login, newLogin); + emit loginChanged(); +} + +QString Settings::password() const +{ + return m_settings.value(Keys::Password).toString(); +} + +void Settings::setPassword(const QString &newPassword) +{ + if (password() == newPassword) { + return; + } + + m_settings.setValue(Keys::Password, newPassword); + emit passwordChanged(); +} diff --git a/src/settings.h b/src/settings.h new file mode 100644 index 0000000..98d0f68 --- /dev/null +++ b/src/settings.h @@ -0,0 +1,37 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +#include +#include +#include + +class Settings : public QObject +{ + Q_OBJECT + QML_ELEMENT + QML_SINGLETON + + Q_PROPERTY(QString serviceUrl READ serviceUrl WRITE setServiceUrl NOTIFY serviceUrlChanged FINAL) + Q_PROPERTY(QString login READ login WRITE setLogin NOTIFY loginChanged FINAL) + Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged FINAL) + +public: + QString serviceUrl() const; + void setServiceUrl(const QString &newServiceUrl); + + QString login() const; + void setLogin(const QString &newLogin); + + QString password() const; + void setPassword(const QString &newPassword); + +signals: + void serviceUrlChanged(); + void loginChanged(); + void passwordChanged(); + +private: + QSettings m_settings; +}; + +#endif // SETTINGS_H