old render cleanup part 3

This commit is contained in:
Agel committed 2026-10-25 15:43:51 +01:00
1 parent cef762c3ee
commit 3faedd4251
45 files changed
+1057 -1135

No files matched your search

+5 -36
View File
@@ -2,15 +2,12 @@
#include "AppState.h"
#include "HistoryModel.h"
#include "IImageProvider.h"
#include "ReadingModel.h"
#include "book/Book.h"
#include "formats/FormatRegistry.h"
#include "state/ReadingPreferences.h"
#include "state/UiState.h"
#include <QCoreApplication>
#include <QQmlApplicationEngine>
#include <QSettings>
AppCoordinator::AppCoordinator(Book &book,
@@ -20,8 +17,6 @@ AppCoordinator::AppCoordinator(Book &book,
ReadingPreferences &readingPreferences,
AppState &appState,
QSettings &settings,
FormatRegistry &formatRegistry,
QQmlApplicationEngine &engine,
QObject *parent)
: QObject(parent)
, m_book(book)
@@ -31,11 +26,9 @@ AppCoordinator::AppCoordinator(Book &book,
, m_readingPreferences(readingPreferences)
, m_appState(appState)
, m_settings(settings)
, m_formatRegistry(formatRegistry)
, m_engine(engine)
{
connect(&m_book, &Book::willOpenNewBook, this, &AppCoordinator::onWillOpenNewBook);
connect(&m_book, &Book::positionSaved, this, &AppCoordinator::onPositionSaved);
connect(&m_readingModel, &ReadingModel::positionSaved, this, &AppCoordinator::onPositionSaved);
connect(&m_book, &Book::bookChanged, this, &AppCoordinator::onBookChanged);
connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit,
@@ -52,14 +45,13 @@ void AppCoordinator::onWillOpenNewBook()
// Real-time history update: fired when position is saved.
void AppCoordinator::onPositionSaved()
{
m_historyModel.addOrUpdateBook(m_book.filePath(), m_readingModel.progress());
if (m_book.hasBook())
m_historyModel.addOrUpdateBook(m_book.filePath(), m_readingModel.progress());
}
// After the new reader is installed: wire up image provider + ReadingModel
// After the new reader is installed: configure ReadingModel
void AppCoordinator::onBookChanged()
{
m_currentImageProvider = nullptr;
if (!m_book.hasBook()) {
m_readingModel.setReader(nullptr);
return;
@@ -67,26 +59,12 @@ void AppCoordinator::onBookChanged()
FormatReader *reader = m_book.reader();
const QString filePath = reader->filePath();
IImageProvider *provider = m_formatRegistry.createImageProvider(filePath);
if (provider) {
m_engine.removeImageProvider(provider->scheme());
m_engine.addImageProvider(provider->scheme(), provider);
provider->setFilePath(filePath);
m_currentImageProvider = provider;
if (!reader->coverImagePath().isEmpty())
m_book.setCoverImageUrl(provider->coverImageUrl(reader->coverImagePath()));
}
m_readingModel.setReader(reader);
m_uiState.setLastFilePath(filePath);
m_historyModel.addOrUpdateBook(filePath, -1.0);
}
// Quit: flush everything to persistent storage.
// Scroll position was last saved by PageView's scroll tracker; we save library progress here.
void AppCoordinator::onAboutToQuit()
{
if (m_book.hasBook()) {
@@ -96,18 +74,9 @@ void AppCoordinator::onAboutToQuit()
m_uiState.setLastFilePath(QString());
}
m_historyModel.save(m_appState);
m_readingPreferences.save();
m_uiState.save();
QList<QVariantMap> items;
for (int i = 0; i < m_historyModel.rowCount(); ++i) {
items.append({
{QStringLiteral("filePath"), m_historyModel.filePath(i)},
{QStringLiteral("progress"), m_historyModel.progress(i)},
{QStringLiteral("lastOpened"), m_historyModel.lastOpened(i)},
});
}
m_appState.saveArray(QStringLiteral("history"), items);
qInfo() << "Settings saved to:" << m_settings.fileName();
}