mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
remember last link's groupId and muted dictionary
This commit is contained in:
parent
88b265765f
commit
547f2a4cd2
|
@ -250,22 +250,11 @@ QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest co
|
|||
}
|
||||
|
||||
sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource(
|
||||
QUrl const & resUrl, QString & contentType )
|
||||
QUrl const & url, QString & contentType )
|
||||
{
|
||||
GD_DPRINTF( "getResource: %ls", resUrl.toString().toStdWString().c_str() );
|
||||
GD_DPRINTF( "scheme: %ls", resUrl.scheme().toStdWString().c_str() );
|
||||
GD_DPRINTF( "host: %ls", resUrl.host().toStdWString().c_str() );
|
||||
|
||||
QUrl url = resUrl;
|
||||
if( url.scheme() == "bword" || url.scheme() == "entry" )
|
||||
{
|
||||
url.setScheme( "gdlookup" );
|
||||
url.setHost( "localhost" );
|
||||
url.setPath( "" );
|
||||
auto [ valid, word ] = Utils::Url::getQueryWord( resUrl );
|
||||
Utils::Url::addQueryItem( url, "word", word );
|
||||
Utils::Url::addQueryItem( url, "group", QString( "%1" ).arg( GlobalBroadcaster::instance()->getGroupId() ) );
|
||||
}
|
||||
GD_DPRINTF( "getResource: %ls", url.toString().toStdWString().c_str() );
|
||||
GD_DPRINTF( "scheme: %ls", url.scheme().toStdWString().c_str() );
|
||||
GD_DPRINTF( "host: %ls", url.host().toStdWString().c_str() );
|
||||
|
||||
if ( url.scheme() == "gdlookup" )
|
||||
{
|
||||
|
@ -285,8 +274,6 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource(
|
|||
|
||||
bool groupIsValid = false;
|
||||
unsigned group = Utils::Url::queryItemValue( url, "group" ).toUInt( &groupIsValid );
|
||||
|
||||
GlobalBroadcaster::instance()->setGroupId(group);
|
||||
|
||||
QString dictIDs = Utils::Url::queryItemValue( url, "dictionaries" );
|
||||
if( !dictIDs.isEmpty() )
|
||||
|
|
|
@ -1,15 +1,38 @@
|
|||
#include "articlewebpage.h"
|
||||
#include "utils.hh"
|
||||
|
||||
ArticleWebPage::ArticleWebPage(QObject *parent)
|
||||
: QWebEnginePage{parent}
|
||||
{
|
||||
}
|
||||
bool ArticleWebPage::acceptNavigationRequest( const QUrl & url, NavigationType type, bool isMainFrame )
|
||||
bool ArticleWebPage::acceptNavigationRequest( const QUrl & resUrl, NavigationType type, bool isMainFrame )
|
||||
{
|
||||
QUrl url = resUrl;
|
||||
if( url.scheme() == "bword" || url.scheme() == "entry" )
|
||||
{
|
||||
url.setScheme( "gdlookup" );
|
||||
url.setHost( "localhost" );
|
||||
url.setPath( "" );
|
||||
auto [ valid, word ] = Utils::Url::getQueryWord( resUrl );
|
||||
Utils::Url::addQueryItem( url, "word", word );
|
||||
Utils::Url::addQueryItem( url, "group", lastReq.group );
|
||||
Utils::Url::addQueryItem( url, "muted", lastReq.mutedDicts );
|
||||
setUrl( url );
|
||||
return false;
|
||||
}
|
||||
|
||||
//save current gdlookup's values.
|
||||
if( url.scheme() == "gdlookup" )
|
||||
{
|
||||
lastReq.group = Utils::Url::queryItemValue( url, "group" );
|
||||
lastReq.mutedDicts = Utils::Url::queryItemValue( url, "muted" );
|
||||
}
|
||||
|
||||
if( type == QWebEnginePage::NavigationTypeLinkClicked )
|
||||
{
|
||||
emit linkClicked( url );
|
||||
return true;
|
||||
}
|
||||
|
||||
return QWebEnginePage::acceptNavigationRequest( url, type, isMainFrame );
|
||||
}
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
|
||||
#include <QWebEnginePage>
|
||||
|
||||
struct LastReqInfo{
|
||||
QString group;
|
||||
QString mutedDicts;
|
||||
};
|
||||
|
||||
class ArticleWebPage : public QWebEnginePage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -12,6 +17,8 @@ signals:
|
|||
void linkClicked( const QUrl & url );
|
||||
protected:
|
||||
virtual bool acceptNavigationRequest( const QUrl & url, NavigationType type, bool isMainFrame );
|
||||
private:
|
||||
LastReqInfo lastReq;
|
||||
};
|
||||
|
||||
#endif // ARTICLEWEBPAGE_H
|
||||
|
|
|
@ -20,21 +20,15 @@ Config::Preferences * GlobalBroadcaster::getPreference()
|
|||
return preference;
|
||||
}
|
||||
|
||||
void GlobalBroadcaster::addWhitelist(QString url){
|
||||
whitelist.push_back(url);
|
||||
auto baseUrl=::getHostBase(url);
|
||||
whitelist.push_back(baseUrl);
|
||||
void GlobalBroadcaster::addWhitelist( QString url )
|
||||
{
|
||||
whitelist.push_back( url );
|
||||
auto baseUrl = ::getHostBase( url );
|
||||
whitelist.push_back( baseUrl );
|
||||
}
|
||||
|
||||
bool GlobalBroadcaster::existedInWhitelist(QString url){
|
||||
return std::find(whitelist.begin(), whitelist.end(), url) != whitelist.end();
|
||||
}
|
||||
|
||||
void GlobalBroadcaster::setGroupId(int groupId){
|
||||
this->groupId = groupId;
|
||||
}
|
||||
|
||||
int GlobalBroadcaster::getGroupId(){
|
||||
return groupId;
|
||||
bool GlobalBroadcaster::existedInWhitelist( QString url )
|
||||
{
|
||||
return std::find( whitelist.begin(), whitelist.end(), url ) != whitelist.end();
|
||||
}
|
||||
// namespace global
|
||||
|
|
|
@ -17,7 +17,6 @@ class GlobalBroadcaster : public QObject
|
|||
private:
|
||||
Config::Preferences * preference;
|
||||
std::vector<QString> whitelist;
|
||||
int groupId;
|
||||
|
||||
public:
|
||||
void setPreference( Config::Preferences * _pre );
|
||||
|
@ -27,9 +26,6 @@ public:
|
|||
bool existedInWhitelist(QString host);
|
||||
static GlobalBroadcaster * instance();
|
||||
|
||||
//store the latest groupId;
|
||||
void setGroupId(int groupId);
|
||||
int getGroupId();
|
||||
signals:
|
||||
void dictionaryChanges( ActiveDictIds ad );
|
||||
};
|
||||
|
|
|
@ -1417,6 +1417,7 @@ void MainWindow::updateGroupList()
|
|||
|
||||
groupList->fill( groupInstances );
|
||||
groupList->setCurrentGroup( cfg.lastMainGroupId );
|
||||
|
||||
updateCurrentGroupProperty();
|
||||
|
||||
updateDictionaryBar();
|
||||
|
|
Loading…
Reference in a new issue