15#include <KLocalizedString>
16#include <KStringHandler>
19#include <kio/jobuidelegateextension.h>
25 , d_ptr(new JobPrivate)
31Job::Job(JobPrivate &dd)
47 return d->m_uiDelegateExtension;
53 d->m_uiDelegateExtension = extension;
75 job->setUiDelegateExtension(d->m_uiDelegateExtension);
86static QString url_description_string(
const QUrl &url)
91KIO::JobPrivate::~JobPrivate()
95void JobPrivate::emitMoving(KIO::Job *job,
const QUrl &src,
const QUrl &dest)
97 static const QString s_title =
i18nc(
"@title job",
"Moving");
98 static const QString s_source =
i18nc(
"The source of a file operation",
"Source");
99 static const QString s_destination =
i18nc(
"The destination of a file operation",
"Destination");
100 Q_EMIT job->
description(job, s_title, qMakePair(s_source, url_description_string(src)), qMakePair(s_destination, url_description_string(dest)));
103void JobPrivate::emitRenaming(KIO::Job *job,
const QUrl &src,
const QUrl &dest)
105 static const QString s_title =
i18nc(
"@title job",
"Renaming");
106 static const QString s_source =
i18nc(
"The source of a file operation",
"Source");
107 static const QString s_destination =
i18nc(
"The destination of a file operation",
"Destination");
108 Q_EMIT job->
description(job, s_title, {s_source, url_description_string(src)}, {s_destination, url_description_string(dest)});
111void JobPrivate::emitCopying(KIO::Job *job,
const QUrl &src,
const QUrl &dest)
113 static const QString s_title =
i18nc(
"@title job",
"Copying");
114 static const QString s_source =
i18nc(
"The source of a file operation",
"Source");
115 static const QString s_destination =
i18nc(
"The destination of a file operation",
"Destination");
116 Q_EMIT job->
description(job, s_title, qMakePair(s_source, url_description_string(src)), qMakePair(s_destination, url_description_string(dest)));
119void JobPrivate::emitCreatingDir(KIO::Job *job,
const QUrl &dir)
121 static const QString s_title =
i18nc(
"@title job",
"Creating directory");
122 static const QString s_directory =
i18n(
"Directory");
123 Q_EMIT job->
description(job, s_title, qMakePair(s_directory, url_description_string(dir)));
126void JobPrivate::emitDeleting(KIO::Job *job,
const QUrl &url)
128 static const QString s_title =
i18nc(
"@title job",
"Deleting");
129 static const QString s_file =
i18n(
"File");
130 Q_EMIT job->
description(job, s_title, qMakePair(s_file, url_description_string(url)));
133void JobPrivate::emitStating(KIO::Job *job,
const QUrl &url)
135 static const QString s_title =
i18nc(
"@title job",
"Examining");
136 static const QString s_file =
i18n(
"File");
137 Q_EMIT job->
description(job, s_title, qMakePair(s_file, url_description_string(url)));
140void JobPrivate::emitTransferring(KIO::Job *job,
const QUrl &url)
142 static const QString s_title =
i18nc(
"@title job",
"Transferring");
143 static const QString s_source =
i18nc(
"The source of a file operation",
"Source");
144 Q_EMIT job->
description(job, s_title, qMakePair(s_source, url_description_string(url)));
147void JobPrivate::emitMounting(KIO::Job *job,
const QString &dev,
const QString &point)
149 Q_EMIT job->
description(job,
i18nc(
"@title job",
"Mounting"), qMakePair(
i18n(
"Device"), dev), qMakePair(
i18n(
"Mountpoint"), point));
152void JobPrivate::emitUnmounting(KIO::Job *job,
const QString &point)
154 Q_EMIT job->
description(job,
i18nc(
"@title job",
"Unmounting"), qMakePair(
i18n(
"Mountpoint"), point));
161 job->
kill(KJob::Quietly);
195 Q_ASSERT(d->m_parentJob ==
nullptr);
197 d->m_parentJob = job;
202 return d_func()->m_parentJob;
207 return d_func()->m_incomingMetaData;
212 return d_func()->m_incomingMetaData.value(key,
QString());
218 d->m_outgoingMetaData = _metaData;
223 d_func()->m_outgoingMetaData.
insert(key, value);
229 for (
auto it = values.
cbegin(); it != values.
cend(); ++it) {
230 d->m_outgoingMetaData.insert(it.key(), it.value());
237 for (
auto it = values.
cbegin(); it != values.
cend(); ++it) {
239 if (!d->m_outgoingMetaData.contains(it.key())) {
240 d->m_outgoingMetaData.insert(it.key(), it.value());
247 return d_func()->m_outgoingMetaData;
250QByteArray JobPrivate::privilegeOperationData()
255 QByteArray jobData = m_parentJob->d_func()->privilegeOperationData();
257 m_incomingMetaData.
insert(QStringLiteral(
"TestData"), m_parentJob->queryMetaData(QStringLiteral(
"TestData")));
260 if (m_privilegeExecutionEnabled) {
261 status = OperationAllowed;
262 switch (m_operationType) {
264 m_title =
i18n(
"Change Attribute");
266 "Root privileges are required to change file attributes. "
267 "Do you want to continue?");
270 m_title =
i18n(
"Copy Files");
272 "Root privileges are required to complete the copy operation. "
273 "Do you want to continue?");
276 m_title =
i18n(
"Delete Files");
278 "Root privileges are required to complete the delete operation. "
279 "However, doing so may damage your system. Do you want to continue?");
282 m_title =
i18n(
"Create Folder");
284 "Root privileges are required to create this folder. "
285 "Do you want to continue?");
288 m_title =
i18n(
"Move Items");
290 "Root privileges are required to complete the move operation. "
291 "Do you want to continue?");
294 m_title =
i18n(
"Rename");
296 "Root privileges are required to complete renaming. "
297 "Do you want to continue?");
300 m_title =
i18n(
"Create Symlink");
302 "Root privileges are required to create a symlink. "
303 "Do you want to continue?");
306 m_title =
i18n(
"Transfer data");
308 "Root privileges are required to complete transferring data. "
309 "Do you want to continue?");
315 if (m_outgoingMetaData.value(QStringLiteral(
"UnitTesting")) == QLatin1String(
"true")) {
317 m_incomingMetaData.insert(QStringLiteral(
"TestData"), QStringLiteral(
"PrivilegeOperationAllowed"));
322 QByteArray parentJobData;
324 ds <<
status << m_title << m_message;
325 return parentJobData;
330class KIO::DirectCopyJobPrivate :
public KIO::SimpleJobPrivate
333 DirectCopyJobPrivate(
const QUrl &url,
int command,
const QByteArray &packedArgs)
334 : SimpleJobPrivate(url, command, packedArgs)
344 void start(Worker *worker)
override;
346 Q_DECLARE_PUBLIC(DirectCopyJob)
349DirectCopyJob::DirectCopyJob(
const QUrl &url,
const QByteArray &packedArgs)
350 :
SimpleJob(*new DirectCopyJobPrivate(url, CMD_COPY, packedArgs))
355DirectCopyJob::~DirectCopyJob()
359void DirectCopyJobPrivate::start(Worker *worker)
362 q->connect(worker, &WorkerInterface::canResume, q, &DirectCopyJob::slotCanResume);
363 SimpleJobPrivate::start(worker);
368 Q_EMIT canResume(
this, offset);
375 KIO_ARGS << src << qint8(
true);
376 SimpleJob *job = SimpleJobPrivate::newJob(src, CMD_DEL, packedArgs, flags);
386#include "moc_job_base.cpp"
387#include "moc_job_p.cpp"
virtual bool addSubjob(KJob *job)
const QList< KJob * > & subjobs() const
virtual bool removeSubjob(KJob *job)
An abstract class defining interaction with users from KIO jobs:
virtual ClipboardUpdater * createClipboardUpdater(Job *job, ClipboardUpdaterMode mode)
Creates a clipboard updater as a child of the given job.
The base class for all jobs.
void setMetaData(const KIO::MetaData &metaData)
Set meta data to be sent to the worker, replacing existing meta data.
bool doKill() override
Abort this job.
void setParentJob(Job *parentJob)
Set the parent Job.
Job * parentJob() const
Returns the parent job, if there is one.
void mergeMetaData(const QMap< QString, QString > &values)
Add key/value pairs to the meta data that is sent to the worker.
JobUiDelegateExtension * uiDelegateExtension() const
Retrieves the UI delegate extension used by this job.
void setUiDelegateExtension(JobUiDelegateExtension *extension)
Sets the UI delegate extension to be used by this job.
MetaData outgoingMetaData() const
QString queryMetaData(const QString &key)
Query meta data received from the worker.
bool removeSubjob(KJob *job) override
Mark a sub job as being done.
bool doSuspend() override
Suspend this job.
bool doResume() override
Resume this job.
bool addSubjob(KJob *job) override
Add a job that has to be finished before a result is emitted.
MetaData metaData() const
Get meta data received from the worker.
void addMetaData(const QString &key, const QString &value)
Add key/value pair to the meta data that is sent to the worker.
A simple job (one url and one command).
void description(KJob *job, const QString &title, const QPair< QString, QString > &field1=QPair< QString, QString >(), const QPair< QString, QString > &field2=QPair< QString, QString >())
KJob(QObject *parent=nullptr)
bool kill(KJob::KillVerbosity verbosity=KJob::Quietly)
void setUiDelegate(KJobUiDelegate *delegate)
void emitSpeed(unsigned long speed)
void speed(KJob *job, unsigned long speed)
Q_SCRIPTABLE CaptureState status()
Q_SCRIPTABLE Q_NOREPLY void start()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
A namespace for KIO globals.
KIOCORE_EXPORT SimpleJob * file_delete(const QUrl &src, JobFlags flags=DefaultFlags)
Delete a single file.
PrivilegeOperationStatus
Specifies privilege file operation status.
KIOCORE_EXPORT KJobUiDelegate * createDefaultJobUiDelegate()
Convenience method: use default factory, if there's one, to create a delegate and return it.
QFlags< JobFlag > JobFlags
Stores a combination of JobFlag values.
qulonglong filesize_t
64-bit file size
QByteArray & insert(qsizetype i, QByteArrayView data)
const_iterator cbegin() const const
const_iterator cend() const const
iterator insert(const Key &key, const T &value)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QVariant property(const char *name) const const
T qobject_cast(QObject *object)
bool setProperty(const char *name, QVariant &&value)
QString scheme() const const