Merge branch 'staged' into dev

This commit is contained in:
YiFang Xiao 2023-09-11 17:21:30 +08:00
commit 1074a27ae9
15 changed files with 76 additions and 44 deletions

View file

@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
env:
version: 23.07.25
version: 23.09.11
version-suffix: alpha
prerelease: true

View file

@ -26,7 +26,7 @@ jobs:
qt_arch: [clang_64]
env:
targetName: GoldenDict
version: 23.07.25
version: 23.09.11
version-suffix: alpha
prerelease: true
steps:

View file

@ -26,7 +26,7 @@ jobs:
qt_arch: [clang_64]
env:
targetName: GoldenDict
version: 23.07.25
version: 23.09.11
version-suffix: alpha
prerelease: true
steps:

View file

@ -29,7 +29,7 @@ jobs:
qt_ver: [ 6.5.2 ]
qt_arch: [gcc_64]
env:
version: 23.07.25
version: 23.09.11
version-suffix: alpha
prerelease: true
steps:

View file

@ -30,7 +30,7 @@ jobs:
qt_ver: [5.15.2]
qt_arch: [gcc_64]
env:
version: 23.07.25
version: 23.09.11
version-suffix: alpha
prerelease: true
steps:

View file

@ -31,7 +31,7 @@ jobs:
qt_arch: [win64_msvc2019_64]
env:
targetName: GoldenDict.exe
version: 23.07.25
version: 23.09.11
version-suffix: alpha
prerelease: true
steps:

View file

@ -32,7 +32,7 @@ jobs:
qt_arch: [win64_msvc2019_64]
env:
targetName: GoldenDict.exe
version: 23.07.25
version: 23.09.11
version-suffix: alpha
prerelease: true
# 步骤

View file

@ -1,6 +1,6 @@
TEMPLATE = app
TARGET = goldendict
VERSION = 23.07.25
VERSION = 23.09.11
# Generate version file. We do this here and in a build rule described later.
# The build rule is required since qmake isn't run each time the project is
@ -133,7 +133,7 @@ win32 {
win32-msvc* {
# VS does not recognize 22.number.alpha,cause errors during compilation under MSVC++
VERSION = 23.07.25
VERSION = 23.09.11
DEFINES += __WIN32 _CRT_SECURE_NO_WARNINGS
contains(QMAKE_TARGET.arch, x86_64) {
DEFINES += NOMINMAX __WIN64

View file

@ -406,15 +406,17 @@ qint64 ArticleResourceReply::bytesAvailable() const
if ( avail < 0 )
return 0;
if ( !req->isFinished() ) {
return 65536;
}
return avail - alreadyRead + QNetworkReply::bytesAvailable();
}
bool ArticleResourceReply::atEnd() const
{
// QWebEngineUrlRequestJob finishes and is destroyed as soon as QIODevice::atEnd() returns true.
// QNetworkReply::atEnd() returns true while bytesAvailable() returns 0.
// Return false if the data request is not finished to work around always-blank web page.
return req->isFinished() && QNetworkReply::atEnd();
return req->isFinished() && bytesAvailable() == 0;
}
qint64 ArticleResourceReply::readData( char * out, qint64 maxSize )
@ -431,20 +433,12 @@ qint64 ArticleResourceReply::readData( char * out, qint64 maxSize )
if ( avail < 0 )
return finished ? -1 : 0;
qint64 left = avail - alreadyRead;
if ( left == 0 && !finished ) {
// Work around endlessly repeated useless calls to readData(). The sleep duration is a tradeoff.
// On the one hand, lowering the duration reduces CPU usage. On the other hand, overly long
// sleep duration reduces page content update frequency in the web view.
// Waiting on a condition variable is more complex and actually works worse than
// simple fixed-duration sleeping, because the web view is not updated until
// the data request is finished if readData() returns only when new data arrives.
QThread::msleep( 30 );
return 0;
}
qint64 toRead = maxSize < left ? maxSize : left;
if ( !toRead && finished )
return -1;
GD_DPRINTF( "====reading %d of (%lld) bytes . Finished: %d", (int)toRead, avail, finished );
try {

View file

@ -180,7 +180,7 @@ public:
protected:
virtual qint64 bytesAvailable() const;
bool atEnd() const override;
bool atEnd() const;
virtual void abort() {}
virtual qint64 readData( char * data, qint64 maxSize );

View file

@ -886,16 +886,22 @@ static uint32_t buildBtreeNode( IndexedWords::const_iterator & nextIndex,
void IndexedWords::addWord( wstring const & index_word, uint32_t articleOffset, unsigned int maxHeadwordSize )
{
wstring const & word = gd::removeTrailingZero( index_word );
wstring word = gd::removeTrailingZero( index_word );
wchar const * wordBegin = word.c_str();
string::size_type wordSize = word.size();
// Safeguard us against various bugs here. Don't attempt adding words
// which are freakishly huge.
if ( wordSize > maxHeadwordSize ) {
qWarning() << "Skipped too long headword: " << QString::fromStdU32String( word.substr( 0, 30 ) )
qWarning() << "Abbreviate the too long headword: " << QString::fromStdU32String( word.substr( 0, 30 ) )
<< "size:" << wordSize;
return;
//find the closest string to the maxHeadwordSize;
auto nonSpacePos = word.find_last_not_of( ' ', maxHeadwordSize );
if ( nonSpacePos > 0 )
word = word.substr( 0, nonSpacePos );
else
word = word.substr( 0, maxHeadwordSize );
}
// Skip any leading whitespace

View file

@ -32,16 +32,19 @@ bool Request::isFinished()
void Request::update()
{
if ( !Utils::AtomicInt::loadAcquire( isFinishedFlag ) )
if ( !Utils::AtomicInt::loadAcquire( isFinishedFlag ) ) {
emit updated();
}
}
void Request::finish()
{
if ( !Utils::AtomicInt::loadAcquire( isFinishedFlag ) ) {
isFinishedFlag.ref();
emit finished();
QMutexLocker _( &dataMutex );
cond.wakeAll();
}
}
@ -103,8 +106,13 @@ void WordSearchRequest::addMatch( WordMatch const & match )
long DataRequest::dataSize()
{
QMutexLocker _( &dataMutex );
long size = hasAnyData ? (long)data.size() : -1;
return hasAnyData ? (long)data.size() : -1;
if ( size == 0 && !isFinished() ) {
cond.wait( &dataMutex );
size = hasAnyData ? (long)data.size() : -1;
}
return size;
}
void DataRequest::appendDataSlice( const void * buffer, size_t size )
@ -116,6 +124,7 @@ void DataRequest::appendDataSlice( const void * buffer, size_t size )
data.resize( data.size() + size );
memcpy( &data.front() + offset, buffer, size );
cond.wakeAll();
}
void DataRequest::appendString( std::string_view str )
@ -123,13 +132,14 @@ void DataRequest::appendString( std::string_view str )
QMutexLocker _( &dataMutex );
data.reserve( data.size() + str.size() );
data.insert( data.end(), str.begin(), str.end() );
cond.wakeAll();
}
void DataRequest::getDataSlice( size_t offset, size_t size, void * buffer )
{
if ( size == 0 )
if ( size == 0 ) {
return;
}
QMutexLocker _( &dataMutex );
if ( !hasAnyData )
@ -178,7 +188,7 @@ sptr< WordSearchRequest > Class::findHeadwordsForSynonym( wstring const & )
vector< wstring > Class::getAlternateWritings( wstring const & ) noexcept
{
return vector< wstring >();
return {};
}
QString Class::getContainingFolder() const
@ -190,7 +200,7 @@ QString Class::getContainingFolder() const
return fileInfo.absolutePath();
}
return QString();
return {};
}
sptr< DataRequest > Class::getResource( string const & /*name*/ )
@ -211,7 +221,7 @@ QString const & Class::getDescription()
QString Class::getMainFilename()
{
return QString();
return {};
}
QIcon const & Class::getIcon() noexcept

View file

@ -104,7 +104,6 @@ signals:
void matchCount( int );
protected:
/// Called by derivatives to signal update().
void update();
@ -113,6 +112,10 @@ protected:
/// Sets the error string to be returned by getErrorString().
void setErrorString( QString const & );
QWaitCondition cond;
// Subclasses should be filling up the 'data' array, locking the mutex when
// whey work with it.
QMutex dataMutex;
private:
@ -225,11 +228,6 @@ public:
}
protected:
// Subclasses should be filling up the 'data' array, locking the mutex when
// whey work with it.
QMutex dataMutex;
bool hasAnyData; // With this being false, dataSize() always returns -1
vector< char > data;
};

View file

@ -57,6 +57,22 @@ TranslateBox::TranslateBox( QWidget * parent ):
translate_line->setText( text );
emit returnPressed();
} );
connect( completer,
QOverload< const QString & >::of( &QCompleter::highlighted ),
translate_line,
[ & ]( const QString & text ) {
selectedItem = true;
} );
connect( translate_line,
&QLineEdit::returnPressed,
[ this ]() {
if ( selectedItem )
return;
emit returnPressed();
} );
}
void TranslateBox::setText( const QString & text, bool showPopup )
@ -88,14 +104,21 @@ void TranslateBox::setModel( QStringList & _words )
connect( completer,
QOverload< const QString & >::of( &QCompleter::activated ),
translate_line,
[ & ]( const QString & text) {
translate_line->setText(text);
[ & ]( const QString & text ) {
translate_line->setText( text );
emit returnPressed();
} );
connect( completer,
QOverload< const QString & >::of( &QCompleter::highlighted ),
translate_line,
[ & ]( const QString & text ) {
selectedItem = true;
} );
}
void TranslateBox::showPopup()
{
selectedItem = false;
if ( m_popupEnabled ) {
completer->popup()->show();
completer->complete();

View file

@ -36,6 +36,7 @@ private slots:
private:
QLineEdit * translate_line;
bool selectedItem = false;
bool m_popupEnabled;
QCompleter * completer;
QStringList words;