Some refactor
This commit is contained in:
37 files changed
+1599
-981
No files matched your search
@@ -0,0 +1,83 @@
|
||||
#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/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(QList<TocEntry> toc READ toc NOTIFY bookChanged)
|
||||
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
|
||||
public:
|
||||
Book(IFileDialogService &dialog,
|
||||
BookPositionStore &positions,
|
||||
QObject *parent = nullptr);
|
||||
~Book() override;
|
||||
|
||||
bool hasBook() const;
|
||||
bool loading() const;
|
||||
QString title() const;
|
||||
QString author() const;
|
||||
QString filePath() const;
|
||||
QString coverImageUrl() const;
|
||||
QList<TocEntry> toc() const;
|
||||
QString errorMessage() const;
|
||||
|
||||
// Called by main.cpp's bookChanged lambda 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 scroll position. Called from QML's scroll tracker; forwards to BookPositionStore.
|
||||
Q_INVOKABLE void saveCurrentPosition(int chunkIndex, int intraOffset);
|
||||
|
||||
// Called from QML's PageView when its width changes. Propagates to image provider + ReadingModel
|
||||
// via the contentWidthChanged signal (wired in main.cpp).
|
||||
Q_INVOKABLE void setContentWidth(int width);
|
||||
|
||||
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 bookChanged();
|
||||
void loadingChanged();
|
||||
void errorMessageChanged();
|
||||
void contentWidthChanged(int width);
|
||||
|
||||
private:
|
||||
void openImpl(const QString &filePath);
|
||||
|
||||
IFileDialogService &m_dialog;
|
||||
BookPositionStore &m_positions;
|
||||
std::unique_ptr<FormatReader> m_reader;
|
||||
QString m_coverImageUrl;
|
||||
QString m_errorMessage;
|
||||
bool m_loading = false;
|
||||
int m_openGeneration = 0;
|
||||
int m_contentWidth = 0;
|
||||
QFuture<void> m_openFuture;
|
||||
};
|
||||
|
||||
#endif // BOOK_H
|
||||
Reference in new issue
Block a user