added language recognition for dictd files

This commit is contained in:
ars_goldendict 2009-05-05 22:45:02 +00:00
parent ebf1f61c4e
commit 4e0b2626fb
2 changed files with 29 additions and 10 deletions

View file

@ -8,6 +8,7 @@
#include "dictzip.h"
#include "htmlescape.hh"
#include "fsencoding.hh"
#include "langcoder.hh"
#include <map>
#include <set>
#include <string>
@ -45,7 +46,7 @@ DEF_EX( exInvalidBase64, "Invalid base64 sequence encountered", Dictionary::Ex )
enum
{
Signature = 0x58444344, // DCDX on little-endian, XDCD on big-endian
CurrentFormatVersion = 2 + BtreeIndexing::FormatVersion + Folding::Version
CurrentFormatVersion = 3 + BtreeIndexing::FormatVersion + Folding::Version
};
struct IdxHeader
@ -55,6 +56,8 @@ struct IdxHeader
uint32_t wordCount; // Total number of words
uint32_t indexBtreeMaxElements; // Two fields from IndexInfo
uint32_t indexRootOffset;
uint32_t langFrom; // Source language
uint32_t langTo; // Target language
}
#ifndef _MSC_VER
__attribute__((packed))
@ -100,6 +103,12 @@ public:
virtual QIcon getIcon() throw()
{ return QIcon(":/icons/icon32_dictd.png"); }
inline virtual quint32 getLangFrom() const
{ return idxHeader.langFrom; }
inline virtual quint32 getLangTo() const
{ return idxHeader.langTo; }
virtual sptr< Dictionary::DataRequest > getArticle( wstring const &,
vector< wstring > const & alts )
throw( std::exception );
@ -403,6 +412,20 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
idxHeader.signature = Signature;
idxHeader.formatVersion = CurrentFormatVersion;
// read languages
QPair<quint32,quint32> langs =
LangCoder::findIdsForFilename( QString::fromStdString( dictFiles[ 0 ] ) );
// if no languages found, try dictionary's name
if ( langs.first == 0 || langs.second == 0 )
{
langs =
LangCoder::findIdsForFilename( QString::fromStdString( nameFromFileName( dictFiles[ 0 ] ) ) );
}
idxHeader.langFrom = langs.first;
idxHeader.langTo = langs.second;
idx.rewind();
idx.write( &idxHeader, sizeof( idxHeader ) );

View file

@ -1090,22 +1090,18 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
// read languages
QPair<quint32,quint32> langs =
LangCoder::findIdsForFilename( QString::fromStdString( dictFileName ) );
idxHeader.langFrom = langs.first;
idxHeader.langTo = langs.second;
// qDebug() << QString::fromStdString( dictFileName ) << " " << langs;
// if no languages found, try dictionary's name
if ( langs.first == 0 || langs.second == 0 )
{
// qDebug() << QString::fromStdString( ifo.bookname );
langs =
LangCoder::findIdsForFilename( QString::fromStdString( ifo.bookname ) );
idxHeader.langFrom = langs.first;
idxHeader.langTo = langs.second;
}
idxHeader.langFrom = langs.first;
idxHeader.langTo = langs.second;
idx.rewind();
idx.write( &idxHeader, sizeof( idxHeader ) );