File indexing completed on 2024-04-28 11:41:10

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef __kio_slaveinterface_h
0009 #define __kio_slaveinterface_h
0010 
0011 #include <qplatformdefs.h>
0012 
0013 #include <QHostInfo>
0014 #include <QObject>
0015 
0016 #include <kio/authinfo.h>
0017 #include <kio/global.h>
0018 #include <kio/udsentry.h>
0019 
0020 class QUrl;
0021 
0022 namespace KIO
0023 {
0024 class Connection;
0025 // better there is one ...
0026 class SlaveInterfacePrivate;
0027 
0028 // Definition of enum Command has been moved to global.h
0029 
0030 /**
0031  * Identifiers for KIO informational messages.
0032  */
0033 enum Info {
0034     INF_TOTAL_SIZE = 10,
0035     INF_PROCESSED_SIZE = 11,
0036     INF_SPEED,
0037     INF_REDIRECTION = 20,
0038     INF_MIME_TYPE = 21,
0039     INF_ERROR_PAGE = 22,
0040     INF_WARNING = 23,
0041 #if KIOCORE_ENABLE_DEPRECATED_SINCE(3, 0)
0042     INF_GETTING_FILE ///< @deprecated Since 3.0
0043         KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 3, 0, "No known users."),
0044 #else
0045     INF_GETTING_FILE_DEPRECATED_DO_NOT_USE,
0046 #endif
0047     INF_UNUSED = 25, ///< now unused
0048     INF_INFOMESSAGE,
0049     INF_META_DATA,
0050     INF_NETWORK_STATUS,
0051     INF_MESSAGEBOX,
0052     INF_POSITION,
0053     INF_TRUNCATED,
0054     // add new ones here once a release is done, to avoid breaking binary compatibility
0055 };
0056 
0057 /**
0058  * Identifiers for KIO data messages.
0059  */
0060 enum Message {
0061     MSG_DATA = 100,
0062     MSG_DATA_REQ,
0063     MSG_ERROR,
0064     MSG_CONNECTED,
0065     MSG_FINISHED,
0066     MSG_STAT_ENTRY, // 105
0067     MSG_LIST_ENTRIES,
0068     MSG_RENAMED, ///< unused
0069     MSG_RESUME,
0070 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 45)
0071     MSG_SLAVE_STATUS ///< @deprecated Since 5.45, use MSG_SLAVE_STATUS_V2
0072         KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 45, "Use MSG_SLAVE_STATUS_V2."),
0073 #else
0074     MSG_SLAVE_STATUS_DEPRECATED_DO_NOT_USE,
0075 #endif
0076     MSG_SLAVE_ACK, // 110
0077     MSG_NET_REQUEST,
0078     MSG_NET_DROP,
0079     MSG_NEED_SUBURL_DATA,
0080     MSG_CANRESUME,
0081 #if KIOCORE_ENABLE_DEPRECATED_SINCE(3, 1)
0082     MSG_AUTH_KEY ///< @deprecated Since 3.1
0083         KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 3, 1, "No known users."),
0084     MSG_DEL_AUTH_KEY ///< @deprecated Since 3.1
0085         KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 3, 1, "No known users."),
0086 #else
0087     MSG_AUTH_KEY_DEPRECATED_DO_NOT_USE,
0088     MSG_DEL_AUTH_KEY_DEPRECATED_DO_NOT_USE,
0089 #endif
0090     MSG_OPENED,
0091     MSG_WRITTEN,
0092     MSG_HOST_INFO_REQ,
0093     MSG_PRIVILEGE_EXEC,
0094     MSG_SLAVE_STATUS_V2,
0095     // add new ones here once a release is done, to avoid breaking binary compatibility
0096 };
0097 
0098 /**
0099  * @class KIO::SlaveInterface slaveinterface.h <KIO/SlaveInterface>
0100  *
0101  * There are two classes that specifies the protocol between application
0102  * ( KIO::Job) and kioslave. SlaveInterface is the class to use on the application
0103  * end, SlaveBase is the one to use on the slave end.
0104  *
0105  * A call to foo() results in a call to slotFoo() on the other end.
0106  */
0107 // KF6 TODO: remove export macro, nothing uses this class outside kio anymore
0108 // (and rename this file to slaveinterface_p.h, and don't install it anymore)
0109 class KIOCORE_EXPORT SlaveInterface : public QObject
0110 {
0111     Q_OBJECT
0112 
0113 protected:
0114     SlaveInterface(SlaveInterfacePrivate &dd, QObject *parent = nullptr);
0115 
0116 public:
0117     ~SlaveInterface() override;
0118 
0119 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 0)
0120     // TODO KF6: remove these methods, Connection isn't an exported class
0121     KIOCORE_DEPRECATED_VERSION(5, 0, "Do not use")
0122     void setConnection(Connection *connection);
0123     KIOCORE_DEPRECATED_VERSION(5, 0, "Do not use")
0124     Connection *connection() const;
0125 #endif
0126 
0127     // Send our answer to the MSG_RESUME (canResume) request
0128     // (to tell the "put" job whether to resume or not)
0129     void sendResumeAnswer(bool resume);
0130 
0131     /**
0132      * Sends our answer for the INF_MESSAGEBOX request.
0133      *
0134      * @since 4.11
0135      */
0136     void sendMessageBoxAnswer(int result);
0137 
0138     void setOffset(KIO::filesize_t offset);
0139     KIO::filesize_t offset() const;
0140 
0141 Q_SIGNALS:
0142     ///////////
0143     // Messages sent by the slave
0144     ///////////
0145 
0146     void data(const QByteArray &);
0147     void dataReq();
0148     void error(int, const QString &);
0149     void connected();
0150     void finished();
0151     void slaveStatus(qint64, const QByteArray &, const QString &, bool);
0152     void listEntries(const KIO::UDSEntryList &);
0153     void statEntry(const KIO::UDSEntry &);
0154     void needSubUrlData();
0155 
0156     void canResume(KIO::filesize_t);
0157 
0158     void open();
0159     void written(KIO::filesize_t);
0160     void close();
0161 
0162     void privilegeOperationRequested();
0163 
0164     ///////////
0165     // Info sent by the slave
0166     //////////
0167     void metaData(const KIO::MetaData &);
0168     void totalSize(KIO::filesize_t);
0169     void processedSize(KIO::filesize_t);
0170     void redirection(const QUrl &);
0171     void position(KIO::filesize_t);
0172     void truncated(KIO::filesize_t);
0173 
0174     void speed(unsigned long);
0175     void errorPage();
0176     void mimeType(const QString &);
0177     void warning(const QString &);
0178     void infoMessage(const QString &);
0179     // void connectFinished(); //it does not get emitted anywhere
0180 
0181 protected:
0182     /////////////////
0183     // Dispatching
0184     ////////////////
0185 
0186     virtual bool dispatch();
0187     virtual bool dispatch(int _cmd, const QByteArray &data);
0188 
0189     void messageBox(int type, const QString &text, const QString &title, const QString &primaryActionText, const QString &secondaryActionText);
0190 
0191     void messageBox(int type,
0192                     const QString &text,
0193                     const QString &title,
0194                     const QString &primaryActionText,
0195                     const QString &secondaryActionText,
0196                     const QString &dontAskAgainName);
0197 
0198     // I need to identify the slaves
0199     void requestNetwork(const QString &, const QString &);
0200     void dropNetwork(const QString &, const QString &);
0201 
0202 protected Q_SLOTS:
0203     void calcSpeed();
0204 
0205 protected:
0206     SlaveInterfacePrivate *const d_ptr;
0207     Q_DECLARE_PRIVATE(SlaveInterface)
0208 private:
0209     Q_PRIVATE_SLOT(d_func(), void slotHostInfo(QHostInfo))
0210 };
0211 
0212 }
0213 
0214 #endif