Index: sources/view/settings/VSDCardFilesModel.cpp =================================================================== diff -u -ra53bdf104b52cae3a49705a4cc8bd886530084c9 -r61f87c52ccba9ce140fd8039915e025b6c790575 --- sources/view/settings/VSDCardFilesModel.cpp (.../VSDCardFilesModel.cpp) (revision a53bdf104b52cae3a49705a4cc8bd886530084c9) +++ sources/view/settings/VSDCardFilesModel.cpp (.../VSDCardFilesModel.cpp) (revision 61f87c52ccba9ce140fd8039915e025b6c790575) @@ -14,13 +14,15 @@ */ // Qt -#include +#include // Project #include "VSDCardFilesModel.h" -#include "WifiInterface.h" #include "Logger.h" +#include "StorageGlobals.h" +#include "DeviceController.h" + using namespace View; VSDCardFilesModel::VSDCardFilesModel(QAbstractListModel *parent) : QAbstractListModel(parent) { @@ -35,83 +37,22 @@ */ void VSDCardFilesModel::initConnections() { - // incoming + connect(&_DeviceController , SIGNAL(didWatchDirectoryChange (const QString &)), + this , SLOT( onWatchDirectoryChange (const QString &))); + // The model gets a total refresh when Logger class emits didRemoveLogs + connect(&_Logger , SIGNAL( didRemoveLogs (bool)), + this , SLOT(onTotalModelRefresh (bool))); } /*! - * \brief VSDCardFilesModel::addSDCardFile - * Adds a network to the network model - * \param network (Network) - the network to add to the model - */ -void VSDCardFilesModel::addSDCardFile(const SDCardFileData &vFileData) -{ - qDebug()<< "adding to SD card list : "<< vFileData.filePath() << "/" << vFileData.fileName(); - beginInsertRows(QModelIndex(), rowCount(), rowCount()); - _sdCardFiles << vFileData; - endInsertRows(); -} - -///*! -// * \brief VNetworkModel::removeRows -// * Removes all rows from the model -// */ -//void VSDCardFilesModel::removeAllRows() -//{ -// beginRemoveRows(QModelIndex(), 0, rowCount()); -// _networks.clear(); -// endRemoveRows(); -//} - -/*! * \brief VSDCardFilesModel::doInit * \details Initializes the view or what needs to be done when for example getting into the WiFi setting screen (do scan for now). */ void VSDCardFilesModel::doInit() { // Do the first population - - // WIP ! - QDir dir("/media/sd-card/log/"); - dir.setFilter(QDir::NoDotAndDotDot | QDir::Files); // not using "| QDir::NoSymLinks" dur to performance - dir.setSorting(QDir::Time); - QStringList listOfFiles = dir.entryList(); - - listOfFiles.append(listOfFiles); - - /******* - * // TODO - * NOTE TO FUTURE VY : TODO -------------------------- - * - * Need a QSortFilterProxyModel that can sort the file list - * - * To get all files in parent and subdir, use QDirIterator with : - * - * QDirIterator it("/etc", QDirIterator::Subdirectories); - * while (it.hasNext()) { .... } - * - * this will give us files from top and subdir, but it does not sort...This is - * where the ProxyModel comes in for sorting. - * - * The result from the QDirIterator will be the "source model". the source model will add/remove - * the added/removed files and the proxymodel will do the automatic sorting/filtering - * - * Need to figure out how to use one model for 3 directories, then use the proxy model to filter based on - * log category this will improve the performance since we are not re-creating the model each time - * - * The exposed model to the QML is the proxyModel. The proxyModel and the abstractlistmodel are both - * derived from the abstractItemModel. - * - * Get this ^^^ to work first and then refactor to re-use in USB - maybe - * - * Need to add a folder/file watcher to the log directories to monitor file add or remove and then update the source model - */ - qDebug()<= _sdCardFiles.count()) - return QVariant(); + if (index.row() < 0 || index.row() >= _sdCardFiles.count()) return QVariant(); const SDCardFileData &sdCardFile = _sdCardFiles[index.row()]; switch (role) { - case FilePathRole: return sdCardFile.filePath(); - case FileNameRole: return sdCardFile.fileName(); - case FileSizeRole: return sdCardFile.fileSize_bytes(); - -// case FilePathRole: return QString("somePath %1").arg(index.column());//sdCardFile.filePath(); -// case FileNameRole: return QString("someFilename %1").arg(index.column());//sdCardFile.fileName(); -// case FileSizeRole: return 150100;//sdCardFile.fileSize_bytes(); - + case FilePathRole: + return sdCardFile.filePath(); + case FileNameRole: + return sdCardFile.fileName(); + case FileSizeRole: + return sdCardFile.fileSize_bytes(); + case FileLogTypeRole : + return sdCardFile.logType(); + case FileModificationDateTimeRole: + return sdCardFile.lastModificationDateTime(); } return QVariant(); @@ -164,34 +106,67 @@ roles[FilePathRole] = "filePath"; roles[FileNameRole] = "fileName"; roles[FileSizeRole] = "fileSize_bytes"; + roles[FileLogTypeRole] = "fileLogType"; + roles[FileModificationDateTimeRole] = "fileModDateTime"; return roles; } /*! - * \brief VSDCardFilesModel::onAddSDCardFile - * Slot that receives a request to add a new file - * \param vFileData - the new sd card file data + * \brief VSDCardFilesModel::timerEvent + * \details The overloaded parent QObject timer event handler function */ -void VSDCardFilesModel::onAddSDCardFile(const SDCardFileData &vFileData) +void VSDCardFilesModel::timerEvent(QTimerEvent *) { - if (!_sdCardFiles.contains(vFileData)) - { - qDebug() < logTypes = Storage::Logger::getLogTypeList(); + foreach(Storage::Logger::LogType type , logTypes) + { + QString folderPath = QString("%1%2").arg(Storage::Log_Folder_Base).arg(_Logger.getPathOfLogType(type)); + + // Add to systemWatcher to update for changes + _DeviceController.doAddDirectoryWatch(folderPath); + + QDirIterator dirIterator(folderPath, QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); + QString absolutePath; + absolutePath = dirIterator.path(); + while(dirIterator.hasNext()) { + absolutePath = dirIterator.next(); + if(!dirIterator.fileName().isEmpty()) + { + //DEBUG: qDebug() << " FOUND " << absolutePath + dirIterator.fileName(); + _sdCardFiles.append(SDCardFileData(type, dirIterator.fileInfo())); + } + } + } }