mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-12-23 23:54:05 +00:00
Description for SDictionary dictionaries
This commit is contained in:
parent
c35dcbeb2b
commit
ec407aa6bb
67
sdict.cc
67
sdict.cc
|
@ -161,6 +161,8 @@ class SdictDictionary: public BtreeIndexing::BtreeDictionary
|
||||||
wstring const & )
|
wstring const & )
|
||||||
throw( std::exception );
|
throw( std::exception );
|
||||||
|
|
||||||
|
virtual QString const & getDescription();
|
||||||
|
|
||||||
virtual sptr< Dictionary::DataRequest > getSearchResults( QString const & searchString,
|
virtual sptr< Dictionary::DataRequest > getSearchResults( QString const & searchString,
|
||||||
int searchMode, bool matchCase,
|
int searchMode, bool matchCase,
|
||||||
int distanceBetweenWords,
|
int distanceBetweenWords,
|
||||||
|
@ -635,6 +637,71 @@ sptr< Dictionary::DataRequest > SdictDictionary::getArticle( wstring const & wor
|
||||||
return new SdictArticleRequest( word, alts, *this );
|
return new SdictArticleRequest( word, alts, *this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString const& SdictDictionary::getDescription()
|
||||||
|
{
|
||||||
|
if( !dictionaryDescription.isEmpty() )
|
||||||
|
return dictionaryDescription;
|
||||||
|
|
||||||
|
dictionaryDescription = QString::fromLatin1( "Title: " )
|
||||||
|
+ QString::fromUtf8( getName().c_str() );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Mutex::Lock _( sdictMutex );
|
||||||
|
|
||||||
|
DCT_header dictHeader;
|
||||||
|
|
||||||
|
df.seek( 0 );
|
||||||
|
if( df.readRecords( &dictHeader, sizeof(dictHeader), 1 ) != 1 )
|
||||||
|
throw exCantReadFile( getDictionaryFilenames()[ 0 ] );
|
||||||
|
|
||||||
|
int compression = dictHeader.compression & 0x0F;
|
||||||
|
|
||||||
|
vector< char > data;
|
||||||
|
uint32_t size;
|
||||||
|
string str;
|
||||||
|
|
||||||
|
df.seek( dictHeader.copyrightOffset );
|
||||||
|
df.read( &size, sizeof( size ) );
|
||||||
|
data.resize( size );
|
||||||
|
df.read( &data.front(), size );
|
||||||
|
|
||||||
|
if( compression == 1 )
|
||||||
|
str = decompressZlib( data.data(), size );
|
||||||
|
else if( compression == 2 )
|
||||||
|
str = decompressBzip2( data.data(), size );
|
||||||
|
else
|
||||||
|
str = string( data.data(), size );
|
||||||
|
|
||||||
|
dictionaryDescription += QString::fromLatin1( "\n\nCopyright: " )
|
||||||
|
+ QString::fromUtf8( str.c_str(), str.size() );
|
||||||
|
|
||||||
|
df.seek( dictHeader.versionOffset );
|
||||||
|
df.read( &size, sizeof( size ) );
|
||||||
|
data.resize( size );
|
||||||
|
df.read( &data.front(), size );
|
||||||
|
|
||||||
|
if( compression == 1 )
|
||||||
|
str = decompressZlib( data.data(), size );
|
||||||
|
else if( compression == 2 )
|
||||||
|
str = decompressBzip2( data.data(), size );
|
||||||
|
else
|
||||||
|
str = string( data.data(), size );
|
||||||
|
|
||||||
|
dictionaryDescription += QString::fromLatin1( "\n\nVersion: " )
|
||||||
|
+ QString::fromUtf8( str.c_str(), str.size() );
|
||||||
|
}
|
||||||
|
catch( std::exception &ex )
|
||||||
|
{
|
||||||
|
gdWarning( "SDict: Failed description reading for \"%s\", reason: %s\n", getName().c_str(), ex.what() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( dictionaryDescription.isEmpty() )
|
||||||
|
dictionaryDescription = "NONE";
|
||||||
|
|
||||||
|
return dictionaryDescription;
|
||||||
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
vector< sptr< Dictionary::Class > > makeDictionaries(
|
vector< sptr< Dictionary::Class > > makeDictionaries(
|
||||||
|
|
Loading…
Reference in a new issue