Skip to content

Commit

Permalink
Merge branch 'staged' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed Jun 8, 2022
2 parents b2e9728 + 0e4e7af commit 7820146
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 5 deletions.
21 changes: 17 additions & 4 deletions article_netmgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "gddebug.hh"
#include "utils.hh"
#include <QNetworkAccessManager>
#include "globalbroadcaster.h"

using std::string;

Expand Down Expand Up @@ -249,11 +250,23 @@ QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest co
}

sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource(
QUrl const & url, QString & contentType )
QUrl const & resUrl, QString & contentType )
{
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() );
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::number( GlobalBroadcaster::instance()->getGroupId() ) );
Utils::Url::addQueryItem( url, "muted", GlobalBroadcaster::instance()->mutedDicts );
}

if ( url.scheme() == "gdlookup" )
{
Expand Down
2 changes: 2 additions & 0 deletions articleview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ void ArticleView::showDefinition( Config::InputPhrase const & phrase, unsigned g
if ( mutedDicts.size() )
Utils::Url::addQueryItem( req, "muted", mutedDicts );

GlobalBroadcaster::instance()->mutedDicts = mutedDicts;

// Update both histories (pages history and headwords history)
saveHistoryUserData();
emit sendWordToHistory( phrase.phrase );
Expand Down
8 changes: 8 additions & 0 deletions globalbroadcaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@ void GlobalBroadcaster::addWhitelist(QString url){
bool GlobalBroadcaster::existedInWhitelist(QString url){
return std::find(whitelist.begin(), whitelist.end(), url) != whitelist.end();
}

void GlobalBroadcaster::setGroupId(unsigned groupId){
this->groupId = groupId;
}

unsigned GlobalBroadcaster::getGroupId(){
return groupId;
}
// namespace global
9 changes: 9 additions & 0 deletions globalbroadcaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@ class GlobalBroadcaster : public QObject
private:
Config::Preferences * preference;
std::vector<QString> whitelist;
unsigned groupId;


public:
void setPreference( Config::Preferences * _pre );
Config::Preferences * getPreference();
GlobalBroadcaster( QObject * parent = nullptr );
void addWhitelist(QString host);
bool existedInWhitelist(QString host);
static GlobalBroadcaster * instance();

//store the latest groupId;
void setGroupId(unsigned groupId);
unsigned getGroupId();

QString mutedDicts;
signals:
void dictionaryChanges( ActiveDictIds ad );
};
Expand Down
6 changes: 6 additions & 0 deletions mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,9 @@ void MainWindow::updateGroupList()

groupList->fill( groupInstances );
groupList->setCurrentGroup( cfg.lastMainGroupId );

GlobalBroadcaster::instance()->setGroupId( cfg.lastMainGroupId);

updateCurrentGroupProperty();

updateDictionaryBar();
Expand Down Expand Up @@ -2305,6 +2308,9 @@ void MainWindow::updateCurrentGroupProperty()
Instances::Group * grp =
groupInstances.findGroup( groupList->getCurrentGroup() );

//record the latest groupid
GlobalBroadcaster::instance()->setGroupId(groupList->getCurrentGroup());

if ( grp && translateLine->property( "currentGroup" ).toString() !=
grp->name )
{
Expand Down
5 changes: 5 additions & 0 deletions resources/gd-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ $(function() {
if ('string' != typeof(link)) {
return;
}

if(link.indexOf("javascript:")>=0){
return;
}

if(link.indexOf(":")>=0){
emitClickedEvent(link);
return false;
Expand Down
4 changes: 3 additions & 1 deletion utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ inline std::pair< bool, QString > getQueryWord( QUrl const & url )
{
//url,bword://localhost/word
if( path.startsWith( "/" ) )
word = url.path().mid( 1 );
word = path.mid( 1 );
else
word = path;
}
else
{
Expand Down

0 comments on commit 7820146

Please sign in to comment.