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 10, 2024
2 parents af72c97 + 752b880 commit d017f80
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 17 deletions.
16 changes: 6 additions & 10 deletions src/article_maker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,28 +282,24 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeDefinitionFor( QString const &
bool ignoreDiacritics ) const
{
if ( !dictIDs.isEmpty() ) {
QStringList ids = dictIDs;
std::vector< sptr< Dictionary::Class > > ftsDicts;
std::vector< sptr< Dictionary::Class > > dicts;

// Find dictionaries by ID's
for ( unsigned x = 0; x < dictionaries.size(); x++ ) {
for ( QStringList::Iterator it = ids.begin(); it != ids.end(); ++it ) {
if ( *it == QString::fromStdString( dictionaries[ x ]->getId() ) ) {
ftsDicts.push_back( dictionaries[ x ] );
ids.erase( it );
for ( const auto & dictId : dictIDs ) {
for ( unsigned x = 0; x < dictionaries.size(); x++ ) {
if ( dictId == QString::fromStdString( dictionaries[ x ]->getId() ) ) {
dicts.push_back( dictionaries[ x ] );
break;
}
}
if ( ids.isEmpty() )
break;
}

string header = makeHtmlHeader( word, QString(), true );

return std::make_shared< ArticleRequest >( word,
Instances::Group{ groupId, "" },
contexts,
ftsDicts,
dicts,
header,
-1,
true );
Expand Down
17 changes: 13 additions & 4 deletions src/dictzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,10 @@ static enum DZ_ERRORS dict_read_header( const char * filename, dictData * header
if ( pt == buffer + sizeof( buffer ) ) {
err_fatal( __func__, "too long FNAME field in dzip file \"%s\"\n", filename );
fclose( str );
if ( header->chunks )
if ( header->chunks ) {
free( header->chunks );
header->chunks = NULL;
}
return DZ_ERR_INVALID_FORMAT;
}
}
Expand All @@ -393,8 +395,10 @@ static enum DZ_ERRORS dict_read_header( const char * filename, dictData * header
if ( pt == buffer + sizeof( buffer ) ) {
err_fatal( __func__, "too long COMMENT field in dzip file \"%s\"\n", filename );
fclose( str );
if ( header->chunks )
if ( header->chunks ) {
free( header->chunks );
header->chunks = NULL;
}
return DZ_ERR_INVALID_FORMAT;
}
}
Expand All @@ -416,8 +420,10 @@ static enum DZ_ERRORS dict_read_header( const char * filename, dictData * header
if ( ftell( str ) != header->headerLength + 1 ) {
err_internal( __func__, "File position (%lu) != header length + 1 (%d)\n", ftell( str ), header->headerLength + 1 );
fclose( str );
if ( header->chunks )
if ( header->chunks ) {
free( header->chunks );
header->chunks = NULL;
}
return DZ_ERR_INVALID_FORMAT;
}

Expand All @@ -435,8 +441,11 @@ static enum DZ_ERRORS dict_read_header( const char * filename, dictData * header
/* Compute offsets */
header->offsets = xmalloc( sizeof( header->offsets[ 0 ] ) * header->chunkCount );
if ( header->offsets == 0 ) {
if ( header->chunks )
if ( header->chunks ) {
free( header->chunks );
header->chunks = NULL;
}
fclose( str );
return DZ_ERR_NOMEMORY;
}

Expand Down
14 changes: 11 additions & 3 deletions src/ui/articleview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2111,10 +2111,18 @@ void ArticleView::highlightFTSResults()

webview->page()->runJavaScript( script );
auto parts = regString.split( " ", Qt::SkipEmptyParts );
if ( !parts.isEmpty() ) {
firstAvailableText = parts[ 0 ];
ftsSearchPanel->show();
if ( parts.isEmpty() ) {
return;
}

//hold the longest word
for ( auto & p : parts ) {
if ( p.size() > firstAvailableText.size() ) {
firstAvailableText = p;
}
}

ftsSearchPanel->show();
}

void ArticleView::setActiveDictIds( const ActiveDictIds & ad )
Expand Down
17 changes: 17 additions & 0 deletions website/docs/topic_move_index_folder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
How to move the default index folder to other places?


## Windows

!!! note
the [`mklink`](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/mklink#related-links) is built-in tool in Windows.


1. Open `cmd` as administrator
2. copy the index folder to another place,take `D:\gd-ng\index_new` for example.
3. Run `mklink /D "C:\Users\USERNAME\Application Data\GoldenDict\index" "D:\gd-ng\index_new"`
4. Run GoldenDict

## Linux

use `ln` to create a link.
1 change: 1 addition & 0 deletions website/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ nav:
- Wayland: topic_wayland.md
- Debug dictionary JS: howto/how to debug dictionary js.md
- Flatpak/FlatHub: topic_flatpak.md
- Move index folder: topic_move_index_folder.md
- Related tools:
- Anki Integration: topic_anki.md
- OCR Integration: howto/ocr.md
Expand Down

0 comments on commit d017f80

Please sign in to comment.