File indexing completed on 2024-05-12 05:47:29
0001 /* 0002 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com> 0003 * SPDX-FileCopyrightText: 2013 Frank Reininghaus <frank78ac@googlemail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef KDIRECTORYCONTENTSCOUNTER_H 0009 #define KDIRECTORYCONTENTSCOUNTER_H 0010 0011 #include "kdirectorycontentscounterworker.h" 0012 0013 #include <QSet> 0014 0015 class KDirWatch; 0016 class KFileItemModel; 0017 class QString; 0018 0019 class KDirectoryContentsCounter : public QObject 0020 { 0021 Q_OBJECT 0022 0023 public: 0024 enum PathCountPriority { Normal, High }; 0025 0026 explicit KDirectoryContentsCounter(KFileItemModel *model, QObject *parent = nullptr); 0027 ~KDirectoryContentsCounter() override; 0028 0029 /** 0030 * Requests the number of items inside the directory \a path. The actual 0031 * counting is done asynchronously, and the result is announced via the 0032 * signal \a result. 0033 * 0034 * The directory \a path is watched for changes, and the signal is emitted 0035 * again if a change occurs. 0036 * 0037 * Uses a cache internally to speed up first result, 0038 * but emit again result when the cache was updated 0039 */ 0040 void scanDirectory(const QString &path, PathCountPriority priority); 0041 0042 /** 0043 * Stops the work until new input is passed 0044 */ 0045 void stopWorker(); 0046 0047 Q_SIGNALS: 0048 /** 0049 * Signals that the directory \a path contains \a count items of size \a 0050 * Size calculation depends on parameter ContentDisplaySettings::recursiveDirectorySizeLimit 0051 */ 0052 void result(const QString &path, int count, long long size); 0053 0054 void requestDirectoryContentsCount(const QString &path, KDirectoryContentsCounterWorker::Options options, int maxRecursiveLevel); 0055 0056 private Q_SLOTS: 0057 void slotResult(const QString &path, int count, long long size); 0058 void slotDirWatchDirty(const QString &path); 0059 void slotItemsRemoved(); 0060 void slotDirectoryRefreshing(); 0061 void scheduleNext(); 0062 0063 private: 0064 void enqueuePathScanning(const QString &path, bool alreadyInCache, PathCountPriority priority); 0065 0066 KFileItemModel *m_model; 0067 0068 // Used as FIFO queues. 0069 std::list<QString> m_priorityQueue; 0070 std::list<QString> m_queue; 0071 0072 bool m_workerIsBusy; 0073 0074 KDirWatch *m_dirWatcher; 0075 QSet<QString> m_watchedDirs; // Required as sadly KDirWatch does not offer a getter method 0076 // to get all watched directories. 0077 QString m_currentPath; 0078 }; 0079 0080 #endif