#include "cachewebview.h" #include CacheWebView::CacheWebView(QWidget *parent) : QWebView(parent) { cache = 0; isCacheFile = false; m_isloading = false; setAcceptDrops(false); QObject::connect(this,SIGNAL(linkClicked(QUrl)),this,SLOT(onLinkClicked(QUrl))); } void CacheWebView::setPageUrl(QString pageUrl, QString cachePath) { if(pageUrl.isEmpty()) return; this->pageUrl = pageUrl; this->cachePath = cachePath; QUrl url(pageUrl); connect(this,SIGNAL(loadFinished(bool)),this,SLOT(onWebViewFinished(bool))); this->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); this->load(url); } CacheWebView::~CacheWebView() { if(cache) { cache->abort(); cache->wait(); delete cache; cache = 0; } qDebug()<pageUrl,QCoreApplication::applicationDirPath()+"/../cache/"); } cache->start(); } else { isCacheFile = true; displayCacheFile(); } } } void CacheWebView::displayCacheFile() { QUrl url(this->pageUrl); QString md5; QByteArray ba; ba = QCryptographicHash::hash ( this->pageUrl.toAscii(), QCryptographicHash::Md5 ); md5.append(ba.toHex()); QString cacheFile = QCoreApplication::applicationDirPath()+"/../cache/" + md5 + url.path(); if(QFile::exists(cacheFile)) { this->load(QUrl::fromUserInput(cacheFile)); } }