KIO

filecopyjob.h
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2000 Stephan Kulow <[email protected]>
4  SPDX-FileCopyrightText: 2000-2009 David Faure <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #ifndef KIO_FILECOPYJOB_H
10 #define KIO_FILECOPYJOB_H
11 
12 #include "job_base.h"
13 #include <kio/global.h> // filesize_t
14 
15 namespace KIO
16 {
17 class FileCopyJobPrivate;
18 /**
19  * @class KIO::FileCopyJob filecopyjob.h <KIO/FileCopyJob>
20  *
21  * The FileCopyJob copies data from one place to another.
22  * @see KIO::file_copy()
23  * @see KIO::file_move()
24  */
25 class KIOCORE_EXPORT FileCopyJob : public Job
26 {
27  Q_OBJECT
28 
29 public:
30  ~FileCopyJob() override;
31  /**
32  * If you know the size of the source file, call this method
33  * to inform this job. It will be displayed in the "resume" dialog.
34  * @param size the size of the source file
35  */
36  void setSourceSize(KIO::filesize_t size);
37 
38  /**
39  * Sets the modification time of the file
40  *
41  * Note that this is ignored if a direct copy (WorkerBase::copy) can be done,
42  * in which case the mtime of the source is applied to the destination (if the protocol
43  * supports the concept).
44  */
45  void setModificationTime(const QDateTime &mtime);
46 
47  /**
48  * Returns the source URL.
49  * @return the source URL
50  */
51  QUrl srcUrl() const;
52 
53  /**
54  * Returns the destination URL.
55  * @return the destination URL
56  */
57  QUrl destUrl() const;
58 
59  bool doSuspend() override;
60  bool doResume() override;
61  bool doKill() override;
62 
63 Q_SIGNALS:
64 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 78)
65  /**
66  * MIME type determined during a file copy.
67  * This is never emitted during a move, and might not be emitted during
68  * a file copy, depending on the worker. But when a get and a put are
69  * being used (which is the common case), this signal forwards the
70  * MIME type information from the get job.
71  *
72  * @param job the job that emitted this signal
73  * @param mimeType the MIME type
74  * @deprecated Since 5.78, use mimeTypeFound(KIO::Job *, const QString &)
75  */
76  KIOCORE_DEPRECATED_VERSION(5, 78, "Use KIO::FileCopyJob::mimeTypeFound(KIO::Job *, const QString &)")
77  void mimetype(KIO::Job *job, const QString &mimeType);
78 #endif
79 
80  /**
81  * MIME type determined during a file copy.
82  * This is never emitted during a move, and might not be emitted during
83  * a file copy, depending on the worker. But when a get and a put are
84  * being used (which is the common case), this signal forwards the
85  * MIME type information from the get job.
86  *
87  * @param job the job that emitted this signal
88  * @param mimeType the MIME type
89  * @since 5.78
90  */
91  void mimeTypeFound(KIO::Job *job, const QString &mimeType);
92 
93 protected Q_SLOTS:
94  /**
95  * Called whenever a subjob finishes.
96  * @param job the job that emitted this signal
97  */
98  void slotResult(KJob *job) override;
99 
100 protected:
101  KIOCORE_NO_EXPORT explicit FileCopyJob(FileCopyJobPrivate &dd);
102 
103 private:
104  Q_DECLARE_PRIVATE(FileCopyJob)
105 };
106 
107 /**
108  * Copy a single file.
109  *
110  * Uses either WorkerBase::copy() if the worker supports that
111  * or get() and put() otherwise.
112  *
113  * @param src Where to get the file
114  * @param dest Where to put the file
115  * @param permissions the file mode permissions to set on @p dest; if this is -1
116  * (the default) no special permissions will be set on @p dest, i.e. it'll have
117  * the default system permissions for newly created files, and the owner and group
118  * permissions are not preserved.
119  * @param flags Can be @ref JobFlag::HideProgressInfo, Overwrite and Resume here
120  * WARNING: Setting @ref JobFlag::Resume means that the data will be appended to
121  * @p dest if @p dest exists
122  * @return the job handling the operation
123  */
124 KIOCORE_EXPORT FileCopyJob *file_copy(const QUrl &src, const QUrl &dest, int permissions = -1, JobFlags flags = DefaultFlags);
125 
126 /**
127  * Overload for catching code mistakes. Do NOT call this method (it is not implemented),
128  * insert a value for permissions (-1 by default) before the JobFlags.
129  * @since 4.5
130  */
131 FileCopyJob *file_copy(const QUrl &src, const QUrl &dest, JobFlags flags) Q_DECL_EQ_DELETE; // not implemented - on purpose.
132 
133 /**
134  * Move a single file.
135  *
136  * Use either WorkerBase::rename() if the worker supports that,
137  * or copy() and del() otherwise, or eventually get() & put() & del()
138  *
139  * @param src Where to get the file
140  * @param dest Where to put the file
141  * @param permissions the file mode permissions to set on @p dest; if this is -1
142  * (the default), no special permissions are set on @p dest, i.e. it'll have
143  * the default system permissions for newly created files, and the owner and group
144  * permissions are not preserved.
145  * @param flags Can be HideProgressInfo, Overwrite and Resume here
146  * WARNING: Setting @ref JobFlag::Resume means that the data will be appended to
147  * @p dest if @p dest exists
148  * @return the job handling the operation
149  */
150 KIOCORE_EXPORT FileCopyJob *file_move(const QUrl &src, const QUrl &dest, int permissions = -1, JobFlags flags = DefaultFlags);
151 
152 /**
153  * Overload for catching code mistakes. Do NOT call this method (it is not implemented),
154  * insert a value for permissions (-1 by default) before the JobFlags.
155  * @since 4.3
156  */
157 FileCopyJob *file_move(const QUrl &src, const QUrl &dest, JobFlags flags) Q_DECL_EQ_DELETE; // not implemented - on purpose.
158 
159 }
160 
161 #endif
KIOCORE_EXPORT SimpleJob * setModificationTime(const QUrl &url, const QDateTime &mtime)
Changes the modification time on a file or directory.
Definition: simplejob.cpp:356
qulonglong filesize_t
64-bit file size
Definition: global.h:39
@ DefaultFlags
Show the progress info GUI, no Resume and no Overwrite.
Definition: job_base.h:270
KIOCORE_EXPORT FileCopyJob * file_copy(const QUrl &src, const QUrl &dest, int permissions=-1, JobFlags flags=DefaultFlags)
Copy a single file.
KIOCORE_EXPORT MimetypeJob * mimetype(const QUrl &url, JobFlags flags=DefaultFlags)
Find MIME type for one file or directory.
Definition: mimetypejob.cpp:85
KIOCORE_EXPORT FileCopyJob * file_move(const QUrl &src, const QUrl &dest, int permissions=-1, JobFlags flags=DefaultFlags)
Move a single file.
A namespace for KIO globals.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Nov 28 2023 03:55:12 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.