ACF $AcfVersion:0$
CFileListProviderComp.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QFileSystemWatcher>
7#include <QtCore/QDir>
8
9// ACF includes
10#include <imod/IModel.h>
15#include <ifile/IFileTypeInfo.h>
16
17
18namespace ifile
19{
20
21
26 public QObject,
28 virtual public ifile::IFileListProvider,
30{
31 Q_OBJECT
32public:
34
35 I_BEGIN_COMPONENT(CFileListProviderComp);
36 I_REGISTER_INTERFACE(istd::IChangeable);
37 I_REGISTER_INTERFACE(ifile::IFileListProvider);
38 I_ASSIGN(m_dirParamCompPtr, "DirParam", "Parameter storing root directory", true, "DirParam");
39 I_ASSIGN_TO(m_dirParamModelCompPtr, m_dirParamCompPtr, false);
40 I_ASSIGN(m_fileTypeInfoCompPtr, "FileTypeInfo", "File type info used to create file filters", false, "FileTypeInfo");
41 I_ASSIGN_MULTI_0(m_filtersAttrPtr, "Filters", "List of filters if no loader is specified", false);
42 I_ASSIGN(m_minRecurDepthAttrPtr, "MinRecurDepth", "Minimal recursion depth for file search", true, 0);
43 I_ASSIGN(m_maxRecurDepthAttrPtr, "MaxRecurDepth", "Maximal recursion depth for file search, negative value means no depth limit", true, 0);
44 I_END_COMPONENT;
45
46 // reimplemented (ifile::IFileListProvider)
47 virtual const QFileInfoList& GetFileList() const override;
48
56 static bool CreateFileList(const QDir& root,
57 int minRecursionDepth,
58 int maxRecursionDepth,
59 const QStringList& nameFilters,
60 QDir::SortFlags sortSpec,
61 QFileInfoList& fileList,
62 istd::ILogger* loggerPtr = NULL);
68 static bool CreateDirectoryList(const QDir& root,
69 int minRecursionDepth,
70 int maxRecursionDepth,
71 const QStringList& nameFilters,
72 QDir::SortFlags sortSpec,
73 QFileInfoList& directoryList,
74 istd::ILogger* loggerPtr = NULL);
75protected:
76 // reimplemented (imod::CSingleModelObserverBase)
77 virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet) override;
78
79 // reimplemented (icomp::CComponentBase)
80 virtual void OnComponentCreated() override;
81 virtual void OnComponentDestroyed() override;
82
83private Q_SLOTS:
84 void OnDirectoryContentChanged(const QString& directoryPath);
85
86private:
87 static void EnumerateDirectory(
88 const QDir& root,
89 int minRecursionDepth,
90 int maxRecursionDepth,
91 const QStringList& nameFilters,
92 QDir::SortFlags sortSpec,
93 QFileInfoList& directoryList);
94
95private:
96 I_REF(ifile::IFileNameParam, m_dirParamCompPtr);
97 I_REF(imod::IModel, m_dirParamModelCompPtr);
98 I_REF(ifile::IFileTypeInfo, m_fileTypeInfoCompPtr);
99 I_MULTIATTR(QString, m_filtersAttrPtr);
100 I_ATTR(int, m_minRecurDepthAttrPtr);
101 I_ATTR(int, m_maxRecurDepthAttrPtr);
102
103 QFileInfoList m_fileList;
104
105 QFileSystemWatcher m_directoryWatcher;
106};
107
108
109} // namespace ifile
110
111
Provide list of file pathes using recursive search of some file directory.
virtual void OnComponentCreated() override
Called when component is created.
virtual void OnComponentDestroyed() override
Called when component is destroyed.
virtual void OnUpdate(const istd::IChangeable::ChangeSet &changeSet) override
Called on update of observed model.
virtual const QFileInfoList & GetFileList() const override
Get list of files.
static bool CreateDirectoryList(const QDir &root, int minRecursionDepth, int maxRecursionDepth, const QStringList &nameFilters, QDir::SortFlags sortSpec, QFileInfoList &directoryList, istd::ILogger *loggerPtr=NULL)
Several filters can be applied to the QDir object before call of this function.
ilog::CLoggerComponentBase BaseClass
static bool CreateFileList(const QDir &root, int minRecursionDepth, int maxRecursionDepth, const QStringList &nameFilters, QDir::SortFlags sortSpec, QFileInfoList &fileList, istd::ILogger *loggerPtr=NULL)
Creates the list of files in a root directory root.
Provide access to a list of files.
Common interface for any file system item name (e.g directory, file or URL path)
Provide loading and saving of objects.
Template wrapper adding comprehensive logging functionality to components.
Basic implementation for a single model observer.
Common interface for model objects, that supports Model/Observer design pattern.
Definition IModel.h:25
Set of change flags (its IDs).
Definition IChangeable.h:36
Common interface for data model objects, which can be changed.
Definition IChangeable.h:28
Common interface for classes sending some log info.
Definition ILogger.h:23
#define NULL
Definition istd.h:74
Contains interfaces and implementations of file system related components.