/*! * * Copyright (c) 2021-2023 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 VLogFileListModel.cpp * \author (last) Vy * \date (last) 10-Aug-2023 * \author (original) Vy * \date (original) 10-Aug-2023 * */ // Qt #include #include // Project #include "VLogFileListModel.h" #include "Logger.h" #include "StorageGlobals.h" #include "DeviceController.h" using namespace View; using namespace Storage; /*! * \brief VLogFileListModel::VLogFileListModel * Constructor of the VLogFileListModel class */ VLogFileListModel::VLogFileListModel(QAbstractListModel *parent) : QAbstractListModel(parent) { initConnections(); } /*! * \brief VLogFileListModel::initConnections * Makes the necessary connections. Called inside VIEW_DEF_CLASS */ void VLogFileListModel::initConnections() { connect(this, SIGNAL( folderChanged(const QString &)), this, SLOT(updateModelWithFolder(const QString &))); connect(this, SIGNAL( includeSubFoldersChanged(bool)), this, SLOT( refreshModel( ))); // Refresh the model when the logger had triggered a log clean up connect(&_Logger , SIGNAL( didRemoveLogs (bool)), this , SLOT( onLogsRemoved (bool))); } /*! * \brief VLogFileListModel::doInit * \details Initializes the view or what needs to be done */ void VLogFileListModel::doInit() { // initialize the model with the logs from type eLogAppED updateFolderWithType(Logger::eLogAppED); } /*! * \brief VLogFileListModel::rowCount * Gets the number of networks * \param parent - (QModelIndex) the parent QModelIndex * \return (int) - the number of networks */ int VLogFileListModel::rowCount(const QModelIndex & parent) const { Q_UNUSED(parent); return _logFiles.count(); } /*! * \brief VLogFileListModel::data * Returns the sd card file properties at the specified index * \param index (QModelIndex) contains the row of data to lookup * \param role - (int) the property index to return. See SDCardFileDataRole * \return (QVariant) - the value for the specified network property */ QVariant VLogFileListModel::data(const QModelIndex & index, int role) const { if (index.row() < 0 || index.row() >= _logFiles.count()) return QVariant(); const QFileInfo &logFile = _logFiles[index.row()]; switch (role) { case FilePathRole: return logFile.filePath(); case FileNameRole: return logFile.fileName(); case FileSizeRole: return logFile.size(); } return QVariant(); } /*! * \brief VLogFileListModel::roleNames * Translates how to access specific properties of the data for QML from the NetworkDataRole enum * \return (QHash) - maps enums to property names */ QHash VLogFileListModel::roleNames() const { QHash roles; roles[FilePathRole] = "filePath"; roles[FileNameRole] = "fileName"; roles[FileSizeRole] = "fileSize"; return roles; } /*! * \brief VLogFileListModel::removeAllRows * Clear the model of all its data */ void VLogFileListModel::removeAllRows() { //DEBUG qDebug()<(vType)); break; default: LOG_DEBUG(QString("SD - updateFolderWithType: Invalid log type index %1").arg(vType)); }; updateModelWithFolder(path); } /*! * \brief VUSBLogFileListModel::VUSBLogFileListModel * \details Constructor of the VUSBLogFileListModel class */ VUSBLogFileListModel::VUSBLogFileListModel(QAbstractListModel *parent) : VLogFileListModel(parent) { // no op } /*! * \brief VUSBLogFileListModel::updateFolderWithType * \details Update the folder path and model based on the passed type of logs (see Logger::LogTypes) * \param vType = the type of logs */ void VUSBLogFileListModel::updateFolderWithType(const int &vType) { QString path = ""; switch (vType) { case Logger::eLogAppED: case Logger::eLogDebug: case Logger::eLogTrtmt: { QString baseName = _Logger.getLogBasePathNames().value(static_cast(vType)); path = QString("%1\%2").arg(Storage::USB_Mount_Point).arg(baseName); break; } default: LOG_DEBUG(QString("USB : updateFolderWithType: Invalid log type index %1").arg(vType)); }; updateModelWithFolder(path); }