File indexing completed on 2024-04-21 07:41:55

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2000, 2006 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef DIRECTORYSIZEJOB_H
0009 #define DIRECTORYSIZEJOB_H
0010 
0011 #include "job_base.h"
0012 #include "kiocore_export.h"
0013 #include <kfileitem.h>
0014 
0015 namespace KIO
0016 {
0017 class DirectorySizeJobPrivate;
0018 /**
0019  * @class KIO::DirectorySizeJob directorysizejob.h <KIO/DirectorySizeJob>
0020  *
0021  * Computes a directory size (similar to "du", but doesn't give the same results
0022  * since we simply sum up the dir and file sizes, whereas du speaks disk blocks)
0023  *
0024  * Usage: see KIO::directorySize.
0025  */
0026 class KIOCORE_EXPORT DirectorySizeJob : public KIO::Job
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     ~DirectorySizeJob() override;
0032 
0033 public:
0034     /**
0035      * @return the size we found
0036      */
0037     KIO::filesize_t totalSize() const;
0038 
0039     /**
0040      * @return the total number of files (counting symlinks to files, sockets
0041      * and character devices as files) in this directory and all sub-directories
0042      */
0043     KIO::filesize_t totalFiles() const;
0044 
0045     /**
0046      * @return the total number of sub-directories found (not including the
0047      * directory the search started from and treating symlinks to directories
0048      * as directories)
0049      */
0050     KIO::filesize_t totalSubdirs() const;
0051 
0052 protected Q_SLOTS:
0053     void slotResult(KJob *job) override;
0054 
0055 protected:
0056     KIOCORE_NO_EXPORT explicit DirectorySizeJob(DirectorySizeJobPrivate &dd);
0057 
0058 private:
0059     Q_DECLARE_PRIVATE(DirectorySizeJob)
0060 };
0061 
0062 /**
0063  * Computes a directory size (by doing a recursive listing).
0064  * Connect to the result signal (this is the preferred solution to avoid blocking the GUI),
0065  * or use exec() for a synchronous (blocking) calculation.
0066  *
0067  * This one lists a single directory.
0068  */
0069 KIOCORE_EXPORT DirectorySizeJob *directorySize(const QUrl &directory);
0070 
0071 /**
0072  * Computes a directory size (by doing a recursive listing).
0073  * Connect to the result signal (this is the preferred solution to avoid blocking the GUI),
0074  * or use exec() for a synchronous (blocking) calculation.
0075  *
0076  * This one lists the items from @p lstItems.
0077  * The reason we asks for items instead of just urls, is so that
0078  * we directly know if the item is a file or a directory,
0079  * and in case of a file, we already have its size.
0080  */
0081 KIOCORE_EXPORT DirectorySizeJob *directorySize(const KFileItemList &lstItems);
0082 
0083 }
0084 
0085 #endif