]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kdirectorycontentscounter.h
9a5e4a86b333f1dbb156a3071abc3c6048d2d6c9
[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
15 class KDirWatch;
16 class KFileItemModel;
17 class QString;
18
19 class KDirectoryContentsCounter : public QObject
20 {
21 Q_OBJECT
22
23 public:
24 enum PathCountPriority { Normal, High };
25
26 explicit KDirectoryContentsCounter(KFileItemModel *model, QObject *parent = nullptr);
27 ~KDirectoryContentsCounter() override;
28
29 /**
30 * Requests the number of items inside the directory \a path. The actual
31 * counting is done asynchronously, and the result is announced via the
32 * signal \a result.
33 *
34 * The directory \a path is watched for changes, and the signal is emitted
35 * again if a change occurs.
36 *
37 * Uses a cache internally to speed up first result,
38 * but emit again result when the cache was updated
39 */
40 void scanDirectory(const QString &path, PathCountPriority priority);
41
42 /**
43 * Stops the work until new input is passed
44 */
45 void stopWorker();
46
47 Q_SIGNALS:
48 /**
49 * Signals that the directory \a path contains \a count items of size \a
50 * Size calculation depends on parameter DetailsModeSettings::recursiveDirectorySizeLimit
51 */
52 void result(const QString &path, int count, long size);
53
54 void requestDirectoryContentsCount(const QString &path, KDirectoryContentsCounterWorker::Options options);
55
56 void stop();
57
58 private Q_SLOTS:
59 void slotResult(const QString &path, int count, long size);
60 void slotDirWatchDirty(const QString &path);
61 void slotItemsRemoved();
62
63 private:
64 KFileItemModel *m_model;
65
66 // Used as FIFO queues.
67 std::list<QString> m_priorityQueue;
68 std::list<QString> m_queue;
69
70 static QThread *m_workerThread;
71
72 KDirectoryContentsCounterWorker *m_worker;
73 bool m_workerIsBusy;
74
75 KDirWatch *m_dirWatcher;
76 QSet<QString> m_watchedDirs; // Required as sadly KDirWatch does not offer a getter method
77 // to get all watched directories.
78 };
79
80 #endif