Merge branch 'staged' into dev

This commit is contained in:
YiFang Xiao 2023-09-02 17:51:56 +08:00
commit eb238c0007
14 changed files with 40 additions and 47 deletions

View file

@ -750,7 +750,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
for ( const auto & fileName : fileNames ) {
// Skip files with the extensions different to .aar to speed up the
// scanning
if ( fileName.size() < 4 || strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".aar" ) != 0 )
if ( !Utils::endsWithIgnoreCase( fileName, ".aar" ) )
continue;
// Got the file -- check if we need to rebuid the index

View file

@ -1017,7 +1017,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
for ( const auto & fileName : fileNames ) {
// Skip files with the extensions different to .bgl to speed up the
// scanning
if ( fileName.size() < 4 || strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".bgl" ) != 0 )
if ( !Utils::endsWithIgnoreCase( fileName, ".bgl" ) )
continue;
// Got the file -- check if we need to rebuid the index

View file

@ -550,7 +550,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
for ( const auto & fileName : fileNames ) {
// Only allow .index suffixes
if ( fileName.size() < 6 || strcasecmp( fileName.c_str() + ( fileName.size() - 6 ), ".index" ) != 0 )
if ( !Utils::endsWithIgnoreCase( fileName, ".index" ) )
continue;
try {

View file

@ -1713,10 +1713,8 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
for ( const auto & fileName : fileNames ) {
// Try .dsl and .dsl.dz suffixes
bool uncompressedDsl =
( fileName.size() >= 4 && strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".dsl" ) == 0 );
if ( !uncompressedDsl
&& ( fileName.size() < 7 || strcasecmp( fileName.c_str() + ( fileName.size() - 7 ), ".dsl.dz" ) != 0 ) )
bool uncompressedDsl = Utils::endsWithIgnoreCase( fileName, ".dsl" );
if ( !uncompressedDsl && !Utils::endsWithIgnoreCase( fileName, ".dsl.dz" ) )
continue;
// Make sure it's not an abbreviation file

View file

@ -839,7 +839,7 @@ QString EpwingBook::getPreviousTextWithLength( int page, int offset, int total,
if ( buf.length() > TextSizeLimit ) {
error_string = "Data too large";
currentPosition.page = 0;
return QString();
return {};
}
}
@ -1373,6 +1373,7 @@ void EpwingBook::finalizeText( QString & text )
url.setHost( "localhost" );
url.setPath( Utils::Url::ensureLeadingSlash( QString( "r%1At%2" ).arg( ebpos.page ).arg( ebpos.offset ) ) );
url.setQuery( "dictionaries=" + dictID );
QString link = "<a href=\"" + url.toEncoded() + "\">";

View file

@ -1195,8 +1195,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
for ( const auto & fileName : fileNames ) {
// Try .gls and .gls.dz suffixes
if ( !( fileName.size() >= 4 && strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".gls" ) == 0 )
&& !( fileName.size() >= 7 && strcasecmp( fileName.c_str() + ( fileName.size() - 7 ), ".gls.dz" ) == 0 ) )
if ( !Utils::endsWithIgnoreCase( fileName, ".gls" ) && !Utils::endsWithIgnoreCase( fileName, ".gls.dz" ) )
continue;
unsigned atLine = 0; // Indicates current line in .gls, for debug purposes

View file

@ -75,7 +75,7 @@ bool indexIsOldOrBad( string const & indexFile )
string stripExtension( string const & str )
{
if ( str.size() > 3 && ( strcasecmp( str.c_str() + ( str.size() - 4 ), ".wav" ) == 0 ) )
if ( Utils::endsWithIgnoreCase( str, ".wav" ) )
return string( str, 0, str.size() - 4 );
else
return str;
@ -119,7 +119,7 @@ Entry::Entry( File::Class & f )
// Skip zero or ff, or just ff.
if ( uint8_t x = f.read< uint8_t >() ) {
if ( auto x = f.read< uint8_t >() ) {
if ( x != 0xFF )
throw exInvalidData();
}
@ -291,7 +291,7 @@ sptr< Dictionary::DataRequest > LsaDictionary::getArticle( wstring const & word,
result += "</table>";
Dictionary::DataRequestInstant * ret = new Dictionary::DataRequestInstant( true );
auto * ret = new Dictionary::DataRequestInstant( true );
ret->getData().resize( result.size() );
@ -321,14 +321,14 @@ struct ShiftedVorbis
size_t ShiftedVorbis::read( void * ptr, size_t size, size_t nmemb, void * datasource )
{
ShiftedVorbis * sv = (ShiftedVorbis *)datasource;
auto * sv = (ShiftedVorbis *)datasource;
return sv->f.read( reinterpret_cast< char * >( ptr ), size * nmemb );
}
int ShiftedVorbis::seek( void * datasource, ogg_int64_t offset, int whence )
{
ShiftedVorbis * sv = (ShiftedVorbis *)datasource;
auto * sv = (ShiftedVorbis *)datasource;
if ( whence == SEEK_SET )
offset += sv->shift;
@ -344,7 +344,7 @@ int ShiftedVorbis::seek( void * datasource, ogg_int64_t offset, int whence )
long ShiftedVorbis::tell( void * datasource )
{
ShiftedVorbis * sv = (ShiftedVorbis *)datasource;
auto * sv = (ShiftedVorbis *)datasource;
long result = sv->f.pos();
if ( result != -1 )
@ -381,7 +381,7 @@ sptr< Dictionary::DataRequest > LsaDictionary::getResource( string const & name
{
// See if the name ends in .wav. Remove that extension then
string strippedName = ( name.size() > 3 && ( name.compare( name.size() - 4, 4, ".wav" ) == 0 ) ) ?
string strippedName = Utils::endsWithIgnoreCase( name, ".wav" ) ?
string( name, 0, name.size() - 4 ) :
name;
@ -423,7 +423,7 @@ sptr< Dictionary::DataRequest > LsaDictionary::getResource( string const & name
data.resize( sizeof( WavHeader ) + e.samplesLength * 2 );
WavHeader * wh = (WavHeader *)&data.front();
auto * wh = (WavHeader *)&data.front();
memset( wh, 0, sizeof( *wh ) );
@ -494,15 +494,12 @@ void LsaDictionary::loadIcon() noexcept
vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & fileNames,
string const & indicesDir,
Dictionary::Initializing & initializing )
{
vector< sptr< Dictionary::Class > > dictionaries;
for ( vector< string >::const_iterator i = fileNames.begin(); i != fileNames.end(); ++i ) {
for ( auto i = fileNames.begin(); i != fileNames.end(); ++i ) {
/// Only allow .dat and .lsa extensions to save scanning time
if ( i->size() < 4
|| ( strcasecmp( i->c_str() + ( i->size() - 4 ), ".dat" ) != 0
&& strcasecmp( i->c_str() + ( i->size() - 4 ), ".lsa" ) != 0 ) )
if ( !Utils::endsWithIgnoreCase( *i, ".dat" ) && !Utils::endsWithIgnoreCase( *i, ".lsa" ) )
continue;
try {
@ -545,7 +542,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
IndexedWords indexedWords;
/// XXX handle big-endian machines here!
uint32_t entriesCount = f.read< uint32_t >();
auto entriesCount = f.read< uint32_t >();
GD_DPRINTF( "%s: %u entries\n", i->c_str(), entriesCount );

View file

@ -1272,7 +1272,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
for ( const auto & fileName : fileNames ) {
// Skip files with the extensions different to .mdx to speed up the
// scanning
if ( fileName.size() < 4 || strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".mdx" ) != 0 )
if ( !Utils::endsWithIgnoreCase( fileName, ".mdx" ) )
continue;
vector< string > dictFiles( 1, fileName );

View file

@ -661,7 +661,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
for ( const auto & fileName : fileNames ) {
// Skip files with the extensions different to .dct to speed up the
// scanning
if ( fileName.size() < 4 || strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".dct" ) != 0 )
if ( !Utils::endsWithIgnoreCase( fileName, ".dct" ) )
continue;
// Got the file -- check if we need to rebuid the index

View file

@ -1775,7 +1775,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
vector< sptr< Dictionary::Class > > dictionaries;
for ( const auto & fileName : fileNames ) {
if ( fileName.size() < 4 || strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".ifo" ) != 0 )
if ( !Utils::endsWithIgnoreCase( fileName, ".ifo" ) )
continue;
try {

View file

@ -1010,8 +1010,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
for ( const auto & fileName : fileNames ) {
// Only allow .xdxf and .xdxf.dz suffixes
if ( ( fileName.size() < 5 || strcasecmp( fileName.c_str() + ( fileName.size() - 5 ), ".xdxf" ) != 0 )
&& ( fileName.size() < 8 || strcasecmp( fileName.c_str() + ( fileName.size() - 8 ), ".xdxf.dz" ) != 0 ) )
if ( !Utils::endsWithIgnoreCase( fileName, ".xdxf" ) && !Utils::endsWithIgnoreCase( fileName, ".xdxf.dz" ) )
continue;
try {

View file

@ -383,7 +383,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
for ( const auto & fileName : fileNames ) {
/// Only allow .zips extension
if ( fileName.size() < 5 || strcasecmp( fileName.c_str() + ( fileName.size() - 5 ), ".zips" ) != 0 )
if ( !Utils::endsWithIgnoreCase( fileName, ".zips" ) )
continue;
try {

View file

@ -584,11 +584,6 @@ void ArticleView::isFramedArticle( QString const & ca, const std::function< void
} );
}
bool ArticleView::isExternalLink( QUrl const & url )
{
return Utils::isExternalLink( url );
}
void ArticleView::tryMangleWebsiteClickedUrl( QUrl & url, Contexts & contexts )
{
// Don't try mangling audio urls, even if they are from the framed websites
@ -796,7 +791,7 @@ QString ArticleView::getMutedForGroup( unsigned group )
else
mutedDictionaries = grp ? ( popupView ? &grp->popupMutedDictionaries : &grp->mutedDictionaries ) : nullptr;
if ( !mutedDictionaries )
return QString();
return {};
QStringList mutedDicts;
@ -813,7 +808,7 @@ QString ArticleView::getMutedForGroup( unsigned group )
return mutedDicts.join( "," );
}
return QString();
return {};
}
QStringList ArticleView::getMutedDictionaries( unsigned group )
@ -830,7 +825,7 @@ QStringList ArticleView::getMutedDictionaries( unsigned group )
else
mutedDictionaries = grp ? ( popupView ? &grp->popupMutedDictionaries : &grp->mutedDictionaries ) : nullptr;
if ( !mutedDictionaries )
return QStringList();
return {};
QStringList mutedDicts;
@ -846,7 +841,7 @@ QStringList ArticleView::getMutedDictionaries( unsigned group )
return mutedDicts;
}
return QStringList();
return {};
}
void ArticleView::linkHovered( const QString & link )
@ -1010,6 +1005,14 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, QString const &
return;
}
if ( Utils::Url::hasQueryItem( url, "dictionaries" ) ) {
// Specific dictionary group from full-text search
QStringList dictsList = Utils::Url::queryItemValue( url, "dictionaries" ).split( ",", Qt::SkipEmptyParts );
showDefinition( word, dictsList, QRegExp(), getGroup( url ), false );
return;
}
QString newScrollTo( scrollTo );
if ( Utils::Url::hasQueryItem( url, "dict" ) ) {
// Link to other dictionary
@ -1054,7 +1057,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, QString const &
std::vector< sptr< Dictionary::Class > > const * activeDicts = nullptr;
if ( groups.size() ) {
if ( !groups.empty() ) {
for ( const auto & group : groups )
if ( group.id == currentGroup ) {
activeDicts = &( group.dictionaries );
@ -1203,7 +1206,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, QString const &
}
}
}
else if ( isExternalLink( url ) ) {
else if ( Utils::isExternalLink( url ) ) {
// Use the system handler for the conventional external links
QDesktopServices::openUrl( url );
}
@ -1518,7 +1521,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
tryMangleWebsiteClickedUrl( targetUrl, contexts );
if ( !targetUrl.isEmpty() ) {
if ( !isExternalLink( targetUrl ) ) {
if ( !Utils::isExternalLink( targetUrl ) ) {
followLink = new QAction( tr( "Op&en Link" ), &menu );
menu.addAction( followLink );
@ -1528,7 +1531,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
}
}
if ( isExternalLink( targetUrl ) ) {
if ( Utils::isExternalLink( targetUrl ) ) {
followLinkExternal = new QAction( tr( "Open Link in &External Browser" ), &menu );
menu.addAction( followLinkExternal );
menu.addAction( webview->pageAction( QWebEnginePage::CopyLinkToClipboard ) );

View file

@ -401,10 +401,6 @@ private:
/// frame.
void isFramedArticle( QString const & article, const std::function< void( bool framed ) > & callback );
/// Checks if the given link is to be opened externally, as opposed to opening
/// it in-place.
bool isExternalLink( QUrl const & url );
/// Sees if the last clicked link is from a website frame. If so, changes url
/// to point to url text translation instead, and saves the original
/// url to the appropriate "contexts" entry.