MythTV
master
|
#include <libmythbase/mythdownloadmanager.h>
Public Member Functions | |
MythDownloadManager () | |
Constructor for MythDownloadManager. More... | |
~MythDownloadManager () override | |
Destructor for MythDownloadManager. More... | |
void | run (void) override |
Runs a loop to process incoming download requests and triggers download events to be processed. More... | |
void | setRunThread (void) |
QThread * | getQueueThread (void) |
bool | isRunning (void) const |
void | preCache (const QString &url) |
Downloads a URL but doesn't store the resulting data anywhere. More... | |
void | queueDownload (const QString &url, const QString &dest, QObject *caller, bool reload=false) |
Adds a url to the download queue. More... | |
void | queueDownload (QNetworkRequest *req, QByteArray *data, QObject *caller) |
Downloads a QNetworkRequest via the QNetworkAccessManager. More... | |
bool | download (const QString &url, const QString &dest, bool reload=false) |
Downloads a URL to a file in blocking mode. More... | |
bool | download (const QString &url, QByteArray *data, bool reload=false, QString *finalUrl=nullptr) |
Downloads a URI to a QByteArray in blocking mode. More... | |
QNetworkReply * | download (const QString &url, bool reload=false) |
Downloads a URI to a QByteArray in blocking mode. More... | |
bool | download (QNetworkRequest *req, QByteArray *data) |
Downloads a QNetworkRequest via the QNetworkAccessManager. More... | |
bool | downloadAuth (const QString &url, const QString &dest, bool reload=false, AuthCallback authCallback=nullptr, void *authArg=nullptr, const QHash< QByteArray, QByteArray > *headers=nullptr) |
Downloads a URL to a file in blocking mode. More... | |
void | queuePost (const QString &url, QByteArray *data, QObject *caller) |
Queues a post to a URL via the QNetworkAccessManager. More... | |
void | queuePost (QNetworkRequest *req, QByteArray *data, QObject *caller) |
Queues a post to a URL via the QNetworkAccessManager. More... | |
bool | post (const QString &url, QByteArray *data) |
Posts data to a url via the QNetworkAccessManager. More... | |
bool | post (QNetworkRequest *req, QByteArray *data) |
Posts a QNetworkRequest via the QNetworkAccessManager. More... | |
bool | postAuth (const QString &url, QByteArray *data, AuthCallback authCallback, void *authArg, const QHash< QByteArray, QByteArray > *headers=nullptr) |
Posts data to a url via the QNetworkAccessManager. More... | |
void | cancelDownload (const QString &url, bool block=true) |
Cancel a queued or current download. More... | |
void | cancelDownload (const QStringList &urls, bool block=true) |
Cancel a queued or current download. More... | |
void | removeListener (QObject *caller) |
Disconnects the specified caller from any existing MythDownloadInfo instances. More... | |
QDateTime | GetLastModified (const QString &url) |
Gets the Last Modified timestamp for a URI. More... | |
void | loadCookieJar (const QString &filename) |
Loads the cookie jar from a cookie file. More... | |
void | saveCookieJar (const QString &filename) |
Saves the cookie jar to a cookie file. More... | |
void | setCookieJar (QNetworkCookieJar *cookieJar) |
QNetworkCookieJar * | copyCookieJar (void) |
Copy from one cookie jar to another. More... | |
void | refreshCookieJar (QNetworkCookieJar *jar) |
Refresh the temporary cookie jar from another cookie jar. More... | |
void | updateCookieJar (void) |
Update the cookie jar from the temporary cookie jar. More... | |
QString | getHeader (const QUrl &url, const QString &header) |
Public Member Functions inherited from MThread | |
MThread (const QString &objectName) | |
Standard constructor. More... | |
MThread (const QString &objectName, QRunnable *runnable) | |
Use this constructor if you want the default run() method to run the QRunnable's run() method instead of entering the Qt event loop. More... | |
virtual | ~MThread () |
MThread (const MThread &)=delete | |
MThread & | operator= (const MThread &)=delete |
void | RunProlog (void) |
Sets up a thread, call this if you reimplement run(). More... | |
void | RunEpilog (void) |
Cleans up a thread's resources, call this if you reimplement run(). More... | |
QThread * | qthread (void) |
Returns the thread, this will always return the same pointer no matter how often you restart the thread. More... | |
void | setObjectName (const QString &name) |
QString | objectName (void) const |
void | setPriority (QThread::Priority priority) |
QThread::Priority | priority (void) const |
bool | isFinished (void) const |
bool | isRunning (void) const |
void | setStackSize (uint stackSize) |
uint | stackSize (void) const |
void | exit (int retcode=0) |
Use this to exit from the thread if you are using a Qt event loop. More... | |
void | start (QThread::Priority p=QThread::InheritPriority) |
Tell MThread to start running the thread in the near future. More... | |
void | terminate (void) |
Kill a thread unsafely. More... | |
void | quit (void) |
calls exit(0) More... | |
bool | wait (std::chrono::milliseconds time=std::chrono::milliseconds::max()) |
Wait for the MThread to exit, with a maximum timeout. More... | |
Static Public Member Functions | |
static QString | getHeader (const QNetworkCacheMetaData &cacheData, const QString &header) |
Gets the value of an HTTP header from the cache. More... | |
Static Public Member Functions inherited from MThread | |
static void | ThreadSetup (const QString &name) |
This is to be called on startup in those few threads that haven't been ported to MThread. More... | |
static void | ThreadCleanup (void) |
This is to be called on exit in those few threads that haven't been ported to MThread. More... | |
static void | Cleanup (void) |
This will print out all the running threads, call exit(1) on each and then wait up to 5 seconds total for all the threads to exit. More... | |
static void | GetAllThreadNames (QStringList &list) |
static void | GetAllRunningThreadNames (QStringList &list) |
Private Slots | |
void | downloadFinished (QNetworkReply *reply) |
Slot to process download finished events. More... | |
void | authCallback (QNetworkReply *reply, QAuthenticator *authenticator) |
Signal handler for authentication requests. More... | |
void | downloadError (QNetworkReply::NetworkError errorCode) |
Slot to process download error events. More... | |
void | downloadProgress (qint64 bytesReceived, qint64 bytesTotal) |
Slot to process download update events. More... | |
Private Member Functions | |
void | downloadFinished (MythDownloadInfo *dlInfo) |
Callback to process download finished events. More... | |
void | queueItem (const QString &url, QNetworkRequest *req, const QString &dest, QByteArray *data, QObject *caller, MRequestType reqType=kRequestGet, bool reload=false) |
Adds a request to the download queue. More... | |
bool | processItem (const QString &url, QNetworkRequest *req, const QString &dest, QByteArray *data, MRequestType reqType=kRequestGet, bool reload=false, AuthCallback authCallback=nullptr, void *authArg=nullptr, const QHash< QByteArray, QByteArray > *headers=nullptr, QString *finalUrl=nullptr) |
Processes a network request immediately and waits for a response. More... | |
void | downloadRemoteFile (MythDownloadInfo *dlInfo) |
Triggers a myth:// URI download in the background via RemoteFile. More... | |
void | downloadQNetworkRequest (MythDownloadInfo *dlInfo) |
Downloads a QNetworkRequest via the QNetworkAccessManager. More... | |
bool | downloadNow (MythDownloadInfo *dlInfo, bool deleteInfo=true) |
Download helper for download() blocking methods. More... | |
void | downloadCanceled (void) |
void | updateCookieJar (QNetworkCookieJar *jar) |
Static Private Member Functions | |
static QUrl | redirectUrl (const QUrl &possibleRedirectUrl, const QUrl &oldRedirectUrl) |
Checks whether we were redirected to the given URL. More... | |
static bool | saveFile (const QString &outFile, const QByteArray &data, bool append=false) |
Saves a QByteArray of data to a given filename. More... | |
Private Attributes | |
QNetworkAccessManager * | m_manager {nullptr} |
QNetworkDiskCache * | m_diskCache {nullptr} |
QNetworkProxy * | m_proxy {nullptr} |
QWaitCondition | m_queueWaitCond |
QMutex | m_queueWaitLock |
QRecursiveMutex * | m_infoLock {nullptr} |
QMap< QString, MythDownloadInfo * > | m_downloadInfos |
QMap< QNetworkReply *, MythDownloadInfo * > | m_downloadReplies |
QList< MythDownloadInfo * > | m_downloadQueue |
QList< MythDownloadInfo * > | m_cancellationQueue |
QThread * | m_queueThread {nullptr} |
bool | m_runThread {false} |
bool | m_isRunning {false} |
QNetworkCookieJar * | m_inCookieJar {nullptr} |
QMutex | m_cookieLock |
Friends | |
class | RemoteFileDownloadThread |
Additional Inherited Members | |
Protected Member Functions inherited from MThread | |
int | exec (void) |
Enters the qt event loop. call exit or quit to exit thread. More... | |
Static Protected Member Functions inherited from MThread | |
static void | setTerminationEnabled (bool enabled=true) |
static void | usleep (std::chrono::microseconds time) |
template<typename R , typename P > | |
static std::enable_if_t< std::chrono::treat_as_floating_point< R >::value, void > | usleep (std::chrono::duration< R, P > time) |
Protected Attributes inherited from MThread | |
MThreadInternal * | m_thread {nullptr} |
QRunnable * | m_runnable {nullptr} |
bool | m_prologExecuted {true} |
bool | m_epilogExecuted {true} |
Definition at line 48 of file mythdownloadmanager.h.
|
inline |
Constructor for MythDownloadManager.
Instantiates a QNetworkAccessManager and QNetworkDiskCache.
Definition at line 56 of file mythdownloadmanager.h.
|
override |
Destructor for MythDownloadManager.
Definition at line 177 of file mythdownloadmanager.cpp.
|
overridevirtual |
Runs a loop to process incoming download requests and triggers download events to be processed.
Reimplemented from MThread.
Definition at line 191 of file mythdownloadmanager.cpp.
|
inline |
Definition at line 65 of file mythdownloadmanager.h.
|
inline |
Definition at line 66 of file mythdownloadmanager.h.
|
inline |
Definition at line 67 of file mythdownloadmanager.h.
void MythDownloadManager::preCache | ( | const QString & | url | ) |
Downloads a URL but doesn't store the resulting data anywhere.
url | URI to download. |
Definition at line 381 of file mythdownloadmanager.cpp.
void MythDownloadManager::queueDownload | ( | const QString & | url, |
const QString & | dest, | ||
QObject * | caller, | ||
bool | reload = false |
||
) |
Adds a url to the download queue.
url | URI to download. |
dest | Destination filename. |
caller | QObject to receive event notifications. |
reload | Whether to force reloading of the URL or not |
Definition at line 393 of file mythdownloadmanager.cpp.
Referenced by DecoderHandler::createPlaylistFromRemoteUrl(), ThemeChooser::customEvent(), MythWebView::doDownload(), FileServerHandler::HandleDownloadFile(), MainServer::HandleDownloadFile(), ThemeChooser::LoadVersion(), NewsSite::retrieve(), and ThemeChooser::saveAndReload().
void MythDownloadManager::queueDownload | ( | QNetworkRequest * | req, |
QByteArray * | data, | ||
QObject * | caller | ||
) |
Downloads a QNetworkRequest via the QNetworkAccessManager.
req | Network request to GET |
data | Location to store download data |
caller | QObject of caller for event notification |
Definition at line 409 of file mythdownloadmanager.cpp.
bool MythDownloadManager::download | ( | const QString & | url, |
const QString & | dest, | ||
bool | reload = false |
||
) |
Downloads a URL to a file in blocking mode.
url | URI to download. |
dest | Destination filename. |
reload | Whether to force reloading of the URL or not |
Definition at line 430 of file mythdownloadmanager.cpp.
Referenced by ImportIconsWizard::checkAndDownload(), V2Channel::CopyIconToBackend(), Content::DownloadFile(), V2Content::DownloadFile(), DownloadFile(), downloadURL(), RecExtEspnDataSource::loadPage(), RecExtMlbDataSource::loadPage(), ThemeUpdateTask::LoadVersion(), ThemeChooser::LoadVersion(), MythImageReader::MythImageReader(), ThemeInfo::parseThemeInfo(), UPnpDeviceDesc::Retrieve(), and MetadataImageDownload::run().
bool MythDownloadManager::download | ( | const QString & | url, |
QByteArray * | data, | ||
bool | reload = false , |
||
QString * | finalUrl = nullptr |
||
) |
Downloads a URI to a QByteArray in blocking mode.
url | URI to download. |
data | Pointer to destination QByteArray. |
reload | Whether to force reloading of the URL or not |
Definition at line 442 of file mythdownloadmanager.cpp.
Downloads a URI to a QByteArray in blocking mode.
url | URI to download. |
reload | Whether to force reloading of the URL or not |
Definition at line 460 of file mythdownloadmanager.cpp.
bool MythDownloadManager::download | ( | QNetworkRequest * | req, |
QByteArray * | data | ||
) |
Downloads a QNetworkRequest via the QNetworkAccessManager.
req | Information on the network request |
data | Location to store download data |
Definition at line 495 of file mythdownloadmanager.cpp.
bool MythDownloadManager::downloadAuth | ( | const QString & | url, |
const QString & | dest, | ||
bool | reload = false , |
||
AuthCallback | authCallbackFn = nullptr , |
||
void * | authArg = nullptr , |
||
const QHash< QByteArray, QByteArray > * | headers = nullptr |
||
) |
Downloads a URL to a file in blocking mode.
url | URI to download. |
dest | Destination filename. |
reload | Whether to force reloading of the URL or not |
authCallbackFn | AuthCallback function for use with authentication |
authArg | Opaque argument for callback function |
headers | Hash of optional HTTP header to add to the request |
Definition at line 515 of file mythdownloadmanager.cpp.
void MythDownloadManager::queuePost | ( | const QString & | url, |
QByteArray * | data, | ||
QObject * | caller | ||
) |
Queues a post to a URL via the QNetworkAccessManager.
url | URL to post to |
data | Location holding post and response data |
caller | QObject of caller for event notification |
Definition at line 529 of file mythdownloadmanager.cpp.
void MythDownloadManager::queuePost | ( | QNetworkRequest * | req, |
QByteArray * | data, | ||
QObject * | caller | ||
) |
Queues a post to a URL via the QNetworkAccessManager.
req | QNetworkRequest to post |
data | Location holding post and response data |
caller | QObject of caller for event notification |
Definition at line 550 of file mythdownloadmanager.cpp.
bool MythDownloadManager::post | ( | const QString & | url, |
QByteArray * | data | ||
) |
Posts data to a url via the QNetworkAccessManager.
url | URL to post to |
data | Location holding post and response data |
Definition at line 576 of file mythdownloadmanager.cpp.
bool MythDownloadManager::post | ( | QNetworkRequest * | req, |
QByteArray * | data | ||
) |
Posts a QNetworkRequest via the QNetworkAccessManager.
req | Information on the network request |
data | Location holding post and response data |
Definition at line 595 of file mythdownloadmanager.cpp.
bool MythDownloadManager::postAuth | ( | const QString & | url, |
QByteArray * | data, | ||
AuthCallback | authCallbackFn, | ||
void * | authArg, | ||
const QHash< QByteArray, QByteArray > * | headers = nullptr |
||
) |
Posts data to a url via the QNetworkAccessManager.
url | URL to post to |
data | Location holding post and response data |
authCallbackFn | AuthCallback function for authentication |
authArg | Opaque argument for callback function |
headers | Hash of optional HTTP headers to add to the request |
Definition at line 622 of file mythdownloadmanager.cpp.
Cancel a queued or current download.
url | URL for download to cancel |
block | If true, wait until all the cancellations have finished. |
Definition at line 1013 of file mythdownloadmanager.cpp.
Referenced by cancelURL(), DecoderHandler::createPlaylistFromRemoteUrl(), NewsSite::deleteLater(), NewsSite::stop(), ThemeUpdateTask::Terminate(), and NewsSite::~NewsSite().
Cancel a queued or current download.
urls | List of URLs for download to cancel |
block | If true, wait until all the cancellations have finished. |
Definition at line 1022 of file mythdownloadmanager.cpp.
void MythDownloadManager::removeListener | ( | QObject * | caller | ) |
Disconnects the specified caller from any existing MythDownloadInfo instances.
caller | QObject listener to remove |
Definition at line 1106 of file mythdownloadmanager.cpp.
Referenced by NewsSite::deleteLater(), NewsSite::stop(), and NewsSite::~NewsSite().
QDateTime MythDownloadManager::GetLastModified | ( | const QString & | url | ) |
Gets the Last Modified timestamp for a URI.
url | URI to test. |
Definition at line 1541 of file mythdownloadmanager.cpp.
Referenced by MythUIThemeCache::LoadCacheImage(), and MusicMetadata::updateStreamList().
void MythDownloadManager::loadCookieJar | ( | const QString & | filename | ) |
Loads the cookie jar from a cookie file.
filename | Filename of the cookie file to read. |
Definition at line 1635 of file mythdownloadmanager.cpp.
Referenced by GetNetworkAccessManager().
void MythDownloadManager::saveCookieJar | ( | const QString & | filename | ) |
Saves the cookie jar to a cookie file.
filename | Filename of the cookie file to write. |
Definition at line 1647 of file mythdownloadmanager.cpp.
Referenced by MythWebPage::~MythWebPage().
void MythDownloadManager::setCookieJar | ( | QNetworkCookieJar * | cookieJar | ) |
Definition at line 1660 of file mythdownloadmanager.cpp.
QNetworkCookieJar * MythDownloadManager::copyCookieJar | ( | void | ) |
Copy from one cookie jar to another.
Definition at line 1669 of file mythdownloadmanager.cpp.
void MythDownloadManager::refreshCookieJar | ( | QNetworkCookieJar * | jar | ) |
Refresh the temporary cookie jar from another cookie jar.
jar | other cookie jar to update from |
Definition at line 1688 of file mythdownloadmanager.cpp.
Referenced by MythWebPage::~MythWebPage().
void MythDownloadManager::updateCookieJar | ( | void | ) |
Update the cookie jar from the temporary cookie jar.
Definition at line 1707 of file mythdownloadmanager.cpp.
Referenced by run().
QString MythDownloadManager::getHeader | ( | const QUrl & | url, |
const QString & | header | ||
) |
Definition at line 1723 of file mythdownloadmanager.cpp.
Referenced by downloadFinished(), downloadQNetworkRequest(), and GetLastModified().
|
static |
Gets the value of an HTTP header from the cache.
cacheData | The cache data to search through |
header | Which HTTP header to get the value of |
Definition at line 1740 of file mythdownloadmanager.cpp.
|
privateslot |
Slot to process download finished events.
reply | QNetworkReply for completed download. |
Definition at line 1182 of file mythdownloadmanager.cpp.
Referenced by run(), and RemoteFileDownloadThread::run().
|
privateslot |
Signal handler for authentication requests.
reply | Response from the remote server |
authenticator | To fill in with authentication details |
Definition at line 781 of file mythdownloadmanager.cpp.
Referenced by downloadQNetworkRequest().
|
privateslot |
Slot to process download error events.
errorCode | error code |
Definition at line 1138 of file mythdownloadmanager.cpp.
Referenced by downloadFinished(), and downloadQNetworkRequest().
|
privateslot |
Slot to process download update events.
bytesReceived | Bytes received so far |
bytesTotal | Bytes total for the download, -1 if the total is unknown |
Definition at line 1426 of file mythdownloadmanager.cpp.
Referenced by downloadFinished(), and downloadQNetworkRequest().
|
private |
Callback to process download finished events.
dlInfo | MythDownloadInfo for completed download. |
Definition at line 1205 of file mythdownloadmanager.cpp.
|
private |
Adds a request to the download queue.
url | URI to download. |
req | QNetworkRequest to queue |
dest | Destination filename. |
data | Location of data for request |
caller | QObject to receive event notifications. |
reqType | Issue a POST/GET/HEAD request |
reload | Force reloading of the URL |
Definition at line 321 of file mythdownloadmanager.cpp.
Referenced by preCache(), queueDownload(), and queuePost().
|
private |
Processes a network request immediately and waits for a response.
url | URI to download. |
req | QNetworkRequest to queue |
dest | Destination filename. |
data | Location of data for request |
reqType | Issue a POST/GET/HEAD request |
reload | Force reloading of the URL |
authCallback | AuthCallback function for authentication |
authArg | Opaque argument for callback function |
headers | Hash of optional HTTP header to add to the request |
Definition at line 353 of file mythdownloadmanager.cpp.
Referenced by download(), downloadAuth(), post(), and postAuth().
|
private |
Triggers a myth:// URI download in the background via RemoteFile.
dlInfo | MythDownloadInfo information for download |
Definition at line 642 of file mythdownloadmanager.cpp.
Referenced by run().
|
private |
Downloads a QNetworkRequest via the QNetworkAccessManager.
dlInfo | MythDownloadInfo information for download |
Definition at line 651 of file mythdownloadmanager.cpp.
Referenced by run().
|
private |
Download helper for download() blocking methods.
dlInfo | Information on URI to download. |
deleteInfo | Flag to indicate whether to delete the provided MythDownloadInfo instance when done. |
Definition at line 805 of file mythdownloadmanager.cpp.
Referenced by download(), GetLastModified(), and processItem().
|
private |
Definition at line 1073 of file mythdownloadmanager.cpp.
Referenced by cancelDownload(), and run().
|
staticprivate |
Checks whether we were redirected to the given URL.
possibleRedirectUrl | Possible Redirect URL |
oldRedirectUrl | Old Redirect URL |
Definition at line 1167 of file mythdownloadmanager.cpp.
Referenced by downloadFinished().
|
staticprivate |
Saves a QByteArray of data to a given filename.
Any parent directories are created automatically.
outFile | Filename to save to. |
data | Data to save. |
append | Append data to output file instead of overwriting. |
Definition at line 1488 of file mythdownloadmanager.cpp.
Referenced by downloadFinished(), and downloadProgress().
|
private |
|
friend |
Definition at line 180 of file mythdownloadmanager.h.
Referenced by downloadRemoteFile().
|
private |
Definition at line 159 of file mythdownloadmanager.h.
Referenced by copyCookieJar(), downloadFinished(), downloadQNetworkRequest(), getHeader(), GetLastModified(), loadCookieJar(), run(), saveCookieJar(), setCookieJar(), and updateCookieJar().
|
private |
Definition at line 160 of file mythdownloadmanager.h.
Referenced by run().
|
private |
Definition at line 161 of file mythdownloadmanager.h.
Referenced by run().
|
private |
Definition at line 163 of file mythdownloadmanager.h.
Referenced by cancelDownload(), downloadFinished(), downloadNow(), queueItem(), refreshCookieJar(), run(), and ~MythDownloadManager().
|
private |
Definition at line 164 of file mythdownloadmanager.h.
Referenced by downloadNow(), refreshCookieJar(), and run().
|
private |
Definition at line 166 of file mythdownloadmanager.h.
Referenced by cancelDownload(), downloadCanceled(), downloadError(), downloadFinished(), downloadNow(), downloadProgress(), downloadQNetworkRequest(), getHeader(), GetLastModified(), queueItem(), removeListener(), run(), and ~MythDownloadManager().
|
private |
Definition at line 167 of file mythdownloadmanager.h.
Referenced by cancelDownload(), downloadFinished(), removeListener(), and run().
|
private |
Definition at line 168 of file mythdownloadmanager.h.
Referenced by authCallback(), cancelDownload(), downloadError(), downloadFinished(), downloadProgress(), and downloadQNetworkRequest().
|
private |
Definition at line 169 of file mythdownloadmanager.h.
Referenced by cancelDownload(), downloadNow(), queueItem(), removeListener(), and run().
|
private |
Definition at line 170 of file mythdownloadmanager.h.
Referenced by cancelDownload(), downloadCanceled(), and run().
|
private |
Definition at line 172 of file mythdownloadmanager.h.
Referenced by run().
Definition at line 174 of file mythdownloadmanager.h.
Referenced by run(), and ~MythDownloadManager().
Definition at line 175 of file mythdownloadmanager.h.
Referenced by run().
|
private |
Definition at line 177 of file mythdownloadmanager.h.
Referenced by refreshCookieJar(), run(), updateCookieJar(), and ~MythDownloadManager().
|
private |
Definition at line 178 of file mythdownloadmanager.h.
Referenced by copyCookieJar(), loadCookieJar(), refreshCookieJar(), run(), saveCookieJar(), setCookieJar(), and updateCookieJar().