Index: sources/storage/TreatmentLog.cpp =================================================================== diff -u -rc9f8f8cf3c6c37fc6460d8675c62c9442c4d4263 -r6210028a421d6259963bf172efbe4f23abfecf2f --- sources/storage/TreatmentLog.cpp (.../TreatmentLog.cpp) (revision c9f8f8cf3c6c37fc6460d8675c62c9442c4d4263) +++ sources/storage/TreatmentLog.cpp (.../TreatmentLog.cpp) (revision 6210028a421d6259963bf172efbe4f23abfecf2f) @@ -34,6 +34,7 @@ #define ADDTITLE(vTITLE) logContent += QString("[%1]\n").arg(vTITLE) #define ADDALINE(vTEXT ) logContent += QString("%1\n" ).arg(vTEXT ) #define ADDTOLOG(vINDEX) index = vINDEX; logContent += title(index) + sep + value(index) + sep + unit(index) + "\n"; + /*! * \brief TreatmentLog::TreatmentLog * The constructor to initial the Treatment Log @@ -173,7 +174,12 @@ else { _treatmentLogPath = vLogPath; } - LOG_DEBUG(QString("Treatment log folder has been set to %1").arg(_treatmentLogPath)); + _treatmentLogPath_Pending = QString("%1%2") + .arg(Storage::SDCard_Base_Path_Name) + .arg(Storage::Log_Folder_Pending ); + + LOG_DEBUG(QString("Treatment log folder has been set to %1" ).arg(_treatmentLogPath )); + LOG_DEBUG(QString("Treatment log pending folder has been set to %1" ).arg(_treatmentLogPath_Pending )); } } @@ -218,7 +224,7 @@ QString end = "%1" ; uint index = 0 ; - ADDTITLE("Title"); + // ADDTITLE("Title"); // will be added with Tx Code when gets out of pending, by receiving the Tx Code from CloudSync ADDTOLOG( ePatientID ); ADDTITLE("Treatment Parameters" ); @@ -304,12 +310,12 @@ _lastTxInfo.mDeviceID = _deviceID; _lastTxInfo.mPatientID = _values[ePatientID]; _lastTxInfo.mFileName = QString("%1%2_%3.log") - .arg(_treatmentLogPath) + .arg(_treatmentLogPath_Pending) .arg(_lastTxInfo.mDateTime) .arg(_lastTxInfo.mDeviceID); - ok = Storage::FileHandler::makeFolder(_treatmentLogPath); - if ( ! ok ) { LOG_DEBUG(QString("Cannot create folder %1").arg(_treatmentLogPath)); return ok; } + ok = Storage::FileHandler::makeFolder(_treatmentLogPath_Pending); + if ( ! ok ) { LOG_DEBUG(QString("Cannot create folder %1").arg(_treatmentLogPath_Pending)); return ok; } ok = Storage::FileHandler::write(_lastTxInfo.mFileName, logContent, false); if ( ! ok ) { LOG_DEBUG(QString("Cannot write to file %1").arg(_lastTxInfo.mFileName)); return ok; } _treatmentLogAvrgeData.clear(); @@ -409,5 +415,40 @@ void TreatmentLog::onTxCodeReceive(const QString &vTxCode) { _txCode = vTxCode; + addTxCode(); emit didTxCodeReceive(_txCode); } + +/*! + * \brief TreatmentLog::addTxCode + * \details Adds the [Title] and Tx Code to the file and moves it from pending. + * \return true on success, false on any case of read, write, remove. + */ +bool TreatmentLog::addTxCode() +{ + bool ok = true; + QString src = _lastTxInfo.mFileName; + QString dst = _treatmentLogPath + QFileInfo(src).fileName(); + QString logContent; + ADDTITLE("Title"); + ADDALINE(QString("Tx Code,%1,").arg(_txCode)); + + ok = FileHandler::read (src, logContent, true ); // reads the file and appends the content to logContent + if ( ! ok ) { + LOG_DEBUG(QString("Couldn't read pending treatment log file '%1'").arg(src)); + return ok; + } + + ok = FileHandler::write (dst, logContent ); + if ( ! ok ) { + LOG_DEBUG(QString("Couldn't settle pending treatment log file '%1'").arg(src)); + return ok; + } + + QFile::remove(src); + if ( ! ok ) { + LOG_DEBUG(QString("Couldn't remove pending treatment log file '%1'").arg(src)); + return ok; + } + return ok; +}