From d73956b90d35374245eb1a39504f1f8cad0fcb4f Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Thu, 19 May 2022 07:14:36 +0800 Subject: [PATCH] opt: change ArticleNetworkAccessManager's method createRequest to getArticleReply createRequest was the parent's protected method ,give the impression that the derived class has override it. rename it to clacify the misunderstand. --- article_netmgr.cc | 18 ++++++++---------- article_netmgr.hh | 16 +++++----------- resourceschemehandler.cpp | 2 +- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/article_netmgr.cc b/article_netmgr.cc index 9a3edc6b..e63ebfff 100644 --- a/article_netmgr.cc +++ b/article_netmgr.cc @@ -150,12 +150,11 @@ using std::string; return size; } -QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op, - QNetworkRequest const & req, - QIODevice * outgoingData ) +QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest const & req ) { QUrl url; - if ( op == GetOperation ) + auto op = GetOperation; +// if ( op == GetOperation ) { if ( req.url().scheme() == "qrcx" ) { @@ -169,7 +168,7 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op, QNetworkRequest newReq( req ); newReq.setUrl( newUrl ); - return QNetworkAccessManager::createRequest( op, newReq, outgoingData ); + return QNetworkAccessManager::createRequest( op, newReq, nullptr ); } url=req.url(); @@ -237,7 +236,7 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op, QNetworkRequest newReq( req ); newReq.setUrl( newUrl ); - return QNetworkAccessManager::createRequest( op, newReq, outgoingData ); + return QNetworkAccessManager::createRequest( op, newReq, nullptr ); } } @@ -250,7 +249,7 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op, newReq.setRawHeader("User-Agent", req.rawHeader("User-Agent").replace(qApp->applicationName().toUtf8(), "")); } - QNetworkReply * reply = QNetworkAccessManager::createRequest( op, newReq, outgoingData ); + QNetworkReply * reply = QNetworkAccessManager::createRequest( op, newReq, nullptr ); if( url.scheme() == "https") { @@ -260,8 +259,7 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op, #endif } - return op == QNetworkAccessManager::GetOperation - || op == QNetworkAccessManager::HeadOperation ? new AllowFrameReply( reply ) : reply; + return new AllowFrameReply( reply ); } sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource( @@ -528,7 +526,7 @@ void LocalSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob) QNetworkRequest request; request.setUrl( url ); - QNetworkReply * reply = this->mManager.createRequest( QNetworkAccessManager::GetOperation, request ); + QNetworkReply * reply = this->mManager.getArticleReply( request ); connect( reply, &QNetworkReply::finished, requestJob, [ = ]() { requestJob->reply( "text/html", reply ); } ); connect( requestJob, &QObject::destroyed, reply, &QObject::deleteLater ); } diff --git a/article_netmgr.hh b/article_netmgr.hh index 2e881b28..713d1b79 100644 --- a/article_netmgr.hh +++ b/article_netmgr.hh @@ -122,11 +122,7 @@ public: sptr< Dictionary::DataRequest > getResource( QUrl const & url, QString & contentType ); -// protected: - - virtual QNetworkReply * createRequest( Operation op, - QNetworkRequest const & req, - QIODevice * outgoingData = nullptr); + virtual QNetworkReply * getArticleReply( QNetworkRequest const & req ); }; @@ -202,18 +198,16 @@ private slots: void finishedSlot(); }; - class LocalSchemeHandler : public QWebEngineUrlSchemeHandler { - Q_OBJECT + Q_OBJECT public: - LocalSchemeHandler(ArticleNetworkAccessManager &articleNetMgr); - void requestStarted(QWebEngineUrlRequestJob *requestJob); + LocalSchemeHandler( ArticleNetworkAccessManager & articleNetMgr ); + void requestStarted( QWebEngineUrlRequestJob * requestJob ); protected: - private: - ArticleNetworkAccessManager& mManager; + ArticleNetworkAccessManager & mManager; QNetworkAccessManager mgr; }; #endif diff --git a/resourceschemehandler.cpp b/resourceschemehandler.cpp index 38c257aa..97a79253 100644 --- a/resourceschemehandler.cpp +++ b/resourceschemehandler.cpp @@ -10,7 +10,7 @@ void ResourceSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob) QNetworkRequest request; request.setUrl(url); request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); - QNetworkReply *reply = this->mManager.createRequest(QNetworkAccessManager::GetOperation, request); + QNetworkReply *reply = this->mManager.getArticleReply( request); connect(reply, &QNetworkReply::finished, requestJob, [=]() { if (reply->error() == QNetworkReply::ContentNotFoundError) { requestJob->fail(QWebEngineUrlRequestJob::UrlNotFound);