KIO

simplejob.h
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2000 Stephan Kulow <[email protected]>
4  SPDX-FileCopyrightText: 2000-2013 David Faure <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #ifndef KIO_SIMPLEJOB_H
10 #define KIO_SIMPLEJOB_H
11 
12 #include "job_base.h"
13 #include <kio/global.h> // filesize_t
14 
15 namespace KIO
16 {
17 class SimpleJobPrivate;
18 /**
19  * @class KIO::SimpleJob simplejob.h <KIO/SimpleJob>
20  *
21  * A simple job (one url and one command).
22  * This is the base class for all jobs that are scheduled.
23  * Other jobs are high-level jobs (CopyJob, DeleteJob, FileCopyJob...)
24  * that manage subjobs but aren't scheduled directly.
25  */
26 class KIOCORE_EXPORT SimpleJob : public KIO::Job
27 {
28  Q_OBJECT
29 
30 public:
31  ~SimpleJob() override;
32 
33 protected:
34  /**
35  * Suspend this job
36  * @see resume
37  */
38  bool doSuspend() override;
39 
40  /**
41  * Resume this job
42  * @see suspend
43  */
44  bool doResume() override;
45 
46  /**
47  * Abort job.
48  * This kills all subjobs and deletes the job.
49  */
50  bool doKill() override;
51 
52 public:
53  /**
54  * Returns the SimpleJob's URL
55  * @return the url
56  */
57  const QUrl &url() const;
58 
59  /**
60  * Abort job.
61  * Suspends worker to be reused by another job for the same request.
62  */
63  virtual void putOnHold();
64 
65  /**
66  * Discard suspended worker.
67  */
68  static void removeOnHold();
69 
70  /**
71  * Returns true when redirections are handled internally, the default.
72  *
73  * @since 4.4
74  */
75  bool isRedirectionHandlingEnabled() const;
76 
77  /**
78  * Set @p handle to false to prevent the internal handling of redirections.
79  *
80  * When this flag is set, redirection requests are simply forwarded to the
81  * caller instead of being handled internally.
82  *
83  * @since 4.4
84  */
85  void setRedirectionHandlingEnabled(bool handle);
86 
87 public Q_SLOTS:
88  /**
89  * @internal
90  * Called on a worker's error.
91  * Made public for the scheduler.
92  */
93  void slotError(int, const QString &);
94 
95 protected Q_SLOTS:
96  /**
97  * Called when the worker marks the job
98  * as finished.
99  */
100  virtual void slotFinished();
101 
102  /**
103  * @internal
104  * Called on a worker's warning.
105  */
106  virtual void slotWarning(const QString &);
107 
108  /**
109  * MetaData from the worker is received.
110  * @param _metaData the meta data
111  * @see metaData()
112  */
113  virtual void slotMetaData(const KIO::MetaData &_metaData);
114 
115 protected:
116 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 101)
117  /**
118  * Allow jobs that inherit SimpleJob and are aware
119  * of redirections to store the SSL session used.
120  * Retrieval is handled by SimpleJob::start
121  * @param m_redirectionURL Reference to redirection URL,
122  * used instead of m_url if not empty
123  *
124  * @deprecated Since 4.3, this is a no-op.
125  */
126  KIOCORE_DEPRECATED_VERSION_BELATED(5, 101, 4, 3, "A no-op method now.")
127  void storeSSLSessionFromJob(const QUrl &m_redirectionURL);
128 #endif
129 
130  /**
131  * Creates a new simple job. You don't need to use this constructor,
132  * unless you create a new job that inherits from SimpleJob.
133  */
134  KIOCORE_NO_EXPORT explicit SimpleJob(SimpleJobPrivate &dd);
135 
136 private:
137  Q_DECLARE_PRIVATE(SimpleJob)
138 };
139 
140 /**
141  * Removes a single directory.
142  *
143  * The directory is assumed to be empty.
144  * The job will fail if the directory is not empty.
145  * Use KIO::del() (DeleteJob) to delete non-empty directories.
146  *
147  * @param url The URL of the directory to remove.
148  * @return A pointer to the job handling the operation.
149  */
150 KIOCORE_EXPORT SimpleJob *rmdir(const QUrl &url);
151 
152 /**
153  * Changes permissions on a file or directory.
154  * See the other chmod in chmodjob.h for changing many files
155  * or directories.
156  *
157  * @param url The URL of file or directory.
158  * @param permissions The permissions to set.
159  * @return the job handling the operation.
160  */
161 KIOCORE_EXPORT SimpleJob *chmod(const QUrl &url, int permissions);
162 
163 /**
164  * Changes ownership and group of a file or directory.
165  *
166  * @param url The URL of file or directory.
167  * @param owner the new owner
168  * @param group the new group
169  * @return the job handling the operation.
170  */
171 KIOCORE_EXPORT SimpleJob *chown(const QUrl &url, const QString &owner, const QString &group);
172 
173 /**
174  * Changes the modification time on a file or directory.
175  *
176  * @param url The URL of file or directory.
177  * @param mtime The modification time to set.
178  * @return the job handling the operation.
179  */
180 KIOCORE_EXPORT SimpleJob *setModificationTime(const QUrl &url, const QDateTime &mtime);
181 
182 /**
183  * Rename a file or directory.
184  * Warning: this operation fails if a direct renaming is not
185  * possible (like with files or dirs on separate partitions)
186  * Use move or file_move in this case.
187  *
188  * @param src The original URL
189  * @param dest The final URL
190  * @param flags Can be Overwrite here
191  * @return the job handling the operation.
192  */
193 KIOCORE_EXPORT SimpleJob *rename(const QUrl &src, const QUrl &dest, JobFlags flags = DefaultFlags);
194 
195 /**
196  * Create or move a symlink.
197  * This is the lowlevel operation, similar to file_copy and file_move.
198  * It doesn't do any check (other than those the worker does)
199  * and it doesn't show rename and skip dialogs - use KIO::link for that.
200  * @param target The string that will become the "target" of the link (can be relative)
201  * @param dest The symlink to create.
202  * @param flags Can be Overwrite and HideProgressInfo
203  * @return the job handling the operation.
204  */
205 KIOCORE_EXPORT SimpleJob *symlink(const QString &target, const QUrl &dest, JobFlags flags = DefaultFlags);
206 
207 /**
208  * Execute any command that is specific to one worker (protocol).
209  *
210  * Examples are : HTTP POST, mount and unmount (kio_file)
211  *
212  * @param url The URL isn't passed to the worker, but is used to know
213  * which worker to send it to :-)
214  * @param data Packed data. The meaning is completely dependent on the
215  * worker, but usually starts with an int for the command number.
216  * @param flags Can be HideProgressInfo here
217  * @return the job handling the operation.
218  */
219 KIOCORE_EXPORT SimpleJob *special(const QUrl &url, const QByteArray &data, JobFlags flags = DefaultFlags);
220 
221 /**
222  * Mount filesystem.
223  *
224  * Special job for @p kio_file.
225  *
226  * @param ro Mount read-only if @p true.
227  * @param fstype File system type (e.g. "ext2", can be empty).
228  * @param dev Device (e.g. /dev/sda0).
229  * @param point Mount point, can be @p null.
230  * @param flags Can be HideProgressInfo here
231  * @return the job handling the operation.
232  */
233 KIOCORE_EXPORT SimpleJob *mount(bool ro, const QByteArray &fstype, const QString &dev, const QString &point, JobFlags flags = DefaultFlags);
234 
235 /**
236  * Unmount filesystem.
237  *
238  * Special job for @p kio_file.
239  *
240  * @param point Point to unmount.
241  * @param flags Can be HideProgressInfo here
242  * @return the job handling the operation.
243  */
244 KIOCORE_EXPORT SimpleJob *unmount(const QString &point, JobFlags flags = DefaultFlags);
245 
246 /**
247  * HTTP cache update
248  *
249  * @param url Url to update, protocol must be "http".
250  * @param no_cache If true, cache entry for @p url is deleted.
251  * @param expireDate Local machine time indicating when the entry is
252  * supposed to expire.
253  * @return the job handling the operation.
254  */
255 KIOCORE_EXPORT SimpleJob *http_update_cache(const QUrl &url, bool no_cache, const QDateTime &expireDate);
256 
257 /**
258  * Delete a single file.
259  *
260  * @param src File to delete.
261  * @param flags Can be HideProgressInfo here
262  * @return the job handling the operation.
263  */
264 KIOCORE_EXPORT SimpleJob *file_delete(const QUrl &src, JobFlags flags = DefaultFlags);
265 
266 }
267 
268 #endif
KIOCORE_EXPORT SimpleJob * rename(const QUrl &src, const QUrl &dest, JobFlags flags=DefaultFlags)
Rename a file or directory.
Definition: simplejob.cpp:363
KIOCORE_EXPORT SimpleJob * file_delete(const QUrl &src, JobFlags flags=DefaultFlags)
Delete a single file.
Definition: job.cpp:380
KIOCORE_EXPORT SimpleJob * setModificationTime(const QUrl &url, const QDateTime &mtime)
Changes the modification time on a file or directory.
Definition: simplejob.cpp:356
KIOCORE_EXPORT SimpleJob * http_update_cache(const QUrl &url, bool no_cache, const QDateTime &expireDate)
HTTP cache update.
Definition: simplejob.cpp:405
@ DefaultFlags
Show the progress info GUI, no Resume and no Overwrite.
Definition: job_base.h:270
KIOCORE_EXPORT SimpleJob * unmount(const QString &point, JobFlags flags=DefaultFlags)
Unmount filesystem.
Definition: simplejob.cpp:393
KIOCORE_EXPORT SimpleJob * mount(bool ro, const QByteArray &fstype, const QString &dev, const QString &point, JobFlags flags=DefaultFlags)
Mount filesystem.
Definition: simplejob.cpp:383
KIOCORE_EXPORT ChmodJob * chmod(const KFileItemList &lstItems, int permissions, int mask, const QString &newOwner, const QString &newGroup, bool recursive, JobFlags flags=DefaultFlags)
Creates a job that changes permissions/ownership on several files or directories, optionally recursiv...
Definition: chmodjob.cpp:288
KIOCORE_EXPORT SimpleJob * special(const QUrl &url, const QByteArray &data, JobFlags flags=DefaultFlags)
Execute any command that is specific to one worker (protocol).
Definition: simplejob.cpp:377
A namespace for KIO globals.
KIOCORE_EXPORT SimpleJob * rmdir(const QUrl &url)
Removes a single directory.
Definition: simplejob.cpp:336
KIOCORE_EXPORT SimpleJob * symlink(const QString &target, const QUrl &dest, JobFlags flags=DefaultFlags)
Create or move a symlink.
Definition: simplejob.cpp:370
KIOCORE_EXPORT SimpleJob * chown(const QUrl &url, const QString &owner, const QString &group)
Changes ownership and group of a file or directory.
Definition: simplejob.cpp:350
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Mar 26 2023 04:00:07 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.