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 May 29, 2022
2 parents 83684c2 + 9c1a22d commit 99876e6
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 240 deletions.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
## Until to now

- **CLEANING OLD/USELESS CODE**
- remove Runnable Class in dsl, zim , epwing etc files.

- add "send to anki"
- right context menu actions, remove nonsense character like `OBJ`,punctuation etc.
- epwing remove duplicate entries when index.


## Until 2022-5-21
- fix a zim about:blank#block [issue](https://github.com/goldendict/goldendict/issues/1472#issuecomment-1086776611)
- add fallback font family configuration for dictionary through preference dialog.
- fix mdx (compact html) display error on the last item.
Expand Down
9 changes: 4 additions & 5 deletions article_inspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ ArticleInspector::ArticleInspector( QWidget * parent ) : QWidget( parent, Qt::Wi
QVBoxLayout * v = new QVBoxLayout( this );
v->setSpacing( 0 );
v->setContentsMargins( 0, 0, 0, 0 );
inspectView = new QWebEngineView( this );
v->addWidget( inspectView );
viewContainer = new QWebEngineView( this );
v->addWidget( viewContainer );

resize(800,600);
}

void ArticleInspector::setInspectPage( QWebEngineView * view )
{
auto page=view->page();
this->inspectedPage = page;
page->setDevToolsPage( inspectView->page() );
viewContainer->page()->setInspectedPage(page);
#if( QT_VERSION > QT_VERSION_CHECK( 6, 0, 0 ) )
// without this line, application will crash on qt6.2 ,see https://bugreports.qt.io/browse/QTBUG-101724
if( view->lastContextMenuRequest() )
Expand All @@ -36,5 +35,5 @@ void ArticleInspector::setInspectPage( QWebEngineView * view )

void ArticleInspector::closeEvent( QCloseEvent * )
{
inspectedPage->setDevToolsPage( nullptr );
viewContainer->page()->setInspectedPage(nullptr);
}
3 changes: 1 addition & 2 deletions article_inspect.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
class ArticleInspector : public QWidget
{
Q_OBJECT
QWebEngineView * inspectView = nullptr;
QWebEnginePage * inspectedPage = nullptr;
QWebEngineView * viewContainer = nullptr;
public:
ArticleInspector( QWidget * parent = nullptr );

Expand Down
12 changes: 6 additions & 6 deletions article_maker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ void ArticleRequest::altSearchFinished()
if ( altSearches.empty() )
{
#ifdef QT_DEBUG
qDebug( "alts finished\n" );
qDebug( "alts finished" );
#endif

// They all've finished! Now we can look up bodies
Expand Down Expand Up @@ -534,7 +534,7 @@ void ArticleRequest::bodyFinished()
if ( bodyDone )
return;

GD_DPRINTF( "some body finished\n" );
GD_DPRINTF( "some body finished" );

bool wasUpdated = false;

Expand All @@ -546,7 +546,7 @@ void ArticleRequest::bodyFinished()
{
// Good

GD_DPRINTF( "one finished.\n" );
GD_DPRINTF( "one finished." );

Dictionary::DataRequest & req = *bodyRequests.front();

Expand Down Expand Up @@ -672,13 +672,13 @@ void ArticleRequest::bodyFinished()

foundAnyDefinitions = true;
}
GD_DPRINTF( "erasing..\n" );
GD_DPRINTF( "erasing.." );
bodyRequests.pop_front();
GD_DPRINTF( "erase done..\n" );
GD_DPRINTF( "erase done.." );
}
else
{
GD_DPRINTF( "one not finished.\n" );
GD_DPRINTF( "one not finished." );
break;
}
}
Expand Down
19 changes: 15 additions & 4 deletions article_netmgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest co
// getHostBase( refererUrl ).toUtf8().data() );

if ( !url.host().endsWith( refererUrl.host() ) &&
getHostBase( url ) != getHostBase( refererUrl ) && !url.scheme().startsWith("data") )
getHostBaseFromUrl( url ) != getHostBaseFromUrl( refererUrl ) && !url.scheme().startsWith("data") )
{
gdWarning( "Blocking element \"%s\" due to not same domain", url.toEncoded().data() );

Expand Down Expand Up @@ -254,9 +254,9 @@ QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest co
sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource(
QUrl const & url, QString & contentType )
{
GD_DPRINTF( "getResource: %ls\n", url.toString().toStdWString().c_str() );
GD_DPRINTF( "scheme: %ls\n", url.scheme().toStdWString().c_str() );
GD_DPRINTF( "host: %ls\n", url.host().toStdWString().c_str() );
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" )
{
Expand Down Expand Up @@ -515,6 +515,17 @@ void LocalSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
QNetworkRequest request;
request.setUrl( url );

//all the url reached here must be either gdlookup or bword scheme.
auto queryWord = Utils::Url::getQueryWord( url );
auto word = queryWord.second;
// or the condition can be (!queryWord.first || word.isEmpty())
// ( queryWord.first && word.isEmpty() ) is only part of the above condition.
if( queryWord.first && word.isEmpty() )
{
// invalid gdlookup url.
return;
}

QNetworkReply * reply = this->mManager.getArticleReply( request );
connect( reply, &QNetworkReply::finished, requestJob, [ = ]() { requestJob->reply( "text/html", reply ); } );
connect( requestJob, &QObject::destroyed, reply, &QObject::deleteLater );
Expand Down
59 changes: 14 additions & 45 deletions articleview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -708,39 +708,14 @@ void ArticleView::tryMangleWebsiteClickedUrl( QUrl & url, Contexts & contexts )
{
if( framed )
{
// QVariant result = runJavaScriptSync( ui.definition->page(), "gdLastUrlText" );
QVariant result;

if( result.type() == QVariant::String )
{
// Looks this way
contexts[ dictionaryIdFromScrollTo( ca ) ] = QString::fromLatin1( url.toEncoded() );

QUrl target;

QString queryWord = result.toString();

// Empty requests are treated as no request, so we work this around by
// adding a space.
if( queryWord.isEmpty() )
queryWord = " ";

target.setScheme( "gdlookup" );
target.setHost( "localhost" );
target.setPath( "/" + queryWord );

url = target;
}
// no need to translate website internal url to gd builtin url
// and lack the formulation to convert them.
qDebug() << "in the website with url:" << url;
}
} );
}
}

void ArticleView::updateCurrentArticleFromCurrentFrame( QWebEnginePage * frame ,QPoint * point)
{

}

void ArticleView::saveHistoryUserData()
{
ui.definition->setProperty("sx", ui.definition->page()->scrollPosition().x());
Expand Down Expand Up @@ -1100,8 +1075,6 @@ void ArticleView::linkClicked( QUrl const & url_ )
if( kmod & Qt::AltModifier )
return;

updateCurrentArticleFromCurrentFrame();

QUrl url( url_ );
Contexts contexts;

Expand Down Expand Up @@ -1134,6 +1107,14 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref,
audioPlayer->stop();
qDebug() << "open link url:" << url;

auto queryWord = Utils::Url::getQueryWord( url );
auto word = queryWord.second;
if( queryWord.first && word.isEmpty() )
{
// invalid gdlookup url.
return;
}

Contexts contexts( contexts_ );

if( url.scheme().compare( "gdpicture" ) == 0 )
Expand All @@ -1146,10 +1127,10 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref,
QStringList dictsList = Utils::Url::queryItemValue( ref, "dictionaries" )
.split( ",", Qt::SkipEmptyParts );

showDefinition( url.path(), dictsList, QRegExp(), getGroup( ref ), false );
showDefinition( word, dictsList, QRegExp(), getGroup( ref ), false );
}
else
showDefinition( url.path(),
showDefinition( word,
getGroup( ref ), scrollTo, contexts );
}
else
Expand All @@ -1172,16 +1153,6 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref,
return;
}

QString word;

if( Utils::Url::hasQueryItem( url, "word" ) )
{
word=Utils::Url::queryItemValue (url,"word");
}
else{
word=url.path ().mid (1);
}

QString newScrollTo( scrollTo );
if( Utils::Url::hasQueryItem( url, "dict" ) )
{
Expand Down Expand Up @@ -1725,8 +1696,6 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
{
// Is that a link? Is there a selection?
QWebEnginePage* r=ui.definition->page();
updateCurrentArticleFromCurrentFrame(ui.definition->page(), const_cast<QPoint *>(& pos));

QMenu menu( this );

QAction * followLink = 0;
Expand Down Expand Up @@ -1801,7 +1770,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
}

QString selectedText = ui.definition->selectedText();
QString text = selectedText.trimmed();
QString text = Utils::trimNonChar( selectedText );

if ( text.size() && text.size() < 60 )
{
Expand Down
4 changes: 0 additions & 4 deletions articleview.hh
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,6 @@ private:
/// url to the appropriate "contexts" entry.
void tryMangleWebsiteClickedUrl( QUrl & url, Contexts & contexts );

/// Use the known information about the current frame to update the current
/// article's value.
void updateCurrentArticleFromCurrentFrame( QWebEnginePage * frame = 0 ,QPoint * point=0);

/// Saves current article and scroll position for the current history item.
/// Should be used when leaving the page.
void saveHistoryUserData();
Expand Down
72 changes: 6 additions & 66 deletions dsl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1556,32 +1556,8 @@ void DslDictionary::getArticleText( uint32_t articleAddress, QString & headword,

/// DslDictionary::getArticle()

class DslArticleRequest;

class DslArticleRequestRunnable: public QRunnable
{
DslArticleRequest & r;
QSemaphore & hasExited;

public:

DslArticleRequestRunnable( DslArticleRequest & r_,
QSemaphore & hasExited_ ): r( r_ ),
hasExited( hasExited_ )
{}

~DslArticleRequestRunnable()
{
hasExited.release();
}

virtual void run();
};

class DslArticleRequest: public Dictionary::DataRequest
{
friend class DslArticleRequestRunnable;

wstring word;
vector< wstring > alts;
DslDictionary & dict;
Expand All @@ -1597,11 +1573,10 @@ class DslArticleRequest: public Dictionary::DataRequest
DslDictionary & dict_, bool ignoreDiacritics_ ):
word( word_ ), alts( alts_ ), dict( dict_ ), ignoreDiacritics( ignoreDiacritics_ )
{
QThreadPool::globalInstance()->start(
new DslArticleRequestRunnable( *this, hasExited ) );
QThreadPool::globalInstance()->start( [ this ]() { this->run(); } );
}

void run(); // Run from another thread by DslArticleRequestRunnable
void run();

virtual void cancel()
{
Expand All @@ -1611,15 +1586,10 @@ class DslArticleRequest: public Dictionary::DataRequest
~DslArticleRequest()
{
isCancelled.ref();
hasExited.acquire();
//hasExited.acquire();
}
};

void DslArticleRequestRunnable::run()
{
r.run();
}

void DslArticleRequest::run()
{
if ( Utils::AtomicInt::loadAcquire( isCancelled ) )
Expand Down Expand Up @@ -1759,32 +1729,8 @@ sptr< Dictionary::DataRequest > DslDictionary::getArticle( wstring const & word,

//// DslDictionary::getResource()

class DslResourceRequest;

class DslResourceRequestRunnable: public QRunnable
{
DslResourceRequest & r;
QSemaphore & hasExited;

public:

DslResourceRequestRunnable( DslResourceRequest & r_,
QSemaphore & hasExited_ ): r( r_ ),
hasExited( hasExited_ )
{}

~DslResourceRequestRunnable()
{
hasExited.release();
}

virtual void run();
};

class DslResourceRequest: public Dictionary::DataRequest
{
friend class DslResourceRequestRunnable;

DslDictionary & dict;

string resourceName;
Expand All @@ -1799,11 +1745,10 @@ class DslResourceRequest: public Dictionary::DataRequest
dict( dict_ ),
resourceName( resourceName_ )
{
QThreadPool::globalInstance()->start(
new DslResourceRequestRunnable( *this, hasExited ) );
QThreadPool::globalInstance()->start( [ this ]() { this->run(); } );
}

void run(); // Run from another thread by DslResourceRequestRunnable
void run();

virtual void cancel()
{
Expand All @@ -1813,15 +1758,10 @@ class DslResourceRequest: public Dictionary::DataRequest
~DslResourceRequest()
{
isCancelled.ref();
hasExited.acquire();
//hasExited.acquire();
}
};

void DslResourceRequestRunnable::run()
{
r.run();
}

void DslResourceRequest::run()
{
// Some runnables linger enough that they are cancelled before they start
Expand Down
Loading

0 comments on commit 99876e6

Please sign in to comment.