┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews/private/kdirectorycontentscounter.h
blob: c90925e445d9800a825efe2e95a8f761b2512ea0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 *   SPDX-FileCopyrightText: 2011 Peter Penz <[email protected]>
 *   SPDX-FileCopyrightText: 2013 Frank Reininghaus <[email protected]>
 *
 *   SPDX-License-Identifier: GPL-2.0-or-later
 */

#ifndef KDIRECTORYCONTENTSCOUNTER_H
#define KDIRECTORYCONTENTSCOUNTER_H

#include "kdirectorycontentscounterworker.h"

#include <QSet>
#include <QHash>

class KDirWatch;
class KFileItemModel;
class QString;

class KDirectoryContentsCounter : public QObject
{
    Q_OBJECT

public:
    explicit KDirectoryContentsCounter(KFileItemModel* model, QObject* parent = nullptr);
    ~KDirectoryContentsCounter() override;

    /**
     * Requests the number of items inside the directory \a path. The actual
     * counting is done asynchronously, and the result is announced via the
     * signal \a result.
     *
     * The directory \a path is watched for changes, and the signal is emitted
     * again if a change occurs.
     *
     * Uses a cache internally to speed up first result,
     * but emit again result when the cache was updated
     */
    void scanDirectory(const QString& path);

Q_SIGNALS:
    /**
     * Signals that the directory \a path contains \a count items of size \a
     * Size calculation depends on parameter DetailsModeSettings::recursiveDirectorySizeLimit
     */
    void result(const QString& path, int count, long size);

    void requestDirectoryContentsCount(const QString& path, KDirectoryContentsCounterWorker::Options options);

private Q_SLOTS:
    void slotResult(const QString& path, int count, long size);
    void slotDirWatchDirty(const QString& path);
    void slotItemsRemoved();

private:
    void startWorker(const QString& path);

private:
    KFileItemModel* m_model;

    // Used as FIFO queues.
    std::list<QString> m_priorityQueue;
    std::list<QString> m_queue;

    static QThread* m_workerThread;

    KDirectoryContentsCounterWorker* m_worker;
    bool m_workerIsBusy;

    KDirWatch* m_dirWatcher;
    QSet<QString> m_watchedDirs;    // Required as sadly KDirWatch does not offer a getter method
                                    // to get all watched directories.
};

#endif