]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kdirectorycontentscounter.h
Output of licensedigger + manual cleanup afterwards.
[dolphin.git] / src / kitemviews / private / kdirectorycontentscounter.h
1 /*
2 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2013 Frank Reininghaus <frank78ac@googlemail.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8 #ifndef KDIRECTORYCONTENTSCOUNTER_H
9 #define KDIRECTORYCONTENTSCOUNTER_H
10
11 #include "kdirectorycontentscounterworker.h"
12
13 #include <QSet>
14 #include <QHash>
15
16 class KDirWatch;
17 class KFileItemModel;
18 class QString;
19
20 class KDirectoryContentsCounter : public QObject
21 {
22 Q_OBJECT
23
24 public:
25 explicit KDirectoryContentsCounter(KFileItemModel* model, QObject* parent = nullptr);
26 ~KDirectoryContentsCounter() override;
27
28 /**
29 * Requests the number of items inside the directory \a path. The actual
30 * counting is done asynchronously, and the result is announced via the
31 * signal \a result.
32 *
33 * The directory \a path is watched for changes, and the signal is emitted
34 * again if a change occurs.
35 *
36 * Uses a cache internally to speed up first result,
37 * but emit again result when the cache was updated
38 */
39 void scanDirectory(const QString& path);
40
41 signals:
42 /**
43 * Signals that the directory \a path contains \a count items of size \a
44 * Size calculation depends on parameter DetailsModeSettings::recursiveDirectorySizeLimit
45 */
46 void result(const QString& path, int count, long size);
47
48 void requestDirectoryContentsCount(const QString& path, KDirectoryContentsCounterWorker::Options options);
49
50 private slots:
51 void slotResult(const QString& path, int count, long size);
52 void slotDirWatchDirty(const QString& path);
53 void slotItemsRemoved();
54
55 private:
56 void startWorker(const QString& path);
57
58 private:
59 KFileItemModel* m_model;
60
61 // Used as FIFO queues.
62 std::list<QString> m_priorityQueue;
63 std::list<QString> m_queue;
64
65 static QThread* m_workerThread;
66
67 KDirectoryContentsCounterWorker* m_worker;
68 bool m_workerIsBusy;
69
70 KDirWatch* m_dirWatcher;
71 QSet<QString> m_watchedDirs; // Required as sadly KDirWatch does not offer a getter method
72 // to get all watched directories.
73 };
74
75 #endif