mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-10-06 09:17:07 +02:00
Refactor project struct to be self contained
This commit is contained in:
parent
7871573179
commit
1e8ca2e2d8
@ -51,7 +51,7 @@ public:
|
||||
Type,
|
||||
Preview,
|
||||
PreviewGIF,
|
||||
FolderId,
|
||||
FolderName,
|
||||
FileId,
|
||||
AbsoluteStoragePath,
|
||||
PublishedFileID,
|
||||
@ -71,7 +71,7 @@ public slots:
|
||||
QVariantMap get(const QString& folderName) const;
|
||||
|
||||
void loadInstalledContent();
|
||||
void append(const QJsonObject&, const QString&, const bool isNew, const QDateTime& lastModified);
|
||||
void append(const QString& projectJsonFilePath);
|
||||
void reset();
|
||||
void init();
|
||||
void deinstallItemAt(const QString& absoluteStoragePath);
|
||||
|
@ -229,7 +229,7 @@ Item {
|
||||
customTitle: m_title
|
||||
type: m_type
|
||||
isNew: m_isNew
|
||||
screenId: m_folderId
|
||||
screenId: m_folderName
|
||||
absoluteStoragePath: m_absoluteStoragePath
|
||||
publishedFileID: m_publishedFileID
|
||||
itemIndex: index
|
||||
|
@ -55,7 +55,7 @@ void InstalledListModel::deinstallItemAt(const QString& absoluteStoragePath)
|
||||
QTimer::singleShot(1000, this, [this, absoluteStoragePath]() {
|
||||
int index = -1;
|
||||
for (int i = 0; i < m_screenPlayFiles.size(); ++i) {
|
||||
if (m_screenPlayFiles.at(i).m_absoluteStoragePath.toString() == absoluteStoragePath) {
|
||||
if (m_screenPlayFiles.at(i).projectJsonFilePath.absoluteFilePath() == absoluteStoragePath) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
@ -135,29 +135,29 @@ QVariant InstalledListModel::data(const QModelIndex& index, int role) const
|
||||
if (row < rowCount())
|
||||
switch (role) {
|
||||
case static_cast<int>(ScreenPlayItem::Title):
|
||||
return m_screenPlayFiles.at(row).m_title;
|
||||
return m_screenPlayFiles.at(row).title;
|
||||
case static_cast<int>(ScreenPlayItem::Preview):
|
||||
return m_screenPlayFiles.at(row).m_preview;
|
||||
return m_screenPlayFiles.at(row).preview;
|
||||
case static_cast<int>(ScreenPlayItem::PreviewGIF):
|
||||
return m_screenPlayFiles.at(row).m_previewGIF;
|
||||
return m_screenPlayFiles.at(row).previewGIF;
|
||||
case static_cast<int>(ScreenPlayItem::Type):
|
||||
return QVariant::fromValue(m_screenPlayFiles.at(row).m_type);
|
||||
case static_cast<int>(ScreenPlayItem::FolderId):
|
||||
return m_screenPlayFiles.at(row).m_folderId;
|
||||
return QVariant::fromValue(m_screenPlayFiles.at(row).type);
|
||||
case static_cast<int>(ScreenPlayItem::FolderName):
|
||||
return m_screenPlayFiles.at(row).folderName;
|
||||
case static_cast<int>(ScreenPlayItem::FileId):
|
||||
return m_screenPlayFiles.at(row).m_file;
|
||||
return m_screenPlayFiles.at(row).file;
|
||||
case static_cast<int>(ScreenPlayItem::AbsoluteStoragePath):
|
||||
return m_screenPlayFiles.at(row).m_absoluteStoragePath;
|
||||
return QUrl::fromLocalFile(m_screenPlayFiles.at(row).projectJsonFilePath.dir().path());
|
||||
case static_cast<int>(ScreenPlayItem::PublishedFileID):
|
||||
return m_screenPlayFiles.at(row).m_publishedFileID;
|
||||
return m_screenPlayFiles.at(row).publishedFileID;
|
||||
case static_cast<int>(ScreenPlayItem::Tags):
|
||||
return m_screenPlayFiles.at(row).m_tags;
|
||||
return m_screenPlayFiles.at(row).tags;
|
||||
case static_cast<int>(ScreenPlayItem::IsNew):
|
||||
return m_screenPlayFiles.at(row).m_isNew;
|
||||
return m_screenPlayFiles.at(row).isNew;
|
||||
case static_cast<int>(ScreenPlayItem::LastModified):
|
||||
return m_screenPlayFiles.at(row).m_lastModified;
|
||||
return m_screenPlayFiles.at(row).lastModified;
|
||||
case static_cast<int>(ScreenPlayItem::SearchType):
|
||||
return QVariant::fromValue(m_screenPlayFiles.at(row).m_searchType);
|
||||
return QVariant::fromValue(m_screenPlayFiles.at(row).searchType);
|
||||
}
|
||||
|
||||
qWarning() << "Unable to fetch value for row type:" << role;
|
||||
@ -174,7 +174,7 @@ QHash<int, QByteArray> InstalledListModel::roleNames() const
|
||||
{ static_cast<int>(ScreenPlayItem::Type), "m_type" },
|
||||
{ static_cast<int>(ScreenPlayItem::Preview), "m_preview" },
|
||||
{ static_cast<int>(ScreenPlayItem::PreviewGIF), "m_previewGIF" },
|
||||
{ static_cast<int>(ScreenPlayItem::FolderId), "m_folderId" },
|
||||
{ static_cast<int>(ScreenPlayItem::FolderName), "m_folderName" },
|
||||
{ static_cast<int>(ScreenPlayItem::FileId), "m_file" },
|
||||
{ static_cast<int>(ScreenPlayItem::AbsoluteStoragePath), "m_absoluteStoragePath" },
|
||||
{ static_cast<int>(ScreenPlayItem::PublishedFileID), "m_publishedFileID" },
|
||||
@ -188,10 +188,16 @@ QHash<int, QByteArray> InstalledListModel::roleNames() const
|
||||
/*!
|
||||
\brief Append an ProjectFile to the list.
|
||||
*/
|
||||
void InstalledListModel::append(const QJsonObject& obj, const QString& folderName, const bool isNew, const QDateTime& lastModified)
|
||||
void InstalledListModel::append(const QString& projectJsonFilePath)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), m_screenPlayFiles.size(), m_screenPlayFiles.size());
|
||||
m_screenPlayFiles.append(ProjectFile(obj, folderName, m_globalVariables->localStoragePath(), isNew, lastModified));
|
||||
ProjectFile projectFile;
|
||||
projectFile.projectJsonFilePath = QFileInfo(projectJsonFilePath);
|
||||
if(!projectFile.init()){
|
||||
qWarning() << "Invalid project at "<< projectJsonFilePath;
|
||||
return;
|
||||
}
|
||||
m_screenPlayFiles.append(std::move(projectFile));
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
@ -211,33 +217,14 @@ void InstalledListModel::loadInstalledContent()
|
||||
QFileInfoList list = QDir(m_globalVariables->localStoragePath().toLocalFile()).entryInfoList(QDir::NoDotAndDotDot | QDir::AllDirs);
|
||||
int counter = 0;
|
||||
|
||||
for (const auto& item : list) {
|
||||
for (const QFileInfo& item : list) {
|
||||
const QString absoluteFilePath = m_globalVariables->localStoragePath().toLocalFile() + "/" + item.baseName() + "/project.json";
|
||||
|
||||
if (!QFile::exists(absoluteFilePath))
|
||||
continue;
|
||||
|
||||
bool isNew = false;
|
||||
|
||||
if (item.birthTime().date() == QDateTime::currentDateTime().date())
|
||||
isNew = true;
|
||||
|
||||
if (auto obj = ScreenPlayUtil::openJsonFileToObject(absoluteFilePath)) {
|
||||
|
||||
if (obj->isEmpty())
|
||||
continue;
|
||||
|
||||
if (!obj->contains("type"))
|
||||
continue;
|
||||
|
||||
if (ScreenPlayUtil::getAvailableTypes().contains(obj->value("type").toString())) {
|
||||
if (ScreenPlayUtil::getAvailableTypes().contains(obj->value("type").toString(), Qt::CaseInsensitive)) {
|
||||
append(*obj, item.baseName(), isNew, item.lastModified());
|
||||
}
|
||||
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
append(absoluteFilePath);
|
||||
counter += 1;
|
||||
}
|
||||
setCount(counter);
|
||||
emit installedLoadingFinished();
|
||||
@ -262,17 +249,17 @@ QVariantMap InstalledListModel::get(const QString& folderName) const
|
||||
}
|
||||
|
||||
for (const auto& item : m_screenPlayFiles) {
|
||||
if (item.m_folderId == folderName) {
|
||||
if (item.folderName == folderName) {
|
||||
QVariantMap map;
|
||||
map.insert("m_title", item.m_title);
|
||||
map.insert("m_preview", item.m_preview);
|
||||
map.insert("m_previewGIF", item.m_previewGIF);
|
||||
map.insert("m_file", item.m_file);
|
||||
map.insert("m_type", QVariant::fromValue(item.m_type));
|
||||
map.insert("m_absoluteStoragePath", item.m_absoluteStoragePath);
|
||||
map.insert("m_publishedFileID", item.m_publishedFileID);
|
||||
map.insert("m_isNew", item.m_isNew);
|
||||
map.insert("m_lastModified", item.m_lastModified);
|
||||
map.insert("m_title", item.title);
|
||||
map.insert("m_preview", item.preview);
|
||||
map.insert("m_previewGIF", item.previewGIF);
|
||||
map.insert("m_file", item.file);
|
||||
map.insert("m_type", QVariant::fromValue(item.type));
|
||||
map.insert("m_absoluteStoragePath", QUrl::fromLocalFile(item.projectJsonFilePath.dir().path()));
|
||||
map.insert("m_publishedFileID", item.publishedFileID);
|
||||
map.insert("m_isNew", item.isNew);
|
||||
map.insert("m_lastModified", item.lastModified);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ set(QML
|
||||
qml/TrayIcon.qml)
|
||||
|
||||
set(SOURCES # cmake-format: sort
|
||||
inc/public/ScreenPlayUtil/httpfileserver.cpp src/contenttypes.cpp src/util.cpp)
|
||||
inc/public/ScreenPlayUtil/httpfileserver.cpp src/contenttypes.cpp src/util.cpp src/projectfile.cpp)
|
||||
|
||||
set(HEADER
|
||||
# cmake-format: sort
|
||||
|
@ -4,109 +4,50 @@
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QObject>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QMetaEnum>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QDir>
|
||||
#include <QVariant>
|
||||
#include <QVariantList>
|
||||
#include <QQmlEngine>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include "ScreenPlayUtil/util.h"
|
||||
#include "ScreenPlayUtil/PropertyHelpers.h"
|
||||
|
||||
/*!
|
||||
\class ProjectFile
|
||||
\brief In ScreenPlay every Wallpaper, Scene or Widget has an project.json to store its configuration
|
||||
\brief In ScreenPlay every Wallpaper, Scene or Widget has an project.json to store its configuration.
|
||||
|
||||
*/
|
||||
namespace ScreenPlay {
|
||||
|
||||
struct ProjectFile {
|
||||
|
||||
ProjectFile(
|
||||
const QJsonObject& obj,
|
||||
const QString& folderName,
|
||||
const QUrl& absolutePath,
|
||||
const bool isNew,
|
||||
const QDateTime& lastModified)
|
||||
{
|
||||
bool init();
|
||||
bool isValid();
|
||||
|
||||
if (obj.contains("description"))
|
||||
m_description = obj.value("description").toString();
|
||||
|
||||
if (obj.contains("file"))
|
||||
m_file = obj.value("file").toString();
|
||||
|
||||
if (obj.contains("previewThumbnail")) {
|
||||
m_preview = obj.value("previewThumbnail").toString();
|
||||
} else {
|
||||
if (obj.contains("preview")) {
|
||||
m_preview = obj.value("preview").toString();
|
||||
}
|
||||
}
|
||||
|
||||
if (obj.contains("previewGIF"))
|
||||
m_previewGIF = obj.value("previewGIF").toString();
|
||||
|
||||
if (obj.contains("title"))
|
||||
m_title = obj.value("title").toString();
|
||||
|
||||
if (obj.contains("workshopid")) {
|
||||
m_publishedFileID = obj.value("workshopid").toInt(0);
|
||||
}
|
||||
|
||||
if (obj.contains("tags")) {
|
||||
if (obj.value("tags").isArray()) {
|
||||
auto tagArray = obj.value("tags").toArray();
|
||||
if (tagArray.size() > 0) {
|
||||
for (const auto& tag : tagArray) {
|
||||
m_tags.append(tag.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_absoluteStoragePath = QUrl(absolutePath.toString() + "/" + folderName);
|
||||
|
||||
m_folderId = folderName;
|
||||
|
||||
if (!obj.contains("type"))
|
||||
return;
|
||||
|
||||
auto type = ScreenPlayUtil::getInstalledTypeFromString(obj.value("type").toString());
|
||||
if (!type) {
|
||||
qWarning() << "Type could not parsed from: " << *type << folderName;
|
||||
return;
|
||||
}
|
||||
|
||||
m_type = *type;
|
||||
if (m_type == InstalledType::InstalledType::GifWallpaper) {
|
||||
m_preview = m_previewGIF;
|
||||
}
|
||||
m_searchType = ScreenPlayUtil::getSearchTypeFromInstalledType(m_type);
|
||||
m_isNew = isNew;
|
||||
m_lastModified = lastModified;
|
||||
}
|
||||
|
||||
ProjectFile() { }
|
||||
|
||||
QString m_title;
|
||||
QString m_description;
|
||||
QString title;
|
||||
QString description;
|
||||
// Filenames
|
||||
QString m_file;
|
||||
QString m_preview;
|
||||
QString m_previewGIF;
|
||||
// Path
|
||||
QUrl m_absoluteStoragePath;
|
||||
QString file;
|
||||
QString preview;
|
||||
QString previewGIF;
|
||||
// Path to project.json
|
||||
QFileInfo projectJsonFilePath;
|
||||
// Folder name
|
||||
QString m_folderId;
|
||||
QString folderName;
|
||||
|
||||
QVariant m_publishedFileID { 0 };
|
||||
QStringList m_tags;
|
||||
QVariant publishedFileID { 0 };
|
||||
QStringList tags;
|
||||
|
||||
InstalledType::InstalledType m_type = InstalledType::InstalledType::Unknown;
|
||||
SearchType::SearchType m_searchType = SearchType::SearchType::All;
|
||||
bool m_isNew = false;
|
||||
QDateTime m_lastModified;
|
||||
InstalledType::InstalledType type = InstalledType::InstalledType::Unknown;
|
||||
SearchType::SearchType searchType = SearchType::SearchType::All;
|
||||
bool isNew = false;
|
||||
QDateTime lastModified;
|
||||
};
|
||||
}
|
||||
|
90
ScreenPlayUtil/src/projectfile.cpp
Normal file
90
ScreenPlayUtil/src/projectfile.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
#include "ScreenPlayUtil/projectfile.h"
|
||||
|
||||
namespace ScreenPlay {
|
||||
|
||||
bool ProjectFile::init()
|
||||
{
|
||||
if(!isValid())
|
||||
return false;
|
||||
|
||||
const auto jsonObjOpt = ScreenPlayUtil::openJsonFileToObject(projectJsonFilePath.absoluteFilePath());
|
||||
QDir folder = projectJsonFilePath.dir();
|
||||
folderName = folder.dirName();
|
||||
QFileInfo folderInfo(folder.path());
|
||||
lastModified = folderInfo.birthTime();
|
||||
if (folderInfo.birthTime().date() == QDateTime::currentDateTime().date())
|
||||
isNew = true;
|
||||
|
||||
if(!jsonObjOpt.has_value())
|
||||
return false;
|
||||
|
||||
const QJsonObject& obj =jsonObjOpt.value();
|
||||
if (obj.isEmpty())
|
||||
return false;
|
||||
|
||||
//Required:
|
||||
if (!obj.contains("description"))
|
||||
return false;
|
||||
description = obj.value("description").toString();
|
||||
|
||||
if (!obj.contains("file"))
|
||||
return false;
|
||||
file = obj.value("file").toString();
|
||||
|
||||
|
||||
if (!obj.contains("title"))
|
||||
return false;
|
||||
title = obj.value("title").toString();
|
||||
|
||||
if (!obj.contains("type"))
|
||||
return false;
|
||||
|
||||
// Optional:
|
||||
if (obj.contains("previewGIF"))
|
||||
previewGIF = obj.value("previewGIF").toString();
|
||||
|
||||
if (obj.contains("workshopid"))
|
||||
publishedFileID = obj.value("workshopid").toInt(0);
|
||||
|
||||
if (obj.contains("previewThumbnail")) {
|
||||
preview = obj.value("previewThumbnail").toString();
|
||||
} else {
|
||||
if (!obj.contains("preview")) {
|
||||
return false;
|
||||
}
|
||||
preview = obj.value("preview").toString();
|
||||
}
|
||||
|
||||
if (obj.contains("tags")) {
|
||||
if (obj.value("tags").isArray()) {
|
||||
auto tagArray = obj.value("tags").toArray();
|
||||
if (tagArray.size() > 0) {
|
||||
for (const auto& tag : tagArray) {
|
||||
tags.append(tag.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto typeParsed = ScreenPlayUtil::getInstalledTypeFromString(obj.value("type").toString());
|
||||
if (!typeParsed) {
|
||||
qWarning() << "Type could not parsed from: " << *typeParsed;
|
||||
return false;
|
||||
}
|
||||
|
||||
type = *typeParsed;
|
||||
if (type == InstalledType::InstalledType::GifWallpaper) {
|
||||
preview = previewGIF;
|
||||
}
|
||||
searchType = ScreenPlayUtil::getSearchTypeFromInstalledType(type);
|
||||
|
||||
return true;
|
||||
}
|
||||
bool ProjectFile::isValid()
|
||||
{
|
||||
if(!projectJsonFilePath.isFile())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -117,7 +117,6 @@ signals:
|
||||
void projectPathChanged(const QString& rojectPath);
|
||||
void projectSourceFileChanged(const QString& projectSourceFile);
|
||||
void projectSourceFileAbsoluteChanged(const QUrl& rojectSourceFileAbsolute);
|
||||
|
||||
void videoCodecChanged();
|
||||
|
||||
public slots:
|
||||
@ -281,8 +280,6 @@ public slots:
|
||||
if (m_visualsPaused == visualsPaused)
|
||||
return;
|
||||
|
||||
qInfo() << "visualsPaused: " << visualsPaused;
|
||||
|
||||
m_visualsPaused = visualsPaused;
|
||||
emit visualsPausedChanged(m_visualsPaused);
|
||||
}
|
||||
|
@ -8,15 +8,14 @@ Item {
|
||||
property alias checkBox: checkBox
|
||||
property string preview: screenPreview
|
||||
property bool isSelected: false
|
||||
property string customTitle: "name here"
|
||||
property string absoluteStoragePath
|
||||
property string type
|
||||
property bool hasMenuOpen: false
|
||||
property var publishedFileID: 0
|
||||
property int itemIndex
|
||||
property string screenId: ""
|
||||
property string folderName
|
||||
|
||||
signal itemClicked(var screenId, var type, var isActive)
|
||||
signal itemClicked(var folderName, var type, var isActive)
|
||||
|
||||
width: 320
|
||||
height: 180
|
||||
|
@ -1,7 +1,7 @@
|
||||
import QtQuick
|
||||
|
||||
Item {
|
||||
id: screenPlayItemImage
|
||||
id: root
|
||||
|
||||
property string sourceImage
|
||||
property string sourceImageGIF
|
||||
@ -15,13 +15,13 @@ Item {
|
||||
|
||||
anchors.fill: parent
|
||||
fillMode: Image.PreserveAspectCrop
|
||||
source: screenPlayItemImage.sourceImage.trim()
|
||||
source: root.sourceImage.trim()
|
||||
onStatusChanged: {
|
||||
if (image.status === Image.Ready) {
|
||||
screenPlayItemImage.state = "loaded";
|
||||
root.state = "loaded";
|
||||
} else if (image.status === Image.Error) {
|
||||
source = "images/missingPreview.png";
|
||||
screenPlayItemImage.state = "loaded";
|
||||
root.state = "loaded";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ Item {
|
||||
width: gridView.cellWidth - 30
|
||||
customTitle: m_title
|
||||
type: m_type
|
||||
screenId: m_folderId
|
||||
screenId: m_folderName
|
||||
absoluteStoragePath: m_absoluteStoragePath
|
||||
publishedFileID: m_publishedFileID
|
||||
preview: m_preview
|
||||
|
@ -39,25 +39,25 @@ QVariant InstalledListModel::data(const QModelIndex& index, int role) const
|
||||
if (row < rowCount())
|
||||
switch (role) {
|
||||
case static_cast<int>(ScreenPlayItem::Title):
|
||||
return m_screenPlayFiles.at(row).m_title;
|
||||
return m_screenPlayFiles.at(row).title;
|
||||
case static_cast<int>(ScreenPlayItem::Preview):
|
||||
return m_screenPlayFiles.at(row).m_preview;
|
||||
return m_screenPlayFiles.at(row).preview;
|
||||
case static_cast<int>(ScreenPlayItem::PreviewGIF):
|
||||
return m_screenPlayFiles.at(row).m_previewGIF;
|
||||
return m_screenPlayFiles.at(row).previewGIF;
|
||||
case static_cast<int>(ScreenPlayItem::Type):
|
||||
return QVariant::fromValue(m_screenPlayFiles.at(row).m_type);
|
||||
case static_cast<int>(ScreenPlayItem::FolderId):
|
||||
return m_screenPlayFiles.at(row).m_folderId;
|
||||
return QVariant::fromValue(m_screenPlayFiles.at(row).type);
|
||||
case static_cast<int>(ScreenPlayItem::FolderName):
|
||||
return m_screenPlayFiles.at(row).folderName;
|
||||
case static_cast<int>(ScreenPlayItem::FileId):
|
||||
return m_screenPlayFiles.at(row).m_file;
|
||||
case static_cast<int>(ScreenPlayItem::AbsoluteStoragePath):
|
||||
return m_screenPlayFiles.at(row).m_absoluteStoragePath;
|
||||
return m_screenPlayFiles.at(row).file;
|
||||
case static_cast<int>(ScreenPlayItem::AbsoluteStoragePath):
|
||||
return QUrl::fromLocalFile(m_screenPlayFiles.at(row).projectJsonFilePath.dir().path());
|
||||
case static_cast<int>(ScreenPlayItem::PublishedFileID):
|
||||
return m_screenPlayFiles.at(row).m_publishedFileID;
|
||||
return m_screenPlayFiles.at(row).publishedFileID;
|
||||
case static_cast<int>(ScreenPlayItem::Tags):
|
||||
return m_screenPlayFiles.at(row).m_tags;
|
||||
return m_screenPlayFiles.at(row).tags;
|
||||
case static_cast<int>(ScreenPlayItem::SearchType):
|
||||
return QVariant::fromValue(m_screenPlayFiles.at(row).m_searchType);
|
||||
return QVariant::fromValue(m_screenPlayFiles.at(row).searchType);
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
@ -71,7 +71,7 @@ QHash<int, QByteArray> InstalledListModel::roleNames() const
|
||||
{ static_cast<int>(ScreenPlayItem::Type), "m_type" },
|
||||
{ static_cast<int>(ScreenPlayItem::Preview), "m_preview" },
|
||||
{ static_cast<int>(ScreenPlayItem::PreviewGIF), "m_previewGIF" },
|
||||
{ static_cast<int>(ScreenPlayItem::FolderId), "m_folderId" },
|
||||
{ static_cast<int>(ScreenPlayItem::FolderName), "m_folderName" },
|
||||
{ static_cast<int>(ScreenPlayItem::FileId), "m_file" },
|
||||
{ static_cast<int>(ScreenPlayItem::AbsoluteStoragePath), "m_absoluteStoragePath" },
|
||||
{ static_cast<int>(ScreenPlayItem::PublishedFileID), "m_publishedFileID" },
|
||||
@ -80,10 +80,17 @@ QHash<int, QByteArray> InstalledListModel::roleNames() const
|
||||
};
|
||||
}
|
||||
|
||||
void InstalledListModel::append(const QJsonObject& obj, const QString& folderName, const QDateTime& lastModified)
|
||||
void InstalledListModel::append(const QString& projectJsonFilePath)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), m_screenPlayFiles.size(), m_screenPlayFiles.size());
|
||||
m_screenPlayFiles.append(ScreenPlay::ProjectFile(obj, folderName, m_absoluteStoragePath, false, lastModified));
|
||||
using namespace ScreenPlay;
|
||||
ProjectFile projectFile;
|
||||
projectFile.projectJsonFilePath = QFileInfo(projectJsonFilePath);
|
||||
if(!projectFile.init()){
|
||||
qWarning() << "Invalid project at "<< projectJsonFilePath;
|
||||
return;
|
||||
}
|
||||
m_screenPlayFiles.append(std::move(projectFile));
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
@ -96,26 +103,12 @@ void InstalledListModel::loadInstalledContent()
|
||||
QFileInfoList list = QDir(m_absoluteStoragePath.toLocalFile()).entryInfoList(QDir::NoDotAndDotDot | QDir::AllDirs);
|
||||
|
||||
for (const auto& item : list) {
|
||||
|
||||
const QString absoluteFilePath = m_absoluteStoragePath.toLocalFile() + "/" + item.baseName() + "/project.json";
|
||||
|
||||
if (!QFile::exists(absoluteFilePath))
|
||||
continue;
|
||||
|
||||
if (auto obj = ScreenPlayUtil::openJsonFileToObject(absoluteFilePath)) {
|
||||
|
||||
if (obj->isEmpty())
|
||||
continue;
|
||||
|
||||
if (!obj->contains("type"))
|
||||
continue;
|
||||
|
||||
if (obj->contains("workshopid"))
|
||||
continue;
|
||||
|
||||
if (ScreenPlayUtil::getAvailableTypes().contains(obj->value("type").toString(), Qt::CaseSensitivity::CaseInsensitive))
|
||||
append(*obj, item.baseName(), item.lastModified());
|
||||
}
|
||||
append(absoluteFilePath);
|
||||
}
|
||||
|
||||
emit installedLoadingFinished();
|
||||
@ -123,7 +116,7 @@ void InstalledListModel::loadInstalledContent()
|
||||
m_loadContentFutureWatcher.setFuture(m_loadContentFuture);
|
||||
}
|
||||
|
||||
QVariantMap InstalledListModel::get(QString folderId)
|
||||
QVariantMap InstalledListModel::get(QString folderName)
|
||||
{
|
||||
|
||||
if (m_screenPlayFiles.count() == 0)
|
||||
@ -133,14 +126,14 @@ QVariantMap InstalledListModel::get(QString folderId)
|
||||
|
||||
for (int i = 0; i < m_screenPlayFiles.count(); i++) {
|
||||
|
||||
if (m_screenPlayFiles[i].m_folderId == folderId) {
|
||||
map.insert("m_title", m_screenPlayFiles[i].m_title);
|
||||
map.insert("m_preview", m_screenPlayFiles[i].m_preview);
|
||||
map.insert("m_previewGIF", m_screenPlayFiles[i].m_previewGIF);
|
||||
map.insert("m_file", m_screenPlayFiles[i].m_file);
|
||||
map.insert("m_type", QVariant::fromValue(m_screenPlayFiles[i].m_type));
|
||||
map.insert("m_absoluteStoragePath", m_screenPlayFiles[i].m_absoluteStoragePath);
|
||||
map.insert("m_publishedFileID", m_screenPlayFiles[i].m_publishedFileID);
|
||||
if (m_screenPlayFiles[i].folderName == folderName) {
|
||||
map.insert("m_title", m_screenPlayFiles[i].title);
|
||||
map.insert("m_preview", m_screenPlayFiles[i].preview);
|
||||
map.insert("m_previewGIF", m_screenPlayFiles[i].previewGIF);
|
||||
map.insert("m_file", m_screenPlayFiles[i].file);
|
||||
map.insert("m_type", QVariant::fromValue(m_screenPlayFiles[i].type));
|
||||
map.insert("m_absoluteStoragePath", QUrl::fromLocalFile(m_screenPlayFiles[i].projectJsonFilePath.dir().path()));
|
||||
map.insert("m_publishedFileID", m_screenPlayFiles[i].publishedFileID);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <QVariant>
|
||||
#include <QVariantList>
|
||||
#include <QVector>
|
||||
#include <vector>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#include <QtQml>
|
||||
|
||||
@ -35,7 +36,7 @@ class InstalledListModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
|
||||
QML_ELEMENT
|
||||
Q_PROPERTY(QUrl absoluteStoragePath READ absoluteStoragePath WRITE setabsoluteStoragePath NOTIFY absoluteStoragePathChanged)
|
||||
Q_PROPERTY(QUrl absoluteStoragePath READ absoluteStoragePath WRITE setAbsoluteStoragePath NOTIFY absoluteStoragePathChanged)
|
||||
|
||||
public:
|
||||
explicit InstalledListModel(QObject* parent = nullptr);
|
||||
@ -49,7 +50,7 @@ public:
|
||||
Type,
|
||||
Preview,
|
||||
PreviewGIF,
|
||||
FolderId,
|
||||
FolderName,
|
||||
FileId,
|
||||
AbsoluteStoragePath,
|
||||
PublishedFileID,
|
||||
@ -66,9 +67,9 @@ public:
|
||||
|
||||
public slots:
|
||||
void loadInstalledContent();
|
||||
QVariantMap get(QString folderId);
|
||||
void append(const QJsonObject&, const QString&, const QDateTime& lastModified);
|
||||
void setabsoluteStoragePath(QUrl absoluteStoragePath)
|
||||
QVariantMap get(QString folderName);
|
||||
void append(const QString& projectJsonFilePath);
|
||||
void setAbsoluteStoragePath(QUrl absoluteStoragePath)
|
||||
{
|
||||
if (m_absoluteStoragePath == absoluteStoragePath)
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user