Upgrade to Qt 6.10.3, refactor AppState for LibraryModel integration, add ChunkMeasurer tests, and update CI/docker configurations.

This commit is contained in:
Agel committed 2026-04-03 13:55:28 +02:00
1 parent 0303107fa2
commit a31b20534a
53 files changed
+2095 -880

No files matched your search

+82 -3
View File
@@ -31,6 +31,7 @@ bool EpubReader::open(const QString &filePath)
m_author.clear();
m_error.clear();
m_opfDir.clear();
m_coverImagePath.clear();
m_spineHrefs.clear();
m_spineRawContent.clear();
m_toc.clear();
@@ -40,7 +41,6 @@ bool EpubReader::open(const QString &filePath)
m_error = QStringLiteral("Cannot open as ZIP archive: ") + filePath;
return false;
}
// Ensure the handle is closed on all exit paths
auto guard = [&](void *) { unzClose(zf); };
std::unique_ptr<void, decltype(guard)> closeGuard(zf, guard);
@@ -85,7 +85,7 @@ bool EpubReader::open(const QString &filePath)
if (!ncxData.isEmpty())
parseNcx(ncxData);
}
m_filePath = filePath;
return true;
}
@@ -116,6 +116,7 @@ bool EpubReader::parseOpf(const QByteArray &data, QString &ncxHref)
QXmlStreamReader xml(data);
QHash<QString, QString> manifest; // id -> relative href
QString ncxId;
QString coverId; // ID of the cover image item
static const QLatin1String kDcNs("http://purl.org/dc/elements/1.1/");
@@ -133,11 +134,25 @@ bool EpubReader::parseOpf(const QByteArray &data, QString &ncxHref)
} else if (name == QLatin1String("creator") && ns == kDcNs) {
if (m_author.isEmpty())
m_author = xml.readElementText().trimmed();
} else if (name == QLatin1String("meta")) {
// Check for cover image metadata
const QString metaName = xml.attributes().value(QLatin1String("name")).toString();
const QString metaContent = xml.attributes().value(QLatin1String("content")).toString();
if (metaName == QLatin1String("cover") && !metaContent.isEmpty()) {
coverId = metaContent;
}
} else if (name == QLatin1String("item")) {
const QString id = xml.attributes().value(QLatin1String("id")).toString();
const QString href = xml.attributes().value(QLatin1String("href")).toString();
const QString properties = xml.attributes().value(QLatin1String("properties")).toString();
if (!id.isEmpty() && !href.isEmpty())
manifest.insert(id, href);
// Check if this item is the cover image
if (properties.contains(QLatin1String("cover-image"))) {
coverId = id;
}
} else if (name == QLatin1String("spine")) {
ncxId = xml.attributes().value(QLatin1String("toc")).toString();
} else if (name == QLatin1String("itemref")) {
@@ -147,6 +162,11 @@ bool EpubReader::parseOpf(const QByteArray &data, QString &ncxHref)
}
}
// Resolve cover image path if we found a cover ID
if (!coverId.isEmpty() && manifest.contains(coverId)) {
m_coverImagePath = m_opfDir + manifest.value(coverId);
}
if (!ncxId.isEmpty() && manifest.contains(ncxId))
ncxHref = m_opfDir + manifest.value(ncxId);
@@ -256,7 +276,8 @@ QStringList EpubReader::chunkXhtml(const QByteArray &data, const QString &xhtmlH
continue;
src = QUrl::fromPercentEncoding(src.toUtf8());
const QString resolved = QDir::cleanPath(xhtmlDir + src);
img.setAttribute(QStringLiteral("src"), QStringLiteral("image://epub/") + resolved);
img.setAttribute(QStringLiteral("src"),
QStringLiteral("image://epub/") + resolved);
}
// Find <body> element (may have namespace prefix in some EPUBs)
@@ -304,13 +325,71 @@ QStringList EpubReader::chunkXhtml(const QByteArray &data, const QString &xhtmlH
// FormatReader interface
// ---------------------------------------------------------------------------
bool EpubReader::loadMetadata(const QString &filePath)
{
// Reset state
m_title.clear();
m_author.clear();
m_error.clear();
m_opfDir.clear();
m_coverImagePath.clear();
m_spineHrefs.clear();
unzFile zf = unzOpen(filePath.toUtf8().constData());
if (!zf) {
m_error = QStringLiteral("Cannot open as ZIP archive: ") + filePath;
return false;
}
// Ensure the handle is closed on all exit paths
auto guard = [&](void *) { unzClose(zf); };
std::unique_ptr<void, decltype(guard)> closeGuard(zf, guard);
// 1. Parse META-INF/container.xml
QByteArray containerData = readZipEntry(zf, "META-INF/container.xml");
if (containerData.isEmpty()) {
m_error = QStringLiteral("Invalid EPUB: missing META-INF/container.xml");
return false;
}
QString opfPath;
if (!parseContainer(containerData, opfPath)) {
m_error = QStringLiteral("Invalid EPUB: cannot parse container.xml");
return false;
}
// 2. Determine OPF base directory
const int lastSlash = opfPath.lastIndexOf(QLatin1Char('/'));
m_opfDir = (lastSlash >= 0) ? opfPath.left(lastSlash + 1) : QString();
// 3. Parse OPF (only metadata and manifest for cover image)
QByteArray opfData = readZipEntry(zf, opfPath.toUtf8().constData());
if (opfData.isEmpty()) {
m_error = QStringLiteral("Invalid EPUB: cannot read OPF file: ") + opfPath;
return false;
}
QString ncxHref;
if (!parseOpf(opfData, ncxHref)) {
m_error = QStringLiteral("Invalid EPUB: cannot parse OPF file");
return false;
}
return true;
}
QString EpubReader::lastError() { return m_error; }
QString EpubReader::title() { return m_title; }
QString EpubReader::author() { return m_author; }
QString EpubReader::coverImagePath() { return m_coverImagePath; }
int EpubReader::chapterCount() { return m_spineHrefs.size(); }
QList<TocEntry> EpubReader::tableOfContents() { return m_toc; }
QString EpubReader::filePath()
{
return m_filePath;
}
Chapter EpubReader::loadChapter(int index)
{
if (index < 0 || index >= m_spineRawContent.size())
+5 -1
View File
@@ -5,23 +5,27 @@
#include <QByteArray>
#include <QHash>
#include <QList>
#include <QStringList>
class EpubReader : public FormatReader {
public:
bool open(const QString &filePath) override;
bool loadMetadata(const QString &filePath) override;
QString lastError() override;
int chapterCount() override;
Chapter loadChapter(int index) override;
QList<TocEntry> tableOfContents() override;
QString filePath() override;
QString title() override;
QString author() override;
QString coverImagePath() override;
private:
QString m_filePath;
QString m_title;
QString m_author;
QString m_error;
QString m_opfDir;
QString m_coverImagePath;
QStringList m_spineHrefs;
QList<QByteArray> m_spineRawContent;
QList<TocEntry> m_toc;
+26 -1
View File
@@ -1,6 +1,5 @@
#include "TxtReader.h"
#include <QFile>
#include <QFileInfo>
#include <QRegularExpression>
#include <QTextStream>
@@ -127,6 +126,7 @@ bool TxtReader::open(const QString &filePath)
uchardet_delete(ud);
if (!m_content.isEmpty()) {
m_title = QFileInfo(filePath).completeBaseName();
m_filePath = filePath;
return true;
}
}
@@ -136,6 +136,21 @@ bool TxtReader::open(const QString &filePath)
// Default: UTF-8
m_content = QString::fromUtf8(raw);
m_title = QFileInfo(filePath).completeBaseName();
m_filePath = filePath;
return true;
}
bool TxtReader::loadMetadata(const QString &filePath)
{
QFile file(filePath);
if (!file.exists()) {
m_error = QStringLiteral("File not found: ") + filePath;
return false;
}
// For TXT files, we only need the filename for title
m_title = QFileInfo(filePath).completeBaseName();
m_author.clear(); // No author info in plain text files
return true;
}
@@ -172,6 +187,11 @@ QList<TocEntry> TxtReader::tableOfContents()
return {};
}
QString TxtReader::filePath()
{
return m_filePath;
}
QString TxtReader::title()
{
return m_title;
@@ -181,3 +201,8 @@ QString TxtReader::author()
{
return {};
}
QString TxtReader::coverImagePath()
{
return {};
}
+5
View File
@@ -6,16 +6,21 @@
class TxtReader : public FormatReader {
public:
bool open(const QString &filePath) override;
bool loadMetadata(const QString &filePath) override;
QString lastError() override;
int chapterCount() override;
Chapter loadChapter(int index) override;
QList<TocEntry> tableOfContents() override;
QString filePath() override;
QString title() override;
QString author() override;
QString coverImagePath() override;
private:
QString m_content;
QString m_filePath;
QString m_title;
QString m_author;
QString m_error;
};