From 4e0b2626fbee9e2bb1b1d04bc5c29b139d8f556d Mon Sep 17 00:00:00 2001 From: ars_goldendict Date: Tue, 5 May 2009 22:45:02 +0000 Subject: [PATCH] added language recognition for dictd files --- src/dictdfiles.cc | 27 +++++++++++++++++++++++++-- src/stardict.cc | 12 ++++-------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/dictdfiles.cc b/src/dictdfiles.cc index aa00b77e..094d41e9 100644 --- a/src/dictdfiles.cc +++ b/src/dictdfiles.cc @@ -8,6 +8,7 @@ #include "dictzip.h" #include "htmlescape.hh" #include "fsencoding.hh" +#include "langcoder.hh" #include #include #include @@ -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,7 +56,9 @@ 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)) #endif @@ -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 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 ) ); diff --git a/src/stardict.cc b/src/stardict.cc index 4ac04eba..140cc32a 100644 --- a/src/stardict.cc +++ b/src/stardict.cc @@ -1090,22 +1090,18 @@ vector< sptr< Dictionary::Class > > makeDictionaries( // read languages QPair 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 ) );