When downloading a book via OPDS, a directory picker now lets the user choose the save location instead of always saving to the SD root. Each OPDS server has a configurable default download path (persisted in opds.json) that the picker opens to. Falls back to "/" if the saved path no longer exists on disk. - Add DirectoryPickerActivity (browse-only directory view with "Save Here") - Add PICKING_DIRECTORY state to OpdsBookBrowserActivity - Add downloadPath field to OpdsServer with JSON serialization - Add Download Path setting to OPDS server edit screen - Extract sortFileList() to StringUtils for shared use - Add i18n strings: STR_SAVE_HERE, STR_SELECT_FOLDER, STR_DOWNLOAD_PATH Made-with: Cursor
67 lines
2.4 KiB
C++
67 lines
2.4 KiB
C++
#pragma once
|
|
#include <OpdsParser.h>
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "../ActivityWithSubactivity.h"
|
|
#include "OpdsServerStore.h"
|
|
#include "util/ButtonNavigator.h"
|
|
|
|
/**
|
|
* Activity for browsing and downloading books from an OPDS server.
|
|
* Supports navigation through catalog hierarchy and downloading EPUBs.
|
|
* When WiFi connection fails, launches WiFi selection to let user connect.
|
|
*/
|
|
class OpdsBookBrowserActivity final : public ActivityWithSubactivity {
|
|
public:
|
|
enum class BrowserState {
|
|
CHECK_WIFI, // Checking WiFi connection
|
|
WIFI_SELECTION, // WiFi selection subactivity is active
|
|
LOADING, // Fetching OPDS feed
|
|
BROWSING, // Displaying entries (navigation or books)
|
|
PICKING_DIRECTORY, // Directory picker subactivity is active
|
|
DOWNLOADING, // Downloading selected EPUB
|
|
ERROR // Error state with message
|
|
};
|
|
|
|
explicit OpdsBookBrowserActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
|
|
const std::function<void()>& onGoHome, const OpdsServer& server)
|
|
: ActivityWithSubactivity("OpdsBookBrowser", renderer, mappedInput), onGoHome(onGoHome), server(server) {}
|
|
|
|
void onEnter() override;
|
|
void onExit() override;
|
|
void loop() override;
|
|
void render(Activity::RenderLock&&) override;
|
|
|
|
private:
|
|
ButtonNavigator buttonNavigator;
|
|
BrowserState state = BrowserState::LOADING;
|
|
std::vector<OpdsEntry> entries;
|
|
std::vector<std::string> navigationHistory; // Stack of previous feed paths for back navigation
|
|
std::string currentPath; // Current feed path being displayed
|
|
int selectorIndex = 0;
|
|
std::string errorMessage;
|
|
std::string statusMessage;
|
|
size_t downloadProgress = 0;
|
|
size_t downloadTotal = 0;
|
|
|
|
const std::function<void()> onGoHome;
|
|
OpdsServer server; // Copied at construction — safe even if the store changes during browsing
|
|
|
|
void checkAndConnectWifi();
|
|
void launchWifiSelection();
|
|
void onWifiSelectionComplete(bool connected);
|
|
void fetchFeed(const std::string& path);
|
|
void navigateToEntry(const OpdsEntry& entry);
|
|
void navigateBack();
|
|
void launchDirectoryPicker(const OpdsEntry& book);
|
|
void onDirectorySelected(const std::string& directory);
|
|
void onDirectoryPickerCancelled();
|
|
void downloadBook(const OpdsEntry& book, const std::string& directory);
|
|
bool preventAutoSleep() override { return true; }
|
|
|
|
OpdsEntry pendingBook;
|
|
};
|