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>
24Q_GLOBAL_STATIC(UserNotificationHandler, globalUserNotificationHandler)
26WorkerInterface::WorkerInterface(
QObject *parent)
32WorkerInterface::~WorkerInterface()
46bool WorkerInterface::dispatch()
48 Q_ASSERT(m_connection);
53 int ret = m_connection->read(&cmd, data);
58 return dispatch(cmd, data);
61void WorkerInterface::calcSpeed()
63 if (m_worker_calcs_speed || !m_connection->isConnected()) {
69 const qint64 diff = currentTime - m_start_time;
70 if (diff - m_last_time >= 900) {
72 if (m_nums == max_nums) {
75 for (
unsigned int i = 1; i < max_nums; ++i) {
76 m_times[i - 1] = m_times[i];
77 m_sizes[i - 1] = m_sizes[i];
81 m_times[m_nums] = diff;
82 m_sizes[m_nums++] = m_filesize - m_offset;
84 KIO::filesize_t lspeed = 1000 * (m_sizes[m_nums - 1] - m_sizes[0]) / (m_times[m_nums - 1] - m_times[0]);
96 m_sizes[0] = m_filesize - m_offset;
102bool WorkerInterface::dispatch(
int _cmd,
const QByteArray &rawdata)
115 Q_EMIT data(rawdata);
126 m_speed_timer.stop();
129 case MSG_STAT_ENTRY: {
132 Q_EMIT statEntry(entry);
135 case MSG_LIST_ENTRIES: {
139 while (!stream.atEnd()) {
144 Q_EMIT listEntries(list);
148 m_offset = readFilesize_t(stream);
149 Q_EMIT canResume(m_offset);
153 m_filesize = m_offset;
159 Q_EMIT
error(i, str1);
161 case MSG_WORKER_STATUS: {
164 stream >> pid >> protocol >> str1 >> b;
165 Q_EMIT workerStatus(pid, protocol, str1, (b != 0));
173 Q_EMIT written(size);
176 case INF_TOTAL_SIZE: {
180 m_filesize = m_offset;
181 m_sizes[0] = m_filesize - m_offset;
184 m_speed_timer.start(1000);
185 m_worker_calcs_speed =
false;
186 Q_EMIT totalSize(size);
189 case INF_PROCESSED_SIZE: {
191 Q_EMIT processedSize(size);
197 Q_EMIT position(pos);
200 case INF_TRUNCATED: {
202 Q_EMIT truncated(length);
207 m_worker_calcs_speed =
true;
208 m_speed_timer.stop();
213 case INF_REDIRECTION: {
216 Q_EMIT redirection(url);
222 if (!m_connection->suspended()) {
223 m_connection->sendnow(CMD_NONE,
QByteArray());
228 Q_EMIT warning(str1);
230 case INF_MESSAGEBOX: {
238 stream >>
type >> text >> title >> primaryActionText >> secondaryActionText;
239 if (stream.atEnd()) {
240 messageBox(type, text, title, primaryActionText, secondaryActionText);
242 stream >> dontAskAgainName;
243 messageBox(type, text, title, primaryActionText, secondaryActionText, dontAskAgainName);
247 case INF_INFOMESSAGE: {
250 Q_EMIT infoMessage(msg);
254 QVariantMap sslErrorData;
255 stream >> sslErrorData;
256 globalUserNotificationHandler->sslError(
this, sslErrorData);
259 case INF_META_DATA: {
262 if (
auto it = m.
constFind(QStringLiteral(
"privilege_conf_details")); it != m.
cend()) {
264 m_messageBoxDetails = it.value();
269 case MSG_HOST_INFO_REQ: {
275 case MSG_PRIVILEGE_EXEC:
276 Q_EMIT privilegeOperationRequested();
279 qCWarning(KIO_CORE) <<
"Worker sends unknown command (" << _cmd <<
"), dropping worker.";
295void WorkerInterface::sendResumeAnswer(
bool resume)
298 m_connection->sendnow(resume ? CMD_RESUMEANSWER : CMD_NONE,
QByteArray());
301void WorkerInterface::sendMessageBoxAnswer(
int result)
307 if (m_connection->suspended()) {
308 m_connection->resume();
313 m_connection->sendnow(CMD_MESSAGEBOXANSWER, packedArgs);
317void WorkerInterface::sendSslErrorAnswer(
int result)
323 if (m_connection->suspended()) {
324 m_connection->resume();
329 m_connection->sendnow(CMD_SSLERRORANSWER, packedArgs);
333void WorkerInterface::messageBox(
int type,
const QString &text,
const QString &title,
const QString &primaryActionText,
const QString &secondaryActionText)
335 messageBox(type, text, title, primaryActionText, secondaryActionText,
QString());
338void WorkerInterface::messageBox(
int type,
341 const QString &primaryActionText,
342 const QString &secondaryActionText,
343 const QString &dontAskAgainName)
346 m_connection->suspend();
350 data.
insert(UserNotificationHandler::MSG_TEXT, text);
351 data.
insert(UserNotificationHandler::MSG_TITLE, title);
352 data.
insert(UserNotificationHandler::MSG_PRIMARYACTION_TEXT, primaryActionText);
353 data.
insert(UserNotificationHandler::MSG_SECONDARYACTION_TEXT, secondaryActionText);
354 data.
insert(UserNotificationHandler::MSG_DONT_ASK_AGAIN, dontAskAgainName);
358 if (primaryActionText ==
i18n(
"&Details")) {
360 }
else if (primaryActionText ==
i18n(
"&Forever")) {
364 if (secondaryActionText ==
i18n(
"Co&ntinue")) {
365 data.
insert(UserNotificationHandler::MSG_SECONDARYACTION_ICON,
QLatin1String(
"arrow-right"));
366 }
else if (secondaryActionText ==
i18n(
"&Current Session only")) {
367 data.
insert(UserNotificationHandler::MSG_SECONDARYACTION_ICON,
QLatin1String(
"chronometer"));
370 if (type == KIO::WorkerBase::WarningContinueCancelDetailed) {
371 data.
insert(UserNotificationHandler::MSG_DETAILS, m_messageBoxDetails);
374 globalUserNotificationHandler()->requestMessageBox(
this, type, data);
377void WorkerInterface::slotHostInfo(
const QHostInfo &info)
382 m_connection->send(CMD_HOST_INFO, data);
385#include "moc_workerinterface_p.cpp"
Universal Directory Service.
QString i18n(const char *text, const TYPE &arg...)
Type type(const QSqlDatabase &db)
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)
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)