KIO

workerbase.cpp
1/*
2 SPDX-License-Identifier: LGPL-2.0-or-later
3 SPDX-FileCopyrightText: 2000 Waldo Bastian <bastian@kde.org>
4 SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org>
5 SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org>
6 SPDX-FileCopyrightText: 2007 Thiago Macieira <thiago@kde.org>
7 SPDX-FileCopyrightText: 2019-2022 Harald Sitter <sitter@kde.org>
8*/
9
10#include "workerbase.h"
11#include "workerbase_p.h"
12
13#include <commands_p.h>
14
15namespace KIO
16{
17
18WorkerBase::WorkerBase(const QByteArray &protocol, const QByteArray &poolSocket, const QByteArray &appSocket)
19 : d(new WorkerBasePrivate(protocol, poolSocket, appSocket, this))
20{
21}
22
23WorkerBase::~WorkerBase() = default;
24
25void WorkerBase::dispatchLoop()
26{
27 d->bridge.dispatchLoop();
28}
29
30void WorkerBase::connectWorker(const QString &address)
31{
32 d->bridge.connectSlave(address);
33}
34
35void WorkerBase::disconnectWorker()
36{
37 d->bridge.disconnectSlave();
38}
39
40void WorkerBase::setMetaData(const QString &key, const QString &value)
41{
42 d->bridge.setMetaData(key, value);
43}
44
45QString WorkerBase::metaData(const QString &key) const
46{
47 return d->bridge.metaData(key);
48}
49
50MetaData WorkerBase::allMetaData() const
51{
52 return d->bridge.allMetaData();
53}
54
55bool WorkerBase::hasMetaData(const QString &key) const
56{
57 return d->bridge.hasMetaData(key);
58}
59
60QMap<QString, QVariant> WorkerBase::mapConfig() const
61{
62 return d->bridge.mapConfig();
63}
64
65bool WorkerBase::configValue(const QString &key, bool defaultValue) const
66{
67 return d->bridge.configValue(key, defaultValue);
68}
69
70int WorkerBase::configValue(const QString &key, int defaultValue) const
71{
72 return d->bridge.configValue(key, defaultValue);
73}
74
75QString WorkerBase::configValue(const QString &key, const QString &defaultValue) const
76{
77 return d->bridge.configValue(key, defaultValue);
78}
79
80KConfigGroup *WorkerBase::config()
81{
82 return d->bridge.config();
83}
84
85void WorkerBase::sendMetaData()
86{
87 d->bridge.sendMetaData();
88}
89
90void WorkerBase::sendAndKeepMetaData()
91{
92 d->bridge.sendAndKeepMetaData();
93}
94
95KRemoteEncoding *WorkerBase::remoteEncoding()
96{
97 return d->bridge.remoteEncoding();
98}
99
100void WorkerBase::data(const QByteArray &data)
101{
102 d->bridge.data(data);
103}
104
105void WorkerBase::dataReq()
106{
107 d->bridge.dataReq();
108}
109
110void WorkerBase::workerStatus(const QString &host, bool connected)
111{
112 d->bridge.slaveStatus(host, connected);
113}
114
115void WorkerBase::canResume()
116{
117 d->bridge.canResume();
118}
119
120void WorkerBase::totalSize(KIO::filesize_t _bytes)
121{
122 d->bridge.totalSize(_bytes);
123}
124
125void WorkerBase::processedSize(KIO::filesize_t _bytes)
126{
127 d->bridge.processedSize(_bytes);
128}
129
130void WorkerBase::written(KIO::filesize_t _bytes)
131{
132 d->bridge.written(_bytes);
133}
134
135void WorkerBase::position(KIO::filesize_t _pos)
136{
137 d->bridge.position(_pos);
138}
139
140void WorkerBase::truncated(KIO::filesize_t _length)
141{
142 d->bridge.truncated(_length);
143}
144
145void WorkerBase::speed(unsigned long _bytes_per_second)
146{
147 d->bridge.speed(_bytes_per_second);
148}
149
150void WorkerBase::redirection(const QUrl &_url)
151{
152 d->bridge.redirection(_url);
153}
154
155#if KIOCORE_BUILD_DEPRECATED_SINCE(6, 3)
156void WorkerBase::errorPage()
157{
158}
159#endif
160
161void WorkerBase::mimeType(const QString &_type)
162{
163 d->bridge.mimeType(_type);
164}
165
166void WorkerBase::exit()
167{
168 d->bridge.exit();
169}
170
171void WorkerBase::warning(const QString &_msg)
172{
173 d->bridge.warning(_msg);
174}
175
176void WorkerBase::infoMessage(const QString &_msg)
177{
178 d->bridge.infoMessage(_msg);
179}
180
181void WorkerBase::statEntry(const UDSEntry &entry)
182{
183 d->bridge.statEntry(entry);
184}
185
186void WorkerBase::listEntry(const UDSEntry &entry)
187{
188 d->bridge.listEntry(entry);
189}
190
191void WorkerBase::listEntries(const UDSEntryList &list)
192{
193 d->bridge.listEntries(list);
194}
195
196void WorkerBase::appConnectionMade()
197{
198} // No response!
199
200void WorkerBase::setHost(QString const &, quint16, QString const &, QString const &)
201{
202} // No response!
203
204WorkerResult WorkerBase::openConnection()
205{
206 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_CONNECT));
207}
208
209void WorkerBase::closeConnection()
210{
211} // No response!
212
213WorkerResult WorkerBase::stat(QUrl const &)
214{
215 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_STAT));
216}
217
218WorkerResult WorkerBase::put(QUrl const &, int, JobFlags)
219{
220 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_PUT));
221}
222
223WorkerResult WorkerBase::special(const QByteArray &)
224{
225 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_SPECIAL));
226}
227
228WorkerResult WorkerBase::listDir(QUrl const &)
229{
230 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_LISTDIR));
231}
232
233WorkerResult WorkerBase::get(QUrl const &)
234{
235 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_GET));
236}
237
238WorkerResult WorkerBase::open(QUrl const &, QIODevice::OpenMode)
239{
240 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_OPEN));
241}
242
244{
245 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_READ));
246}
247
248WorkerResult WorkerBase::write(const QByteArray &)
249{
250 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_WRITE));
251}
252
254{
255 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_SEEK));
256}
257
258WorkerResult WorkerBase::truncate(KIO::filesize_t)
259{
260 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_TRUNCATE));
261}
262
263WorkerResult WorkerBase::close()
264{
265 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_CLOSE));
266}
267
268WorkerResult WorkerBase::mimetype(QUrl const &url)
269{
270 return get(url);
271}
272
273WorkerResult WorkerBase::rename(QUrl const &, QUrl const &, JobFlags)
274{
275 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_RENAME));
276}
277
278WorkerResult WorkerBase::symlink(QString const &, QUrl const &, JobFlags)
279{
280 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_SYMLINK));
281}
282
283WorkerResult WorkerBase::copy(QUrl const &, QUrl const &, int, JobFlags)
284{
285 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_COPY));
286}
287
288WorkerResult WorkerBase::del(QUrl const &, bool)
289{
290 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_DEL));
291}
292
293WorkerResult WorkerBase::mkdir(QUrl const &, int)
294{
295 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_MKDIR));
296}
297
298WorkerResult WorkerBase::chmod(QUrl const &, int)
299{
300 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_CHMOD));
301}
302
303WorkerResult WorkerBase::setModificationTime(QUrl const &, const QDateTime &)
304{
305 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_SETMODIFICATIONTIME));
306}
307
308WorkerResult WorkerBase::chown(QUrl const &, const QString &, const QString &)
309{
310 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_CHOWN));
311}
312
313WorkerResult WorkerBase::fileSystemFreeSpace(const QUrl &)
314{
315 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_FILESYSTEMFREESPACE));
316}
317
318void WorkerBase::worker_status()
319{
320 workerStatus(QString(), false);
321}
322
323void WorkerBase::reparseConfiguration()
324{
325 // base implementation called by bridge
326}
327
328int WorkerBase::openPasswordDialog(AuthInfo &info, const QString &errorMsg)
329{
330 return d->bridge.openPasswordDialogV2(info, errorMsg);
331}
332
333int WorkerBase::messageBox(MessageBoxType type, const QString &text, const QString &title, const QString &primaryActionText, const QString &secondaryActionText)
334{
335 return messageBox(text, type, title, primaryActionText, secondaryActionText, QString());
336}
337
338int WorkerBase::messageBox(const QString &text,
339 MessageBoxType type,
340 const QString &title,
341 const QString &primaryActionText,
342 const QString &secondaryActionText,
343 const QString &dontAskAgainName)
344{
345 return d->bridge.messageBox(text, static_cast<SlaveBase::MessageBoxType>(type), title, primaryActionText, secondaryActionText, dontAskAgainName);
346}
347
348int WorkerBase::sslError(const QVariantMap &sslData)
349{
350 return d->bridge.sslError(sslData);
351}
352
353bool WorkerBase::canResume(KIO::filesize_t offset)
354{
355 return d->bridge.canResume(offset);
356}
357
358int WorkerBase::waitForAnswer(int expected1, int expected2, QByteArray &data, int *pCmd)
359{
360 return d->bridge.waitForAnswer(expected1, expected2, data, pCmd);
361}
362
363int WorkerBase::readData(QByteArray &buffer)
364{
365 return d->bridge.readData(buffer);
366}
367
368void WorkerBase::setTimeoutSpecialCommand(int timeout, const QByteArray &data)
369{
370 d->bridge.setTimeoutSpecialCommand(timeout, data);
371}
372
373bool WorkerBase::checkCachedAuthentication(AuthInfo &info)
374{
375 return d->bridge.checkCachedAuthentication(info);
376}
377
378bool WorkerBase::cacheAuthentication(const AuthInfo &info)
379{
380 return d->bridge.cacheAuthentication(info);
381}
382
383int WorkerBase::connectTimeout()
384{
385 return d->bridge.connectTimeout();
386}
387
388int WorkerBase::proxyConnectTimeout()
389{
390 return d->bridge.proxyConnectTimeout();
391}
392
393int WorkerBase::responseTimeout()
394{
395 return d->bridge.responseTimeout();
396}
397
398int WorkerBase::readTimeout()
399{
400 return d->bridge.readTimeout();
401}
402
403bool WorkerBase::wasKilled() const
404{
405 return d->bridge.wasKilled();
406}
407
408void WorkerBase::lookupHost(const QString &host)
409{
410 return d->bridge.lookupHost(host);
411}
412
413int WorkerBase::waitForHostInfo(QHostInfo &info)
414{
415 return d->bridge.waitForHostInfo(info);
416}
417
418PrivilegeOperationStatus WorkerBase::requestPrivilegeOperation(const QString &operationDetails)
419{
420 return d->bridge.requestPrivilegeOperation(operationDetails);
421}
422
423void WorkerBase::addTemporaryAuthorization(const QString &action)
424{
425 d->bridge.addTemporaryAuthorization(action);
426}
427
428class WorkerResultPrivate
429{
430public:
431 bool success;
432 int error;
433 QString errorString;
434};
435
436WorkerResult::~WorkerResult() = default;
437
438WorkerResult::WorkerResult(const WorkerResult &rhs)
439 : d(std::make_unique<WorkerResultPrivate>(*rhs.d))
440{
441}
442
443WorkerResult &WorkerResult::operator=(const WorkerResult &rhs)
444{
445 if (this == &rhs) {
446 return *this;
447 }
448 d = std::make_unique<WorkerResultPrivate>(*rhs.d);
449 return *this;
450}
451
452WorkerResult::WorkerResult(WorkerResult &&) noexcept = default;
453WorkerResult &WorkerResult::operator=(WorkerResult &&) noexcept = default;
454
455bool WorkerResult::success() const
456{
457 return d->success;
458}
459
461{
462 return d->error;
463}
464
466{
467 return d->errorString;
468}
469
470Q_REQUIRED_RESULT WorkerResult WorkerResult::fail(int _error, const QString &_errorString)
471{
472 return WorkerResult(std::make_unique<WorkerResultPrivate>(WorkerResultPrivate{false, _error, _errorString}));
473}
474
476{
477 return WorkerResult(std::make_unique<WorkerResultPrivate>(WorkerResultPrivate{true, 0, QString()}));
478}
479
480WorkerResult::WorkerResult(std::unique_ptr<WorkerResultPrivate> &&dptr)
481 : d(std::move(dptr))
482{
483}
484
486{
487 d->bridge.setIncomingMetaData(metaData);
488}
489} // namespace KIO
KConfig * config()
This class is intended to make it easier to prompt for, cache and retrieve authorization information.
MetaData is a simple map of key/value strings.
MessageBoxType
Type of message box.
Definition slavebase.h:250
Universal Directory Service.
MessageBoxType
Type of message box.
Definition workerbase.h:223
void setIncomingMetaData(const KIO::MetaData &metaData)
Set the Incoming Meta Data This is only really useful if your worker wants to overwrite the metadata ...
QString metaData(const QString &key) const
Queries for config/meta-data send by the application to the worker.
The result of a worker call When using the Result type always mark the function Q_REQUIRED_RESULT to ...
Definition workerbase.h:36
bool success() const
Whether or not the result was a success.
int error() const
The error code (or ERR_UNKNOWN) of the result.
QString errorString() const
The localized error description if applicable.
static WorkerResult pass()
Constructs a success result.
static WorkerResult fail(int _error=KIO::ERR_UNKNOWN, const QString &_errorString=QString())
Constructs a failure results.
WorkerResult()=delete
Use fail() or pass();.
Allows encoding and decoding properly remote filenames into Unicode.
A namespace for KIO globals.
KIOCORE_EXPORT QString unsupportedActionErrorString(const QString &protocol, int cmd)
Returns an appropriate error message if the given command cmd is an unsupported action (ERR_UNSUPPORT...
KIOCORE_EXPORT CopyJob * move(const QUrl &src, const QUrl &dest, JobFlags flags=DefaultFlags)
Moves a file or directory src to the given destination dest.
Definition copyjob.cpp:2657
PrivilegeOperationStatus
Specifies privilege file operation status.
Definition global.h:239
KIOCORE_EXPORT TransferJob * get(const QUrl &url, LoadType reload=NoReload, JobFlags flags=DefaultFlags)
Get (means: read).
qulonglong filesize_t
64-bit file size
Definition global.h:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.