Merge pull request #109 from jpirnay/kosync_extension
refactor: Picking up some itsthisjustin ideas for KOreader synchronisation
This commit is contained in:
@@ -40,6 +40,7 @@ struct KOReaderSyncSessionState {
|
||||
int totalPagesInSpine = 0;
|
||||
uint16_t paragraphIndex = 0;
|
||||
bool hasParagraphIndex = false;
|
||||
uint32_t xhtmlSeekHint = 0; // byte offset hint for findXPathForParagraph (0 = no hint)
|
||||
KOReaderSyncIntentState intent = KOReaderSyncIntentState::COMPARE;
|
||||
KOReaderSyncOutcomeState outcome = KOReaderSyncOutcomeState::NONE;
|
||||
int resultSpineIndex = 0;
|
||||
@@ -55,6 +56,7 @@ struct KOReaderSyncSessionState {
|
||||
totalPagesInSpine = 0;
|
||||
paragraphIndex = 0;
|
||||
hasParagraphIndex = false;
|
||||
xhtmlSeekHint = 0;
|
||||
intent = KOReaderSyncIntentState::COMPARE;
|
||||
outcome = KOReaderSyncOutcomeState::NONE;
|
||||
resultSpineIndex = 0;
|
||||
|
||||
@@ -82,6 +82,7 @@ bool JsonSettingsIO::saveState(const CrossPointState& s, const char* path) {
|
||||
sync["totalPagesInSpine"] = s.koReaderSyncSession.totalPagesInSpine;
|
||||
sync["paragraphIndex"] = s.koReaderSyncSession.paragraphIndex;
|
||||
sync["hasParagraphIndex"] = s.koReaderSyncSession.hasParagraphIndex;
|
||||
sync["xhtmlSeekHint"] = s.koReaderSyncSession.xhtmlSeekHint;
|
||||
sync["intent"] = static_cast<uint8_t>(s.koReaderSyncSession.intent);
|
||||
sync["outcome"] = static_cast<uint8_t>(s.koReaderSyncSession.outcome);
|
||||
sync["resultSpineIndex"] = s.koReaderSyncSession.resultSpineIndex;
|
||||
@@ -134,6 +135,7 @@ bool JsonSettingsIO::loadState(CrossPointState& s, const char* json) {
|
||||
s.koReaderSyncSession.totalPagesInSpine = sync["totalPagesInSpine"] | 0;
|
||||
s.koReaderSyncSession.paragraphIndex = sync["paragraphIndex"] | (uint16_t)0;
|
||||
s.koReaderSyncSession.hasParagraphIndex = sync["hasParagraphIndex"] | false;
|
||||
s.koReaderSyncSession.xhtmlSeekHint = sync["xhtmlSeekHint"] | (uint32_t)0;
|
||||
s.koReaderSyncSession.intent =
|
||||
static_cast<KOReaderSyncIntentState>(sync["intent"] | static_cast<uint8_t>(KOReaderSyncIntentState::COMPARE));
|
||||
s.koReaderSyncSession.outcome =
|
||||
|
||||
@@ -285,7 +285,7 @@ void ActivityManager::goToKOReaderSync() {
|
||||
|
||||
replaceActivity(std::make_unique<KOReaderSyncActivity>(renderer, mappedInput, sync.epubPath, sync.spineIndex,
|
||||
sync.page, sync.totalPagesInSpine, sync.paragraphIndex,
|
||||
sync.hasParagraphIndex, sync.intent));
|
||||
sync.hasParagraphIndex, sync.xhtmlSeekHint, sync.intent));
|
||||
}
|
||||
|
||||
void ActivityManager::replaceWithReader(std::string path, ReturnHint hint) {
|
||||
|
||||
@@ -637,8 +637,26 @@ void EpubReaderActivity::launchKOReaderSync(const SyncLaunchMode mode) {
|
||||
sync.spineIndex = currentSpineIndex;
|
||||
sync.page = currentPage;
|
||||
sync.totalPagesInSpine = totalPages;
|
||||
sync.paragraphIndex = 0;
|
||||
sync.hasParagraphIndex = false;
|
||||
// Populate paragraph index and XHTML seek hint from section LUT if available.
|
||||
if (section) {
|
||||
if (const auto pIdx = section->getParagraphIndexForPage(static_cast<uint16_t>(currentPage))) {
|
||||
sync.paragraphIndex = *pIdx;
|
||||
sync.hasParagraphIndex = true;
|
||||
if (const auto hint = section->getXhtmlByteOffsetForPage(static_cast<uint16_t>(currentPage))) {
|
||||
sync.xhtmlSeekHint = *hint;
|
||||
} else {
|
||||
sync.xhtmlSeekHint = 0;
|
||||
}
|
||||
} else {
|
||||
sync.paragraphIndex = 0;
|
||||
sync.hasParagraphIndex = false;
|
||||
sync.xhtmlSeekHint = 0;
|
||||
}
|
||||
} else {
|
||||
sync.paragraphIndex = 0;
|
||||
sync.hasParagraphIndex = false;
|
||||
sync.xhtmlSeekHint = 0;
|
||||
}
|
||||
sync.intent = syncIntent;
|
||||
sync.outcome = KOReaderSyncOutcomeState::PENDING;
|
||||
sync.resultSpineIndex = 0;
|
||||
|
||||
@@ -651,8 +651,8 @@ bool KOReaderSyncActivity::computeLocalProgressAndChapter() {
|
||||
return false;
|
||||
}
|
||||
|
||||
CrossPointPosition localPos = {currentSpineIndex, currentPage, totalPagesInSpine, localParagraphIndex,
|
||||
hasLocalParagraphIndex};
|
||||
CrossPointPosition localPos = {currentSpineIndex, currentPage, totalPagesInSpine, localParagraphIndex,
|
||||
hasLocalParagraphIndex, localXhtmlSeekHint};
|
||||
localProgress = ProgressMapper::toKOReader(epub, localPos);
|
||||
|
||||
const int localTocIndex = epub->getTocIndexForSpineIndex(currentSpineIndex);
|
||||
|
||||
@@ -34,7 +34,7 @@ class KOReaderSyncActivity final : public Activity {
|
||||
public:
|
||||
explicit KOReaderSyncActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, const std::string& epubPath,
|
||||
int currentSpineIndex, int currentPage, int totalPagesInSpine,
|
||||
uint16_t paragraphIndex = 0, bool hasParagraphIndex = false,
|
||||
uint16_t paragraphIndex = 0, bool hasParagraphIndex = false, uint32_t xhtmlSeekHint = 0,
|
||||
KOReaderSyncIntentState syncIntent = KOReaderSyncIntentState::COMPARE)
|
||||
: Activity("KOReaderSync", renderer, mappedInput),
|
||||
epubPath(epubPath),
|
||||
@@ -43,6 +43,7 @@ class KOReaderSyncActivity final : public Activity {
|
||||
totalPagesInSpine(totalPagesInSpine),
|
||||
localParagraphIndex(paragraphIndex),
|
||||
hasLocalParagraphIndex(hasParagraphIndex),
|
||||
localXhtmlSeekHint(xhtmlSeekHint),
|
||||
syncIntent(syncIntent),
|
||||
remoteProgress{},
|
||||
remotePosition{},
|
||||
@@ -75,6 +76,7 @@ class KOReaderSyncActivity final : public Activity {
|
||||
int totalPagesInSpine;
|
||||
uint16_t localParagraphIndex;
|
||||
bool hasLocalParagraphIndex;
|
||||
uint32_t localXhtmlSeekHint;
|
||||
KOReaderSyncIntentState syncIntent = KOReaderSyncIntentState::COMPARE;
|
||||
|
||||
State state = WIFI_SELECTION;
|
||||
|
||||
Reference in New Issue
Block a user