diff --git a/article_netmgr.cc b/article_netmgr.cc index 4b07f675..07fd4e26 100644 --- a/article_netmgr.cc +++ b/article_netmgr.cc @@ -1,4 +1,4 @@ -/* This file is (c) 2008-2012 Konstantin Isakov +/* This file is (c) 2008-2012 Konstantin Isakov * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ #if defined( _MSC_VER ) && _MSC_VER < 1800 // VS2012 and older @@ -13,6 +13,7 @@ #include "wstring_qt.hh" #include "gddebug.hh" #include "qt4x5.hh" +#include using std::string; @@ -284,6 +285,17 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op, #else return reply; #endif +} + +void ArticleNetworkAccessManager:: requestStart(QUrl url){ + qDebug(U"slots executes,执行了"); + qDebug()< ArticleNetworkAccessManager::getResource( @@ -556,3 +568,25 @@ void BlockedNetworkReply::finishedSlot() emit readyRead(); emit finished(); } + +MySchemeHandler::MySchemeHandler(ArticleNetworkAccessManager& articleNetMgr):mManager(articleNetMgr){ + } + void MySchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob) + { + // .... + QUrl url = requestJob->requestUrl(); + +// QNetworkRequest* request = new QNetworkRequest(url); + + QNetworkRequest request; + request.setUrl( url ); + QNetworkReply* reply = mManager. createRequest(QNetworkAccessManager::GetOperation,request,NULL); + + + + // Reply segment + requestJob->reply("text/html", reply); + connect(this, SIGNAL(requestStart(QUrl)),&mManager,SLOT(requestStart(QUrl)),Qt::QueuedConnection ); + emit requestStart(url); + } + diff --git a/article_netmgr.hh b/article_netmgr.hh index 6cc31d6a..a91cd735 100644 --- a/article_netmgr.hh +++ b/article_netmgr.hh @@ -1,4 +1,4 @@ -/* This file is (c) 2008-2012 Konstantin Isakov +/* This file is (c) 2008-2012 Konstantin Isakov * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ #ifndef __ARTICLE_NETMGR_HH_INCLUDED__ @@ -11,6 +11,9 @@ #include #include #include +#include +#include +#include #endif #include "dictionary.hh" @@ -94,6 +97,7 @@ protected: class ArticleNetworkAccessManager: public QNetworkAccessManager { + Q_OBJECT vector< sptr< Dictionary::Class > > const & dictionaries; ArticleMaker const & articleMaker; bool const & disallowContentFromOtherSites; @@ -122,11 +126,14 @@ public: sptr< Dictionary::DataRequest > getResource( QUrl const & url, QString & contentType ); -protected: +//protected: virtual QNetworkReply * createRequest( Operation op, QNetworkRequest const & req, QIODevice * outgoingData ); +private slots: + + void requestStart(QUrl url); }; class ArticleResourceReply: public QNetworkReply @@ -199,4 +206,19 @@ private slots: void finishedSlot(); }; + +class MySchemeHandler : public QWebEngineUrlSchemeHandler +{ + Q_OBJECT +public: + MySchemeHandler(ArticleNetworkAccessManager& articleNetMgr); + void requestStarted(QWebEngineUrlRequestJob *requestJob); +protected: +signals: + + void requestStart(QUrl url); + +private: + ArticleNetworkAccessManager& mManager; +}; #endif diff --git a/main.cc b/main.cc index e3d793d2..d96d4d5b 100644 --- a/main.cc +++ b/main.cc @@ -1,4 +1,4 @@ -/* This file is (c) 2008-2012 Konstantin Isakov +/* This file is (c) 2008-2012 Konstantin Isakov * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ #include @@ -6,7 +6,8 @@ #include "gdappstyle.hh" #include "mainwindow.hh" #include "config.hh" - +#include "article_netmgr.hh" +#include #include "processwrapper.hh" #include "hotkeywrapper.hh" #ifdef HAVE_X11 @@ -300,6 +301,14 @@ int main( int argc, char ** argv ) #endif + QWebEngineUrlScheme webUiScheme("gdlookup"); + webUiScheme.setFlags(QWebEngineUrlScheme::SecureScheme | + QWebEngineUrlScheme::LocalScheme | + QWebEngineUrlScheme::LocalAccessAllowed); + QWebEngineUrlScheme::registerScheme(webUiScheme); + + + QHotkeyApplication app( "GoldenDict", argc, argv ); LogFilePtrGuard logFilePtrGuard; @@ -434,11 +443,7 @@ int main( int argc, char ** argv ) // and with the main window closed. app.setQuitOnLastWindowClosed( false ); - QWebEngineUrlScheme webUiScheme("gdlookup"); - webUiScheme.setFlags(QWebEngineUrlScheme::SecureScheme | - QWebEngineUrlScheme::LocalScheme | - QWebEngineUrlScheme::LocalAccessAllowed); - QWebEngineUrlScheme::registerScheme(webUiScheme); + MainWindow m( cfg ); diff --git a/mainwindow.cc b/mainwindow.cc index f2214b12..424807b4 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -1,4 +1,4 @@ -/* This file is (c) 2008-2012 Konstantin Isakov +/* This file is (c) 2008-2012 Konstantin Isakov * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ #ifndef NO_EPWING_SUPPORT @@ -6,6 +6,7 @@ #endif #include "mainwindow.hh" +#include #include #include "editdictionaries.hh" #include "loaddictionaries.hh" @@ -143,6 +144,10 @@ MainWindow::MainWindow( Config::Class & cfg_ ): QThreadPool::globalInstance()->start( new InitSSLRunnable ); #endif + + MySchemeHandler *handler = new MySchemeHandler(articleNetMgr); + QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("gdlookup", handler); + qRegisterMetaType< Config::InputPhrase >(); #ifndef NO_EPWING_SUPPORT