Index: sources/view/settings/VSettings.cpp =================================================================== diff -u -r4696b5fa37cc2ee744582fc70228736cad55ca63 -r6c6f1f5d466badd9b4fd67be7c907234c342b2a2 --- sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision 4696b5fa37cc2ee744582fc70228736cad55ca63) +++ sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision 6c6f1f5d466badd9b4fd67be7c907234c342b2a2) @@ -7,7 +7,7 @@ * * \file VSettings.cpp * \author (last) Behrouz NematiPour - * \date (last) 23-Nov-2022 + * \date (last) 02-Apr-2023 * \author (original) Behrouz NematiPour * \date (original) 29-Mar-2021 * @@ -22,34 +22,55 @@ #include "GuiController.h" #include "MSettings.h" #include "Settings.h" +#include VIEW_DEF_CLASS(VSettings) void VSettings::initConnections() { ACTION_VIEW_CONNECTION (SettingsData ); + connect(&_GuiController, SIGNAL(didActionReceive (GuiActionType, const QVariantList &)), + this , SLOT( onActionReceive (GuiActionType, const QVariantList &))); + +} + +void VSettings::initConnectionsSettings() +{ + static bool init = false; if ( init ) return; + PROPERTY_POST_CONNECTION(VSettings, servicePass ); PROPERTY_POST_CONNECTION(VSettings, alarmVolume ); + PROPERTY_POST_CONNECTION(VSettings, roWaterMode ); PROPERTY_POST_CONNECTION(VSettings, noCANBus ); - connect(&_GuiController, SIGNAL(didActionReceive (GuiActionType, const QVariantList &)), - this , SLOT( onActionReceive (GuiActionType, const QVariantList &))); - + init = true; } void VSettings::servicePass_post(const QString &vservicePass) { + //TODO The Settings shall be the Singleton SettingsController and modify the MSettings like the others. Storage::Settings settings; if ( settings.save(servicePassCategory(), servicePassGroup(), servicePassKey(), vservicePass) != 0 ) { servicePass(""); // FIXME: Notify UI with a message } } +void VSettings::roWaterMode_post(const bool &vroWaterMode_post) { + //TODO The Settings shall be the Singleton SettingsController and modify the MSettings like the others. + Storage::Settings settings; + if ( settings.save(roWaterModeCategory(), roWaterModeGroup(), roWaterModeKey(), QString::number(vroWaterMode_post)) != 0 ) { + roWaterMode(false); + // FIXME: Notify UI with a message + } +} + void VSettings::alarmVolume_post(const quint8 &valarmVolume) { + //TODO The Settings shall be the Singleton SettingsController and modify the MSettings like the others. Storage::Settings settings; settings.save(alarmVolumeCategory(), alarmVolumeGroup(), alarmVolumeKey(), QString::number(valarmVolume)); } void VSettings::noCANBus_post(const bool &vnoCANBus) { + //TODO The Settings shall be the Singleton SettingsController and modify the MSettings like the others. Storage::Settings settings; settings.save(noCANBusCategory(), noCANBusGroup(), noCANBusKey(), QString::number(vnoCANBus)); } @@ -79,6 +100,12 @@ keyValue[key] = mServicePass ; servicePass ( mServicePass); } + else if ( isroWaterMode (category, group, key) ) { + bool mRoWaterMode; + mRoWaterMode = _Settings.value(category, group, key).toBool (); + keyValue[key] = mRoWaterMode ; + roWaterMode ( mRoWaterMode); + } else if ( isalarmVolume (category, group, key) ) { quint8 mAlarmVolume; mAlarmVolume = _Settings.value(category, group, key).toInt (); // returns 0 if fails, so no error checking needed. @@ -108,9 +135,13 @@ // otherwise will use the default value and will notify the update. servicePass ( _servicePass ); alarmVolume ( _alarmVolume ); + roWaterMode ( _roWaterMode ); // noCANBus ( _noCANBus ); // This line has been put here to remind developers that it is intentionally removed, to not to add a default value. + //DEBUG qDebug() << servicePass() << roWaterMode() << alarmVolume() << noCANBus(); adjustment(true); + + initConnectionsSettings(); } VSettings::TKeysList VSettings::updateReplacements(const QString &vGroup, const QStringList &vKeys) @@ -250,28 +281,43 @@ return ok; } -#include +QString View::VSettings::hashedPassword(const QString &vPassword, bool vIsService) +{ + bool ok; + QString hashed = encryption::hashedString(vPassword, ok, ! vIsService); + encryptionPass(ok); + return ok ? hashed : ""; +} -QString VSettings::encryptString(const QString &vString) { - // FIXME: Move this to the utility, storage or settings controller class for more general use. - QString salt = "DVT-HD0004"; // FIXME: Use the actual HD serial number - int iter = 1000; - int len = 16; - auto shuffle = [](const QString &vString) { - // FIXME: Implement this, and make this a function and move this to the utility or storage class for more general use. - QString shuffled = vString; - return shuffled.toUtf8().toHex(); - }; - QCryptographicHash::Algorithm algorithm = QCryptographicHash::Sha512; - QByteArray hashed = QPasswordDigestor::deriveKeyPbkdf2(algorithm, vString.toUtf8(), shuffle(salt), iter, len); - return hashed.toHex(); +/*! + * \brief View::VSettings::isServicePasswordMatch + * \details matches the given password string, vPassword, with the service password. + * \param vPassword - the given password string + * \return true if it matches. + */ +bool View::VSettings::isServicePasswordMatch(const QString &vPassword) +{ + //DEBUG qDebug() << __FUNCTION__ << _servicePass << hashedPassword(vPassword, true); + bool isNotEmpty = ( ! vPassword.trimmed().isEmpty() ); + bool isMatch = ( _servicePass == hashedPassword(vPassword, true) ); + return isMatch && isNotEmpty; } -bool View::VSettings::isPasswordMatch(const QString &vPassword) { - return _servicePass == encryptString(vPassword); +/*! + * \brief View::VSettings::updateServicePassword + * \details Updatest the service password with the given password. + * \param vPassword - the password to be saved as the service password. + */ +void View::VSettings::updateServicePassword(const QString &vPassword) +{ + servicePass(hashedPassword(vPassword, true)); } -void View::VSettings::updatePassword(const QString &vPassword) +void View::VSettings::checkServicePasswordSet() { - servicePass(encryptString(vPassword)); + bool ok; + isDefaultServicePassword(encryption::isDefaultServicePassword(servicePass(), ok)); + //DEBUG qDebug() << __FUNCTION__ << ok; + encryptionPass(ok); } +