@@ -227,35 +227,22 @@ bool EBook_EPUB::parseBookinfo()
227227 return false ;
228228
229229 // Parse the content.opf
230- HelperXmlHandler_EpubContent content_parser;
230+ // TOC is relative to the container_parser.contentPath
231+ QString parentPath = getParentPath ( container_parser.contentPath );
232+ HelperXmlHandler_EpubContent content_parser ( parentPath );
231233
232234 if ( !parseXML ( container_parser.contentPath , &content_parser ) )
233235 return false ;
234236
235237 // At least the TOC must be present
236- if ( content_parser.tocname .isEmpty () )
238+ if ( content_parser.tocPath .isEmpty () )
237239 return false ;
238240
239- // TOC is relative to the container_parser.contentPath
240- QString contentRoot;
241- int sep = container_parser.contentPath .lastIndexOf ( ' /' );
242-
243- if ( sep != -1 )
244- contentRoot = container_parser.contentPath .left ( sep + 1 ); // Keep the trailing slash
245-
246- QString tocPath = combinePath ( contentRoot, content_parser.tocname );
247-
248- // All pages are relative to the container_parser.tocname
249- QString tocRoot;
250- sep = tocPath.lastIndexOf ( ' /' );
251-
252- if ( sep != -1 )
253- tocRoot = tocPath.left ( sep + 1 ); // Keep the trailing slash
254-
255241 // Parse the TOC
256- HelperXmlHandler_EpubTOC toc_parser ( this , tocRoot );
242+ parentPath = getParentPath ( content_parser.tocPath );
243+ HelperXmlHandler_EpubTOC toc_parser ( this , parentPath );
257244
258- if ( !parseXML ( tocPath, &toc_parser ) )
245+ if ( !parseXML ( content_parser. tocPath , &toc_parser ) )
259246 return false ;
260247
261248 // Get the data
@@ -266,18 +253,12 @@ bool EBook_EPUB::parseBookinfo()
266253
267254 // Move the manifest entries into the list
268255 Q_FOREACH ( QString f, content_parser.manifest .values () )
269- {
270- QString combined = combinePath ( contentRoot, f );
271- m_ebookManifest.push_back ( pathToUrl ( combined ) );
272- }
256+ m_ebookManifest.push_back ( pathToUrl ( f ) );
273257
274258 for ( const auto & si : qAsConst ( content_parser.spine ) )
275259 {
276260 if ( content_parser.manifest .contains ( si ) )
277- {
278- QString combined = combinePath ( contentRoot, content_parser.manifest [ si ] );
279- m_spinePath.push_back ( combined );
280- }
261+ m_spinePath.push_back ( content_parser.manifest [ si ] );
281262 }
282263
283264 // Copy the manifest information and fill up the other maps if we have it
@@ -429,8 +410,18 @@ bool EBook_EPUB::getFileAsBinary( QByteArray& data, const QString& path ) const
429410 return true ;
430411}
431412
432- QString EBook_EPUB::combinePath ( const QString& baseDir , const QString& path )
413+ QString EBook_EPUB::combinePath ( const QString& baseDirPath , const QString& path )
433414{
434- QString combined = QDir ( baseDir ).filePath ( path );
415+ QString combined = QDir ( baseDirPath ).filePath ( path );
435416 return QDir::cleanPath ( combined );
436417}
418+
419+ QString EBook_EPUB::getParentPath ( const QString& path )
420+ {
421+ int sep = path.lastIndexOf ( ' /' );
422+
423+ if ( sep != -1 )
424+ return path.left ( sep + 1 ); // Keep the trailing slash
425+
426+ return " " ;
427+ }
0 commit comments