| 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 |
| 20 | * \inheaderfile KIO/FileCopyJob |
| 21 | * \inmodule KIOCore |
| 22 | * |
| 23 | * The FileCopyJob copies data from one place to another. |
| 24 | * |
| 25 | * \sa KIO::file_copy() |
| 26 | * \sa KIO::file_move() |
| 27 | */ |
| 28 | class KIOCORE_EXPORT FileCopyJob : public Job |
| 29 | { |
| 30 | Q_OBJECT |
| 31 | |
| 32 | public: |
| 33 | ~FileCopyJob() override; |
| 34 | /*! |
| 35 | * If you know the size of the source file, call this method |
| 36 | * to inform this job. It will be displayed in the "resume" dialog. |
| 37 | * |
| 38 | * \a size the size of the source file |
| 39 | */ |
| 40 | void setSourceSize(KIO::filesize_t size); |
| 41 | |
| 42 | /*! |
| 43 | * Sets the modification time of the file |
| 44 | * |
| 45 | * Note that this is ignored if a direct copy (WorkerBase::copy) can be done, |
| 46 | * in which case the mtime of the source is applied to the destination (if the protocol |
| 47 | * supports the concept). |
| 48 | */ |
| 49 | void setModificationTime(const QDateTime &mtime); |
| 50 | |
| 51 | /*! |
| 52 | * Returns the source URL |
| 53 | */ |
| 54 | QUrl srcUrl() const; |
| 55 | |
| 56 | /*! |
| 57 | * Returns the destination URL |
| 58 | */ |
| 59 | QUrl destUrl() const; |
| 60 | |
| 61 | bool doSuspend() override; |
| 62 | bool doResume() override; |
| 63 | bool doKill() override; |
| 64 | |
| 65 | Q_SIGNALS: |
| 66 | /*! |
| 67 | * MIME type determined during a file copy. |
| 68 | * This is never emitted during a move, and might not be emitted during |
| 69 | * a file copy, depending on the worker. But when a get and a put are |
| 70 | * being used (which is the common case), this signal forwards the |
| 71 | * MIME type information from the get job. |
| 72 | * |
| 73 | * \a job the job that emitted this signal |
| 74 | * |
| 75 | * \a mimeType the MIME type |
| 76 | * |
| 77 | * \since 5.78 |
| 78 | */ |
| 79 | void mimeTypeFound(KIO::Job *job, const QString &mimeType); |
| 80 | |
| 81 | protected Q_SLOTS: |
| 82 | /*! |
| 83 | * Called whenever a subjob finishes. |
| 84 | * |
| 85 | * \a job the job that emitted this signal |
| 86 | */ |
| 87 | void slotResult(KJob *job) override; |
| 88 | |
| 89 | protected: |
| 90 | KIOCORE_NO_EXPORT explicit FileCopyJob(FileCopyJobPrivate &dd); |
| 91 | |
| 92 | private: |
| 93 | Q_DECLARE_PRIVATE(FileCopyJob) |
| 94 | }; |
| 95 | |
| 96 | /*! |
| 97 | * \relates KIO::FileCopyJob |
| 98 | * |
| 99 | * Copy a single file. |
| 100 | * |
| 101 | * Uses either WorkerBase::copy() if the worker supports that |
| 102 | * or get() and put() otherwise. |
| 103 | * |
| 104 | * \a src Where to get the file |
| 105 | * |
| 106 | * \a dest Where to put the file |
| 107 | * |
| 108 | * \a permissions the file mode permissions to set on \a dest; if this is -1 |
| 109 | * (the default) no special permissions will be set on \a dest, i.e. it'll have |
| 110 | * the default system permissions for newly created files, and the owner and group |
| 111 | * permissions are not preserved. |
| 112 | * |
| 113 | * \a flags Can be JobFlag::HideProgressInfo, Overwrite and Resume here |
| 114 | * WARNING: Setting JobFlag::Resume means that the data will be appended to |
| 115 | * \a dest if \a dest exists |
| 116 | * |
| 117 | * Returns the job handling the operation |
| 118 | */ |
| 119 | KIOCORE_EXPORT FileCopyJob *file_copy(const QUrl &src, const QUrl &dest, int permissions = -1, JobFlags flags = DefaultFlags); |
| 120 | |
| 121 | /*! |
| 122 | * \relates KIO::FileCopyJob |
| 123 | * |
| 124 | * Overload for catching code mistakes. Do NOT call this method (it is not implemented), |
| 125 | * insert a value for permissions (-1 by default) before the JobFlags. |
| 126 | */ |
| 127 | FileCopyJob *file_copy(const QUrl &src, const QUrl &dest, JobFlags flags) Q_DECL_EQ_DELETE; // not implemented - on purpose. |
| 128 | |
| 129 | /*! |
| 130 | * \relates KIO::FileCopyJob |
| 131 | * |
| 132 | * Move a single file. |
| 133 | * |
| 134 | * Use either WorkerBase::rename() if the worker supports that, |
| 135 | * or copy() and del() otherwise, or eventually get() & put() & del() |
| 136 | * |
| 137 | * \a src Where to get the file |
| 138 | * |
| 139 | * \a dest Where to put the file |
| 140 | * |
| 141 | * \a permissions the file mode permissions to set on \a dest; if this is -1 |
| 142 | * (the default), no special permissions are set on \a 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 | * |
| 146 | * \a flags Can be HideProgressInfo, Overwrite and Resume here |
| 147 | * WARNING: Setting JobFlag::Resume means that the data will be appended to |
| 148 | * \a dest if \a dest exists |
| 149 | * |
| 150 | * Returns the job handling the operation |
| 151 | */ |
| 152 | KIOCORE_EXPORT FileCopyJob *file_move(const QUrl &src, const QUrl &dest, int permissions = -1, JobFlags flags = DefaultFlags); |
| 153 | |
| 154 | /* |
| 155 | * Overload for catching code mistakes. Do NOT call this method (it is not implemented), |
| 156 | * insert a value for permissions (-1 by default) before the JobFlags. |
| 157 | */ |
| 158 | FileCopyJob *file_move(const QUrl &src, const QUrl &dest, JobFlags flags) Q_DECL_EQ_DELETE; // not implemented - on purpose. |
| 159 | |
| 160 | } |
| 161 | |
| 162 | #endif |
| 163 | |