Index: sources/applicationcontroller.cpp =================================================================== diff -u -r3aab84456cfbdc4c4f495975ba9b8968eb844309 -r920342d3f8cb8c29966f2354ebc7d241df23ccf7 --- sources/applicationcontroller.cpp (.../applicationcontroller.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) +++ sources/applicationcontroller.cpp (.../applicationcontroller.cpp) (revision 920342d3f8cb8c29966f2354ebc7d241df23ccf7) @@ -108,7 +108,7 @@ connect(&_GuiController , SIGNAL(didExportLog()), this , SLOT( onExportLog())); - connect(&_Logger , SIGNAL(didExport()), + connect(&_Logger , SIGNAL(didExportLogs()), this , SLOT( onExport())); // ---- Signal/Slots Index: sources/maintimer.h =================================================================== diff -u -r0a2ca0373a422201d5316df8fb891ef38799e3f9 -r920342d3f8cb8c29966f2354ebc7d241df23ccf7 --- sources/maintimer.h (.../maintimer.h) (revision 0a2ca0373a422201d5316df8fb891ef38799e3f9) +++ sources/maintimer.h (.../maintimer.h) (revision 920342d3f8cb8c29966f2354ebc7d241df23ccf7) @@ -39,7 +39,7 @@ void quit(); private: - bool isDateChanged(bool vIncludeTime = true); + bool isDateChanged(bool vIncludeTime = false); signals: void didTimeout(); void didDateChange(); Index: sources/storage/DriveWatcher.cpp =================================================================== diff -u -r3aab84456cfbdc4c4f495975ba9b8968eb844309 -r920342d3f8cb8c29966f2354ebc7d241df23ccf7 --- sources/storage/DriveWatcher.cpp (.../DriveWatcher.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) +++ sources/storage/DriveWatcher.cpp (.../DriveWatcher.cpp) (revision 920342d3f8cb8c29966f2354ebc7d241df23ccf7) @@ -299,7 +299,7 @@ if (ok) { _mounted = true; _removed = false; - LOG_EVENT(tr("USB flash drive %1 has been mounted on %2").arg(vDevice).arg(USB_Mount_Point)); + LOG_DEBUG(QString("USB flash drive %1 has been mounted on %2").arg(vDevice).arg(USB_Mount_Point)); emit didUSBDriveMount(); } else { usbError(vDevice); @@ -323,7 +323,7 @@ ok = ::umount(vDevice.toLatin1().constData()) == 0; if (ok) { _mounted = false; - LOG_EVENT(tr("USB drive %2 unmounted").arg(vDevice)); + LOG_DEBUG(QString("USB drive %2 unmounted").arg(vDevice)); emit didUSBDriveUmount(); } else { // the error is irrelevant, commented out for now @@ -346,7 +346,7 @@ usbUmount(USB_Mount_Point); _umounted = false; _removed = true; - LOG_EVENT(tr("USB drive removed")); + LOG_DEBUG("USB drive removed"); emit didUSBDriveRemove(); } // coco end Index: sources/storage/filehandler.cpp =================================================================== diff -u -r3aab84456cfbdc4c4f495975ba9b8968eb844309 -r920342d3f8cb8c29966f2354ebc7d241df23ccf7 --- sources/storage/filehandler.cpp (.../filehandler.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) +++ sources/storage/filehandler.cpp (.../filehandler.cpp) (revision 920342d3f8cb8c29966f2354ebc7d241df23ccf7) @@ -99,7 +99,6 @@ QStringList arguments; arguments << "-r" << vSource << vDestination; int result = QProcess::execute(cp, arguments); - return result; } // coco end Index: sources/storage/logger.cpp =================================================================== diff -u -r3aab84456cfbdc4c4f495975ba9b8968eb844309 -r920342d3f8cb8c29966f2354ebc7d241df23ccf7 --- sources/storage/logger.cpp (.../logger.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) +++ sources/storage/logger.cpp (.../logger.cpp) (revision 920342d3f8cb8c29966f2354ebc7d241df23ccf7) @@ -99,18 +99,18 @@ */ void Logger::initConnections() { - connect(&_exportWatcher, SIGNAL(finished()), - this , SLOT(onExport())); + connect(&_exportLogsWatcher, SIGNAL(finished ()), + this , SLOT(onExportLogs())); connect(this, SIGNAL(didLog(QString,LogType)), this, SLOT( onLog(QString,LogType))); - connect(&_MainTimer, SIGNAL( didDateChange ()), - this , SLOT( concurrentRemoveOldLogs())); + connect(&_MainTimer, SIGNAL( didDateChange ()), + this , SLOT( concurrentRemoveLogs())); - connect(&_removeOldLogsWatcher, SIGNAL(finished ()), - this , SLOT(onRemoveOldLogs())); + connect(&_removeLogsWatcher, SIGNAL(finished ()), + this , SLOT(onRemoveLogs())); connect(&_DriveWatcher, SIGNAL( didSDCardSpaceChange(bool, qint64, qint64, quint8)), this , SLOT( onSDCardSpaceChange(bool, qint64, qint64, quint8))); @@ -276,81 +276,116 @@ } } + +bool Logger::exportLogs() +{ + int result = 0; + static QString mOSource; + QString mDestination = USB_Mount_Point; + for ( const auto &iType : { eLogEvent , eLogDatum } ) { + QString mCSource = _logPathNames[iType]; + if (mOSource != mCSource) { + mOSource = mCSource; + // Copy Folder + result = FileHandler::copyFolder( mCSource, mDestination); + } + } + mOSource = ""; + return result >= 0; // refer to QProcess::execute(hit F1 on execute) doc. +} + /*! - * \brief Logger::concurrentExport + * \brief Logger::concurrentExportLogs * \details Exports the log files from log folder (Storage::Log_Base_Path_Name_Location) * into USB drive folder (Storage::USB_Mount_Point) * \return always returns true for now. * \note This method uses QtConcurrent run to execute the FileHandler copyFolder method. */ -bool Logger::concurrentExport() +bool Logger::concurrentExportLogs() { // coco begin validated: This needs user interaction to export to USB device // has been tested manually - QString mSource = SDCard_Base_Path_Name; - QString mDestination = USB_Mount_Point; - QFuture future = QtConcurrent::run(&FileHandler::copyFolder, mSource, mDestination); - _exportWatcher.setFuture(future); - return true; + LOG_DEBUG("Export Logs Start"); + QFuture future = QtConcurrent::run(this, &Logger::exportLogs); + _exportLogsWatcher.setFuture(future); + return true; } // coco end -void Logger::onExport() +void Logger::onExportLogs() { // coco begin validated: This needs user interaction to export to USB device // has been tested manually - emit didExport(); + LOG_DEBUG(QString("Export Logs Ended: %1").arg(_exportLogsWatcher.result())); + emit didExportLogs(); } // coco end /*! - * \brief Logger::removeOldLogs + * \brief Logger::removeLogs * \details Remove old logs by iterating in the log/service folders and look for expired logs. * \return count file(s) have been removed. */ -int Logger::removeOldLogs() +int Logger::removeLogs() { // coco begin validated: This needs user interaction to check the old files deleted // has been tested manually - QStringList mLogFileFilter ; - QDate mOlderThan ; - for (int iType = 0; iType < eLogType_Count; iType++) { - LogType logType = static_cast(iType); - mLogFileFilter = Format::toStringList(_logFileNameExt .values(logType), true, "*"); - mOlderThan = QDate().currentDate().addDays( _logTypeExpiryDay.value(logType) * -1 ); - FileHandler::removeFiles({_logPathNames[logType]}, mLogFileFilter, mOlderThan); + static QString mOSource; + int countRemoved = 0; + QStringList mLogFileFilter; + QDate mOlderThan ; + for ( const auto &iType : { eLogEvent , eLogDatum , eLogDebug } ) { + QString mCSource = _logPathNames[iType]; + if (mOSource != mCSource) { + mOSource = mCSource; + // Remove Logs + if (_logTypeExpiryDay.value(iType)) { + mOlderThan = QDate().currentDate().addDays( _logTypeExpiryDay.value(iType) * -1 /*Please Notice (-1)*/ ); + mLogFileFilter = Format::toStringList(_logFileNameExt .values(iType), true, "*"); + LOG_DEBUG(QString("Removing logs older than %1 from folder %2").arg(mOlderThan.toString("yyyy-MM-dd")).arg(mCSource)); + countRemoved += FileHandler::removeFiles({ mCSource }, mLogFileFilter, mOlderThan); + } + else { + LOG_DEBUG("Current day logs cannot be deletet"); + } + } } - - return true; + mOSource = ""; + return countRemoved; } // coco end /*! - * \brief Logger::concurrentRemoveOldLogs + * \brief Logger::concurrentRemoveLogs * \details * * \return always returns true for now. * \note This method uses QtConcurrent run to execute the FileHandler copyFolder method. */ -bool Logger::concurrentRemoveOldLogs() +bool Logger::concurrentRemoveLogs() { // coco begin validated: This needs user interaction to check the old files deleted // has been tested manually - QFuture mFuture = QtConcurrent::run(this,&Logger::removeOldLogs); - _removeOldLogsWatcher.setFuture(mFuture); - return true; + LOG_DEBUG("Remove Logs Start"); + QFuture mFuture = QtConcurrent::run(this,&Logger::removeLogs); + _removeLogsWatcher.setFuture(mFuture); + return true; } // coco end -void Logger::onRemoveOldLogs() +void Logger::onRemoveLogs() { // coco begin validated: This needs user interaction to export to USB device // has been tested manually - emit didRemoveOldLogs(); + LOG_DEBUG(QString("Remove Logs Ended: %1").arg(_removeLogsWatcher.result())); + emit didRemoveLogs(); } void Logger::onSDCardSpaceChange(bool vReady, qint64 vTotal, qint64 vAvailable, quint8 vPercent) { + if (vPercent > 10 ) { + concurrentRemoveLogs(); + } qDebug() << vReady << vTotal << vAvailable << vPercent; } // coco end Index: sources/storage/logger.h =================================================================== diff -u -r3aab84456cfbdc4c4f495975ba9b8968eb844309 -r920342d3f8cb8c29966f2354ebc7d241df23ccf7 --- sources/storage/logger.h (.../logger.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) +++ sources/storage/logger.h (.../logger.h) (revision 920342d3f8cb8c29966f2354ebc7d241df23ccf7) @@ -26,7 +26,7 @@ // Define #define _Logger Storage::Logger::I() -#define LOG_EXPORT _Logger.concurrentExport() +#define LOG_EXPORT _Logger.concurrentExportLogs() #define LOG_DEBUG(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogDebug) @@ -107,8 +107,8 @@ QString _logFileName = ""; - QFutureWatcher _exportWatcher; - QFutureWatcher _removeOldLogsWatcher; + QFutureWatcher _exportLogsWatcher; + QFutureWatcher _removeLogsWatcher; QThread *_thread = nullptr; bool _init = false; @@ -137,25 +137,24 @@ bool setLogPath (LogType vLogType); // ----- Export structure -public slots: - bool concurrentExport(); -private slots: - void onExport(); +private : + bool exportLogs(); +public slots: // this slot is thread safe and can be called from outside by LOG_EXPORT. + bool concurrentExportLogs(); + void onExportLogs(); signals: - /*! - * \brief didExport - * \details notifies the UI when the export is done. - */ - void didExport(); + void didExportLogs(); // ----- Remove Old Logs structure private: - int removeOldLogs(); -private slots: - bool concurrentRemoveOldLogs(); - void onRemoveOldLogs(); + int removeLogs(); +private slots: // this slot is thread safe and can be called from outside but preffered not to. + bool concurrentRemoveLogs(); + void onRemoveLogs(); signals: - void didRemoveOldLogs(); + void didRemoveLogs(); + +// ----- Available space is low private slots: void onSDCardSpaceChange(bool vReady, qint64 vTotal, qint64 vAvailable, quint8 vPercent);