diff --git a/article_netmgr.cc b/article_netmgr.cc index 3c0a9062..688569d3 100644 --- a/article_netmgr.cc +++ b/article_netmgr.cc @@ -376,6 +376,7 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource( { if( url.scheme() == "gico" ) { + contentType="image/png"; QByteArray bytes; QBuffer buffer(&bytes); buffer.open(QIODevice::WriteOnly); @@ -564,12 +565,11 @@ void BlockedNetworkReply::finishedSlot() emit finished(); } -MySchemeHandler::MySchemeHandler(ArticleNetworkAccessManager &articleNetMgr):mManager(articleNetMgr){ - //connect(this, SIGNAL(requestStart(QUrl)),&mManager,SLOT(requestStart(QUrl)),Qt::QueuedConnection ); +MySchemeHandler::MySchemeHandler(){ + } void MySchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob) { - // .... QUrl url = requestJob->requestUrl(); // QNetworkRequest* request = new QNetworkRequest(url); diff --git a/article_netmgr.hh b/article_netmgr.hh index c5c17da5..dcd5cf66 100644 --- a/article_netmgr.hh +++ b/article_netmgr.hh @@ -211,14 +211,12 @@ class MySchemeHandler : public QWebEngineUrlSchemeHandler { Q_OBJECT public: - MySchemeHandler(ArticleNetworkAccessManager& articleNetMgr); + MySchemeHandler(); void requestStarted(QWebEngineUrlRequestJob *requestJob); + protected: + signals: - void requestStart(QUrl& url); - -private: - ArticleNetworkAccessManager& mManager; }; #endif diff --git a/articleview.cc b/articleview.cc index f41fcad5..b8f47bf0 100644 --- a/articleview.cc +++ b/articleview.cc @@ -261,12 +261,12 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, ui.definition->pageAction( QWebEnginePage::Copy )->setShortcut( QKeySequence::Copy ); ui.definition->addAction( ui.definition->pageAction( QWebEnginePage::Copy ) ); -// QAction * selectAll = ui.definition->pageAction( QWebEnginePage::SelectAll ); -// selectAll->setShortcut( QKeySequence::SelectAll ); -// selectAll->setShortcutContext( Qt::WidgetWithChildrenShortcut ); -// ui.definition->addAction( selectAll ); + QAction * selectAll = ui.definition->pageAction( QWebEnginePage::SelectAll ); + selectAll->setShortcut( QKeySequence::SelectAll ); + selectAll->setShortcutContext( Qt::WidgetWithChildrenShortcut ); + ui.definition->addAction( selectAll ); -// ui.definition->setContextMenuPolicy( Qt::DefaultContextMenu ); + ui.definition->setContextMenuPolicy( Qt::CustomContextMenu ); //todo //ui.definition->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks ); @@ -1735,6 +1735,10 @@ void ArticleView::setHtml(const QString& content,const QUrl& baseUrl){ ui.definition->page()->setHtml(content,baseUrl); } +void ArticleView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl ){ + ui.definition->page()->setContent(data,mimeType,baseUrl); +} + QString ArticleView::getTitle() { return ui.definition->page()->title(); diff --git a/articleview.hh b/articleview.hh index 9455ec6f..ebd95a9f 100644 --- a/articleview.hh +++ b/articleview.hh @@ -167,6 +167,7 @@ public: QString toHtml(); void setHtml(const QString& content, const QUrl& baseUrl); + void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl()); /// Returns current article's title QString getTitle(); diff --git a/main.cc b/main.cc index 65211ea8..b5522934 100644 --- a/main.cc +++ b/main.cc @@ -294,6 +294,8 @@ int main( int argc, char ** argv ) #endif + + QWebEngineUrlScheme webUiScheme("gdlookup"); webUiScheme.setFlags(QWebEngineUrlScheme::SecureScheme | QWebEngineUrlScheme::LocalScheme | @@ -301,6 +303,12 @@ int main( int argc, char ** argv ) QWebEngineUrlScheme::registerScheme(webUiScheme); + QWebEngineUrlScheme gico("gico"); + webUiScheme.setFlags(QWebEngineUrlScheme::SecureScheme | + QWebEngineUrlScheme::LocalScheme | + QWebEngineUrlScheme::LocalAccessAllowed); + QWebEngineUrlScheme::registerScheme(gico); + QHotkeyApplication app( "GoldenDict", argc, argv ); LogFilePtrGuard logFilePtrGuard; diff --git a/mainwindow.cc b/mainwindow.cc index a208717f..0d46e3e3 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -145,8 +145,9 @@ MainWindow::MainWindow( Config::Class & cfg_ ): #endif - MySchemeHandler *handler = new MySchemeHandler(articleNetMgr); + MySchemeHandler *handler = new MySchemeHandler(); QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("gdlookup", handler); + //QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("gico", handler); connect(handler,SIGNAL(requestStart(QUrl&)),this,SLOT(requestStart(QUrl&))); qRegisterMetaType< Config::InputPhrase >(); @@ -1621,7 +1622,13 @@ void MainWindow::finished(){ ArticleView * view = getCurrentArticleView(); if ( view ) { - view->setHtml(QString(reply->readAll()),reply->url()); + //view->setHtml(QString(reply->readAll()),reply->url()); + QVariant header=reply->header(QNetworkRequest::KnownHeaders::ContentTypeHeader); + QString contentType=header.toString(); + //if(contentType=="text/html") + { + view->setContent(reply->readAll(),header.toString()); + } } } void MainWindow::requestStart(QUrl &url){