Index: sources/device/DeviceController.cpp =================================================================== diff -u -r3e64d98e243484505a44d99b13826097cb6b01eb -r9ae3b0d6624904693329309aaf8ff02784c17184 --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 3e64d98e243484505a44d99b13826097cb6b01eb) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 9ae3b0d6624904693329309aaf8ff02784c17184) @@ -43,6 +43,7 @@ * Qt handles the children destruction by their parent objects life-cycle. */ DeviceController::DeviceController(QObject *parent) : QObject(parent) { + _fileSystemWatcher.setParent(this); DEVICE_DEV_PARENT_LIST } @@ -114,6 +115,9 @@ connect(this , SIGNAL(didScreenshot(const QImage &, const QString &)), this , SLOT( onScreenshot(const QImage &, const QString &))); + connect(&_fileSystemWatcher , SIGNAL( fileChanged(QString)), + this , SLOT( onWatchFileChanged(QString))); + DEVICE_DEV_INIT_CONNECTIONS_LIST } @@ -423,10 +427,10 @@ bool DeviceController::checkError(DeviceError::Scripts_Error_Enum vError, TModel &vModel, QString vExtraLogInfo) { if ( vError ) { - QString src = (vError > DeviceError::eScripts_Error_Start ? MAbstract::unitText(MAbstract::Unit_Enum::eUI) : MAbstract::unitText(MAbstract::Unit_Enum::eDV)) + ","; + QString src = (vError > DeviceError::eDevice_Scripts_Error_Start ? MAbstract::unitText(MAbstract::Unit_Enum::eUI) : MAbstract::unitText(MAbstract::Unit_Enum::eDV)) + ","; vModel._data.mAccepted = false ; vModel._data.mReason = vError ; - vModel._data.mMessage = DeviceError::scriptErrorText(vError) + QString(" [%1]").arg(vError); + vModel._data.mMessage = DeviceError::deviceErrorText(vError) + QString(" [%1]").arg(vError); LOG_EVENT(src + vModel._data.mMessage + " " + vExtraLogInfo); emit didAttributeResponse(vModel._data); return true; @@ -456,14 +460,14 @@ // ----- check if the process is not running if ( _processBrightness.state() != QProcess::NotRunning ) { - checkError(DeviceError::eScripts_Error_IsRunning, _deviceBrightnessResponse); + checkError(DeviceError::eDevice_Scripts_Error_IsRunning, _deviceBrightnessResponse); return; } // ----- check the data is valid // TODO : this should be in the model if ( _deviceBrightnessRequest.mBrightness_min > _deviceBrightnessRequest._data.mBrightness_val || _deviceBrightnessRequest._data.mBrightness_val > _deviceBrightnessRequest.mBrightness_max ) { - checkError(DeviceError::eScripts_Error_OutOfRange, _deviceBrightnessResponse); + checkError(DeviceError::eDevice_Scripts_Error_OutOfRange, _deviceBrightnessResponse); return; } @@ -474,7 +478,7 @@ for ( quint8 i = _deviceBrightnessRequest.mBrightness_min; i <= _deviceBrightnessRequest.mBrightness_max; i += _deviceBrightnessRequest.mBrightness_res ) _allowableValues += i; // check the value is in the list if ( ! _allowableValues.contains(_deviceBrightnessRequest._data.mBrightness_val) ) { - checkError(DeviceError::eScripts_Error_Incorrect_Req, _deviceBrightnessResponse); + checkError(DeviceError::eDevice_Scripts_Error_Incorrect_Req, _deviceBrightnessResponse); return; } @@ -504,7 +508,7 @@ _deviceBrightnessResponse._data.mBrightnessPercent = brightness * 10; } else { - checkError(DeviceError::eScripts_Error_Incorrect_Rsp,_deviceBrightnessResponse, _deviceBrightnessResponse.toString()); + checkError(DeviceError::eDevice_Scripts_Error_Incorrect_Rsp,_deviceBrightnessResponse, _deviceBrightnessResponse.toString()); return; } } @@ -536,3 +540,31 @@ vImage.save(vFileName); LOG_DEBUG("Screenshot saved in " + vFileName); } + +/*! + * \brief DeviceController::ondoAddWatch + * \details The thread safe add file watch method + * \param vFile - The file to add to watch. + */ +void DeviceController::ondoAddWatch(const QString &vFile) +{ + if ( ! QFileInfo::exists(vFile)) { + if ( ! FileHandler::write(vFile, "", false) ) { + LOG_DEBUG(DeviceError::deviceErrorText(DeviceError::eDevice_Watch_Error_NotFound)); + return; + } + } + if ( ! _fileSystemWatcher.addPath(vFile) ) { + LOG_DEBUG(DeviceError::deviceErrorText(DeviceError::eDevice_Watch_Error_NotAdded)); + } +} + +/*! + * \brief DeviceController::onWatchFileChanged + * \details This slot is called once the files being watched is updated. + * \param vFile - the file name. + */ +void DeviceController::onWatchFileChanged(const QString &vFile) +{ + emit didWatchFileChange(vFile); +}