refactor: rename MyLibrary to FileBrowser (#1260)
Some checks failed
CI (build) / clang-format (push) Has been cancelled
CI (build) / cppcheck (push) Has been cancelled
CI (build) / build (push) Has been cancelled
CI (build) / Test Status (push) Has been cancelled

## Summary

* Renames MyLibrary component to FileBrowser, as it better reflects what
it is, in my opinion

## Additional Context

* Frees the Library name for possible future library component that can
cache metadata, provide other ways of browsing than filesystem
structure, etc
---

### AI Usage

Did you use AI tools to help write this code? _**< YES >**_
This commit is contained in:
Arthur Tazhitdinov
2026-03-02 13:00:53 +03:00
committed by GitHub
parent 7dc518624c
commit f0a549b680
11 changed files with 33 additions and 33 deletions

View File

@@ -5,8 +5,8 @@
#include "boot_sleep/BootActivity.h" #include "boot_sleep/BootActivity.h"
#include "boot_sleep/SleepActivity.h" #include "boot_sleep/SleepActivity.h"
#include "browser/OpdsBookBrowserActivity.h" #include "browser/OpdsBookBrowserActivity.h"
#include "home/FileBrowserActivity.h"
#include "home/HomeActivity.h" #include "home/HomeActivity.h"
#include "home/MyLibraryActivity.h"
#include "home/RecentBooksActivity.h" #include "home/RecentBooksActivity.h"
#include "network/CrossPointWebServerActivity.h" #include "network/CrossPointWebServerActivity.h"
#include "reader/ReaderActivity.h" #include "reader/ReaderActivity.h"
@@ -169,8 +169,8 @@ void ActivityManager::goToFileTransfer() {
void ActivityManager::goToSettings() { replaceActivity(std::make_unique<SettingsActivity>(renderer, mappedInput)); } void ActivityManager::goToSettings() { replaceActivity(std::make_unique<SettingsActivity>(renderer, mappedInput)); }
void ActivityManager::goToMyLibrary(std::string path) { void ActivityManager::goToFileBrowser(std::string path) {
replaceActivity(std::make_unique<MyLibraryActivity>(renderer, mappedInput, std::move(path))); replaceActivity(std::make_unique<FileBrowserActivity>(renderer, mappedInput, std::move(path)));
} }
void ActivityManager::goToRecentBooks() { void ActivityManager::goToRecentBooks() {

View File

@@ -79,7 +79,7 @@ class ActivityManager {
// goTo... functions are convenient wrapper for replaceActivity() // goTo... functions are convenient wrapper for replaceActivity()
void goToFileTransfer(); void goToFileTransfer();
void goToSettings(); void goToSettings();
void goToMyLibrary(std::string path = {}); void goToFileBrowser(std::string path = {});
void goToRecentBooks(); void goToRecentBooks();
void goToBrowser(); void goToBrowser();
void goToReader(std::string path); void goToReader(std::string path);

View File

@@ -1,4 +1,4 @@
#include "MyLibraryActivity.h" #include "FileBrowserActivity.h"
#include <Epub.h> #include <Epub.h>
#include <GfxRenderer.h> #include <GfxRenderer.h>
@@ -69,7 +69,7 @@ void sortFileList(std::vector<std::string>& strs) {
}); });
} }
void MyLibraryActivity::loadFiles() { void FileBrowserActivity::loadFiles() {
files.clear(); files.clear();
auto root = Storage.open(basepath.c_str()); auto root = Storage.open(basepath.c_str());
@@ -104,7 +104,7 @@ void MyLibraryActivity::loadFiles() {
sortFileList(files); sortFileList(files);
} }
void MyLibraryActivity::onEnter() { void FileBrowserActivity::onEnter() {
Activity::onEnter(); Activity::onEnter();
loadFiles(); loadFiles();
@@ -113,20 +113,20 @@ void MyLibraryActivity::onEnter() {
requestUpdate(); requestUpdate();
} }
void MyLibraryActivity::onExit() { void FileBrowserActivity::onExit() {
Activity::onExit(); Activity::onExit();
files.clear(); files.clear();
} }
void MyLibraryActivity::clearFileMetadata(const std::string& fullPath) { void FileBrowserActivity::clearFileMetadata(const std::string& fullPath) {
// Only clear cache for .epub files // Only clear cache for .epub files
if (StringUtils::checkFileExtension(fullPath, ".epub")) { if (StringUtils::checkFileExtension(fullPath, ".epub")) {
Epub(fullPath, "/.crosspoint").clearCache(); Epub(fullPath, "/.crosspoint").clearCache();
LOG_DBG("MyLibrary", "Cleared metadata cache for: %s", fullPath.c_str()); LOG_DBG("FileBrowser", "Cleared metadata cache for: %s", fullPath.c_str());
} }
} }
void MyLibraryActivity::loop() { void FileBrowserActivity::loop() {
// Long press BACK (1s+) goes to root folder // Long press BACK (1s+) goes to root folder
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= GO_HOME_MS && if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= GO_HOME_MS &&
basepath != "/") { basepath != "/") {
@@ -152,10 +152,10 @@ void MyLibraryActivity::loop() {
auto handler = [this, fullPath](const ActivityResult& res) { auto handler = [this, fullPath](const ActivityResult& res) {
if (!res.isCancelled) { if (!res.isCancelled) {
LOG_DBG("MyLibrary", "Attempting to delete: %s", fullPath.c_str()); LOG_DBG("FileBrowser", "Attempting to delete: %s", fullPath.c_str());
clearFileMetadata(fullPath); clearFileMetadata(fullPath);
if (Storage.remove(fullPath.c_str())) { if (Storage.remove(fullPath.c_str())) {
LOG_DBG("MyLibrary", "Deleted successfully"); LOG_DBG("FileBrowser", "Deleted successfully");
loadFiles(); loadFiles();
if (files.empty()) { if (files.empty()) {
selectorIndex = 0; selectorIndex = 0;
@@ -166,10 +166,10 @@ void MyLibraryActivity::loop() {
requestUpdate(true); requestUpdate(true);
} else { } else {
LOG_ERR("MyLibrary", "Failed to delete file: %s", fullPath.c_str()); LOG_ERR("FileBrowser", "Failed to delete file: %s", fullPath.c_str());
} }
} else { } else {
LOG_DBG("MyLibrary", "Delete cancelled by user"); LOG_DBG("FileBrowser", "Delete cancelled by user");
} }
}; };
@@ -244,7 +244,7 @@ std::string getFileName(std::string filename) {
return filename.substr(0, pos); return filename.substr(0, pos);
} }
void MyLibraryActivity::render(RenderLock&&) { void FileBrowserActivity::render(RenderLock&&) {
renderer.clearScreen(); renderer.clearScreen();
const auto pageWidth = renderer.getScreenWidth(); const auto pageWidth = renderer.getScreenWidth();
@@ -274,7 +274,7 @@ void MyLibraryActivity::render(RenderLock&&) {
renderer.displayBuffer(); renderer.displayBuffer();
} }
size_t MyLibraryActivity::findEntry(const std::string& name) const { size_t FileBrowserActivity::findEntry(const std::string& name) const {
for (size_t i = 0; i < files.size(); i++) for (size_t i = 0; i < files.size(); i++)
if (files[i] == name) return i; if (files[i] == name) return i;
return 0; return 0;

View File

@@ -8,7 +8,7 @@
#include "RecentBooksStore.h" #include "RecentBooksStore.h"
#include "util/ButtonNavigator.h" #include "util/ButtonNavigator.h"
class MyLibraryActivity final : public Activity { class FileBrowserActivity final : public Activity {
private: private:
// Deletion // Deletion
void clearFileMetadata(const std::string& fullPath); void clearFileMetadata(const std::string& fullPath);
@@ -26,8 +26,8 @@ class MyLibraryActivity final : public Activity {
size_t findEntry(const std::string& name) const; size_t findEntry(const std::string& name) const;
public: public:
explicit MyLibraryActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::string initialPath = "/") explicit FileBrowserActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::string initialPath = "/")
: Activity("MyLibrary", renderer, mappedInput), basepath(initialPath.empty() ? "/" : std::move(initialPath)) {} : Activity("FileBrowser", renderer, mappedInput), basepath(initialPath.empty() ? "/" : std::move(initialPath)) {}
void onEnter() override; void onEnter() override;
void onExit() override; void onExit() override;
void loop() override; void loop() override;

View File

@@ -20,7 +20,7 @@
#include "util/StringUtils.h" #include "util/StringUtils.h"
int HomeActivity::getMenuItemCount() const { int HomeActivity::getMenuItemCount() const {
int count = 4; // My Library, Recents, File transfer, Settings int count = 4; // File Browser, Recents, File transfer, Settings
if (!recentBooks.empty()) { if (!recentBooks.empty()) {
count += recentBooks.size(); count += recentBooks.size();
} }
@@ -189,7 +189,7 @@ void HomeActivity::loop() {
// Calculate dynamic indices based on which options are available // Calculate dynamic indices based on which options are available
int idx = 0; int idx = 0;
int menuSelectedIndex = selectorIndex - static_cast<int>(recentBooks.size()); int menuSelectedIndex = selectorIndex - static_cast<int>(recentBooks.size());
const int myLibraryIdx = idx++; const int fileBrowserIdx = idx++;
const int recentsIdx = idx++; const int recentsIdx = idx++;
const int opdsLibraryIdx = hasOpdsUrl ? idx++ : -1; const int opdsLibraryIdx = hasOpdsUrl ? idx++ : -1;
const int fileTransferIdx = idx++; const int fileTransferIdx = idx++;
@@ -197,8 +197,8 @@ void HomeActivity::loop() {
if (selectorIndex < recentBooks.size()) { if (selectorIndex < recentBooks.size()) {
onSelectBook(recentBooks[selectorIndex].path); onSelectBook(recentBooks[selectorIndex].path);
} else if (menuSelectedIndex == myLibraryIdx) { } else if (menuSelectedIndex == fileBrowserIdx) {
onMyLibraryOpen(); onFileBrowserOpen();
} else if (menuSelectedIndex == recentsIdx) { } else if (menuSelectedIndex == recentsIdx) {
onRecentsOpen(); onRecentsOpen();
} else if (menuSelectedIndex == opdsLibraryIdx) { } else if (menuSelectedIndex == opdsLibraryIdx) {
@@ -231,7 +231,7 @@ void HomeActivity::render(RenderLock&&) {
std::vector<UIIcon> menuIcons = {Folder, Recent, Transfer, Settings}; std::vector<UIIcon> menuIcons = {Folder, Recent, Transfer, Settings};
if (hasOpdsUrl) { if (hasOpdsUrl) {
// Insert OPDS Browser after My Library // Insert OPDS Browser after File Browser
menuItems.insert(menuItems.begin() + 2, tr(STR_OPDS_BROWSER)); menuItems.insert(menuItems.begin() + 2, tr(STR_OPDS_BROWSER));
menuIcons.insert(menuIcons.begin() + 2, Library); menuIcons.insert(menuIcons.begin() + 2, Library);
} }
@@ -261,7 +261,7 @@ void HomeActivity::render(RenderLock&&) {
void HomeActivity::onSelectBook(const std::string& path) { activityManager.goToReader(path); } void HomeActivity::onSelectBook(const std::string& path) { activityManager.goToReader(path); }
void HomeActivity::onMyLibraryOpen() { activityManager.goToMyLibrary(); } void HomeActivity::onFileBrowserOpen() { activityManager.goToFileBrowser(); }
void HomeActivity::onRecentsOpen() { activityManager.goToRecentBooks(); } void HomeActivity::onRecentsOpen() { activityManager.goToRecentBooks(); }

View File

@@ -3,7 +3,7 @@
#include <vector> #include <vector>
#include "../Activity.h" #include "../Activity.h"
#include "./MyLibraryActivity.h" #include "./FileBrowserActivity.h"
#include "util/ButtonNavigator.h" #include "util/ButtonNavigator.h"
struct RecentBook; struct RecentBook;
@@ -21,7 +21,7 @@ class HomeActivity final : public Activity {
uint8_t* coverBuffer = nullptr; // HomeActivity's own buffer for cover image uint8_t* coverBuffer = nullptr; // HomeActivity's own buffer for cover image
std::vector<RecentBook> recentBooks; std::vector<RecentBook> recentBooks;
void onSelectBook(const std::string& path); void onSelectBook(const std::string& path);
void onMyLibraryOpen(); void onFileBrowserOpen();
void onRecentsOpen(); void onRecentsOpen();
void onSettingsOpen(); void onSettingsOpen();
void onFileTransferOpen(); void onFileTransferOpen();

View File

@@ -180,7 +180,7 @@ void EpubReaderActivity::loop() {
// Long press BACK (1s+) goes to file selection // Long press BACK (1s+) goes to file selection
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= goHomeMs) { if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= goHomeMs) {
activityManager.goToMyLibrary(epub ? epub->getPath() : ""); activityManager.goToFileBrowser(epub ? epub->getPath() : "");
return; return;
} }

View File

@@ -80,7 +80,7 @@ std::unique_ptr<Txt> ReaderActivity::loadTxt(const std::string& path) {
void ReaderActivity::goToLibrary(const std::string& fromBookPath) { void ReaderActivity::goToLibrary(const std::string& fromBookPath) {
// If coming from a book, start in that book's folder; otherwise start from root // If coming from a book, start in that book's folder; otherwise start from root
auto initialPath = fromBookPath.empty() ? "/" : extractFolderPath(fromBookPath); auto initialPath = fromBookPath.empty() ? "/" : extractFolderPath(fromBookPath);
activityManager.goToMyLibrary(std::move(initialPath)); activityManager.goToFileBrowser(std::move(initialPath));
} }
void ReaderActivity::onGoToEpubReader(std::unique_ptr<Epub> epub) { void ReaderActivity::onGoToEpubReader(std::unique_ptr<Epub> epub) {

View File

@@ -2,7 +2,7 @@
#include <memory> #include <memory>
#include "../Activity.h" #include "../Activity.h"
#include "activities/home/MyLibraryActivity.h" #include "activities/home/FileBrowserActivity.h"
class Epub; class Epub;
class Xtc; class Xtc;

View File

@@ -76,7 +76,7 @@ void TxtReaderActivity::onExit() {
void TxtReaderActivity::loop() { void TxtReaderActivity::loop() {
// Long press BACK (1s+) goes to file selection // Long press BACK (1s+) goes to file selection
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= goHomeMs) { if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= goHomeMs) {
activityManager.goToMyLibrary(txt ? txt->getPath() : ""); activityManager.goToFileBrowser(txt ? txt->getPath() : "");
return; return;
} }

View File

@@ -70,7 +70,7 @@ void XtcReaderActivity::loop() {
// Long press BACK (1s+) goes to file selection // Long press BACK (1s+) goes to file selection
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= goHomeMs) { if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= goHomeMs) {
activityManager.goToMyLibrary(xtc ? xtc->getPath() : ""); activityManager.goToFileBrowser(xtc ? xtc->getPath() : "");
return; return;
} }