This repository has been archived on 2026-02-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
crosspoint-reader/src/activities/browser/OpdsBookBrowserActivity.h
Justin Mitchell 55c38150cb Adds margin setting and calibre web
Also made the menu items dynamic and capital case. Looks better from a design perspective but I suppose this is an optional thing to accept
2026-01-02 19:39:09 -05:00

57 lines
1.5 KiB
C++

#pragma once
#include <OpdsParser.h>
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
#include <freertos/task.h>
#include <functional>
#include <string>
#include <vector>
#include "../Activity.h"
/**
* Activity for browsing and downloading books from an OPDS server.
* Displays a list of available books and allows downloading EPUBs.
*/
class OpdsBookBrowserActivity final : public Activity {
public:
enum class BrowserState {
LOADING, // Fetching OPDS feed
BOOK_LIST, // Displaying books
DOWNLOADING, // Downloading selected EPUB
ERROR // Error state with message
};
explicit OpdsBookBrowserActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
const std::function<void()>& onGoHome)
: Activity("OpdsBookBrowser", renderer, mappedInput), onGoHome(onGoHome) {}
void onEnter() override;
void onExit() override;
void loop() override;
private:
TaskHandle_t displayTaskHandle = nullptr;
SemaphoreHandle_t renderingMutex = nullptr;
bool updateRequired = false;
BrowserState state = BrowserState::LOADING;
std::vector<OpdsBook> books;
int selectorIndex = 0;
std::string errorMessage;
std::string statusMessage;
size_t downloadProgress = 0;
size_t downloadTotal = 0;
const std::function<void()> onGoHome;
static void taskTrampoline(void* param);
[[noreturn]] void displayTaskLoop();
void render() const;
void fetchBooks();
void downloadBook(const OpdsBook& book);
std::string sanitizeFilename(const std::string& title) const;
};