mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
change to setcontent
This commit is contained in:
parent
b1c4159a3d
commit
e5c72f8ecc
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
8
main.cc
8
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;
|
||||
|
|
|
@ -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){
|
||||
|
|
Loading…
Reference in a new issue