Skip to content

Commit

Permalink
Merge branch 'staged' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed Aug 22, 2024
2 parents d017f80 + 3ca7c39 commit a64dadd
Show file tree
Hide file tree
Showing 19 changed files with 271 additions and 54 deletions.
32 changes: 13 additions & 19 deletions src/decompress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ QByteArray zlibDecompress( const char * bufptr, unsigned length )
memset( &zs, 0, sizeof( zs ) );
zs.next_in = (Bytef *)bufptr;
zs.avail_in = length;
while ( 1 ) {
res = inflateInit( &zs );
if ( res != Z_OK )
break;
res = inflateInit( &zs );

if ( res == Z_OK ) {
while ( res != Z_STREAM_END ) {
zs.next_out = (Bytef *)buf;
zs.avail_out = CHUNK_SIZE;
Expand All @@ -26,8 +25,8 @@ QByteArray zlibDecompress( const char * bufptr, unsigned length )
if ( res != Z_OK && res != Z_STREAM_END )
break;
}
break;
}

inflateEnd( &zs );
if ( res != Z_STREAM_END )
str.clear();
Expand All @@ -50,10 +49,8 @@ string decompressBzip2( const char * bufptr, unsigned length )
zs.next_in = (char *)bufptr;
zs.avail_in = length;
zs.total_in_lo32 = length;
while ( 1 ) {
res = BZ2_bzDecompressInit( &zs, 0, 0 );
if ( res != BZ_OK )
break;
res = BZ2_bzDecompressInit( &zs, 0, 0 );
if ( res == BZ_OK ) {
while ( res != BZ_STREAM_END ) {
zs.next_out = buf;
zs.avail_out = CHUNK_SIZE;
Expand All @@ -63,7 +60,6 @@ string decompressBzip2( const char * bufptr, unsigned length )
if ( res != BZ_OK && res != BZ_STREAM_END )
break;
}
break;
}
BZ2_bzDecompressEnd( &zs );
if ( res != BZ_STREAM_END )
Expand Down Expand Up @@ -92,14 +88,13 @@ string decompressLzma2( const char * bufptr, unsigned length, bool raw_decoder )
filters[ 1 ].id = LZMA_VLI_UNKNOWN;
}

while ( 1 ) {
if ( raw_decoder )
res = lzma_raw_decoder( &strm, filters );
else
res = lzma_stream_decoder( &strm, UINT64_MAX, 0 );

if ( res != LZMA_OK )
break;
if ( raw_decoder )
res = lzma_raw_decoder( &strm, filters );
else
res = lzma_stream_decoder( &strm, UINT64_MAX, 0 );

if ( res == LZMA_OK ) {

while ( res != LZMA_STREAM_END ) {
strm.next_out = reinterpret_cast< uint8_t * >( buf );
Expand All @@ -112,8 +107,7 @@ string decompressLzma2( const char * bufptr, unsigned length, bool raw_decoder )
lzma_end( &strm );
if ( res != LZMA_STREAM_END )
str.clear();

break;
}

return str;
}
9 changes: 7 additions & 2 deletions src/dict/aard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,13 @@ class AardDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "AARD", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( metadata_enable_fts.has_value() ) {
can_FTS = fts.enabled && metadata_enable_fts.value();
}
else {
can_FTS = fts.enabled && !fts.disabledTypes.contains( "AARD", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}
}

protected:
Expand Down
8 changes: 6 additions & 2 deletions src/dict/bgl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,12 @@ class BglDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "BGL", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( metadata_enable_fts.has_value() ) {
can_FTS = fts.enabled && metadata_enable_fts.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "BGL", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

protected:
Expand Down
8 changes: 6 additions & 2 deletions src/dict/dictdfiles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ class DictdDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "DICTD", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( metadata_enable_fts.has_value() ) {
can_FTS = fts.enabled && metadata_enable_fts.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "DICTD", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}
};

Expand Down
5 changes: 2 additions & 3 deletions src/dict/dictionary.hh
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,7 @@ protected:
QAtomicInt FTS_index_completed;
bool synonymSearchEnabled;
string dictionaryName;
//default to true;
bool enable_FTS = true;
std::optional< bool > metadata_enable_fts = std::nullopt;

// Load user icon if it exist
// By default set icon to empty
Expand Down Expand Up @@ -376,7 +375,7 @@ public:

void setFtsEnable( bool _enable_FTS )
{
enable_FTS = _enable_FTS;
metadata_enable_fts = _enable_FTS;
}

/// Returns all the available properties, like the author's name, copyright,
Expand Down
9 changes: 6 additions & 3 deletions src/dict/dsl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,12 @@ class DslDictionary: public BtreeIndexing::BtreeDictionary
{
if ( ensureInitDone().size() )
return;

can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "DSL", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( metadata_enable_fts.has_value() ) {
can_FTS = fts.enabled && metadata_enable_fts.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "DSL", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

uint32_t getFtsIndexVersion() override
Expand Down
9 changes: 6 additions & 3 deletions src/dict/epwing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,12 @@ class EpwingDictionary: public BtreeIndexing::BtreeDictionary
{
if ( ensureInitDone().size() )
return;

can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "EPWING", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( metadata_enable_fts.has_value() ) {
can_FTS = fts.enabled && metadata_enable_fts.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "EPWING", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

static int japaneseWriting( gd::wchar ch );
Expand Down
8 changes: 6 additions & 2 deletions src/dict/gls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,12 @@ class GlsDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "GLS", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( metadata_enable_fts.has_value() ) {
can_FTS = fts.enabled && metadata_enable_fts.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "GLS", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

protected:
Expand Down
9 changes: 6 additions & 3 deletions src/dict/mdx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,12 @@ class MdxDictionary: public BtreeIndexing::BtreeDictionary
{
if ( !ensureInitDone().empty() )
return;

can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "MDICT", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( metadata_enable_fts.has_value() ) {
can_FTS = fts.enabled && metadata_enable_fts.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "MDICT", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

QString getCachedFileName( QString name );
Expand Down
8 changes: 6 additions & 2 deletions src/dict/sdict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,12 @@ class SdictDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "SDICT", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( metadata_enable_fts.has_value() ) {
can_FTS = fts.enabled && metadata_enable_fts.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "SDICT", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

protected:
Expand Down
8 changes: 6 additions & 2 deletions src/dict/slob.cc
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,12 @@ class SlobDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "SLOB", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( metadata_enable_fts.has_value() ) {
can_FTS = fts.enabled && metadata_enable_fts.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "SLOB", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

uint32_t getFtsIndexVersion() override
Expand Down
8 changes: 6 additions & 2 deletions src/dict/stardict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,12 @@ class StardictDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "STARDICT", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( metadata_enable_fts.has_value() ) {
can_FTS = fts.enabled && metadata_enable_fts.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "STARDICT", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

protected:
Expand Down
8 changes: 6 additions & 2 deletions src/dict/xdxf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,12 @@ class XdxfDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "XDXF", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( metadata_enable_fts.has_value() ) {
can_FTS = fts.enabled && metadata_enable_fts.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "XDXF", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

uint32_t getFtsIndexVersion() override
Expand Down
8 changes: 6 additions & 2 deletions src/dict/zim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,12 @@ class ZimDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "ZIM", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( metadata_enable_fts.has_value() ) {
can_FTS = fts.enabled && metadata_enable_fts.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "ZIM", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

protected:
Expand Down
3 changes: 1 addition & 2 deletions src/fulltextsearch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,9 @@ FullTextSearchDialog::FullTextSearchDialog( QWidget * parent,
&FullTextSearchDialog::setNewIndexingName );

ui.searchMode->addItem( tr( "Default" ), WholeWords );
ui.searchMode->addItem( tr( "Plain text" ), PlainText );
ui.searchMode->addItem( tr( "Wildcards" ), Wildcards );

ui.searchLine->setToolTip( tr( "support xapian search syntax,such as AND OR +/- etc" ) );
ui.searchLine->setToolTip( tr( "Support xapian search syntax, such as AND OR +/- etc." ) );

ui.searchMode->setCurrentIndex( cfg.preferences.fts.searchMode );

Expand Down
7 changes: 7 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#if defined( Q_OS_UNIX )
#include <clocale>
#include "unix/ksignalhandler.hh"
#endif

#ifdef Q_OS_WIN32
Expand Down Expand Up @@ -590,6 +591,12 @@ int main( int argc, char ** argv )
if ( gdcl.needTranslateWord() )
m.wordReceived( gdcl.wordToTranslate() );

#ifdef Q_OS_UNIX
// handle Unix's shutdown signals for graceful exit
KSignalHandler::self()->watchSignal( SIGINT );
KSignalHandler::self()->watchSignal( SIGTERM );
QObject::connect( KSignalHandler::self(), &KSignalHandler::signalReceived, &m, &MainWindow::quitApp );
#endif
int r = app.exec();

app.removeDataCommiter( m );
Expand Down
11 changes: 8 additions & 3 deletions src/ui/articleview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,8 @@ QString ArticleView::getTitle()

QString ArticleView::getWord() const
{
return currentWord;
return webview->history()->currentItem().title();
// return currentWord;
}

void ArticleView::print( QPrinter * printer ) const
Expand Down Expand Up @@ -2004,12 +2005,16 @@ void ArticleView::doubleClicked( QPoint pos )
else {
QUrl const & ref = webview->url();

auto groupId = getGroup( ref );
if ( groupId == 0 || groupId == Instances::Group::HelpGroupId ) {
groupId = currentGroupId;
}
if ( Utils::Url::hasQueryItem( ref, "dictionaries" ) ) {
QStringList dictsList = Utils::Url::queryItemValue( ref, "dictionaries" ).split( ",", Qt::SkipEmptyParts );
showDefinition( selectedText, dictsList, getGroup( ref ), false );
showDefinition( selectedText, dictsList, groupId, false );
}
else
showDefinition( selectedText, getGroup( ref ), getCurrentArticle() );
showDefinition( selectedText, groupId, getCurrentArticle() );
}
}
}
Expand Down
Loading

0 comments on commit a64dadd

Please sign in to comment.