File indexing completed on 2024-04-28 07:43:57

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      */
0074     bool isRedirectionHandlingEnabled() const;
0075 
0076     /**
0077      * Set @p handle to false to prevent the internal handling of redirections.
0078      *
0079      * When this flag is set, redirection requests are simply forwarded to the
0080      * caller instead of being handled internally.
0081      *
0082      */
0083     void setRedirectionHandlingEnabled(bool handle);
0084 
0085 public Q_SLOTS:
0086     /**
0087      * @internal
0088      * Called on a worker's error.
0089      * Made public for the scheduler.
0090      */
0091     void slotError(int, const QString &);
0092 
0093 protected Q_SLOTS:
0094     /**
0095      * Called when the worker marks the job
0096      * as finished.
0097      */
0098     virtual void slotFinished();
0099 
0100     /**
0101      * @internal
0102      * Called on a worker's warning.
0103      */
0104     virtual void slotWarning(const QString &);
0105 
0106     /**
0107      * MetaData from the worker is received.
0108      * @param _metaData the meta data
0109      * @see metaData()
0110      */
0111     virtual void slotMetaData(const KIO::MetaData &_metaData);
0112 
0113 protected:
0114     /**
0115      * Creates a new simple job. You don't need to use this constructor,
0116      * unless you create a new job that inherits from SimpleJob.
0117      */
0118     KIOCORE_NO_EXPORT explicit SimpleJob(SimpleJobPrivate &dd);
0119 
0120 private:
0121     Q_DECLARE_PRIVATE(SimpleJob)
0122 };
0123 
0124 /**
0125  * Removes a single directory.
0126  *
0127  * The directory is assumed to be empty.
0128  * The job will fail if the directory is not empty.
0129  * Use KIO::del() (DeleteJob) to delete non-empty directories.
0130  *
0131  * @param url The URL of the directory to remove.
0132  * @return A pointer to the job handling the operation.
0133  */
0134 KIOCORE_EXPORT SimpleJob *rmdir(const QUrl &url);
0135 
0136 /**
0137  * Changes permissions on a file or directory.
0138  * See the other chmod in chmodjob.h for changing many files
0139  * or directories.
0140  *
0141  * @param url The URL of file or directory.
0142  * @param permissions The permissions to set.
0143  * @return the job handling the operation.
0144  */
0145 KIOCORE_EXPORT SimpleJob *chmod(const QUrl &url, int permissions);
0146 
0147 /**
0148  * Changes ownership and group of a file or directory.
0149  *
0150  * @param url The URL of file or directory.
0151  * @param owner the new owner
0152  * @param group the new group
0153  * @return the job handling the operation.
0154  */
0155 KIOCORE_EXPORT SimpleJob *chown(const QUrl &url, const QString &owner, const QString &group);
0156 
0157 /**
0158  * Changes the modification time on a file or directory.
0159  *
0160  * @param url The URL of file or directory.
0161  * @param mtime The modification time to set.
0162  * @return the job handling the operation.
0163  */
0164 KIOCORE_EXPORT SimpleJob *setModificationTime(const QUrl &url, const QDateTime &mtime);
0165 
0166 /**
0167  * Rename a file or directory.
0168  * Warning: this operation fails if a direct renaming is not
0169  * possible (like with files or dirs on separate partitions)
0170  * Use move or file_move in this case.
0171  *
0172  * @param src The original URL
0173  * @param dest The final URL
0174  * @param flags Can be Overwrite here
0175  * @return the job handling the operation.
0176  */
0177 KIOCORE_EXPORT SimpleJob *rename(const QUrl &src, const QUrl &dest, JobFlags flags = DefaultFlags);
0178 
0179 /**
0180  * Create or move a symlink.
0181  * This is the lowlevel operation, similar to file_copy and file_move.
0182  * It doesn't do any check (other than those the worker does)
0183  * and it doesn't show rename and skip dialogs - use KIO::link for that.
0184  * @param target The string that will become the "target" of the link (can be relative)
0185  * @param dest The symlink to create.
0186  * @param flags Can be Overwrite and HideProgressInfo
0187  * @return the job handling the operation.
0188  */
0189 KIOCORE_EXPORT SimpleJob *symlink(const QString &target, const QUrl &dest, JobFlags flags = DefaultFlags);
0190 
0191 /**
0192  * Execute any command that is specific to one worker (protocol).
0193  *
0194  * Examples are : HTTP POST, mount and unmount (kio_file)
0195  *
0196  * @param url The URL isn't passed to the worker, but is used to know
0197  *        which worker to send it to :-)
0198  * @param data Packed data.  The meaning is completely dependent on the
0199  *        worker, but usually starts with an int for the command number.
0200  * @param flags Can be HideProgressInfo here
0201  * @return the job handling the operation.
0202  */
0203 KIOCORE_EXPORT SimpleJob *special(const QUrl &url, const QByteArray &data, JobFlags flags = DefaultFlags);
0204 
0205 /**
0206  * Mount filesystem.
0207  *
0208  * Special job for @p kio_file.
0209  *
0210  * @param ro Mount read-only if @p true.
0211  * @param fstype File system type (e.g. "ext2", can be empty).
0212  * @param dev Device (e.g. /dev/sda0).
0213  * @param point Mount point, can be @p null.
0214  * @param flags Can be HideProgressInfo here
0215  * @return the job handling the operation.
0216  */
0217 KIOCORE_EXPORT SimpleJob *mount(bool ro, const QByteArray &fstype, const QString &dev, const QString &point, JobFlags flags = DefaultFlags);
0218 
0219 /**
0220  * Unmount filesystem.
0221  *
0222  * Special job for @p kio_file.
0223  *
0224  * @param point Point to unmount.
0225  * @param flags Can be HideProgressInfo here
0226  * @return the job handling the operation.
0227  */
0228 KIOCORE_EXPORT SimpleJob *unmount(const QString &point, JobFlags flags = DefaultFlags);
0229 
0230 /**
0231  * HTTP cache update
0232  *
0233  * @param url Url to update, protocol must be "http".
0234  * @param no_cache If true, cache entry for @p url is deleted.
0235  * @param expireDate Local machine time indicating when the entry is
0236  * supposed to expire.
0237  * @return the job handling the operation.
0238  */
0239 KIOCORE_EXPORT SimpleJob *http_update_cache(const QUrl &url, bool no_cache, const QDateTime &expireDate);
0240 
0241 /**
0242  * Delete a single file.
0243  *
0244  * @param src File to delete.
0245  * @param flags Can be HideProgressInfo here
0246  * @return the job handling the operation.
0247  */
0248 KIOCORE_EXPORT SimpleJob *file_delete(const QUrl &src, JobFlags flags = DefaultFlags);
0249 
0250 }
0251 
0252 #endif