mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2025-09-05 18:22:46 +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:
parent
d81fa50715
commit
8a683df2a2
13 changed files with 131 additions and 70 deletions
|
@ -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
|
||||
|
|
|
@ -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
40
core/src/jsonhelper.cpp
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue