33 lines
956 B
C++
33 lines
956 B
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();
|
|
return pos;
|
|
}
|
|
|
|
void BookPositionStore::save(const QByteArray &contentMd5, int chunkIndex, int intraOffset)
|
|
{
|
|
if (contentMd5.isEmpty())
|
|
return;
|
|
m_state.saveSection(sectionKey(contentMd5), {
|
|
{QStringLiteral("chunkIndex"), chunkIndex},
|
|
{QStringLiteral("intraOffset"), intraOffset},
|
|
});
|
|
}
|
|
|
|
QString BookPositionStore::sectionKey(const QByteArray &contentMd5)
|
|
{
|
|
return QStringLiteral("saved-progress/") + QString::fromLatin1(contentMd5.toHex());
|
|
}
|