/*! * * Copyright (c) 2020-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 GuiView.cpp * \author (last) Behrouz NematiPour * \date (last) 18-Apr-2022 * \author (original) Behrouz NematiPour * \date (original) 26-Aug-2020 * */ // Project #include "GuiView.h" #include "GuiController.h" #include "DeviceController.h" // namespace using namespace Gui; /*! * \brief GuiView::GuiView * \details Constructor * \param parent - QObject parent owner object. * Qt handles the children destruction by their parent objects life-cycle. */ GuiView::GuiView(QObject *parent) { Q_UNUSED(parent) initConnections(); } /*! * \brief GuiView::initConnections * \details Initializes the required signal/slot connection between this class and other objects * to be able to communicate. */ void GuiView::initConnections() { connect(&_GuiController, SIGNAL(didActionReceive (GuiActionType, const QVariantList &)), this , SLOT( onActionReceive (GuiActionType, const QVariantList &))); // since we do not have access to this object because it is created in QML. // Connection to the GuiController made here // It should be defined in the class which wants to connect to signal. connect(this , SIGNAL(didActionTransmit(GuiActionType,const QVariantList &)), &_GuiController, SLOT( doActionTransmit(GuiActionType,const QVariantList &))); // From UI : USB drive umount connect(this , SIGNAL(didUSBDriveUmount()), &_GuiController, SLOT( doUSBDriveUmount())); // From OS : USB drive removed connect(&_GuiController, SIGNAL(didUSBDriveMount ()), this , SLOT( onUSBDriveMount ())); connect(&_GuiController, SIGNAL(didUSBDriveRemove()), this , SLOT( onUSBDriveRemove())); // USB Drive connect(&_DeviceController, SIGNAL( didUSBSpaceChange(bool, qint64, qint64, quint8)), this , SLOT( onUSBSpaceChange(bool, qint64, qint64, quint8))); // SD Card connect(&_GuiController, SIGNAL(didSDCardStateChange(bool,bool)), this , SLOT( onSDCardStateChange(bool,bool))); /// TEST: Test the space on GUI, not sure if we keep it. connect(&_DeviceController, SIGNAL( didSDCardSpaceChange(bool, qint64, qint64, quint8)), this , SLOT( onSDCardSpaceChange(bool, qint64, qint64, quint8))); connect(&_GuiController, SIGNAL(didExport()), this , SLOT( onExport())); // From UI : Export Log connect(this , SIGNAL(didExportLog ()), &_GuiController, SLOT( doExportLog ())); connect(this , SIGNAL(didExportService ()), &_GuiController, SLOT( doExportService ())); connect(this , SIGNAL(didExportTreatment ()), &_GuiController, SLOT( doExportTreatment ())); } /*! * \brief GuiView::onActionReceive * \details emits didActionReceive signal to notify other classes (Gui) * , an action has been received. * \param vAction - the action * \param vData - the action data */ void GuiView::onActionReceive (GuiActionType vAction, const QVariantList &vData) { // process the evaluation and notify GUI emit didActionReceive (vAction, vData); } /*! * \brief GuiView::doActionTransmit * \details emits didActionTransmit signal to notify other classes (GuiController) * , an action has been required to be transmitted. * \param vAction - the action * \param vData - the action data */ void GuiView::doActionTransmit(GuiActionType vAction, const QVariantList &vData) { // TODO : Remove this code later when Investigated thoroughly. // disabled coco begin validated: This code later needs to be removed when Investigated thoroughly. // has been tested manually emit didActionTransmit(vAction, vData); } // disabled coco end /*! * \brief GuiView::doActionTransmit * \details emits didActionTransmit signal to notify other classes (GuiController) * , an action has been required to be transmitted. * \note The overloaded method with only one data parameter, for easier use in qml. * \param vAction - the action * \param vData - the action data */ void GuiView::doActionTransmit(GuiActionType vAction, const QVariant &vData) { // TODO : Remove this code later when Investigated thoroughly. // disabled coco begin validated: This code later needs to be removed when Investigated thoroughly. // has been tested manually QVariantList mData; mData += vData; emit didActionTransmit(vAction, mData); } // disabled coco end /*! * \brief GuiView::doUSBDriveMount * \details emits didUSBDriveMount signal to notify other classes (UI) * , the USB drive has been mounted. */ void GuiView::onUSBDriveMount () { // disabled coco begin validated: This needs user interaction to plug-in USB device // has been tested manually usbIsReady (true ); usbIsRemoved(false); emit didUSBDriveMount (); } // disabled coco end /*! * \brief GuiView::doUSBDriveUmount * \details emits didUSBDriveRemove signal to notify other classes (GuiController) * , the USB drive has been removed. */ void GuiView::doUSBDriveUmount() { // disabled coco begin validated: This needs user interaction to plug-in USB device // has been tested manually usbIsReady (false); usbIsRemoved(false); emit didUSBDriveUmount(); } // disabled coco end /*! * \brief GuiView::doUSBDriveRemove * \details emits didUSBDriveRemove signal to notify other classes (UI) * , the USB drive has been removed. */ void GuiView::onUSBDriveRemove() { // disabled coco begin validated: This needs user interaction to plug-in USB device // has been tested manually usbIsReady (false); usbIsRemoved(true ); emit didUSBDriveRemove(); } // disabled coco end /*! * \brief GuiView::onSDCardStateChange * \details emits didSDCardStateChange signal to notify other classes (UI) * , the SD Card State has been changed. * \param vIsReady - SDCard is Ready * \param vIsReadOnly - SDCard is ReadOnly */ void GuiView::onSDCardStateChange(bool vIsReady, bool vIsReadOnly) { // disabled coco begin validated: This needs user interaction to plug-in USB device // has been tested manually /// DEBUG: qDebug() << " ***** GuiView " << Storage::SDCard_Base_Path_Name << vIsReady; sdIsReady (vIsReady ); sdIsReadOnly(vIsReadOnly); } // disabled coco end /*! * \brief GuiController::doSDCardSpaceTooLow * \details The handler slot for the didSDCardSpaceTooLow signal comes form GuiController. * \param vAvailablePercent - the minimum limit of available storage space */ void GuiView::onSDCardSpaceTooLow(quint8 vAvailablePercent) { // disabled coco begin validated: This needs to fill up the SD-Card and test with human interactions. // has been tested manually sdTooLowPecent(vAvailablePercent); } // disabled coco end /*! * \brief GuiView::onExport * \details The slot which will be called to notify the export is done * by emitting the didExport signal. */ void GuiView::onExport() { emit didExport(); exportRunning(false); } /*! * \brief GuiView::doExportLog * \details emits didExportLog signal to notify other classes (GuiController) * , the User requested to export the log. */ void GuiView::doExportLog() { exportRunning(true); emit didExportLog(); } /*! * \brief GuiView::doExportService * \details emits didExportService signal to notify other classes (GuiController) * , the User requested to export the log. */ void GuiView::doExportService() { exportRunning(true); emit didExportService(); } /*! * \brief GuiView::doExportTreatment * \details emits didExportTreatment signal to notify other classes (GuiController) * , the User requested to export the log. */ void GuiView::doExportTreatment() { exportRunning(true); emit didExportTreatment(); } /*! * \brief GuiView::onSDCardSpaceChange * \details SD Card storage space parameter change slot. * This slot when called is calling the function concurrentRemoveLogs, * if percent of available space vPercent is less than Storage::Available_Space_Percent, * if the SD Card is ready (vReady is true) * \param vReady - The SD Card is Ready * \param vTotal - Total storage space on the SD Card * \param vAvailable - Available storage space on the SD Card * \param vPercent - Percent of available storage space on the SD Card */ void GuiView::onSDCardSpaceChange(bool vReady, qint64 vTotal, qint64 vAvailable, quint8 vPercent) { // disabled coco begin validated: This needs user interaction to change the SD card files system. // has been tested manually /// DEBUG: qDebug() << vReady << vTotal << vAvailable << vPercent << Storage::Available_Space_Percent; Q_UNUSED(vReady) sdTotal ( vTotal ); sdAvail ( vAvailable ); sdPercent ( vPercent ); sdIsLow ( Storage::Log_Min_Available_Total_Space_IsLow(vPercent) ); } // disabled coco end void GuiView::onUSBSpaceChange(bool vReady, qint64 vTotal, qint64 vAvailable, quint8 vPercent) { // has been tested manually /// DEBUG: qDebug() << vReady << vTotal << vAvailable << vPercent << Storage::Available_Space_Percent; usbTotal ( vTotal ); usbAvail ( vAvailable ); usbPercent ( vPercent ); usbIsReady ( vReady ); // TODO : the space check should also be done for the USB as destination but needs calculation has will be done later. // usbIsLow ( vPercent <= Storage::Available_Space_Percent ); }