KIO::CopyJob Class
class KIO::CopyJobCopyJob is used to move, copy or symlink files and directories. More...
Header: | #include <KIO/CopyJob> |
CMake: | find_package(KF6 REQUIRED COMPONENTS KIO) target_link_libraries(mytarget PRIVATE KF6::KIOCore) |
Inherits: | KIO::Job |
Public Types
enum | CopyMode { Copy, Move, Link } |
Public Functions
QUrl | destUrl() const |
KIO::CopyJob::CopyMode | operationMode() const |
(since 4.7) void | setAutoRename(bool autoRename) |
(since 4.2) void | setAutoSkip(bool autoSkip) |
void | setDefaultPermissions(bool b) |
(since 4.2) void | setWriteIntoExistingDirectories(bool overwriteAllDirs) |
QList<QUrl> | srcUrls() const |
Reimplemented Public Functions
Signals
void | copying(KIO::Job *job, const QUrl &src, const QUrl &dest) |
void | copyingDone(KIO::Job *job, const QUrl &from, const QUrl &to, const QDateTime &mtime, bool directory, bool renamed) |
void | copyingLinkDone(KIO::Job *job, const QUrl &from, const QString &target, const QUrl &to) |
void | creatingDir(KIO::Job *job, const QUrl &dir) |
void | linking(KIO::Job *job, const QString &target, const QUrl &to) |
void | moving(KIO::Job *job, const QUrl &from, const QUrl &to) |
void | processedDirs(KIO::Job *job, unsigned long dirs) |
void | processedFiles(KIO::Job *job, unsigned long files) |
void | renamed(KIO::Job *job, const QUrl &from, const QUrl &to) |
Protected Slots
virtual void | slotResult(KJob *job) override |
Related Non-Members
KIO::CopyJob * | copy(const QList<QUrl> &src, const QUrl &dest, KIO::JobFlags flags = DefaultFlags) |
KIO::CopyJob * | copy(const QUrl &src, const QUrl &dest, KIO::JobFlags flags = DefaultFlags) |
KIO::CopyJob * | copyAs(const QUrl &src, const QUrl &dest, KIO::JobFlags flags = DefaultFlags) |
KIO::CopyJob * | link(const QList<QUrl> &src, const QUrl &destDir, KIO::JobFlags flags = DefaultFlags) |
KIO::CopyJob * | link(const QUrl &src, const QUrl &destDir, KIO::JobFlags flags = DefaultFlags) |
KIO::CopyJob * | linkAs(const QUrl &src, const QUrl &dest, KIO::JobFlags flags = DefaultFlags) |
KIO::CopyJob * | move(const QList<QUrl> &src, const QUrl &dest, KIO::JobFlags flags = DefaultFlags) |
KIO::CopyJob * | move(const QUrl &src, const QUrl &dest, KIO::JobFlags flags = DefaultFlags) |
KIO::CopyJob * | moveAs(const QUrl &src, const QUrl &dest, KIO::JobFlags flags = DefaultFlags) |
KIO::CopyJob * | trash(const QList<QUrl> &src, KIO::JobFlags flags = DefaultFlags) |
KIO::CopyJob * | trash(const QUrl &src, KIO::JobFlags flags = DefaultFlags) |
Detailed Description
Don't create the job directly, but use KIO::copy(), KIO::move(), KIO::link() and friends.
See also copy(), copyAs(), move(), moveAs(), link(), and linkAs().
Member Type Documentation
enum CopyJob::CopyMode
Defines the mode of the operation
Constant | Value |
---|---|
KIO::CopyJob::Copy | 0 |
KIO::CopyJob::Move | 1 |
KIO::CopyJob::Link | 2 |
Member Function Documentation
[signal]
void CopyJob::copying(KIO::Job *job, const QUrl &src, const QUrl &dest)
The job is copying a file or directory.
Note: This signal is used for progress dialogs, it's not emitted for every file or directory (this would be too slow), but every 200ms.
job the job that emitted this signal
src the URL of the file or directory that is currently being copied
dest the destination of the current operation
[signal]
void CopyJob::copyingDone(KIO::Job *job, const QUrl &from, const QUrl &to, const QDateTime &mtime, bool directory, bool renamed)
The job emits this signal when copying or moving a file or directory successfully finished. This signal is mainly for the Undo feature. If you simply want to know when a copy job is done, use result().
job the job that emitted this signal
from the source URL
to the destination URL
mtime the modification time of the source file, hopefully set on the destination file too (when the KIO worker supports it).
directory indicates whether a file or directory was successfully copied/moved. true for a directory, false for file
renamed indicates that the destination URL was created using a rename operation (i.e. fast directory moving). true if is has been renamed
[signal]
void CopyJob::copyingLinkDone(KIO::Job *job, const QUrl &from, const QString &target, const QUrl &to)
The job is copying or moving a symbolic link, that points to target. The new link is created in to. The existing one is/was in from. This signal is mainly for the Undo feature.
job the job that emitted this signal
from the source URL
target the target
to the destination URL
[signal]
void CopyJob::creatingDir(KIO::Job *job, const QUrl &dir)
The job is creating the directory dir.
This signal is emitted for every directory being created.
job the job that emitted this signal
dir the directory that is currently being created
QUrl CopyJob::destUrl() const
Returns the destination URL.
[override virtual]
bool CopyJob::doResume()
Reimplements: Job::doResume().
[override virtual]
bool CopyJob::doSuspend()
Reimplements: Job::doSuspend().
[signal]
void CopyJob::linking(KIO::Job *job, const QString &target, const QUrl &to)
The job is creating a symbolic link.
Note: This signal is used for progress dialogs, it's not emitted for every file or directory (this would be too slow), but every 200ms.
job the job that emitted this signal
target the URL of the file or directory that is currently being linked
to the destination of the current operation
[signal]
void CopyJob::moving(KIO::Job *job, const QUrl &from, const QUrl &to)
The job is moving a file or directory.
Note: This signal is used for progress dialogs, it's not emitted for every file or directory (this would be too slow), but every 200ms.
job the job that emitted this signal
from the URL of the file or directory that is currently being moved
to the destination of the current operation
KIO::CopyJob::CopyMode CopyJob::operationMode() const
Returns the mode of the operation (copy, move, or link), depending on whether KIO::copy(), KIO::move() or KIO::link() was called.
[signal]
void CopyJob::processedDirs(KIO::Job *job, unsigned long dirs)
Sends the number of processed directories.
job the job that emitted this signal
dirs the number of processed dirs
[signal]
void CopyJob::processedFiles(KIO::Job *job, unsigned long files)
Sends the number of processed files.
job the job that emitted this signal
files the number of processed files
[signal]
void CopyJob::renamed(KIO::Job *job, const QUrl &from, const QUrl &to)
The user chose to rename from to to.
job the job that emitted this signal
from the original name
to the new name
[since 4.7]
void CopyJob::setAutoRename(bool autoRename)
Rename files automatically when the destination already exists, instead of the default behavior (interactive mode: showing a dialog to the user, non-interactive mode: aborting with an error). Initially added for a unit test.
This function was introduced in 4.7.
[since 4.2]
void CopyJob::setAutoSkip(bool autoSkip)
Skip copying or moving any file when the destination already exists, instead of the default behavior (interactive mode: showing a dialog to the user, non-interactive mode: aborting with an error). Initially added for a unit test.
This function was introduced in 4.2.
void CopyJob::setDefaultPermissions(bool b)
By default the permissions of the copied files will be those of the source files.
But when copying "template" files to "new" files, people prefer the umask to apply, rather than the template's permissions. For that case, call setDefaultPermissions(true)
[since 4.2]
void CopyJob::setWriteIntoExistingDirectories(bool overwriteAllDirs)
Reuse any directory that already exists, instead of the default behavior (interactive mode: showing a dialog to the user, non-interactive mode: aborting with an error).
This function was introduced in 4.2.
[override virtual protected slot]
void CopyJob::slotResult(KJob *job)
Reimplements: KCompositeJob::slotResult(KJob *job).
QList<QUrl> CopyJob::srcUrls() const
Returns the list of source URLs.
Related Non-Members
KIO::CopyJob *copy(const QList<QUrl> &src, const QUrl &dest, KIO::JobFlags flags = DefaultFlags)
Copy a list of file/dirs src into a destination directory dest.
src the list of files and/or directories
dest the destination
flags copy() supports HideProgressInfo and Overwrite. Note: Overwrite has the meaning of both "write into existing directories" and "overwrite existing files". However if "dest" exists, then src is copied into a subdir of dest, just like "cp" does.
Returns the job handling the operation
KIO::CopyJob *copy(const QUrl &src, const QUrl &dest, KIO::JobFlags flags = DefaultFlags)
Copy a file or directory src into the destination dest, which can be a file (including the final filename) or a directory (into which src will be copied).
This emulates the cp command completely.
src the file or directory to copy dest the destination flags copy() supports HideProgressInfo and Overwrite. Note: Overwrite has the meaning of both "write into existing directories" and "overwrite existing files". However if "dest" exists, then src is copied into a subdir of dest, just like "cp" does. Use copyAs if you don't want that.
Returns the job handling the operation
See also copyAs().
KIO::CopyJob *copyAs(const QUrl &src, const QUrl &dest, KIO::JobFlags flags = DefaultFlags)
Copy a file or directory src into the destination dest, which is the destination name in any case, even for a directory.
As opposed to copy(), this doesn't emulate cp, but is the only way to copy a directory, giving it a new name and getting an error box if a directory already exists with the same name (or writing the contents of src into dest, when using Overwrite).
src the file or directory to copy dest the destination flags copyAs() supports HideProgressInfo and Overwrite.
Note: Overwrite has the meaning of both "write into existing directories" and "overwrite existing files".
Returns the job handling the operation
KIO::CopyJob *link(const QList<QUrl> &src, const QUrl &destDir, KIO::JobFlags flags = DefaultFlags)
Create several links If the protocols and hosts are the same, a Unix symlink will be created. Otherwise, a .desktop file of Type Link and pointing to the src URL will be created.
src The existing files or directories, 'targets' of the link.
destDir Destination directory where the links will be created.
flags link() supports HideProgressInfo only
Returns the job handling the operation
KIO::CopyJob *link(const QUrl &src, const QUrl &destDir, KIO::JobFlags flags = DefaultFlags)
Create a link. If the protocols and hosts are the same, a Unix symlink will be created. Otherwise, a .desktop file of Type Link and pointing to the src URL will be created.
src The existing file or directory, 'target' of the link.
destDir Destination directory where the link will be created.
flags link() supports HideProgressInfo only
Returns the job handling the operation
KIO::CopyJob *linkAs(const QUrl &src, const QUrl &dest, KIO::JobFlags flags = DefaultFlags)
Create a link. Unlike link() this operation will fail when dest is an existing directory rather than the final name for the link. If the protocols and hosts are the same, a Unix symlink will be created. Otherwise, a .desktop file of Type Link and pointing to the src URL will be created.
src The existing file or directory, 'target' of the link.
dest Destination (i.e. the final symlink)
flags linkAs() supports HideProgressInfo only
Returns the job handling the operation
KIO::CopyJob *move(const QList<QUrl> &src, const QUrl &dest, KIO::JobFlags flags = DefaultFlags)
Moves a list of files or directories src to the given destination dest.
src the list of files or directories to copy
dest the destination
flags move() supports HideProgressInfo and Overwrite. Note: Overwrite has the meaning of both "write into existing directories" and "overwrite existing files". However if "dest" exists, then src is copied into a subdir of dest, just like "cp" does.
Returns the job handling the operation
See also copy().
KIO::CopyJob *move(const QUrl &src, const QUrl &dest, KIO::JobFlags flags = DefaultFlags)
Moves a file or directory src to the given destination dest.
src the file or directory to copy
dest the destination
flags move() supports HideProgressInfo and Overwrite. Note: Overwrite has the meaning of both "write into existing directories" and "overwrite existing files". However if "dest" exists, then src is copied into a subdir of dest, just like "cp" does.
Returns the job handling the operation
KIO::CopyJob *moveAs(const QUrl &src, const QUrl &dest, KIO::JobFlags flags = DefaultFlags)
Moves a file or directory src to the given destination dest. Unlike move() this operation will not move src into dest when dest exists: it will either fail, or move the contents of src into it if Overwrite is set.
src the file or directory to copy
dest the destination
flags moveAs() supports HideProgressInfo and Overwrite. Note: Overwrite has the meaning of both "write into existing directories" and "overwrite existing files".
Returns the job handling the operation
See also copyAs().
KIO::CopyJob *trash(const QList<QUrl> &src, KIO::JobFlags flags = DefaultFlags)
Trash a list of files or directories. This is currently only supported for local files and directories.
src the files to delete
flags trash() supports HideProgressInfo only
Returns the job handling the operation
KIO::CopyJob *trash(const QUrl &src, KIO::JobFlags flags = DefaultFlags)
Trash a file or directory. This is currently only supported for local files and directories. Use QUrl::fromLocalFile to create a URL from a local file path.
src file to delete
flags trash() supports HideProgressInfo only
Returns the job handling the operation