| 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 | |
| 15 | namespace KIO |
| 16 | { |
| 17 | class DirectorySizeJobPrivate; |
| 18 | /*! |
| 19 | * \class KIO::DirectorySizeJob |
| 20 | * \inheaderfile KIO/DirectorySizeJob |
| 21 | * \inmodule KIOCore |
| 22 | * |
| 23 | * \brief Computes a directory size. |
| 24 | * |
| 25 | * Similar to "du", but doesn't give the same results |
| 26 | * since we simply sum up the dir and file sizes, whereas du speaks disk blocks. |
| 27 | * |
| 28 | * \sa KIO::directorySize. |
| 29 | */ |
| 30 | class KIOCORE_EXPORT DirectorySizeJob : public KIO::Job |
| 31 | { |
| 32 | Q_OBJECT |
| 33 | |
| 34 | public: |
| 35 | ~DirectorySizeJob() override; |
| 36 | |
| 37 | public: |
| 38 | /*! |
| 39 | * Returns the size we found |
| 40 | */ |
| 41 | KIO::filesize_t totalSize() const; |
| 42 | |
| 43 | /*! |
| 44 | * Returns the total number of files (counting symlinks to files, sockets |
| 45 | * and character devices as files) in this directory and all sub-directories |
| 46 | */ |
| 47 | KIO::filesize_t totalFiles() const; |
| 48 | |
| 49 | /*! |
| 50 | * Returns the total number of sub-directories found (not including the |
| 51 | * directory the search started from and treating symlinks to directories |
| 52 | * as directories) |
| 53 | */ |
| 54 | KIO::filesize_t totalSubdirs() const; |
| 55 | |
| 56 | protected Q_SLOTS: |
| 57 | void slotResult(KJob *job) override; |
| 58 | |
| 59 | protected: |
| 60 | KIOCORE_NO_EXPORT explicit DirectorySizeJob(DirectorySizeJobPrivate &dd); |
| 61 | |
| 62 | private: |
| 63 | Q_DECLARE_PRIVATE(DirectorySizeJob) |
| 64 | }; |
| 65 | |
| 66 | /*! |
| 67 | * \relates KIO::DirectorySizeJob |
| 68 | * |
| 69 | * Computes a directory size (by doing a recursive listing). |
| 70 | * Connect to the result signal (this is the preferred solution to avoid blocking the GUI), |
| 71 | * or use exec() for a synchronous (blocking) calculation. |
| 72 | * |
| 73 | * This one lists a single directory. |
| 74 | */ |
| 75 | KIOCORE_EXPORT DirectorySizeJob *directorySize(const QUrl &directory); |
| 76 | |
| 77 | /*! |
| 78 | * \relates KIO::DirectorySizeJob |
| 79 | * |
| 80 | * Computes a directory size (by doing a recursive listing). |
| 81 | * Connect to the result signal (this is the preferred solution to avoid blocking the GUI), |
| 82 | * or use exec() for a synchronous (blocking) calculation. |
| 83 | * |
| 84 | * This one lists the items from \a lstItems. |
| 85 | * The reason we asks for items instead of just urls, is so that |
| 86 | * we directly know if the item is a file or a directory, |
| 87 | * and in case of a file, we already have its size. |
| 88 | */ |
| 89 | KIOCORE_EXPORT DirectorySizeJob *directorySize(const KFileItemList &lstItems); |
| 90 | |
| 91 | } |
| 92 | |
| 93 | #endif |
| 94 | |