mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
Show decription for Stardict dictionaries
This commit is contained in:
parent
d0437a48d9
commit
5b4d966439
|
@ -1,6 +1,8 @@
|
|||
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
||||
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||
|
||||
#include <QString>
|
||||
#include <QTextDocumentFragment>
|
||||
#include "htmlescape.hh"
|
||||
|
||||
namespace Html {
|
||||
|
@ -117,4 +119,12 @@ string escapeForJavaScript( string const & str )
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,9 @@ string preformat( string const & );
|
|||
// Escapes the given string to be included in JavaScript.
|
||||
string escapeForJavaScript( string const & );
|
||||
|
||||
// Replace html entities
|
||||
QString unescape( QString const & str );
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
27
stardict.cc
27
stardict.cc
|
@ -72,7 +72,7 @@ struct Ifo
|
|||
string version;
|
||||
string bookname;
|
||||
uint32_t wordcount, synwordcount, idxfilesize, idxoffsetbits;
|
||||
string sametypesequence, dicttype;
|
||||
string sametypesequence, dicttype, description;
|
||||
|
||||
Ifo( File::Class & );
|
||||
};
|
||||
|
@ -167,6 +167,8 @@ public:
|
|||
virtual sptr< Dictionary::DataRequest > getResource( string const & name )
|
||||
throw( std::exception );
|
||||
|
||||
virtual QString const& getDescription();
|
||||
|
||||
private:
|
||||
|
||||
void loadIcon();
|
||||
|
@ -544,6 +546,26 @@ void StardictDictionary::loadArticle( uint32_t address,
|
|||
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()
|
||||
|
||||
|
@ -921,6 +943,9 @@ Ifo::Ifo( File::Class & f ):
|
|||
else
|
||||
if ( char const * val = beginsWith( "dicttype=", option ) )
|
||||
dicttype = val;
|
||||
else
|
||||
if ( char const * val = beginsWith( "description=", option ) )
|
||||
description = val;
|
||||
}
|
||||
}
|
||||
catch( File::exReadError & )
|
||||
|
|
Loading…
Reference in a new issue