Rename Library to History
This commit is contained in:
11 files changed
+102
-102
No files matched your search
@@ -1,42 +1,42 @@
|
||||
#include "LibraryBookModel.h"
|
||||
#include "HistoryBookModel.h"
|
||||
#include "FormatReader.h"
|
||||
#include "formats/ReaderFactory.h"
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
LibraryBookModel::LibraryBookModel(ReaderFactory &factory, QObject *parent)
|
||||
HistoryBookModel::HistoryBookModel(ReaderFactory &factory, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_factory(factory)
|
||||
{
|
||||
connect(this, &LibraryBookModel::metadataLoaded, this, &LibraryBookModel::onMetadataLoaded);
|
||||
connect(this, &HistoryBookModel::metadataLoaded, this, &HistoryBookModel::onMetadataLoaded);
|
||||
}
|
||||
|
||||
LibraryBookModel::LibraryBookModel(const QString &filePath, double progress, const QString &lastOpened, ReaderFactory &factory, QObject *parent)
|
||||
HistoryBookModel::HistoryBookModel(const QString &filePath, double progress, const QString &lastOpened, ReaderFactory &factory, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_filePath(filePath)
|
||||
, m_progress(progress)
|
||||
, m_lastOpened(lastOpened)
|
||||
, m_factory(factory)
|
||||
{
|
||||
connect(this, &LibraryBookModel::metadataLoaded, this, &LibraryBookModel::onMetadataLoaded);
|
||||
connect(this, &HistoryBookModel::metadataLoaded, this, &HistoryBookModel::onMetadataLoaded);
|
||||
}
|
||||
|
||||
LibraryBookModel::~LibraryBookModel()
|
||||
HistoryBookModel::~HistoryBookModel()
|
||||
{
|
||||
if (m_metadataFuture.isRunning())
|
||||
m_metadataFuture.waitForFinished();
|
||||
}
|
||||
|
||||
QString LibraryBookModel::filePath() const
|
||||
QString HistoryBookModel::filePath() const
|
||||
{
|
||||
return m_filePath;
|
||||
}
|
||||
|
||||
double LibraryBookModel::progress() const
|
||||
double HistoryBookModel::progress() const
|
||||
{
|
||||
return m_progress;
|
||||
}
|
||||
|
||||
void LibraryBookModel::setProgress(double progress)
|
||||
void HistoryBookModel::setProgress(double progress)
|
||||
{
|
||||
if (qFuzzyCompare(m_progress, progress))
|
||||
return;
|
||||
@@ -44,12 +44,12 @@ void LibraryBookModel::setProgress(double progress)
|
||||
emit progressChanged();
|
||||
}
|
||||
|
||||
QString LibraryBookModel::lastOpened() const
|
||||
QString HistoryBookModel::lastOpened() const
|
||||
{
|
||||
return m_lastOpened;
|
||||
}
|
||||
|
||||
void LibraryBookModel::setLastOpened(const QString &lastOpened)
|
||||
void HistoryBookModel::setLastOpened(const QString &lastOpened)
|
||||
{
|
||||
if (m_lastOpened == lastOpened)
|
||||
return;
|
||||
@@ -57,27 +57,27 @@ void LibraryBookModel::setLastOpened(const QString &lastOpened)
|
||||
emit lastOpenedChanged();
|
||||
}
|
||||
|
||||
QString LibraryBookModel::title() const
|
||||
QString HistoryBookModel::title() const
|
||||
{
|
||||
return m_title;
|
||||
}
|
||||
|
||||
QString LibraryBookModel::author() const
|
||||
QString HistoryBookModel::author() const
|
||||
{
|
||||
return m_author;
|
||||
}
|
||||
|
||||
QString LibraryBookModel::coverImageUrl() const
|
||||
QString HistoryBookModel::coverImageUrl() const
|
||||
{
|
||||
return m_coverImageUrl;
|
||||
}
|
||||
|
||||
void LibraryBookModel::loadMetadata()
|
||||
void HistoryBookModel::loadMetadata()
|
||||
{
|
||||
if (m_metadataLoaded || m_filePath.isEmpty() || m_metadataFuture.isRunning())
|
||||
return;
|
||||
|
||||
QPointer<LibraryBookModel> self = this;
|
||||
QPointer<HistoryBookModel> self = this;
|
||||
QString filePath = m_filePath;
|
||||
|
||||
ReaderFactory *factory = &m_factory;
|
||||
@@ -104,12 +104,12 @@ void LibraryBookModel::loadMetadata()
|
||||
});
|
||||
}
|
||||
|
||||
void LibraryBookModel::onMetadataLoaded()
|
||||
void HistoryBookModel::onMetadataLoaded()
|
||||
{
|
||||
// This slot can be used for any post-processing after metadata is loaded
|
||||
}
|
||||
|
||||
void LibraryBookModel::loadCoverImage(const QString &epubBasePath)
|
||||
void HistoryBookModel::loadCoverImage(const QString &epubBasePath)
|
||||
{
|
||||
if (!m_coverImageUrl.isEmpty() || m_filePath.isEmpty())
|
||||
return;
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef LIBRARYBOOKMODEL_H
|
||||
#define LIBRARYBOOKMODEL_H
|
||||
#ifndef HISTORYBOOKMODEL_H
|
||||
#define HISTORYBOOKMODEL_H
|
||||
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
class FormatReader;
|
||||
|
||||
class LibraryBookModel : public QObject {
|
||||
class HistoryBookModel : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString filePath READ filePath CONSTANT)
|
||||
Q_PROPERTY(double progress READ progress WRITE setProgress NOTIFY progressChanged)
|
||||
@@ -20,9 +20,9 @@ class LibraryBookModel : public QObject {
|
||||
Q_PROPERTY(QString coverImageUrl READ coverImageUrl NOTIFY coverImageLoaded)
|
||||
|
||||
public:
|
||||
explicit LibraryBookModel(ReaderFactory &factory, QObject *parent = nullptr);
|
||||
explicit LibraryBookModel(const QString &filePath, double progress, const QString &lastOpened, ReaderFactory &factory, QObject *parent = nullptr);
|
||||
~LibraryBookModel() override;
|
||||
explicit HistoryBookModel(ReaderFactory &factory, QObject *parent = nullptr);
|
||||
explicit HistoryBookModel(const QString &filePath, double progress, const QString &lastOpened, ReaderFactory &factory, QObject *parent = nullptr);
|
||||
~HistoryBookModel() override;
|
||||
|
||||
QString filePath() const;
|
||||
double progress() const;
|
||||
@@ -59,4 +59,4 @@ private:
|
||||
ReaderFactory &m_factory;
|
||||
};
|
||||
|
||||
#endif // LIBRARYBOOKMODEL_H
|
||||
#endif // HISTORYBOOKMODEL_H
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "LibraryModel.h"
|
||||
#include "LibraryBookModel.h"
|
||||
#include "HistoryModel.h"
|
||||
#include "HistoryBookModel.h"
|
||||
#include <QDateTime>
|
||||
|
||||
LibraryModel::LibraryModel(ReaderFactory &factory, QObject *parent)
|
||||
HistoryModel::HistoryModel(ReaderFactory &factory, QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
, m_factory(factory)
|
||||
{
|
||||
@@ -15,24 +15,24 @@ LibraryModel::LibraryModel(ReaderFactory &factory, QObject *parent)
|
||||
m_roleNames[CoverImageUrlRole] = "coverImageUrl";
|
||||
}
|
||||
|
||||
LibraryModel::~LibraryModel()
|
||||
HistoryModel::~HistoryModel()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
int LibraryModel::rowCount(const QModelIndex &parent) const
|
||||
int HistoryModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
return m_books.count();
|
||||
}
|
||||
|
||||
QVariant LibraryModel::data(const QModelIndex &index, int role) const
|
||||
QVariant HistoryModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= m_books.count())
|
||||
return QVariant();
|
||||
|
||||
LibraryBookModel* book = m_books.at(index.row());
|
||||
HistoryBookModel* book = m_books.at(index.row());
|
||||
if (!book)
|
||||
return QVariant();
|
||||
|
||||
@@ -54,12 +54,12 @@ QVariant LibraryModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
}
|
||||
|
||||
bool LibraryModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
bool HistoryModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= m_books.count())
|
||||
return false;
|
||||
|
||||
LibraryBookModel* book = m_books.at(index.row());
|
||||
HistoryBookModel* book = m_books.at(index.row());
|
||||
|
||||
switch (role) {
|
||||
case ProgressRole:
|
||||
@@ -75,17 +75,17 @@ bool LibraryModel::setData(const QModelIndex &index, const QVariant &value, int
|
||||
}
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> LibraryModel::roleNames() const
|
||||
QHash<int, QByteArray> HistoryModel::roleNames() const
|
||||
{
|
||||
return m_roleNames;
|
||||
}
|
||||
|
||||
void LibraryModel::addOrUpdateBook(const QString &filePath, double progress, const QString &lastOpened)
|
||||
void HistoryModel::addOrUpdateBook(const QString &filePath, double progress, const QString &lastOpened)
|
||||
{
|
||||
// Check if book already exists
|
||||
for (int i = 0; i < m_books.size(); i++) {
|
||||
if (m_books[i]->filePath() == filePath) {
|
||||
LibraryBookModel* existingBook = m_books[i];
|
||||
HistoryBookModel* existingBook = m_books[i];
|
||||
existingBook->setProgress(progress);
|
||||
existingBook->setLastOpened(lastOpened);
|
||||
|
||||
@@ -98,9 +98,9 @@ void LibraryModel::addOrUpdateBook(const QString &filePath, double progress, con
|
||||
}
|
||||
}
|
||||
|
||||
// New book — LibraryModel takes ownership via parent
|
||||
auto* book = new LibraryBookModel(filePath, progress, lastOpened, m_factory, this);
|
||||
connect(book, &LibraryBookModel::metadataLoaded, this, &LibraryModel::onBookMetadataLoaded);
|
||||
// New book — HistoryModel takes ownership via parent
|
||||
auto* book = new HistoryBookModel(filePath, progress, lastOpened, m_factory, this);
|
||||
connect(book, &HistoryBookModel::metadataLoaded, this, &HistoryModel::onBookMetadataLoaded);
|
||||
|
||||
beginInsertRows(QModelIndex(), 0, 0);
|
||||
m_books.prepend(book);
|
||||
@@ -110,14 +110,14 @@ void LibraryModel::addOrUpdateBook(const QString &filePath, double progress, con
|
||||
book->loadMetadata();
|
||||
}
|
||||
|
||||
void LibraryModel::removeBook(const QString &filePath)
|
||||
void HistoryModel::removeBook(const QString &filePath)
|
||||
{
|
||||
for (int i = 0; i < m_books.size(); i++) {
|
||||
if (m_books[i]->filePath() == filePath) {
|
||||
LibraryBookModel* book = m_books[i];
|
||||
HistoryBookModel* book = m_books[i];
|
||||
|
||||
// Disconnect signals
|
||||
disconnect(book, &LibraryBookModel::metadataLoaded, this, &LibraryModel::onBookMetadataLoaded);
|
||||
disconnect(book, &HistoryBookModel::metadataLoaded, this, &HistoryModel::onBookMetadataLoaded);
|
||||
|
||||
beginRemoveRows(QModelIndex(), i, i);
|
||||
m_books.removeAt(i);
|
||||
@@ -130,9 +130,9 @@ void LibraryModel::removeBook(const QString &filePath)
|
||||
}
|
||||
}
|
||||
|
||||
LibraryBookModel* LibraryModel::findBook(const QString &filePath) const
|
||||
HistoryBookModel* HistoryModel::findBook(const QString &filePath) const
|
||||
{
|
||||
for (LibraryBookModel* book : m_books) {
|
||||
for (HistoryBookModel* book : m_books) {
|
||||
if (book->filePath() == filePath) {
|
||||
return book;
|
||||
}
|
||||
@@ -140,7 +140,7 @@ LibraryBookModel* LibraryModel::findBook(const QString &filePath) const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void LibraryModel::clear()
|
||||
void HistoryModel::clear()
|
||||
{
|
||||
if (m_books.isEmpty())
|
||||
return;
|
||||
@@ -148,8 +148,8 @@ void LibraryModel::clear()
|
||||
beginRemoveRows(QModelIndex(), 0, m_books.size() - 1);
|
||||
|
||||
// Disconnect and delete all books
|
||||
for (LibraryBookModel* book : m_books) {
|
||||
disconnect(book, &LibraryBookModel::metadataLoaded, this, &LibraryModel::onBookMetadataLoaded);
|
||||
for (HistoryBookModel* book : m_books) {
|
||||
disconnect(book, &HistoryBookModel::metadataLoaded, this, &HistoryModel::onBookMetadataLoaded);
|
||||
book->deleteLater();
|
||||
}
|
||||
|
||||
@@ -159,44 +159,44 @@ void LibraryModel::clear()
|
||||
emit countChanged();
|
||||
}
|
||||
|
||||
void LibraryModel::addOrUpdateBook(const QString &filePath, double progress)
|
||||
void HistoryModel::addOrUpdateBook(const QString &filePath, double progress)
|
||||
{
|
||||
// Sentinel: progress < 0 means "preserve the existing progress value"
|
||||
double resolvedProgress = progress;
|
||||
if (progress < 0.0) {
|
||||
LibraryBookModel *existing = findBook(filePath);
|
||||
HistoryBookModel *existing = findBook(filePath);
|
||||
resolvedProgress = existing ? existing->progress() : 0.0;
|
||||
}
|
||||
addOrUpdateBook(filePath, resolvedProgress,
|
||||
QDateTime::currentDateTime().toString(Qt::ISODate));
|
||||
}
|
||||
|
||||
QString LibraryModel::filePath(int index) const
|
||||
QString HistoryModel::filePath(int index) const
|
||||
{
|
||||
if (index < 0 || index >= m_books.size()) return {};
|
||||
return m_books.at(index)->filePath();
|
||||
}
|
||||
|
||||
double LibraryModel::progress(int index) const
|
||||
double HistoryModel::progress(int index) const
|
||||
{
|
||||
if (index < 0 || index >= m_books.size()) return 0.0;
|
||||
return m_books.at(index)->progress();
|
||||
}
|
||||
|
||||
QString LibraryModel::lastOpened(int index) const
|
||||
QString HistoryModel::lastOpened(int index) const
|
||||
{
|
||||
if (index < 0 || index >= m_books.size()) return {};
|
||||
return m_books.at(index)->lastOpened();
|
||||
}
|
||||
|
||||
QList<LibraryBookModel*> LibraryModel::books() const
|
||||
QList<HistoryBookModel*> HistoryModel::books() const
|
||||
{
|
||||
return m_books;
|
||||
}
|
||||
|
||||
void LibraryModel::onBookMetadataLoaded()
|
||||
void HistoryModel::onBookMetadataLoaded()
|
||||
{
|
||||
LibraryBookModel* book = qobject_cast<LibraryBookModel*>(sender());
|
||||
HistoryBookModel* book = qobject_cast<HistoryBookModel*>(sender());
|
||||
if (!book)
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef LIBRARYMODEL_H
|
||||
#define LIBRARYMODEL_H
|
||||
#ifndef HISTORYMODEL_H
|
||||
#define HISTORYMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QList>
|
||||
@@ -7,15 +7,15 @@
|
||||
|
||||
#include "formats/ReaderFactory.h"
|
||||
|
||||
class LibraryBookModel;
|
||||
class HistoryBookModel;
|
||||
|
||||
class LibraryModel : public QAbstractListModel
|
||||
class HistoryModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||
|
||||
public:
|
||||
enum LibraryRoles {
|
||||
enum HistoryRoles {
|
||||
FilePathRole = Qt::UserRole + 1,
|
||||
TitleRole,
|
||||
AuthorRole,
|
||||
@@ -23,10 +23,10 @@ public:
|
||||
LastOpenedRole,
|
||||
CoverImageUrlRole
|
||||
};
|
||||
Q_ENUM(LibraryRoles)
|
||||
Q_ENUM(HistoryRoles)
|
||||
|
||||
explicit LibraryModel(ReaderFactory &factory, QObject *parent = nullptr);
|
||||
~LibraryModel() override;
|
||||
explicit HistoryModel(ReaderFactory &factory, QObject *parent = nullptr);
|
||||
~HistoryModel() override;
|
||||
|
||||
// QAbstractItemModel interface
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
// Convenience overload: sentinel progress < 0 preserves the existing progress value.
|
||||
Q_INVOKABLE void addOrUpdateBook(const QString &filePath, double progress);
|
||||
Q_INVOKABLE void removeBook(const QString &filePath);
|
||||
Q_INVOKABLE LibraryBookModel* findBook(const QString &filePath) const;
|
||||
Q_INVOKABLE HistoryBookModel* findBook(const QString &filePath) const;
|
||||
Q_INVOKABLE void clear();
|
||||
|
||||
// Indexed accessors for persistence (e.g., main.cpp's aboutToQuit loop).
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
QString lastOpened(int index) const;
|
||||
|
||||
// Access to books for saving/loading
|
||||
QList<LibraryBookModel*> books() const;
|
||||
QList<HistoryBookModel*> books() const;
|
||||
|
||||
signals:
|
||||
void countChanged();
|
||||
@@ -59,9 +59,9 @@ private slots:
|
||||
void onBookMetadataLoaded();
|
||||
|
||||
private:
|
||||
QList<LibraryBookModel*> m_books;
|
||||
QList<HistoryBookModel*> m_books;
|
||||
QHash<int, QByteArray> m_roleNames;
|
||||
ReaderFactory &m_factory;
|
||||
};
|
||||
|
||||
#endif // LIBRARYMODEL_H
|
||||
#endif // HISTORYMODEL_H
|
||||
Reference in new issue
Block a user