mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 03:26:05 -04:00
Introduced BookInfo & BookInfoList typedefs
This commit is contained in:
parent
d38ec6bfa3
commit
faf8496095
@ -77,10 +77,10 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader,
|
||||
setLanguages();
|
||||
}
|
||||
|
||||
QList<QMap<QString, QVariant>> ContentManager::getBooksList()
|
||||
ContentManager::BookInfoList ContentManager::getBooksList()
|
||||
{
|
||||
const auto bookIds = getBookIds();
|
||||
QList<QMap<QString, QVariant>> bookList;
|
||||
BookInfoList bookList;
|
||||
QStringList keys = {"title", "tags", "date", "id", "size", "description", "faviconUrl"};
|
||||
QIcon bookIcon;
|
||||
for (auto bookId : bookIds) {
|
||||
@ -216,9 +216,9 @@ void ContentManager::setLanguages()
|
||||
}
|
||||
|
||||
#define ADD_V(KEY, METH) {if(key==KEY) values.insert(key, QString::fromStdString((b->METH())));}
|
||||
QMap<QString, QVariant> ContentManager::getBookInfos(QString id, const QStringList &keys)
|
||||
ContentManager::BookInfo ContentManager::getBookInfos(QString id, const QStringList &keys)
|
||||
{
|
||||
QMap<QString, QVariant> values;
|
||||
BookInfo values;
|
||||
const kiwix::Book* b = [=]()->const kiwix::Book* {
|
||||
try {
|
||||
return &mp_library->getBookById(id);
|
||||
|
@ -17,9 +17,13 @@ class ContentManager : public QObject
|
||||
Q_PROPERTY(QStringList downloadIds READ getDownloadIds NOTIFY downloadsChanged)
|
||||
Q_PROPERTY(bool isLocal MEMBER m_local READ isLocal WRITE setLocal NOTIFY localChanged)
|
||||
|
||||
public:
|
||||
public: // types
|
||||
typedef QList<QPair<QString, QString>> LanguageList;
|
||||
typedef QList<QPair<QString, QString>> FilterList;
|
||||
typedef ContentManagerModel::BookInfo BookInfo;
|
||||
typedef ContentManagerModel::BookInfoList BookInfoList;
|
||||
|
||||
public: // functions
|
||||
explicit ContentManager(Library* library, kiwix::Downloader *downloader, QObject *parent = nullptr);
|
||||
virtual ~ContentManager() {}
|
||||
|
||||
@ -51,7 +55,7 @@ private:
|
||||
|
||||
QStringList getBookIds();
|
||||
void eraseBookFilesFromComputer(const QString dirPath, const QString filename, const bool moveToTrash);
|
||||
QList<QMap<QString, QVariant>> getBooksList();
|
||||
BookInfoList getBooksList();
|
||||
ContentManagerModel *managerModel;
|
||||
QMutex remoteLibraryLocker;
|
||||
void setCategories();
|
||||
@ -71,7 +75,7 @@ signals:
|
||||
|
||||
public slots:
|
||||
QStringList getTranslations(const QStringList &keys);
|
||||
QMap<QString, QVariant> getBookInfos(QString id, const QStringList &keys);
|
||||
BookInfo getBookInfos(QString id, const QStringList &keys);
|
||||
void openBook(const QString& id);
|
||||
QMap<QString, QVariant> updateDownloadInfos(QString id, const QStringList& keys);
|
||||
QString downloadBook(const QString& id);
|
||||
|
@ -102,7 +102,7 @@ QVariant ContentManagerModel::headerData(int section, Qt::Orientation orientatio
|
||||
}
|
||||
}
|
||||
|
||||
void ContentManagerModel::setBooksData(const QList<QMap<QString, QVariant>>& data)
|
||||
void ContentManagerModel::setBooksData(const BookInfoList& data)
|
||||
{
|
||||
m_data = data;
|
||||
rootNode = std::shared_ptr<RowNode>(new RowNode({tr("Icon"), tr("Name"), tr("Date"), tr("Size"), tr("Content Type"), tr("Download")}, "", std::weak_ptr<RowNode>()));
|
||||
@ -124,7 +124,7 @@ QString convertToUnits(QString size)
|
||||
return preciseBytes + " " + units[unitIndex];
|
||||
}
|
||||
|
||||
std::shared_ptr<RowNode> ContentManagerModel::createNode(QMap<QString, QVariant> bookItem, QMap<QString, QByteArray> iconMap) const
|
||||
std::shared_ptr<RowNode> ContentManagerModel::createNode(BookInfo bookItem, QMap<QString, QByteArray> iconMap) const
|
||||
{
|
||||
auto faviconUrl = "https://" + bookItem["faviconUrl"].toString();
|
||||
QString id = bookItem["id"].toString();
|
||||
|
@ -16,7 +16,11 @@ class ContentManagerModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public: // types
|
||||
typedef QMap<QString, QVariant> BookInfo;
|
||||
typedef QList<BookInfo> BookInfoList;
|
||||
|
||||
public: // functions
|
||||
explicit ContentManagerModel(QObject *parent = nullptr);
|
||||
~ContentManagerModel();
|
||||
|
||||
@ -29,13 +33,13 @@ public:
|
||||
QModelIndex parent(const QModelIndex &index) const override;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
void setBooksData(const QList<QMap<QString, QVariant>>& data);
|
||||
void setBooksData(const BookInfoList& data);
|
||||
void setupNodes();
|
||||
bool hasChildren(const QModelIndex &parent) const override;
|
||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
||||
void refreshIcons();
|
||||
|
||||
std::shared_ptr<RowNode> createNode(QMap<QString, QVariant> bookItem, QMap<QString, QByteArray> iconMap) const;
|
||||
std::shared_ptr<RowNode> createNode(BookInfo bookItem, QMap<QString, QByteArray> iconMap) const;
|
||||
|
||||
public slots:
|
||||
void updateImage(QModelIndex index, QString url, QByteArray imageData);
|
||||
@ -44,12 +48,12 @@ public slots:
|
||||
void resumeDownload(QModelIndex index);
|
||||
void cancelDownload(QModelIndex index);
|
||||
|
||||
protected:
|
||||
protected: // functions
|
||||
bool canFetchMore(const QModelIndex &parent) const override;
|
||||
void fetchMore(const QModelIndex &parent) override;
|
||||
|
||||
private:
|
||||
QList<QMap<QString, QVariant>> m_data;
|
||||
private: // data
|
||||
BookInfoList m_data;
|
||||
std::shared_ptr<RowNode> rootNode;
|
||||
int zimCount = 0;
|
||||
ThumbnailDownloader td;
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#include "node.h"
|
||||
#include <QList>
|
||||
#include "contentmanagermodel.h"
|
||||
#include <QIcon>
|
||||
#include "kiwix/book.h"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user