Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/staged' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed Jun 3, 2022
2 parents accbfd8 + 006c45e commit 6a18eb9
Show file tree
Hide file tree
Showing 12 changed files with 295 additions and 114 deletions.
7 changes: 2 additions & 5 deletions article_netmgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest co

QUrl refererUrl = QUrl::fromEncoded( referer );

//GD_DPRINTF( "Considering %s vs %s\n", getHostBase( req.url() ).toUtf8().data(),
// getHostBase( refererUrl ).toUtf8().data() );

if ( !url.host().endsWith( refererUrl.host() ) &&
getHostBaseFromUrl( url ) != getHostBaseFromUrl( refererUrl ) && !url.scheme().startsWith("data") )
{
Expand Down Expand Up @@ -449,15 +446,15 @@ qint64 ArticleResourceReply::readData( char * out, qint64 maxSize )
qint64 left = avail - alreadyRead;

qint64 toRead = maxSize < left ? maxSize : left;
GD_DPRINTF( "====reading %d bytes\n", (int)toRead );
GD_DPRINTF( "====reading %d bytes", (int)toRead );

try
{
req->getDataSlice( alreadyRead, toRead, out );
}
catch( std::exception & e )
{
qWarning( "getDataSlice error: %s\n", e.what() );
qWarning( "getDataSlice error: %s", e.what() );
}

alreadyRead += toRead;
Expand Down
84 changes: 56 additions & 28 deletions articleview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ void ArticleView::showDefinition( Config::InputPhrase const & phrase, unsigned g
if ( scrollTo.size() )
Utils::Url::addQueryItem( req, "scrollto", scrollTo );

if(delayedHighlightText.size())
Utils::Url::addQueryItem( req, "regexp", delayedHighlightText );

Contexts::Iterator pos = contexts.find( "gdanchor" );
if( pos != contexts.end() )
{
Expand Down Expand Up @@ -579,6 +582,12 @@ void ArticleView::loadFinished( bool result )
}
if( Utils::Url::hasQueryItem( ui.definition->url(), "regexp" ) )
highlightFTSResults();

if( !delayedHighlightText.isEmpty() )
{
// findText( delayedHighlightText, QWebEnginePage::FindCaseSensitively ,[](bool){});
delayedHighlightText.clear();
}
}

void ArticleView::loadProgress(int ){
Expand Down Expand Up @@ -1592,6 +1601,11 @@ void ArticleView::setSelectionBySingleClick( bool set )
ui.definition->setSelectionBySingleClick( set );
}

void ArticleView::setDelayedHighlightText(QString const & text)
{
delayedHighlightText = text;
}

void ArticleView::back()
{
// Don't allow navigating back to page 0, which is usually the initial
Expand Down Expand Up @@ -1712,6 +1726,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
QAction * sendWordToInputLineAction = 0;
QAction * saveImageAction = 0;
QAction * saveSoundAction = 0;
QAction * saveBookmark = 0;

#if( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) )
const QWebEngineContextMenuData * menuData = &(r->contextMenuData());
Expand Down Expand Up @@ -1832,6 +1847,13 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
}
}

if(text.size())
{
// avoid too long in the menu ,use left 30 characters.
saveBookmark = new QAction( tr( "Save &Bookmark \"%1...\"" ).arg( text.left( 30 ) ), &menu );
menu.addAction( saveBookmark );
}

// add anki menu
if( !text.isEmpty() && cfg.preferences.ankiConnectServer.enabled )
{
Expand Down Expand Up @@ -1931,7 +1953,11 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
QDesktopServices::openUrl( targetUrl );
else
if ( result == lookupSelection )
showDefinition( selectedText, getGroup( ui.definition->url() ), getCurrentArticle() );
showDefinition( text, getGroup( ui.definition->url() ), getCurrentArticle() );
else if( result == saveBookmark )
{
emit saveBookmarkSignal( text.left( 60 ) );
}
else if( result == sendToAnkiAction )
{
sendToAnki( ui.definition->title(), ui.definition->selectedText() );
Expand Down Expand Up @@ -2333,42 +2359,44 @@ void ArticleView::performFindOperation( bool restart, bool backwards, bool check
if ( backwards )
f |= QWebEnginePage::FindBackward;

bool setMark = text.size() && !findText(text, f);
findText( text,
f,
[ &text, this ]( bool match )
{
bool setMark = !text.isEmpty() && !match;

if ( ui.searchText->property( "noResults" ).toBool() != setMark )
{
ui.searchText->setProperty( "noResults", setMark );
if( ui.searchText->property( "noResults" ).toBool() != setMark )
{
ui.searchText->setProperty( "noResults", setMark );

// Reload stylesheet
reloadStyleSheet();
}
// Reload stylesheet
reloadStyleSheet();
}
} );
}

bool ArticleView::findText(QString& text, const QWebEnginePage::FindFlags& f)
void ArticleView::findText( QString & text,
const QWebEnginePage::FindFlags & f,
const std::function< void( bool match ) > & callback )
{
bool r;
// turn async to sync invoke.
QSharedPointer<QEventLoop> loop = QSharedPointer<QEventLoop>(new QEventLoop());
QTimer::singleShot(1000, loop.data(), &QEventLoop::quit);
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
ui.definition->findText(text, f, [&](const QWebEngineFindTextResult& result)
#if( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
ui.definition->findText( text,
f,
[ callback ]( const QWebEngineFindTextResult & result )
{
if(loop->isRunning()){
r = result.numberOfMatches()>0;
loop->quit();
} });
auto r = result.numberOfMatches() > 0;
if( callback )
callback( r );
} );
#else
ui.definition->findText(text, f, [&](bool result)
ui.definition->findText( text,
f,
[ callback ]( bool result )
{
if(loop->isRunning()){
r = result;
loop->quit();
} });
if( callback )
callback( result );
} );
#endif


loop->exec();
return r;
}

void ArticleView::reloadStyleSheet()
Expand Down
11 changes: 10 additions & 1 deletion articleview.hh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class ArticleView: public QFrame
bool ftsSearchIsOpened, ftsSearchMatchCase;
int ftsPosition;

QString delayedHighlightText;

void highlightFTSResults();
void highlightAllFtsOccurences( QWebEnginePage::FindFlags flags );
void performFtsFindOperation( bool backwards );
Expand Down Expand Up @@ -157,6 +159,8 @@ public:
/// Called when preference changes
void setSelectionBySingleClick( bool set );

void setDelayedHighlightText(QString const & text);

public slots:

/// Goes back in history
Expand Down Expand Up @@ -227,6 +231,10 @@ public:
ResourceToSaveHandler * saveResource( const QUrl & url, const QString & fileName );
ResourceToSaveHandler * saveResource( const QUrl & url, const QUrl & ref, const QString & fileName );

void findText( QString & text,
const QWebEnginePage::FindFlags & f,
const std::function< void( bool match ) > & callback = nullptr );

signals:

void iconChanged( ArticleView *, QIcon const & icon );
Expand Down Expand Up @@ -285,6 +293,8 @@ signals:

void inspectSignal(QWebEngineView * view);

void saveBookmarkSignal( const QString & bookmark );

public slots:

void on_searchPrevious_clicked();
Expand Down Expand Up @@ -391,7 +401,6 @@ private:

void performFindOperation( bool restart, bool backwards, bool checkHighlight = false );

bool findText(QString& text, const QWebEnginePage::FindFlags& f);

void reloadStyleSheet();

Expand Down
2 changes: 1 addition & 1 deletion epwing_book.cc
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ bool EpwingBook::getNextHeadword( EpwingHeadword & head )
{
EB_Position pos;

QRegularExpression badLinks( "#(v|n)\\d" );
QRegularExpression badLinks( "#(v|n)\\d", QRegularExpression::UseUnicodePropertiesOption);

// At first we check references queue
while( !LinksQueue.isEmpty() )
Expand Down
4 changes: 2 additions & 2 deletions ftshelpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ bool parseSearchString( QString const & str, QStringList & indexWords,
{
searchWords.clear();
indexWords.clear();
QRegularExpression spacesRegExp( "\\W+" );
QRegularExpression wordRegExp( QString( "\\w{" ) + QString::number( FTS::MinimumWordSize ) + ",}" );
QRegularExpression spacesRegExp( "\\W+", QRegularExpression::UseUnicodePropertiesOption );
QRegularExpression wordRegExp( QString( "\\w{" ) + QString::number( FTS::MinimumWordSize ) + ",}", QRegularExpression::UseUnicodePropertiesOption );
QRegularExpression setsRegExp( "\\[[^\\]]+\\]", QRegularExpression::CaseInsensitiveOption );
QRegularExpression regexRegExp( "\\\\[afnrtvdDwWsSbB]|\\\\x([0-9A-Fa-f]{4})|\\\\0([0-7]{3})", QRegularExpression::CaseInsensitiveOption);

Expand Down
49 changes: 9 additions & 40 deletions gddebug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,30 @@
#include <QString>
#include "gddebug.hh"
#include <QDebug>
#if(QT_VERSION >= QT_VERSION_CHECK(6,0,0))
#if( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
#include <QtCore5Compat/QTextCodec>
#else
#include <QTextCodec>
#endif

QFile * logFilePtr;
static QTextCodec * utf8Codec;

void gdWarning(const char *msg, ...)
void gdWarning( const char * msg, ... )
{
va_list ap;
va_start(ap, msg);
QTextCodec *localeCodec = 0;

if( logFilePtr && logFilePtr->isOpen() )
{
if( utf8Codec == 0 )
utf8Codec = QTextCodec::codecForName( "UTF8" );

localeCodec = QTextCodec::codecForLocale();
QTextCodec::setCodecForLocale( utf8Codec );
}
va_list ap;
va_start( ap, msg );

qWarning() << QString().vasprintf( msg, ap );

if( logFilePtr && logFilePtr->isOpen() )
{
QTextCodec::setCodecForLocale( localeCodec );
}

va_end(ap);
va_end( ap );
}

void gdDebug(const char *msg, ...)
void gdDebug( const char * msg, ... )
{
va_list ap;
va_start(ap, msg);
// QTextCodec *localeCodec = 0;

// if( logFilePtr && logFilePtr->isOpen() )
// {
// if( utf8Codec == 0 )
// utf8Codec = QTextCodec::codecForName( "UTF8" );

// localeCodec = QTextCodec::codecForLocale();
// QTextCodec::setCodecForLocale( utf8Codec );
// }
va_list ap;
va_start( ap, msg );

qDebug().noquote() << QString().vasprintf( msg, ap );

// if( logFilePtr && logFilePtr->isOpen() )
// {
// QTextCodec::setCodecForLocale( localeCodec );
// }

va_end(ap);
va_end( ap );
}
24 changes: 23 additions & 1 deletion goldendict.pro
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,29 @@ system(git describe --tags --always --dirty): hasGit=1
!isEmpty(hasGit){
GIT_HASH=$$system(git rev-parse --short=8 HEAD )
}
system(echo $${VERSION}.$${GIT_HASH} > version.txt)

win32{
# date /T output is locale aware.
DD=$$system(date /T)
DATE =$$replace(DD, / , )
}
else{
DATE=$$system(date '+%y%m%d')
}

system(echo $${VERSION}.$${GIT_HASH} on $${DATE} > version.txt)

!CONFIG( verbose_build_output ) {
!win32|*-msvc* {
# Reduce build log verbosity except for MinGW builds (mingw-make cannot
# execute "@echo ..." commands inserted by qmake).
CONFIG += silent
}
}

CONFIG( release, debug|release ) {
DEFINES += NDEBUG
}

# DEPENDPATH += . generators
INCLUDEPATH += .
Expand Down
6 changes: 3 additions & 3 deletions indexedzip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data )

if ( !ZipFile::readLocalHeader( zip, header ) )
{
GD_DPRINTF( "Failed to load header\n" );
GD_DPRINTF( "Failed to load header" );
return false;
}

Expand All @@ -73,13 +73,13 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data )
switch( header.compressionMethod )
{
case ZipFile::Uncompressed:
GD_DPRINTF( "Uncompressed\n" );
GD_DPRINTF( "Uncompressed" );
data.resize( header.uncompressedSize );
return (size_t) zip.read( &data.front(), data.size() ) == data.size();

case ZipFile::Deflated:
{
GD_DPRINTF( "Deflated\n" );
GD_DPRINTF( "Deflated" );

// Now do the deflation

Expand Down
7 changes: 6 additions & 1 deletion locale/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,12 @@
<translation>引用的音频播放程序不存在。</translation>
</message>
<message>
<location filename="../articleview.cc" line="1867"/>
<location filename="../articleview.cc" line="1853"/>
<source>Save &amp;Bookmark &quot;%1...&quot;</source>
<translation>保存为书签(&amp;S)“%1...”</translation>
</message>
<message>
<location filename="../articleview.cc" line="1861"/>
<source>&amp;Send &quot;%1&quot; to anki with selected text.</source>
<translation>将“%1”发送到anki并附带选择的文本。</translation>
</message>
Expand Down
Loading

0 comments on commit 6a18eb9

Please sign in to comment.