KIO

mkdirjob.cpp
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org>
4 SPDX-FileCopyrightText: 2000-2009 David Faure <faure@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "mkdirjob.h"
10#include "job.h"
11#include "job_p.h"
12#include "kiocoredebug.h"
13#include <kurlauthorized.h>
14#include <worker_p.h>
15
16using namespace KIO;
17
18class KIO::MkdirJobPrivate : public SimpleJobPrivate
19{
20public:
21 MkdirJobPrivate(const QUrl &url, int command, const QByteArray &packedArgs)
22 : SimpleJobPrivate(url, command, packedArgs)
23 {
24 }
25 QUrl m_redirectionURL;
26 void slotRedirection(const QUrl &url);
27
28 /**
29 * @internal
30 * Called by the scheduler when a @p worker gets to
31 * work on this job.
32 * @param worker the worker that starts working on this job
33 */
34 void start(Worker *worker) override;
35
36 Q_DECLARE_PUBLIC(MkdirJob)
37
38 static inline MkdirJob *newJob(const QUrl &url, int command, const QByteArray &packedArgs)
39 {
40 MkdirJob *job = new MkdirJob(*new MkdirJobPrivate(url, command, packedArgs));
42 return job;
43 }
44};
45
46MkdirJob::MkdirJob(MkdirJobPrivate &dd)
47 : SimpleJob(dd)
48{
49}
50
51MkdirJob::~MkdirJob()
52{
53}
54
55void MkdirJobPrivate::start(Worker *worker)
56{
57 Q_Q(MkdirJob);
58 q->connect(worker, &KIO::WorkerInterface::redirection, q, [this](const QUrl &url) {
59 slotRedirection(url);
60 });
61
62 SimpleJobPrivate::start(worker);
63}
64
65// Worker got a redirection request
66void MkdirJobPrivate::slotRedirection(const QUrl &url)
67{
68 Q_Q(MkdirJob);
69 // qDebug() << url;
70 if (!KUrlAuthorized::authorizeUrlAction(QStringLiteral("redirect"), m_url, url)) {
71 qCWarning(KIO_CORE) << "Redirection from" << m_url << "to" << url << "REJECTED!";
72 q->setError(ERR_ACCESS_DENIED);
73 q->setErrorText(url.toDisplayString());
74 return;
75 }
76 m_redirectionURL = url; // We'll remember that when the job finishes
77 // Tell the user that we haven't finished yet
78 Q_EMIT q->redirection(q, m_redirectionURL);
79}
80
81void MkdirJob::slotFinished()
82{
84
85 if (!d->m_redirectionURL.isEmpty() && d->m_redirectionURL.isValid()) {
86 // qDebug() << "MkdirJob: Redirection to " << m_redirectionURL;
87 if (queryMetaData(QStringLiteral("permanent-redirect")) == QLatin1String("true")) {
88 Q_EMIT permanentRedirection(this, d->m_url, d->m_redirectionURL);
89 }
90
91 if (d->m_redirectionHandlingEnabled) {
92 QUrl dummyUrl;
93 int permissions;
94 QDataStream istream(d->m_packedArgs);
95 istream >> dummyUrl >> permissions;
96
97 d->m_packedArgs.truncate(0);
98 QDataStream stream(&d->m_packedArgs, QIODevice::WriteOnly);
99 stream << d->m_redirectionURL << permissions;
100
101 d->restartAfterRedirection(&d->m_redirectionURL);
102 return;
103 }
104 }
105
106 // Return worker to the scheduler
108}
109
110KIO::MkdirJob *KIO::mkdir(const QUrl &url, int permissions)
111{
112 // qDebug() << "mkdir " << url;
113 KIO_ARGS << url << permissions;
114 return MkdirJobPrivate::newJob(url, CMD_MKDIR, packedArgs);
115}
116
117#include "moc_mkdirjob.cpp"
QString queryMetaData(const QString &key)
Query meta data received from the worker.
Definition job.cpp:210
A KIO job that creates a directory.
void permanentRedirection(KIO::Job *job, const QUrl &fromUrl, const QUrl &toUrl)
Signals a permanent redirection.
A simple job (one url and one command).
virtual void slotFinished()
Called when the worker marks the job as finished.
void setUiDelegate(KJobUiDelegate *delegate)
Q_SCRIPTABLE Q_NOREPLY void start()
A namespace for KIO globals.
KIOCORE_EXPORT MkdirJob * mkdir(const QUrl &url, int permissions=-1)
Creates a single directory.
Definition mkdirjob.cpp:110
KIOCORE_EXPORT KJobUiDelegate * createDefaultJobUiDelegate()
Convenience method: use default factory, if there's one, to create a delegate and return it.
bool authorizeUrlAction(const QString &action, const QUrl &baseURL, const QUrl &destURL)
Returns whether a certain URL related action is authorized.
Q_EMITQ_EMIT
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:09:38 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.