/*! * * 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 VSDCardFilesModel.cpp * \author (last) Vy * \date (last) 16-May-2023 * \author (original) Behrouz NematiPour * \date (original) 11-May-2021 * */ // Qt #include // Project #include "VSDCardFilesModel.h" #include "WifiInterface.h" #include "Logger.h" using namespace View; VSDCardFilesModel::VSDCardFilesModel(QAbstractListModel *parent) : QAbstractListModel(parent) { // startTimer(_interval); initConnections(); doInit(); } /*! * \brief VSDCardFilesModel::initConnections * Makes the necessary connections. Called inside VIEW_DEF_CLASS */ void VSDCardFilesModel::initConnections() { // incoming } /*! * \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(); 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(); } return QVariant(); } /*! * \brief VSDCardFilesModel::roleNames * Translates how to access specific properties of the data for QML from the NetworkDataRole enum * \return (QHash) - maps enums to property names */ QHash VSDCardFilesModel::roleNames() const { QHash roles; roles[FilePathRole] = "filePath"; roles[FileNameRole] = "fileName"; roles[FileSizeRole] = "fileSize_bytes"; return roles; } /*! * \brief VSDCardFilesModel::onAddSDCardFile * Slot that receives a request to add a new file * \param vFileData - the new sd card file data */ void VSDCardFilesModel::onAddSDCardFile(const SDCardFileData &vFileData) { if (!_sdCardFiles.contains(vFileData)) { qDebug() <