8#include "workerinterface_p.h"
10#include "commands_p.h"
11#include "connection_p.h"
13#include "kiocoredebug.h"
14#include "usernotificationhandler_p.h"
15#include "workerbase.h"
17#include <KLocalizedString>
26Q_GLOBAL_STATIC(UserNotificationHandler, globalUserNotificationHandler)
28WorkerInterface::WorkerInterface(
QObject *parent)
34WorkerInterface::~WorkerInterface()
48bool WorkerInterface::dispatch()
50 Q_ASSERT(m_connection);
55 int ret = m_connection->read(&cmd, data);
60 return dispatch(cmd, data);
63void WorkerInterface::calcSpeed()
65 if (m_worker_calcs_speed || !m_connection->isConnected()) {
71 const qint64 diff = currentTime - m_start_time;
72 if (diff - m_last_time >= 900) {
74 if (m_nums == max_nums) {
77 for (
unsigned int i = 1; i < max_nums; ++i) {
78 m_times[i - 1] = m_times[i];
79 m_sizes[i - 1] = m_sizes[i];
83 m_times[m_nums] = diff;
84 m_sizes[m_nums++] = m_filesize - m_offset;
86 KIO::filesize_t lspeed = 1000 * (m_sizes[m_nums - 1] - m_sizes[0]) / (m_times[m_nums - 1] - m_times[0]);
98 m_sizes[0] = m_filesize - m_offset;
100 Q_EMIT speed(lspeed);
104bool WorkerInterface::dispatch(
int _cmd,
const QByteArray &rawdata)
117 Q_EMIT data(rawdata);
128 m_speed_timer.stop();
131 case MSG_STAT_ENTRY: {
134 Q_EMIT statEntry(entry);
137 case MSG_LIST_ENTRIES: {
141 while (!stream.atEnd()) {
146 Q_EMIT listEntries(list);
150 m_offset = readFilesize_t(stream);
151 Q_EMIT canResume(m_offset);
155 m_filesize = m_offset;
161 Q_EMIT
error(i, str1);
163 case MSG_WORKER_STATUS: {
166 stream >> pid >> protocol >> str1 >> b;
167 Q_EMIT workerStatus(pid, protocol, str1, (b != 0));
175 Q_EMIT written(size);
178 case INF_TOTAL_SIZE: {
182 m_filesize = m_offset;
183 m_sizes[0] = m_filesize - m_offset;
186 m_speed_timer.start(1000);
187 m_worker_calcs_speed =
false;
188 Q_EMIT totalSize(size);
191 case INF_PROCESSED_SIZE: {
193 Q_EMIT processedSize(size);
199 Q_EMIT position(pos);
202 case INF_TRUNCATED: {
204 Q_EMIT truncated(length);
209 m_worker_calcs_speed =
true;
210 m_speed_timer.stop();
215 case INF_REDIRECTION: {
218 Q_EMIT redirection(url);
224 if (!m_connection->suspended()) {
225 m_connection->sendnow(CMD_NONE,
QByteArray());
230 Q_EMIT warning(str1);
232 case INF_MESSAGEBOX: {
240 stream >>
type >> text >> title >> primaryActionText >> secondaryActionText;
241 if (stream.atEnd()) {
242 messageBox(type, text, title, primaryActionText, secondaryActionText);
244 stream >> dontAskAgainName;
245 messageBox(type, text, title, primaryActionText, secondaryActionText, dontAskAgainName);
249 case INF_INFOMESSAGE: {
252 Q_EMIT infoMessage(msg);
256 QVariantMap sslErrorData;
257 stream >> sslErrorData;
258 globalUserNotificationHandler->sslError(
this, sslErrorData);
261 case INF_META_DATA: {
264 if (
auto it = m.
constFind(QStringLiteral(
"privilege_conf_details")); it != m.
cend()) {
266 m_messageBoxDetails = it.value();
271 case MSG_HOST_INFO_REQ: {
277 case MSG_PRIVILEGE_EXEC:
278 Q_EMIT privilegeOperationRequested();
281 qCWarning(KIO_CORE) <<
"Worker sends unknown command (" << _cmd <<
"), dropping worker.";
297void WorkerInterface::sendResumeAnswer(
bool resume)
300 m_connection->sendnow(resume ? CMD_RESUMEANSWER : CMD_NONE,
QByteArray());
303void WorkerInterface::sendMessageBoxAnswer(
int result)
309 if (m_connection->suspended()) {
310 m_connection->resume();
315 m_connection->sendnow(CMD_MESSAGEBOXANSWER, packedArgs);
319void WorkerInterface::sendSslErrorAnswer(
int result)
325 if (m_connection->suspended()) {
326 m_connection->resume();
331 m_connection->sendnow(CMD_SSLERRORANSWER, packedArgs);
335void WorkerInterface::messageBox(
int type,
const QString &text,
const QString &title,
const QString &primaryActionText,
const QString &secondaryActionText)
337 messageBox(type, text, title, primaryActionText, secondaryActionText,
QString());
340void WorkerInterface::messageBox(
int type,
343 const QString &primaryActionText,
344 const QString &secondaryActionText,
345 const QString &dontAskAgainName)
348 m_connection->suspend();
352 data.
insert(UserNotificationHandler::MSG_TEXT, text);
353 data.
insert(UserNotificationHandler::MSG_TITLE, title);
354 data.
insert(UserNotificationHandler::MSG_PRIMARYACTION_TEXT, primaryActionText);
355 data.
insert(UserNotificationHandler::MSG_SECONDARYACTION_TEXT, secondaryActionText);
356 data.
insert(UserNotificationHandler::MSG_DONT_ASK_AGAIN, dontAskAgainName);
360 if (primaryActionText ==
i18n(
"&Details")) {
362 }
else if (primaryActionText ==
i18n(
"&Forever")) {
366 if (secondaryActionText ==
i18n(
"Co&ntinue")) {
367 data.
insert(UserNotificationHandler::MSG_SECONDARYACTION_ICON,
QLatin1String(
"arrow-right"));
368 }
else if (secondaryActionText ==
i18n(
"&Current Session only")) {
369 data.
insert(UserNotificationHandler::MSG_SECONDARYACTION_ICON,
QLatin1String(
"chronometer"));
372 if (type == KIO::WorkerBase::WarningContinueCancelDetailed) {
373 data.
insert(UserNotificationHandler::MSG_DETAILS, m_messageBoxDetails);
376 globalUserNotificationHandler()->requestMessageBox(
this, type, data);
379void WorkerInterface::slotHostInfo(
const QHostInfo &info)
384 m_connection->send(CMD_HOST_INFO, data);
387#include "moc_workerinterface_p.cpp"
Universal Directory Service.
QString i18n(const char *text, const TYPE &arg...)
KCALUTILS_EXPORT QString mimeType()
void lookupHost(const QString &hostName, QObject *receiver, const char *member)
A namespace for KIO globals.
KIOCORE_EXPORT FileJob * open(const QUrl &url, QIODevice::OpenMode mode)
Open ( random access I/O )
qulonglong filesize_t
64-bit file size
ButtonCode messageBox(QWidget *parent, DialogType type, const QString &text, const QString &title, const KGuiItem &primaryAction, const KGuiItem &secondaryAction, const KGuiItem &cancelAction=KStandardGuiItem::cancel(), const QString &dontShowAskAgainName=QString(), Options options=Notify)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
Returns a list of directories associated with this file-class.
qint64 currentMSecsSinceEpoch()
iterator insert(const Key &key, const T &value)
QList< QHostAddress > addresses() const const
HostInfoError error() const const
QString errorString() const const
QString hostName() const const
void append(QList< T > &&value)
const_iterator cend() const const
const_iterator constFind(const Key &key) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)