本文整理汇总了C++中QNetworkCacheMetaData类的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkCacheMetaData类的具体用法?C++ QNetworkCacheMetaData怎么用?C++ QNetworkCacheMetaData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QNetworkCacheMetaData类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qurl
/** \brief Downloads a QNetworkRequest via the QNetworkAccessManager
* \param dlInfo MythDownloadInfo information for download
*/
void MythDownloadManager::downloadQNetworkRequest(MythDownloadInfo *dlInfo)
{
if (!dlInfo)
return;
static const char dateFormat[] = "ddd, dd MMM yyyy hh:mm:ss 'GMT'";
QUrl qurl(dlInfo->m_url);
QNetworkRequest request;
if (dlInfo->m_request)
{
request = *dlInfo->m_request;
delete dlInfo->m_request;
dlInfo->m_request = NULL;
}
else
request.setUrl(qurl);
if (!dlInfo->m_reload)
{
// Prefer the in-cache item if one exists and it is less than 5 minutes
// old and it will not expire in the next 10 seconds
QDateTime now = MythDate::current();
// Handle redirects, we want the metadata of the file headers
QString redirectLoc;
int limit = 0;
while (!(redirectLoc = getHeader(qurl, "Location")).isNull())
{
if (limit == CACHE_REDIRECTION_LIMIT)
{
LOG(VB_GENERAL, LOG_WARNING, QString("Cache Redirection limit "
"reached for %1")
.arg(qurl.toString()));
return;
}
qurl.setUrl(redirectLoc);
limit++;
}
LOG(VB_NETWORK, LOG_DEBUG, QString("Checking cache for %1")
.arg(qurl.toString()));
m_infoLock->lock();
QNetworkCacheMetaData urlData = m_manager->cache()->metaData(qurl);
m_infoLock->unlock();
if ((urlData.isValid()) &&
((!urlData.expirationDate().isValid()) ||
(QDateTime(urlData.expirationDate().toUTC()).secsTo(now) < 10)))
{
QString dateString = getHeader(urlData, "Date");
if (!dateString.isNull())
{
QDateTime loadDate =
MythDate::fromString(dateString, dateFormat);
loadDate.setTimeSpec(Qt::UTC);
if (loadDate.secsTo(now) <= 720)
{
dlInfo->m_preferCache = true;
LOG(VB_NETWORK, LOG_DEBUG, QString("Prefering cache for %1")
.arg(qurl.toString()));
}
}
}
}
if (dlInfo->m_preferCache)
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
QNetworkRequest::PreferCache);
request.setRawHeader("User-Agent",
"MythTV v" MYTH_BINARY_VERSION " MythDownloadManager");
if (dlInfo->m_headers)
{
QHash<QByteArray, QByteArray>::const_iterator it =
dlInfo->m_headers->constBegin();
for ( ; it != dlInfo->m_headers->constEnd(); ++it )
{
if (!it.key().isEmpty() && !it.value().isEmpty())
{
request.setRawHeader(it.key(), it.value());
}
}
}
switch (dlInfo->m_requestType)
{
case kRequestPost :
dlInfo->m_reply = m_manager->post(request, *dlInfo->m_data);
break;
case kRequestHead :
dlInfo->m_reply = m_manager->head(request);
break;
case kRequestGet :
default:
//.........这里部分代码省略.........
示例2: QCOMPARE
void tst_QNetworkCacheMetaData::qnetworkcachemetadata()
{
QNetworkCacheMetaData data;
QCOMPARE(data.expirationDate(), QDateTime());
QCOMPARE(data.isValid(), false);
QCOMPARE(data.lastModified(), QDateTime());
QCOMPARE(data.operator!=(QNetworkCacheMetaData()), false);
QNetworkCacheMetaData metaData;
QCOMPARE(data.operator=(metaData), QNetworkCacheMetaData());
QCOMPARE(data.operator==(QNetworkCacheMetaData()), true);
QCOMPARE(data.rawHeaders(), QNetworkCacheMetaData::RawHeaderList());
QCOMPARE(data.saveToDisk(), true);
QCOMPARE(data.url(), QUrl());
data.setExpirationDate(QDateTime());
data.setLastModified(QDateTime());
data.setRawHeaders(QNetworkCacheMetaData::RawHeaderList());
data.setSaveToDisk(false);
data.setUrl(QUrl());
}