From f8025f185442dc184ad9ac7e670bbd9150492c47 Mon Sep 17 00:00:00 2001 From: Abs62 Date: Fri, 7 Sep 2012 20:17:44 +0400 Subject: [PATCH] Show decription for DSL dictionaries --- dsl.cc | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/dsl.cc b/dsl.cc index 0c379e2a..f9f1e1b9 100644 --- a/dsl.cc +++ b/dsl.cc @@ -185,6 +185,8 @@ public: virtual sptr< Dictionary::DataRequest > getResource( string const & name ) throw( std::exception ); + virtual QString const& getDescription(); + private: virtual string const & ensureInitDone(); @@ -420,8 +422,6 @@ void DslDictionary::loadIcon() // Remove the extension - QString lc = fileName.toLower(); - if ( fileName.endsWith( ".dsl.dz", Qt::CaseInsensitive ) ) fileName.chop( 6 ); else @@ -894,6 +894,73 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node ) 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 vector< wstring > StardictDictionary::findHeadwordsForSynonym( wstring const & str ) throw( std::exception )