feat(browser): support display subfolders
This commit is contained in:
parent
15cef03f08
commit
1f7adc2a3a
@ -16,6 +16,8 @@ qt_add_executable(pcomic
|
|||||||
dataitems/libraryitem.h
|
dataitems/libraryitem.h
|
||||||
dataitems/comicitem.cpp
|
dataitems/comicitem.cpp
|
||||||
dataitems/comicitem.h
|
dataitems/comicitem.h
|
||||||
|
dataitems/folderitem.cpp
|
||||||
|
dataitems/folderitem.h
|
||||||
)
|
)
|
||||||
|
|
||||||
qt_add_qml_module(pcomic
|
qt_add_qml_module(pcomic
|
||||||
|
@ -1,13 +1,46 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
|
import net.blumia.pineapple.comic.reader
|
||||||
|
|
||||||
ColumnLayout {
|
Item {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
|
Drawer {
|
||||||
|
id: drawer
|
||||||
|
width: Math.min(0.66 * parent.width, 320)
|
||||||
|
height: parent.height
|
||||||
|
|
||||||
|
ListView {
|
||||||
|
id: listView
|
||||||
|
clip: true
|
||||||
|
anchors.fill: parent
|
||||||
|
model: AppController.foldersModel
|
||||||
|
delegate: ItemDelegate {
|
||||||
|
text: model.display
|
||||||
|
width: listView.width
|
||||||
|
onClicked: function() {
|
||||||
|
AppController.updateComicsInFolder(model.folderId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
anchors.fill: parent
|
||||||
|
RowLayout {
|
||||||
|
ToolButton {
|
||||||
|
flat: true
|
||||||
|
icon.name: "folder-open"
|
||||||
|
onClicked: function() {
|
||||||
|
drawer.open();
|
||||||
|
}
|
||||||
|
}
|
||||||
Label {
|
Label {
|
||||||
text: "Comics"
|
text: "Comics"
|
||||||
font.pixelSize: 20
|
font.pixelSize: 20
|
||||||
}
|
}
|
||||||
|
}
|
||||||
GridView {
|
GridView {
|
||||||
id: gridView
|
id: gridView
|
||||||
clip: true
|
clip: true
|
||||||
@ -39,4 +72,5 @@ ColumnLayout {
|
|||||||
Component.onCompleted: function() {
|
Component.onCompleted: function() {
|
||||||
AppController.updateComicsInFolder()
|
AppController.updateComicsInFolder()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "dataitems/libraryitem.h"
|
#include "dataitems/libraryitem.h"
|
||||||
#include "dataitems/comicitem.h"
|
#include "dataitems/comicitem.h"
|
||||||
|
#include "dataitems/folderitem.h"
|
||||||
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
@ -17,20 +18,11 @@ AppController::AppController(QObject *parent)
|
|||||||
, m_restAccessManager(new QRestAccessManager(m_networkAccessManager, this))
|
, m_restAccessManager(new QRestAccessManager(m_networkAccessManager, this))
|
||||||
, m_librariesModel(new QStandardItemModel(this))
|
, m_librariesModel(new QStandardItemModel(this))
|
||||||
, m_comicsModel(new QStandardItemModel(this))
|
, m_comicsModel(new QStandardItemModel(this))
|
||||||
|
, m_foldersModel(new QStandardItemModel(this))
|
||||||
{
|
{
|
||||||
m_librariesModel->setItemRoleNames({
|
m_librariesModel->setItemRoleNames(LibraryItem::roleNames());
|
||||||
{Qt::DisplayRole, "display"},
|
m_comicsModel->setItemRoleNames(ComicItem::roleNames());
|
||||||
{LibraryItem::IdRole, "libraryId"},
|
m_foldersModel->setItemRoleNames(FolderItem::roleNames());
|
||||||
{LibraryItem::UuidRole, "uuid"},
|
|
||||||
});
|
|
||||||
m_comicsModel->setItemRoleNames({
|
|
||||||
{Qt::DisplayRole, "display"},
|
|
||||||
{ComicItem::IdRole, "comicId"},
|
|
||||||
{ComicItem::HashRole, "hash"},
|
|
||||||
{ComicItem::PageCountRole, "pageCount"},
|
|
||||||
{ComicItem::CurrentPageRole, "currentPage"},
|
|
||||||
{ComicItem::TypeRole, "type"},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppController::connectServer(QUrl serverBaseUrl)
|
void AppController::connectServer(QUrl serverBaseUrl)
|
||||||
@ -72,8 +64,9 @@ void AppController::updateLibraries()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppController::updateComicsInFolder(int folderId)
|
void AppController::updateComicsInFolder(QString folderId)
|
||||||
{
|
{
|
||||||
|
qDebug() << folderId;
|
||||||
m_restAccessManager->get(apiFactory().createRequest(QString("library/%1/folder/%2/content")
|
m_restAccessManager->get(apiFactory().createRequest(QString("library/%1/folder/%2/content")
|
||||||
.arg(m_currentLibraryId).arg(folderId)),
|
.arg(m_currentLibraryId).arg(folderId)),
|
||||||
this, [=](QRestReply &reply){
|
this, [=](QRestReply &reply){
|
||||||
@ -83,10 +76,19 @@ void AppController::updateComicsInFolder(int folderId)
|
|||||||
if (libraries && !(*libraries).isEmpty() && (*libraries).isArray()) {
|
if (libraries && !(*libraries).isEmpty() && (*libraries).isArray()) {
|
||||||
const QJsonArray array = (*libraries).array();
|
const QJsonArray array = (*libraries).array();
|
||||||
m_comicsModel->clear();
|
m_comicsModel->clear();
|
||||||
|
m_foldersModel->clear();
|
||||||
|
// always add a top-leven folder entry...for now
|
||||||
|
QJsonObject root;
|
||||||
|
root["id"] = "1";
|
||||||
|
m_foldersModel->appendRow(new FolderItem(root, "Root"));
|
||||||
for (const QJsonValue & value : array) {
|
for (const QJsonValue & value : array) {
|
||||||
QJsonObject comicObj = value.toObject();
|
QJsonObject obj = value.toObject();
|
||||||
qDebug() << comicObj;
|
// qDebug() << obj;
|
||||||
m_comicsModel->appendRow(new ComicItem(comicObj, comicObj["file_name"].toString()));
|
if (obj["type"].toString() == QLatin1String("folder")) {
|
||||||
|
m_foldersModel->appendRow(new FolderItem(obj, obj["folder_name"].toString()));
|
||||||
|
} else {
|
||||||
|
m_comicsModel->appendRow(new ComicItem(obj, obj["file_name"].toString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,12 +24,13 @@ public:
|
|||||||
Q_PROPERTY(bool selectedComicOpened MEMBER m_currentComicOpened NOTIFY currentComicOpenedChanged FINAL)
|
Q_PROPERTY(bool selectedComicOpened MEMBER m_currentComicOpened NOTIFY currentComicOpenedChanged FINAL)
|
||||||
Q_PROPERTY(QStandardItemModel * librariesModel MEMBER m_librariesModel CONSTANT FINAL)
|
Q_PROPERTY(QStandardItemModel * librariesModel MEMBER m_librariesModel CONSTANT FINAL)
|
||||||
Q_PROPERTY(QStandardItemModel * comicsModel MEMBER m_comicsModel CONSTANT FINAL)
|
Q_PROPERTY(QStandardItemModel * comicsModel MEMBER m_comicsModel CONSTANT FINAL)
|
||||||
|
Q_PROPERTY(QStandardItemModel * foldersModel MEMBER m_foldersModel CONSTANT FINAL)
|
||||||
|
|
||||||
AppController(QObject *parent = nullptr);
|
AppController(QObject *parent = nullptr);
|
||||||
|
|
||||||
Q_INVOKABLE void connectServer(QUrl serverBaseUrl);
|
Q_INVOKABLE void connectServer(QUrl serverBaseUrl);
|
||||||
Q_INVOKABLE void updateLibraries();
|
Q_INVOKABLE void updateLibraries();
|
||||||
Q_INVOKABLE void updateComicsInFolder(int folderId = 1);
|
Q_INVOKABLE void updateComicsInFolder(QString folderId = "1");
|
||||||
Q_INVOKABLE void openComic();
|
Q_INVOKABLE void openComic();
|
||||||
Q_INVOKABLE void closeComic();
|
Q_INVOKABLE void closeComic();
|
||||||
Q_INVOKABLE QString coverImageSource(QString comicHash);
|
Q_INVOKABLE QString coverImageSource(QString comicHash);
|
||||||
@ -54,4 +55,5 @@ private:
|
|||||||
QRestAccessManager * m_restAccessManager;
|
QRestAccessManager * m_restAccessManager;
|
||||||
QStandardItemModel * m_librariesModel;
|
QStandardItemModel * m_librariesModel;
|
||||||
QStandardItemModel * m_comicsModel;
|
QStandardItemModel * m_comicsModel;
|
||||||
|
QStandardItemModel * m_foldersModel;
|
||||||
};
|
};
|
||||||
|
@ -9,3 +9,15 @@ ComicItem::ComicItem(QJsonObject jsonObj, const QString &name)
|
|||||||
setData(jsonObj["current_page"].toInt(), CurrentPageRole);
|
setData(jsonObj["current_page"].toInt(), CurrentPageRole);
|
||||||
setData(jsonObj["type"].toInt(), TypeRole);
|
setData(jsonObj["type"].toInt(), TypeRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> ComicItem::roleNames()
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
{Qt::DisplayRole, "display"},
|
||||||
|
{ComicItem::IdRole, "comicId"},
|
||||||
|
{ComicItem::HashRole, "hash"},
|
||||||
|
{ComicItem::PageCountRole, "pageCount"},
|
||||||
|
{ComicItem::CurrentPageRole, "currentPage"},
|
||||||
|
{ComicItem::TypeRole, "type"},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -18,4 +18,5 @@ public:
|
|||||||
Q_ENUM(Roles)
|
Q_ENUM(Roles)
|
||||||
|
|
||||||
explicit ComicItem(QJsonObject jsonObj, const QString &name);
|
explicit ComicItem(QJsonObject jsonObj, const QString &name);
|
||||||
|
static QHash<int, QByteArray> roleNames();
|
||||||
};
|
};
|
||||||
|
18
dataitems/folderitem.cpp
Normal file
18
dataitems/folderitem.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include "folderitem.h"
|
||||||
|
|
||||||
|
FolderItem::FolderItem(QJsonObject jsonObj, const QString &name)
|
||||||
|
: QStandardItem(name)
|
||||||
|
{
|
||||||
|
setData(jsonObj["id"].toString(), IdRole);
|
||||||
|
setData(jsonObj["first_comic_hash"].toString(), FirstComicHashRole);
|
||||||
|
setData(jsonObj["path"].toString(), PathRole);
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> FolderItem::roleNames()
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
{Qt::DisplayRole, "display"},
|
||||||
|
{FolderItem::IdRole, "folderId"},
|
||||||
|
{FolderItem::PathRole, "path"},
|
||||||
|
};
|
||||||
|
}
|
20
dataitems/folderitem.h
Normal file
20
dataitems/folderitem.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QStandardItem>
|
||||||
|
#include <QQmlEngine>
|
||||||
|
|
||||||
|
class FolderItem : public QStandardItem
|
||||||
|
{
|
||||||
|
Q_GADGET
|
||||||
|
public:
|
||||||
|
enum Roles {
|
||||||
|
IdRole = Qt::UserRole + 1,
|
||||||
|
FirstComicHashRole,
|
||||||
|
PathRole,
|
||||||
|
};
|
||||||
|
Q_ENUM(Roles)
|
||||||
|
|
||||||
|
explicit FolderItem(QJsonObject jsonObj, const QString &name);
|
||||||
|
static QHash<int, QByteArray> roleNames();
|
||||||
|
};
|
@ -6,3 +6,12 @@ LibraryItem::LibraryItem(int id, const QString &name, const QString &uuid)
|
|||||||
setData(id, IdRole);
|
setData(id, IdRole);
|
||||||
setData(uuid, UuidRole);
|
setData(uuid, UuidRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> LibraryItem::roleNames()
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
{Qt::DisplayRole, "display"},
|
||||||
|
{LibraryItem::IdRole, "libraryId"},
|
||||||
|
{LibraryItem::UuidRole, "uuid"},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -13,4 +13,5 @@ public:
|
|||||||
Q_ENUM(Roles)
|
Q_ENUM(Roles)
|
||||||
|
|
||||||
explicit LibraryItem(int id, const QString &name, const QString &uuid);
|
explicit LibraryItem(int id, const QString &name, const QString &uuid);
|
||||||
|
static QHash<int, QByteArray> roleNames();
|
||||||
};
|
};
|
||||||
|
2
main.cpp
2
main.cpp
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "dataitems/libraryitem.h"
|
#include "dataitems/libraryitem.h"
|
||||||
#include "dataitems/comicitem.h"
|
#include "dataitems/comicitem.h"
|
||||||
|
#include "dataitems/folderitem.h"
|
||||||
|
|
||||||
class QmlNetworkAccessManager : public QNetworkAccessManager
|
class QmlNetworkAccessManager : public QNetworkAccessManager
|
||||||
{
|
{
|
||||||
@ -38,6 +39,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
qmlRegisterUncreatableMetaObject(LibraryItem::staticMetaObject, "net.blumia.pineapple.comic.reader.libraryitem", 1, 0, "LibraryItem", "enum");
|
qmlRegisterUncreatableMetaObject(LibraryItem::staticMetaObject, "net.blumia.pineapple.comic.reader.libraryitem", 1, 0, "LibraryItem", "enum");
|
||||||
qmlRegisterUncreatableMetaObject(ComicItem::staticMetaObject, "net.blumia.pineapple.comic.reader.comicitem", 1, 0, "ComicItem", "enum");
|
qmlRegisterUncreatableMetaObject(ComicItem::staticMetaObject, "net.blumia.pineapple.comic.reader.comicitem", 1, 0, "ComicItem", "enum");
|
||||||
|
qmlRegisterUncreatableMetaObject(FolderItem::staticMetaObject, "net.blumia.pineapple.comic.reader.folderitem", 1, 0, "FolderItem", "enum");
|
||||||
|
|
||||||
QmlNetworkAccessManagerFactory namFactory;
|
QmlNetworkAccessManagerFactory namFactory;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user