Show decription for Stardict dictionaries

This commit is contained in:
Abs62 2012-09-07 17:58:45 +04:00
parent d0437a48d9
commit 5b4d966439
3 changed files with 39 additions and 1 deletions

View file

@ -1,6 +1,8 @@
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org> /* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#include <QString>
#include <QTextDocumentFragment>
#include "htmlescape.hh" #include "htmlescape.hh"
namespace Html { namespace Html {
@ -117,4 +119,12 @@ string escapeForJavaScript( string const & str )
return result; return result;
} }
QString unescape( QString const & str )
{
// Does it contain HTML? If it does, we need to strip it
if ( str.contains( '<' ) || str.contains( '&' ) )
return QTextDocumentFragment::fromHtml( str ).toPlainText();
return str;
}
} }

View file

@ -22,6 +22,9 @@ string preformat( string const & );
// Escapes the given string to be included in JavaScript. // Escapes the given string to be included in JavaScript.
string escapeForJavaScript( string const & ); string escapeForJavaScript( string const & );
// Replace html entities
QString unescape( QString const & str );
} }
#endif #endif

View file

@ -72,7 +72,7 @@ struct Ifo
string version; string version;
string bookname; string bookname;
uint32_t wordcount, synwordcount, idxfilesize, idxoffsetbits; uint32_t wordcount, synwordcount, idxfilesize, idxoffsetbits;
string sametypesequence, dicttype; string sametypesequence, dicttype, description;
Ifo( File::Class & ); Ifo( File::Class & );
}; };
@ -167,6 +167,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:
void loadIcon(); void loadIcon();
@ -544,6 +546,26 @@ void StardictDictionary::loadArticle( uint32_t address,
free( articleBody ); free( articleBody );
} }
QString const& StardictDictionary::getDescription()
{
if( !dictionaryDescription.isEmpty() )
return dictionaryDescription;
dictionaryDescription = "NONE";
File::Class ifoFile( getDictionaryFilenames()[ 0 ], "r" );
Ifo ifo( ifoFile );
if( !ifo.description.empty() )
{
dictionaryDescription = QString::fromUtf8( ifo.description.c_str() );
dictionaryDescription.replace( "\t", "<br/>" );
dictionaryDescription.replace( "\\n", "<br/>" );
dictionaryDescription = Html::unescape( dictionaryDescription );
}
return dictionaryDescription;
}
/// StardictDictionary::findHeadwordsForSynonym() /// StardictDictionary::findHeadwordsForSynonym()
@ -921,6 +943,9 @@ Ifo::Ifo( File::Class & f ):
else else
if ( char const * val = beginsWith( "dicttype=", option ) ) if ( char const * val = beginsWith( "dicttype=", option ) )
dicttype = val; dicttype = val;
else
if ( char const * val = beginsWith( "description=", option ) )
description = val;
} }
} }
catch( File::exReadError & ) catch( File::exReadError & )