File indexing completed on 2024-04-28 11:40:54

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 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 78)
0065     /**
0066      * MIME type determined during a file copy.
0067      * This is never emitted during a move, and might not be emitted during
0068      * a file copy, depending on the worker. But when a get and a put are
0069      * being used (which is the common case), this signal forwards the
0070      * MIME type information from the get job.
0071      *
0072      * @param job the job that emitted this signal
0073      * @param mimeType the MIME type
0074      * @deprecated Since 5.78, use mimeTypeFound(KIO::Job *, const QString &)
0075      */
0076     KIOCORE_DEPRECATED_VERSION(5, 78, "Use KIO::FileCopyJob::mimeTypeFound(KIO::Job *, const QString &)")
0077     void mimetype(KIO::Job *job, const QString &mimeType);
0078 #endif
0079 
0080     /**
0081      * MIME type determined during a file copy.
0082      * This is never emitted during a move, and might not be emitted during
0083      * a file copy, depending on the worker. But when a get and a put are
0084      * being used (which is the common case), this signal forwards the
0085      * MIME type information from the get job.
0086      *
0087      * @param job the job that emitted this signal
0088      * @param mimeType the MIME type
0089      * @since 5.78
0090      */
0091     void mimeTypeFound(KIO::Job *job, const QString &mimeType);
0092 
0093 protected Q_SLOTS:
0094     /**
0095      * Called whenever a subjob finishes.
0096      * @param job the job that emitted this signal
0097      */
0098     void slotResult(KJob *job) override;
0099 
0100 protected:
0101     KIOCORE_NO_EXPORT explicit FileCopyJob(FileCopyJobPrivate &dd);
0102 
0103 private:
0104     Q_DECLARE_PRIVATE(FileCopyJob)
0105 };
0106 
0107 /**
0108  * Copy a single file.
0109  *
0110  * Uses either WorkerBase::copy() if the worker supports that
0111  * or get() and put() otherwise.
0112  *
0113  * @param src Where to get the file
0114  * @param dest Where to put the file
0115  * @param permissions the file mode permissions to set on @p dest; if this is -1
0116  * (the default) no special permissions will be set on @p dest, i.e. it'll have
0117  * the default system permissions for newly created files, and the owner and group
0118  * permissions are not preserved.
0119  * @param flags Can be @ref JobFlag::HideProgressInfo, Overwrite and Resume here
0120  * WARNING: Setting @ref JobFlag::Resume means that the data will be appended to
0121  * @p dest if @p dest exists
0122  * @return the job handling the operation
0123  */
0124 KIOCORE_EXPORT FileCopyJob *file_copy(const QUrl &src, const QUrl &dest, int permissions = -1, JobFlags flags = DefaultFlags);
0125 
0126 /**
0127  * Overload for catching code mistakes. Do NOT call this method (it is not implemented),
0128  * insert a value for permissions (-1 by default) before the JobFlags.
0129  * @since 4.5
0130  */
0131 FileCopyJob *file_copy(const QUrl &src, const QUrl &dest, JobFlags flags) Q_DECL_EQ_DELETE; // not implemented - on purpose.
0132 
0133 /**
0134  * Move a single file.
0135  *
0136  * Use either WorkerBase::rename() if the worker supports that,
0137  * or copy() and del() otherwise, or eventually get() & put() & del()
0138  *
0139  * @param src Where to get the file
0140  * @param dest Where to put the file
0141  * @param permissions the file mode permissions to set on @p dest; if this is -1
0142  * (the default), no special permissions are set on @p dest, i.e. it'll have
0143  * the default system permissions for newly created files, and the owner and group
0144  * permissions are not preserved.
0145  * @param flags Can be HideProgressInfo, Overwrite and Resume here
0146  * WARNING: Setting @ref JobFlag::Resume means that the data will be appended to
0147  * @p dest if @p dest exists
0148  * @return the job handling the operation
0149  */
0150 KIOCORE_EXPORT FileCopyJob *file_move(const QUrl &src, const QUrl &dest, int permissions = -1, JobFlags flags = DefaultFlags);
0151 
0152 /**
0153  * Overload for catching code mistakes. Do NOT call this method (it is not implemented),
0154  * insert a value for permissions (-1 by default) before the JobFlags.
0155  * @since 4.3
0156  */
0157 FileCopyJob *file_move(const QUrl &src, const QUrl &dest, JobFlags flags) Q_DECL_EQ_DELETE; // not implemented - on purpose.
0158 
0159 }
0160 
0161 #endif