]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kdirectorycontentscounter.h
Fix issues if QT_NO_CAST_FROM_ASCII is defined
[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 ContentDisplaySettings::recursiveDirectorySizeLimit
51 */
52 void result(const QString &path, int count, long long size);
53
54 void requestDirectoryContentsCount(const QString &path, KDirectoryContentsCounterWorker::Options options, int maxRecursiveLevel);
55
56 private Q_SLOTS:
57 void slotResult(const QString &path, int count, long long size);
58 void slotDirWatchDirty(const QString &path);
59 void slotItemsRemoved();
60 void slotDirectoryRefreshing();
61 void scheduleNext();
62
63 private:
64 void enqueuePathScanning(const QString &path, bool alreadyInCache, PathCountPriority priority);
65
66 KFileItemModel *m_model;
67
68 // Used as FIFO queues.
69 std::list<QString> m_priorityQueue;
70 std::list<QString> m_queue;
71
72 bool m_workerIsBusy;
73
74 KDirWatch *m_dirWatcher;
75 QSet<QString> m_watchedDirs; // Required as sadly KDirWatch does not offer a getter method
76 // to get all watched directories.
77 QString m_currentPath;
78 };
79
80 #endif