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 Oct 18, 2023
2 parents 743226e + 22f35dd commit 375c537
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 121 deletions.
15 changes: 5 additions & 10 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,10 @@ Copy & paste `help` -> `about` -> `Copy version info` to here
**Additional context**
Add any other context about the problem here.

Windows:
Platform | Context
---------|----------
Windows |Upload the dmp file in the crash folder located in the configuration folder (can be opened through the menu help->configuration folder) to here
Macos | upload the crashpad crash log
Linux | gdb backtrace info

Upload the dmp file in the crash folder located in the configuration folder (can be opened through the menu help->configuration folder) to here

Macos:

upload the crashpad crash log

Linux:

gdb backtrace info.

14 changes: 5 additions & 9 deletions .github/ISSUE_TEMPLATE/bug_report_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,10 @@ assignees: ''

**额外的信息**

Windows:

_将位于配置文件夹中(可以通过菜单 **help->配置文件夹** 打开)crash文件夹里面的dmp文件上传到此处_
平台 | 信息
---------|----------
Windows | _将位于配置文件夹中(可以通过菜单 **help->配置文件夹** 打开)crash文件夹里面的dmp文件上传到此处_
Macos | 将macos自带的crashpad的log粘贴到此处
Linux | gdb crash 堆栈信息

Macos:

将macos自带的crashpad的log粘贴到此处

Linux:

gdb crash 堆栈信息
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu-PR-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
qt_ver: [5.15.2,6.5.2,6.6.0]
qt_ver: [5.15.2,6.6.0]
qt_arch: [gcc_64]

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-PR-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
strategy:
matrix:
os: [windows-2019]
qt_ver: [5.15.2,6.5.2,6.6.0]
qt_ver: [5.15.2,6.6.0]
qt_arch: [win64_msvc2019_64]
steps:
- uses: actions/setup-python@v3
Expand Down
47 changes: 17 additions & 30 deletions src/article_netmgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest co
}
}

sptr< Dictionary::DataRequest > dr = getResource( url, contentType );
auto dr = getResource( url, contentType );

if ( dr.get() )
return new ArticleResourceReply( this, req, dr, contentType );
Expand All @@ -129,7 +129,7 @@ QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest co
//if not external url,can be blocked from here. no need to continue execute the following code.
//such as bres://upload.wikimedia.... etc .
if ( !Utils::isExternalLink( url ) ) {
gdWarning( "Blocking element \"%s\" as built-in link ", req.url().toEncoded().data() );
gdWarning( R"(Blocking element "%s" as built-in link )", req.url().toEncoded().data() );
return new BlockedNetworkReply( this );
}

Expand All @@ -144,7 +144,7 @@ QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest co
if ( !url.host().endsWith( refererUrl.host() )
&& Utils::Url::getHostBaseFromUrl( url ) != Utils::Url::getHostBaseFromUrl( refererUrl )
&& !url.scheme().startsWith( "data" ) ) {
gdWarning( "Blocking element \"%s\" due to not same domain", url.toEncoded().data() );
gdWarning( R"(Blocking element "%s" due to not same domain)", url.toEncoded().data() );

return new BlockedNetworkReply( this );
}
Expand All @@ -153,7 +153,7 @@ QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest co
if ( req.url().scheme() == "file" ) {
// Check file presence and adjust path if necessary
QString fileName = req.url().toLocalFile();
if ( req.url().host().isEmpty() && articleMaker.adjustFilePath( fileName ) ) {
if ( req.url().host().isEmpty() && ArticleMaker::adjustFilePath( fileName ) ) {
QUrl newUrl( req.url() );
QUrl localUrl = QUrl::fromLocalFile( fileName );

Expand Down Expand Up @@ -236,21 +236,8 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource( QUrl c

// Unpack contexts

QMap< QString, QString > contexts;

QString contextsEncoded = Utils::Url::queryItemValue( url, "contexts" );

if ( contextsEncoded.size() ) {
QByteArray ba = QByteArray::fromBase64( contextsEncoded.toLatin1() );

QBuffer buf( &ba );

buf.open( QBuffer::ReadOnly );

QDataStream stream( &buf );

stream >> contexts;
}
QString const contextsEncoded = Utils::Url::queryItemValue( url, "contexts" );
QMap< QString, QString > const contexts = Utils::str2map( contextsEncoded );

// See for ignore diacritics

Expand Down Expand Up @@ -289,13 +276,13 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource( QUrl c
}
catch ( std::exception & e ) {
gdWarning( "getResource request error (%s) in \"%s\"\n", e.what(), dictionary->getName().c_str() );
return sptr< Dictionary::DataRequest >();
return {};
}
}
}
}

return sptr< Dictionary::DataRequest >();
return {};
}

ArticleResourceReply::ArticleResourceReply( QObject * parent,
Expand Down Expand Up @@ -356,12 +343,12 @@ void ArticleResourceReply::reqFinished()

qint64 ArticleResourceReply::bytesAvailable() const
{
qint64 avail = req->dataSize();
qint64 const avail = req->dataSize();

if ( avail < 0 )
return 0;

qint64 availBytes = avail - alreadyRead + QNetworkReply::bytesAvailable();
qint64 const availBytes = avail - alreadyRead + QNetworkReply::bytesAvailable();
if ( availBytes == 0 && !req->isFinished() ) {
return 10240;
}
Expand All @@ -382,17 +369,17 @@ qint64 ArticleResourceReply::readData( char * out, qint64 maxSize )
if ( maxSize == 0 )
return 0;

bool finished = req->isFinished();
bool const finished = req->isFinished();

qint64 avail = req->dataSize();
qint64 const avail = req->dataSize();

if ( avail < 0 )
return finished ? -1 : 0;


qint64 left = avail - alreadyRead;
qint64 const left = avail - alreadyRead;

qint64 toRead = maxSize < left ? maxSize : left;
qint64 const toRead = maxSize < left ? maxSize : left;
if ( !toRead && finished )
return -1;
GD_DPRINTF( "====reading %d of (%lld) bytes . Finished: %d", (int)toRead, avail, finished );
Expand Down Expand Up @@ -457,15 +444,15 @@ LocalSchemeHandler::LocalSchemeHandler( ArticleNetworkAccessManager & articleNet

void LocalSchemeHandler::requestStarted( QWebEngineUrlRequestJob * requestJob )
{
QUrl url = requestJob->requestUrl();
QUrl const url = requestJob->requestUrl();
QNetworkRequest request;
request.setUrl( url );

//all the url reached here must be either gdlookup or bword scheme.
auto [ valid, word ] = Utils::Url::getQueryWord( url );
auto [ schemeValid, word ] = Utils::Url::getQueryWord( url );
// or the condition can be (!queryWord.first || word.isEmpty())
// ( queryWord.first && word.isEmpty() ) is only part of the above condition.
if ( valid && word.isEmpty() ) {
if ( schemeValid && word.isEmpty() ) {
// invalid gdlookup url.
return;
}
Expand Down
8 changes: 0 additions & 8 deletions src/common/globalbroadcaster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ GlobalBroadcaster * GlobalBroadcaster::instance()
return bdcaster;
}

void GlobalBroadcaster::insertCache( const QString & key, QByteArray * object )
{
//do not cache the item when debug dictionary.
if ( preference->dictionaryDebug )
return;
cache.insert( key, object );
}

void GlobalBroadcaster::setPreference( Config::Preferences * p )
{
preference = p;
Expand Down
4 changes: 0 additions & 4 deletions src/common/globalbroadcaster.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ public:
QMap< QString, QSet< QString > > folderFavoritesMap;
QMap< unsigned, QString > groupFolderMap;
PronounceEngine pronounce_engine;
QCache< QString, QByteArray > cache;

void insertCache( const QString &, QByteArray * );

signals:
void dictionaryChanges( ActiveDictIds ad );
void dictionaryClear( ActiveDictIds ad );
Expand Down
32 changes: 23 additions & 9 deletions src/common/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,23 @@
#ifdef _MSC_VER
#include <stub_msvc.h>
#endif
#include <QBuffer>

using std::string;
namespace Utils {
QMap< QString, QString > str2map( const QString & contextsEncoded )
{
QMap< QString, QString > contexts;

if ( contextsEncoded.size() ) {
QByteArray ba = QByteArray::fromBase64( contextsEncoded.toLatin1() );
QBuffer buf( &ba );
buf.open( QBuffer::ReadOnly );
QDataStream stream( &buf );
stream >> contexts;
}
return contexts;
}
//some str has \0 in the middle of the string. return the string before the \0
std::string c_string( const QString & str )
{
Expand Down Expand Up @@ -38,17 +53,16 @@ QString Utils::Url::getSchemeAndHost( QUrl const & url )
void Utils::Widget::setNoResultColor( QWidget * widget, bool noResult )
{
if ( noResult ) {
QPalette pal( widget->palette() );
// #febb7d
QRgb rgb = 0xfebb7d;
pal.setColor( QPalette::Base, QColor( rgb ) );
widget->setAutoFillBackground( true );
widget->setPalette( pal );
auto font = widget->font();
font.setItalic( true );

widget->setFont( font );
}
else {
QPalette pal( widget->style()->standardPalette() );
widget->setAutoFillBackground( true );
widget->setPalette( pal );
auto font = widget->font();
font.setItalic( false );

widget->setFont( font );
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/common/utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
using std::string;

namespace Utils {
QMap< QString, QString > str2map( const QString & contextsEncoded );

inline bool isCJKChar( ushort ch )
{
if ( ( ch >= 0x3400 && ch <= 0x9FFF ) || ( ch >= 0xF900 && ch <= 0xFAFF ) || ( ch >= 0xD800 && ch <= 0xDFFF ) )
Expand Down
6 changes: 0 additions & 6 deletions src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1013,8 +1013,6 @@ Class load()
c.preferences.removeInvalidIndexOnExit =
( preferences.namedItem( "removeInvalidIndexOnExit" ).toElement().text() == "1" );

c.preferences.dictionaryDebug = fromConfig2Preference( preferences.namedItem( "dictionaryDebug" ), "1" );

if ( !preferences.namedItem( "maxStringsInHistory" ).isNull() )
c.preferences.maxStringsInHistory = preferences.namedItem( "maxStringsInHistory" ).toElement().text().toUInt();

Expand Down Expand Up @@ -2000,10 +1998,6 @@ void save( Class const & c )
opt.appendChild( dd.createTextNode( c.preferences.removeInvalidIndexOnExit ? "1" : "0" ) );
preferences.appendChild( opt );

opt = dd.createElement( "dictionaryDebug" );
opt.appendChild( dd.createTextNode( c.preferences.dictionaryDebug ? "1" : "0" ) );
preferences.appendChild( opt );

opt = dd.createElement( "maxStringsInHistory" );
opt.appendChild( dd.createTextNode( QString::number( c.preferences.maxStringsInHistory ) ) );
preferences.appendChild( opt );
Expand Down
1 change: 0 additions & 1 deletion src/config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@ struct Preferences
int maxNetworkCacheSize;
bool clearNetworkCacheOnExit;
bool removeInvalidIndexOnExit = false;
bool dictionaryDebug = false;

qreal zoomFactor;
qreal helpZoomFactor;
Expand Down
10 changes: 6 additions & 4 deletions src/dict/dictionary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ void Request::update()
void Request::finish()
{
if ( !Utils::AtomicInt::loadAcquire( isFinishedFlag ) ) {
isFinishedFlag.ref();
emit finished();
{
QMutexLocker _( &dataMutex );
isFinishedFlag.ref();

QMutexLocker _( &dataMutex );
cond.wakeAll();
cond.wakeAll();
}
emit finished();
}
}

Expand Down
1 change: 0 additions & 1 deletion src/dict/dictserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,6 @@ void DictServerArticleRequest::cancel()
}

sptr< WordSearchRequest > DictServerDictionary::prefixMatch( wstring const & word, unsigned long maxResults )

{
(void)maxResults;
if ( word.size() > 80 ) {
Expand Down
14 changes: 0 additions & 14 deletions src/dict/mdx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -749,18 +749,6 @@ void MddResourceRequest::run()
const QString id = QString::fromUtf8( dict.getId().c_str() );

const QString unique_key = id + QString::fromStdString( u8ResourceName );
if ( GlobalBroadcaster::instance()->cache.contains( unique_key ) ) {
//take first ,then insert again . the object() method may become null anytime.
auto bytes = GlobalBroadcaster::instance()->cache.take( unique_key );
if ( bytes ) {
hasAnyData = true;
data.resize( bytes->size() );
memcpy( &data.front(), bytes->constData(), bytes->size() );
GlobalBroadcaster::instance()->insertCache( unique_key, bytes );
break;
}
}


dict.loadResourceFile( resourceName, data );

Expand Down Expand Up @@ -789,8 +777,6 @@ void MddResourceRequest::run()

data.resize( bytes.size() );
memcpy( &data.front(), bytes.constData(), bytes.size() );
//cache the processed css result to avoid process again.
GlobalBroadcaster::instance()->insertCache( unique_key, new QByteArray( bytes ) );
}
if ( Filetype::isNameOfTiff( u8ResourceName ) ) {
// Convert it
Expand Down
Loading

0 comments on commit 375c537

Please sign in to comment.