1/*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KIO_WORKERINTERFACE_P_H
9#define KIO_WORKERINTERFACE_P_H
10
11#include <qplatformdefs.h>
12
13#include <QHostInfo>
14#include <QObject>
15#include <QTimer>
16
17#include "connection_p.h"
18#include "global.h"
19#include "metadata.h"
20#include "udsentry.h"
21
22class QUrl;
23
24namespace KIO
25{
26
27// Definition of enum Command has been moved to global.h
28
29/**
30 * Identifiers for KIO informational messages.
31 */
32enum Info {
33 INF_TOTAL_SIZE = 10,
34 INF_PROCESSED_SIZE = 11,
35 INF_SPEED,
36 INF_REDIRECTION = 20,
37 INF_MIME_TYPE = 21,
38 INF_ERROR_PAGE = 22,
39 INF_WARNING = 23,
40 INF_UNUSED = 25, ///< now unused
41 INF_INFOMESSAGE,
42 INF_META_DATA,
43 INF_MESSAGEBOX,
44 INF_POSITION,
45 INF_TRUNCATED,
46 INF_SSLERROR,
47 // add new ones here once a release is done, to avoid breaking binary compatibility
48};
49
50/**
51 * Identifiers for KIO data messages.
52 */
53enum Message {
54 MSG_DATA = 100,
55 MSG_DATA_REQ,
56 MSG_ERROR,
57 MSG_CONNECTED,
58 MSG_FINISHED,
59 MSG_STAT_ENTRY, // 105
60 MSG_LIST_ENTRIES,
61 MSG_RENAMED, ///< unused
62 MSG_RESUME,
63 MSG_CANRESUME,
64 MSG_OPENED,
65 MSG_WRITTEN,
66 MSG_HOST_INFO_REQ,
67 MSG_PRIVILEGE_EXEC,
68 MSG_WORKER_STATUS,
69 // add new ones here once a release is done, to avoid breaking binary compatibility
70};
71
72/**
73 * @class KIO::WorkerInterface workerinterface_p.h <KIO/WorkerInterface>
74 *
75 * There are two classes that specifies the protocol between application
76 * ( KIO::Job) and kioworker. WorkerInterface is the class to use on the application
77 * end, WorkerBase is the one to use on the worker end.
78 *
79 * A call to foo() results in a call to slotFoo() on the other end.
80 */
81class WorkerInterface : public QObject
82{
83 Q_OBJECT
84
85protected:
86 explicit WorkerInterface(QObject *parent = nullptr);
87
88public:
89 ~WorkerInterface() override;
90
91 // Send our answer to the MSG_RESUME (canResume) request
92 // (to tell the "put" job whether to resume or not)
93 void sendResumeAnswer(bool resume);
94
95 /**
96 * Sends our answer for the INF_MESSAGEBOX request.
97 *
98 */
99 void sendMessageBoxAnswer(int result);
100
101 void sendSslErrorAnswer(int result);
102
103 void setOffset(KIO::filesize_t offset);
104 KIO::filesize_t offset() const;
105
106Q_SIGNALS:
107 ///////////
108 // Messages sent by the worker
109 ///////////
110
111 void data(const QByteArray &);
112 void dataReq();
113 void error(int, const QString &);
114 void connected();
115 void finished();
116 void workerStatus(qint64, const QByteArray &, const QString &, bool);
117 void listEntries(const KIO::UDSEntryList &);
118 void statEntry(const KIO::UDSEntry &);
119
120 void canResume(KIO::filesize_t);
121
122 void open();
123 void written(KIO::filesize_t);
124 void close();
125
126 void privilegeOperationRequested();
127
128 ///////////
129 // Info sent by the worker
130 //////////
131 void metaData(const KIO::MetaData &);
132 void totalSize(KIO::filesize_t);
133 void processedSize(KIO::filesize_t);
134 void redirection(const QUrl &);
135 void position(KIO::filesize_t);
136 void truncated(KIO::filesize_t);
137
138 void speed(unsigned long);
139 void errorPage();
140 void mimeType(const QString &);
141 void warning(const QString &);
142 void infoMessage(const QString &);
143 // void connectFinished(); //it does not get emitted anywhere
144
145protected:
146 /////////////////
147 // Dispatching
148 ////////////////
149
150 virtual bool dispatch();
151 virtual bool dispatch(int _cmd, const QByteArray &data);
152
153 void messageBox(int type, const QString &text, const QString &title, const QString &primaryActionText, const QString &secondaryActionText);
154
155 void messageBox(int type,
156 const QString &text,
157 const QString &title,
158 const QString &primaryActionText,
159 const QString &secondaryActionText,
160 const QString &dontAskAgainName);
161
162protected Q_SLOTS:
163 void calcSpeed();
164
165private Q_SLOTS:
166 void slotHostInfo(const QHostInfo &info);
167
168protected:
169 Connection *m_connection = nullptr;
170
171 // We need some metadata here for our SSL code in messageBox() and for sslMetaData().
172 MetaData m_sslMetaData;
173
174private:
175 QTimer m_speed_timer;
176
177 // Used to cache privilege operation details passed from the worker by the metadata hack
178 // See WORKER_MESSAGEBOX_DETAILS_HACK
179 QString m_messageBoxDetails;
180
181 static const unsigned int max_nums = 8;
182 KIO::filesize_t m_sizes[max_nums];
183 qint64 m_times[max_nums];
184
185 KIO::filesize_t m_filesize = 0;
186 KIO::filesize_t m_offset = 0;
187 size_t m_last_time = 0;
188 qint64 m_start_time = 0;
189 uint m_nums = 0;
190 bool m_worker_calcs_speed = false;
191};
192
193}
194
195#endif
196

source code of kio/src/core/workerinterface_p.h