File indexing completed on 2024-12-22 04:31:17

0001 #include "folders.h"
0002 
0003 #include <QDebug>
0004 #include <QDir>
0005 #include <QDirIterator>
0006 
0007 #include <MauiKit3/FileBrowsing/fmstatic.h>
0008 
0009 Folders::Folders(QObject *parent)
0010     : MauiList(parent)
0011 {}
0012 
0013 const FMH::MODEL_LIST &Folders::items() const
0014 {
0015     return this->list;
0016 }
0017 
0018 void Folders::setFolders(const QList<QUrl> &folders)
0019 {
0020     if (m_folders == folders)
0021         return;
0022 
0023     m_folders = folders;
0024     Q_EMIT this->foldersChanged();
0025 }
0026 
0027 QList<QUrl> Folders::folders() const
0028 {
0029     return m_folders;
0030 }
0031 
0032 void Folders::refresh()
0033 {
0034     this->setFolders(m_folders);
0035 }
0036 
0037 void Folders::componentComplete()
0038 {
0039     connect (this, &Folders::foldersChanged, this, &Folders::setList);
0040     setList();
0041 }
0042 
0043 void Folders::setList()
0044 {
0045     Q_EMIT this->preListChanged();
0046     this->list.clear();
0047 
0048     for (const auto &folder : (m_folders))
0049     {
0050         auto item = FMStatic::getFileInfoModel(folder);
0051         item[FMH::MODEL_KEY::PREVIEW] = getPreviews(item[FMH::MODEL_KEY::PATH]).join(",");
0052         this->list << item;
0053     }
0054 
0055     Q_EMIT this->postListChanged();
0056     Q_EMIT this->countChanged();
0057 }
0058 
0059 QStringList Folders::getPreviews(const QString &path)
0060 {
0061     QStringList res;
0062     QDir dir(QUrl::fromUserInput(path).toLocalFile());
0063 
0064     qDebug() << "GET PREVIEWS" << path << QUrl::fromUserInput(path).toLocalFile();
0065 
0066     if(!dir.exists())
0067         return res;
0068 
0069     dir.setFilter(QDir::Files);
0070     dir.setSorting(QDir::Time);
0071     dir.setNameFilters(FMStatic::FILTER_LIST[FMStatic::FILTER_TYPE::IMAGE]);
0072 
0073     int i= 0;
0074 
0075     for(const auto &entry : dir.entryInfoList())
0076     {
0077         if(i >= 4)
0078             break;
0079 
0080         res << QUrl::fromLocalFile(entry.filePath()).toString();
0081         i++;
0082     }
0083 
0084     qDebug() << "GET PREVIEWS" << res;
0085 
0086     return res;
0087 }
0088 
0089