| 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 | |
| 22 | class QUrl; |
| 23 | |
| 24 | namespace KIO |
| 25 | { |
| 26 | |
| 27 | // Definition of enum Command has been moved to global.h |
| 28 | |
| 29 | /* |
| 30 | * Identifiers for KIO informational messages. |
| 31 | */ |
| 32 | enum 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 | */ |
| 53 | enum 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 | * There are two classes that specifies the protocol between application |
| 74 | * ( KIO::Job) and kioworker. WorkerInterface is the class to use on the application |
| 75 | * end, WorkerBase is the one to use on the worker end. |
| 76 | * |
| 77 | * A call to foo() results in a call to slotFoo() on the other end. |
| 78 | */ |
| 79 | class WorkerInterface : public QObject |
| 80 | { |
| 81 | Q_OBJECT |
| 82 | |
| 83 | protected: |
| 84 | explicit WorkerInterface(QObject *parent = nullptr); |
| 85 | |
| 86 | public: |
| 87 | ~WorkerInterface() override; |
| 88 | |
| 89 | // Send our answer to the MSG_RESUME (canResume) request |
| 90 | // (to tell the "put" job whether to resume or not) |
| 91 | void sendResumeAnswer(bool resume); |
| 92 | |
| 93 | /*! |
| 94 | * Sends our answer for the INF_MESSAGEBOX request. |
| 95 | * |
| 96 | */ |
| 97 | void sendMessageBoxAnswer(int result); |
| 98 | |
| 99 | void sendSslErrorAnswer(int result); |
| 100 | |
| 101 | void setOffset(KIO::filesize_t offset); |
| 102 | KIO::filesize_t offset() const; |
| 103 | |
| 104 | Q_SIGNALS: |
| 105 | /////////// |
| 106 | // Messages sent by the worker |
| 107 | /////////// |
| 108 | |
| 109 | void data(const QByteArray &); |
| 110 | void dataReq(); |
| 111 | void error(int, const QString &); |
| 112 | void connected(); |
| 113 | void finished(); |
| 114 | void workerStatus(qint64, const QByteArray &, const QString &, bool); |
| 115 | void listEntries(const KIO::UDSEntryList &); |
| 116 | void statEntry(const KIO::UDSEntry &); |
| 117 | |
| 118 | void canResume(KIO::filesize_t); |
| 119 | |
| 120 | void open(); |
| 121 | void written(KIO::filesize_t); |
| 122 | void close(); |
| 123 | |
| 124 | void privilegeOperationRequested(); |
| 125 | |
| 126 | /////////// |
| 127 | // Info sent by the worker |
| 128 | ////////// |
| 129 | void metaData(const KIO::MetaData &); |
| 130 | void totalSize(KIO::filesize_t); |
| 131 | void processedSize(KIO::filesize_t); |
| 132 | void redirection(const QUrl &); |
| 133 | void position(KIO::filesize_t); |
| 134 | void truncated(KIO::filesize_t); |
| 135 | |
| 136 | void speed(unsigned long); |
| 137 | void mimeType(const QString &); |
| 138 | void warning(const QString &); |
| 139 | void infoMessage(const QString &); |
| 140 | // void connectFinished(); //it does not get emitted anywhere |
| 141 | |
| 142 | protected: |
| 143 | ///////////////// |
| 144 | // Dispatching |
| 145 | //////////////// |
| 146 | |
| 147 | virtual bool dispatch(); |
| 148 | virtual bool dispatch(int _cmd, const QByteArray &data); |
| 149 | |
| 150 | void messageBox(int type, const QString &text, const QString &title, const QString &primaryActionText, const QString &secondaryActionText); |
| 151 | |
| 152 | void messageBox(int type, |
| 153 | const QString &text, |
| 154 | const QString &title, |
| 155 | const QString &primaryActionText, |
| 156 | const QString &secondaryActionText, |
| 157 | const QString &dontAskAgainName); |
| 158 | |
| 159 | protected Q_SLOTS: |
| 160 | void calcSpeed(); |
| 161 | |
| 162 | private Q_SLOTS: |
| 163 | void slotHostInfo(const QHostInfo &info); |
| 164 | |
| 165 | protected: |
| 166 | Connection *m_connection = nullptr; |
| 167 | |
| 168 | private: |
| 169 | QTimer m_speed_timer; |
| 170 | |
| 171 | // Used to cache privilege operation details passed from the worker by the metadata hack |
| 172 | // See WORKER_MESSAGEBOX_DETAILS_HACK |
| 173 | QString m_messageBoxDetails; |
| 174 | |
| 175 | static const unsigned int max_nums = 8; |
| 176 | KIO::filesize_t m_sizes[max_nums]; |
| 177 | qint64 m_times[max_nums]; |
| 178 | |
| 179 | KIO::filesize_t m_filesize = 0; |
| 180 | KIO::filesize_t m_offset = 0; |
| 181 | size_t m_last_time = 0; |
| 182 | qint64 m_start_time = 0; |
| 183 | uint m_nums = 0; |
| 184 | bool m_worker_calcs_speed = false; |
| 185 | }; |
| 186 | |
| 187 | } |
| 188 | |
| 189 | #endif |
| 190 | |