mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-23 03:02:30 +01:00
Add workaround for qml enum namespace collision
This commit is contained in:
parent
1ce2f2386d
commit
f449ace8ab
@ -4,7 +4,7 @@ import QtQuick.Controls 2.2
|
||||
|
||||
//Enums
|
||||
import LocalWorkshopCreationStatus 1.0
|
||||
import WorkshopCreationStatus 1.0
|
||||
|
||||
|
||||
Rectangle {
|
||||
id: create
|
||||
|
@ -1,6 +1,8 @@
|
||||
import QtQuick 2.7
|
||||
import QtGraphicalEffects 1.0
|
||||
import QtQuick.Controls 2.2
|
||||
// Qt Creator does not support Namespaced enums yet
|
||||
// https://bugreports.qt.io/browse/QTCREATORBUG-17850
|
||||
import LocalWorkshopCreationStatus 1.0
|
||||
|
||||
Item {
|
||||
@ -33,6 +35,8 @@ Item {
|
||||
txtStatus.text = "Finished"
|
||||
busyIndicator.running = false
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,12 @@ SteamWorkshop::SteamWorkshop(AppId_t nConsumerAppId, SteamWorkshopListModel* wlm
|
||||
m_AppId = nConsumerAppId;
|
||||
m_workshopListModel = wlm;
|
||||
m_settings = s;
|
||||
qRegisterMetaType<SteamWorkshop::LocalWorkshopCreationStatus>();
|
||||
qmlRegisterUncreatableType<SteamWorkshop>("LocalWorkshopCreationStatus", 1, 0, "LocalWorkshopCreationStatus", "none");
|
||||
qmlRegisterUncreatableType<SteamWorkshop>("WorkshopCreationStatus", 1, 0, "WorkshopCreationStatus", "none");
|
||||
|
||||
// Register namespace seperated enums because qml has no enum scope WTF
|
||||
qRegisterMetaType<LocalWorkshopCreationStatus::Value>();
|
||||
qRegisterMetaType<RemoteWorkshopCreationStatus::Value>();
|
||||
qmlRegisterUncreatableMetaObject(LocalWorkshopCreationStatus::staticMetaObject,"LocalWorkshopCreationStatus", 1, 0, "LocalWorkshopCreationStatus", "Error: only enums");
|
||||
qmlRegisterUncreatableMetaObject(RemoteWorkshopCreationStatus::staticMetaObject,"RemoteWorkshopCreationStatus", 1, 0, "RemoteWorkshopCreationStatus", "Error: only enums");
|
||||
}
|
||||
|
||||
void SteamWorkshop::createWorkshopItem()
|
||||
@ -70,7 +73,7 @@ void SteamWorkshop::createLocalWorkshopItem(QString title, QUrl videoPath, QUrl
|
||||
{
|
||||
QtConcurrent::run([=]() {
|
||||
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Started);
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::Started);
|
||||
|
||||
QString fromVideoPath = QString(videoPath.toString()).replace("file:///", "");
|
||||
QString fromImagePath = QString(previewPath.toString()).replace("file:///", "");
|
||||
@ -80,7 +83,7 @@ void SteamWorkshop::createLocalWorkshopItem(QString title, QUrl videoPath, QUrl
|
||||
|
||||
if (QDir(toPath).exists()) {
|
||||
if (!QDir(toPath).isEmpty()) {
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::ErrorFolder);
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::ErrorFolder);
|
||||
return;
|
||||
} else {
|
||||
//if(!QDir(toPath + ))
|
||||
@ -89,30 +92,30 @@ void SteamWorkshop::createLocalWorkshopItem(QString title, QUrl videoPath, QUrl
|
||||
} else {
|
||||
//TODO: Display Error
|
||||
if (!QDir().mkdir(toPath)) {
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::ErrorFolderCreation);
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::ErrorFolderCreation);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Copy Video File
|
||||
if (QFile::copy(fromVideoPath, toPathWithVideoFile)) {
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::CopyVideoFinished);
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::CopyVideoFinished);
|
||||
} else {
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::ErrorCopyVideo);
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::ErrorCopyVideo);
|
||||
}
|
||||
|
||||
//Copy Image File
|
||||
if (QFile::copy(fromImagePath, toPathWithImageFile)) {
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::CopyImageFinished);
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::CopyImageFinished);
|
||||
} else {
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::ErrorCopyVideo);
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::ErrorCopyImage);
|
||||
}
|
||||
|
||||
//Copy Project File
|
||||
QFile configFile(toPath + "/" + "project.json");
|
||||
|
||||
if (!configFile.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::ErrorCopyConfig);
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::ErrorCopyConfig);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -129,10 +132,9 @@ void SteamWorkshop::createLocalWorkshopItem(QString title, QUrl videoPath, QUrl
|
||||
out << configJsonDocument.toJson();
|
||||
configFile.close();
|
||||
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::CopyConfigFinished);
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::Finished);
|
||||
});
|
||||
|
||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Finished);
|
||||
}
|
||||
|
||||
void SteamWorkshop::subscribeItem(unsigned int id)
|
||||
|
@ -1,40 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
#include "settings.h"
|
||||
#include "steam/steam_api.h"
|
||||
#include "steamworkshoplistmodel.h"
|
||||
#include "settings.h"
|
||||
#include <QByteArray>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
|
||||
class SteamWorkshop : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SteamWorkshop(QObject* parent = nullptr);
|
||||
SteamWorkshop(AppId_t nConsumerAppId, SteamWorkshopListModel* wlm, Settings* s);
|
||||
|
||||
Q_PROPERTY(unsigned int itemProcessed READ itemProcessed WRITE setItemProcessed NOTIFY itemProcessedChanged)
|
||||
Q_PROPERTY(unsigned int bytesTotal READ bytesTotal WRITE setBytesTotal NOTIFY bytesTotalChanged)
|
||||
|
||||
|
||||
unsigned int itemProcessed() const
|
||||
{
|
||||
return m_itemProcessed;
|
||||
}
|
||||
|
||||
unsigned int bytesTotal() const
|
||||
{
|
||||
return m_bytesTotal;
|
||||
}
|
||||
|
||||
enum class LocalWorkshopCreationStatus{
|
||||
/* FIXME:
|
||||
* Workaround because QML enums are like c++98 with a
|
||||
* global namespace.
|
||||
* https://www.kdab.com/new-qt-5-8-meta-object-support-namespaces/
|
||||
*/
|
||||
namespace LocalWorkshopCreationStatus {
|
||||
Q_NAMESPACE
|
||||
enum Value{
|
||||
Idle,
|
||||
Started,
|
||||
CopyVideoFinished,
|
||||
@ -49,9 +36,11 @@ public:
|
||||
ErrorCopyConfig,
|
||||
ErrorUnknown,
|
||||
};
|
||||
Q_ENUM(LocalWorkshopCreationStatus)
|
||||
|
||||
enum class WorkshopCreationStatus{
|
||||
Q_ENUM_NS(Value)
|
||||
}
|
||||
namespace RemoteWorkshopCreationStatus {
|
||||
Q_NAMESPACE
|
||||
enum Value{
|
||||
Idle,
|
||||
Started,
|
||||
Importing,
|
||||
@ -60,7 +49,27 @@ public:
|
||||
ErrorWorkshopItemCreation,
|
||||
ErrorUnknown,
|
||||
};
|
||||
Q_ENUM(WorkshopCreationStatus)
|
||||
Q_ENUM_NS(Value)
|
||||
}
|
||||
|
||||
class SteamWorkshop : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SteamWorkshop(QObject* parent = nullptr);
|
||||
SteamWorkshop(AppId_t nConsumerAppId, SteamWorkshopListModel* wlm, Settings* s);
|
||||
|
||||
Q_PROPERTY(unsigned int itemProcessed READ itemProcessed WRITE setItemProcessed NOTIFY itemProcessedChanged)
|
||||
Q_PROPERTY(unsigned int bytesTotal READ bytesTotal WRITE setBytesTotal NOTIFY bytesTotalChanged)
|
||||
|
||||
unsigned int itemProcessed() const
|
||||
{
|
||||
return m_itemProcessed;
|
||||
}
|
||||
|
||||
unsigned int bytesTotal() const
|
||||
{
|
||||
return m_bytesTotal;
|
||||
}
|
||||
|
||||
public slots:
|
||||
void searchWorkshop();
|
||||
@ -96,7 +105,7 @@ signals:
|
||||
void itemProcessedChanged(unsigned int itemProcessed);
|
||||
void bytesTotalChanged(unsigned int bytesTotal);
|
||||
|
||||
void localWorkshopCreationStatusChanged(SteamWorkshop::LocalWorkshopCreationStatus status);
|
||||
void localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value status);
|
||||
|
||||
private:
|
||||
void workshopItemCreated(CreateItemResult_t* pCallback, bool bIOFailure);
|
||||
|
Loading…
Reference in New Issue
Block a user