1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-09-02 08:39:49 +02:00

Add ability to save wallpapers

Add preview
Cleanup
This commit is contained in:
Elias 2019-03-28 21:26:47 +01:00
parent 0d12c84107
commit 22ef3494e0
6 changed files with 102 additions and 77 deletions

View File

@ -3,14 +3,16 @@ import QtGraphicalEffects 1.0
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.3
import Qt.labs.platform 1.0
import QtQuick.Layouts 1.3
import QtQuick.Layouts 1.12
import net.aimber.create 1.0
Item {
id: wrapperContent
property string customVideoPreviewPath: ""
property bool conversionFinishedSuccessful: false
property bool canSave: false
signal save
Text {
id: txtHeadline
@ -96,18 +98,15 @@ Item {
imgPreview.source = "file:///"
+ screenPlayCreate.workingDir + "/preview.png"
imgPreview.visible = true
txtConvert.text = qsTr(
"Converting Video preview mp4")
txtConvert.text = qsTr("Converting Video preview mp4")
}
if (state === CreateImportVideo.State.ConvertingPreviewVideo) {
txtConvert.text = qsTr(
"Generating preview video...")
txtConvert.text = qsTr("Generating preview video...")
}
if (state === CreateImportVideo.State.ConvertingPreviewGif) {
txtConvert.text = qsTr(
"Generating preview gif...")
txtConvert.text = qsTr("Generating preview gif...")
}
if (state === CreateImportVideo.State.ConvertingPreviewGifFinished) {
@ -124,8 +123,9 @@ Item {
}
if (state === CreateImportVideo.State.Finished) {
imgSuccess.source = "file:///"
+ screenPlayCreate.workingDir + "/preview.gif"
txtConvert.text = ""
conversionFinishedSuccessful = true
busyIndicator.running = false
}
}
onProgressChanged: {
@ -151,16 +151,17 @@ Item {
Rectangle {
height: 50
color: "#eeeeee"
Layout.fillWidth: true
Layout.preferredWidth: imgWrapper.width
Text {
id: txtCustomPreviewPath
color: "#333333"
text: qsTr("Add custom preview image")
anchors {
verticalCenter: parent.verticalCenter
left: parent.left
leftMargin: 10
leftMargin: 20
}
}
@ -176,10 +177,9 @@ Item {
onClicked: fileDialogOpenFile.open()
}
FileDialog {
id: fileDialogOpenFile
nameFilters: ["*.png *.jpg"]
nameFilters: []
onAccepted: {
var file = fileDialogOpenFile.file.toString()
@ -207,44 +207,44 @@ Item {
right: parent.right
left: parent.left
margins: 30
top:parent.top
top: parent.top
topMargin: 0
bottom: column1.top
bottomMargin: 50
}
TextField {
id: textField
id: textFieldName
placeholderText: qsTr("Name")
width:parent.width
width: parent.width
Layout.fillWidth: true
onTextChanged: {
if (textField.text.length >= 3) {
canNext = true
if (textFieldName.text.length >= 3) {
canSave = true
} else {
canNext = false
canSave = false
}
}
}
TextField {
id: textField1
id: textFieldDescription
placeholderText: qsTr("Description")
width:parent.width
width: parent.width
Layout.fillWidth: true
}
TextField {
id: textField2
id: textFieldYoutubeURL
placeholderText: qsTr("Youtube URL")
width:parent.width
width: parent.width
Layout.fillWidth: true
}
TextField {
id: textField3
width:parent.width
placeholderText: qsTr("Tags")
id: textFieldTags
width: parent.width
placeholderText: qsTr("Tags (seperate with comma)")
Layout.fillWidth: true
}
}
@ -271,33 +271,32 @@ Item {
}
}
NextButton {
Button {
id: btnFinish
onClicked: {
if (btnFinish.state === "enabled" && canNext) {
screenPlayCreate.createWallpaperProjectFile(
textField.text, textField1.text)
utility.setNavigationActive(true)
createNew.state = "success"
text: qsTr("Save")
Material.background: Material.Gray
Material.foreground: "white"
enabled: {
if (canSave && conversionFinishedSuccessful) {
return true
} else {
return false
}
}
}
}
Connections {
target: screenPlayCreate
onCreateWallpaperStateChanged: {
if (state === CreateImportVideo.State.ConvertingVideoFinished) {
btnFinish.state = "enabled"
onClicked: {
if (conversionFinishedSuccessful) {
screenPlayCreate.saveWallpaper(
textFieldName.text, textFieldDescription.text, textFieldYoutubeURL.text, textFieldTags.text)
}
}
}
}
}
}
/*##^## Designer {
D{i:0;autoSize:true;height:480;width:640}
D{i:0;autoSize:true;height:480;width:950}
}
##^##*/

View File

@ -30,12 +30,14 @@ Item {
Connections {
target: screenPlayCreate
onCreateWallpaperStateChanged: {
if (state === CreateImportVideo.State.ConvertingPreviewGifError
if (state === CreateImportVideo.State.AnalyseVideoError
|| state === CreateImportVideo.State.ConvertingPreviewVideoError
|| state === CreateImportVideo.State.ConvertingPreviewGifError
|| state === CreateImportVideo.State.ConvertingPreviewImageError
|| state === CreateImportVideo.State.AnalyseVideoError) {
createNew.state = "error"
|| state === CreateImportVideo.State.ConvertingAudioError
|| state === CreateImportVideo.State.AbortCleanupError
|| state === CreateImportVideo.State.ErrorUnknown) {
createNew.state = "result"
}
}
}
@ -84,6 +86,12 @@ Item {
id: loader_wrapperContent
anchors.fill: parent
z: 10
Connections {
target: loader_wrapperContent.sourceComponent
onSave:{
createNew.state = "result"
}
}
}
CreateWallpaperResult {
@ -275,7 +283,7 @@ Item {
},
Transition {
from: "in"
to: "error"
to: "result"
SequentialAnimation {
PropertyAnimation {
target: loader_wrapperContent
@ -293,21 +301,6 @@ Item {
easing.type: Easing.OutQuart
}
}
},
Transition {
from: "in"
to: "success"
SequentialAnimation {
PropertyAnimation {
target: loader_wrapperContent
duration: 600
property: "opacity"
easing.type: Easing.OutQuart
}
PauseAnimation {
duration: 50
}
}
}
]
}

View File

@ -55,18 +55,20 @@ void Create::createWallpaperStart(QString videoPath)
videoPath.remove("file:///");
QDir dir;
dir.cd(this->m_settings->localStoragePath().toLocalFile());
dir.cd(m_settings->localStoragePath().toLocalFile());
// Create a temp dir so we can later alter it to the workshop id
auto folderName = QString("_tmp_" + QTime::currentTime().toString()).replace(":", "");
if (!dir.mkdir(folderName)) {
emit createWallpaperStateChanged(CreateImportVideo::State::CreateTmpFolderError);
emit abortCreateWallpaper();
return;
}
setWorkingDir(dir.path() + "/" + folderName);
m_createImportVideoThread = new QThread;
m_createImportVideo = new CreateImportVideo(videoPath, dir.path() + "/" + folderName);
m_createImportVideo = new CreateImportVideo(videoPath, workingDir());
connect(m_createImportVideo, &CreateImportVideo::createWallpaperStateChanged, this, &Create::createWallpaperStateChanged);
connect(m_createImportVideoThread, &QThread::started, m_createImportVideo, &CreateImportVideo::process);
@ -78,8 +80,17 @@ void Create::createWallpaperStart(QString videoPath)
m_createImportVideoThread->start();
}
void Create::createWallpaperProjectFile(QString name, QString description, QString youtube, QStringList tags)
{
}
void Create::abortAndCleanup()
{
if (m_createImportVideo != nullptr || m_createImportVideoThread != nullptr) {
return;
}
// Save to export path before aborting to be able to cleanup the tmp folder
QString tmpExportPath = m_createImportVideo->m_exportPath;
@ -94,6 +105,8 @@ void Create::abortAndCleanup()
qDebug() << "cleanup " << tmpExportPath;
}
}
m_createImportVideo = nullptr;
m_createImportVideoThread = nullptr;
});
m_createImportVideoThread->requestInterruption();
}

View File

@ -31,6 +31,7 @@ class Create : public QObject {
public:
explicit Create(Settings* st, QMLUtilities* util, QObject* parent = nullptr);
Q_PROPERTY(QString workingDir READ workingDir WRITE setWorkingDir NOTIFY workingDirChanged)
Q_PROPERTY(float progress READ progress WRITE setProgress NOTIFY progressChanged)
Create() {}
@ -41,17 +42,24 @@ public:
return m_progress;
}
QString workingDir() const
{
return m_workingDir;
}
signals:
void createWallpaperStateChanged(CreateImportVideo::State state);
void processOutput(QString text);
void progressChanged(float progress);
void abortCreateWallpaper();
void workingDirChanged(QString workingDir);
public slots:
void copyProject(QString relativeProjectPath, QString toPath);
bool copyRecursively(const QString& srcFilePath, const QString& tgtFilePath);
void abortAndCleanup();
void createWallpaperStart(QString videoPath);
void saveWallpaper(QString name, QString description, QString youtube, QString tags);
void abortAndCleanup();
void setProgress(float progress)
{
@ -62,6 +70,15 @@ public slots:
emit progressChanged(m_progress);
}
void setWorkingDir(QString workingDir)
{
if (m_workingDir == workingDir)
return;
m_workingDir = workingDir;
emit workingDirChanged(m_workingDir);
}
private:
CreateImportVideo* m_createImportVideo;
Settings* m_settings;
@ -69,4 +86,5 @@ private:
QMLUtilities* m_utils;
float m_progress = 0.0f;
QString m_workingDir;
};

View File

@ -14,11 +14,13 @@ CreateImportVideo::CreateImportVideo(QString videoPath, QString exportPath, QObj
void CreateImportVideo::process()
{
qDebug() << "start converting video" << QThread::currentThreadId();
qDebug() << "start converting video in thread: " << QThread::currentThreadId();
createWallpaperInfo();
createWallpaperVideoPreview();
createWallpaperGifPreview();
extractWallpaperAudio();
emit createWallpaperStateChanged(CreateImportVideo::State::Finished);
emit finished();
}
@ -117,20 +119,20 @@ bool CreateImportVideo::createWallpaperVideoPreview()
{
QStringList args;
// args.append("-loglevel");
// args.append("error");
// args.append("-y");
// args.append("-stats");
args.append("-loglevel");
args.append("error");
args.append("-y");
args.append("-stats");
args.append("-i");
args.append(m_videoPath);
//args.append("-vf");
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((m_length / 5)) + "))',setpts=N/FRAME_RATE/TB,crop=in_h*16/9:in_h,scale=-2:400");
args.append("select='not(mod(n," + QString::number((m_length / 5)) + "))',setpts=N/FRAME_RATE/TB,crop=in_h*16/9:in_h,scale=-2:400");
// Disable audio
//args.append("-an");
args.append("-an");
args.append(m_exportPath + "/preview.webm");
QScopedPointer<QProcess> proConvertPreviewWebM(new QProcess());
@ -143,7 +145,6 @@ bool CreateImportVideo::createWallpaperVideoPreview()
#endif
emit createWallpaperStateChanged(CreateImportVideo::State::ConvertingPreviewVideo);
proConvertPreviewWebM.data()->start();
while (!proConvertPreviewWebM.data()->waitForFinished(100)) //Wake up every 100ms and check if we must exit
{

View File

@ -45,6 +45,7 @@ public:
// ConvertingVideoFinished,
// ConvertingVideoError,
AbortCleanupError,
CreateTmpFolderError,
Finished,
ErrorUnknown,
};