mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
add local scheme ,such as qrcx,gadu,etc.
This commit is contained in:
parent
0279273369
commit
4a5af10277
|
@ -201,15 +201,11 @@ static QVariant runJavaScriptSync(QWebEnginePage* frame, const QString& variable
|
|||
{
|
||||
qDebug(QString("runJavascriptScriptSync with :%1").arg(variable).toLatin1().data());
|
||||
QVariant variant;
|
||||
// QSemaphore semaph(1);
|
||||
// semaph.acquire(1);
|
||||
|
||||
frame->runJavaScript(variable, [](const QVariant& result) {
|
||||
// variant = result;
|
||||
//semaph.release(1);
|
||||
|
||||
});
|
||||
|
||||
//todo ,
|
||||
//semaph.acquire(1);
|
||||
return variant;
|
||||
}
|
||||
|
||||
|
@ -1697,25 +1693,18 @@ bool ArticleView::hasSound()
|
|||
//todo ,need further effort
|
||||
void ArticleView::playSound()
|
||||
{
|
||||
QVariant v;
|
||||
QString soundScript;
|
||||
runJavaScriptSync( ui.definition->page(),
|
||||
" var link=gdAudioLinks[gdAudioLinks.current]; "
|
||||
" if(link==undefined){ "
|
||||
" link=gdAudioLinks.first; "
|
||||
" } "
|
||||
" "
|
||||
" var music = new Audio(link); "
|
||||
" music.muted=true; "
|
||||
|
||||
v = runJavaScriptSync( ui.definition->page(),"gdAudioLinks[gdAudioLinks.current]" );
|
||||
" music.play(); "
|
||||
|
||||
|
||||
if ( v.type() == QVariant::String )
|
||||
soundScript = v.toString();
|
||||
|
||||
// fallback to the first one
|
||||
if ( soundScript.isEmpty() )
|
||||
{
|
||||
v = runJavaScriptSync( ui.definition->page(), "gdAudioLinks.first" );
|
||||
if ( v.type() == QVariant::String )
|
||||
soundScript = v.toString();
|
||||
}
|
||||
|
||||
if ( !soundScript.isEmpty() )
|
||||
openLink( QUrl::fromEncoded( soundScript.toUtf8() ), ui.definition->url() );
|
||||
);
|
||||
}
|
||||
|
||||
QString ArticleView::toHtml()
|
||||
|
|
|
@ -12,6 +12,10 @@ void GicoSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
|
|||
|
||||
QNetworkReply* reply=this->mManager.createRequest(QNetworkAccessManager::GetOperation,request,NULL);
|
||||
|
||||
QString contentType="image/png";
|
||||
if(url.scheme()=="gadu"){
|
||||
contentType="audio/wav";
|
||||
}
|
||||
// Reply segment
|
||||
requestJob->reply("image/png", reply);
|
||||
requestJob->reply(contentType.toLatin1(), reply);
|
||||
}
|
||||
|
|
22
main.cc
22
main.cc
|
@ -295,19 +295,17 @@ int main( int argc, char ** argv )
|
|||
#endif
|
||||
|
||||
|
||||
QStringList localSchemes={"gdlookup","gdau","gico","qrcx","bres"};
|
||||
|
||||
QWebEngineUrlScheme webUiScheme("gdlookup");
|
||||
webUiScheme.setFlags(QWebEngineUrlScheme::SecureScheme |
|
||||
QWebEngineUrlScheme::LocalScheme |
|
||||
QWebEngineUrlScheme::LocalAccessAllowed);
|
||||
QWebEngineUrlScheme::registerScheme(webUiScheme);
|
||||
|
||||
|
||||
QWebEngineUrlScheme gico("gico");
|
||||
webUiScheme.setFlags(QWebEngineUrlScheme::SecureScheme |
|
||||
QWebEngineUrlScheme::LocalScheme |
|
||||
QWebEngineUrlScheme::LocalAccessAllowed);
|
||||
QWebEngineUrlScheme::registerScheme(gico);
|
||||
for (int i = 0; i < localSchemes.size(); ++i)
|
||||
{
|
||||
QString localScheme=localSchemes.at(i);
|
||||
QWebEngineUrlScheme webUiScheme(localScheme.toLatin1());
|
||||
webUiScheme.setFlags(QWebEngineUrlScheme::SecureScheme |
|
||||
QWebEngineUrlScheme::LocalScheme |
|
||||
QWebEngineUrlScheme::LocalAccessAllowed);
|
||||
QWebEngineUrlScheme::registerScheme(webUiScheme);
|
||||
}
|
||||
|
||||
|
||||
QHotkeyApplication app( "GoldenDict", argc, argv );
|
||||
|
|
|
@ -148,7 +148,11 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
|
||||
MySchemeHandler *handler = new MySchemeHandler();
|
||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("gdlookup", handler);
|
||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("gico", new GicoSchemeHandler(articleNetMgr));
|
||||
|
||||
QStringList localSchemes={"gdau","gico","qrcx","bres"};
|
||||
for(int i=0;i<localSchemes.size();i++){
|
||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler(localSchemes.at(i).toLatin1(), new GicoSchemeHandler(articleNetMgr));
|
||||
}
|
||||
connect(handler,SIGNAL(requestStart(QUrl&)),this,SLOT(requestStart(QUrl&)));
|
||||
|
||||
qRegisterMetaType< Config::InputPhrase >();
|
||||
|
|
Loading…
Reference in a new issue