File indexing completed on 2024-04-14 03:52:52

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org>
0004     SPDX-FileCopyrightText: 2000-2009 David Faure <faure@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef KIO_FILECOPYJOB_H
0010 #define KIO_FILECOPYJOB_H
0011 
0012 #include "job_base.h"
0013 #include <kio/global.h> // filesize_t
0014 
0015 namespace KIO
0016 {
0017 class FileCopyJobPrivate;
0018 /**
0019  * @class KIO::FileCopyJob filecopyjob.h <KIO/FileCopyJob>
0020  *
0021  * The FileCopyJob copies data from one place to another.
0022  * @see KIO::file_copy()
0023  * @see KIO::file_move()
0024  */
0025 class KIOCORE_EXPORT FileCopyJob : public Job
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     ~FileCopyJob() override;
0031     /**
0032      * If you know the size of the source file, call this method
0033      * to inform this job. It will be displayed in the "resume" dialog.
0034      * @param size the size of the source file
0035      */
0036     void setSourceSize(KIO::filesize_t size);
0037 
0038     /**
0039      * Sets the modification time of the file
0040      *
0041      * Note that this is ignored if a direct copy (WorkerBase::copy) can be done,
0042      * in which case the mtime of the source is applied to the destination (if the protocol
0043      * supports the concept).
0044      */
0045     void setModificationTime(const QDateTime &mtime);
0046 
0047     /**
0048      * Returns the source URL.
0049      * @return the source URL
0050      */
0051     QUrl srcUrl() const;
0052 
0053     /**
0054      * Returns the destination URL.
0055      * @return the destination URL
0056      */
0057     QUrl destUrl() const;
0058 
0059     bool doSuspend() override;
0060     bool doResume() override;
0061     bool doKill() override;
0062 
0063 Q_SIGNALS:
0064     /**
0065      * MIME type determined during a file copy.
0066      * This is never emitted during a move, and might not be emitted during
0067      * a file copy, depending on the worker. But when a get and a put are
0068      * being used (which is the common case), this signal forwards the
0069      * MIME type information from the get job.
0070      *
0071      * @param job the job that emitted this signal
0072      * @param mimeType the MIME type
0073      * @since 5.78
0074      */
0075     void mimeTypeFound(KIO::Job *job, const QString &mimeType);
0076 
0077 protected Q_SLOTS:
0078     /**
0079      * Called whenever a subjob finishes.
0080      * @param job the job that emitted this signal
0081      */
0082     void slotResult(KJob *job) override;
0083 
0084 protected:
0085     KIOCORE_NO_EXPORT explicit FileCopyJob(FileCopyJobPrivate &dd);
0086 
0087 private:
0088     Q_DECLARE_PRIVATE(FileCopyJob)
0089 };
0090 
0091 /**
0092  * Copy a single file.
0093  *
0094  * Uses either WorkerBase::copy() if the worker supports that
0095  * or get() and put() otherwise.
0096  *
0097  * @param src Where to get the file
0098  * @param dest Where to put the file
0099  * @param permissions the file mode permissions to set on @p dest; if this is -1
0100  * (the default) no special permissions will be set on @p dest, i.e. it'll have
0101  * the default system permissions for newly created files, and the owner and group
0102  * permissions are not preserved.
0103  * @param flags Can be @ref JobFlag::HideProgressInfo, Overwrite and Resume here
0104  * WARNING: Setting @ref JobFlag::Resume means that the data will be appended to
0105  * @p dest if @p dest exists
0106  * @return the job handling the operation
0107  */
0108 KIOCORE_EXPORT FileCopyJob *file_copy(const QUrl &src, const QUrl &dest, int permissions = -1, JobFlags flags = DefaultFlags);
0109 
0110 /**
0111  * Overload for catching code mistakes. Do NOT call this method (it is not implemented),
0112  * insert a value for permissions (-1 by default) before the JobFlags.
0113  */
0114 FileCopyJob *file_copy(const QUrl &src, const QUrl &dest, JobFlags flags) Q_DECL_EQ_DELETE; // not implemented - on purpose.
0115 
0116 /**
0117  * Move a single file.
0118  *
0119  * Use either WorkerBase::rename() if the worker supports that,
0120  * or copy() and del() otherwise, or eventually get() & put() & del()
0121  *
0122  * @param src Where to get the file
0123  * @param dest Where to put the file
0124  * @param permissions the file mode permissions to set on @p dest; if this is -1
0125  * (the default), no special permissions are set on @p dest, i.e. it'll have
0126  * the default system permissions for newly created files, and the owner and group
0127  * permissions are not preserved.
0128  * @param flags Can be HideProgressInfo, Overwrite and Resume here
0129  * WARNING: Setting @ref JobFlag::Resume means that the data will be appended to
0130  * @p dest if @p dest exists
0131  * @return the job handling the operation
0132  */
0133 KIOCORE_EXPORT FileCopyJob *file_move(const QUrl &src, const QUrl &dest, int permissions = -1, JobFlags flags = DefaultFlags);
0134 
0135 /**
0136  * Overload for catching code mistakes. Do NOT call this method (it is not implemented),
0137  * insert a value for permissions (-1 by default) before the JobFlags.
0138  */
0139 FileCopyJob *file_move(const QUrl &src, const QUrl &dest, JobFlags flags) Q_DECL_EQ_DELETE; // not implemented - on purpose.
0140 
0141 }
0142 
0143 #endif