File indexing completed on 2024-10-06 03:39:33

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org>
0004     SPDX-FileCopyrightText: 2000-2009 David Faure <faure@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef KIO_LISTJOB_H
0010 #define KIO_LISTJOB_H
0011 
0012 #include "simplejob.h"
0013 #include <kio/udsentry.h>
0014 
0015 namespace KIO
0016 {
0017 class ListJobPrivate;
0018 /**
0019  * @class KIO::ListJob listjob.h <KIO/ListJob>
0020  *
0021  * A ListJob is allows you to get the get the content of a directory.
0022  * Don't create the job directly, but use KIO::listRecursive() or
0023  * KIO::listDir() instead.
0024  * @see KIO::listRecursive()
0025  * @see KIO::listDir()
0026  */
0027 class KIOCORE_EXPORT ListJob : public SimpleJob
0028 {
0029     Q_OBJECT
0030 
0031 public:
0032     ~ListJob() override;
0033 
0034     enum class ListFlag {
0035         IncludeHidden = 1 << 0, ///< Include hidden files in the listing.
0036     };
0037     Q_DECLARE_FLAGS(ListFlags, ListFlag)
0038 
0039     /**
0040      * Returns the ListJob's redirection URL. This will be invalid if there
0041      * was no redirection.
0042      * @return the redirection url
0043      */
0044     const QUrl &redirectionUrl() const;
0045 
0046     /**
0047      * Do not apply any KIOSK restrictions to this job.
0048      */
0049     void setUnrestricted(bool unrestricted);
0050 
0051 Q_SIGNALS:
0052     /**
0053      * This signal emits the entry found by the job while listing.
0054      * The progress signals aren't specific to ListJob. It simply
0055      * uses SimpleJob's processedSize (number of entries listed) and
0056      * totalSize (total number of entries, if known),
0057      * as well as percent.
0058      * @param job the job that emitted this signal
0059      * @param list the list of UDSEntries
0060      */
0061     void entries(KIO::Job *job, const KIO::UDSEntryList &list); // TODO KDE5: use KIO::ListJob* argument to avoid casting
0062 
0063     /**
0064      * This signal is emitted when a sub-directory could not be listed.
0065      * The job keeps going, thus doesn't result in an overall error.
0066      * @param job the job that emitted the signal
0067      * @param subJob the job listing a sub-directory, which failed. Use
0068      *       url(), error() and errorText() on that job to find
0069      *       out more.
0070      */
0071     void subError(KIO::ListJob *job, KIO::ListJob *subJob);
0072 
0073     /**
0074      * Signals a redirection.
0075      * Use to update the URL shown to the user.
0076      * The redirection itself is handled internally.
0077      * @param job the job that is redirected
0078      * @param url the new url
0079      */
0080     void redirection(KIO::Job *job, const QUrl &url);
0081 
0082     /**
0083      * Signals a permanent redirection.
0084      * The redirection itself is handled internally.
0085      * @param job the job that emitted this signal
0086      * @param fromUrl the original URL
0087      * @param toUrl the new URL
0088      */
0089     void permanentRedirection(KIO::Job *job, const QUrl &fromUrl, const QUrl &toUrl);
0090 
0091 protected Q_SLOTS:
0092     void slotFinished() override;
0093     void slotResult(KJob *job) override;
0094 
0095 protected:
0096     KIOCORE_NO_EXPORT explicit ListJob(ListJobPrivate &dd);
0097 
0098     Q_DECLARE_PRIVATE(ListJob)
0099     friend class ListJobPrivate;
0100 };
0101 
0102 /**
0103  * List the contents of @p url, which is assumed to be a directory.
0104  *
0105  * "." and ".." are returned, filter them out if you don't want them.
0106  *
0107  *
0108  * @param url the url of the directory
0109  * @param flags Can be HideProgressInfo here
0110  * @param includeHidden true for all files, false to cull out UNIX hidden
0111  *                      files/dirs (whose names start with dot)
0112  * @return the job handling the operation.
0113  */
0114 KIOCORE_EXPORT ListJob *listDir(const QUrl &url, JobFlags flags = DefaultFlags, ListJob::ListFlags listFlags = ListJob::ListFlag::IncludeHidden);
0115 
0116 /**
0117  * The same as the previous method, but recurses subdirectories.
0118  * Directory links are not followed.
0119  *
0120  * "." and ".." are returned but only for the toplevel directory.
0121  * Filter them out if you don't want them.
0122  *
0123  * @param url the url of the directory
0124  * @param flags Can be HideProgressInfo here
0125  * @param includeHidden true for all files, false to cull out UNIX hidden
0126  *                      files/dirs (whose names start with dot)
0127  * @return the job handling the operation.
0128  */
0129 KIOCORE_EXPORT ListJob *listRecursive(const QUrl &url, JobFlags flags = DefaultFlags, ListJob::ListFlags listFlags = ListJob::ListFlag::IncludeHidden);
0130 
0131 Q_DECLARE_OPERATORS_FOR_FLAGS(KIO::ListJob::ListFlags)
0132 }
0133 
0134 #endif