9#include "clipboardupdater_p.h"
12#include "filecopyjob.h"
14#include <KUrlMimeData>
17#include <QGuiApplication>
22static void overwriteUrlsInClipboard(
KJob *job)
24 CopyJob *copyJob = qobject_cast<CopyJob *>(job);
25 FileCopyJob *fileCopyJob = qobject_cast<FileCopyJob *>(job);
27 if (!copyJob && !fileCopyJob) {
34 const auto srcUrls = copyJob->
srcUrls();
35 newUrls.
reserve(srcUrls.size());
36 for (
const QUrl &url : srcUrls) {
38 dUrl.
setPath(Utils::concatPaths(dUrl.
path(), url.fileName()));
41 }
else if (fileCopyJob) {
42 newUrls << fileCopyJob->
destUrl();
50static void updateUrlsInClipboard(
KJob *job)
52 CopyJob *copyJob = qobject_cast<CopyJob *>(job);
53 FileCopyJob *fileCopyJob = qobject_cast<FileCopyJob *>(job);
55 if (!copyJob && !fileCopyJob) {
60 auto mimeData = clipboard->
mimeData();
70 for (
const QUrl &url : urls) {
71 const int index = clipboardUrls.
indexOf(url);
74 dUrl.
setPath(Utils::concatPaths(dUrl.
path(), url.fileName()));
75 clipboardUrls.
replace(index, dUrl);
79 }
else if (fileCopyJob) {
80 const int index = clipboardUrls.
indexOf(fileCopyJob->
srcUrl());
94static void removeUrlsFromClipboard(
KJob *job)
96 SimpleJob *simpleJob = qobject_cast<SimpleJob *>(job);
97 DeleteJob *deleteJob = qobject_cast<DeleteJob *>(job);
99 if (!simpleJob && !deleteJob) {
105 deletedUrls << simpleJob->
url();
106 }
else if (deleteJob) {
107 deletedUrls << deleteJob->
urls();
115 auto mimeData = clipboard->
mimeData();
121 quint32 removedCount = 0;
123 for (
const QUrl &url : std::as_const(deletedUrls)) {
124 removedCount += clipboardUrls.
removeAll(url);
127 if (removedCount > 0) {
129 if (!clipboardUrls.
isEmpty()) {
136void ClipboardUpdater::slotResult(
KJob *job)
143 case JobUiDelegateExtension::UpdateContent:
144 updateUrlsInClipboard(job);
146 case JobUiDelegateExtension::OverwriteContent:
147 overwriteUrlsInClipboard(job);
149 case JobUiDelegateExtension::RemoveContent:
150 removeUrlsFromClipboard(job);
155void ClipboardUpdater::setMode(JobUiDelegateExtension::ClipboardUpdaterMode mode)
160void ClipboardUpdater::update(
const QUrl &srcUrl,
const QUrl &destUrl)
163 auto mimeData = clipboard->
mimeData();
164 if (mimeData && mimeData->hasUrls()) {
166 const int index = clipboardUrls.
indexOf(srcUrl);
168 clipboardUrls.
replace(index, destUrl);
176ClipboardUpdater::ClipboardUpdater(
Job *job, JobUiDelegateExtension::ClipboardUpdaterMode mode)
184#include "moc_clipboardupdater_p.cpp"
CopyJob is used to move, copy or symlink files and directories.
QList< QUrl > srcUrls() const
Returns the list of source URLs.
QUrl destUrl() const
Returns the destination URL.
A more complex Job to delete files and directories.
QList< QUrl > urls() const
Returns the list of URLs.
The FileCopyJob copies data from one place to another.
QUrl destUrl() const
Returns the destination URL.
QUrl srcUrl() const
Returns the source URL.
The base class for all jobs.
A simple job (one url and one command).
const QUrl & url() const
Returns the SimpleJob's URL.
void update(Part *part, const QByteArray &data, qint64 dataSize)
A namespace for KIO globals.
KCOREADDONS_EXPORT QList< QUrl > urlsFromMimeData(const QMimeData *mimeData, DecodeOptions decodeOptions=PreferKdeUrls, MetaDataMap *metaData=nullptr)
const QMimeData * mimeData(Mode mode) const const
void setMimeData(QMimeData *src, Mode mode)
void append(QList< T > &&value)
qsizetype indexOf(const AT &value, qsizetype from) const const
bool isEmpty() const const
qsizetype removeAll(const AT &t)
void replace(qsizetype i, parameter_type value)
void reserve(qsizetype size)
void setUrls(const QList< QUrl > &urls)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QUrl adjusted(FormattingOptions options) const const
QString path(ComponentFormattingOptions options) const const
void setPath(const QString &path, ParsingMode mode)