Changeset View
Changeset View
Standalone View
Standalone View
src/kitemviews/private/kdirectorycontentscounter.h
Show All 19 Lines | |||||
20 | 20 | | |||
21 | #ifndef KDIRECTORYCONTENTSCOUNTER_H | 21 | #ifndef KDIRECTORYCONTENTSCOUNTER_H | ||
22 | #define KDIRECTORYCONTENTSCOUNTER_H | 22 | #define KDIRECTORYCONTENTSCOUNTER_H | ||
23 | 23 | | |||
24 | #include "kdirectorycontentscounterworker.h" | 24 | #include "kdirectorycontentscounterworker.h" | ||
25 | 25 | | |||
26 | #include <QQueue> | 26 | #include <QQueue> | ||
27 | #include <QSet> | 27 | #include <QSet> | ||
28 | #include <QHash> | ||||
28 | 29 | | |||
29 | class KDirWatch; | 30 | class KDirWatch; | ||
30 | class KFileItemModel; | 31 | class KFileItemModel; | ||
31 | class QString; | 32 | class QString; | ||
32 | 33 | | |||
33 | class KDirectoryContentsCounter : public QObject | 34 | class KDirectoryContentsCounter : public QObject | ||
34 | { | 35 | { | ||
35 | Q_OBJECT | 36 | Q_OBJECT | ||
36 | 37 | | |||
37 | public: | 38 | public: | ||
38 | explicit KDirectoryContentsCounter(KFileItemModel* model, QObject* parent = nullptr); | 39 | explicit KDirectoryContentsCounter(KFileItemModel* model, QObject* parent = nullptr); | ||
39 | ~KDirectoryContentsCounter() override; | 40 | ~KDirectoryContentsCounter() override; | ||
40 | 41 | | |||
41 | /** | 42 | /** | ||
42 | * Requests the number of items inside the directory \a path. The actual | 43 | * Requests the number of items inside the directory \a path. The actual | ||
43 | * counting is done asynchronously, and the result is announced via the | 44 | * counting is done asynchronously, and the result is announced via the | ||
44 | * signal \a result. | 45 | * signal \a result. | ||
45 | * | 46 | * | ||
46 | * The directory \a path is watched for changes, and the signal is emitted | 47 | * The directory \a path is watched for changes, and the signal is emitted | ||
47 | * again if a change occurs. | 48 | * again if a change occurs. | ||
48 | */ | | |||
49 | void addDirectory(const QString& path); | | |||
50 | | ||||
51 | /** | | |||
52 | * In contrast to \a addDirectory, this function counts the items inside | | |||
53 | * the directory \a path synchronously and returns the result. | | |||
54 | * | 49 | * | ||
55 | * The directory is watched for changes, and the signal \a result is | 50 | * Uses a cache internally to speed up first result, | ||
56 | * emitted if a change occurs. | 51 | * but emit again result when the cache was updated | ||
57 | */ | 52 | */ | ||
58 | int countDirectoryContentsSynchronously(const QString& path); | 53 | void scanDirectory(const QString& path); | ||
59 | 54 | | |||
60 | signals: | 55 | signals: | ||
61 | /** | 56 | /** | ||
62 | * Signals that the directory \a path contains \a count items. | 57 | * Signals that the directory \a path contains \a count items of size \a | ||
58 | * Size calculation depends on parameter DetailsModeSettings::recursiveDirectorySizeLimit | ||||
63 | */ | 59 | */ | ||
64 | void result(const QString& path, int count); | 60 | void result(const QString& path, int count, long size); | ||
65 | 61 | | |||
66 | void requestDirectoryContentsCount(const QString& path, KDirectoryContentsCounterWorker::Options options); | 62 | void requestDirectoryContentsCount(const QString& path, KDirectoryContentsCounterWorker::Options options); | ||
67 | 63 | | |||
68 | private slots: | 64 | private slots: | ||
69 | void slotResult(const QString& path, int count); | 65 | void slotResult(const QString& path, int count, long size); | ||
70 | void slotDirWatchDirty(const QString& path); | 66 | void slotDirWatchDirty(const QString& path); | ||
71 | void slotItemsRemoved(); | 67 | void slotItemsRemoved(); | ||
72 | 68 | | |||
73 | private: | 69 | private: | ||
74 | void startWorker(const QString& path); | 70 | void startWorker(const QString& path); | ||
75 | 71 | | |||
76 | private: | 72 | private: | ||
77 | KFileItemModel* m_model; | 73 | KFileItemModel* m_model; | ||
78 | 74 | | |||
79 | QQueue<QString> m_queue; | 75 | QQueue<QString> m_queue; | ||
80 | 76 | | |||
81 | static QThread* m_workerThread; | 77 | static QThread* m_workerThread; | ||
82 | static int m_workersCount; | | |||
83 | 78 | | |||
84 | KDirectoryContentsCounterWorker* m_worker; | 79 | KDirectoryContentsCounterWorker* m_worker; | ||
85 | bool m_workerIsBusy; | 80 | bool m_workerIsBusy; | ||
86 | 81 | | |||
87 | KDirWatch* m_dirWatcher; | 82 | KDirWatch* m_dirWatcher; | ||
88 | QSet<QString> m_watchedDirs; // Required as sadly KDirWatch does not offer a getter method | 83 | QSet<QString> m_watchedDirs; // Required as sadly KDirWatch does not offer a getter method | ||
89 | // to get all watched directories. | 84 | // to get all watched directories. | ||
90 | }; | 85 | }; | ||
91 | 86 | | |||
92 | #endif | 87 | #endif |