Compare commits

...

8 commits

Author SHA1 Message Date
xiaoyifang 8c9d84f5db
Merge 15b918eb6a into f2ce85cda2 2024-11-20 21:25:21 +08:00
shenleban tongying f2ce85cda2
clean: remove duplicated getName overrides
Some checks are pending
SonarCloud / Build and analyze (push) Waiting to run
2024-11-20 07:50:43 -05:00
atauzki 9c46e5c317
fix: wrong use of QBtyeArrayView::compare (#1971)
* fix wrong use of `QBtyeArrayView::compare`

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-20 20:02:36 +08:00
shenleban tongying 5b9a1611ff
clean: delete stub_msvc.h 2024-11-20 05:27:01 -05:00
shenleban tongying 112874b0e3
clean: unify a common idx file read pattern uint32_t size + data
Some checks are pending
SonarCloud / Build and analyze (push) Waiting to run
2024-11-20 03:22:08 -05:00
autofix-ci[bot] 15b918eb6a
[autofix.ci] apply automated fixes 2024-11-08 01:47:29 +00:00
xiaoyifang 27cbb7351b opt: add option about 2024-11-06 13:35:22 +08:00
xiaoyifang c787a08d2f opt: add option about 2024-11-06 12:07:23 +08:00
30 changed files with 78 additions and 234 deletions

View file

@ -4,9 +4,6 @@
#include <QStyle> #include <QStyle>
#include <QMessageBox> #include <QMessageBox>
#include <string> #include <string>
#ifdef _MSC_VER
#include <stub_msvc.h>
#endif
#include <QBuffer> #include <QBuffer>
#include <QTextCodec> #include <QTextCodec>
@ -31,10 +28,10 @@ std::string c_string( const QString & str )
return std::string( str.toUtf8().constData() ); return std::string( str.toUtf8().constData() );
} }
bool endsWithIgnoreCase( const string & str1, string str2 ) bool endsWithIgnoreCase( QByteArrayView str, QByteArrayView extension )
{ {
return ( str1.size() >= (unsigned)str2.size() ) return ( str.size() >= extension.size() )
&& ( strcasecmp( str1.c_str() + ( str1.size() - str2.size() ), str2.data() ) == 0 ); && ( str.last( extension.size() ).compare( extension, Qt::CaseInsensitive ) == 0 );
} }
QString escapeAmps( QString const & str ) QString escapeAmps( QString const & str )

View file

@ -40,7 +40,7 @@ inline QString rstrip( const QString & str )
} }
std::string c_string( const QString & str ); std::string c_string( const QString & str );
bool endsWithIgnoreCase( const string & str1, string str2 ); bool endsWithIgnoreCase( QByteArrayView str, QByteArrayView extension );
/** /**
* remove punctuation , space, symbol * remove punctuation , space, symbol
* *

View file

@ -150,6 +150,7 @@ Preferences::Preferences():
doubleClickTranslates( true ), doubleClickTranslates( true ),
selectWordBySingleClick( false ), selectWordBySingleClick( false ),
autoScrollToTargetArticle( true ), autoScrollToTargetArticle( true ),
targetArticleAtFirst( false ),
escKeyHidesMainWindow( false ), escKeyHidesMainWindow( false ),
alwaysOnTop( false ), alwaysOnTop( false ),
searchInDock( false ), searchInDock( false ),
@ -878,6 +879,11 @@ Class load()
( preferences.namedItem( "autoScrollToTargetArticle" ).toElement().text() == "1" ); ( preferences.namedItem( "autoScrollToTargetArticle" ).toElement().text() == "1" );
} }
if ( !preferences.namedItem( "targetArticleAtFirst" ).isNull() ) {
c.preferences.targetArticleAtFirst =
( preferences.namedItem( "targetArticleAtFirst" ).toElement().text() == "1" );
}
if ( !preferences.namedItem( "escKeyHidesMainWindow" ).isNull() ) { if ( !preferences.namedItem( "escKeyHidesMainWindow" ).isNull() ) {
c.preferences.escKeyHidesMainWindow = c.preferences.escKeyHidesMainWindow =
( preferences.namedItem( "escKeyHidesMainWindow" ).toElement().text() == "1" ); ( preferences.namedItem( "escKeyHidesMainWindow" ).toElement().text() == "1" );
@ -1815,6 +1821,10 @@ void save( Class const & c )
opt.appendChild( dd.createTextNode( c.preferences.autoScrollToTargetArticle ? "1" : "0" ) ); opt.appendChild( dd.createTextNode( c.preferences.autoScrollToTargetArticle ? "1" : "0" ) );
preferences.appendChild( opt ); preferences.appendChild( opt );
opt = dd.createElement( "targetArticleAtFirst" );
opt.appendChild( dd.createTextNode( c.preferences.targetArticleAtFirst ? "1" : "0" ) );
preferences.appendChild( opt );
opt = dd.createElement( "escKeyHidesMainWindow" ); opt = dd.createElement( "escKeyHidesMainWindow" );
opt.appendChild( dd.createTextNode( c.preferences.escKeyHidesMainWindow ? "1" : "0" ) ); opt.appendChild( dd.createTextNode( c.preferences.escKeyHidesMainWindow ? "1" : "0" ) );
preferences.appendChild( opt ); preferences.appendChild( opt );

View file

@ -297,6 +297,7 @@ struct Preferences
bool doubleClickTranslates; bool doubleClickTranslates;
bool selectWordBySingleClick; bool selectWordBySingleClick;
bool autoScrollToTargetArticle; bool autoScrollToTargetArticle;
bool targetArticleAtFirst;
bool escKeyHidesMainWindow; bool escKeyHidesMainWindow;
bool alwaysOnTop; bool alwaysOnTop;

View file

@ -16,9 +16,6 @@
#include <set> #include <set>
#include <string> #include <string>
#ifdef _MSC_VER
#include <stub_msvc.h>
#endif
#include <QString> #include <QString>
#include <QSemaphore> #include <QSemaphore>
@ -295,11 +292,7 @@ AardDictionary::AardDictionary( string const & id, string const & indexFile, vec
// Read dictionary name // Read dictionary name
idx.seek( sizeof( idxHeader ) ); idx.seek( sizeof( idxHeader ) );
vector< char > dName( idx.read< quint32 >() ); idx.readU32SizeAndData<>( dictionaryName );
if ( dName.size() ) {
idx.read( &dName.front(), dName.size() );
dictionaryName = string( &dName.front(), dName.size() );
}
// Initialize the index // Initialize the index

View file

@ -22,9 +22,6 @@
#include <string.h> #include <string.h>
#include <zlib.h> #include <zlib.h>
#ifdef _MSC_VER
#include <stub_msvc.h>
#endif
#include <QAtomicInt> #include <QAtomicInt>
#include <QPainter> #include <QPainter>
@ -258,15 +255,7 @@ BglDictionary::BglDictionary( string const & id, string const & indexFile, strin
// Read the dictionary's name // Read the dictionary's name
size_t len = idx.read< uint32_t >(); idx.readU32SizeAndData<>( dictionaryName );
if ( len ) {
vector< char > nameBuf( len );
idx.read( &nameBuf.front(), len );
dictionaryName = string( &nameBuf.front(), len );
}
// Initialize the index // Initialize the index
@ -899,8 +888,8 @@ void BglResourceRequest::run()
break; break;
} }
vector< char > nameData( idx.read< uint32_t >() ); vector< char > nameData;
idx.read( &nameData.front(), nameData.size() ); idx.readU32SizeAndData<>( nameData );
for ( size_t x = nameData.size(); x--; ) { for ( size_t x = nameData.size(); x--; ) {
nameData[ x ] = tolower( nameData[ x ] ); nameData[ x ] = tolower( nameData[ x ] );
@ -917,9 +906,9 @@ void BglResourceRequest::run()
data.resize( idx.read< uint32_t >() ); data.resize( idx.read< uint32_t >() );
vector< unsigned char > compressedData( idx.read< uint32_t >() ); vector< unsigned char > compressedData;
idx.read( &compressedData.front(), compressedData.size() ); idx.readU32SizeAndData<>( compressedData );
unsigned long decompressedLength = data.size(); unsigned long decompressedLength = data.size();

View file

@ -23,10 +23,6 @@
#include <QRegularExpression> #include <QRegularExpression>
#ifdef _MSC_VER
#include <stub_msvc.h>
#endif
namespace DictdFiles { namespace DictdFiles {
using std::map; using std::map;
@ -96,11 +92,6 @@ public:
~DictdDictionary(); ~DictdDictionary();
string getName() noexcept override
{
return dictionaryName;
}
map< Dictionary::Property, string > getProperties() noexcept override map< Dictionary::Property, string > getProperties() noexcept override
{ {
return map< Dictionary::Property, string >(); return map< Dictionary::Property, string >();
@ -163,11 +154,7 @@ DictdDictionary::DictdDictionary( string const & id,
// Read the dictionary name // Read the dictionary name
idx.seek( sizeof( idxHeader ) ); idx.seek( sizeof( idxHeader ) );
vector< char > dName( idx.read< uint32_t >() ); idx.readU32SizeAndData<>( dictionaryName );
if ( dName.size() > 0 ) {
idx.read( &dName.front(), dName.size() );
dictionaryName = string( &dName.front(), dName.size() );
}
// Open the .dict file // Open the .dict file

View file

@ -176,7 +176,6 @@ class DictServerDictionary: public Dictionary::Class
{ {
Q_OBJECT Q_OBJECT
string name;
QString url, icon; QString url, icon;
quint32 langId; quint32 langId;
QString errorString; QString errorString;
@ -196,11 +195,13 @@ public:
QString const & strategies_, QString const & strategies_,
QString const & icon_ ): QString const & icon_ ):
Dictionary::Class( id, vector< string >() ), Dictionary::Class( id, vector< string >() ),
name( name_ ),
url( url_ ), url( url_ ),
icon( icon_ ), icon( icon_ ),
langId( 0 ) langId( 0 )
{ {
dictionaryName = name_;
int pos = url.indexOf( "://" ); int pos = url.indexOf( "://" );
if ( pos < 0 ) { if ( pos < 0 ) {
url = "dict://" + url; url = "dict://" + url;
@ -301,11 +302,6 @@ public:
disconnectFromServer( socket ); disconnectFromServer( socket );
} }
string getName() noexcept override
{
return name;
}
map< Property, string > getProperties() noexcept override map< Property, string > getProperties() noexcept override
{ {
return {}; return {};
@ -925,4 +921,4 @@ vector< sptr< Dictionary::Class > > makeDictionaries( Config::DictServers const
return result; return result;
} }
#include "dictserver.moc" #include "dictserver.moc"
} // namespace DictServer } // namespace DictServer

View file

@ -27,10 +27,6 @@
#include <list> #include <list>
#include <wctype.h> #include <wctype.h>
#ifdef _MSC_VER
#include <stub_msvc.h>
#endif
#include <QSemaphore> #include <QSemaphore>
#include <QThreadPool> #include <QThreadPool>
#include <QAtomicInt> #include <QAtomicInt>
@ -176,10 +172,6 @@ public:
~DslDictionary(); ~DslDictionary();
string getName() noexcept override
{
return dictionaryName;
}
map< Dictionary::Property, string > getProperties() noexcept override map< Dictionary::Property, string > getProperties() noexcept override
{ {
@ -303,17 +295,9 @@ DslDictionary::DslDictionary( string const & id, string const & indexFile, vecto
idx.seek( sizeof( idxHeader ) ); idx.seek( sizeof( idxHeader ) );
vector< char > dName( idx.read< uint32_t >() ); idx.readU32SizeAndData<>( dictionaryName );
if ( dName.size() > 0 ) { idx.readU32SizeAndData<>( preferredSoundDictionary );
idx.read( &dName.front(), dName.size() );
dictionaryName = string( &dName.front(), dName.size() );
}
vector< char > sName( idx.read< uint32_t >() );
if ( sName.size() > 0 ) {
idx.read( &sName.front(), sName.size() );
preferredSoundDictionary = string( &sName.front(), sName.size() );
}
resourceDir1 = getDictionaryFilenames()[ 0 ] + ".files" + Utils::Fs::separator(); resourceDir1 = getDictionaryFilenames()[ 0 ] + ".files" + Utils::Fs::separator();
QString s = QString::fromStdString( getDictionaryFilenames()[ 0 ] ); QString s = QString::fromStdString( getDictionaryFilenames()[ 0 ] );
@ -1745,11 +1729,10 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
continue; continue;
} }
// Make sure it's not an abbreviation file // Make sure it's not an abbreviation file. extSize of ".dsl" or ".dsl.dz"
int extSize = ( uncompressedDsl ? 4 : 7 ); if ( int extSize = ( uncompressedDsl ? 4 : 7 ); ( fileName.size() >= ( 5 + extSize ) )
if ( fileName.size() - extSize >= 5 && ( QByteArrayView( fileName ).chopped( extSize ).last( 5 ).compare( "_abrv", Qt::CaseInsensitive ) == 0 ) ) {
&& strncasecmp( fileName.c_str() + fileName.size() - extSize - 5, "_abrv", 5 ) == 0 ) {
// It is, skip it // It is, skip it
continue; continue;
} }

View file

@ -82,7 +82,6 @@ class EpwingDictionary: public BtreeIndexing::BtreeDictionary
QMutex idxMutex; QMutex idxMutex;
File::Index idx; File::Index idx;
IdxHeader idxHeader; IdxHeader idxHeader;
string bookName;
ChunkedStorage::Reader chunks; ChunkedStorage::Reader chunks;
Epwing::Book::EpwingBook eBook; Epwing::Book::EpwingBook eBook;
QString cacheDirectory; QString cacheDirectory;
@ -96,15 +95,6 @@ public:
~EpwingDictionary(); ~EpwingDictionary();
string getName() noexcept override
{
return bookName;
}
void setName( string _name ) noexcept override
{
bookName = _name;
}
map< Dictionary::Property, string > getProperties() noexcept override map< Dictionary::Property, string > getProperties() noexcept override
{ {
@ -227,7 +217,7 @@ EpwingDictionary::EpwingDictionary( string const & id,
idx.seek( sizeof( idxHeader ) ); idx.seek( sizeof( idxHeader ) );
if ( data.size() > 0 ) { if ( data.size() > 0 ) {
idx.read( &data.front(), idxHeader.nameSize ); idx.read( &data.front(), idxHeader.nameSize );
bookName = string( &data.front(), idxHeader.nameSize ); dictionaryName = string( &data.front(), idxHeader.nameSize );
} }
// Initialize eBook // Initialize eBook

View file

@ -18,8 +18,12 @@
#include <QString> #include <QString>
#include <QtCore5Compat/QTextCodec> #include <QtCore5Compat/QTextCodec>
#ifdef _MSC_VER // POSIX symbol unavailable on Windows needed for eb headers
#include <stub_msvc.h> #ifdef Q_OS_WIN
#ifndef _SSIZE_T
#define _SSIZE_T
#define ssize_t long
#endif
#endif #endif
#include <eb/eb.h> #include <eb/eb.h>

View file

@ -20,7 +20,6 @@ namespace {
class ForvoDictionary: public Dictionary::Class class ForvoDictionary: public Dictionary::Class
{ {
string name;
QString apiKey, languageCode; QString apiKey, languageCode;
QNetworkAccessManager & netMgr; QNetworkAccessManager & netMgr;
@ -32,17 +31,13 @@ public:
QString const & languageCode_, QString const & languageCode_,
QNetworkAccessManager & netMgr_ ): QNetworkAccessManager & netMgr_ ):
Dictionary::Class( id, vector< string >() ), Dictionary::Class( id, vector< string >() ),
name( name_ ),
apiKey( apiKey_ ), apiKey( apiKey_ ),
languageCode( languageCode_ ), languageCode( languageCode_ ),
netMgr( netMgr_ ) netMgr( netMgr_ )
{ {
dictionaryName = name_;
} }
string getName() noexcept override
{
return name;
}
map< Property, string > getProperties() noexcept override map< Property, string > getProperties() noexcept override
{ {

View file

@ -39,9 +39,6 @@
#include <map> #include <map>
#include <set> #include <set>
#ifdef _MSC_VER
#include <stub_msvc.h>
#endif
namespace Gls { namespace Gls {
@ -361,11 +358,6 @@ public:
~GlsDictionary(); ~GlsDictionary();
string getName() noexcept override
{
return dictionaryName;
}
map< Dictionary::Property, string > getProperties() noexcept override map< Dictionary::Property, string > getProperties() noexcept override
{ {
return map< Dictionary::Property, string >(); return map< Dictionary::Property, string >();
@ -461,11 +453,7 @@ GlsDictionary::GlsDictionary( string const & id, string const & indexFile, vecto
idx.seek( sizeof( idxHeader ) ); idx.seek( sizeof( idxHeader ) );
vector< char > dName( idx.read< uint32_t >() ); idx.readU32SizeAndData<>( dictionaryName );
if ( dName.size() > 0 ) {
idx.read( &dName.front(), dName.size() );
dictionaryName = string( &dName.front(), dName.size() );
}
// Initialize the index // Initialize the index

View file

@ -41,7 +41,6 @@ namespace {
class HunspellDictionary: public Dictionary::Class class HunspellDictionary: public Dictionary::Class
{ {
string name;
Hunspell hunspell; Hunspell hunspell;
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
@ -56,19 +55,15 @@ public:
/// files[ 0 ] should be .aff file, files[ 1 ] should be .dic file. /// files[ 0 ] should be .aff file, files[ 1 ] should be .dic file.
HunspellDictionary( string const & id, string const & name_, vector< string > const & files ): HunspellDictionary( string const & id, string const & name_, vector< string > const & files ):
Dictionary::Class( id, files ), Dictionary::Class( id, files ),
name( name_ ),
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
hunspell( Utf8ToLocal8Bit( files[ 0 ] ).c_str(), Utf8ToLocal8Bit( files[ 1 ] ).c_str() ) hunspell( Utf8ToLocal8Bit( files[ 0 ] ).c_str(), Utf8ToLocal8Bit( files[ 1 ] ).c_str() )
#else #else
hunspell( files[ 0 ].c_str(), files[ 1 ].c_str() ) hunspell( files[ 0 ].c_str(), files[ 1 ].c_str() )
#endif #endif
{ {
dictionaryName = name_;
} }
string getName() noexcept override
{
return name;
}
map< Property, string > getProperties() noexcept override map< Property, string > getProperties() noexcept override
{ {

View file

@ -60,7 +60,6 @@ private slots:
class LinguaDictionary: public Dictionary::Class class LinguaDictionary: public Dictionary::Class
{ {
string name;
QString languageCode; QString languageCode;
QString langWikipediaID; QString langWikipediaID;
QNetworkAccessManager & netMgr; QNetworkAccessManager & netMgr;
@ -68,10 +67,10 @@ class LinguaDictionary: public Dictionary::Class
public: public:
LinguaDictionary( string const & id, string name_, QString languageCode_, QNetworkAccessManager & netMgr_ ): LinguaDictionary( string const & id, string name_, QString languageCode_, QNetworkAccessManager & netMgr_ ):
Dictionary::Class( id, vector< string >() ), Dictionary::Class( id, vector< string >() ),
name( std::move( name_ ) ),
languageCode( std::move( languageCode_ ) ), languageCode( std::move( languageCode_ ) ),
netMgr( netMgr_ ) netMgr( netMgr_ )
{ {
dictionaryName = name_;
/* map of iso lang code to wikipedia lang id /* map of iso lang code to wikipedia lang id
Data was obtained by this query on https://commons-query.wikimedia.org/ Data was obtained by this query on https://commons-query.wikimedia.org/
@ -166,10 +165,6 @@ WHERE {
} }
} }
string getName() noexcept override
{
return name;
}
map< Property, string > getProperties() noexcept override map< Property, string > getProperties() noexcept override
{ {

View file

@ -14,10 +14,6 @@
#include <set> #include <set>
#include <string> #include <string>
#ifdef _MSC_VER
#include <stub_msvc.h>
#endif
#define OV_EXCLUDE_STATIC_CALLBACKS #define OV_EXCLUDE_STATIC_CALLBACKS
#include <vorbis/vorbisfile.h> #include <vorbis/vorbisfile.h>
#include <QDir> #include <QDir>

View file

@ -23,9 +23,6 @@
#include <map> #include <map>
#include <set> #include <set>
#include <list> #include <list>
#ifdef _MSC_VER
#include <stub_msvc.h>
#endif
#include "globalregex.hh" #include "globalregex.hh"
#include "tiff.hh" #include "tiff.hh"
@ -218,10 +215,6 @@ public:
void deferredInit() override; void deferredInit() override;
string getName() noexcept override
{
return dictionaryName;
}
map< Dictionary::Property, string > getProperties() noexcept override map< Dictionary::Property, string > getProperties() noexcept override
{ {
@ -310,12 +303,7 @@ MdxDictionary::MdxDictionary( string const & id, string const & indexFile, vecto
{ {
// Read the dictionary's name // Read the dictionary's name
idx.seek( sizeof( idxHeader ) ); idx.seek( sizeof( idxHeader ) );
size_t len = idx.read< uint32_t >(); idx.readU32SizeAndData<>( dictionaryName );
vector< char > buf( len );
if ( len > 0 ) {
idx.read( &buf.front(), len );
dictionaryName = string( &buf.front(), len );
}
//fallback, use filename as dictionary name //fallback, use filename as dictionary name
if ( dictionaryName.empty() ) { if ( dictionaryName.empty() ) {
@ -324,12 +312,7 @@ MdxDictionary::MdxDictionary( string const & id, string const & indexFile, vecto
} }
// then read the dictionary's encoding // then read the dictionary's encoding
len = idx.read< uint32_t >(); idx.readU32SizeAndData<>( encoding );
if ( len > 0 ) {
buf.resize( len );
idx.read( &buf.front(), len );
encoding = string( &buf.front(), len );
}
dictFile.setFileName( QString::fromUtf8( dictionaryFiles[ 0 ].c_str() ) ); dictFile.setFileName( QString::fromUtf8( dictionaryFiles[ 0 ].c_str() ) );
dictFile.open( QIODevice::ReadOnly ); dictFile.open( QIODevice::ReadOnly );

View file

@ -19,12 +19,6 @@
#include <set> #include <set>
#include <string> #include <string>
#include "utils.hh"
#ifdef _MSC_VER
#include <stub_msvc.h>
#endif
namespace Sdict { namespace Sdict {
@ -119,10 +113,6 @@ public:
~SdictDictionary(); ~SdictDictionary();
string getName() noexcept override
{
return dictionaryName;
}
map< Dictionary::Property, string > getProperties() noexcept override map< Dictionary::Property, string > getProperties() noexcept override
{ {
@ -196,11 +186,7 @@ SdictDictionary::SdictDictionary( string const & id,
// Read dictionary name // Read dictionary name
idx.seek( sizeof( idxHeader ) ); idx.seek( sizeof( idxHeader ) );
vector< char > dName( idx.read< uint32_t >() ); idx.readU32SizeAndData<>( dictionaryName );
if ( dName.size() > 0 ) {
idx.read( &dName.front(), dName.size() );
dictionaryName = string( &dName.front(), dName.size() );
}
// Initialize the index // Initialize the index

View file

@ -17,10 +17,6 @@
#include "tiff.hh" #include "tiff.hh"
#include "utils.hh" #include "utils.hh"
#ifdef _MSC_VER
#include <stub_msvc.h>
#endif
#include "iconv.hh" #include "iconv.hh"
#include <QString> #include <QString>
@ -618,10 +614,6 @@ public:
~SlobDictionary(); ~SlobDictionary();
string getName() noexcept override
{
return dictionaryName;
}
map< Dictionary::Property, string > getProperties() noexcept override map< Dictionary::Property, string > getProperties() noexcept override
{ {

View file

@ -61,7 +61,6 @@ bool indexIsOldOrBad( string const & indexFile )
class SoundDirDictionary: public BtreeIndexing::BtreeDictionary class SoundDirDictionary: public BtreeIndexing::BtreeDictionary
{ {
string name;
QMutex idxMutex; QMutex idxMutex;
File::Index idx; File::Index idx;
IdxHeader idxHeader; IdxHeader idxHeader;
@ -76,10 +75,6 @@ public:
vector< string > const & dictionaryFiles, vector< string > const & dictionaryFiles,
QString const & iconFilename_ ); QString const & iconFilename_ );
string getName() noexcept override
{
return name;
}
map< Dictionary::Property, string > getProperties() noexcept override map< Dictionary::Property, string > getProperties() noexcept override
{ {
@ -113,12 +108,13 @@ SoundDirDictionary::SoundDirDictionary( string const & id,
vector< string > const & dictionaryFiles, vector< string > const & dictionaryFiles,
QString const & iconFilename_ ): QString const & iconFilename_ ):
BtreeDictionary( id, dictionaryFiles ), BtreeDictionary( id, dictionaryFiles ),
name( name_ ),
idx( indexFile, QIODevice::ReadOnly ), idx( indexFile, QIODevice::ReadOnly ),
idxHeader( idx.read< IdxHeader >() ), idxHeader( idx.read< IdxHeader >() ),
chunks( idx, idxHeader.chunksOffset ), chunks( idx, idxHeader.chunksOffset ),
iconFilename( iconFilename_ ) iconFilename( iconFilename_ )
{ {
dictionaryName = name_;
// Initialize the index // Initialize the index
openIndex( IndexInfo( idxHeader.indexBtreeMaxElements, idxHeader.indexRootOffset ), idx, idxMutex ); openIndex( IndexInfo( idxHeader.indexBtreeMaxElements, idxHeader.indexRootOffset ), idx, idxMutex );

View file

@ -30,9 +30,6 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#ifdef _MSC_VER
#include <stub_msvc.h>
#endif
#include <QString> #include <QString>
#include <QSemaphore> #include <QSemaphore>
@ -131,7 +128,6 @@ class StardictDictionary: public BtreeIndexing::BtreeDictionary
QMutex idxMutex; QMutex idxMutex;
File::Index idx; File::Index idx;
IdxHeader idxHeader; IdxHeader idxHeader;
string bookName;
string sameTypeSequence; string sameTypeSequence;
ChunkedStorage::Reader chunks; ChunkedStorage::Reader chunks;
QMutex dzMutex; QMutex dzMutex;
@ -145,17 +141,6 @@ public:
~StardictDictionary(); ~StardictDictionary();
string getName() noexcept override
{
return bookName;
}
void setName( string _name ) noexcept override
{
bookName = _name;
}
map< Dictionary::Property, string > getProperties() noexcept override map< Dictionary::Property, string > getProperties() noexcept override
{ {
return map< Dictionary::Property, string >(); return map< Dictionary::Property, string >();
@ -239,10 +224,10 @@ StardictDictionary::StardictDictionary( string const & id,
BtreeDictionary( id, dictionaryFiles ), BtreeDictionary( id, dictionaryFiles ),
idx( indexFile, QIODevice::ReadOnly ), idx( indexFile, QIODevice::ReadOnly ),
idxHeader( idx.read< IdxHeader >() ), idxHeader( idx.read< IdxHeader >() ),
bookName( loadString( idxHeader.bookNameSize ) ),
sameTypeSequence( loadString( idxHeader.sameTypeSequenceSize ) ), sameTypeSequence( loadString( idxHeader.sameTypeSequenceSize ) ),
chunks( idx, idxHeader.chunksOffset ) chunks( idx, idxHeader.chunksOffset )
{ {
dictionaryName = loadString( idxHeader.bookNameSize );
// Open the .dict file // Open the .dict file
DZ_ERRORS error; DZ_ERRORS error;

View file

@ -81,6 +81,18 @@ public:
/// Like the above, but uses its own local internal buffer and strips newlines by default. /// Like the above, but uses its own local internal buffer and strips newlines by default.
std::string gets( bool stripNl = true ); std::string gets( bool stripNl = true );
/// Read 32bit as uint, then reading the subsequent data into a container
template< typename T >
void readU32SizeAndData( T & container )
{
uint32_t size = 0;
read( &size, sizeof( uint32_t ) );
if ( size > 0 ) {
container.resize( size );
read( container.data(), size );
}
};
/// export QFile::readall /// export QFile::readall
QByteArray readall(); QByteArray readall();

View file

@ -22,7 +22,6 @@ namespace {
class WebSiteDictionary: public Dictionary::Class class WebSiteDictionary: public Dictionary::Class
{ {
string name;
QByteArray urlTemplate; QByteArray urlTemplate;
bool experimentalIframe; bool experimentalIframe;
QString iconFilename; QString iconFilename;
@ -38,12 +37,13 @@ public:
bool inside_iframe_, bool inside_iframe_,
QNetworkAccessManager & netMgr_ ): QNetworkAccessManager & netMgr_ ):
Dictionary::Class( id, vector< string >() ), Dictionary::Class( id, vector< string >() ),
name( name_ ),
iconFilename( iconFilename_ ), iconFilename( iconFilename_ ),
inside_iframe( inside_iframe_ ), inside_iframe( inside_iframe_ ),
netMgr( netMgr_ ), netMgr( netMgr_ ),
experimentalIframe( false ) experimentalIframe( false )
{ {
dictionaryName = name_;
if ( urlTemplate_.startsWith( "http://" ) || urlTemplate_.startsWith( "https://" ) ) { if ( urlTemplate_.startsWith( "http://" ) || urlTemplate_.startsWith( "https://" ) ) {
experimentalIframe = true; experimentalIframe = true;
} }
@ -53,10 +53,6 @@ public:
dictionaryDescription = urlTemplate_; dictionaryDescription = urlTemplate_;
} }
string getName() noexcept override
{
return name;
}
map< Property, string > getProperties() noexcept override map< Property, string > getProperties() noexcept override
{ {
@ -478,7 +474,8 @@ void WebSiteDictionary::loadIcon() noexcept
loadIconFromFile( fInfo.absoluteFilePath(), true ); loadIconFromFile( fInfo.absoluteFilePath(), true );
} }
} }
if ( dictionaryIcon.isNull() && !loadIconFromText( ":/icons/webdict.svg", QString::fromStdString( name ) ) ) { if ( dictionaryIcon.isNull()
&& !loadIconFromText( ":/icons/webdict.svg", QString::fromStdString( dictionaryName ) ) ) {
dictionaryIcon = QIcon( ":/icons/webdict.svg" ); dictionaryIcon = QIcon( ":/icons/webdict.svg" );
} }
dictionaryIconLoaded = true; dictionaryIconLoaded = true;

View file

@ -27,9 +27,6 @@
#include "tiff.hh" #include "tiff.hh"
#include "ftshelpers.hh" #include "ftshelpers.hh"
#ifdef _MSC_VER
#include <stub_msvc.h>
#endif
#include <QIODevice> #include <QIODevice>
#include <QXmlStreamReader> #include <QXmlStreamReader>
@ -152,10 +149,6 @@ public:
~XdxfDictionary(); ~XdxfDictionary();
string getName() noexcept override
{
return dictionaryName;
}
map< Dictionary::Property, string > getProperties() noexcept override map< Dictionary::Property, string > getProperties() noexcept override
{ {

View file

@ -17,10 +17,6 @@
#include "ftshelpers.hh" #include "ftshelpers.hh"
#include "htmlescape.hh" #include "htmlescape.hh"
#ifdef _MSC_VER
#include <stub_msvc.h>
#endif
#include <QByteArray> #include <QByteArray>
#include <QFile> #include <QFile>
#include <QString> #include <QString>
@ -168,10 +164,6 @@ public:
~ZimDictionary() = default; ~ZimDictionary() = default;
string getName() noexcept override
{
return dictionaryName;
}
map< Dictionary::Property, string > getProperties() noexcept override map< Dictionary::Property, string > getProperties() noexcept override
{ {

View file

@ -19,9 +19,6 @@
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#ifdef _MSC_VER
#include <stub_msvc.h>
#endif
#include "utils.hh" #include "utils.hh"

View file

@ -9,9 +9,6 @@
#include <QLocale> #include <QLocale>
#include <QRegularExpression> #include <QRegularExpression>
#ifdef _MSC_VER
#include <stub_msvc.h>
#endif
// Language codes // Language codes
QMap< QString, GDLangCode > LangCoder::LANG_CODE_MAP = { QMap< QString, GDLangCode > LangCoder::LANG_CODE_MAP = {
@ -231,10 +228,10 @@ QString LangCoder::intToCode2( quint32 val )
quint32 LangCoder::findIdForLanguage( gd::wstring const & lang ) quint32 LangCoder::findIdForLanguage( gd::wstring const & lang )
{ {
const auto langFolded = Utf8::encode( lang ); const auto langFolded = QByteArrayView( Utf8::encode( lang ) );
for ( auto const & lc : LANG_CODE_MAP ) { for ( auto const & lc : LANG_CODE_MAP ) {
if ( strcasecmp( langFolded.c_str(), lc.lang.c_str() ) == 0 ) { if ( langFolded.compare( lc.lang, Qt::CaseInsensitive ) == 0 ) {
return code2toInt( lc.code2.toStdString().c_str() ); return code2toInt( lc.code2.toStdString().c_str() );
} }
} }

View file

@ -185,6 +185,7 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
ui.doubleClickTranslates->setChecked( p.doubleClickTranslates ); ui.doubleClickTranslates->setChecked( p.doubleClickTranslates );
ui.selectBySingleClick->setChecked( p.selectWordBySingleClick ); ui.selectBySingleClick->setChecked( p.selectWordBySingleClick );
ui.autoScrollToTargetArticle->setChecked( p.autoScrollToTargetArticle ); ui.autoScrollToTargetArticle->setChecked( p.autoScrollToTargetArticle );
ui.targetArticleAtFirst->setChecked( p.targetArticleAtFirst );
ui.escKeyHidesMainWindow->setChecked( p.escKeyHidesMainWindow ); ui.escKeyHidesMainWindow->setChecked( p.escKeyHidesMainWindow );
ui.darkMode->addItem( tr( "On" ), QVariant::fromValue( Config::Dark::On ) ); ui.darkMode->addItem( tr( "On" ), QVariant::fromValue( Config::Dark::On ) );
@ -441,6 +442,7 @@ Config::Preferences Preferences::getPreferences()
p.doubleClickTranslates = ui.doubleClickTranslates->isChecked(); p.doubleClickTranslates = ui.doubleClickTranslates->isChecked();
p.selectWordBySingleClick = ui.selectBySingleClick->isChecked(); p.selectWordBySingleClick = ui.selectBySingleClick->isChecked();
p.autoScrollToTargetArticle = ui.autoScrollToTargetArticle->isChecked(); p.autoScrollToTargetArticle = ui.autoScrollToTargetArticle->isChecked();
p.targetArticleAtFirst = ui.targetArticleAtFirst->isChecked();
p.escKeyHidesMainWindow = ui.escKeyHidesMainWindow->isChecked(); p.escKeyHidesMainWindow = ui.escKeyHidesMainWindow->isChecked();
p.darkMode = ui.darkMode->currentData().value< Config::Dark >(); p.darkMode = ui.darkMode->currentData().value< Config::Dark >();

View file

@ -169,6 +169,16 @@ however, the article from the topmost dictionary is shown.</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1">
<widget class="QCheckBox" name="targetArticleAtFirst">
<property name="text">
<string>Place the target article at the first place.</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QGroupBox" name="enableTrayIcon"> <widget class="QGroupBox" name="enableTrayIcon">
<property name="toolTip"> <property name="toolTip">

View file

@ -1,17 +0,0 @@
#pragma once
#include <string>
#ifdef _MSC_VER
#if !defined(strcasecmp)
# define strcasecmp _strcmpi
#endif
#if !defined(strncasecmp)
# define strncasecmp _strnicmp
#endif
#ifndef _SSIZE_T
#define _SSIZE_T
#define ssize_t long
#endif
#endif