mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 04:24:09 +00:00
Show decription for DSL dictionaries
This commit is contained in:
parent
5b4d966439
commit
f8025f1854
71
dsl.cc
71
dsl.cc
|
@ -185,6 +185,8 @@ public:
|
||||||
virtual sptr< Dictionary::DataRequest > getResource( string const & name )
|
virtual sptr< Dictionary::DataRequest > getResource( string const & name )
|
||||||
throw( std::exception );
|
throw( std::exception );
|
||||||
|
|
||||||
|
virtual QString const& getDescription();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
virtual string const & ensureInitDone();
|
virtual string const & ensureInitDone();
|
||||||
|
@ -420,8 +422,6 @@ void DslDictionary::loadIcon()
|
||||||
|
|
||||||
// Remove the extension
|
// Remove the extension
|
||||||
|
|
||||||
QString lc = fileName.toLower();
|
|
||||||
|
|
||||||
if ( fileName.endsWith( ".dsl.dz", Qt::CaseInsensitive ) )
|
if ( fileName.endsWith( ".dsl.dz", Qt::CaseInsensitive ) )
|
||||||
fileName.chop( 6 );
|
fileName.chop( 6 );
|
||||||
else
|
else
|
||||||
|
@ -894,6 +894,73 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString const& DslDictionary::getDescription()
|
||||||
|
{
|
||||||
|
if( !dictionaryDescription.isEmpty() )
|
||||||
|
return dictionaryDescription;
|
||||||
|
|
||||||
|
dictionaryDescription = "NONE";
|
||||||
|
|
||||||
|
QString fileName =
|
||||||
|
QDir::fromNativeSeparators( FsEncoding::decode( getDictionaryFilenames()[ 0 ].c_str() ) );
|
||||||
|
|
||||||
|
// Remove the extension
|
||||||
|
if ( fileName.endsWith( ".dsl.dz", Qt::CaseInsensitive ) )
|
||||||
|
fileName.chop( 6 );
|
||||||
|
else
|
||||||
|
fileName.chop( 3 );
|
||||||
|
|
||||||
|
fileName += "ann";
|
||||||
|
QFileInfo info( fileName );
|
||||||
|
|
||||||
|
if ( info.exists() )
|
||||||
|
{
|
||||||
|
QFile annFile( fileName );
|
||||||
|
if( !annFile.open( QFile::ReadOnly | QFile::Text ) )
|
||||||
|
return dictionaryDescription;
|
||||||
|
|
||||||
|
QTextStream annStream( &annFile );
|
||||||
|
QString data, str;
|
||||||
|
|
||||||
|
str = annStream.readLine();
|
||||||
|
|
||||||
|
if( str.left( 10 ).compare( "#LANGUAGE " ) != 0 )
|
||||||
|
{
|
||||||
|
annStream.seek( 0 );
|
||||||
|
dictionaryDescription = annStream.readAll();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Multilanguage annotation
|
||||||
|
|
||||||
|
qint32 gdLang, annLang;
|
||||||
|
QString langStr;
|
||||||
|
gdLang = LangCoder::code2toInt( QLocale::system().name().left( 2 ).toAscii().data() );
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
data.clear();
|
||||||
|
langStr = str.mid( 10 ).replace( '\"', ' ').trimmed();
|
||||||
|
annLang = LangCoder::findIdForLanguage( gd::toWString( langStr ) );
|
||||||
|
do
|
||||||
|
{
|
||||||
|
str = annStream.readLine();
|
||||||
|
if( str.left( 10 ).compare( "#LANGUAGE " ) == 0 )
|
||||||
|
break;
|
||||||
|
if( !str.endsWith( '\n' ) )
|
||||||
|
str.append( '\n' );
|
||||||
|
data += str;
|
||||||
|
}
|
||||||
|
while ( !annStream.atEnd() );
|
||||||
|
if( dictionaryDescription.compare( "NONE ") == 0 || langStr.compare( "English", Qt::CaseInsensitive ) == 0 || gdLang == annLang )
|
||||||
|
dictionaryDescription = data.trimmed();
|
||||||
|
if( gdLang == annLang || annStream.atEnd() )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dictionaryDescription;
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
vector< wstring > StardictDictionary::findHeadwordsForSynonym( wstring const & str )
|
vector< wstring > StardictDictionary::findHeadwordsForSynonym( wstring const & str )
|
||||||
throw( std::exception )
|
throw( std::exception )
|
||||||
|
|
Loading…
Reference in a new issue