]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kdirectorycontentscounterworker.h
5266960cd39f88438de177d4bf258de45a835d27
[dolphin.git] / src / kitemviews / private / kdirectorycontentscounterworker.h
1 /*
2 * SPDX-FileCopyrightText: 2013 Frank Reininghaus <frank78ac@googlemail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef KDIRECTORYCONTENTSCOUNTERWORKER_H
8 #define KDIRECTORYCONTENTSCOUNTERWORKER_H
9
10 #include <QMetaType>
11 #include <QObject>
12
13 class QString;
14
15 class KDirectoryContentsCounterWorker : public QObject
16 {
17 Q_OBJECT
18
19 public:
20 enum Option { NoOptions = 0x0, CountHiddenFiles = 0x1, CountDirectoriesOnly = 0x2 };
21 Q_DECLARE_FLAGS(Options, Option)
22
23 struct CountResult {
24 /// number of elements in the directory
25 int count;
26 /// Recursive sum of the size of the directory content files and folders
27 /// Calculation depends on DetailsModeSettings::recursiveDirectorySizeLimit
28 long size;
29 };
30
31 explicit KDirectoryContentsCounterWorker(QObject *parent = nullptr);
32
33 /**
34 * Counts the items inside the directory \a path using the options
35 * \a options.
36 *
37 * @return The number of items.
38 */
39 CountResult subItemsCount(const QString &path, Options options);
40
41 Q_SIGNALS:
42 /**
43 * Signals that the directory \a path contains \a count items and optionally the size of its content.
44 */
45 void result(const QString &path, int count, long size);
46
47 public Q_SLOTS:
48 /**
49 * Requests the number of items inside the directory \a path using the
50 * options \a options. The result is announced via the signal \a result.
51 */
52 // Note that the full type name KDirectoryContentsCounterWorker::Options
53 // is needed here. Just using 'Options' is OK for the compiler, but
54 // confuses moc.
55 void countDirectoryContents(const QString &path, KDirectoryContentsCounterWorker::Options options);
56 void stop();
57
58 private:
59 #ifndef Q_OS_WIN
60 KDirectoryContentsCounterWorker::CountResult
61 walkDir(const QString &dirPath, const bool countHiddenFiles, const bool countDirectoriesOnly, const uint allowedRecursiveLevel);
62 #endif
63
64 bool m_stopping = false;
65 };
66
67 Q_DECLARE_METATYPE(KDirectoryContentsCounterWorker::Options)
68 Q_DECLARE_OPERATORS_FOR_FLAGS(KDirectoryContentsCounterWorker::Options)
69
70 #endif