File indexing completed on 2024-06-16 10:06:10

0001 /*
0002     This file is part of the KDE project.
0003     SPDX-FileCopyrightText: 2008-2009 Urs Wolfer <uwolfer @ kde.org>
0004     SPDX-FileCopyrightText: 2009-2012 Dawit Alemayehu <adawit @ kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef KIO_ACCESSMANAGERREPLY_P_H
0010 #define KIO_ACCESSMANAGERREPLY_P_H
0011 
0012 #include "kiowidgets_export.h"
0013 
0014 #include <QNetworkReply>
0015 #include <QPointer>
0016 
0017 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 107)
0018 
0019 namespace KIO
0020 {
0021 class Job;
0022 class SimpleJob;
0023 class MetaData;
0024 }
0025 class KJob;
0026 class QUrl;
0027 
0028 namespace KDEPrivate
0029 {
0030 /**
0031  * Used for KIO::Integration::AccessManager; KDE implementation of QNetworkReply.
0032  *
0033  * @since 4.3
0034  * @author Urs Wolfer \<uwolfer @ kde.org\>
0035  */
0036 
0037 class AccessManagerReply : public QNetworkReply
0038 {
0039     Q_OBJECT
0040 public:
0041     explicit AccessManagerReply(const QNetworkAccessManager::Operation op,
0042                                 const QNetworkRequest &request,
0043                                 KIO::SimpleJob *kioJob,
0044                                 bool emitReadyReadOnMetaDataChange = false,
0045                                 QObject *parent = nullptr);
0046 
0047     explicit AccessManagerReply(const QNetworkAccessManager::Operation op,
0048                                 const QNetworkRequest &request,
0049                                 const QByteArray &data,
0050                                 const QUrl &url,
0051                                 const KIO::MetaData &metaData,
0052                                 QObject *parent = nullptr);
0053 
0054     explicit AccessManagerReply(const QNetworkAccessManager::Operation op,
0055                                 const QNetworkRequest &request,
0056                                 QNetworkReply::NetworkError errorCode,
0057                                 const QString &errorMessage,
0058                                 QObject *parent = nullptr);
0059 
0060     ~AccessManagerReply() override;
0061     qint64 bytesAvailable() const override;
0062     void abort() override;
0063 
0064     void setIgnoreContentDisposition(bool on);
0065     void putOnHold();
0066 
0067     static bool isLocalRequest(const QUrl &url);
0068 
0069 protected:
0070     qint64 readData(char *data, qint64 maxSize) override;
0071     bool ignoreContentDisposition(const KIO::MetaData &);
0072     void setHeaderFromMetaData(const KIO::MetaData &);
0073     void readHttpResponseHeaders(KIO::Job *);
0074     int jobError(KJob *kJob);
0075     void emitFinished(bool state, Qt::ConnectionType type = Qt::AutoConnection);
0076 
0077 private Q_SLOTS:
0078     void slotData(KIO::Job *kioJob, const QByteArray &data);
0079     void slotMimeType(KIO::Job *kioJob, const QString &mimeType);
0080     void slotResult(KJob *kJob);
0081     void slotStatResult(KJob *kJob);
0082     void slotRedirection(KIO::Job *job, const QUrl &url);
0083     void slotPercent(KJob *job, unsigned long percent);
0084 
0085 private:
0086     QByteArray m_data;
0087     qint64 m_offset;
0088     bool m_metaDataRead;
0089     bool m_ignoreContentDisposition;
0090     bool m_emitReadyReadOnMetaDataChange;
0091     QPointer<KIO::SimpleJob> m_kioJob;
0092 };
0093 
0094 }
0095 
0096 #endif
0097 
0098 #endif // KIO_ACCESSMANAGERREPLY_P_H