Index: sources/gui/qml/PowerItem.qml =================================================================== diff -u -rf502bc55feb08cd037d9caa12086d30034fe715b -r981e534e5b3174aab7ec47de3b1ead1511dbb6ef --- sources/gui/qml/PowerItem.qml (.../PowerItem.qml) (revision f502bc55feb08cd037d9caa12086d30034fe715b) +++ sources/gui/qml/PowerItem.qml (.../PowerItem.qml) (revision 981e534e5b3174aab7ec47de3b1ead1511dbb6ef) @@ -40,13 +40,14 @@ AutoHideInfo { id: _autoHideInfo } PowerOff { id: _powerOffDialog - visible : vConfirm.visible + idText : vConfirm.id titleText : vConfirm.title messageText : vConfirm.message confirmText : vConfirm.confirm - confirmVisible : ! vConfirm.isReject cancelText : vConfirm.cancel + confirmVisible : ! vConfirm.isReject notificationText: vConfirm.adjustment_ReasonText + autoClose : vConfirm.isPowerOff || vConfirm.isReject onVisibleChanged: { if (visible) _alarmItem.alarmHide() Index: sources/gui/qml/components/Footer.qml =================================================================== diff -u -rf502bc55feb08cd037d9caa12086d30034fe715b -r981e534e5b3174aab7ec47de3b1ead1511dbb6ef --- sources/gui/qml/components/Footer.qml (.../Footer.qml) (revision f502bc55feb08cd037d9caa12086d30034fe715b) +++ sources/gui/qml/components/Footer.qml (.../Footer.qml) (revision 981e534e5b3174aab7ec47de3b1ead1511dbb6ef) @@ -44,7 +44,7 @@ let visibleCount = 0 for (let i = 0; i < count; i++) { - console.debug(children[i].text.text) + //DEBUG: console.debug(children[i].text.text) if ( children[i].visible ) { visibleCount += 1 @@ -57,7 +57,7 @@ } } let spacing = (_root.width - (width * visibleCount)) / (visibleCount + 1) - console.debug( " ~~~~~~~~~~ ", count, visibleCount, spacing) + //DEBUG: console.debug( " ~~~~~~~~~~ ", count, visibleCount, spacing) _private.spacing = spacing } Index: sources/gui/qml/dialogs/PowerOff.qml =================================================================== diff -u -rf502bc55feb08cd037d9caa12086d30034fe715b -r981e534e5b3174aab7ec47de3b1ead1511dbb6ef --- sources/gui/qml/dialogs/PowerOff.qml (.../PowerOff.qml) (revision f502bc55feb08cd037d9caa12086d30034fe715b) +++ sources/gui/qml/dialogs/PowerOff.qml (.../PowerOff.qml) (revision 981e534e5b3174aab7ec47de3b1ead1511dbb6ef) @@ -26,12 +26,14 @@ */ ModalDialog { id : _root contentItem.objectName : "PowerOffDialog" //SquishQt testability - property alias titleText : _titleText.text - property alias messageText : _messageText.text - property alias confirmText : _confirmTouch.textString - property alias confirmVisible : _confirmTouch.visible - property alias cancelText : _cancelTouch.textString - property alias cancelVisible : _cancelTouch.visible + property string idText : "" + property alias titleText : _titleText.text + property alias messageText : _messageText.text + property alias confirmText : _confirmTouch.textString + property alias confirmVisible : _confirmTouch.visible + property alias cancelText : _cancelTouch.textString + property alias cancelVisible : _cancelTouch.visible + property bool autoClose : true function footerUpdate() { _footer.update() @@ -60,16 +62,28 @@ textString : qsTr("CANCEL") onPressed : { rejected() - close() + if ( autoClose ) close() } }, TouchRect { id : _confirmTouch textString : qsTr("SHUTDOWN") onPressed : { accepted() - close() + if ( autoClose ) close() } } ] } + + Text { id: _idText + text : qsTr("ID") + ":" + _root.idText + anchors { + left : parent.left + bottom : parent.bottom + leftMargin : 5 + bottomMargin: 5 + } + color : notification.visible ? Colors.backgroundDialog : Colors.textMain + font.pixelSize : Fonts.fontPixelDialogText + } } Index: sources/main.h =================================================================== diff -u -r265ce7409a0ea99a4ae059f5ce7978c9cdb10631 -r981e534e5b3174aab7ec47de3b1ead1511dbb6ef --- sources/main.h (.../main.h) (revision 265ce7409a0ea99a4ae059f5ce7978c9cdb10631) +++ sources/main.h (.../main.h) (revision 981e534e5b3174aab7ec47de3b1ead1511dbb6ef) @@ -172,7 +172,7 @@ #define PROPERTY_POST_CONNECTION( vCLASS, vVARIABLE ) \ connect(this, &vCLASS::vVARIABLE##Changed \ , &vCLASS::vVARIABLE##_post ); - +//--------------------------------------------------------------------------------// #define PROPERTY_BASE(vTYPE , vVARIABLE , vDEFVALUE, vSIGNAL) \ /*! \brief Qt Property declaration \details The Qt Property definition by Q_PROPERTY documentation. @@ -232,6 +232,45 @@ return _##vVARIABLE ; \ } //--------------------------------------------------------------------------------// +#define IDBASED_BASE(vTYPE , vVARIABLE , vDEFVALUE , vLIST , vID) \ + /*! \brief Qt Property declaration + \details The Qt Property definition by Q_PROPERTY documentation. + */\ + Q_PROPERTY( vTYPE vVARIABLE \ + READ vVARIABLE \ + WRITE vVARIABLE \ + NOTIFY vID##Changed) \ + Q_SIGNALS: \ + /*! \brief Property notify signal + \details The property notify signal (...Changed) + which will be emitted by property setter + - if only the value has been changed \n + - or it's the first time property is set. \n + \return current value + */\ + void vVARIABLE##Changed( const vTYPE & v##vVARIABLE ); \ + private: \ + vTYPE _##vVARIABLE = vDEFVALUE; \ + bool _##vVARIABLE##Changed = false; \ + bool _##vVARIABLE##ByID = true ; \ + protected: \ + /*! \brief Property byId setter + \details The property sets the ByID value to be used in the getter + */\ + void vVARIABLE##ByID(bool vByID = true) { \ + _##vVARIABLE##ByID = vByID ; \ + } \ + /*! \brief Property getter + \details The property getter which reads the private variable + \return current value + */\ + vTYPE vVARIABLE () const { \ + if ( ! _##vVARIABLE##ByID ) return _##vVARIABLE; \ + QString value = _##vLIST [ _##vID ].vVARIABLE; \ + if ( ! value.isEmpty() ) return value; \ + return vDEFVALUE; \ + } +//--------------------------------------------------------------------------------// #define READONLY( vTYPE , vVARIABLE , vDEFVALUE ) \ READONLY_BASE( vTYPE , vVARIABLE , vDEFVALUE , Changed ) \ PROPERTY_SLOT( vTYPE , vVARIABLE) @@ -248,6 +287,11 @@ PROPERTY_BASE( vTYPE , vVARIABLE , vDEFVALUE , Entered ) \ STATE_SLOT ( vTYPE , vVARIABLE) //--------------------------------------------------------------------------------// + +#define IDBASED( vTYPE , vVARIABLE , vDEFAULT , vLIST , vID ) \ + IDBASED_BASE ( vTYPE , vVARIABLE , vDEFAULT , vLIST , vID ) \ + PROPERTY_SLOT( vTYPE , vVARIABLE ) +//--------------------------------------------------------------------------------// #define CONSTANT( vTYPE , vVARIABLE , vDEFVALUE ) \ /*! \brief Qt Constant Property declaration \details The Qt Property definition by Q_PROPERTY documentation. Index: sources/view/confirm/VConfirm.cpp =================================================================== diff -u -r3a2114c103d6eaf2807d2f515eeb9e0fbdeabc69 -r981e534e5b3174aab7ec47de3b1ead1511dbb6ef --- sources/view/confirm/VConfirm.cpp (.../VConfirm.cpp) (revision 3a2114c103d6eaf2807d2f515eeb9e0fbdeabc69) +++ sources/view/confirm/VConfirm.cpp (.../VConfirm.cpp) (revision 981e534e5b3174aab7ec47de3b1ead1511dbb6ef) @@ -33,18 +33,16 @@ } /*! - * \brief VConfirm::onActionReceive - * \details received response model data handler - * \param vData - model data + * \brief View::VConfirm::setConfirmCommand + * \param vCommand - confirm command */ -void View::VConfirm::onActionReceive(const DuetConfirmHDiData &vData) +void View::VConfirm::setConfirmCommand(const DuetConfirmHDiData &vData) { - isPowerOff(false ); - - id ( vData.mId ); command ( vData.mCommand ); - GuiConfirmCommand cmd = static_cast( _command ); + + visible( ( cmd == GuiConfirmCommand::GENERIC_CONFIRM_CMD_REQUEST_OPEN || cmd == GuiConfirmCommand::GENERIC_CONFIRM_CMD_REJECT ) ); + switch ( cmd ) { case GuiConfirmCommand::GENERIC_CONFIRM_CMD_REQUEST_OPEN : adjustment_Reason ( GuiConfirmId::GENERIC_CONFIRM_ID_NONE ); @@ -76,42 +74,88 @@ break; case GuiConfirmCommand::NUM_OF_GENERIC_CONFIRM_COMMAND : /* No code */ break; } +} - // TODO: These values shall be read form the Confirm.conf - title ( QString("Title [%1]").arg(_id) ); - message ( Gui::enumString(static_cast(vData.mId), "[%1] Unknown Request") ); // For now - confirm (tr("CONFIRM")); - cancel (isReject() ? tr("CLOSE") : tr("CANCEL")); +/*! + * \brief View::VConfirm::setConfirmId + * \param vId - confirm id + */ +void View::VConfirm::setConfirmId(const DuetConfirmHDiData &vData) +{ + titleByID (); + messageByID (); + confirmByID (); + cancelByID ( ! isReject() ); + cancel ( tr("CLOSE" ) ); - // *** has to be the last to let the dialog to setup itself before becomes visible. *** - visible ( cmd == GuiConfirmCommand::GENERIC_CONFIRM_CMD_REQUEST_OPEN || cmd == GuiConfirmCommand::GENERIC_CONFIRM_CMD_REJECT ); + id ( vData.mId ); +} +/*! + * \brief View::VConfirm::setPowerOffCommand + */ +void View::VConfirm::setPowerOffCommand() +{ + command ( 0 ); + adjustment_Reason ( GuiConfirmId::GENERIC_CONFIRM_ID_NONE ); + adjustment_Accepted ( false ); // it has not been accepted yet. + isTimeout ( false ); + isReject ( false ); + isAccept ( false ); +} + +/*! + * \brief View::VConfirm::setPowerOffId + */ +void View::VConfirm::setPowerOffId() +{ + titleByID ( false ); + messageByID ( false ); + confirmByID ( false ); + cancelByID ( false ); + + title ( tr("Shutdown") ); + message ( tr("Are you sure you want to Shutdown?") ); + adjustment_Reason ( GuiConfirmId::GENERIC_CONFIRM_ID_NONE ); // power off has no rejection reason on the dialog + confirm ( tr("SHUTDOWN") ); + cancel ( tr("CANCEL") ); + + id ( 0 ); +} + +/*! + * \brief VConfirm::onActionReceive + * \details received response model data handler + * \param vData - model data + */ +void View::VConfirm::onActionReceive(const DuetConfirmHDiData &vData) +{ + isPowerOff(false ); + + setConfirmCommand ( vData ); + setConfirmId ( vData ); + // *** has to be the last to let the information to be set and then emit the signal *** // *** otherwise will use the Previous values before being set. *** adjustment ( true ); - // DEBUG: - qDebug() << _id << _command << adjustment_Reason() << _title << _message; + // DEBUG: qDebug() << _id << _command << adjustment_Reason() << _title << _message << _isReject; } void View::VConfirm::onActionReceive(const PowerOffData &vData) { isPowerOff(true ); - title ( tr("Shutdown") ); - message ( tr("Are you sure you want to Shutdown?") ); - adjustment_Reason ( GuiConfirmId::GENERIC_CONFIRM_ID_NONE ); // power off has no rejection reason on the dialog - confirm ( tr("SHUTDOWN") ); - cancel ( tr("CANCEL") ); + setPowerOffCommand ( ); + setPowerOffId ( ); poweroff(vData.mStatus); // *** has to be the last to let the information to be set and then emit the signal *** // *** otherwise will use the Previous values before being set. *** adjustment ( true ); - // DEBUG: - qDebug() << _id << _command << adjustment_Reason() << _title << _message; + // DEBUG: qDebug() << _id << _command << adjustment_Reason() << _title << _message << _isReject; } /*! @@ -120,8 +164,8 @@ */ void View::VConfirm::doConfirm(bool vConfirm) { DuetConfirmUIrData data; - data.mId = id(); - data.mConfirm = vConfirm; + data.mId = id(); + data.mConfirm = vConfirm; emit didAdjustment(data); } @@ -133,30 +177,28 @@ for (const auto &group : groups) { bool ok = true; - quint32 id = group.toInt( &ok ); Q_UNUSED(id) + quint32 id = group.toInt( &ok ); if ( ! ok ) { LOG_DEBUG(QString("Not an confirm ID number [%1]").arg(group)); continue; } - // AlarmData alarmData; - // InstructionData instructionData; - // for (const QString &key : _Settings.keys(group)) { - // if (isTitle ( key ) ) { - // alarmData.title = _Settings.value(group, key).toString(); - // } else if (isMessage ( key ) ) { - // alarmData.message = _Settings.value(group, key).toString(); - // } else { - // instructionData[key] = _Settings.value(group, key).toString(); - // alarmData.instructions = instructionData; - // } - // } - // _alarms[id] = alarmData; - // - /// DEBUG: - /// TODO: the MSettings model should do the same has been done here and use map instead of separate structure to iterate vertically, while map supports, keys, values. - // qDebug() << "@" << id << _alarms[id].title << _alarms[id].message << _alarms[id].instructions.keys() << _alarms[id].instructions.values(); - // for (const auto &key : _alarms[id].instructions.keys()) { - // qDebug() << "-" << key << _alarms[id].instructions.value(key); - // } + ConfirmData confirmData; + for (const QString &key : _Settings.keys(category, group)) { + if (Storage::Settings::isKeyTitle ( key ) ) { + confirmData.title = _Settings.value(category, group, key).toString(); + } else if (Storage::Settings::isKeyMessage ( key ) ) { + confirmData.message = _Settings.value(category, group, key).toString(); + } else if (Storage::Settings::isKeyConfirm ( key ) ) { + confirmData.confirm = _Settings.value(category, group, key).toString(); + } else if (Storage::Settings::isKeyCancel ( key ) ) { + confirmData.cancel = _Settings.value(category, group, key).toString(); + } else { + } + } + _confirms[id] = confirmData; + + // DEBUG: + // TODO: the MSettings model should do the same has been done here and use map instead of separate structure to iterate vertically, while map supports, keys, values. + // qDebug() << "@" << id << _confirms[id].title << _confirms[id].message << _confirms[id].confirm << _confirms[id].cancel; } } - // emit alarm_AlarmIDChanged(_alarm_AlarmID); // to get the dialog content in sync with the Alarm.conf in case there is an early alarm. + emit idChanged(_id); // to get the dialog content in sync with the Confirm.conf in case there is an early confirm. } Index: sources/view/confirm/VConfirm.h =================================================================== diff -u -rdb12df03b8067e1ccc81f190cabfb03359c3d8cb -r981e534e5b3174aab7ec47de3b1ead1511dbb6ef --- sources/view/confirm/VConfirm.h (.../VConfirm.h) (revision db12df03b8067e1ccc81f190cabfb03359c3d8cb) +++ sources/view/confirm/VConfirm.h (.../VConfirm.h) (revision 981e534e5b3174aab7ec47de3b1ead1511dbb6ef) @@ -40,6 +40,15 @@ // // friends // friend class ::tst_views; + struct ConfirmData { + QString title = ""; + QString message = ""; + QString confirm = ""; + QString cancel = ""; + }; + + QMap _confirms; + // disabled coco begin validated: // The property adjustment_Triggered has to be always true // and to always trigger the change event to work as a notifier for GUI @@ -57,13 +66,20 @@ PROPERTY(bool , isReject , 0) PROPERTY(bool , isAccept , 0) - TRIGGER (bool , visible , 0) - PROPERTY(QString , title ,"") - PROPERTY(QString , message ,"") - PROPERTY(QString , confirm ,tr("CONFIRM")) - PROPERTY(QString , cancel ,tr("CANCEL" )) + IDBASED (QString , title ,tr("Confirm" ), confirms, id) + IDBASED (QString , message ,tr("Are you sure?" ), confirms, id) + IDBASED (QString , confirm ,tr("CONFIRM" ), confirms, id) + IDBASED (QString , cancel ,tr("CANCEL" ), confirms, id) + + void setConfirmCommand (const DuetConfirmHDiData &vData); + void setConfirmId (const DuetConfirmHDiData &vData); + + void setPowerOffCommand (); + void setPowerOffId (); + + VIEW_DEC_CLASS (VConfirm ) VIEW_DEC_SLOT (DuetConfirmHDiData ) VIEW_DEC_SLOT (PowerOffData )