]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kdirectorycontentscounter.h
Port away from QLinkedList
[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 <QSet>
27 #include <QHash>
28
29 class KDirWatch;
30 class KFileItemModel;
31 class QString;
32
33 class KDirectoryContentsCounter : public QObject
34 {
35 Q_OBJECT
36
37 public:
38 explicit KDirectoryContentsCounter(KFileItemModel* model, QObject* parent = nullptr);
39 ~KDirectoryContentsCounter() override;
40
41 /**
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
44 * signal \a result.
45 *
46 * The directory \a path is watched for changes, and the signal is emitted
47 * again if a change occurs.
48 *
49 * Uses a cache internally to speed up first result,
50 * but emit again result when the cache was updated
51 */
52 void scanDirectory(const QString& path);
53
54 signals:
55 /**
56 * Signals that the directory \a path contains \a count items of size \a
57 * Size calculation depends on parameter DetailsModeSettings::recursiveDirectorySizeLimit
58 */
59 void result(const QString& path, int count, long size);
60
61 void requestDirectoryContentsCount(const QString& path, KDirectoryContentsCounterWorker::Options options);
62
63 private slots:
64 void slotResult(const QString& path, int count, long size);
65 void slotDirWatchDirty(const QString& path);
66 void slotItemsRemoved();
67
68 private:
69 void startWorker(const QString& path);
70
71 private:
72 KFileItemModel* m_model;
73
74 // Used as FIFO queues.
75 std::list<QString> m_priorityQueue;
76 std::list<QString> m_queue;
77
78 static QThread* m_workerThread;
79
80 KDirectoryContentsCounterWorker* m_worker;
81 bool m_workerIsBusy;
82
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.
86 };
87
88 #endif