]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kdirectorycontentscounter.h
KDirectoryContentsCounter: don't schedule scanning a folder already in the Queue
[dolphin.git] / src / kitemviews / private / kdirectorycontentscounter.h
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2013 by Frank Reininghaus <frank78ac@googlemail.com> *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20
21 #ifndef KDIRECTORYCONTENTSCOUNTER_H
22 #define KDIRECTORYCONTENTSCOUNTER_H
23
24 #include "kdirectorycontentscounterworker.h"
25
26 #include <QLinkedList>
27 #include <QSet>
28 #include <QHash>
29
30 class KDirWatch;
31 class KFileItemModel;
32 class QString;
33
34 class KDirectoryContentsCounter : public QObject
35 {
36 Q_OBJECT
37
38 public:
39 explicit KDirectoryContentsCounter(KFileItemModel* model, QObject* parent = nullptr);
40 ~KDirectoryContentsCounter() override;
41
42 /**
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
45 * signal \a result.
46 *
47 * The directory \a path is watched for changes, and the signal is emitted
48 * again if a change occurs.
49 *
50 * Uses a cache internally to speed up first result,
51 * but emit again result when the cache was updated
52 */
53 void scanDirectory(const QString& path);
54
55 signals:
56 /**
57 * Signals that the directory \a path contains \a count items of size \a
58 * Size calculation depends on parameter DetailsModeSettings::recursiveDirectorySizeLimit
59 */
60 void result(const QString& path, int count, long size);
61
62 void requestDirectoryContentsCount(const QString& path, KDirectoryContentsCounterWorker::Options options);
63
64 private slots:
65 void slotResult(const QString& path, int count, long size);
66 void slotDirWatchDirty(const QString& path);
67 void slotItemsRemoved();
68
69 private:
70 void startWorker(const QString& path);
71
72 private:
73 KFileItemModel* m_model;
74
75 QLinkedList<QString> m_queue;
76
77 static QThread* m_workerThread;
78
79 KDirectoryContentsCounterWorker* m_worker;
80 bool m_workerIsBusy;
81
82 KDirWatch* m_dirWatcher;
83 QSet<QString> m_watchedDirs; // Required as sadly KDirWatch does not offer a getter method
84 // to get all watched directories.
85 };
86
87 #endif