37 lines
1.2 KiB
C++
37 lines
1.2 KiB
C++
#include "BookPositionStore.h"
|
|
|
|
BookPositionStore::BookPositionStore(AppState &state)
|
|
: m_state(state)
|
|
{
|
|
}
|
|
|
|
BookPosition BookPositionStore::load(const QByteArray &contentMd5)
|
|
{
|
|
if (contentMd5.isEmpty())
|
|
return {};
|
|
const QVariantMap d = m_state.loadSection(sectionKey(contentMd5));
|
|
BookPosition pos;
|
|
pos.chunkIndex = d.value(QStringLiteral("chunkIndex"), 0).toInt();
|
|
pos.intraOffset = d.value(QStringLiteral("intraOffset"), 0).toInt();
|
|
pos.pageShift = d.value(QStringLiteral("pageShift"), true).toBool();
|
|
pos.mangaRTL = d.value(QStringLiteral("mangaRTL"), true).toBool();
|
|
return pos;
|
|
}
|
|
|
|
void BookPositionStore::save(const QByteArray &contentMd5, int chunkIndex, int intraOffset, bool mangaRTL, bool pageShift)
|
|
{
|
|
if (contentMd5.isEmpty())
|
|
return;
|
|
m_state.saveSection(sectionKey(contentMd5), {
|
|
{QStringLiteral("chunkIndex"), chunkIndex},
|
|
{QStringLiteral("intraOffset"), intraOffset},
|
|
{QStringLiteral("pageShift"), pageShift},
|
|
{QStringLiteral("mangaRTL"), mangaRTL},
|
|
});
|
|
}
|
|
|
|
QString BookPositionStore::sectionKey(const QByteArray &contentMd5)
|
|
{
|
|
return QStringLiteral("saved-progress/") + QString::fromLatin1(contentMd5.toHex());
|
|
}
|