@@ -410,12 +410,11 @@ bool EBook_CHM::parseFileAndFillArray( const QString& file, QList< ParsedEntry >
410410 }
411411 */
412412
413- EBookTocEntry::Icon defaultimagenum = EBookTocEntry::IMAGE_AUTO ;
414413 int pos = 0 , indent = 0 , root_indent_offset = 0 ;
415414 bool in_object = false , root_indent_offset_set = false ;
416415
417416 ParsedEntry entry;
418- entry. iconid = defaultimagenum ;
417+ QMap< QString, ParsedEntry > indexNameEntryMap ;
419418
420419 // Split the HHC file by HTML tags
421420 int stringlen = src.length ();
@@ -488,17 +487,22 @@ bool EBook_CHM::parseFileAndFillArray( const QString& file, QList< ParsedEntry >
488487
489488 // Trim the entry name
490489 entry.name = entry.name .trimmed ();
491-
492490 int real_indent = indent - root_indent_offset;
493-
494491 entry.indent = real_indent;
495- data.push_back ( entry );
492+
493+ if ( !asIndex )
494+ data.push_back ( entry );
495+ else
496+ {
497+ QMap< QString, ParsedEntry >::iterator it = indexNameEntryMap.find ( entry.name );
498+ if ( it == indexNameEntryMap.end () )
499+ indexNameEntryMap[ entry.name ] = entry;
500+ else
501+ it.value ().urls .append ( entry.urls );
502+ }
496503 }
497504
498- entry.name = QString ();
499- entry.urls .clear ();
500- entry.iconid = defaultimagenum;
501- entry.seealso .clear ();
505+ entry.clear ();
502506 in_object = false ;
503507 }
504508 else if ( tagword == " param" && in_object )
@@ -536,7 +540,7 @@ bool EBook_CHM::parseFileAndFillArray( const QString& file, QList< ParsedEntry >
536540 if ( pname == " name" || pname == " keyword" )
537541 {
538542 // Some help files contain duplicate names, where the second name is empty. Work it around by keeping the first one
539- if ( !pvalue.isEmpty () )
543+ if ( !pvalue.isEmpty () && entry. name . isEmpty () )
540544 entry.name = pvalue;
541545 }
542546 else if ( pname == " merge" )
@@ -602,6 +606,9 @@ bool EBook_CHM::parseFileAndFillArray( const QString& file, QList< ParsedEntry >
602606 pos = i;
603607 }
604608
609+ if ( asIndex )
610+ data = indexNameEntryMap.values ();
611+
605612 // Dump our array
606613// for ( int i = 0; i < data.size(); i++ )
607614// qDebug() << data[i].indent << data[i].name << data[i].urls;
@@ -940,8 +947,12 @@ void EBook_CHM::fillTopicsUrlMap()
940947 unsigned int off_url = get_int32_le ( ( unsigned int * )( topics.data () + i + 8 ) );
941948 off_url = get_int32_le ( ( unsigned int * )( urltbl.data () + off_url + 8 ) ) + 8 ;
942949
943- QUrl url = pathToUrl ( ( const char * ) urlstr.data () + off_url );
950+ QUrl url = pathToUrl ( encodeInternalWithCurrentCodec ( ( const char * ) urlstr.data () + off_url ) );
944951
952+ /*
953+ * Titles are extracted from the <title> field from html pages when compling the chm file, try with text codec.
954+ * These values are used in index search and index with multiple topics selection currently.
955+ */
945956 if ( off_title < ( unsigned int )strings.size () )
946957 m_url2topics[url] = encodeWithCurrentCodec ( ( const char * ) strings.data () + off_title );
947958 else
@@ -1137,9 +1148,3 @@ QString EBook_CHM::urlToPath( const QUrl& link ) const
11371148
11381149 return " " ;
11391150}
1140-
1141- EBook_CHM::ParsedEntry::ParsedEntry ()
1142- {
1143- iconid = 0 ;
1144- indent = 0 ;
1145- }
0 commit comments