1 | /*************************************************************************** |
2 | * Copyright (C) 2013 by Frank Reininghaus <frank78ac@googlemail.com> * |
3 | * * |
4 | * This program is free software; you can redistribute it and/or modify * |
5 | * it under the terms of the GNU General Public License as published by * |
6 | * the Free Software Foundation; either version 2 of the License, or * |
7 | * (at your option) any later version. * |
8 | * * |
9 | * This program is distributed in the hope that it will be useful, * |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * GNU General Public License for more details. * |
13 | * * |
14 | * You should have received a copy of the GNU General Public License * |
15 | * along with this program; if not, write to the * |
16 | * Free Software Foundation, Inc., * |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
18 | ***************************************************************************/ |
19 | |
20 | #ifndef KDIRECTORYCONTENTENTSCOUNTERWORKER_H |
21 | #define KDIRECTORYCONTENTENTSCOUNTERWORKER_H |
22 | |
23 | #include <QFlags> |
24 | #include <QMetaType> |
25 | #include <QObject> |
26 | |
27 | class QString; |
28 | |
29 | class KDirectoryContentsCounterWorker : public QObject |
30 | { |
31 | Q_OBJECT |
32 | |
33 | public: |
34 | enum Option { |
35 | NoOptions = 0x0, |
36 | CountHiddenFiles = 0x1, |
37 | CountDirectoriesOnly = 0x2 |
38 | }; |
39 | Q_DECLARE_FLAGS(Options, Option) |
40 | |
41 | explicit KDirectoryContentsCounterWorker(QObject* parent = 0); |
42 | |
43 | /** |
44 | * Counts the items inside the directory \a path using the options |
45 | * \a options. |
46 | * |
47 | * @return The number of items. |
48 | */ |
49 | static int subItemsCount(const QString& path, Options options); |
50 | |
51 | signals: |
52 | /** |
53 | * Signals that the directory \a path contains \a count items. |
54 | */ |
55 | void result(const QString& path, int count); |
56 | |
57 | public slots: |
58 | /** |
59 | * Requests the number of items inside the directory \a path using the |
60 | * options \a options. The result is announced via the signal \a result. |
61 | */ |
62 | // Note that the full type name KDirectoryContentsCounterWorker::Options |
63 | // is needed here. Just using 'Options' is OK for the compiler, but |
64 | // confuses moc. |
65 | void countDirectoryContents(const QString& path, KDirectoryContentsCounterWorker::Options options); |
66 | }; |
67 | |
68 | Q_DECLARE_METATYPE(KDirectoryContentsCounterWorker::Options) |
69 | Q_DECLARE_OPERATORS_FOR_FLAGS(KDirectoryContentsCounterWorker::Options) |
70 | |
71 | #endif |
72 | |