Allow search of audio files in sound dictionaries for Xdxf and Stardict-xdxf dictionaries

This commit is contained in:
Abs62 2015-08-01 13:38:39 +03:00
parent a8df5c941f
commit b4bb1e9635
4 changed files with 38 additions and 12 deletions

View file

@ -335,7 +335,7 @@ string StardictDictionary::handleResource( char type, char const * resource, siz
switch( type )
{
case 'x': // Xdxf content
return Xdxf2Html::convert( string( resource, size ), Xdxf2Html::STARDICT, NULL, this );
return Xdxf2Html::convert( string( resource, size ), Xdxf2Html::STARDICT, NULL, this, &resourceZip );
case 'h': // Html content
{
string articleText = "<div class=\"sdct_h\">" + string( resource, size ) + "</div>";

View file

@ -659,7 +659,7 @@ void XdxfDictionary::loadArticle( uint32_t address,
}
articleText = Xdxf2Html::convert( string( articleBody ), Xdxf2Html::XDXF, idxHeader.hasAbrv ? &abrv : NULL, this,
fType == Logical, idxHeader.revisionNumber, headword );
&resourceZip, fType == Logical, idxHeader.revisionNumber, headword );
free( articleBody );
}

View file

@ -57,8 +57,8 @@ string convertToRoman( int input, int lower_case )
}
string convert( string const & in, DICT_TYPE type, map < string, string > const * pAbrv,
Dictionary::Class *dictPtr, bool isLogicalFormat, unsigned revisionNumber,
QString * headword )
Dictionary::Class *dictPtr, IndexedZip * resourceZip,
bool isLogicalFormat, unsigned revisionNumber, QString * headword )
{
// DPRINTF( "Source>>>>>>>>>>: %s\n\n\n", in.c_str() );
@ -510,15 +510,40 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
}
else if( Filetype::isNameOfSound( filename ) )
{
QUrl url;
url.setScheme( "gdau" );
url.setHost( QString::fromUtf8( dictPtr->getId().c_str() ) );
url.setPath( QString::fromUtf8( filename.c_str() ) );
QDomElement el_script = dd.createElement( "script" );
QDomNode parent = el.parentNode();
if( !parent.isNull() )
{
bool search = false;
if( type == STARDICT )
{
string n = FsEncoding::dirname( dictPtr->getDictionaryFilenames()[ 0 ] ) +
FsEncoding::separator() + string( "res" ) + FsEncoding::separator() +
FsEncoding::encode( filename );
search = !File::exists( n ) &&
( !resourceZip ||
!resourceZip->isOpen() ||
!resourceZip->hasFile( Utf8::decode( filename ) ) );
}
else
{
string n = dictPtr->getDictionaryFilenames()[ 0 ] + ".files" +
FsEncoding::separator() +
FsEncoding::encode( filename );
search = !File::exists( n ) && !File::exists( FsEncoding::dirname( dictPtr->getDictionaryFilenames()[ 0 ] ) +
FsEncoding::separator() +
FsEncoding::encode( filename ) ) &&
( !resourceZip ||
!resourceZip->isOpen() ||
!resourceZip->hasFile( Utf8::decode( filename ) ) );
}
QUrl url;
url.setScheme( "gdau" );
url.setHost( QString::fromUtf8( search ? "search" : dictPtr->getId().c_str() ) );
url.setPath( QString::fromUtf8( filename.c_str() ) );
el_script.setAttribute( "type", "text/javascript" );
parent.replaceChild( el_script, el );

View file

@ -7,6 +7,7 @@
#include <string>
#include <map>
#include "dictionary.hh"
#include "indexedzip.hh"
/// Xdxf is an xml file format. Since we display html, we'd like to be able
/// to convert articles with such a markup to an html.
@ -19,9 +20,9 @@ using std::map;
/// Converts the given xdxf markup to an html one. This is currently used
/// for Stardict's 'x' records.
string convert( string const &, DICT_TYPE type = STARDICT, map < string, string > const * pAbrv = NULL,
Dictionary::Class *dictPtr = NULL, bool isLogicalFormat = false, unsigned revisionNumber = 0,
QString * headword = 0 );
string convert( string const &, DICT_TYPE type, map < string, string > const * pAbrv,
Dictionary::Class *dictPtr, IndexedZip * resourceZip, bool isLogicalFormat = false,
unsigned revisionNumber = 0, QString * headword = 0 );
}