1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org> |
4 | SPDX-FileCopyrightText: 2000-2009 David Faure <faure@kde.org> |
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 | /** |
65 | * MIME type determined during a file copy. |
66 | * This is never emitted during a move, and might not be emitted during |
67 | * a file copy, depending on the worker. But when a get and a put are |
68 | * being used (which is the common case), this signal forwards the |
69 | * MIME type information from the get job. |
70 | * |
71 | * @param job the job that emitted this signal |
72 | * @param mimeType the MIME type |
73 | * @since 5.78 |
74 | */ |
75 | void mimeTypeFound(KIO::Job *job, const QString &mimeType); |
76 | |
77 | protected Q_SLOTS: |
78 | /** |
79 | * Called whenever a subjob finishes. |
80 | * @param job the job that emitted this signal |
81 | */ |
82 | void slotResult(KJob *job) override; |
83 | |
84 | protected: |
85 | KIOCORE_NO_EXPORT explicit FileCopyJob(FileCopyJobPrivate &dd); |
86 | |
87 | private: |
88 | Q_DECLARE_PRIVATE(FileCopyJob) |
89 | }; |
90 | |
91 | /** |
92 | * Copy a single file. |
93 | * |
94 | * Uses either WorkerBase::copy() if the worker supports that |
95 | * or get() and put() otherwise. |
96 | * |
97 | * @param src Where to get the file |
98 | * @param dest Where to put the file |
99 | * @param permissions the file mode permissions to set on @p dest; if this is -1 |
100 | * (the default) no special permissions will be set on @p dest, i.e. it'll have |
101 | * the default system permissions for newly created files, and the owner and group |
102 | * permissions are not preserved. |
103 | * @param flags Can be @ref JobFlag::HideProgressInfo, Overwrite and Resume here |
104 | * WARNING: Setting @ref JobFlag::Resume means that the data will be appended to |
105 | * @p dest if @p dest exists |
106 | * @return the job handling the operation |
107 | */ |
108 | KIOCORE_EXPORT FileCopyJob *file_copy(const QUrl &src, const QUrl &dest, int permissions = -1, JobFlags flags = DefaultFlags); |
109 | |
110 | /** |
111 | * Overload for catching code mistakes. Do NOT call this method (it is not implemented), |
112 | * insert a value for permissions (-1 by default) before the JobFlags. |
113 | */ |
114 | FileCopyJob *file_copy(const QUrl &src, const QUrl &dest, JobFlags flags) Q_DECL_EQ_DELETE; // not implemented - on purpose. |
115 | |
116 | /** |
117 | * Move a single file. |
118 | * |
119 | * Use either WorkerBase::rename() if the worker supports that, |
120 | * or copy() and del() otherwise, or eventually get() & put() & del() |
121 | * |
122 | * @param src Where to get the file |
123 | * @param dest Where to put the file |
124 | * @param permissions the file mode permissions to set on @p dest; if this is -1 |
125 | * (the default), no special permissions are set on @p dest, i.e. it'll have |
126 | * the default system permissions for newly created files, and the owner and group |
127 | * permissions are not preserved. |
128 | * @param flags Can be HideProgressInfo, Overwrite and Resume here |
129 | * WARNING: Setting @ref JobFlag::Resume means that the data will be appended to |
130 | * @p dest if @p dest exists |
131 | * @return the job handling the operation |
132 | */ |
133 | KIOCORE_EXPORT FileCopyJob *file_move(const QUrl &src, const QUrl &dest, int permissions = -1, JobFlags flags = DefaultFlags); |
134 | |
135 | /** |
136 | * Overload for catching code mistakes. Do NOT call this method (it is not implemented), |
137 | * insert a value for permissions (-1 by default) before the JobFlags. |
138 | */ |
139 | FileCopyJob *file_move(const QUrl &src, const QUrl &dest, JobFlags flags) Q_DECL_EQ_DELETE; // not implemented - on purpose. |
140 | |
141 | } |
142 | |
143 | #endif |
144 | |