Skip to content

Commit ab3b580

Browse files
committed
Fix one index with multiple topic urls.
1 parent 49f6f9d commit ab3b580

4 files changed

Lines changed: 55 additions & 37 deletions

File tree

lib/libebook/ebook_chm.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
}

lib/libebook/ebook_chm.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,19 @@ class EBook_CHM : public EBook
201201
class ParsedEntry
202202
{
203203
public:
204-
ParsedEntry();
204+
ParsedEntry()
205+
{
206+
iconid = EBookTocEntry::IMAGE_AUTO;
207+
indent = 0;
208+
}
209+
void clear()
210+
{
211+
name.clear();
212+
urls.clear();
213+
iconid = EBookTocEntry::IMAGE_AUTO;
214+
indent = 0;
215+
seealso.clear();
216+
}
205217

206218
QString name;
207219
QList<QUrl> urls;

src/dialog_topicselector.ui

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
<ui version="4.0" >
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
23
<class>DialogTopicSelector</class>
3-
<widget class="QDialog" name="DialogTopicSelector" >
4-
<property name="geometry" >
4+
<widget class="QDialog" name="DialogTopicSelector">
5+
<property name="geometry">
56
<rect>
67
<x>0</x>
78
<y>0</y>
8-
<width>218</width>
9+
<width>360</width>
910
<height>258</height>
1011
</rect>
1112
</property>
12-
<property name="windowTitle" >
13+
<property name="windowTitle">
1314
<string>Multiple topics</string>
1415
</property>
15-
<layout class="QVBoxLayout" >
16-
<property name="margin" >
16+
<layout class="QVBoxLayout">
17+
<property name="margin">
1718
<number>9</number>
1819
</property>
19-
<property name="spacing" >
20+
<property name="spacing">
2021
<number>6</number>
2122
</property>
2223
<item>
23-
<widget class="QLabel" name="label" >
24-
<property name="text" >
24+
<widget class="QLabel" name="label">
25+
<property name="text">
2526
<string>Please select the topic to open:</string>
2627
</property>
27-
<property name="alignment" >
28+
<property name="alignment">
2829
<set>Qt::AlignCenter</set>
2930
</property>
3031
</widget>
@@ -33,11 +34,11 @@
3334
<widget class="QListWidget" name="list" />
3435
</item>
3536
<item>
36-
<widget class="QDialogButtonBox" name="buttonBox" >
37-
<property name="orientation" >
37+
<widget class="QDialogButtonBox" name="buttonBox">
38+
<property name="orientation">
3839
<enum>Qt::Horizontal</enum>
3940
</property>
40-
<property name="standardButtons" >
41+
<property name="standardButtons">
4142
<set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
4243
</property>
4344
</widget>
@@ -53,11 +54,11 @@
5354
<receiver>DialogTopicSelector</receiver>
5455
<slot>accept()</slot>
5556
<hints>
56-
<hint type="sourcelabel" >
57+
<hint type="sourcelabel">
5758
<x>66</x>
5859
<y>330</y>
5960
</hint>
60-
<hint type="destinationlabel" >
61+
<hint type="destinationlabel">
6162
<x>-3</x>
6263
<y>275</y>
6364
</hint>
@@ -69,11 +70,11 @@
6970
<receiver>DialogTopicSelector</receiver>
7071
<slot>reject()</slot>
7172
<hints>
72-
<hint type="sourcelabel" >
73+
<hint type="sourcelabel">
7374
<x>151</x>
7475
<y>327</y>
7576
</hint>
76-
<hint type="destinationlabel" >
77+
<hint type="destinationlabel">
7778
<x>277</x>
7879
<y>293</y>
7980
</hint>

src/tab_index.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void TabIndex::onTextChanged( const QString& newvalue )
9191
{
9292
m_lastSelectedItem = items[0];
9393
tree->setCurrentItem( m_lastSelectedItem );
94-
tree->scrollToItem( m_lastSelectedItem );
94+
tree->scrollToItem( m_lastSelectedItem, QAbstractItemView::PositionAtTop );
9595
}
9696
else
9797
m_lastSelectedItem = 0;

0 commit comments

Comments
 (0)