Remove obsolete BookController files and update documentation

BookController was superseded by the Book class during a prior refactoring.
The old files were never removed and are not in CMakeLists.txt. Deleted:
- src/backend/BookController.h/cpp (not in build, calls non-existent AppState APIs)
- tests/BookControllerTest.cpp (not in CMake test targets)

Updated CLAUDE.md architecture documentation to reference Book instead of
BookController for all book management operations and tests.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
AgelandClaude Haiku 4.5 committed 2026-04-08 14:22:34 +02:00
1 parent 9280c838b2
commit efd52a57ef
4 files changed
+8 -658

No files matched your search

-266
View File
@@ -1,266 +0,0 @@
#include "BookController.h"
#include "AppState.h"
#include "ImageLoaderFactory.h"
#include "ImageProviderFactory.h"
#include "ReaderFactory.h"
#include "ReadingModel.h"
#include <QtConcurrent>
BookController::BookController(QObject *parent)
: QObject(parent)
{
}
BookController::~BookController()
{
if (m_openFuture.isRunning()) {
m_openFuture.cancel();
m_openFuture.waitForFinished();
}
}
QString BookController::bookTitle() const
{
return m_bookTitle;
}
QString BookController::bookAuthor() const
{
return m_bookAuthor;
}
bool BookController::loading() const
{
return m_loading;
}
QString BookController::errorMessage() const
{
return m_errorMessage;
}
bool BookController::hasBook() const
{
return m_reader != nullptr;
}
QString BookController::currentFilePath() const
{
return m_currentFilePath;
}
bool BookController::startupRestore() const
{
return m_startupRestore;
}
QList<TocEntry> BookController::toc() const
{
if (m_reader)
return m_reader->tableOfContents();
return {};
}
QString BookController::coverImageUrl() const
{
return m_coverImageUrl;
}
void BookController::setReadingModel(ReadingModel *model)
{
m_readingModel = model;
if (m_readingModel) {
connect(m_readingModel, &ReadingModel::restoreReady,
this, [this]() {
if (!m_loading)
return;
m_loading = false;
emit loadingChanged();
emit bookReady();
m_startupRestore = false;
});
}
}
void BookController::setAppState(AppState *state)
{
m_appState = state;
}
void BookController::setFileDialogService(IFileDialogService *service)
{
m_fileDialogService = service;
if (m_fileDialogService)
connect(m_fileDialogService, &IFileDialogService::fileSelected,
this, &BookController::openBookFromPath);
}
void BookController::uiReady()
{
if (!m_appState || m_appState->lastFilePath().isEmpty()) {
emit noSavedBook();
return;
}
m_startupRestore = true;
openBook(m_appState->lastFileUrl());
}
void BookController::openBookFromPath(const QString &filePath)
{
openBook(QUrl::fromLocalFile(filePath));
}
void BookController::openBook(const QUrl &fileUrl)
{
const QString filePath = fileUrl.toLocalFile();
if (m_reader && m_appState && m_readingModel) {
m_appState->addOrUpdateLibraryBook(m_currentFilePath, m_readingModel->progress());
}
if (m_reader)
closeBook();
m_loading = true;
emit loadingChanged();
m_errorMessage.clear();
emit errorMessageChanged();
const int generation = ++m_openGeneration;
m_openFuture = QtConcurrent::run([this, filePath, generation]() {
// --- background thread: all file I/O ---
auto reader = ReaderFactory::create(filePath);
if (!reader) {
QMetaObject::invokeMethod(this, [this, generation]() {
if (generation != m_openGeneration) return;
m_loading = false;
emit loadingChanged();
m_errorMessage = QStringLiteral("No format readers available");
emit errorMessageChanged();
emit bookError(m_errorMessage);
}, Qt::QueuedConnection);
return;
}
if (!reader->open(filePath)) {
const QString err = reader->lastError();
QMetaObject::invokeMethod(this, [this, generation, err]() {
if (generation != m_openGeneration) return;
m_loading = false;
emit loadingChanged();
m_errorMessage = err;
emit errorMessageChanged();
emit bookError(m_errorMessage);
}, Qt::QueuedConnection);
return;
}
// Cheap metadata reads while still on background thread
const QString title = reader->title();
const QString author = reader->author();
const QString coverPath = reader->coverImagePath();
// Box the unique_ptr in a shared_ptr so the lambda capturing it is copyable
// (QMetaObject::invokeMethod requires a copyable functor for queued delivery).
auto readerBox = std::make_shared<std::unique_ptr<FormatReader>>(std::move(reader));
// --- main thread: model / provider setup ---
QMetaObject::invokeMethod(this, [this, generation, filePath,
readerBox, title, author, coverPath]() {
if (generation != m_openGeneration) return;
m_reader = std::move(*readerBox);
m_currentFilePath = filePath;
m_bookTitle = title;
m_bookAuthor = author;
IImageProvider *rawProvider = ImageProviderFactory::create(filePath);
m_ownedProvider.reset();
if (rawProvider && m_providerRegistrar) {
m_providerRegistrar(rawProvider->scheme(), rawProvider);
} else {
m_ownedProvider.reset(rawProvider);
}
m_imageProvider = rawProvider;
if (m_imageProvider) {
m_imageProvider->setFilePath(filePath);
m_imageProvider->setDisplayWidth(m_contentWidth);
}
if (!coverPath.isEmpty() && m_imageProvider)
m_coverImageUrl = m_imageProvider->coverImageUrl(coverPath);
else
m_coverImageUrl.clear();
if (m_readingModel) {
if (m_appState)
m_readingModel->setFontParams(m_appState->fontSize(), m_appState->lineSpacing());
m_readingModel->setImageLoader(ImageLoaderFactory::create(filePath));
m_readingModel->setCoverImageUrl(m_coverImageUrl);
m_readingModel->setReader(m_reader.get());
}
if (m_readingModel && m_appState) {
m_readingModel->measure(true);
emit bookChanged();
} else {
m_loading = false;
emit loadingChanged();
emit bookChanged();
emit bookReady();
m_startupRestore = false;
}
}, Qt::QueuedConnection);
});
}
void BookController::browseAndOpen()
{
if (m_fileDialogService)
m_fileDialogService->open();
}
void BookController::closeBook()
{
if (m_reader && m_appState && m_readingModel && !m_currentFilePath.isEmpty()) {
m_appState->addOrUpdateLibraryBook(m_currentFilePath, m_readingModel->progress());
}
if (m_imageProvider)
m_imageProvider->clear();
m_imageProvider = nullptr;
m_ownedProvider.reset();
if (m_readingModel)
m_readingModel->setReader(nullptr);
m_reader.reset();
m_bookTitle.clear();
m_bookAuthor.clear();
m_currentFilePath.clear();
m_coverImageUrl.clear();
emit bookChanged();
}
void BookController::clearError()
{
if (m_errorMessage.isEmpty())
return;
m_errorMessage.clear();
emit errorMessageChanged();
}
void BookController::setImageProviderRegistrar(
std::function<void(const QString &scheme, IImageProvider *)> fn)
{
m_providerRegistrar = std::move(fn);
}
void BookController::setContentWidth(int width)
{
m_contentWidth = width;
if (m_imageProvider)
m_imageProvider->setDisplayWidth(width);
if (m_readingModel)
m_readingModel->setContentWidth(width);
}
-90
View File
@@ -1,90 +0,0 @@
#ifndef BOOKCONTROLLER_H
#define BOOKCONTROLLER_H
#include <QFuture>
#include <QString>
#include <QList>
#include <functional>
#include <memory>
#include "FormatReader.h"
#include "IFileDialogService.h"
#include "IImageLoader.h"
#include "IImageProvider.h"
class AppState;
class ReadingModel;
class BookController : public QObject {
Q_OBJECT
Q_PROPERTY(QString bookTitle READ bookTitle NOTIFY bookChanged)
Q_PROPERTY(QString bookAuthor READ bookAuthor NOTIFY bookChanged)
Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
Q_PROPERTY(bool hasBook READ hasBook NOTIFY bookChanged)
Q_PROPERTY(QList<TocEntry> toc READ toc NOTIFY bookChanged)
Q_PROPERTY(QString currentFilePath READ currentFilePath NOTIFY bookChanged)
Q_PROPERTY(QString coverImageUrl READ coverImageUrl NOTIFY bookChanged)
Q_PROPERTY(bool startupRestore READ startupRestore NOTIFY bookReady)
public:
explicit BookController(QObject *parent = nullptr);
~BookController();
QString bookTitle() const;
QString bookAuthor() const;
bool loading() const;
QString errorMessage() const;
bool hasBook() const;
QList<TocEntry> toc() const;
QString currentFilePath() const;
QString coverImageUrl() const;
bool startupRestore() const;
void setReadingModel(ReadingModel *model);
void setAppState(AppState *state);
void setFileDialogService(IFileDialogService *service);
// Called each time a new image provider is created for a book.
// The callback must register the provider with the QML engine (which takes ownership).
void setImageProviderRegistrar(std::function<void(const QString &scheme, IImageProvider *)> fn);
// Called by QML once the window is fully laid out. Reads AppState to decide
// whether to open the last book or emit noSavedBook().
Q_INVOKABLE void uiReady();
Q_INVOKABLE void openBook(const QUrl &fileUrl);
Q_INVOKABLE void openBookFromPath(const QString &filePath);
Q_INVOKABLE void browseAndOpen();
Q_INVOKABLE void closeBook();
Q_INVOKABLE void clearError();
Q_INVOKABLE void setContentWidth(int width);
signals:
void bookReady();
void bookError(const QString &error);
void bookChanged();
void loadingChanged();
void errorMessageChanged();
void noSavedBook(); // emitted by uiReady() when there is no last file to open
private:
std::unique_ptr<FormatReader> m_reader;
ReadingModel *m_readingModel = nullptr;
AppState *m_appState = nullptr;
IFileDialogService *m_fileDialogService = nullptr;
std::function<void(const QString &, IImageProvider *)> m_providerRegistrar;
// Non-owning when the QML engine owns the provider; owning otherwise (e.g., in tests).
std::unique_ptr<IImageProvider> m_ownedProvider;
IImageProvider *m_imageProvider = nullptr;
QString m_bookTitle;
QString m_bookAuthor;
QString m_currentFilePath;
QString m_coverImageUrl;
bool m_loading = false;
QString m_errorMessage;
bool m_startupRestore = false;
int m_contentWidth = 0;
int m_openGeneration = 0; // incremented per openBook call; callbacks check for staleness
QFuture<void> m_openFuture;
};
#endif // BOOKCONTROLLER_H