1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2000, 2006 David Faure <faure@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef DIRECTORYSIZEJOB_H
9#define DIRECTORYSIZEJOB_H
10
11#include "job_base.h"
12#include "kiocore_export.h"
13#include <kfileitem.h>
14
15namespace KIO
16{
17class DirectorySizeJobPrivate;
18/**
19 * @class KIO::DirectorySizeJob directorysizejob.h <KIO/DirectorySizeJob>
20 *
21 * Computes a directory size (similar to "du", but doesn't give the same results
22 * since we simply sum up the dir and file sizes, whereas du speaks disk blocks)
23 *
24 * Usage: see KIO::directorySize.
25 */
26class KIOCORE_EXPORT DirectorySizeJob : public KIO::Job
27{
28 Q_OBJECT
29
30public:
31 ~DirectorySizeJob() override;
32
33public:
34 /**
35 * @return the size we found
36 */
37 KIO::filesize_t totalSize() const;
38
39 /**
40 * @return the total number of files (counting symlinks to files, sockets
41 * and character devices as files) in this directory and all sub-directories
42 */
43 KIO::filesize_t totalFiles() const;
44
45 /**
46 * @return the total number of sub-directories found (not including the
47 * directory the search started from and treating symlinks to directories
48 * as directories)
49 */
50 KIO::filesize_t totalSubdirs() const;
51
52protected Q_SLOTS:
53 void slotResult(KJob *job) override;
54
55protected:
56 KIOCORE_NO_EXPORT explicit DirectorySizeJob(DirectorySizeJobPrivate &dd);
57
58private:
59 Q_DECLARE_PRIVATE(DirectorySizeJob)
60};
61
62/**
63 * Computes a directory size (by doing a recursive listing).
64 * Connect to the result signal (this is the preferred solution to avoid blocking the GUI),
65 * or use exec() for a synchronous (blocking) calculation.
66 *
67 * This one lists a single directory.
68 */
69KIOCORE_EXPORT DirectorySizeJob *directorySize(const QUrl &directory);
70
71/**
72 * Computes a directory size (by doing a recursive listing).
73 * Connect to the result signal (this is the preferred solution to avoid blocking the GUI),
74 * or use exec() for a synchronous (blocking) calculation.
75 *
76 * This one lists the items from @p lstItems.
77 * The reason we asks for items instead of just urls, is so that
78 * we directly know if the item is a file or a directory,
79 * and in case of a file, we already have its size.
80 */
81KIOCORE_EXPORT DirectorySizeJob *directorySize(const KFileItemList &lstItems);
82
83}
84
85#endif
86

source code of kio/src/core/directorysizejob.h