/*! * * Copyright (c) 2021-2022 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) 22-Sep-2022 * \author (original) Behrouz NematiPour * \date (original) 22-Sep-2022 * */ #include "VConfirm.h" // Project #include "GuiController.h" 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 ); ADJUST_VIEW_CONNECTION(DuetConfirmUIrData ); } /*! * \brief VConfirm::onActionReceive * \details received response model data handler * \param vData - model data */ void View::VConfirm::onActionReceive(const DuetConfirmHDiData &vData) { isPowerOff(false ); id ( vData.mId ); command ( vData.mCommand ); GuiConfirmCommand cmd = static_cast( _command ); 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; } // 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")); // *** 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 ); // *** 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; } 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") ); 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; } /*! * \brief View::VConfirm::doConfirm * \details the invocable slot to send user's Confirmation */ void View::VConfirm::doConfirm(bool vConfirm) { DuetConfirmUIrData data; data.mId = id(); data.mConfirm = vConfirm; emit didAdjustment(data); }