Skip to content

Commit e5c2cb2

Browse files
committed
Ensure encoding for internal files, and refresh index tab when changing encoding.
1 parent ab3b580 commit e5c2cb2

5 files changed

Lines changed: 14 additions & 10 deletions

File tree

lib/libebook/ebook_chm.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ void EBook_CHM::close()
9292

9393
QString EBook_CHM::title() const
9494
{
95-
return encodeWithCurrentCodec( m_title );
95+
return encodeInternalWithCurrentCodec( m_title );
9696
}
9797

9898
QUrl EBook_CHM::homeUrl() const
9999
{
100-
return pathToUrl( encodeWithCurrentCodec( m_home ) );
100+
return pathToUrl( encodeInternalWithCurrentCodec( m_home ) );
101101
}
102102

103103
bool EBook_CHM::hasFeature( EBook::Feature code ) const
@@ -125,7 +125,7 @@ bool EBook_CHM::getTableOfContents( QList<EBookTocEntry>& toc ) const
125125
// Parse the plain text TOC
126126
QList< ParsedEntry > parsed;
127127

128-
if ( !parseFileAndFillArray( encodeWithCurrentCodec( m_topicsFile ), parsed, false ) )
128+
if ( !parseFileAndFillArray( encodeInternalWithCurrentCodec( m_topicsFile ), parsed, false ) )
129129
return false;
130130

131131
// Find out the root offset, and reduce the indent level to it
@@ -159,7 +159,7 @@ bool EBook_CHM::getIndex( QList<EBookIndexEntry>& index ) const
159159
// Parse the plain text index
160160
QList< ParsedEntry > parsed;
161161

162-
if ( !parseFileAndFillArray( encodeWithCurrentCodec( m_indexFile ), parsed, true ) )
162+
if ( !parseFileAndFillArray( encodeInternalWithCurrentCodec( m_indexFile ), parsed, true ) )
163163
return false;
164164

165165
// Find out the root offset, and reduce the indent level to it
@@ -950,11 +950,11 @@ void EBook_CHM::fillTopicsUrlMap()
950950
QUrl url = pathToUrl( encodeInternalWithCurrentCodec( ( const char* ) urlstr.data() + off_url ) );
951951

952952
/*
953-
* Titles are extracted from the <title> field from html pages when compling the chm file, try with text codec.
953+
* Titles are extracted from the <title> field from html pages when compling the chm file.
954954
* These values are used in index search and index with multiple topics selection currently.
955955
*/
956956
if ( off_title < ( unsigned int )strings.size() )
957-
m_url2topics[url] = encodeWithCurrentCodec( ( const char* ) strings.data() + off_title );
957+
m_url2topics[url] = encodeInternalWithCurrentCodec( ( const char* ) strings.data() + off_title );
958958
else
959959
m_url2topics[url] = "Untitled";
960960
}

lib/libebook/ebook_chm.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ class EBook_CHM : public EBook
206206
iconid = EBookTocEntry::IMAGE_AUTO;
207207
indent = 0;
208208
}
209+
209210
void clear()
210211
{
211212
name.clear();
@@ -245,9 +246,9 @@ class EBook_CHM : public EBook
245246

246247
//! Encode the string from internal files with the currently selected text codec, if possible.
247248
//! Or return as-is, if not.
248-
inline QString encodeInternalWithCurrentCodec( const QString& str ) const
249+
inline QString encodeInternalWithCurrentCodec( const QByteArray& str ) const
249250
{
250-
return ( m_textCodecForSpecialFiles ? m_textCodecForSpecialFiles->toUnicode( qPrintable( str ) ) : str );
251+
return ( m_textCodecForSpecialFiles ? m_textCodecForSpecialFiles->toUnicode( str.constData() ) : str );
251252
}
252253

253254
//! Encode the string from internal files with the currently selected text codec, if possible.

src/mainwindow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,8 @@ void MainWindow::setTextEncoding( const QString& encoding )
543543
}
544544
}
545545

546+
m_navPanel->refresh();
547+
546548
// Because updateView() will call view->invalidate(), which clears the view->url(),
547549
// we have to make a copy of it.
548550
QUrl url = currentBrowser()->url();

src/navigationpanel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ void NavigationPanel::getSettings( Settings* settings )
116116

117117
void NavigationPanel::refresh()
118118
{
119+
if ( m_indexTab )
120+
m_indexTab->refillIndex();
119121
if ( m_contentsTab )
120122
m_contentsTab->refillTableOfContents();
121123
}

src/tab_index.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class TabIndex : public QWidget, public Ui::TabIndex
3737
public:
3838
TabIndex( QWidget* parent = 0 );
3939

40+
void refillIndex();
4041
void invalidate();
4142
void search( const QString& index );
4243
void focus();
@@ -50,8 +51,6 @@ class TabIndex : public QWidget, public Ui::TabIndex
5051
private:
5152
void showEvent( QShowEvent* );
5253

53-
void refillIndex();
54-
5554
QMenu* m_contextMenu;
5655
QTreeWidgetItem* m_lastSelectedItem;
5756
bool m_indexListFilled;

0 commit comments

Comments
 (0)