mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
feature:webengineprofile use non off record profile
This commit is contained in:
parent
da406e1e02
commit
e84b5aa861
|
@ -1,8 +1,9 @@
|
||||||
#include "articlewebpage.h"
|
#include "articlewebpage.h"
|
||||||
#include "utils.hh"
|
#include "utils.hh"
|
||||||
|
#include "globalbroadcaster.h"
|
||||||
|
|
||||||
ArticleWebPage::ArticleWebPage(QObject *parent)
|
ArticleWebPage::ArticleWebPage( QObject * parent ):
|
||||||
: QWebEnginePage{parent}
|
QWebEnginePage{ GlobalBroadcaster::instance()->profile, parent }
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
bool ArticleWebPage::acceptNavigationRequest( const QUrl & resUrl, NavigationType type, bool isMainFrame )
|
bool ArticleWebPage::acceptNavigationRequest( const QUrl & resUrl, NavigationType type, bool isMainFrame )
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <QWebEngineProfile>
|
||||||
#include "config.hh"
|
#include "config.hh"
|
||||||
|
|
||||||
struct ActiveDictIds
|
struct ActiveDictIds
|
||||||
|
@ -27,6 +28,7 @@ public:
|
||||||
static GlobalBroadcaster * instance();
|
static GlobalBroadcaster * instance();
|
||||||
unsigned currentGroupId;
|
unsigned currentGroupId;
|
||||||
QString translateLineText{};
|
QString translateLineText{};
|
||||||
|
QWebEngineProfile * profile;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void dictionaryChanges( ActiveDictIds ad );
|
void dictionaryChanges( ActiveDictIds ad );
|
||||||
|
|
|
@ -97,12 +97,11 @@ void MainWindow::changeWebEngineViewFont()
|
||||||
{
|
{
|
||||||
if( cfg.preferences.webFontFamily.isEmpty() )
|
if( cfg.preferences.webFontFamily.isEmpty() )
|
||||||
{
|
{
|
||||||
QWebEngineProfile::defaultProfile()->settings()->resetFontFamily( QWebEngineSettings::StandardFont );
|
webEngineProfile->settings()->resetFontFamily( QWebEngineSettings::StandardFont );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QWebEngineProfile::defaultProfile()->settings()->setFontFamily( QWebEngineSettings::StandardFont,
|
webEngineProfile->settings()->setFontFamily( QWebEngineSettings::StandardFont, cfg.preferences.webFontFamily );
|
||||||
cfg.preferences.webFontFamily );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,28 +153,28 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
||||||
QThreadPool::globalInstance()->start( new InitSSLRunnable );
|
QThreadPool::globalInstance()->start( new InitSSLRunnable );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GlobalBroadcaster::instance()->setPreference(&cfg.preferences);
|
GlobalBroadcaster::instance()->setPreference( &cfg.preferences );
|
||||||
|
|
||||||
localSchemeHandler = new LocalSchemeHandler( articleNetMgr, this);
|
webEngineProfile.reset( new QWebEngineProfile( "GoldenDictProfile" ) );
|
||||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "gdlookup", localSchemeHandler );
|
GlobalBroadcaster::instance()->profile = webEngineProfile.get();
|
||||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "bword", localSchemeHandler );
|
localSchemeHandler = new LocalSchemeHandler( articleNetMgr, this );
|
||||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "entry", localSchemeHandler );
|
webEngineProfile->installUrlSchemeHandler( "gdlookup", localSchemeHandler );
|
||||||
|
webEngineProfile->installUrlSchemeHandler( "bword", localSchemeHandler );
|
||||||
|
webEngineProfile->installUrlSchemeHandler( "entry", localSchemeHandler );
|
||||||
|
|
||||||
iframeSchemeHandler = new IframeSchemeHandler( this );
|
iframeSchemeHandler = new IframeSchemeHandler( this );
|
||||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "ifr", iframeSchemeHandler );
|
webEngineProfile->installUrlSchemeHandler( "ifr", iframeSchemeHandler );
|
||||||
|
|
||||||
QStringList localSchemes = { "gdau", "gico", "qrcx", "bres", "gdprg", "gdvideo", "gdpicture", "gdtts" };
|
QStringList localSchemes = { "gdau", "gico", "qrcx", "bres", "gdprg", "gdvideo", "gdpicture", "gdtts" };
|
||||||
resourceSchemeHandler = new ResourceSchemeHandler( articleNetMgr, this);
|
resourceSchemeHandler = new ResourceSchemeHandler( articleNetMgr, this );
|
||||||
for( int i = 0; i < localSchemes.size(); i++ )
|
for( const auto & localScheme : localSchemes ) {
|
||||||
{
|
webEngineProfile->installUrlSchemeHandler( localScheme.toLatin1(), resourceSchemeHandler );
|
||||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( localSchemes.at( i ).toLatin1(),
|
|
||||||
resourceSchemeHandler );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QWebEngineProfile::defaultProfile()->setUrlRequestInterceptor( new WebUrlRequestInterceptor(this) );
|
webEngineProfile->setUrlRequestInterceptor( new WebUrlRequestInterceptor( this ) );
|
||||||
|
|
||||||
if(!cfg.preferences.hideGoldenDictHeader){
|
if( !cfg.preferences.hideGoldenDictHeader ) {
|
||||||
QWebEngineProfile::defaultProfile()->setHttpUserAgent(QWebEngineProfile::defaultProfile()->httpUserAgent()+" GoldenDict/WebEngine");
|
webEngineProfile->setHttpUserAgent( webEngineProfile->httpUserAgent() + " GoldenDict/WebEngine" );
|
||||||
}
|
}
|
||||||
|
|
||||||
qRegisterMetaType< Config::InputPhrase >();
|
qRegisterMetaType< Config::InputPhrase >();
|
||||||
|
@ -1416,8 +1415,7 @@ void MainWindow::setupNetworkCache( int maxSize )
|
||||||
return; // There is currently no cache and it is not needed.
|
return; // There is currently no cache and it is not needed.
|
||||||
|
|
||||||
QString const cacheDirectory = Config::getNetworkCacheDir();
|
QString const cacheDirectory = Config::getNetworkCacheDir();
|
||||||
if( !QDir().mkpath( cacheDirectory ) )
|
if( !QDir().mkpath( cacheDirectory ) ) {
|
||||||
{
|
|
||||||
gdWarning( "Cannot create a cache directory %s. Disabling network cache.", cacheDirectory.toUtf8().constData() );
|
gdWarning( "Cannot create a cache directory %s. Disabling network cache.", cacheDirectory.toUtf8().constData() );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1425,6 +1423,9 @@ void MainWindow::setupNetworkCache( int maxSize )
|
||||||
diskCache->setMaximumCacheSize( maxCacheSizeInBytes );
|
diskCache->setMaximumCacheSize( maxCacheSizeInBytes );
|
||||||
diskCache->setCacheDirectory( cacheDirectory );
|
diskCache->setCacheDirectory( cacheDirectory );
|
||||||
articleNetMgr.setCache( diskCache );
|
articleNetMgr.setCache( diskCache );
|
||||||
|
|
||||||
|
webEngineProfile->setCachePath( cacheDirectory );
|
||||||
|
webEngineProfile->setPersistentStoragePath( cacheDirectory );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::makeDictionaries()
|
void MainWindow::makeDictionaries()
|
||||||
|
|
|
@ -136,7 +136,7 @@ private:
|
||||||
History history;
|
History history;
|
||||||
DictionaryBar dictionaryBar;
|
DictionaryBar dictionaryBar;
|
||||||
vector< sptr< Dictionary::Class > > dictionaries;
|
vector< sptr< Dictionary::Class > > dictionaries;
|
||||||
QMap<std::string, sptr< Dictionary::Class > > dictMap;
|
QMap< std::string, sptr< Dictionary::Class > > dictMap;
|
||||||
/// Here we store unmuted dictionaries when the dictionary bar is active
|
/// Here we store unmuted dictionaries when the dictionary bar is active
|
||||||
vector< sptr< Dictionary::Class > > dictionariesUnmuted;
|
vector< sptr< Dictionary::Class > > dictionariesUnmuted;
|
||||||
Instances::Groups groupInstances;
|
Instances::Groups groupInstances;
|
||||||
|
@ -145,6 +145,9 @@ private:
|
||||||
QNetworkAccessManager dictNetMgr; // We give dictionaries a separate manager,
|
QNetworkAccessManager dictNetMgr; // We give dictionaries a separate manager,
|
||||||
// since their requests can be destroyed
|
// since their requests can be destroyed
|
||||||
// in a separate thread
|
// in a separate thread
|
||||||
|
|
||||||
|
QScopedPointer< QWebEngineProfile > webEngineProfile;
|
||||||
|
|
||||||
AudioPlayerFactory audioPlayerFactory;
|
AudioPlayerFactory audioPlayerFactory;
|
||||||
|
|
||||||
WordList * wordList;
|
WordList * wordList;
|
||||||
|
|
|
@ -657,14 +657,11 @@ void Preferences::on_buttonBox_accepted()
|
||||||
if( prevWebFontFamily != currentFontFamily )
|
if( prevWebFontFamily != currentFontFamily )
|
||||||
{
|
{
|
||||||
//reset to default font .
|
//reset to default font .
|
||||||
if( currentFontFamily.isEmpty() )
|
if( currentFontFamily.isEmpty() ) {
|
||||||
{
|
GlobalBroadcaster::instance()->profile->settings()->resetFontFamily( QWebEngineSettings::StandardFont );
|
||||||
QWebEngineProfile::defaultProfile()->settings()->resetFontFamily( QWebEngineSettings::StandardFont );
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
GlobalBroadcaster::instance()->profile->settings()->setFontFamily( QWebEngineSettings::StandardFont, currentFontFamily );
|
||||||
QWebEngineProfile::defaultProfile()->settings()->setFontFamily( QWebEngineSettings::StandardFont,
|
|
||||||
currentFontFamily );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue