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 (SlaveBase::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 slave. 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 slave. 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     FileCopyJob(FileCopyJobPrivate &dd);
102 
103 private:
104     Q_DECLARE_PRIVATE(FileCopyJob)
105 };
106 
107 /**
108  * Copy a single file.
109  *
110  * Uses either SlaveBase::copy() if the slave 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.
118  * @param flags Can be @ref JobFlag::HideProgressInfo, Overwrite and Resume here
119  * WARNING: Setting @ref JobFlag::Resume means that the data will be appended to
120  * @p dest if @p dest exists
121  * @return the job handling the operation
122  */
123 KIOCORE_EXPORT FileCopyJob *file_copy(const QUrl &src, const QUrl &dest, int permissions = -1, JobFlags flags = DefaultFlags);
124 
125 /**
126  * Overload for catching code mistakes. Do NOT call this method (it is not implemented),
127  * insert a value for permissions (-1 by default) before the JobFlags.
128  * @since 4.5
129  */
130 FileCopyJob *file_copy(const QUrl &src, const QUrl &dest, JobFlags flags) Q_DECL_EQ_DELETE; // not implemented - on purpose.
131 
132 /**
133  * Move a single file.
134  *
135  * Use either SlaveBase::rename() if the slave supports that,
136  * or copy() and del() otherwise, or eventually get() & put() & del()
137  *
138  * @param src Where to get the file
139  * @param dest Where to put the file
140  * @param permissions the file mode permissions to set on @p dest; if this is -1
141  * (the default), no special permissions are set on @p dest, i.e. it'll have
142  * the default system permissions for newly created files.
143  * @param flags Can be HideProgressInfo, Overwrite and Resume here
144  * WARNING: Setting @ref JobFlag::Resume means that the data will be appended to
145  * @p dest if @p dest exists
146  * @return the job handling the operation
147  */
148 KIOCORE_EXPORT FileCopyJob *file_move(const QUrl &src, const QUrl &dest, int permissions = -1, JobFlags flags = DefaultFlags);
149 
150 /**
151  * Overload for catching code mistakes. Do NOT call this method (it is not implemented),
152  * insert a value for permissions (-1 by default) before the JobFlags.
153  * @since 4.3
154  */
155 FileCopyJob *file_move(const QUrl &src, const QUrl &dest, JobFlags flags) Q_DECL_EQ_DELETE; // not implemented - on purpose.
156 
157 }
158 
159 #endif
160