feat: context-aware screenshot filenames with book title (#1589)
## Summary I love the new screenshot feature but I can tell that soon I'm gonna have a folder full of screenshots and not know what's what. It would be great if the folder could self organize. When a screenshot is taken while reading, the filename would now include the book title, chapter (EPUB), page number, and progress percentage. Example: My-Great-Book_ch3_p5_42pct_12345.bmp * **What is the goal of this PR?** (e.g., Implements the new feature for file uploading.) * **What changes are included?** ## Additional Context * Non-reader screens keep the existing screenshot-<millis>.bmp naming. --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**< YES >**_ I reviewed all the changes but I don't have any experience with this project so this is my best guess
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "GfxRenderer.h"
|
||||
#include "MappedInputManager.h"
|
||||
#include "RenderLock.h"
|
||||
#include "util/ScreenshotInfo.h"
|
||||
|
||||
class Activity {
|
||||
friend class ActivityManager;
|
||||
@@ -43,6 +44,7 @@ class Activity {
|
||||
virtual bool skipLoopDelay() { return false; }
|
||||
virtual bool preventAutoSleep() { return false; }
|
||||
virtual bool isReaderActivity() const { return false; }
|
||||
virtual ScreenshotInfo getScreenshotInfo() const { return {}; }
|
||||
|
||||
// Start a new activity without destroying the current one
|
||||
// Note: requestUpdate() will be invoked automatically once resultHandler finishes
|
||||
|
||||
@@ -234,6 +234,13 @@ bool ActivityManager::isReaderActivity() const { return currentActivity && curre
|
||||
|
||||
bool ActivityManager::skipLoopDelay() const { return currentActivity && currentActivity->skipLoopDelay(); }
|
||||
|
||||
ScreenshotInfo ActivityManager::getScreenshotInfo() const {
|
||||
if (currentActivity) {
|
||||
return currentActivity->getScreenshotInfo();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void ActivityManager::requestUpdate(bool immediate) {
|
||||
if (immediate) {
|
||||
if (renderTaskHandle) {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include "GfxRenderer.h"
|
||||
#include "MappedInputManager.h"
|
||||
#include "util/ScreenshotInfo.h"
|
||||
|
||||
class Activity; // forward declaration
|
||||
class RenderLock; // forward declaration
|
||||
@@ -99,6 +100,7 @@ class ActivityManager {
|
||||
bool preventAutoSleep() const;
|
||||
bool isReaderActivity() const;
|
||||
bool skipLoopDelay() const;
|
||||
ScreenshotInfo getScreenshotInfo() const;
|
||||
|
||||
// If immediate is true, the update will be triggered immediately.
|
||||
// Otherwise, it will be deferred until the end of the current loop iteration.
|
||||
|
||||
@@ -928,3 +928,24 @@ void EpubReaderActivity::restoreSavedPosition() {
|
||||
}
|
||||
requestUpdate();
|
||||
}
|
||||
|
||||
ScreenshotInfo EpubReaderActivity::getScreenshotInfo() const {
|
||||
ScreenshotInfo info;
|
||||
info.readerType = ScreenshotInfo::ReaderType::Epub;
|
||||
if (epub) {
|
||||
snprintf(info.title, sizeof(info.title), "%s", epub->getTitle().c_str());
|
||||
info.spineIndex = currentSpineIndex;
|
||||
}
|
||||
if (section) {
|
||||
info.currentPage = section->currentPage + 1;
|
||||
info.totalPages = section->pageCount;
|
||||
if (epub && epub->getBookSize() > 0 && section->pageCount > 0) {
|
||||
const float chapterProgress = static_cast<float>(section->currentPage) / static_cast<float>(section->pageCount);
|
||||
int pct = static_cast<int>(epub->calculateProgress(currentSpineIndex, chapterProgress) * 100.0f + 0.5f);
|
||||
if (pct < 0) pct = 0;
|
||||
if (pct > 100) pct = 100;
|
||||
info.progressPercent = pct;
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@@ -65,4 +65,5 @@ class EpubReaderActivity final : public Activity {
|
||||
void loop() override;
|
||||
void render(RenderLock&& lock) override;
|
||||
bool isReaderActivity() const override { return true; }
|
||||
ScreenshotInfo getScreenshotInfo() const override;
|
||||
};
|
||||
|
||||
@@ -546,3 +546,17 @@ void TxtReaderActivity::savePageIndexCache() const {
|
||||
|
||||
LOG_DBG("TRS", "Saved page index cache: %d pages", totalPages);
|
||||
}
|
||||
|
||||
ScreenshotInfo TxtReaderActivity::getScreenshotInfo() const {
|
||||
ScreenshotInfo info;
|
||||
info.readerType = ScreenshotInfo::ReaderType::Txt;
|
||||
if (txt) {
|
||||
const std::string t = txt->getTitle();
|
||||
snprintf(info.title, sizeof(info.title), "%s", t.c_str());
|
||||
}
|
||||
info.currentPage = currentPage + 1;
|
||||
info.totalPages = totalPages;
|
||||
info.progressPercent = totalPages > 0 ? static_cast<int>((currentPage + 1) * 100.0f / totalPages + 0.5f) : 0;
|
||||
if (info.progressPercent > 100) info.progressPercent = 100;
|
||||
return info;
|
||||
}
|
||||
|
||||
@@ -49,4 +49,5 @@ class TxtReaderActivity final : public Activity {
|
||||
void loop() override;
|
||||
void render(RenderLock&&) override;
|
||||
bool isReaderActivity() const override { return true; }
|
||||
ScreenshotInfo getScreenshotInfo() const override;
|
||||
};
|
||||
|
||||
@@ -360,3 +360,21 @@ void XtcReaderActivity::loadProgress() {
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
|
||||
ScreenshotInfo XtcReaderActivity::getScreenshotInfo() const {
|
||||
ScreenshotInfo info;
|
||||
info.readerType = ScreenshotInfo::ReaderType::Xtc;
|
||||
if (xtc) {
|
||||
const std::string t = xtc->getTitle();
|
||||
snprintf(info.title, sizeof(info.title), "%s", t.c_str());
|
||||
const uint32_t pageCount = xtc->getPageCount();
|
||||
info.totalPages = pageCount;
|
||||
// Clamp to last valid page to avoid sentinel value (currentPage == pageCount)
|
||||
uint32_t clampedPage = (pageCount > 0 && currentPage >= pageCount) ? pageCount - 1 : currentPage;
|
||||
info.progressPercent = pageCount > 0 ? xtc->calculateProgress(clampedPage) : 0;
|
||||
info.currentPage = static_cast<int>(clampedPage) + 1;
|
||||
} else {
|
||||
info.currentPage = currentPage + 1;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@@ -29,4 +29,5 @@ class XtcReaderActivity final : public Activity {
|
||||
void loop() override;
|
||||
void render(RenderLock&&) override;
|
||||
bool isReaderActivity() const override { return true; }
|
||||
ScreenshotInfo getScreenshotInfo() const override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user