From e73ac98fc96dfffd79e85c46f0a5d7ccc6c76726 Mon Sep 17 00:00:00 2001 From: Elias Steurer Date: Wed, 12 May 2021 17:33:17 +0200 Subject: [PATCH] Refactor project to use Util functions --- ScreenPlayWidget/CMakeLists.txt | 2 +- ScreenPlayWidget/src/widgetwindow.cpp | 27 +++++++++------------------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/ScreenPlayWidget/CMakeLists.txt b/ScreenPlayWidget/CMakeLists.txt index 5a12ccf1..dbc1b9e3 100644 --- a/ScreenPlayWidget/CMakeLists.txt +++ b/ScreenPlayWidget/CMakeLists.txt @@ -31,4 +31,4 @@ if(APPLE) set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE true) endif() -target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Quick Qt5::Gui Qt5::Widgets Qt5::Core ScreenPlaySDK) +target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Quick Qt5::Gui Qt5::Widgets Qt5::Core ScreenPlaySDK ScreenPlayUtil) diff --git a/ScreenPlayWidget/src/widgetwindow.cpp b/ScreenPlayWidget/src/widgetwindow.cpp index 3ff7675e..05dff2a4 100644 --- a/ScreenPlayWidget/src/widgetwindow.cpp +++ b/ScreenPlayWidget/src/widgetwindow.cpp @@ -2,6 +2,9 @@ #include +#include "ScreenPlayUtil/contenttypes.h" +#include "ScreenPlayUtil/util.h" + WidgetWindow::WidgetWindow( const QString& projectPath, const QString& appID, @@ -18,12 +21,7 @@ WidgetWindow::WidgetWindow( QObject::connect(m_sdk.get(), &ScreenPlaySDK::sdkDisconnected, this, &WidgetWindow::qmlExit); QObject::connect(m_sdk.get(), &ScreenPlaySDK::incommingMessage, this, &WidgetWindow::messageReceived); - QStringList availableTypes { - "qmlWidget", - "htmlWidget" - }; - - if (!availableTypes.contains(m_type, Qt::CaseSensitivity::CaseInsensitive)) { + if (!ScreenPlayUtil::getAvailableWidgets().contains(m_type, Qt::CaseSensitivity::CaseInsensitive)) { QApplication::exit(-4); } @@ -44,20 +42,13 @@ WidgetWindow::WidgetWindow( if (projectPath == "test") { setSourcePath("qrc:/test.qml"); } else { - QFile configTmp; - QJsonDocument configJsonDocument; - QJsonParseError parseError {}; - - configTmp.setFileName(projectPath + "/project.json"); - configTmp.open(QIODevice::ReadOnly | QIODevice::Text); - m_projectConfig = configTmp.readAll(); - configJsonDocument = QJsonDocument::fromJson(m_projectConfig.toUtf8(), &parseError); - - if (!(parseError.error == QJsonParseError::NoError)) { - qWarning() << "Settings Json Parse Error " << parseError.errorString() << configTmp.fileName(); + auto projectOpt = ScreenPlayUtil::openJsonFileToObject(projectPath + "/project.json"); + if (projectOpt.has_value()) { + qWarning() << "Unable to parse project file!"; + QApplication::exit(-1); } - m_project = configJsonDocument.object(); + m_project = projectOpt.value(); QString fullPath = "file:///" + projectPath + "/" + m_project.value("file").toString(); setSourcePath(fullPath); }