Add SLOB dictionaries support

This commit is contained in:
Abs62 2015-01-22 18:17:05 +03:00
parent 8075fd04b2
commit 0912df7cb5
13 changed files with 1391 additions and 9 deletions

View file

@ -37,7 +37,7 @@ Alternatively, you might want to load `goldendict.pro` file from within Qt Creat
### Building with Zim dictionaries support ### Building with Zim dictionaries support
To add Zim format support you need at first install lzma-dev package: To add Zim and Slob formats support you need at first install lzma-dev package:
sudo apt-get liblzma-dev sudo apt-get liblzma-dev

View file

@ -82,7 +82,8 @@ int res;
#define BUFSIZE 0xFFFF #define BUFSIZE 0xFFFF
string decompressLzma2( const char * bufptr, unsigned length ) string decompressLzma2( const char * bufptr, unsigned length,
bool raw_decoder )
{ {
string str; string str;
lzma_ret res; lzma_ret res;
@ -92,9 +93,25 @@ char buf[BUFSIZE];
strm.next_in = reinterpret_cast< const uint8_t * >( bufptr ); strm.next_in = reinterpret_cast< const uint8_t * >( bufptr );
strm.avail_in = length; strm.avail_in = length;
lzma_options_lzma opt;
lzma_filter filters[ 2 ];
if( raw_decoder )
{
lzma_lzma_preset(&opt, LZMA_PRESET_DEFAULT);
filters[ 0 ].id = LZMA_FILTER_LZMA2;
filters[ 0 ].options = &opt;
filters[ 1 ].id = LZMA_VLI_UNKNOWN;
}
while( 1 ) while( 1 )
{ {
if( raw_decoder )
res = lzma_raw_decoder( &strm, filters );
else
res = lzma_stream_decoder( &strm, UINT64_MAX, 0 ); res = lzma_stream_decoder( &strm, UINT64_MAX, 0 );
if( res != LZMA_OK ) if( res != LZMA_OK )
break; break;

View file

@ -14,7 +14,8 @@ string decompressBzip2( const char * bufptr, unsigned length );
#ifdef MAKE_ZIM_SUPPORT #ifdef MAKE_ZIM_SUPPORT
string decompressLzma2( const char * bufptr, unsigned length ); string decompressLzma2( const char * bufptr, unsigned length,
bool raw_decoder = false );
#endif #endif

View file

@ -293,7 +293,8 @@ HEADERS += folding.hh \
fulltextsearch.hh \ fulltextsearch.hh \
ftshelpers.hh \ ftshelpers.hh \
dictserver.hh \ dictserver.hh \
helpwindow.hh helpwindow.hh \
slob.hh
FORMS += groups.ui \ FORMS += groups.ui \
dictgroupwidget.ui \ dictgroupwidget.ui \
@ -311,6 +312,7 @@ FORMS += groups.ui \
dictheadwords.ui \ dictheadwords.ui \
authentication.ui \ authentication.ui \
fulltextsearch.ui fulltextsearch.ui
SOURCES += folding.cc \ SOURCES += folding.cc \
main.cc \ main.cc \
dictionary.cc \ dictionary.cc \
@ -414,7 +416,8 @@ SOURCES += folding.cc \
fulltextsearch.cc \ fulltextsearch.cc \
ftshelpers.cc \ ftshelpers.cc \
dictserver.cc \ dictserver.cc \
helpwindow.cc helpwindow.cc \
slob.cc
win32 { win32 {
FORMS += texttospeechsource.ui FORMS += texttospeechsource.ui

Binary file not shown.

Binary file not shown.

BIN
icons/icon32_slob.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -29,6 +29,7 @@
#include "mdx.hh" #include "mdx.hh"
#include "zim.hh" #include "zim.hh"
#include "dictserver.hh" #include "dictserver.hh"
#include "slob.hh"
#ifndef NO_EPWING_SUPPORT #ifndef NO_EPWING_SUPPORT
#include "epwing.hh" #include "epwing.hh"
@ -58,7 +59,7 @@ LoadDictionaries::LoadDictionaries( Config::Class const & cfg ):
<< "*.xdxf.dz" << "*.dct" << "*.aar" << "*.zips" << "*.xdxf.dz" << "*.dct" << "*.aar" << "*.zips"
<< "*.mdx" << "*.mdx"
#ifdef MAKE_ZIM_SUPPORT #ifdef MAKE_ZIM_SUPPORT
<< "*.zim" << "*.zimaa" << "*.zim" << "*.zimaa" << "*.slob"
#endif #endif
#ifndef NO_EPWING_SUPPORT #ifndef NO_EPWING_SUPPORT
<< "*catalogs" << "*catalogs"
@ -207,6 +208,13 @@ void LoadDictionaries::handlePath( Config::Path const & path )
dictionaries.insert( dictionaries.end(), zimDictionaries.begin(), dictionaries.insert( dictionaries.end(), zimDictionaries.begin(),
zimDictionaries.end() ); zimDictionaries.end() );
} }
{
vector< sptr< Dictionary::Class > > slobDictionaries =
Slob::makeDictionaries( allFiles, FsEncoding::encode( Config::getIndexDir() ), *this );
dictionaries.insert( dictionaries.end(), slobDictionaries.begin(),
slobDictionaries.end() );
}
#endif #endif
#ifndef NO_EPWING_SUPPORT #ifndef NO_EPWING_SUPPORT
{ {

View file

@ -294,12 +294,14 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
ui.allowDSL->setChecked( !p.fts.disabledTypes.contains( "DSL", Qt::CaseInsensitive ) ); ui.allowDSL->setChecked( !p.fts.disabledTypes.contains( "DSL", Qt::CaseInsensitive ) );
ui.allowMDict->setChecked( !p.fts.disabledTypes.contains( "MDICT", Qt::CaseInsensitive ) ); ui.allowMDict->setChecked( !p.fts.disabledTypes.contains( "MDICT", Qt::CaseInsensitive ) );
ui.allowSDict->setChecked( !p.fts.disabledTypes.contains( "SDICT", Qt::CaseInsensitive ) ); ui.allowSDict->setChecked( !p.fts.disabledTypes.contains( "SDICT", Qt::CaseInsensitive ) );
ui.allowSlob->setChecked( !p.fts.disabledTypes.contains( "SLOB", Qt::CaseInsensitive ) );
ui.allowStardict->setChecked( !p.fts.disabledTypes.contains( "STARDICT", Qt::CaseInsensitive ) ); ui.allowStardict->setChecked( !p.fts.disabledTypes.contains( "STARDICT", Qt::CaseInsensitive ) );
ui.allowXDXF->setChecked( !p.fts.disabledTypes.contains( "XDXF", Qt::CaseInsensitive ) ); ui.allowXDXF->setChecked( !p.fts.disabledTypes.contains( "XDXF", Qt::CaseInsensitive ) );
ui.allowZim->setChecked( !p.fts.disabledTypes.contains( "ZIM", Qt::CaseInsensitive ) ); ui.allowZim->setChecked( !p.fts.disabledTypes.contains( "ZIM", Qt::CaseInsensitive ) );
ui.allowEpwing->setChecked( !p.fts.disabledTypes.contains( "EPWING", Qt::CaseInsensitive ) ); ui.allowEpwing->setChecked( !p.fts.disabledTypes.contains( "EPWING", Qt::CaseInsensitive ) );
#ifndef MAKE_ZIM_SUPPORT #ifndef MAKE_ZIM_SUPPORT
ui.allowZim->hide(); ui.allowZim->hide();
ui.allowSlob->hide();
#endif #endif
#ifdef NO_EPWING_SUPPORT #ifdef NO_EPWING_SUPPORT
ui.allowEpwing->hide(); ui.allowEpwing->hide();
@ -441,6 +443,13 @@ Config::Preferences Preferences::getPreferences()
p.fts.disabledTypes += "SDICT"; p.fts.disabledTypes += "SDICT";
} }
if( !ui.allowSlob->isChecked() )
{
if( !p.fts.disabledTypes.isEmpty() )
p.fts.disabledTypes += ',';
p.fts.disabledTypes += "SLOB";
}
if( !ui.allowStardict->isChecked() ) if( !ui.allowStardict->isChecked() )
{ {
if( !p.fts.disabledTypes.isEmpty() ) if( !p.fts.disabledTypes.isEmpty() )

View file

@ -1240,13 +1240,20 @@ download page.</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="5" column="0">
<widget class="QCheckBox" name="allowSDict"> <widget class="QCheckBox" name="allowSDict">
<property name="text"> <property name="text">
<string notr="true">SDict</string> <string notr="true">SDict</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<widget class="QCheckBox" name="allowSlob">
<property name="text">
<string notr="true">Slob</string>
</property>
</widget>
</item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QCheckBox" name="allowStardict"> <widget class="QCheckBox" name="allowStardict">
<property name="text"> <property name="text">
@ -1268,7 +1275,7 @@ download page.</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="0" colspan="2"> <item row="6" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_14"> <layout class="QHBoxLayout" name="horizontalLayout_14">
<item> <item>
<widget class="QLabel" name="label_14"> <widget class="QLabel" name="label_14">

View file

@ -78,5 +78,6 @@
<file>icons/playsound_full.png</file> <file>icons/playsound_full.png</file>
<file>icons/icon32_zim.png</file> <file>icons/icon32_zim.png</file>
<file>icons/icon32_epwing.png</file> <file>icons/icon32_epwing.png</file>
<file>icons/icon32_slob.png</file>
</qresource> </qresource>
</RCC> </RCC>

1312
slob.cc Normal file

File diff suppressed because it is too large Load diff

24
slob.hh Normal file
View file

@ -0,0 +1,24 @@
#ifndef __SLOB_HH_INCLUDED__
#define __SLOB_HH_INCLUDED__
#ifdef MAKE_ZIM_SUPPORT
#include "dictionary.hh"
/// Support for the Slob dictionaries.
namespace Slob {
using std::vector;
using std::string;
vector< sptr< Dictionary::Class > > makeDictionaries(
vector< string > const & fileNames,
string const & indicesDir,
Dictionary::Initializing & )
throw( std::exception );
}
#endif
#endif // __SLOB_HH_INCLUDED__