File indexing completed on 2024-05-12 05:47:29
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Frank Reininghaus <frank78ac@googlemail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KDIRECTORYCONTENTSCOUNTERWORKER_H 0008 #define KDIRECTORYCONTENTSCOUNTERWORKER_H 0009 0010 #include <QMetaType> 0011 #include <QObject> 0012 0013 class QString; 0014 0015 class KDirectoryContentsCounterWorker : public QObject 0016 { 0017 Q_OBJECT 0018 0019 public: 0020 enum Option { NoOptions = 0x0, CountHiddenFiles = 0x1 }; 0021 Q_DECLARE_FLAGS(Options, Option) 0022 0023 explicit KDirectoryContentsCounterWorker(QObject *parent = nullptr); 0024 0025 bool stopping() const; 0026 QString scannedPath() const; 0027 Q_SIGNALS: 0028 /** 0029 * Signals that the directory \a path contains \a count items and optionally the size of its content. 0030 */ 0031 void result(const QString &path, int count, long long size); 0032 void intermediateResult(const QString &path, int count, long long size); 0033 void finished(); 0034 0035 public Q_SLOTS: 0036 /** 0037 * Requests the number of items inside the directory \a path using the 0038 * options \a options. The result is announced via the signal \a result. 0039 */ 0040 // Note that the full type name KDirectoryContentsCounterWorker::Options 0041 // is needed here. Just using 'Options' is OK for the compiler, but 0042 // confuses moc. 0043 void countDirectoryContents(const QString &path, KDirectoryContentsCounterWorker::Options options, int maxRecursiveLevel); 0044 void stop(); 0045 0046 private: 0047 #ifndef Q_OS_WIN 0048 void walkDir(const QString &dirPath, bool countHiddenFiles, uint allowedRecursiveLevel); 0049 #endif 0050 0051 QString m_scannedPath; 0052 0053 std::atomic<bool> m_stopping = false; 0054 }; 0055 0056 Q_DECLARE_METATYPE(KDirectoryContentsCounterWorker::Options) 0057 Q_DECLARE_OPERATORS_FOR_FLAGS(KDirectoryContentsCounterWorker::Options) 0058 0059 #endif