MythDownloadManager Class Reference

#include <mythdownloadmanager.h>

Inheritance diagram for MythDownloadManager:
MThread

List of all members.

Public Member Functions

 MythDownloadManager ()
 Constructor for MythDownloadManager.
 ~MythDownloadManager ()
 Destructor for MythDownloadManager.
void run (void)
 Runs a loop to process incoming download requests and triggers download events to be processed.
void setRunThread (void)
QThread * getQueueThread (void)
bool isRunning (void)
void preCache (const QString &url)
 Downloads a URL but doesn't store the resulting data anywhere.
void queueDownload (const QString &url, const QString &dest, QObject *caller, const bool reload=false)
 Adds a url to the download queue.
void queueDownload (QNetworkRequest *req, QByteArray *data, QObject *caller)
 Downloads a QNetworkRequest via the QNetworkAccessManager.
bool download (const QString &url, const QString &dest, const bool reload=false)
 Downloads a URL to a file in blocking mode.
bool download (const QString &url, QByteArray *data, const bool reload=false)
 Downloads a URI to a QByteArray in blocking mode.
QNetworkReply * download (const QString &url, const bool reload=false)
 Downloads a URI to a QByteArray in blocking mode.
bool download (QNetworkRequest *req, QByteArray *data)
 Downloads a QNetworkRequest via the QNetworkAccessManager.
bool downloadAuth (const QString &url, const QString &dest, const bool reload=false, AuthCallback authCallback=NULL, void *authArg=NULL, const QByteArray *header=NULL, const QByteArray *headerVal=NULL)
 Downloads a URL to a file in blocking mode.
void queuePost (const QString &url, QByteArray *data, QObject *caller)
 Queues a post to a URL via the QNetworkAccessManager.
void queuePost (QNetworkRequest *req, QByteArray *data, QObject *caller)
 Queues a post to a URL via the QNetworkAccessManager.
bool post (const QString &url, QByteArray *data)
 Posts data to a url via the QNetworkAccessManager.
bool post (QNetworkRequest *req, QByteArray *data)
 Posts a QNetworkRequest via the QNetworkAccessManager.
bool postAuth (const QString &url, QByteArray *data, AuthCallback authCallback, void *authArg, const QByteArray *header=NULL, const QByteArray *headerVal=NULL)
 Posts data to a url via the QNetworkAccessManager.
void cancelDownload (const QString &url)
 Cancel a queued or current download.
void removeListener (QObject *caller)
 Disconnects the specified caller from any existing MythDownloadInfo instances.
QDateTime GetLastModified (const QString &url)
 Gets the Last Modified timestamp for a URI.
void loadCookieJar (const QString &filename)
 Loads the cookie jar from a cookie file.
void saveCookieJar (const QString &filename)
 Saves the cookie jar to a cookie file.
void setCookieJar (QNetworkCookieJar *cookieJar)
QNetworkCookieJar * copyCookieJar (void)
 Copy from one cookie jar to another.
void refreshCookieJar (QNetworkCookieJar *jar)
 Refresh the temporary cookie jar from another cookie jar.
void updateCookieJar (void)
 Update the cookie jar from the temporary cookie jar.
QString getHeader (const QUrl &url, const QString &header)
QString getHeader (const QNetworkCacheMetaData &cacheData, const QString &header)
 Gets the value of an HTTP header from the cache.

Private Slots

void downloadFinished (QNetworkReply *reply)
 Slot to process download finished events.
void authCallback (QNetworkReply *reply, QAuthenticator *authenticator)
 Signal handler for authentication requests.
void downloadError (QNetworkReply::NetworkError errorCode)
 Slot to process download error events.
void downloadProgress (qint64 bytesReceived, qint64 bytesTotal)
 Slot to process download update events.

Private Member Functions

void downloadFinished (MythDownloadInfo *dlInfo)
 Callback to process download finished events.
void queueItem (const QString &url, QNetworkRequest *req, const QString &dest, QByteArray *data, QObject *caller, const MRequestType reqType=kRequestGet, const bool reload=false)
 Adds a request to the download queue.
bool processItem (const QString &url, QNetworkRequest *req, const QString &dest, QByteArray *data, const MRequestType reqType=kRequestGet, const bool reload=false, AuthCallback authCallback=NULL, void *authArg=NULL, const QByteArray *header=NULL, const QByteArray *headerVal=NULL)
 Processes a network request immediately and waits for a response.
void downloadRemoteFile (MythDownloadInfo *dlInfo)
 Triggers a myth:// URI download in the background via RemoteFile.
void downloadQNetworkRequest (MythDownloadInfo *dlInfo)
 Downloads a QNetworkRequest via the QNetworkAccessManager.
bool downloadNow (MythDownloadInfo *dlInfo, bool deleteInfo=true)
 Download helper for download() blocking methods.
QUrl redirectUrl (const QUrl &possibleRedirectUrl, const QUrl &oldRedirectUrl) const
 Checks whether we were redirected to the given URL.
bool saveFile (const QString &outFile, const QByteArray &data, const bool append=false)
 Saves a QByteArray of data to a given filename.
void updateCookieJar (QNetworkCookieJar *jar)

Private Attributes

QNetworkAccessManager * m_manager
QNetworkDiskCache * m_diskCache
QNetworkProxy * m_proxy
QWaitCondition m_queueWaitCond
QMutex m_queueWaitLock
QMutex * m_infoLock
QMap< QString, MythDownloadInfo * > m_downloadInfos
QMap< QNetworkReply
*, MythDownloadInfo * > 
m_downloadReplies
QList< MythDownloadInfo * > m_downloadQueue
QThread * m_queueThread
bool m_runThread
bool m_isRunning
QNetworkCookieJar * m_inCookieJar
QMutex m_cookieLock

Friends

class RemoteFileDownloadThread

Detailed Description

Definition at line 31 of file mythdownloadmanager.h.


Constructor & Destructor Documentation

MythDownloadManager::MythDownloadManager (  ) 

Constructor for MythDownloadManager.

Instantiates a QNetworkAccessManager and QNetworkDiskCache.

Definition at line 193 of file mythdownloadmanager.cpp.

MythDownloadManager::~MythDownloadManager (  ) 

Destructor for MythDownloadManager.

Definition at line 208 of file mythdownloadmanager.cpp.


Member Function Documentation

void MythDownloadManager::run ( void   )  [virtual]

Runs a loop to process incoming download requests and triggers download events to be processed.

Reimplemented from MThread.

Definition at line 224 of file mythdownloadmanager.cpp.

void MythDownloadManager::setRunThread ( void   )  [inline]

Definition at line 41 of file mythdownloadmanager.h.

Referenced by GetMythDownloadManager().

QThread* MythDownloadManager::getQueueThread ( void   )  [inline]

Definition at line 42 of file mythdownloadmanager.h.

Referenced by GetMythDownloadManager().

bool MythDownloadManager::isRunning ( void   )  [inline]

Definition at line 43 of file mythdownloadmanager.h.

Referenced by GetMythDownloadManager().

void MythDownloadManager::preCache ( const QString &  url  ) 

Downloads a URL but doesn't store the resulting data anywhere.

Parameters:
url URI to download.

Definition at line 398 of file mythdownloadmanager.cpp.

void MythDownloadManager::queueDownload ( const QString &  url,
const QString &  dest,
QObject *  caller,
const bool  reload = false 
)

Adds a url to the download queue.

Parameters:
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 410 of file mythdownloadmanager.cpp.

Referenced by ThemeChooser::customEvent(), MythWebView::doDownload(), MainServer::HandleDownloadFile(), FileServerHandler::HandleDownloadFile(), ThemeChooser::Load(), and ThemeChooser::saveAndReload().

void MythDownloadManager::queueDownload ( QNetworkRequest *  req,
QByteArray *  data,
QObject *  caller 
)

Downloads a QNetworkRequest via the QNetworkAccessManager.

Parameters:
req Network request to GET
data Location to store download data
caller QObject of caller for event notification

Definition at line 426 of file mythdownloadmanager.cpp.

bool MythDownloadManager::download ( const QString &  url,
const QString &  dest,
const bool  reload = false 
)

Downloads a URL to a file in blocking mode.

Parameters:
url URI to download.
dest Destination filename.
reload Whether to force reloading of the URL or not
Returns:
true if download was successful, false otherwise.

Definition at line 443 of file mythdownloadmanager.cpp.

Referenced by downloadURL(), Metadata::getAlbumArtFile(), ChannelData::handleChannels(), ThemeChooser::Load(), MythUIHelper::LoadScaleImage(), MythImageReader::MythImageReader(), ThemeInfo::parseThemeInfo(), MetadataImageDownload::run(), and HouseKeeper::UpdateThemeChooserInfoCache().

bool MythDownloadManager::download ( const QString &  url,
QByteArray *  data,
const bool  reload = false 
)

Downloads a URI to a QByteArray in blocking mode.

Parameters:
url URI to download.
data Pointer to destination QByteArray.
reload Whether to force reloading of the URL or not
Returns:
true if download was successful, false otherwise.

Definition at line 455 of file mythdownloadmanager.cpp.

QNetworkReply * MythDownloadManager::download ( const QString &  url,
const bool  reload = false 
)

Downloads a URI to a QByteArray in blocking mode.

Parameters:
url URI to download.
reload Whether to force reloading of the URL or not
Returns:
pointer to the QNetworkReply containing the download response, NULL if an error

Definition at line 467 of file mythdownloadmanager.cpp.

bool MythDownloadManager::download ( QNetworkRequest *  req,
QByteArray *  data 
)

Downloads a QNetworkRequest via the QNetworkAccessManager.

Parameters:
req Information on the network request
data Location to store download data
Returns:
true if download was successful, false otherwise.

Definition at line 498 of file mythdownloadmanager.cpp.

bool MythDownloadManager::downloadAuth ( const QString &  url,
const QString &  dest,
const bool  reload = false,
AuthCallback  authCallback = NULL,
void *  authArg = NULL,
const QByteArray *  header = NULL,
const QByteArray *  headerVal = NULL 
)

Downloads a URL to a file in blocking mode.

Parameters:
url URI to download.
dest Destination filename.
reload Whether to force reloading of the URL or not
authCallback AuthCallback function for use with authentication
authArg Opaque argument for callback function
header Optional HTTP header to add to the request
headerVal Value for the optional HTTP header to add to the request
Returns:
true if download was successful, false otherwise.

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.

Parameters:
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.

Parameters:
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.

Parameters:
url URL to post to
data Location holding post and response data
Returns:
true if post was successful, false otherwise.

Definition at line 572 of file mythdownloadmanager.cpp.

Referenced by DataDirectProcessor::Post().

bool MythDownloadManager::post ( QNetworkRequest *  req,
QByteArray *  data 
)

Posts a QNetworkRequest via the QNetworkAccessManager.

Parameters:
req Information on the network request
data Location holding post and response data
Returns:
true if post was successful, false otherwise.

Definition at line 591 of file mythdownloadmanager.cpp.

bool MythDownloadManager::postAuth ( const QString &  url,
QByteArray *  data,
AuthCallback  authCallback,
void *  authArg,
const QByteArray *  header = NULL,
const QByteArray *  headerVal = NULL 
)

Posts data to a url via the QNetworkAccessManager.

Parameters:
url URL to post to
data Location holding post and response data
authCallback AuthCallback function for authentication
authArg Opaque argument for callback function
header Optional HTTP header to add to the request
headerVal Value for the optional HTTP header to add to the request
Returns:
true if post was successful, false otherwise.

Definition at line 615 of file mythdownloadmanager.cpp.

Referenced by DataDirectProcessor::DDPost(), and DataDirectProcessor::GrabNextSuggestedTime().

void MythDownloadManager::cancelDownload ( const QString &  url  ) 

Cancel a queued or current download.

Parameters:
url for download to cancel

Definition at line 843 of file mythdownloadmanager.cpp.

void MythDownloadManager::removeListener ( QObject *  caller  ) 

Disconnects the specified caller from any existing MythDownloadInfo instances.

Parameters:
caller QObject listener to remove

Definition at line 888 of file mythdownloadmanager.cpp.

QDateTime MythDownloadManager::GetLastModified ( const QString &  url  ) 

Gets the Last Modified timestamp for a URI.

Parameters:
url URI to test.
Returns:
Timestamp the URI was last modified or now if an error occurred

Definition at line 1286 of file mythdownloadmanager.cpp.

Referenced by MythUIHelper::LoadCacheImage().

void MythDownloadManager::loadCookieJar ( const QString &  filename  ) 

Loads the cookie jar from a cookie file.

Parameters:
filename Filename of the cookie file to read.

Definition at line 1374 of file mythdownloadmanager.cpp.

Referenced by DataDirectProcessor::Post().

void MythDownloadManager::saveCookieJar ( const QString &  filename  ) 

Saves the cookie jar to a cookie file.

Parameters:
filename Filename of the cookie file to write.

Definition at line 1386 of file mythdownloadmanager.cpp.

Referenced by DataDirectProcessor::Post().

void MythDownloadManager::setCookieJar ( QNetworkCookieJar *  cookieJar  ) 

Definition at line 1397 of file mythdownloadmanager.cpp.

QNetworkCookieJar * MythDownloadManager::copyCookieJar ( void   ) 

Copy from one cookie jar to another.

Returns:
new copy of the cookie jar

Definition at line 1406 of file mythdownloadmanager.cpp.

void MythDownloadManager::refreshCookieJar ( QNetworkCookieJar *  jar  ) 

Refresh the temporary cookie jar from another cookie jar.

Parameters:
jar other cookie jar to update from

Definition at line 1422 of file mythdownloadmanager.cpp.

Referenced by DestroyNetworkAccessManager().

void MythDownloadManager::updateCookieJar ( void   ) 

Update the cookie jar from the temporary cookie jar.

Definition at line 1438 of file mythdownloadmanager.cpp.

Referenced by run().

QString MythDownloadManager::getHeader ( const QUrl &  url,
const QString &  header 
)
QString MythDownloadManager::getHeader ( const QNetworkCacheMetaData &  cacheData,
const QString &  header 
)

Gets the value of an HTTP header from the cache.

Parameters:
cacheData The cache data to search through
header Which HTTP header to get the value of
Returns:
a QString containing the value of the HTTP header

Definition at line 1467 of file mythdownloadmanager.cpp.

void MythDownloadManager::downloadFinished ( QNetworkReply *  reply  )  [private, slot]

Slot to process download finished events.

Parameters:
reply QNetworkReply for completed download.

Definition at line 963 of file mythdownloadmanager.cpp.

Referenced by run(), and RemoteFileDownloadThread::run().

void MythDownloadManager::authCallback ( QNetworkReply *  reply,
QAuthenticator *  authenticator 
) [private, slot]

Signal handler for authentication requests.

Parameters:
reply Response from the remote server
authenticator To fill in with authentication details

Definition at line 759 of file mythdownloadmanager.cpp.

Referenced by downloadQNetworkRequest().

void MythDownloadManager::downloadError ( QNetworkReply::NetworkError  errorCode  )  [private, slot]

Slot to process download error events.

Parameters:
errorCode error code

Definition at line 921 of file mythdownloadmanager.cpp.

Referenced by downloadFinished(), and downloadQNetworkRequest().

void MythDownloadManager::downloadProgress ( qint64  bytesReceived,
qint64  bytesTotal 
) [private, slot]

Slot to process download update events.

Parameters:
bytesReceived Bytes received so far
bytesTotal Bytes total for the download, -1 if the total is unknown

Definition at line 1170 of file mythdownloadmanager.cpp.

Referenced by downloadFinished(), and downloadQNetworkRequest().

void MythDownloadManager::downloadFinished ( MythDownloadInfo dlInfo  )  [private]

Callback to process download finished events.

Parameters:
dlInfo MythDownloadInfo for completed download.

Definition at line 986 of file mythdownloadmanager.cpp.

void MythDownloadManager::queueItem ( const QString &  url,
QNetworkRequest *  req,
const QString &  dest,
QByteArray *  data,
QObject *  caller,
const MRequestType  reqType = kRequestGet,
const bool  reload = false 
) [private]

Adds a request to the download queue.

Parameters:
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 335 of file mythdownloadmanager.cpp.

Referenced by preCache(), queueDownload(), and queuePost().

bool MythDownloadManager::processItem ( const QString &  url,
QNetworkRequest *  req,
const QString &  dest,
QByteArray *  data,
const MRequestType  reqType = kRequestGet,
const bool  reload = false,
AuthCallback  authCallback = NULL,
void *  authArg = NULL,
const QByteArray *  header = NULL,
const QByteArray *  headerVal = NULL 
) [private]

Processes a network request immediately and waits for a response.

Parameters:
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
header Optional HTTP header to add to the request
headerVal Value for the optional HTTP header to add to the request

Definition at line 370 of file mythdownloadmanager.cpp.

Referenced by download(), downloadAuth(), post(), and postAuth().

void MythDownloadManager::downloadRemoteFile ( MythDownloadInfo dlInfo  )  [private]

Triggers a myth:// URI download in the background via RemoteFile.

Parameters:
dlInfo MythDownloadInfo information for download

Definition at line 636 of file mythdownloadmanager.cpp.

Referenced by run().

void MythDownloadManager::downloadQNetworkRequest ( MythDownloadInfo dlInfo  )  [private]

Downloads a QNetworkRequest via the QNetworkAccessManager.

Parameters:
dlInfo MythDownloadInfo information for download

Definition at line 646 of file mythdownloadmanager.cpp.

Referenced by run().

bool MythDownloadManager::downloadNow ( MythDownloadInfo dlInfo,
bool  deleteInfo = true 
) [private]

Download helper for download() blocking methods.

Parameters:
dlInfo Information on URI to download.
deleteInfo Flag to indicate whether to delete the provided MythDownloadInfo instance when done.
Returns:
true if download was successful, false otherwise.

Definition at line 783 of file mythdownloadmanager.cpp.

Referenced by download(), GetLastModified(), and processItem().

QUrl MythDownloadManager::redirectUrl ( const QUrl &  possibleRedirectUrl,
const QUrl &  oldRedirectUrl 
) const [private]

Checks whether we were redirected to the given URL.

Parameters:
possibleRedirectUrl Possible Redirect URL
oldRedirectUrl Old Redirect URL
Returns:
empty QUrl if we were not redirected, otherwise the redirected URL

Definition at line 948 of file mythdownloadmanager.cpp.

Referenced by downloadFinished().

bool MythDownloadManager::saveFile ( const QString &  outFile,
const QByteArray &  data,
const bool  append = false 
) [private]

Saves a QByteArray of data to a given filename.

Any parent directories are created automatically.

Parameters:
outFile Filename to save to.
data Data to save.
append Append data to output file instead of overwriting.
Returns:
true if successful, false otherwise

Definition at line 1230 of file mythdownloadmanager.cpp.

Referenced by downloadFinished(), and downloadProgress().

void MythDownloadManager::updateCookieJar ( QNetworkCookieJar *  jar  )  [private]

Friends And Related Function Documentation

friend class RemoteFileDownloadThread [friend]

Definition at line 150 of file mythdownloadmanager.h.

Referenced by downloadRemoteFile().


Member Data Documentation

QNetworkAccessManager* MythDownloadManager::m_manager [private]
QNetworkDiskCache* MythDownloadManager::m_diskCache [private]

Definition at line 131 of file mythdownloadmanager.h.

Referenced by run().

QNetworkProxy* MythDownloadManager::m_proxy [private]

Definition at line 132 of file mythdownloadmanager.h.

Referenced by run().

QWaitCondition MythDownloadManager::m_queueWaitCond [private]

Definition at line 135 of file mythdownloadmanager.h.

Referenced by downloadNow(), refreshCookieJar(), and run().

Definition at line 138 of file mythdownloadmanager.h.

Referenced by cancelDownload(), downloadFinished(), removeListener(), and run().

QMap<QNetworkReply*, MythDownloadInfo*> MythDownloadManager::m_downloadReplies [private]

Definition at line 140 of file mythdownloadmanager.h.

Referenced by cancelDownload(), downloadNow(), queueItem(), removeListener(), and run().

Definition at line 142 of file mythdownloadmanager.h.

Referenced by run().

Definition at line 144 of file mythdownloadmanager.h.

Referenced by run(), and ~MythDownloadManager().

Definition at line 145 of file mythdownloadmanager.h.

Referenced by run().

QNetworkCookieJar* MythDownloadManager::m_inCookieJar [private]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends
Generated on Fri May 25 06:42:13 2012 for MythTV by  doxygen 1.6.3