1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2025-09-04 01:42:44 +00:00

Added more fields to Jellyfin::Item, update qml

* [UI] Improved: series season page now shows favourite and watched marks

Refractored some more QML to support camelCase items
This commit is contained in:
Chris Josten 2020-10-10 14:30:49 +02:00
parent d81fa50715
commit 8a683df2a2
13 changed files with 131 additions and 70 deletions

View file

@ -13,6 +13,7 @@ SOURCES += \
src/jellyfinitem.cpp \
src/jellyfinplaybackmanager.cpp \
src/jellyfinwebsocket.cpp \
src/jsonhelper.cpp \
src/serverdiscoverymodel.cpp
HEADERS += \
@ -24,6 +25,7 @@ HEADERS += \
include/jellyfinitem.h \
include/jellyfinplaybackmanager.h \
include/jellyfinwebsocket.h \
include/jsonhelper.h \
include/serverdiscoverymodel.h
VERSION = $$SAILFIN_VERSION

View file

@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <QVariant>
#include "jellyfinapiclient.h"
#include "jsonhelper.h"
namespace Jellyfin {
class SortOptions : public QObject{
@ -243,9 +244,6 @@ private:
*/
void generateFields();
QString sortByToString(SortOptions::SortBy sortBy);
void convertToCamelCase(QJsonValueRef val);
QString convertToCamelCaseHelper(const QString &str);
};
/**

View file

@ -40,6 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <cmath>
#include "jellyfinapiclient.h"
#include "jsonhelper.h"
namespace Jellyfin {
class ApiClient;
@ -63,6 +64,7 @@ public:
private:
QVariant jsonToVariant(QMetaProperty prop, const QJsonValue &val, const QJsonObject &root);
QJsonValue variantToJson(const QVariant var) const;
QVariant deserializeQobject(const QJsonObject &obj, const QMetaProperty &prop);
/**
* @brief Sets the first letter of the string to lower case (to make it camelCase).
@ -278,6 +280,10 @@ public:
Q_PROPERTY(QString seasonName MEMBER m_seasonName NOTIFY seasonNameChanged)
Q_PROPERTY(QList<MediaStream *> __list__mediaStreams MEMBER __list__m_mediaStreams NOTIFY mediaStreamsChanged)
Q_PROPERTY(QVariantList mediaStreams MEMBER m_mediaStreams NOTIFY mediaStreamsChanged STORED false)
// Why is this a QJsonObject? Well, because I couldn't be bothered to implement the deserialisations of
// a QHash at the moment.
Q_PROPERTY(QJsonObject imageTags MEMBER m_imageTags NOTIFY imageTagsChanged)
Q_PROPERTY(QJsonObject imageBlurHashes MEMBER m_imageBlurHashes NOTIFY imageBlurHashesChanged)
QString jellyfinId() const { return m_id; }
void setJellyfinId(QString newId);
@ -355,6 +361,8 @@ signals:
void seriesNameChanged(const QString &newSeriesName);
void seasonNameChanged(const QString &newSeasonName);
void mediaStreamsChanged(/*const QList<MediaStream *> &newMediaStreams*/);
void imageTagsChanged();
void imageBlurHashesChanged();
public slots:
/**
@ -402,6 +410,8 @@ protected:
QString m_seasonName;
QList<MediaStream *> __list__m_mediaStreams;
QVariantList m_mediaStreams;
QJsonObject m_imageTags;
QJsonObject m_imageBlurHashes;
template<typename T>
QQmlListProperty<T> toReadOnlyQmlListProperty(QList<T *> &list) {

21
core/include/jsonhelper.h Normal file
View file

@ -0,0 +1,21 @@
#ifndef JSON_SERIALIZER_H
#define JSON_SERIALIZER_H
#include <QList>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonValue>
#include <QJsonValueRef>
#include <QString>
namespace Jellyfin {
namespace JsonHelper {
void convertToCamelCase(QJsonValueRef val);
QString convertToCamelCaseHelper(const QString &str);
};
}
#endif // JSONSERIALIZER_H

View file

@ -126,7 +126,7 @@ void ApiModel::load(LoadType type) {
this->beginInsertRows(QModelIndex(), m_array.size(), m_array.size() + items.size() - 1);
// QJsonArray apparently doesn't allow concatenating lists like QList or std::vector
for (auto it = items.begin(); it != items.end(); it++) {
convertToCamelCase(*it);
JsonHelper::convertToCamelCase(*it);
}
foreach (const QJsonValue &val, items) {
m_array.append(val);
@ -165,7 +165,7 @@ void ApiModel::generateFields() {
}
}
for (auto it = m_array.begin(); it != m_array.end(); it++){
convertToCamelCase(*it);
JsonHelper::convertToCamelCase(*it);
}
this->endResetModel();
}
@ -212,37 +212,7 @@ void ApiModel::fetchMore(const QModelIndex &parent) {
void ApiModel::addQueryParameters(QUrlQuery &query) { Q_UNUSED(query)}
void ApiModel::convertToCamelCase(QJsonValueRef val) {
switch(val.type()) {
case QJsonValue::Object: {
QJsonObject obj = val.toObject();
for(const QString &key: obj.keys()) {
QJsonValueRef ref = obj[key];
convertToCamelCase(ref);
obj[convertToCamelCaseHelper(key)] = ref;
obj.remove(key);
}
val = obj;
break;
}
case QJsonValue::Array: {
QJsonArray arr = val.toArray();
for (auto it = arr.begin(); it != arr.end(); it++) {
convertToCamelCase(*it);
}
val = arr;
break;
}
default:
break;
}
}
QString ApiModel::convertToCamelCaseHelper(const QString &str) {
QString res(str);
res[0] = res[0].toLower();
return res;
}
// Itemmodel

View file

@ -87,7 +87,19 @@ QVariant JsonSerializable::jsonToVariant(QMetaProperty prop, const QJsonValue &v
}
case QJsonValue::Object:
QJsonObject innerObj = val.toObject();
int typeNo = prop.userType();
if (prop.userType() == QMetaType::QJsonObject) {
QJsonArray tmp = {innerObj };
JsonHelper::convertToCamelCase(QJsonValueRef(&tmp, 0));
return QVariant(innerObj);
} else {
return deserializeQobject(innerObj, prop);
}
}
return QVariant();
}
QVariant JsonSerializable::deserializeQobject(const QJsonObject &innerObj, const QMetaProperty &prop) {
int typeNo = prop.userType();
const QMetaObject *metaType = QMetaType::metaObjectForType(prop.userType());
if (metaType == nullptr) {
// Try to determine if the type is a qlist
@ -119,8 +131,6 @@ QVariant JsonSerializable::jsonToVariant(QMetaProperty prop, const QJsonValue &v
qDebug() << "Object is not a serializable one!";
return QVariant();
}
}
return QVariant();
}
QJsonObject JsonSerializable::serialize(bool capitalize) const {

40
core/src/jsonhelper.cpp Normal file
View file

@ -0,0 +1,40 @@
#include "jsonhelper.h"
namespace Jellyfin {
namespace JsonHelper {
void convertToCamelCase(QJsonValueRef val) {
switch(val.type()) {
case QJsonValue::Object: {
QJsonObject obj = val.toObject();
for(const QString &key: obj.keys()) {
QJsonValueRef ref = obj[key];
convertToCamelCase(ref);
obj[convertToCamelCaseHelper(key)] = ref;
obj.remove(key);
}
val = obj;
break;
}
case QJsonValue::Array: {
QJsonArray arr = val.toArray();
for (auto it = arr.begin(); it != arr.end(); it++) {
convertToCamelCase(*it);
}
val = arr;
break;
}
default:
break;
}
}
QString convertToCamelCaseHelper(const QString &str) {
QString res(str);
res[0] = res[0].toLower();
return res;
}
} // NS JsonHelper
} // NS Jellyfin