Audit best practice 0.4.8: orientazioni per pagina (reader in landscape), licenza nel pacchetto, EPUB lazy lengths, cover dinamica (ReaderState), flush config senza sync per tasto, pulizia chapterFraction/commenti

This commit is contained in:
2026-09-03 14:16:18 +02:00
parent 7fca7fbfcd
commit 041b9b9567
17 changed files with 225 additions and 45 deletions
+23 -13
View File
@@ -490,8 +490,14 @@ bool EpubBook::open(const QString &epubPath)
if (!parseOpf())
return false;
const bool ok = !m_chapters.isEmpty();
if (ok)
computeTextLengths();
if (ok) {
// lunghezze testo LAZY: -1 = da calcolare al primo accesso. L'apertura
// resta veloce anche per libri grossi (niente parse di tutti i capitoli).
m_textLengths.clear();
m_textLengths.reserve(m_chapters.size());
for (int i = 0; i < m_chapters.size(); ++i)
m_textLengths.append(-1);
}
emit changed();
return ok;
}
@@ -763,24 +769,26 @@ QString EpubBook::chapterRichText(int index) const
return htmlToRichText(html);
}
void EpubBook::computeTextLengths()
// calcola (e cache) la lunghezza del capitolo index se non ancora nota
void EpubBook::ensureTextLength(int index) const
{
m_textLengths.clear();
for (const EpubChapter &c : m_chapters) {
QFile f(c.path);
if (!f.open(QIODevice::ReadOnly)) {
m_textLengths.append(0);
continue;
}
const QString html = QString::fromUtf8(f.readAll());
m_textLengths.append(plainTextLength(html));
if (index < 0 || index >= m_textLengths.size() || m_textLengths.at(index) >= 0)
return;
const EpubChapter &c = m_chapters.at(index);
QFile f(c.path);
if (!f.open(QIODevice::ReadOnly)) {
m_textLengths[index] = 0;
return;
}
const QString html = QString::fromUtf8(f.readAll());
m_textLengths[index] = plainTextLength(html);
}
int EpubBook::chapterTextLength(int index) const
{
if (index < 0 || index >= m_textLengths.size())
return 0;
ensureTextLength(index);
return m_textLengths.at(index);
}
@@ -788,8 +796,10 @@ qint64 EpubBook::chapterStartChar(int index) const
{
qint64 start = 0;
const int end = qMin(index, m_textLengths.size());
for (int i = 0; i < end; ++i)
for (int i = 0; i < end; ++i) {
ensureTextLength(i);
start += m_textLengths.at(i);
}
return start;
}