mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
register local scheme gdlookup://
This commit is contained in:
parent
54bdf12d8d
commit
939a96b7a6
|
@ -1,4 +1,4 @@
|
|||
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
||||
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
||||
* 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 <QNetworkAccessManager>
|
||||
|
||||
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()<<url;
|
||||
// QNetworkRequest request;
|
||||
// request.setUrl( url );
|
||||
// QNetworkReply* reply = mManager. createRequest(QNetworkAccessManager::GetOperation,request,NULL);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
sptr< Dictionary::DataRequest > 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
||||
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
||||
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||
|
||||
#ifndef __ARTICLE_NETMGR_HH_INCLUDED__
|
||||
|
@ -11,6 +11,9 @@
|
|||
#include <QSet>
|
||||
#include <QMap>
|
||||
#include <QPair>
|
||||
#include <QWebEngineUrlSchemeHandler>
|
||||
#include <QWebEngineUrlRequestJob>
|
||||
#include <QNetworkAccessManager>
|
||||
#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
|
||||
|
|
19
main.cc
19
main.cc
|
@ -1,4 +1,4 @@
|
|||
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
||||
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
||||
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -6,7 +6,8 @@
|
|||
#include "gdappstyle.hh"
|
||||
#include "mainwindow.hh"
|
||||
#include "config.hh"
|
||||
|
||||
#include "article_netmgr.hh"
|
||||
#include <QWebEngineProfile>
|
||||
#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 );
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
||||
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
||||
* 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 <QWebEngineProfile>
|
||||
#include <QWebEngineSettings>
|
||||
#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
|
||||
|
|
Loading…
Reference in a new issue