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