1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2013 by Frank Reininghaus <frank78ac@googlemail.com> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #ifndef KDIRECTORYCONTENTSCOUNTER_H
22 #define KDIRECTORYCONTENTSCOUNTER_H
24 #include "kdirectorycontentscounterworker.h"
33 class KDirectoryContentsCounter
: public QObject
38 explicit KDirectoryContentsCounter(KFileItemModel
* model
, QObject
* parent
= nullptr);
39 ~KDirectoryContentsCounter() override
;
42 * Requests the number of items inside the directory \a path. The actual
43 * counting is done asynchronously, and the result is announced via the
46 * The directory \a path is watched for changes, and the signal is emitted
47 * again if a change occurs.
49 void addDirectory(const QString
& path
);
52 * In contrast to \a addDirectory, this function counts the items inside
53 * the directory \a path synchronously and returns the result.
55 * The directory is watched for changes, and the signal \a result is
56 * emitted if a change occurs.
58 int countDirectoryContentsSynchronously(const QString
& path
);
62 * Signals that the directory \a path contains \a count items.
64 void result(const QString
& path
, int count
);
66 void requestDirectoryContentsCount(const QString
& path
, KDirectoryContentsCounterWorker::Options options
);
69 void slotResult(const QString
& path
, int count
);
70 void slotDirWatchDirty(const QString
& path
);
71 void slotItemsRemoved();
74 void startWorker(const QString
& path
);
77 KFileItemModel
* m_model
;
79 QQueue
<QString
> m_queue
;
81 static QThread
* m_workerThread
;
82 static int m_workersCount
;
84 KDirectoryContentsCounterWorker
* m_worker
;
87 KDirWatch
* m_dirWatcher
;
88 QSet
<QString
> m_watchedDirs
; // Required as sadly KDirWatch does not offer a getter method
89 // to get all watched directories.