From 0bb4df86c9058336e4a49f2f66d00757db11c9aa Mon Sep 17 00:00:00 2001 From: Binhao Qian Date: Tue, 20 Jan 2026 20:55:22 +0800 Subject: [PATCH] Fix epub files with an empty title in metadata. --- lib/libebook/ebook_epub.cpp | 10 +++++++--- src/mainwindow.cpp | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/libebook/ebook_epub.cpp b/lib/libebook/ebook_epub.cpp index c9077404..40512c87 100644 --- a/lib/libebook/ebook_epub.cpp +++ b/lib/libebook/ebook_epub.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -224,8 +225,8 @@ bool EBook_EPUB::parseBookinfo() if ( !parseXML( container_parser.contentPath, &content_parser ) ) return false; - // At least title and the TOC must be present - if ( !content_parser.metadata.contains( "title" ) || content_parser.tocname.isEmpty() ) + // At least the TOC must be present + if ( content_parser.tocname.isEmpty() ) return false; // All the files, including TOC, are relative to the container_parser.contentPath @@ -242,7 +243,10 @@ bool EBook_EPUB::parseBookinfo() return false; // Get the data - m_title = content_parser.metadata[ "title" ]; + if ( content_parser.metadata.contains( "title" ) ) + m_title = content_parser.metadata[ "title" ]; + else + m_title = QFileInfo( m_epubFile ).fileName(); // Move the manifest entries into the list Q_FOREACH ( QString f, content_parser.manifest.values() ) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index db3e39f8..1fd8a8bc 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -382,8 +382,8 @@ bool MainWindow::loadFile( const QString& loadFileName, bool call_open_page ) else { QMessageBox mbox( - i18n( "%1 - failed to load the chm file" ) . arg( QCoreApplication::applicationName() ), - i18n( "Unable to load the chm file %1" ) . arg( fileName ), + i18n( "%1 - failed to load file" ) . arg( QCoreApplication::applicationName() ), + i18n( "Unable to load file %1" ) . arg( fileName ), QMessageBox::Critical, QMessageBox::Ok, Qt::NoButton,