80 lines
2.6 KiB
C++
80 lines
2.6 KiB
C++
#ifndef BOOK_H
|
|
#define BOOK_H
|
|
|
|
#include <QFuture>
|
|
#include <QList>
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <QUrl>
|
|
#include <memory>
|
|
|
|
#include "backend/FormatReader.h"
|
|
#include "backend/IFileDialogService.h"
|
|
#include "backend/formats/FormatRegistry.h"
|
|
#include "backend/state/BookPositionStore.h"
|
|
|
|
class Book : public QObject {
|
|
Q_OBJECT
|
|
Q_PROPERTY(bool hasBook READ hasBook NOTIFY bookChanged)
|
|
Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
|
|
Q_PROPERTY(QString title READ title NOTIFY bookChanged)
|
|
Q_PROPERTY(QString author READ author NOTIFY bookChanged)
|
|
Q_PROPERTY(QString filePath READ filePath NOTIFY bookChanged)
|
|
Q_PROPERTY(QString coverImageUrl READ coverImageUrl NOTIFY bookChanged)
|
|
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
|
|
public:
|
|
Book(IFileDialogService &dialog,
|
|
BookPositionStore &positions,
|
|
FormatRegistry ®istry,
|
|
QObject *parent = nullptr);
|
|
~Book() override;
|
|
|
|
bool hasBook() const;
|
|
bool loading() const;
|
|
QString title() const;
|
|
QString author() const;
|
|
QString filePath() const;
|
|
QString coverImageUrl() const;
|
|
QString errorMessage() const;
|
|
|
|
// Called by AppCoordinator::onBookChanged after the image provider resolves the cover URL.
|
|
void setCoverImageUrl(const QString &url);
|
|
|
|
// Access the underlying reader for wiring purposes (e.g., to push into ReadingModel).
|
|
FormatReader *reader() const;
|
|
|
|
Q_INVOKABLE void openFromUrl(const QUrl &url);
|
|
Q_INVOKABLE void openFromPath(const QString &path);
|
|
Q_INVOKABLE void browseAndOpen();
|
|
Q_INVOKABLE void close();
|
|
Q_INVOKABLE void clearError();
|
|
|
|
// Save current position. Called from QML; forwards to BookPositionStore.
|
|
Q_INVOKABLE void saveCurrentPosition(int chunkIndex, bool mangaRTL = true, bool pageShift = true);
|
|
|
|
signals:
|
|
// Emitted just before replacing the current reader with a new one.
|
|
// Listeners can snapshot the outgoing book's progress before the swap.
|
|
void willOpenNewBook();
|
|
void positionSaved();
|
|
|
|
void bookChanged();
|
|
void loadingChanged();
|
|
void errorMessageChanged();
|
|
|
|
private:
|
|
void openImpl(const QString &filePath);
|
|
|
|
IFileDialogService &m_dialog;
|
|
BookPositionStore &m_positions;
|
|
FormatRegistry &m_registry;
|
|
std::unique_ptr<FormatReader> m_reader;
|
|
QString m_coverImageUrl;
|
|
QString m_errorMessage;
|
|
bool m_loading = false;
|
|
int m_openGeneration = 0;
|
|
QFuture<void> m_openFuture;
|
|
};
|
|
|
|
#endif // BOOK_H
|