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"
26 #include <QLinkedList>
34 class KDirectoryContentsCounter
: public QObject
39 explicit KDirectoryContentsCounter(KFileItemModel
* model
, QObject
* parent
= nullptr);
40 ~KDirectoryContentsCounter() override
;
43 * Requests the number of items inside the directory \a path. The actual
44 * counting is done asynchronously, and the result is announced via the
47 * The directory \a path is watched for changes, and the signal is emitted
48 * again if a change occurs.
50 * Uses a cache internally to speed up first result,
51 * but emit again result when the cache was updated
53 void scanDirectory(const QString
& path
);
57 * Signals that the directory \a path contains \a count items of size \a
58 * Size calculation depends on parameter DetailsModeSettings::recursiveDirectorySizeLimit
60 void result(const QString
& path
, int count
, long size
);
62 void requestDirectoryContentsCount(const QString
& path
, KDirectoryContentsCounterWorker::Options options
);
65 void slotResult(const QString
& path
, int count
, long size
);
66 void slotDirWatchDirty(const QString
& path
);
67 void slotItemsRemoved();
70 void startWorker(const QString
& path
);
73 KFileItemModel
* m_model
;
75 QLinkedList
<QString
> m_priorityQueue
;
76 QLinkedList
<QString
> m_queue
;
78 static QThread
* m_workerThread
;
80 KDirectoryContentsCounterWorker
* m_worker
;
83 KDirWatch
* m_dirWatcher
;
84 QSet
<QString
> m_watchedDirs
; // Required as sadly KDirWatch does not offer a getter method
85 // to get all watched directories.