1 #ifndef MYTHDOWNLOADMANAGER_H
2 #define MYTHDOWNLOADMANAGER_H
7 #include <QNetworkAccessManager>
8 #include <QNetworkCookieJar>
9 #include <QNetworkDiskCache>
10 #include <QNetworkProxy>
11 #include <QNetworkReply>
12 #include <QRecursiveMutex>
15 #include <QWaitCondition>
46 using AuthCallback = void (*)(QNetworkReply*, QAuthenticator*,
void*);
58 m_infoLock(new QRecursiveMutex())
64 void run(
void)
override;
70 void preCache(
const QString &url);
71 void queueDownload(
const QString &url,
const QString &
dest,
72 QObject *caller,
bool reload =
false);
73 void queueDownload(QNetworkRequest *req, QByteArray *data,
75 bool download(
const QString &url,
const QString &
dest,
77 bool download(
const QString &url, QByteArray *data,
78 bool reload =
false, QString *finalUrl =
nullptr);
79 QNetworkReply *download(
const QString &url,
bool reload =
false);
80 bool download(QNetworkRequest *req, QByteArray *data);
81 bool downloadAuth(
const QString &url,
const QString &
dest,
84 void *authArg =
nullptr,
85 const QHash<QByteArray, QByteArray> *
headers =
nullptr);
88 void queuePost(
const QString &url, QByteArray *data, QObject *caller);
89 void queuePost(QNetworkRequest *req, QByteArray *data, QObject *caller);
90 bool post(
const QString &url, QByteArray *data);
91 bool post(QNetworkRequest *req, QByteArray *data);
92 bool postAuth(
const QString &url, QByteArray *data,
94 const QHash<QByteArray, QByteArray> *
headers =
nullptr);
97 void cancelDownload(
const QString &url,
bool block =
true);
98 void cancelDownload(
const QStringList &urls,
bool block =
true);
101 void removeListener(QObject *caller);
102 QDateTime GetLastModified(
const QString &url);
104 void loadCookieJar(
const QString &
filename);
105 void saveCookieJar(
const QString &
filename);
106 void setCookieJar(QNetworkCookieJar *cookieJar);
108 QNetworkCookieJar *copyCookieJar(
void);
109 void refreshCookieJar(QNetworkCookieJar *jar);
110 void updateCookieJar(
void);
112 QString getHeader(
const QUrl &url,
const QString &header);
113 static QString getHeader(
const QNetworkCacheMetaData &cacheData,
const QString &header);
117 void downloadFinished(QNetworkReply* reply);
118 void authCallback(QNetworkReply *reply, QAuthenticator *authenticator);
121 void downloadError(QNetworkReply::NetworkError errorCode);
122 void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
129 void queueItem(
const QString &url, QNetworkRequest *req,
130 const QString &
dest, QByteArray *data, QObject *caller,
132 bool reload =
false);
134 bool processItem(
const QString &url, QNetworkRequest *req,
135 const QString &
dest, QByteArray *data,
139 void *authArg =
nullptr,
140 const QHash<QByteArray, QByteArray> *
headers =
nullptr,
141 QString *finalUrl =
nullptr);
147 static bool downloadNowLinkLocal(
MythDownloadInfo *dlInfo,
bool deleteInfo);
149 void downloadCanceled(
void);
151 static QUrl redirectUrl(
const QUrl& possibleRedirectUrl,
152 const QUrl& oldRedirectUrl) ;
154 static bool saveFile(
const QString &outFile,
const QByteArray &data,
155 bool append =
false);
157 void updateCookieJar(QNetworkCookieJar *jar);
159 QNetworkAccessManager *m_manager {
nullptr};
160 QNetworkDiskCache *m_diskCache {
nullptr};
161 QNetworkProxy *m_proxy {
nullptr};
166 QRecursiveMutex *m_infoLock {
nullptr};
172 QThread *m_queueThread {
nullptr};
174 bool m_runThread {
false};
175 bool m_isRunning {
false};
177 QNetworkCookieJar *m_inCookieJar {
nullptr};