File indexing completed on 2024-04-21 15:00:04

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     /**
0035      * Returns the ListJob's redirection URL. This will be invalid if there
0036      * was no redirection.
0037      * @return the redirection url
0038      */
0039     const QUrl &redirectionUrl() const;
0040 
0041     /**
0042      * Do not apply any KIOSK restrictions to this job.
0043      */
0044     void setUnrestricted(bool unrestricted);
0045 
0046 Q_SIGNALS:
0047     /**
0048      * This signal emits the entry found by the job while listing.
0049      * The progress signals aren't specific to ListJob. It simply
0050      * uses SimpleJob's processedSize (number of entries listed) and
0051      * totalSize (total number of entries, if known),
0052      * as well as percent.
0053      * @param job the job that emitted this signal
0054      * @param list the list of UDSEntries
0055      */
0056     void entries(KIO::Job *job, const KIO::UDSEntryList &list); // TODO KDE5: use KIO::ListJob* argument to avoid casting
0057 
0058     /**
0059      * This signal is emitted when a sub-directory could not be listed.
0060      * The job keeps going, thus doesn't result in an overall error.
0061      * @param job the job that emitted the signal
0062      * @param subJob the job listing a sub-directory, which failed. Use
0063      *       url(), error() and errorText() on that job to find
0064      *       out more.
0065      */
0066     void subError(KIO::ListJob *job, KIO::ListJob *subJob);
0067 
0068     /**
0069      * Signals a redirection.
0070      * Use to update the URL shown to the user.
0071      * The redirection itself is handled internally.
0072      * @param job the job that is redirected
0073      * @param url the new url
0074      */
0075     void redirection(KIO::Job *job, const QUrl &url);
0076 
0077     /**
0078      * Signals a permanent redirection.
0079      * The redirection itself is handled internally.
0080      * @param job the job that emitted this signal
0081      * @param fromUrl the original URL
0082      * @param toUrl the new URL
0083      */
0084     void permanentRedirection(KIO::Job *job, const QUrl &fromUrl, const QUrl &toUrl);
0085 
0086 protected Q_SLOTS:
0087     void slotFinished() override;
0088 #if KIOCORE_BUILD_DEPRECATED_SINCE(5, 101) // override no longer needed
0089     void slotMetaData(const KIO::MetaData &_metaData) override;
0090 #endif
0091     void slotResult(KJob *job) override;
0092 
0093 protected:
0094     KIOCORE_NO_EXPORT explicit ListJob(ListJobPrivate &dd);
0095 
0096     Q_DECLARE_PRIVATE(ListJob)
0097     friend class ListJobPrivate;
0098 };
0099 
0100 /**
0101  * List the contents of @p url, which is assumed to be a directory.
0102  *
0103  * "." and ".." are returned, filter them out if you don't want them.
0104  *
0105  *
0106  * @param url the url of the directory
0107  * @param flags Can be HideProgressInfo here
0108  * @param includeHidden true for all files, false to cull out UNIX hidden
0109  *                      files/dirs (whose names start with dot)
0110  * @return the job handling the operation.
0111  */
0112 KIOCORE_EXPORT ListJob *listDir(const QUrl &url, JobFlags flags = DefaultFlags, bool includeHidden = true);
0113 
0114 /**
0115  * The same as the previous method, but recurses subdirectories.
0116  * Directory links are not followed.
0117  *
0118  * "." and ".." are returned but only for the toplevel directory.
0119  * Filter them out if you don't want them.
0120  *
0121  * @param url the url of the directory
0122  * @param flags Can be HideProgressInfo here
0123  * @param includeHidden true for all files, false to cull out UNIX hidden
0124  *                      files/dirs (whose names start with dot)
0125  * @return the job handling the operation.
0126  */
0127 KIOCORE_EXPORT ListJob *listRecursive(const QUrl &url, JobFlags flags = DefaultFlags, bool includeHidden = true);
0128 
0129 }
0130 
0131 #endif