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 */
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||||
|
|
||||||
#if defined( _MSC_VER ) && _MSC_VER < 1800 // VS2012 and older
|
#if defined( _MSC_VER ) && _MSC_VER < 1800 // VS2012 and older
|
||||||
|
@ -13,6 +13,7 @@
|
||||||
#include "wstring_qt.hh"
|
#include "wstring_qt.hh"
|
||||||
#include "gddebug.hh"
|
#include "gddebug.hh"
|
||||||
#include "qt4x5.hh"
|
#include "qt4x5.hh"
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
@ -284,6 +285,17 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
|
||||||
#else
|
#else
|
||||||
return reply;
|
return reply;
|
||||||
#endif
|
#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(
|
sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource(
|
||||||
|
@ -556,3 +568,25 @@ void BlockedNetworkReply::finishedSlot()
|
||||||
emit readyRead();
|
emit readyRead();
|
||||||
emit finished();
|
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 */
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||||
|
|
||||||
#ifndef __ARTICLE_NETMGR_HH_INCLUDED__
|
#ifndef __ARTICLE_NETMGR_HH_INCLUDED__
|
||||||
|
@ -11,6 +11,9 @@
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
|
#include <QWebEngineUrlSchemeHandler>
|
||||||
|
#include <QWebEngineUrlRequestJob>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "dictionary.hh"
|
#include "dictionary.hh"
|
||||||
|
@ -94,6 +97,7 @@ protected:
|
||||||
|
|
||||||
class ArticleNetworkAccessManager: public QNetworkAccessManager
|
class ArticleNetworkAccessManager: public QNetworkAccessManager
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
vector< sptr< Dictionary::Class > > const & dictionaries;
|
vector< sptr< Dictionary::Class > > const & dictionaries;
|
||||||
ArticleMaker const & articleMaker;
|
ArticleMaker const & articleMaker;
|
||||||
bool const & disallowContentFromOtherSites;
|
bool const & disallowContentFromOtherSites;
|
||||||
|
@ -122,11 +126,14 @@ public:
|
||||||
sptr< Dictionary::DataRequest > getResource( QUrl const & url,
|
sptr< Dictionary::DataRequest > getResource( QUrl const & url,
|
||||||
QString & contentType );
|
QString & contentType );
|
||||||
|
|
||||||
protected:
|
//protected:
|
||||||
|
|
||||||
virtual QNetworkReply * createRequest( Operation op,
|
virtual QNetworkReply * createRequest( Operation op,
|
||||||
QNetworkRequest const & req,
|
QNetworkRequest const & req,
|
||||||
QIODevice * outgoingData );
|
QIODevice * outgoingData );
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void requestStart(QUrl url);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ArticleResourceReply: public QNetworkReply
|
class ArticleResourceReply: public QNetworkReply
|
||||||
|
@ -199,4 +206,19 @@ private slots:
|
||||||
void finishedSlot();
|
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
|
#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 */
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -6,7 +6,8 @@
|
||||||
#include "gdappstyle.hh"
|
#include "gdappstyle.hh"
|
||||||
#include "mainwindow.hh"
|
#include "mainwindow.hh"
|
||||||
#include "config.hh"
|
#include "config.hh"
|
||||||
|
#include "article_netmgr.hh"
|
||||||
|
#include <QWebEngineProfile>
|
||||||
#include "processwrapper.hh"
|
#include "processwrapper.hh"
|
||||||
#include "hotkeywrapper.hh"
|
#include "hotkeywrapper.hh"
|
||||||
#ifdef HAVE_X11
|
#ifdef HAVE_X11
|
||||||
|
@ -300,6 +301,14 @@ int main( int argc, char ** argv )
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
QWebEngineUrlScheme webUiScheme("gdlookup");
|
||||||
|
webUiScheme.setFlags(QWebEngineUrlScheme::SecureScheme |
|
||||||
|
QWebEngineUrlScheme::LocalScheme |
|
||||||
|
QWebEngineUrlScheme::LocalAccessAllowed);
|
||||||
|
QWebEngineUrlScheme::registerScheme(webUiScheme);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QHotkeyApplication app( "GoldenDict", argc, argv );
|
QHotkeyApplication app( "GoldenDict", argc, argv );
|
||||||
LogFilePtrGuard logFilePtrGuard;
|
LogFilePtrGuard logFilePtrGuard;
|
||||||
|
|
||||||
|
@ -434,11 +443,7 @@ int main( int argc, char ** argv )
|
||||||
// and with the main window closed.
|
// and with the main window closed.
|
||||||
app.setQuitOnLastWindowClosed( false );
|
app.setQuitOnLastWindowClosed( false );
|
||||||
|
|
||||||
QWebEngineUrlScheme webUiScheme("gdlookup");
|
|
||||||
webUiScheme.setFlags(QWebEngineUrlScheme::SecureScheme |
|
|
||||||
QWebEngineUrlScheme::LocalScheme |
|
|
||||||
QWebEngineUrlScheme::LocalAccessAllowed);
|
|
||||||
QWebEngineUrlScheme::registerScheme(webUiScheme);
|
|
||||||
|
|
||||||
MainWindow m( cfg );
|
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 */
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||||
|
|
||||||
#ifndef NO_EPWING_SUPPORT
|
#ifndef NO_EPWING_SUPPORT
|
||||||
|
@ -6,6 +6,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "mainwindow.hh"
|
#include "mainwindow.hh"
|
||||||
|
#include <QWebEngineProfile>
|
||||||
#include <QWebEngineSettings>
|
#include <QWebEngineSettings>
|
||||||
#include "editdictionaries.hh"
|
#include "editdictionaries.hh"
|
||||||
#include "loaddictionaries.hh"
|
#include "loaddictionaries.hh"
|
||||||
|
@ -143,6 +144,10 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
||||||
QThreadPool::globalInstance()->start( new InitSSLRunnable );
|
QThreadPool::globalInstance()->start( new InitSSLRunnable );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
MySchemeHandler *handler = new MySchemeHandler(articleNetMgr);
|
||||||
|
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("gdlookup", handler);
|
||||||
|
|
||||||
qRegisterMetaType< Config::InputPhrase >();
|
qRegisterMetaType< Config::InputPhrase >();
|
||||||
|
|
||||||
#ifndef NO_EPWING_SUPPORT
|
#ifndef NO_EPWING_SUPPORT
|
||||||
|
|
Loading…
Reference in a new issue