Rename Library to History
This commit is contained in:
11 files changed
+102
-102
No files matched your search
File renamed without changes.
+8
-8
@@ -42,10 +42,10 @@ set(SOURCES
|
|||||||
src/backend/FormatReader.h
|
src/backend/FormatReader.h
|
||||||
src/backend/AppState.h
|
src/backend/AppState.h
|
||||||
src/backend/AppState.cpp
|
src/backend/AppState.cpp
|
||||||
src/backend/LibraryBookModel.h
|
src/backend/HistoryBookModel.h
|
||||||
src/backend/LibraryBookModel.cpp
|
src/backend/HistoryBookModel.cpp
|
||||||
src/backend/LibraryModel.h
|
src/backend/HistoryModel.h
|
||||||
src/backend/LibraryModel.cpp
|
src/backend/HistoryModel.cpp
|
||||||
src/backend/ReadingModel.h
|
src/backend/ReadingModel.h
|
||||||
src/backend/ReadingModel.cpp
|
src/backend/ReadingModel.cpp
|
||||||
src/backend/state/ReadingPreferences.h
|
src/backend/state/ReadingPreferences.h
|
||||||
@@ -157,7 +157,7 @@ set_source_files_properties(src/qml/components/SideBarButton.qml PROPERTIES QT_R
|
|||||||
set_source_files_properties(src/qml/pages/StarterPage.qml PROPERTIES QT_RESOURCE_ALIAS pages/StarterPage.qml)
|
set_source_files_properties(src/qml/pages/StarterPage.qml PROPERTIES QT_RESOURCE_ALIAS pages/StarterPage.qml)
|
||||||
set_source_files_properties(src/qml/pages/ReaderPage.qml PROPERTIES QT_RESOURCE_ALIAS pages/ReaderPage.qml)
|
set_source_files_properties(src/qml/pages/ReaderPage.qml PROPERTIES QT_RESOURCE_ALIAS pages/ReaderPage.qml)
|
||||||
set_source_files_properties(src/qml/pages/SettingsPage.qml PROPERTIES QT_RESOURCE_ALIAS pages/SettingsPage.qml)
|
set_source_files_properties(src/qml/pages/SettingsPage.qml PROPERTIES QT_RESOURCE_ALIAS pages/SettingsPage.qml)
|
||||||
set_source_files_properties(src/qml/pages/LibraryPage.qml PROPERTIES QT_RESOURCE_ALIAS pages/LibraryPage.qml)
|
set_source_files_properties(src/qml/pages/HistoryPage.qml PROPERTIES QT_RESOURCE_ALIAS pages/HistoryPage.qml)
|
||||||
|
|
||||||
# QML module
|
# QML module
|
||||||
qt_policy(SET QTP0004 NEW)
|
qt_policy(SET QTP0004 NEW)
|
||||||
@@ -179,7 +179,7 @@ qt_add_qml_module(asteria-qt
|
|||||||
src/qml/pages/StarterPage.qml
|
src/qml/pages/StarterPage.qml
|
||||||
src/qml/pages/ReaderPage.qml
|
src/qml/pages/ReaderPage.qml
|
||||||
src/qml/pages/SettingsPage.qml
|
src/qml/pages/SettingsPage.qml
|
||||||
src/qml/pages/LibraryPage.qml
|
src/qml/pages/HistoryPage.qml
|
||||||
RESOURCES
|
RESOURCES
|
||||||
src/assets/moon1.svg
|
src/assets/moon1.svg
|
||||||
src/assets/MaterialIconsOutlined-Regular.otf
|
src/assets/MaterialIconsOutlined-Regular.otf
|
||||||
@@ -248,8 +248,8 @@ add_asteria_test(ReadingModelTest tests/ReadingModelTest.cpp
|
|||||||
src/backend/formats/WebImageProvider.cpp
|
src/backend/formats/WebImageProvider.cpp
|
||||||
src/backend/AppState.cpp
|
src/backend/AppState.cpp
|
||||||
src/backend/state/BookPositionStore.cpp
|
src/backend/state/BookPositionStore.cpp
|
||||||
src/backend/LibraryBookModel.cpp
|
src/backend/HistoryBookModel.cpp
|
||||||
src/backend/LibraryModel.cpp
|
src/backend/HistoryModel.cpp
|
||||||
src/backend/formats/ReaderFactory.cpp
|
src/backend/formats/ReaderFactory.cpp
|
||||||
src/backend/formats/TxtReader.cpp
|
src/backend/formats/TxtReader.cpp
|
||||||
src/backend/formats/EpubReader.cpp)
|
src/backend/formats/EpubReader.cpp)
|
||||||
|
|||||||
@@ -1,42 +1,42 @@
|
|||||||
#include "LibraryBookModel.h"
|
#include "HistoryBookModel.h"
|
||||||
#include "FormatReader.h"
|
#include "FormatReader.h"
|
||||||
#include "formats/ReaderFactory.h"
|
#include "formats/ReaderFactory.h"
|
||||||
#include <QtConcurrent/QtConcurrent>
|
#include <QtConcurrent/QtConcurrent>
|
||||||
|
|
||||||
LibraryBookModel::LibraryBookModel(ReaderFactory &factory, QObject *parent)
|
HistoryBookModel::HistoryBookModel(ReaderFactory &factory, QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_factory(factory)
|
, 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)
|
: QObject(parent)
|
||||||
, m_filePath(filePath)
|
, m_filePath(filePath)
|
||||||
, m_progress(progress)
|
, m_progress(progress)
|
||||||
, m_lastOpened(lastOpened)
|
, m_lastOpened(lastOpened)
|
||||||
, m_factory(factory)
|
, 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())
|
if (m_metadataFuture.isRunning())
|
||||||
m_metadataFuture.waitForFinished();
|
m_metadataFuture.waitForFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LibraryBookModel::filePath() const
|
QString HistoryBookModel::filePath() const
|
||||||
{
|
{
|
||||||
return m_filePath;
|
return m_filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
double LibraryBookModel::progress() const
|
double HistoryBookModel::progress() const
|
||||||
{
|
{
|
||||||
return m_progress;
|
return m_progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryBookModel::setProgress(double progress)
|
void HistoryBookModel::setProgress(double progress)
|
||||||
{
|
{
|
||||||
if (qFuzzyCompare(m_progress, progress))
|
if (qFuzzyCompare(m_progress, progress))
|
||||||
return;
|
return;
|
||||||
@@ -44,12 +44,12 @@ void LibraryBookModel::setProgress(double progress)
|
|||||||
emit progressChanged();
|
emit progressChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LibraryBookModel::lastOpened() const
|
QString HistoryBookModel::lastOpened() const
|
||||||
{
|
{
|
||||||
return m_lastOpened;
|
return m_lastOpened;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryBookModel::setLastOpened(const QString &lastOpened)
|
void HistoryBookModel::setLastOpened(const QString &lastOpened)
|
||||||
{
|
{
|
||||||
if (m_lastOpened == lastOpened)
|
if (m_lastOpened == lastOpened)
|
||||||
return;
|
return;
|
||||||
@@ -57,27 +57,27 @@ void LibraryBookModel::setLastOpened(const QString &lastOpened)
|
|||||||
emit lastOpenedChanged();
|
emit lastOpenedChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LibraryBookModel::title() const
|
QString HistoryBookModel::title() const
|
||||||
{
|
{
|
||||||
return m_title;
|
return m_title;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LibraryBookModel::author() const
|
QString HistoryBookModel::author() const
|
||||||
{
|
{
|
||||||
return m_author;
|
return m_author;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LibraryBookModel::coverImageUrl() const
|
QString HistoryBookModel::coverImageUrl() const
|
||||||
{
|
{
|
||||||
return m_coverImageUrl;
|
return m_coverImageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryBookModel::loadMetadata()
|
void HistoryBookModel::loadMetadata()
|
||||||
{
|
{
|
||||||
if (m_metadataLoaded || m_filePath.isEmpty() || m_metadataFuture.isRunning())
|
if (m_metadataLoaded || m_filePath.isEmpty() || m_metadataFuture.isRunning())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPointer<LibraryBookModel> self = this;
|
QPointer<HistoryBookModel> self = this;
|
||||||
QString filePath = m_filePath;
|
QString filePath = m_filePath;
|
||||||
|
|
||||||
ReaderFactory *factory = &m_factory;
|
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
|
// 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())
|
if (!m_coverImageUrl.isEmpty() || m_filePath.isEmpty())
|
||||||
return;
|
return;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef LIBRARYBOOKMODEL_H
|
#ifndef HISTORYBOOKMODEL_H
|
||||||
#define LIBRARYBOOKMODEL_H
|
#define HISTORYBOOKMODEL_H
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
class FormatReader;
|
class FormatReader;
|
||||||
|
|
||||||
class LibraryBookModel : public QObject {
|
class HistoryBookModel : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString filePath READ filePath CONSTANT)
|
Q_PROPERTY(QString filePath READ filePath CONSTANT)
|
||||||
Q_PROPERTY(double progress READ progress WRITE setProgress NOTIFY progressChanged)
|
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)
|
Q_PROPERTY(QString coverImageUrl READ coverImageUrl NOTIFY coverImageLoaded)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit LibraryBookModel(ReaderFactory &factory, QObject *parent = nullptr);
|
explicit HistoryBookModel(ReaderFactory &factory, QObject *parent = nullptr);
|
||||||
explicit LibraryBookModel(const QString &filePath, double progress, const QString &lastOpened, ReaderFactory &factory, QObject *parent = nullptr);
|
explicit HistoryBookModel(const QString &filePath, double progress, const QString &lastOpened, ReaderFactory &factory, QObject *parent = nullptr);
|
||||||
~LibraryBookModel() override;
|
~HistoryBookModel() override;
|
||||||
|
|
||||||
QString filePath() const;
|
QString filePath() const;
|
||||||
double progress() const;
|
double progress() const;
|
||||||
@@ -59,4 +59,4 @@ private:
|
|||||||
ReaderFactory &m_factory;
|
ReaderFactory &m_factory;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LIBRARYBOOKMODEL_H
|
#endif // HISTORYBOOKMODEL_H
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#include "LibraryModel.h"
|
#include "HistoryModel.h"
|
||||||
#include "LibraryBookModel.h"
|
#include "HistoryBookModel.h"
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
||||||
LibraryModel::LibraryModel(ReaderFactory &factory, QObject *parent)
|
HistoryModel::HistoryModel(ReaderFactory &factory, QObject *parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
, m_factory(factory)
|
, m_factory(factory)
|
||||||
{
|
{
|
||||||
@@ -15,24 +15,24 @@ LibraryModel::LibraryModel(ReaderFactory &factory, QObject *parent)
|
|||||||
m_roleNames[CoverImageUrlRole] = "coverImageUrl";
|
m_roleNames[CoverImageUrlRole] = "coverImageUrl";
|
||||||
}
|
}
|
||||||
|
|
||||||
LibraryModel::~LibraryModel()
|
HistoryModel::~HistoryModel()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
int LibraryModel::rowCount(const QModelIndex &parent) const
|
int HistoryModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (parent.isValid())
|
if (parent.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
return m_books.count();
|
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())
|
if (!index.isValid() || index.row() < 0 || index.row() >= m_books.count())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
LibraryBookModel* book = m_books.at(index.row());
|
HistoryBookModel* book = m_books.at(index.row());
|
||||||
if (!book)
|
if (!book)
|
||||||
return QVariant();
|
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())
|
if (!index.isValid() || index.row() < 0 || index.row() >= m_books.count())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
LibraryBookModel* book = m_books.at(index.row());
|
HistoryBookModel* book = m_books.at(index.row());
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case ProgressRole:
|
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;
|
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
|
// Check if book already exists
|
||||||
for (int i = 0; i < m_books.size(); i++) {
|
for (int i = 0; i < m_books.size(); i++) {
|
||||||
if (m_books[i]->filePath() == filePath) {
|
if (m_books[i]->filePath() == filePath) {
|
||||||
LibraryBookModel* existingBook = m_books[i];
|
HistoryBookModel* existingBook = m_books[i];
|
||||||
existingBook->setProgress(progress);
|
existingBook->setProgress(progress);
|
||||||
existingBook->setLastOpened(lastOpened);
|
existingBook->setLastOpened(lastOpened);
|
||||||
|
|
||||||
@@ -98,9 +98,9 @@ void LibraryModel::addOrUpdateBook(const QString &filePath, double progress, con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// New book — LibraryModel takes ownership via parent
|
// New book — HistoryModel takes ownership via parent
|
||||||
auto* book = new LibraryBookModel(filePath, progress, lastOpened, m_factory, this);
|
auto* book = new HistoryBookModel(filePath, progress, lastOpened, m_factory, this);
|
||||||
connect(book, &LibraryBookModel::metadataLoaded, this, &LibraryModel::onBookMetadataLoaded);
|
connect(book, &HistoryBookModel::metadataLoaded, this, &HistoryModel::onBookMetadataLoaded);
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), 0, 0);
|
beginInsertRows(QModelIndex(), 0, 0);
|
||||||
m_books.prepend(book);
|
m_books.prepend(book);
|
||||||
@@ -110,14 +110,14 @@ void LibraryModel::addOrUpdateBook(const QString &filePath, double progress, con
|
|||||||
book->loadMetadata();
|
book->loadMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryModel::removeBook(const QString &filePath)
|
void HistoryModel::removeBook(const QString &filePath)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_books.size(); i++) {
|
for (int i = 0; i < m_books.size(); i++) {
|
||||||
if (m_books[i]->filePath() == filePath) {
|
if (m_books[i]->filePath() == filePath) {
|
||||||
LibraryBookModel* book = m_books[i];
|
HistoryBookModel* book = m_books[i];
|
||||||
|
|
||||||
// Disconnect signals
|
// Disconnect signals
|
||||||
disconnect(book, &LibraryBookModel::metadataLoaded, this, &LibraryModel::onBookMetadataLoaded);
|
disconnect(book, &HistoryBookModel::metadataLoaded, this, &HistoryModel::onBookMetadataLoaded);
|
||||||
|
|
||||||
beginRemoveRows(QModelIndex(), i, i);
|
beginRemoveRows(QModelIndex(), i, i);
|
||||||
m_books.removeAt(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) {
|
if (book->filePath() == filePath) {
|
||||||
return book;
|
return book;
|
||||||
}
|
}
|
||||||
@@ -140,7 +140,7 @@ LibraryBookModel* LibraryModel::findBook(const QString &filePath) const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryModel::clear()
|
void HistoryModel::clear()
|
||||||
{
|
{
|
||||||
if (m_books.isEmpty())
|
if (m_books.isEmpty())
|
||||||
return;
|
return;
|
||||||
@@ -148,8 +148,8 @@ void LibraryModel::clear()
|
|||||||
beginRemoveRows(QModelIndex(), 0, m_books.size() - 1);
|
beginRemoveRows(QModelIndex(), 0, m_books.size() - 1);
|
||||||
|
|
||||||
// Disconnect and delete all books
|
// Disconnect and delete all books
|
||||||
for (LibraryBookModel* book : m_books) {
|
for (HistoryBookModel* book : m_books) {
|
||||||
disconnect(book, &LibraryBookModel::metadataLoaded, this, &LibraryModel::onBookMetadataLoaded);
|
disconnect(book, &HistoryBookModel::metadataLoaded, this, &HistoryModel::onBookMetadataLoaded);
|
||||||
book->deleteLater();
|
book->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,44 +159,44 @@ void LibraryModel::clear()
|
|||||||
emit countChanged();
|
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"
|
// Sentinel: progress < 0 means "preserve the existing progress value"
|
||||||
double resolvedProgress = progress;
|
double resolvedProgress = progress;
|
||||||
if (progress < 0.0) {
|
if (progress < 0.0) {
|
||||||
LibraryBookModel *existing = findBook(filePath);
|
HistoryBookModel *existing = findBook(filePath);
|
||||||
resolvedProgress = existing ? existing->progress() : 0.0;
|
resolvedProgress = existing ? existing->progress() : 0.0;
|
||||||
}
|
}
|
||||||
addOrUpdateBook(filePath, resolvedProgress,
|
addOrUpdateBook(filePath, resolvedProgress,
|
||||||
QDateTime::currentDateTime().toString(Qt::ISODate));
|
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 {};
|
if (index < 0 || index >= m_books.size()) return {};
|
||||||
return m_books.at(index)->filePath();
|
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;
|
if (index < 0 || index >= m_books.size()) return 0.0;
|
||||||
return m_books.at(index)->progress();
|
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 {};
|
if (index < 0 || index >= m_books.size()) return {};
|
||||||
return m_books.at(index)->lastOpened();
|
return m_books.at(index)->lastOpened();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<LibraryBookModel*> LibraryModel::books() const
|
QList<HistoryBookModel*> HistoryModel::books() const
|
||||||
{
|
{
|
||||||
return m_books;
|
return m_books;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryModel::onBookMetadataLoaded()
|
void HistoryModel::onBookMetadataLoaded()
|
||||||
{
|
{
|
||||||
LibraryBookModel* book = qobject_cast<LibraryBookModel*>(sender());
|
HistoryBookModel* book = qobject_cast<HistoryBookModel*>(sender());
|
||||||
if (!book)
|
if (!book)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef LIBRARYMODEL_H
|
#ifndef HISTORYMODEL_H
|
||||||
#define LIBRARYMODEL_H
|
#define HISTORYMODEL_H
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
@@ -7,15 +7,15 @@
|
|||||||
|
|
||||||
#include "formats/ReaderFactory.h"
|
#include "formats/ReaderFactory.h"
|
||||||
|
|
||||||
class LibraryBookModel;
|
class HistoryBookModel;
|
||||||
|
|
||||||
class LibraryModel : public QAbstractListModel
|
class HistoryModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum LibraryRoles {
|
enum HistoryRoles {
|
||||||
FilePathRole = Qt::UserRole + 1,
|
FilePathRole = Qt::UserRole + 1,
|
||||||
TitleRole,
|
TitleRole,
|
||||||
AuthorRole,
|
AuthorRole,
|
||||||
@@ -23,10 +23,10 @@ public:
|
|||||||
LastOpenedRole,
|
LastOpenedRole,
|
||||||
CoverImageUrlRole
|
CoverImageUrlRole
|
||||||
};
|
};
|
||||||
Q_ENUM(LibraryRoles)
|
Q_ENUM(HistoryRoles)
|
||||||
|
|
||||||
explicit LibraryModel(ReaderFactory &factory, QObject *parent = nullptr);
|
explicit HistoryModel(ReaderFactory &factory, QObject *parent = nullptr);
|
||||||
~LibraryModel() override;
|
~HistoryModel() override;
|
||||||
|
|
||||||
// QAbstractItemModel interface
|
// QAbstractItemModel interface
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
@@ -41,7 +41,7 @@ public:
|
|||||||
// Convenience overload: sentinel progress < 0 preserves the existing progress value.
|
// Convenience overload: sentinel progress < 0 preserves the existing progress value.
|
||||||
Q_INVOKABLE void addOrUpdateBook(const QString &filePath, double progress);
|
Q_INVOKABLE void addOrUpdateBook(const QString &filePath, double progress);
|
||||||
Q_INVOKABLE void removeBook(const QString &filePath);
|
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();
|
Q_INVOKABLE void clear();
|
||||||
|
|
||||||
// Indexed accessors for persistence (e.g., main.cpp's aboutToQuit loop).
|
// Indexed accessors for persistence (e.g., main.cpp's aboutToQuit loop).
|
||||||
@@ -50,7 +50,7 @@ public:
|
|||||||
QString lastOpened(int index) const;
|
QString lastOpened(int index) const;
|
||||||
|
|
||||||
// Access to books for saving/loading
|
// Access to books for saving/loading
|
||||||
QList<LibraryBookModel*> books() const;
|
QList<HistoryBookModel*> books() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void countChanged();
|
void countChanged();
|
||||||
@@ -59,9 +59,9 @@ private slots:
|
|||||||
void onBookMetadataLoaded();
|
void onBookMetadataLoaded();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<LibraryBookModel*> m_books;
|
QList<HistoryBookModel*> m_books;
|
||||||
QHash<int, QByteArray> m_roleNames;
|
QHash<int, QByteArray> m_roleNames;
|
||||||
ReaderFactory &m_factory;
|
ReaderFactory &m_factory;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LIBRARYMODEL_H
|
#endif // HISTORYMODEL_H
|
||||||
+13
-13
@@ -14,7 +14,7 @@
|
|||||||
#include "backend/formats/ImageLoaderFactory.h"
|
#include "backend/formats/ImageLoaderFactory.h"
|
||||||
#include "backend/formats/ImageProviderFactory.h"
|
#include "backend/formats/ImageProviderFactory.h"
|
||||||
#include "backend/formats/WebImageProvider.h"
|
#include "backend/formats/WebImageProvider.h"
|
||||||
#include "backend/LibraryModel.h"
|
#include "backend/HistoryModel.h"
|
||||||
#include "backend/ReadingModel.h"
|
#include "backend/ReadingModel.h"
|
||||||
#include "backend/NativeFileDialogService.h"
|
#include "backend/NativeFileDialogService.h"
|
||||||
#include "backend/formats/ReaderFactory.h"
|
#include "backend/formats/ReaderFactory.h"
|
||||||
@@ -103,14 +103,14 @@ int main(int argc, char *argv[])
|
|||||||
[] { return std::make_unique<EpubReader>(); },
|
[] { return std::make_unique<EpubReader>(); },
|
||||||
});
|
});
|
||||||
|
|
||||||
LibraryModel libraryModel(readerFactory);
|
HistoryModel historyModel(readerFactory);
|
||||||
for (const QVariantMap &entry : appState.loadArray(QStringLiteral("library"))) {
|
for (const QVariantMap &entry : appState.loadArray(QStringLiteral("history"))) {
|
||||||
const QString fp = entry.value(QStringLiteral("filePath")).toString();
|
const QString fp = entry.value(QStringLiteral("filePath")).toString();
|
||||||
if (fp.isEmpty()) continue;
|
if (fp.isEmpty()) continue;
|
||||||
double progress = entry.value(QStringLiteral("progress"), 0.0).toDouble();
|
double progress = entry.value(QStringLiteral("progress"), 0.0).toDouble();
|
||||||
progress = qBound(0.0, progress, 1.0);
|
progress = qBound(0.0, progress, 1.0);
|
||||||
const QString lo = entry.value(QStringLiteral("lastOpened")).toString();
|
const QString lo = entry.value(QStringLiteral("lastOpened")).toString();
|
||||||
libraryModel.addOrUpdateBook(fp, progress, lo);
|
historyModel.addOrUpdateBook(fp, progress, lo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command-line override: treat first argument as the file to open on startup
|
// Command-line override: treat first argument as the file to open on startup
|
||||||
@@ -149,7 +149,7 @@ int main(int argc, char *argv[])
|
|||||||
engine.rootContext()->setContextProperty(QStringLiteral("readingModel"), &readingModel);
|
engine.rootContext()->setContextProperty(QStringLiteral("readingModel"), &readingModel);
|
||||||
engine.rootContext()->setContextProperty(QStringLiteral("readingPreferences"), &readingPreferences);
|
engine.rootContext()->setContextProperty(QStringLiteral("readingPreferences"), &readingPreferences);
|
||||||
engine.rootContext()->setContextProperty(QStringLiteral("uiState"), &uiState);
|
engine.rootContext()->setContextProperty(QStringLiteral("uiState"), &uiState);
|
||||||
engine.rootContext()->setContextProperty(QStringLiteral("libraryModel"), &libraryModel);
|
engine.rootContext()->setContextProperty(QStringLiteral("historyModel"), &historyModel);
|
||||||
|
|
||||||
// --- Cross-class signal wiring ---
|
// --- Cross-class signal wiring ---
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ int main(int argc, char *argv[])
|
|||||||
// Scroll position is handled by PageView's scroll tracker via book.saveCurrentPosition().
|
// Scroll position is handled by PageView's scroll tracker via book.saveCurrentPosition().
|
||||||
QObject::connect(&book, &Book::willOpenNewBook, [&]{
|
QObject::connect(&book, &Book::willOpenNewBook, [&]{
|
||||||
if (book.hasBook())
|
if (book.hasBook())
|
||||||
libraryModel.addOrUpdateBook(book.filePath(), readingModel.progress());
|
historyModel.addOrUpdateBook(book.filePath(), readingModel.progress());
|
||||||
});
|
});
|
||||||
|
|
||||||
// After the new reader is installed: wire up image provider + ReadingModel
|
// After the new reader is installed: wire up image provider + ReadingModel
|
||||||
@@ -201,7 +201,7 @@ int main(int argc, char *argv[])
|
|||||||
readingModel.measure(true);
|
readingModel.measure(true);
|
||||||
|
|
||||||
uiState.setLastFilePath(filePath);
|
uiState.setLastFilePath(filePath);
|
||||||
libraryModel.addOrUpdateBook(filePath, -1.0);
|
historyModel.addOrUpdateBook(filePath, -1.0);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Propagate content-width changes to image provider + reading model.
|
// Propagate content-width changes to image provider + reading model.
|
||||||
@@ -216,7 +216,7 @@ int main(int argc, char *argv[])
|
|||||||
// Scroll position was last saved by PageView's scroll tracker; we save library progress here.
|
// Scroll position was last saved by PageView's scroll tracker; we save library progress here.
|
||||||
QObject::connect(&app, &QCoreApplication::aboutToQuit, [&]{
|
QObject::connect(&app, &QCoreApplication::aboutToQuit, [&]{
|
||||||
if (book.hasBook()) {
|
if (book.hasBook()) {
|
||||||
libraryModel.addOrUpdateBook(book.filePath(), readingModel.progress());
|
historyModel.addOrUpdateBook(book.filePath(), readingModel.progress());
|
||||||
uiState.setLastFilePath(book.filePath());
|
uiState.setLastFilePath(book.filePath());
|
||||||
} else {
|
} else {
|
||||||
uiState.setLastFilePath(QString());
|
uiState.setLastFilePath(QString());
|
||||||
@@ -226,14 +226,14 @@ int main(int argc, char *argv[])
|
|||||||
uiState.save();
|
uiState.save();
|
||||||
|
|
||||||
QList<QVariantMap> items;
|
QList<QVariantMap> items;
|
||||||
for (int i = 0; i < libraryModel.rowCount(); ++i) {
|
for (int i = 0; i < historyModel.rowCount(); ++i) {
|
||||||
items.append({
|
items.append({
|
||||||
{QStringLiteral("filePath"), libraryModel.filePath(i)},
|
{QStringLiteral("filePath"), historyModel.filePath(i)},
|
||||||
{QStringLiteral("progress"), libraryModel.progress(i)},
|
{QStringLiteral("progress"), historyModel.progress(i)},
|
||||||
{QStringLiteral("lastOpened"), libraryModel.lastOpened(i)},
|
{QStringLiteral("lastOpened"), historyModel.lastOpened(i)},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
appState.saveArray(QStringLiteral("library"), items);
|
appState.saveArray(QStringLiteral("history"), items);
|
||||||
|
|
||||||
qInfo() << "Settings saved to:" << settings.fileName();
|
qInfo() << "Settings saved to:" << settings.fileName();
|
||||||
});
|
});
|
||||||
|
|||||||
+4
-4
@@ -134,9 +134,9 @@ ApplicationWindow {
|
|||||||
visible: window.currentPage === "settings"
|
visible: window.currentPage === "settings"
|
||||||
}
|
}
|
||||||
|
|
||||||
LibraryPage {
|
HistoryPage {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
visible: window.currentPage === "library"
|
visible: window.currentPage === "history"
|
||||||
}
|
}
|
||||||
|
|
||||||
BusyIndicator {
|
BusyIndicator {
|
||||||
@@ -171,7 +171,7 @@ ApplicationWindow {
|
|||||||
if (window._startupRestore) {
|
if (window._startupRestore) {
|
||||||
window._startupRestore = false
|
window._startupRestore = false
|
||||||
var savedPage = uiState.lastPage
|
var savedPage = uiState.lastPage
|
||||||
if (savedPage === "library" || savedPage === "settings")
|
if (savedPage === "history" || savedPage === "settings")
|
||||||
window.currentPage = savedPage
|
window.currentPage = savedPage
|
||||||
else
|
else
|
||||||
window.currentPage = "reader"
|
window.currentPage = "reader"
|
||||||
@@ -277,7 +277,7 @@ ApplicationWindow {
|
|||||||
book.openFromPath(uiState.lastFilePath)
|
book.openFromPath(uiState.lastFilePath)
|
||||||
} else {
|
} else {
|
||||||
var savedPage = uiState.lastPage
|
var savedPage = uiState.lastPage
|
||||||
if (savedPage === "library" || savedPage === "settings")
|
if (savedPage === "history" || savedPage === "settings")
|
||||||
window.currentPage = savedPage
|
window.currentPage = savedPage
|
||||||
window.sidebarOpen = true
|
window.sidebarOpen = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,8 +62,8 @@ Rectangle {
|
|||||||
|
|
||||||
SideBarButton {
|
SideBarButton {
|
||||||
iconText: "\ue02f"
|
iconText: "\ue02f"
|
||||||
title: "Library"
|
title: "History"
|
||||||
onClicked: sidebar.navigateTo("library")
|
onClicked: sidebar.navigateTo("history")
|
||||||
}
|
}
|
||||||
|
|
||||||
SideBarButton {
|
SideBarButton {
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ Rectangle {
|
|||||||
color: ThemeManager.currentTheme.backgroundDefault
|
color: ThemeManager.currentTheme.backgroundDefault
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
visible: libraryModel.count === 0
|
visible: historyModel.count === 0
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
text: "No books read yet.\nOpen a book to start your library."
|
text: "No books read yet.\nOpen a book to start your history."
|
||||||
horizontalAlignment: Text.AlignHCenter
|
horizontalAlignment: Text.AlignHCenter
|
||||||
color: ThemeManager.currentTheme.dimText
|
color: ThemeManager.currentTheme.dimText
|
||||||
font.pixelSize: 14
|
font.pixelSize: 14
|
||||||
@@ -16,12 +16,12 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
visible: libraryModel.count > 0
|
visible: historyModel.count > 0
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: 16
|
anchors.margins: 16
|
||||||
spacing: 8
|
spacing: 8
|
||||||
clip: true
|
clip: true
|
||||||
model: libraryModel
|
model: historyModel
|
||||||
|
|
||||||
delegate: Rectangle {
|
delegate: Rectangle {
|
||||||
id: bookRow
|
id: bookRow
|
||||||
@@ -92,7 +92,7 @@ Rectangle {
|
|||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
}
|
}
|
||||||
background: Item {}
|
background: Item {}
|
||||||
onClicked: libraryModel.removeBook(filePath)
|
onClicked: historyModel.removeBook(filePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,9 +84,9 @@ private slots:
|
|||||||
{QStringLiteral("progress"), 0.5}});
|
{QStringLiteral("progress"), 0.5}});
|
||||||
items.append({{QStringLiteral("filePath"), QStringLiteral("/c/d.txt")},
|
items.append({{QStringLiteral("filePath"), QStringLiteral("/c/d.txt")},
|
||||||
{QStringLiteral("progress"), 0.0}});
|
{QStringLiteral("progress"), 0.0}});
|
||||||
state.saveArray(QStringLiteral("library"), items);
|
state.saveArray(QStringLiteral("history"), items);
|
||||||
|
|
||||||
const auto loaded = state.loadArray(QStringLiteral("library"));
|
const auto loaded = state.loadArray(QStringLiteral("history"));
|
||||||
QCOMPARE(loaded.size(), 2);
|
QCOMPARE(loaded.size(), 2);
|
||||||
QCOMPARE(loaded[0].value(QStringLiteral("filePath")).toString(), QStringLiteral("/a/b.epub"));
|
QCOMPARE(loaded[0].value(QStringLiteral("filePath")).toString(), QStringLiteral("/a/b.epub"));
|
||||||
QCOMPARE(loaded[0].value(QStringLiteral("progress")).toDouble(), 0.5);
|
QCOMPARE(loaded[0].value(QStringLiteral("progress")).toDouble(), 0.5);
|
||||||
|
|||||||
Reference in new issue
Block a user