diff --git a/ScreenPlay/Resources.qrc b/ScreenPlay/Resources.qrc index d8cda573..13e859c6 100644 --- a/ScreenPlay/Resources.qrc +++ b/ScreenPlay/Resources.qrc @@ -122,5 +122,6 @@ qml/Create/Wizards/CreateWallpaper/Page_0.qml qml/Create/Wizards/CreateWallpaper/Page_1.qml qml/Create/Wizards/CreateWallpaper/Page_2.qml + qml/Create/Wizards/CreateWallpaper/NextButton.qml diff --git a/ScreenPlay/qml/Create/Wizards/CreateWallpaper/CreateWallpaperWizard.qml b/ScreenPlay/qml/Create/Wizards/CreateWallpaper/CreateWallpaperWizard.qml index 26a22423..78df6943 100644 --- a/ScreenPlay/qml/Create/Wizards/CreateWallpaper/CreateWallpaperWizard.qml +++ b/ScreenPlay/qml/Create/Wizards/CreateWallpaper/CreateWallpaperWizard.qml @@ -4,11 +4,11 @@ import QtQuick.Controls 2.2 import QtQuick.Controls.Material 2.2 import Qt.labs.platform 1.0 import QtQuick.Layouts 1.3 +import net.aimber.create 1.0 Item { id: createNew anchors.fill: parent - Component.onCompleted: state = "in" state: "out" property string filePath @@ -18,6 +18,20 @@ Item { anchors.fill: parent } + Timer { + interval: 1000 + triggeredOnStart: false + running: true + repeat: false + onTriggered: { + screenPlayCreate.createWallpaperStart(filePath) + } + } + + Component.onCompleted: { + state = "in" + } + RectangularGlow { id: effect anchors { @@ -70,6 +84,7 @@ Item { id: view clip: true currentIndex: 0 + interactive: false onCurrentIndexChanged: { } @@ -84,10 +99,24 @@ Item { topMargin: 0 } - interactive: false - Page_0 { - id: firstPage + id: page_0 + onCanNextChanged: { + if (canNext) { + btnNext.state = "enabledPage0" + } else { + if (gifCreated) { + btnNext.state = "diabledPage0NoTitle" + } else { + btnNext.state = "diabledPage0" + } + } + } + onGifCreatedChanged: { + if (gifCreated) { + btnNext.state = "diabledPage0NoTitle" + } + } } Page_1 { id: secondPage @@ -148,7 +177,7 @@ Item { } Row { - width: 160 + width: childrenRect.width height: 50 spacing: 20 anchors { @@ -171,16 +200,14 @@ Item { view.setCurrentIndex(view.currentIndex - 1) } } - Button { - text: qsTr("Next") - Material.background: Material.Orange - Material.foreground: "white" - - icon.source: "qrc:/assets/icons/icon_arrow_right.svg" - icon.color: "white" - icon.width: 16 - icon.height: 16 + NextButton { + id: btnNext + state: "diabledPage0" onClicked: { + + if (!page_0.canNext && !page_0.gifCreated ) + return + if (view.currentIndex < view.count - 1) view.setCurrentIndex(view.currentIndex + 1) } diff --git a/ScreenPlay/qml/Create/Wizards/CreateWallpaper/NextButton.qml b/ScreenPlay/qml/Create/Wizards/CreateWallpaper/NextButton.qml new file mode 100644 index 00000000..95327c8c --- /dev/null +++ b/ScreenPlay/qml/Create/Wizards/CreateWallpaper/NextButton.qml @@ -0,0 +1,62 @@ +import QtQuick 2.9 +import QtGraphicalEffects 1.0 +import QtQuick.Controls 2.2 +import QtQuick.Controls.Material 2.2 +import Qt.labs.platform 1.0 +import QtQuick.Layouts 1.3 + +Button { + id: root + text: qsTr("Next") + Material.background: Material.Orange + Material.foreground: "white" + + icon.source: "qrc:/assets/icons/icon_arrow_right.svg" + icon.color: "white" + icon.width: 16 + icon.height: 16 + + states: [ + State { + name: "enabled" + PropertyChanges { + target: root + } + }, + State { + name: "diabledPage0" + PropertyChanges { + target: root + text: qsTr("Creating preview") + Material.background: Material.Grey + } + }, + State { + name: "diabledPage0NoTitle" + PropertyChanges { + target: root + text: qsTr("No title set!") + Material.background: Material.Grey + } + }, + State { + name: "enabledPage0" + PropertyChanges { + target: root + text: qsTr("Next") + Material.background: Material.Orange + } + } + ] + transitions: [ + Transition { + from: "*" + to: "*" + NumberAnimation { + property: "width" + easing.type: Easing.InOutQuad + duration: 2000 + } + } + ] +} diff --git a/ScreenPlay/qml/Create/Wizards/CreateWallpaper/Page_0.qml b/ScreenPlay/qml/Create/Wizards/CreateWallpaper/Page_0.qml index e7dfab47..50292b76 100644 --- a/ScreenPlay/qml/Create/Wizards/CreateWallpaper/Page_0.qml +++ b/ScreenPlay/qml/Create/Wizards/CreateWallpaper/Page_0.qml @@ -1,12 +1,15 @@ import QtQuick 2.9 import QtQuick.Controls 2.3 import QtGraphicalEffects 1.0 +import net.aimber.create 1.0 Rectangle { id: root - property bool allNecessaryConfigsSet: false - Rectangle { + property bool canNext: false + property bool gifCreated: false + + Item { id: rectangle1 width: parent.width * .5 anchors { @@ -33,21 +36,70 @@ Rectangle { cornerRadius: 15 } - Rectangle { id: imgWrapper width: parent.width * .9 anchors { - top:parent.top + top: parent.top margins: parent.width * .05 - right:parent.right - left:parent.left + right: parent.right + left: parent.left } height: 200 color: "gray" - Image { + + BusyIndicator { + id: busyIndicator + anchors.centerIn: parent + running: true + } + + Text { + id: text1 + color: "white" + text: qsTr("Generating preview...") + font.pixelSize: 14 + anchors { + horizontalCenter: parent.horizontalCenter + bottom: parent.bottom + bottomMargin: 30 + } + } + + Connections { + target: screenPlayCreate + + onCreateWallpaperStateChanged: { + if (state === Create.State.ConvertingPreviewGifFinished) { + imgPreview.source = "file:///" + + screenPlayCreate.workingDir + "/preview.gif" + imgPreview.visible = true + gifCreated = true + } + } + } + + AnimatedImage { id: imgPreview + asynchronous: true + playing: true + visible: false + anchors.fill: parent + } + } + + ScrollView { + anchors { + top: imgWrapper.bottom + right: parent.right + bottom: parent.bottom + left: parent.left + margins: 20 + } + Text { + id: txtOut + width: parent.width } } } @@ -72,7 +124,13 @@ Rectangle { placeholderText: qsTr("Name") anchors.right: parent.right anchors.left: parent.left - + onTextChanged: { + if (textField.text.length >= 3 && gifCreated) { + canNext = true + } else { + canNext = false + } + } } TextField { @@ -98,9 +156,3 @@ Rectangle { } } } - -/*##^## Designer { - D{i:0;autoSize:true;height:768;width:1366}D{i:4;anchors_height:200;anchors_x:200;anchors_y:0} -D{i:7;anchors_height:400;anchors_width:200}D{i:3;anchors_height:200;anchors_width:683} -} - ##^##*/ diff --git a/ScreenPlay/src/create.cpp b/ScreenPlay/src/create.cpp index ee11bb6c..2d24761a 100644 --- a/ScreenPlay/src/create.cpp +++ b/ScreenPlay/src/create.cpp @@ -6,17 +6,11 @@ Create::Create(Settings* st, QMLUtilities* util, QObject* parent) m_settings = st; m_utils = util; + + qRegisterMetaType(); qmlRegisterType("net.aimber.create", 1, 0, "Create"); } -Create::Create() -{ -} - -Create::~Create() -{ -} - void Create::copyProject(QString relativeProjectPath, QString toPath) { if (toPath.contains("file:///")) { @@ -53,321 +47,222 @@ bool Create::copyRecursively(const QString& srcFilePath, const QString& tgtFileP return true; } -void Create::importVideo(QString title, QUrl videoPath, QUrl previewPath, int videoDuration) +void Create::createWallpaperStart(QString videoPath) { - if (m_importState != Create::State::Idle) { - return; - } + videoPath.remove("file:///"); + QtConcurrent::run([=]() { - emit localWorkshopCreationStatusChanged(State::Started); - QString fromVideoPath = QString(videoPath.toString()).replace("file:///", ""); - QString fromImagePath = QString(previewPath.toString()).replace("file:///", ""); - QString toPath = m_settings->localStoragePath().toString() + "/" + title; - QString toPathWithVideoFile = toPath + "/" + videoPath.fileName(); - QString toPathWithImageFile = toPath + "/" + previewPath.fileName(); + QDir dir; + dir.cd(m_settings->localStoragePath().toString()); - if (QDir(toPath).exists()) { - if (!QDir(toPath).isEmpty()) { - emit localWorkshopCreationStatusChanged(State::ErrorFolder); - return; - } else { - //if(!QDir(toPath + )) - } + CreateWallpaperData createWallpaperData; + createWallpaperData.videoPath = videoPath; + // Create a temp dir so we can later alter it to the workshop id + createWallpaperData.exportPath = QString(dir.path() + "/" + "_tmp_" + QTime::currentTime().toString()).replace(":", ""); + + + if (dir.mkdir(createWallpaperData.exportPath)) { + // TODO } else { - //TODO: Display Error - if (!QDir().mkdir(toPath)) { - emit localWorkshopCreationStatusChanged(State::ErrorFolderCreation); - return; - } - } - - //Copy Video File - if (QFile::copy(fromVideoPath, toPathWithVideoFile)) { - emit localWorkshopCreationStatusChanged(State::CopyVideoFinished); - } else { - emit localWorkshopCreationStatusChanged(State::ErrorCopyVideo); - } - - //Copy Image File - if (QFile::copy(fromImagePath, toPathWithImageFile)) { - emit localWorkshopCreationStatusChanged(State::CopyImageFinished); - } else { - emit localWorkshopCreationStatusChanged(State::ErrorCopyImage); - } - - //Copy Project File - QFile configFile(toPath + "/" + "project.json"); - - if (!configFile.open(QIODevice::ReadWrite | QIODevice::Text)) { - emit localWorkshopCreationStatusChanged(State::ErrorCopyConfig); return; } - QTextStream out(&configFile); - QJsonObject configObj; + // If we return early/false this means the creation + // process did not work + // Todo: cleanup! - configObj.insert("file", videoPath.fileName()); - configObj.insert("preview", previewPath.fileName()); - //TODO - configObj.insert("description", ""); - configObj.insert("title", title); + if (!this->createWallpaperInfo(createWallpaperData)) + return; - QJsonDocument configJsonDocument(configObj); - out << configJsonDocument.toJson(); - configFile.close(); + if (!this->createWallpaperVideoPreview(createWallpaperData)) + return; - emit localWorkshopCreationStatusChanged(State::Finished); + if (!this->createWallpaperVideo(createWallpaperData)) + return; + + if (!this->createWallpaperProjectFile(createWallpaperData)) + return; }); } -void Create::importVideo(QString title, QUrl videoPath, int timeStamp, int videoDuration, int videoFrameRate) +bool Create::createWallpaperInfo(CreateWallpaperData& createWallpaperData) { + // Get video info + QStringList args; + args.append("-print_format"); + args.append("json"); + args.append("-show_format"); + args.append("-show_streams"); + args.append(createWallpaperData.videoPath); + QScopedPointer pro(new QProcess()); + pro.data()->setArguments(args); - if (m_importState != Create::State::Idle) { - return; - } - qDebug() << title << videoPath << timeStamp; - - QString tmpPath = videoPath.toString(); - tmpPath.remove("file:///"); - - QString tmpTimeStamp = QString::number(timeStamp); - QString ffmpegTimeStamp; - - QString sHours; - QString sMinutes; - QString sSeconds; - int intTmpTimeStamp; - - if (tmpTimeStamp.length() > 3) { - tmpTimeStamp.remove(tmpTimeStamp.length() - 3, 3); - intTmpTimeStamp = tmpTimeStamp.toInt(); - - const int cseconds_in_day = 86400; - const int cseconds_in_hour = 3600; - const int cseconds_in_minute = 60; - const int cseconds = 1; - int32 hours = (intTmpTimeStamp % cseconds_in_day) / cseconds_in_hour; - int32 minutes = ((intTmpTimeStamp % cseconds_in_day) % cseconds_in_hour) / cseconds_in_minute; - int32 seconds = (((intTmpTimeStamp % cseconds_in_day) % cseconds_in_hour) % cseconds_in_minute) / cseconds; - - if (hours < 10) { - sHours = "0" + QString::number(hours); - } else { - sHours = QString::number(hours); - } - if (minutes < 10) { - sMinutes = "0" + QString::number(minutes); - } else { - sMinutes = QString::number(minutes); - } - if (seconds < 10) { - sSeconds = "0" + QString::number(seconds); - } else { - sSeconds = QString::number(seconds); - } - } else { - ffmpegTimeStamp = "00:00:00"; - } - - QString tmpVideoDuration = QString::number(videoDuration); - - if (tmpVideoDuration.length() > 3) - tmpVideoDuration.remove(tmpVideoDuration.length() - 3, 3); - - int videoDurationInSeconds = tmpVideoDuration.toInt(); - - ffmpegTimeStamp = sHours + ":" + sMinutes + ":" + sSeconds; - - if (intTmpTimeStamp == 0 || videoFrameRate == 0) - qWarning() << "Cannot be zero!"; - - QtConcurrent::run([=]() { - QStringList args; - // Seek first because otherwise it will load - // the complete video first and this will make - // the conversion 50x slower! - args.append("-y"); - args.append("-ss"); - args.append(ffmpegTimeStamp); - args.append("-i"); - args.append(tmpPath); - args.append("-speed"); - args.append("ultrafast"); - args.append("-vframes"); - args.append("1"); - args.append("preview.png"); - QScopedPointer pro(new QProcess()); - - pro.data()->setArguments(args); - qDebug() << "Start converting video to thumbnail"; #ifdef Q_OS_WIN - pro.data()->setProgram(QApplication::applicationDirPath() + "/ffmpeg.exe"); + pro.data()->setProgram(QApplication::applicationDirPath() + "/ffprobe.exe"); #endif - emit localWorkshopCreationStatusChanged(State::ConvertingPreviewImage); - pro.data()->start(); - pro.data()->waitForFinished(-1); - qDebug() << "Done converting video to thumbnail" << pro.data()->readAllStandardOutput(); - emit localWorkshopCreationStatusChanged(State::ConvertingPreviewImageFinished); - pro.data()->close(); - }); + + pro.data()->start(); + pro.data()->waitForFinished(-1); + QJsonObject obj; + QJsonParseError err; + QJsonDocument doc = QJsonDocument::fromJson(pro.data()->readAll(), &err); + if (err.error == QJsonParseError::NoError) { + obj = doc.object(); + } + + pro.data()->close(); + + // Get video length + QJsonObject objFormat = obj.value("format").toObject(); + bool okParseDuration = false; + auto tmpLength = objFormat.value("duration").toVariant().toFloat(&okParseDuration); + + if (!okParseDuration) { + qDebug() << "Error parsing video length"; + return false; + } + + int length = 0; + length = static_cast(tmpLength); + createWallpaperData.length = length; + + // Get framerate + QJsonArray arrSteams = obj.value("streams").toArray(); + if (arrSteams.size() < 1) { + qDebug() << "Error container does not have any video streams"; + return false; + } + + QJsonObject tmpObjStreams = arrSteams.at(0).toObject(); + + // The paramter gets us the exact framerate + // "avg_frame_rate":"47850000/797509" + // so we need no calc the value by dividing the two numbers + QString avgFrameRate = tmpObjStreams.value("avg_frame_rate").toVariant().toString(); + + QStringList avgFrameRateList = avgFrameRate.split('/', QString::SkipEmptyParts); + if (avgFrameRateList.length() != 2) { + qDebug() << "Error could not parse streams with length: " << avgFrameRateList.length(); + return false; + } + + int framerate = 0; + float value1 = static_cast(avgFrameRateList.at(0).toInt()); + float value2 = static_cast(avgFrameRateList.at(1).toInt()); + + framerate = qCeil(value1 / value2); + createWallpaperData.framerate = framerate; + + return true; } -void Create::createVideoPreview(QString path, int frames, int frameRate) +bool Create::createWallpaperVideoPreview(CreateWallpaperData& createWallpaperData) { - if (m_importState != Create::State::Idle) { - return; - } - qDebug() << frames << frameRate; - QtConcurrent::run([=]() { - QStringList args; - args.append("-y"); - args.append("-stats"); - args.append("-i"); - args.append(path); - args.append("-speed"); - args.append("ultrafast"); - args.append("-vf"); - // We allways want to have a 5 second clip via 24fps -> 120 frames - // Divided by the number of frames we can skip (timeInSeconds * Framrate) - // scale & crop parameter: https://unix.stackexchange.com/a/284731 - args.append("select='not(mod(n," + QString::number((frames / 5)) + "))',setpts=N/FRAME_RATE/TB,crop=in_h*16/9:in_h,scale=-2:400"); - // Disable audio - args.append("-an"); - args.append(m_workingDir + "/preview.mp4"); - QScopedPointer proConvertPreviewMP4(new QProcess()); + qDebug() << createWallpaperData.length << createWallpaperData.framerate; + QStringList args; + args.append("-y"); + args.append("-stats"); + args.append("-i"); + args.append(createWallpaperData.videoPath); + args.append("-speed"); + args.append("ultrafast"); + args.append("-vf"); + // We allways want to have a 5 second clip via 24fps -> 120 frames + // Divided by the number of frames we can skip (timeInSeconds * Framrate) + // scale & crop parameter: https://unix.stackexchange.com/a/284731 + args.append("select='not(mod(n," + QString::number((createWallpaperData.length / 5)) + "))',setpts=N/FRAME_RATE/TB,crop=in_h*16/9:in_h,scale=-2:400"); + // Disable audio + args.append("-an"); + args.append(createWallpaperData.exportPath + "/preview.mp4"); + QScopedPointer proConvertPreviewMP4(new QProcess()); - proConvertPreviewMP4.data()->setArguments(args); - qDebug() << "Start converting video to preview mp4"; + proConvertPreviewMP4.data()->setArguments(args); + qDebug() << "Start converting video to preview mp4"; #ifdef Q_OS_WIN - proConvertPreviewMP4.data()->setProgram(QApplication::applicationDirPath() + "/ffmpeg.exe"); + proConvertPreviewMP4.data()->setProgram(QApplication::applicationDirPath() + "/ffmpeg.exe"); #endif - proConvertPreviewMP4.data()->start(); - proConvertPreviewMP4.data()->waitForFinished(-1); - qDebug() << proConvertPreviewMP4.data()->program() << proConvertPreviewMP4.data()->arguments(); - qDebug() << "Done converting video to preview" << proConvertPreviewMP4.data()->readAll() << "\n" - << proConvertPreviewMP4.data()->readAllStandardError(); - proConvertPreviewMP4.data()->close(); + emit createWallpaperStateChanged(Create::State::ConvertingPreviewVideo); - /* + proConvertPreviewMP4.data()->start(); + + QScopedPointer processOutputTimer(new QTimer()); + + connect(processOutputTimer.data(), &QTimer::timeout, [&]() { + qDebug() << "### " << proConvertPreviewMP4.data()->readAll(); + this->processOutput(proConvertPreviewMP4.data()->readAll()); + }); + processOutputTimer.data()->start(100); + proConvertPreviewMP4.data()->waitForFinished(-1); + // qDebug() << proConvertPreviewMP4.data()->program() << proConvertPreviewMP4.data()->arguments(); + // qDebug() << "Done converting video to preview" << proConvertPreviewMP4.data()->readAll() << "\n" + // << proConvertPreviewMP4.data()->readAllStandardError(); + proConvertPreviewMP4.data()->close(); + processOutputTimer.data()->stop(); + emit createWallpaperStateChanged(Create::State::ConvertingPreviewVideoFinished); + + /* * * Create gif * */ - args.clear(); - args.append("-y"); - args.append("-stats"); - args.append("-i"); - args.append(m_workingDir + "/preview.mp4"); - args.append("-filter_complex"); - args.append("[0:v] fps=12,scale=w=480:h=-1,split [a][b];[a] palettegen=stats_mode=single [p];[b][p] paletteuse=new=1"); - args.append(m_workingDir + "/preview.gif"); + emit createWallpaperStateChanged(Create::State::ConvertingPreviewGif); + args.clear(); + args.append("-y"); + args.append("-stats"); + args.append("-i"); + args.append(createWallpaperData.exportPath + "/preview.mp4"); + args.append("-filter_complex"); + args.append("[0:v] fps=12,scale=w=480:h=-1,split [a][b];[a] palettegen=stats_mode=single [p];[b][p] paletteuse=new=1"); + args.append(createWallpaperData.exportPath + "/preview.gif"); - QScopedPointer proConvertGif(new QProcess()); - proConvertGif.data()->setArguments(args); - qDebug() << "Start converting video to preview gif"; + QScopedPointer proConvertGif(new QProcess()); + proConvertGif.data()->setArguments(args); + qDebug() << "Start converting video to preview gif"; #ifdef Q_OS_WIN - proConvertGif.data()->setProgram(QApplication::applicationDirPath() + "/ffmpeg.exe"); + proConvertGif.data()->setProgram(QApplication::applicationDirPath() + "/ffmpeg.exe"); #endif - proConvertGif.data()->start(); - proConvertGif.data()->waitForFinished(-1); - qDebug() << proConvertGif.data()->program() << proConvertGif.data()->arguments(); - qDebug() << "Done converting video to preview" << proConvertGif.data()->readAll() << "\n" - << proConvertGif.data()->readAllStandardError(); - proConvertGif.data()->close(); - }); + proConvertGif.data()->start(); + proConvertGif.data()->waitForFinished(-1); + // qDebug() << proConvertGif.data()->program() << proConvertGif.data()->arguments(); + // qDebug() << "Done converting video to preview" << proConvertGif.data()->readAll() << "\n" + // << proConvertGif.data()->readAllStandardError(); + proConvertGif.data()->close(); + emit createWallpaperStateChanged(Create::State::ConvertingPreviewGifFinished); + + return true; } -void Create::createWallpaper(QString videoPath) +bool Create::createWallpaperVideo(CreateWallpaperData& createWallpaperData) { - - if (m_importState != Create::State::Idle) { - return; - } - videoPath.remove("file:///"); - - QDir dir; - dir.cd(m_settings->localStoragePath().toString()); - m_workingDir = QString("_tmp_" + QTime::currentTime().toString()).replace(":", ""); - - if (dir.mkdir(m_workingDir)) { - - } else { - return; - } - - m_workingDir = dir.path() + "/" + m_workingDir; - - QtConcurrent::run([=]() { - // Get video info - QStringList args; - args.append("-print_format"); - args.append("json"); - args.append("-show_format"); - args.append("-show_streams"); - args.append(videoPath); - QScopedPointer pro(new QProcess()); - pro.data()->setArguments(args); - -#ifdef Q_OS_WIN - pro.data()->setProgram(QApplication::applicationDirPath() + "/ffprobe.exe"); -#endif - - pro.data()->start(); - pro.data()->waitForFinished(-1); - QJsonObject obj; - QJsonParseError err; - QJsonDocument doc = QJsonDocument::fromJson(pro.data()->readAll(), &err); - if (err.error == QJsonParseError::NoError) { - obj = doc.object(); - } - - pro.data()->close(); - - // Get video length - QJsonObject objFormat = obj.value("format").toObject(); - bool okParseDuration = false; - auto tmpLength = objFormat.value("duration").toVariant().toFloat(&okParseDuration); - - if (!okParseDuration) { - qDebug() << "Error parsing video length"; - return; - } - - int length = 0; - length = static_cast(tmpLength); - - // Get framerate - QJsonArray arrSteams = obj.value("streams").toArray(); - if (arrSteams.size() < 1) { - qDebug() << "Error container does not have any video streams"; - return; - } - - QJsonObject tmpObjStreams = arrSteams.at(0).toObject(); - - // The paramter gets us the exact framerate - // "avg_frame_rate":"47850000/797509" - // so we need no calc the value by dividing the two numbers - QString avgFrameRate = tmpObjStreams.value("avg_frame_rate").toVariant().toString(); - - QStringList avgFrameRateList = avgFrameRate.split('/', QString::SkipEmptyParts); - if (avgFrameRateList.length() != 2) { - qDebug() << "Error could not parse streams with length: " << avgFrameRateList.length(); - return; - } - - int framerate = 0; - float value1 = static_cast(avgFrameRateList.at(0).toInt()); - float value2 = static_cast(avgFrameRateList.at(1).toInt()); - - framerate = qCeil(value1 / value2); - - this->createVideoPreview(videoPath, length, framerate); - }); + return true; +} + +bool Create::createWallpaperProjectFile(CreateWallpaperData& createWallpaperData) +{ + //Copy Project File + QFile configFile(createWallpaperData.exportPath + "/project.json"); + + if (!configFile.open(QIODevice::ReadWrite | QIODevice::Text)) { + + return false; + } + + // QTextStream out(&configFile); + // QJsonObject configObj; + + // configObj.insert("file", videoPath.fileName()); + // configObj.insert("preview", previewPath.fileName()); + // //TODO + // configObj.insert("description", ""); + // configObj.insert("title", title); + + // QJsonDocument configJsonDocument(configObj); + // out << configJsonDocument.toJson(); + configFile.close(); + return true; } diff --git a/ScreenPlay/src/create.h b/ScreenPlay/src/create.h index 456f0323..d3bff356 100644 --- a/ScreenPlay/src/create.h +++ b/ScreenPlay/src/create.h @@ -3,43 +3,49 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include +#include #include #include #include -#include -#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include #include "qmlutilities.h" #include "settings.h" +struct CreateWallpaperData { + CreateWallpaperData() {} + + QString videoPath = ""; + QString exportPath = ""; + int length = 0; + int framerate = 0; +}; + class Create : public QObject { Q_OBJECT public: - explicit Create(Settings* st, QMLUtilities* util,QObject *parent = nullptr); - Create(); - ~Create(); - - Q_PROPERTY(State importState READ importState WRITE setImportState NOTIFY importStateChanged) - + explicit Create(Settings* st, QMLUtilities* util, QObject* parent = nullptr); + Create() {} + ~Create() {} enum class State { Idle, Started, - CopyVideoFinished, - CopyImageFinished, - CopyConfigFinished, ConvertingPreviewImage, ConvertingPreviewImageFinished, ConvertingPreviewVideo, ConvertingPreviewVideoFinished, + ConvertingPreviewGif, + ConvertingPreviewGifFinished, Finished, ErrorFolder, ErrorFolderCreation, @@ -52,37 +58,25 @@ public: Q_ENUM(State) - - State importState() const - { - return m_importState; - } - signals: - void localWorkshopCreationStatusChanged(State status); - void importStateChanged(State importState); + void createWallpaperStateChanged(Create::State state); + void processOutput(QString text); + public slots: void copyProject(QString relativeProjectPath, QString toPath); bool copyRecursively(const QString& srcFilePath, const QString& tgtFilePath); - void importVideo(QString title, QUrl videoPath, QUrl previewPath, int videoDuration); - void importVideo(QString title, QUrl videoPath, int timeStamp, int videoDuration, int videoFrameRate); - void createVideoPreview(QString path, int frames, int length); - void createWallpaper(QString videoPath); - void setImportState(State importState) - { - if (m_importState == importState) - return; - - m_importState = importState; - emit importStateChanged(m_importState); - } + // Steps to convert any video to a wallpaper broken down into + // several methods in this order: + void createWallpaperStart(QString videoPath); + bool createWallpaperInfo(CreateWallpaperData& createWallpaperData); + bool createWallpaperVideoPreview(CreateWallpaperData& createWallpaperData); + bool createWallpaperVideo(CreateWallpaperData& createWallpaperData); + bool createWallpaperProjectFile(CreateWallpaperData& createWallpaperData); private: Settings* m_settings; QMLUtilities* m_utils; - QString m_workingDir; - State m_importState = State::Idle; };