/*! * * Copyright (c) 2022-2025 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file VConfirm.cpp * \author (last) Behrouz NematiPour * \date (last) 10-Oct-2022 * \author (original) Behrouz NematiPour * \date (original) 30-Sep-2022 * */ #include "VConfirm.h" // Project #include "GuiController.h" #include "Settings.h" #include VIEW_DEF_CLASS_ADJUSTMENT(VConfirm) /*! * \brief Connection Initializer * \details All the class signal/slot connections are defined here. */ void View::VConfirm::initConnections() { ACTION_VIEW_CONNECTION(DuetConfirmHDiData ); ACTION_VIEW_CONNECTION(PowerOffData ); ACTION_VIEW_CONNECTION(SettingsData ); ADJUST_VIEW_CONNECTION(DuetConfirmUIrData ); } /*! * \brief View::VConfirm::setConfirmCommand * \param vCommand - confirm command */ void View::VConfirm::setConfirmCommand(const DuetConfirmHDiData &vData) { 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 ); adjustment_Accepted ( false ); // it has not been accepted yet. isTimeout ( false ); isReject ( false ); isAccept ( false ); break; case GuiConfirmCommand::GENERIC_CONFIRM_CMD_TIMEOUT_CLOSE : adjustment_Reason ( GuiConfirmId::GENERIC_CONFIRM_ID_NONE ); // there is no need to display the timeout reason and just hides the dialog. adjustment_Accepted ( false ); isTimeout ( true ); isReject ( false ); isAccept ( false ); break; case GuiConfirmCommand::GENERIC_CONFIRM_CMD_REJECT : adjustment_Reason ( vData.mReason ); // there is no need to display the timeout reason and just hides the dialog. adjustment_Accepted ( false ); isTimeout ( false ); isReject ( true ); isAccept ( false ); break; case GuiConfirmCommand::GENERIC_CONFIRM_CMD_ACCEPT_CLOSE : adjustment_Reason ( GuiConfirmId::GENERIC_CONFIRM_ID_NONE ); // there is no need to display the timeout reason and just hides the dialog. adjustment_Accepted ( true ); isTimeout ( false ); isReject ( false ); isAccept ( true ); break; case GuiConfirmCommand::NUM_OF_GENERIC_CONFIRM_COMMAND : /* No code */ break; } needConfirm ( cmd == GuiConfirmCommand::GENERIC_CONFIRM_CMD_REQUEST_OPEN ); } /*! * \brief View::VConfirm::setConfirmId * \param vId - confirm id */ void View::VConfirm::setConfirmId(const DuetConfirmHDiData &vData) { titleByID (); messageByID (); confirmByID (); // FIXME: - having issue changing the caption by isRejected, disabled for now. cancelByID ( /*! isReject()*/ ); // cancel ( tr("CLOSE" ) ); // These need to be set to be used in the messageModifier if ( vData.mId == GuiConfirmId::GENERIC_CONFIRM_ID_UF_RATE_CHANGE_IN_TX_DURATION_CHANGE ) { extraParam1 ( qCeil(vData.mExtraParam1 )); } else { extraParam1 ( vData.mExtraParam1 ); } extraParam2 ( vData.mExtraParam2 ); extraParam3 ( vData.mExtraParam3 ); extraParam4 ( vData.mExtraParam4 ); //id ( vData.mId ); // FIXME: change this to a TRIGGER // Qt moc compile issue _id = vData.mId; emit idChanged(_id); } /*! * \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 ); extraParam1 ( vData.mExtraParam1 ); extraParam2 ( vData.mExtraParam2 ); extraParam3 ( vData.mExtraParam3 ); extraParam4 ( vData.mExtraParam4 ); // *** 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 << _isReject; } void View::VConfirm::onActionReceive(const PowerOffData &vData) { isPowerOff( true ); 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 << _isReject; } /*! * \brief View::VConfirm::doConfirm * \details the invocable slot to send user's Confirmation */ void View::VConfirm::doConfirm(bool vConfirm) { needConfirm ( false ); DuetConfirmUIrData data; data.mId = id(); data.mConfirm = vConfirm; emit didAdjustment(data); } void View::VConfirm::onActionReceive(const SettingsData &) { QStringList mCategorys = _Settings.categorys(); for (const QString &category : mCategorys) { QStringList groups = _Settings.groups(category); if ( ! Storage::Settings::isCategoryConfirm( category ) ) continue; for (const auto &group : groups) { bool ok = true; quint32 id = group.toInt( &ok ); if ( ! ok ) { LOG_DEBUG(QString("Not an confirm ID number [%1]").arg(group)); continue; } 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 idChanged(_id); // to get the dialog content in sync with the Confirm.conf in case there is an early confirm. }