Proper sidecar cover support

This commit is contained in:
jpirnay
2026-05-08 16:09:39 +02:00
parent a26d076721
commit 98e7c14c16
8 changed files with 181 additions and 52 deletions
+4 -1
View File
@@ -29,6 +29,7 @@
#include "KOReaderCredentialStore.h"
#include "MappedInputManager.h"
#include "QrDisplayActivity.h"
#include "ReaderActivity.h"
#include "ReaderUtils.h"
#include "RecentBooksStore.h"
#include "SdCardFontGlobals.h"
@@ -207,7 +208,9 @@ void EpubReaderActivity::onEnter() {
if (!series.empty() && !epub->getSeriesIndex().empty()) {
series += " #" + epub->getSeriesIndex();
}
RECENT_BOOKS.addBook(epub->getPath(), epub->getTitle(), epub->getAuthor(), series, epub->getThumbBmpPath());
const std::string epubSidecar = ReaderActivity::sidecarCoverPath(epub->getPath());
const std::string epubCover = epubSidecar.empty() ? epub->getThumbBmpPath() : epubSidecar;
RECENT_BOOKS.addBook(epub->getPath(), epub->getTitle(), epub->getAuthor(), series, epubCover);
const RecentBook currentBook = RECENT_BOOKS.getBookByPath(epub->getPath());
bookEmbeddedStyleOverride = currentBook.embeddedStyleOverride;
bookImageRenderingOverride = currentBook.imageRenderingOverride;
+2 -1
View File
@@ -15,6 +15,7 @@
#include "CrossPointState.h"
#include "MappedInputManager.h"
#include "MdReaderTocSelectionActivity.h"
#include "ReaderActivity.h"
#include "ReaderUtils.h"
#include "RecentBooksStore.h"
#include "components/UITheme.h"
@@ -52,7 +53,7 @@ void MdReaderActivity::onEnter() {
auto fileName = filePath.substr(filePath.rfind('/') + 1);
APP_STATE.openEpubPath = filePath;
APP_STATE.saveToFile();
RECENT_BOOKS.addBook(filePath, fileName, "", "", "");
RECENT_BOOKS.addBook(filePath, fileName, "", "", ReaderActivity::sidecarCoverPath(filePath));
requestUpdate();
}
+11
View File
@@ -56,6 +56,17 @@ bool ReaderActivity::isImageFile(const std::string& path) {
return FsHelpers::hasBmpExtension(path) || FsHelpers::hasJpgExtension(path) || FsHelpers::hasPngExtension(path);
}
std::string ReaderActivity::sidecarCoverPath(const std::string& bookPath) {
const auto dot = bookPath.rfind('.');
if (dot == std::string::npos) return "";
const std::string base = bookPath.substr(0, dot);
for (const char* ext : {".jpg", ".jpeg", ".png", ".bmp"}) {
const std::string candidate = base + ext;
if (Storage.exists(candidate.c_str())) return candidate;
}
return "";
}
std::unique_ptr<Epub> ReaderActivity::loadEpub(const std::string& path) {
if (!Storage.exists(path.c_str())) {
LOG_ERR("READER", "File does not exist: %s", path.c_str());
+2
View File
@@ -30,6 +30,8 @@ class ReaderActivity final : public Activity {
void onGoBack();
public:
static std::string sidecarCoverPath(const std::string& bookPath);
explicit ReaderActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::string initialBookPath)
: Activity("Reader", renderer, mappedInput), initialBookPath(std::move(initialBookPath)) {}
void onEnter() override;
+2 -1
View File
@@ -13,6 +13,7 @@
#include "CrossPointState.h"
#include "GlobalBookmarkIndex.h"
#include "MappedInputManager.h"
#include "ReaderActivity.h"
#include "ReaderUtils.h"
#include "RecentBooksStore.h"
#include "StarredPagesActivity.h"
@@ -112,7 +113,7 @@ void TxtReaderActivity::onEnter() {
auto fileName = filePath.substr(filePath.rfind('/') + 1);
APP_STATE.openEpubPath = filePath;
APP_STATE.saveToFile();
RECENT_BOOKS.addBook(filePath, fileName, "", "", "");
RECENT_BOOKS.addBook(filePath, fileName, "", "", ReaderActivity::sidecarCoverPath(filePath));
// Trigger first update
requestUpdate();
+4 -1
View File
@@ -17,6 +17,7 @@
#include "CrossPointSettings.h"
#include "CrossPointState.h"
#include "MappedInputManager.h"
#include "ReaderActivity.h"
#include "ReaderUtils.h"
#include "RecentBooksStore.h"
#include "XtcReaderChapterSelectionActivity.h"
@@ -42,7 +43,9 @@ void XtcReaderActivity::onEnter() {
// Save current XTC as last opened book and add to recent books
APP_STATE.openEpubPath = xtc->getPath();
APP_STATE.saveToFile();
RECENT_BOOKS.addBook(xtc->getPath(), xtc->getTitle(), xtc->getAuthor(), "", xtc->getThumbBmpPath());
const std::string xtcSidecar = ReaderActivity::sidecarCoverPath(xtc->getPath());
const std::string xtcCover = xtcSidecar.empty() ? xtc->getThumbBmpPath() : xtcSidecar;
RECENT_BOOKS.addBook(xtc->getPath(), xtc->getTitle(), xtc->getAuthor(), "", xtcCover);
// Trigger first update
requestUpdate();