diff --git a/ScreenPlay/qml/Create/Wizards/CreateWallpaper/CreateWallpaperVideoImportConvert.qml b/ScreenPlay/qml/Create/Wizards/CreateWallpaper/CreateWallpaperVideoImportConvert.qml index eb7b8211..7e2aac65 100644 --- a/ScreenPlay/qml/Create/Wizards/CreateWallpaper/CreateWallpaperVideoImportConvert.qml +++ b/ScreenPlay/qml/Create/Wizards/CreateWallpaper/CreateWallpaperVideoImportConvert.qml @@ -30,33 +30,33 @@ Item { target: screenPlayCreate onCreateWallpaperStateChanged: { - if (state === CreateImportVideo.State.ConvertingPreviewImageFinished) { + if (state === CreateImportVideo.ConvertingPreviewImageFinished) { imgPreview.source = "file:///" + screenPlayCreate.workingDir + "/preview.png" imgPreview.visible = true txtConvert.text = qsTr("Converting Video preview mp4") } - if (state === CreateImportVideo.State.ConvertingPreviewVideo) { + if (state === CreateImportVideo.ConvertingPreviewVideo) { txtConvert.text = qsTr("Generating preview video...") } - if (state === CreateImportVideo.State.ConvertingPreviewGif) { + if (state === CreateImportVideo.ConvertingPreviewGif) { txtConvert.text = qsTr("Generating preview gif...") } - if (state === CreateImportVideo.State.ConvertingPreviewGifFinished) { + if (state === CreateImportVideo.ConvertingPreviewGifFinished) { imgPreview.source = "file:///" + screenPlayCreate.workingDir + "/preview.gif" imgPreview.visible = true imgPreview.playing = true } - if (state === CreateImportVideo.State.ConvertingAudio) { + if (state === CreateImportVideo.ConvertingAudio) { txtConvert.text = qsTr("Converting Audio...") } - if (state === CreateImportVideo.State.ConvertingVideo) { + if (state === CreateImportVideo.ConvertingVideo) { txtConvert.text = qsTr("Converting Video...") } - if (state === CreateImportVideo.State.Finished) { + if (state === CreateImportVideo.Finished) { txtConvert.text = "" conversionFinishedSuccessful = true busyIndicator.running = false diff --git a/ScreenPlay/qml/Create/Wizards/CreateWallpaper/CreateWallpaperWizard.qml b/ScreenPlay/qml/Create/Wizards/CreateWallpaper/CreateWallpaperWizard.qml index e85469d2..4e4847b1 100644 --- a/ScreenPlay/qml/Create/Wizards/CreateWallpaper/CreateWallpaperWizard.qml +++ b/ScreenPlay/qml/Create/Wizards/CreateWallpaper/CreateWallpaperWizard.qml @@ -34,14 +34,14 @@ Item { Connections { target: screenPlayCreate onCreateWallpaperStateChanged: { - if (state === CreateImportVideo.State.AnalyseVideoError || state - === CreateImportVideo.State.ConvertingPreviewGifError || state - === CreateImportVideo.State.ConvertingPreviewImageError || state - === CreateImportVideo.State.ConvertingAudioError || state - === CreateImportVideo.State.AbortCleanupError || state - === CreateImportVideo.State.CopyFilesError || state - === CreateImportVideo.State.CreateProjectFileError || state - === CreateImportVideo.State.CreateTmpFolderError) { + if (state === CreateImportVideo.AnalyseVideoError || state + === CreateImportVideo.ConvertingPreviewGifError || state + === CreateImportVideo.ConvertingPreviewImageError || state + === CreateImportVideo.ConvertingAudioError || state + === CreateImportVideo.AbortCleanupError || state + === CreateImportVideo.CopyFilesError || state + === CreateImportVideo.CreateProjectFileError || state + === CreateImportVideo.CreateTmpFolderError) { createNew.state = "result" } } diff --git a/ScreenPlay/src/create.cpp b/ScreenPlay/src/create.cpp index 3eb18a62..1d622d66 100644 --- a/ScreenPlay/src/create.cpp +++ b/ScreenPlay/src/create.cpp @@ -15,9 +15,9 @@ Create::Create(const shared_ptr& settings, QObject* parent) , m_settings(settings) { - qRegisterMetaType(); + qRegisterMetaType("CreateImportVideo::ImportVideoState"); + qmlRegisterUncreatableType("ScreenPlay.Create", 1, 0, "CreateImportVideo", "Error only for enums"); qmlRegisterType("ScreenPlay.Create", 1, 0, "Create"); - qmlRegisterType("ScreenPlay.Create", 1, 0, "CreateImportVideo"); } // Constructor for the QMLEngine @@ -25,9 +25,9 @@ Create::Create() : QObject(nullptr) , m_settings(nullptr) { - qRegisterMetaType(); + qRegisterMetaType("CreateImportVideo::ImportVideoState"); + qmlRegisterUncreatableType("ScreenPlay.Create", 1, 0, "CreateImportVideo", "Error only for enums"); qmlRegisterType("ScreenPlay.Create", 1, 0, "Create"); - qmlRegisterType("ScreenPlay.Create", 1, 0, "CreateImportVideo"); } void Create::createWallpaperStart(QString videoPath) @@ -41,7 +41,7 @@ void Create::createWallpaperStart(QString videoPath) auto folderName = QString("_tmp_" + QTime::currentTime().toString()).replace(":", ""); if (!dir.mkdir(folderName)) { - emit createWallpaperStateChanged(CreateImportVideo::State::CreateTmpFolderError); + emit createWallpaperStateChanged(CreateImportVideo::ImportVideoState::CreateTmpFolderError); emit abortCreateWallpaper(); return; } @@ -66,23 +66,23 @@ void Create::saveWallpaper(QString title, QString description, QString filePath, filePath.remove("file:///"); previewImagePath.remove("file:///"); - emit createWallpaperStateChanged(CreateImportVideo::State::CopyFiles); + emit createWallpaperStateChanged(CreateImportVideo::ImportVideoState::CopyFiles); QFileInfo previewImageFile(previewImagePath); if (!QFile::copy(previewImagePath, m_workingDir + "/" + previewImageFile.fileName())) { qDebug() << "Could not copy" << previewImagePath << " to " << m_workingDir + "/" + previewImageFile.fileName(); - emit createWallpaperStateChanged(CreateImportVideo::State::CopyFilesError); + emit createWallpaperStateChanged(CreateImportVideo::ImportVideoState::CopyFilesError); return; } QFileInfo filePathFile(filePath); if (!QFile::copy(filePath, m_workingDir + "/" + filePathFile.fileName())) { qDebug() << "Could not copy" << filePath << " to " << m_workingDir + "/" + filePathFile.fileName(); - emit createWallpaperStateChanged(CreateImportVideo::State::CopyFilesError); + emit createWallpaperStateChanged(CreateImportVideo::ImportVideoState::CopyFilesError); return; } - emit createWallpaperStateChanged(CreateImportVideo::State::CopyFilesFinished); - emit createWallpaperStateChanged(CreateImportVideo::State::CreateProjectFile); + emit createWallpaperStateChanged(CreateImportVideo::ImportVideoState::CopyFilesFinished); + emit createWallpaperStateChanged(CreateImportVideo::ImportVideoState::CreateProjectFile); QFile file(m_workingDir + "/project.json"); QJsonObject obj; @@ -103,7 +103,7 @@ void Create::saveWallpaper(QString title, QString description, QString filePath, if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { qDebug() << "Could not open /project.json"; - emit createWallpaperStateChanged(CreateImportVideo::State::CreateProjectFileError); + emit createWallpaperStateChanged(CreateImportVideo::ImportVideoState::CreateProjectFileError); return; } @@ -113,11 +113,12 @@ void Create::saveWallpaper(QString title, QString description, QString filePath, out << doc.toJson(); file.close(); - emit createWallpaperStateChanged(CreateImportVideo::State::CreateProjectFileFinished); + emit createWallpaperStateChanged(CreateImportVideo::ImportVideoState::CreateProjectFileFinished); } void Create::abortAndCleanup() { + qWarning() << "Abort and Cleanup!"; if (m_createImportVideo == nullptr || m_createImportVideoThread == nullptr) { qDebug() << m_createImportVideo << m_createImportVideoThread; return; @@ -134,7 +135,7 @@ void Create::abortAndCleanup() if (exportPath.exists()) { if (!exportPath.removeRecursively()) { - emit createWallpaperStateChanged(CreateImportVideo::State::AbortCleanupError); + emit createWallpaperStateChanged(CreateImportVideo::ImportVideoState::AbortCleanupError); qWarning() << "Could not delete temp exportPath: " << exportPath; } else { qDebug() << "cleanup " << tmpExportPath; diff --git a/ScreenPlay/src/create.h b/ScreenPlay/src/create.h index 12290423..e89cdf40 100644 --- a/ScreenPlay/src/create.h +++ b/ScreenPlay/src/create.h @@ -28,8 +28,6 @@ namespace ScreenPlay { - - using std::shared_ptr, std::make_shared; @@ -56,7 +54,7 @@ public: } signals: - void createWallpaperStateChanged(CreateImportVideo::State state); + void createWallpaperStateChanged(CreateImportVideo::ImportVideoState state); void processOutput(QString text); void progressChanged(float progress); void abortCreateWallpaper(); diff --git a/ScreenPlay/src/createimportvideo.cpp b/ScreenPlay/src/createimportvideo.cpp index e5db6f16..c790b832 100644 --- a/ScreenPlay/src/createimportvideo.cpp +++ b/ScreenPlay/src/createimportvideo.cpp @@ -8,7 +8,7 @@ namespace ScreenPlay { class only exsits as long as the user creates a wallpaper and gets destroyed if the creation was successful or not. - The state get propagated via createWallpaperStateChanged(CreateImportVideo::State state); + The state get propagated via createWallpaperStateChanged(ImportVideoState state); \todo - Maybe: Replace with QThread to avoid running QCoreApplication::processEvents();? @@ -28,7 +28,6 @@ CreateImportVideo::CreateImportVideo(const QString& videoPath, const QString& ex void CreateImportVideo::process() { - qDebug() << "start converting video in thread: " << QThread::currentThreadId(); auto cleanup = qScopeGuard([this] { qDebug() << "ABORT"; @@ -48,7 +47,7 @@ void CreateImportVideo::process() if (!extractWallpaperAudio()) return; - emit createWallpaperStateChanged(CreateImportVideo::State::Finished); + emit createWallpaperStateChanged(ImportVideoState::Finished); } bool CreateImportVideo::createWallpaperInfo() @@ -71,7 +70,7 @@ bool CreateImportVideo::createWallpaperInfo() #endif pro.data()->start(); - emit createWallpaperStateChanged(CreateImportVideo::State::AnalyseVideo); + emit createWallpaperStateChanged(ImportVideoState::AnalyseVideo); while (!pro.data()->waitForFinished(100)) { if (QThread::currentThread()->isInterruptionRequested()) { qDebug() << "Interrupt thread"; @@ -83,13 +82,13 @@ bool CreateImportVideo::createWallpaperInfo() } QCoreApplication::processEvents(); } - emit createWallpaperStateChanged(CreateImportVideo::State::AnalyseVideoFinished); + emit createWallpaperStateChanged(ImportVideoState::AnalyseVideoFinished); QJsonObject obj; QJsonParseError err; QJsonDocument doc = QJsonDocument::fromJson(pro.data()->readAll(), &err); if (err.error != QJsonParseError::NoError) { emit processOutput("Error parsing ffmpeg json output"); - emit createWallpaperStateChanged(CreateImportVideo::State::AnalyseVideoError); + emit createWallpaperStateChanged(ImportVideoState::AnalyseVideoError); return false; } @@ -104,7 +103,7 @@ bool CreateImportVideo::createWallpaperInfo() if (!okParseDuration) { qDebug() << "Error parsing video length"; emit processOutput("Error parsing video length"); - emit createWallpaperStateChanged(CreateImportVideo::State::AnalyseVideoError); + emit createWallpaperStateChanged(ImportVideoState::AnalyseVideoError); return false; } @@ -170,7 +169,7 @@ bool CreateImportVideo::createWallpaperVideoPreview() #ifdef Q_OS_MACOS proConvertPreviewMP4.data()->setProgram(QApplication::applicationDirPath() + "/ffmpeg"); #endif - emit createWallpaperStateChanged(CreateImportVideo::State::ConvertingPreviewVideo); + emit createWallpaperStateChanged(ImportVideoState::ConvertingPreviewVideo); proConvertPreviewWebM.data()->start(); while (!proConvertPreviewWebM.data()->waitForFinished(100)) //Wake up every 100ms and check if we must exit @@ -191,7 +190,7 @@ bool CreateImportVideo::createWallpaperVideoPreview() QFile previewVideo(m_exportPath + "/preview.webm"); if (!previewVideo.exists() && !(previewVideo.size() > 0)) { emit processOutput(tmpErr); - emit createWallpaperStateChanged(CreateImportVideo::State::ConvertingPreviewVideoError); + emit createWallpaperStateChanged(ImportVideoState::ConvertingPreviewVideoError); return false; } } @@ -199,7 +198,7 @@ bool CreateImportVideo::createWallpaperVideoPreview() //this->processOutput(proConvertPreviewWebM.data()->readAll()); proConvertPreviewWebM.data()->close(); - emit createWallpaperStateChanged(CreateImportVideo::State::ConvertingPreviewVideoFinished); + emit createWallpaperStateChanged(ImportVideoState::ConvertingPreviewVideoFinished); return true; } @@ -207,7 +206,7 @@ bool CreateImportVideo::createWallpaperVideoPreview() bool CreateImportVideo::createWallpaperGifPreview() { - emit createWallpaperStateChanged(CreateImportVideo::State::ConvertingPreviewGif); + emit createWallpaperStateChanged(ImportVideoState::ConvertingPreviewGif); QStringList args; args.append("-y"); @@ -245,14 +244,14 @@ bool CreateImportVideo::createWallpaperGifPreview() if (!tmpErrGif.isEmpty()) { QFile previewGif(m_exportPath + "/preview.gif"); if (!previewGif.exists() && !(previewGif.size() > 0)) { - emit createWallpaperStateChanged(CreateImportVideo::State::ConvertingPreviewGifError); + emit createWallpaperStateChanged(ImportVideoState::ConvertingPreviewGifError); return false; } } //this->processOutput(proConvertGif.data()->readAll()); proConvertGif.data()->close(); - emit createWallpaperStateChanged(CreateImportVideo::State::ConvertingPreviewGifFinished); + emit createWallpaperStateChanged(ImportVideoState::ConvertingPreviewGifFinished); return true; } @@ -260,7 +259,7 @@ bool CreateImportVideo::createWallpaperGifPreview() bool CreateImportVideo::createWallpaperImagePreview() { - emit createWallpaperStateChanged(CreateImportVideo::State::ConvertingPreviewImage); + emit createWallpaperStateChanged(ImportVideoState::ConvertingPreviewImage); QStringList args; args.clear(); @@ -303,14 +302,14 @@ bool CreateImportVideo::createWallpaperImagePreview() if (!tmpErrImg.isEmpty()) { QFile previewImg(m_exportPath + "/preview.png"); if (!previewImg.exists() && !(previewImg.size() > 0)) { - emit createWallpaperStateChanged(CreateImportVideo::State::ConvertingPreviewImageError); + emit createWallpaperStateChanged(ImportVideoState::ConvertingPreviewImageError); return false; } } //this->processOutput(proConvertImage.data()->readAll()); proConvertImage.data()->close(); - emit createWallpaperStateChanged(CreateImportVideo::State::ConvertingPreviewImageFinished); + emit createWallpaperStateChanged(ImportVideoState::ConvertingPreviewImageFinished); return true; } @@ -318,7 +317,7 @@ bool CreateImportVideo::createWallpaperImagePreview() bool CreateImportVideo::extractWallpaperAudio() { - emit createWallpaperStateChanged(CreateImportVideo::State::ConvertingAudio); + emit createWallpaperStateChanged(ImportVideoState::ConvertingAudio); QStringList args; args.clear(); @@ -360,14 +359,14 @@ bool CreateImportVideo::extractWallpaperAudio() if (!tmpErrImg.isEmpty()) { QFile previewImg(m_exportPath + "/audio.mp3"); if (!previewImg.exists() && !(previewImg.size() > 0)) { - emit createWallpaperStateChanged(CreateImportVideo::State::ConvertingAudioError); + emit createWallpaperStateChanged(ImportVideoState::ConvertingAudioError); return false; } } //this->processOutput(proConvertAudio.data()->readAll()); proConvertAudio.data()->close(); - emit createWallpaperStateChanged(CreateImportVideo::State::ConvertingAudioFinished); + emit createWallpaperStateChanged(ImportVideoState::ConvertingAudioFinished); return true; } diff --git a/ScreenPlay/src/createimportvideo.h b/ScreenPlay/src/createimportvideo.h index 59b18652..3da8a02d 100644 --- a/ScreenPlay/src/createimportvideo.h +++ b/ScreenPlay/src/createimportvideo.h @@ -11,21 +11,28 @@ #include #include #include +#include #include #include #include -#include namespace ScreenPlay { + class CreateImportVideo : public QObject { Q_OBJECT public: + CreateImportVideo(){} CreateImportVideo(QObject* parent = nullptr); explicit CreateImportVideo(const QString& videoPath, const QString& exportPath, QObject* parent = nullptr); + ~CreateImportVideo(){} - enum class State { + QString m_videoPath; + QString m_exportPath; + int m_length = 0; + int m_framerate = 0; + enum class ImportVideoState { Idle, Started, AnalyseVideo, @@ -58,15 +65,10 @@ public: CreateTmpFolderError, Finished, }; - Q_ENUM(State) - - QString m_videoPath; - QString m_exportPath; - int m_length = 0; - int m_framerate = 0; + Q_ENUM(ImportVideoState) signals: - void createWallpaperStateChanged(CreateImportVideo::State state); + void createWallpaperStateChanged(CreateImportVideo::ImportVideoState state); void processOutput(QString text); void finished(); void canceled(); @@ -82,3 +84,4 @@ public slots: bool extractWallpaperAudio(); }; } +Q_DECLARE_METATYPE(ScreenPlay::CreateImportVideo::ImportVideoState)