File indexing completed on 2024-12-01 12:35:56

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org>
0004     SPDX-FileCopyrightText: 2000-2013 David Faure <faure@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef KIO_SIMPLEJOB_H
0010 #define KIO_SIMPLEJOB_H
0011 
0012 #include "job_base.h"
0013 #include <kio/global.h> // filesize_t
0014 
0015 namespace KIO
0016 {
0017 class SimpleJobPrivate;
0018 /**
0019  * @class KIO::SimpleJob simplejob.h <KIO/SimpleJob>
0020  *
0021  * A simple job (one url and one command).
0022  * This is the base class for all jobs that are scheduled.
0023  * Other jobs are high-level jobs (CopyJob, DeleteJob, FileCopyJob...)
0024  * that manage subjobs but aren't scheduled directly.
0025  */
0026 class KIOCORE_EXPORT SimpleJob : public KIO::Job
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     ~SimpleJob() override;
0032 
0033 protected:
0034     /**
0035      * Suspend this job
0036      * @see resume
0037      */
0038     bool doSuspend() override;
0039 
0040     /**
0041      * Resume this job
0042      * @see suspend
0043      */
0044     bool doResume() override;
0045 
0046     /**
0047      * Abort job.
0048      * This kills all subjobs and deletes the job.
0049      */
0050     bool doKill() override;
0051 
0052 public:
0053     /**
0054      * Returns the SimpleJob's URL
0055      * @return the url
0056      */
0057     const QUrl &url() const;
0058 
0059     /**
0060      * Abort job.
0061      * Suspends worker to be reused by another job for the same request.
0062      */
0063     virtual void putOnHold();
0064 
0065     /**
0066      * Discard suspended worker.
0067      */
0068     static void removeOnHold();
0069 
0070     /**
0071      * Returns true when redirections are handled internally, the default.
0072      *
0073      * @since 4.4
0074      */
0075     bool isRedirectionHandlingEnabled() const;
0076 
0077     /**
0078      * Set @p handle to false to prevent the internal handling of redirections.
0079      *
0080      * When this flag is set, redirection requests are simply forwarded to the
0081      * caller instead of being handled internally.
0082      *
0083      * @since 4.4
0084      */
0085     void setRedirectionHandlingEnabled(bool handle);
0086 
0087 public Q_SLOTS:
0088     /**
0089      * @internal
0090      * Called on a worker's error.
0091      * Made public for the scheduler.
0092      */
0093     void slotError(int, const QString &);
0094 
0095 protected Q_SLOTS:
0096     /**
0097      * Called when the worker marks the job
0098      * as finished.
0099      */
0100     virtual void slotFinished();
0101 
0102     /**
0103      * @internal
0104      * Called on a worker's warning.
0105      */
0106     virtual void slotWarning(const QString &);
0107 
0108     /**
0109      * MetaData from the worker is received.
0110      * @param _metaData the meta data
0111      * @see metaData()
0112      */
0113     virtual void slotMetaData(const KIO::MetaData &_metaData);
0114 
0115 protected:
0116 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 101)
0117     /**
0118      * Allow jobs that inherit SimpleJob and are aware
0119      * of redirections to store the SSL session used.
0120      * Retrieval is handled by SimpleJob::start
0121      * @param m_redirectionURL Reference to redirection URL,
0122      * used instead of m_url if not empty
0123      *
0124      * @deprecated Since 4.3, this is a no-op.
0125      */
0126     KIOCORE_DEPRECATED_VERSION_BELATED(5, 101, 4, 3, "A no-op method now.")
0127     void storeSSLSessionFromJob(const QUrl &m_redirectionURL);
0128 #endif
0129 
0130     /**
0131      * Creates a new simple job. You don't need to use this constructor,
0132      * unless you create a new job that inherits from SimpleJob.
0133      */
0134     KIOCORE_NO_EXPORT explicit SimpleJob(SimpleJobPrivate &dd);
0135 
0136 private:
0137     Q_DECLARE_PRIVATE(SimpleJob)
0138 };
0139 
0140 /**
0141  * Removes a single directory.
0142  *
0143  * The directory is assumed to be empty.
0144  * The job will fail if the directory is not empty.
0145  * Use KIO::del() (DeleteJob) to delete non-empty directories.
0146  *
0147  * @param url The URL of the directory to remove.
0148  * @return A pointer to the job handling the operation.
0149  */
0150 KIOCORE_EXPORT SimpleJob *rmdir(const QUrl &url);
0151 
0152 /**
0153  * Changes permissions on a file or directory.
0154  * See the other chmod in chmodjob.h for changing many files
0155  * or directories.
0156  *
0157  * @param url The URL of file or directory.
0158  * @param permissions The permissions to set.
0159  * @return the job handling the operation.
0160  */
0161 KIOCORE_EXPORT SimpleJob *chmod(const QUrl &url, int permissions);
0162 
0163 /**
0164  * Changes ownership and group of a file or directory.
0165  *
0166  * @param url The URL of file or directory.
0167  * @param owner the new owner
0168  * @param group the new group
0169  * @return the job handling the operation.
0170  */
0171 KIOCORE_EXPORT SimpleJob *chown(const QUrl &url, const QString &owner, const QString &group);
0172 
0173 /**
0174  * Changes the modification time on a file or directory.
0175  *
0176  * @param url The URL of file or directory.
0177  * @param mtime The modification time to set.
0178  * @return the job handling the operation.
0179  */
0180 KIOCORE_EXPORT SimpleJob *setModificationTime(const QUrl &url, const QDateTime &mtime);
0181 
0182 /**
0183  * Rename a file or directory.
0184  * Warning: this operation fails if a direct renaming is not
0185  * possible (like with files or dirs on separate partitions)
0186  * Use move or file_move in this case.
0187  *
0188  * @param src The original URL
0189  * @param dest The final URL
0190  * @param flags Can be Overwrite here
0191  * @return the job handling the operation.
0192  */
0193 KIOCORE_EXPORT SimpleJob *rename(const QUrl &src, const QUrl &dest, JobFlags flags = DefaultFlags);
0194 
0195 /**
0196  * Create or move a symlink.
0197  * This is the lowlevel operation, similar to file_copy and file_move.
0198  * It doesn't do any check (other than those the worker does)
0199  * and it doesn't show rename and skip dialogs - use KIO::link for that.
0200  * @param target The string that will become the "target" of the link (can be relative)
0201  * @param dest The symlink to create.
0202  * @param flags Can be Overwrite and HideProgressInfo
0203  * @return the job handling the operation.
0204  */
0205 KIOCORE_EXPORT SimpleJob *symlink(const QString &target, const QUrl &dest, JobFlags flags = DefaultFlags);
0206 
0207 /**
0208  * Execute any command that is specific to one worker (protocol).
0209  *
0210  * Examples are : HTTP POST, mount and unmount (kio_file)
0211  *
0212  * @param url The URL isn't passed to the worker, but is used to know
0213  *        which worker to send it to :-)
0214  * @param data Packed data.  The meaning is completely dependent on the
0215  *        worker, but usually starts with an int for the command number.
0216  * @param flags Can be HideProgressInfo here
0217  * @return the job handling the operation.
0218  */
0219 KIOCORE_EXPORT SimpleJob *special(const QUrl &url, const QByteArray &data, JobFlags flags = DefaultFlags);
0220 
0221 /**
0222  * Mount filesystem.
0223  *
0224  * Special job for @p kio_file.
0225  *
0226  * @param ro Mount read-only if @p true.
0227  * @param fstype File system type (e.g. "ext2", can be empty).
0228  * @param dev Device (e.g. /dev/sda0).
0229  * @param point Mount point, can be @p null.
0230  * @param flags Can be HideProgressInfo here
0231  * @return the job handling the operation.
0232  */
0233 KIOCORE_EXPORT SimpleJob *mount(bool ro, const QByteArray &fstype, const QString &dev, const QString &point, JobFlags flags = DefaultFlags);
0234 
0235 /**
0236  * Unmount filesystem.
0237  *
0238  * Special job for @p kio_file.
0239  *
0240  * @param point Point to unmount.
0241  * @param flags Can be HideProgressInfo here
0242  * @return the job handling the operation.
0243  */
0244 KIOCORE_EXPORT SimpleJob *unmount(const QString &point, JobFlags flags = DefaultFlags);
0245 
0246 /**
0247  * HTTP cache update
0248  *
0249  * @param url Url to update, protocol must be "http".
0250  * @param no_cache If true, cache entry for @p url is deleted.
0251  * @param expireDate Local machine time indicating when the entry is
0252  * supposed to expire.
0253  * @return the job handling the operation.
0254  */
0255 KIOCORE_EXPORT SimpleJob *http_update_cache(const QUrl &url, bool no_cache, const QDateTime &expireDate);
0256 
0257 /**
0258  * Delete a single file.
0259  *
0260  * @param src File to delete.
0261  * @param flags Can be HideProgressInfo here
0262  * @return the job handling the operation.
0263  */
0264 KIOCORE_EXPORT SimpleJob *file_delete(const QUrl &src, JobFlags flags = DefaultFlags);
0265 
0266 }
0267 
0268 #endif