mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-25 20:22:39 +01:00
Refactor wizards into separate class
This commit is contained in:
parent
bbb827ed66
commit
7302b2eba5
@ -41,7 +41,8 @@ set(src
|
||||
src/screenplaymanager.cpp
|
||||
src/sdkconnection.cpp
|
||||
src/util.cpp
|
||||
src/create.cpp)
|
||||
src/create.cpp
|
||||
src/wizards.cpp)
|
||||
|
||||
set(headers
|
||||
app.h
|
||||
@ -61,7 +62,8 @@ set(headers
|
||||
src/screenplaymanager.h
|
||||
src/sdkconnection.h
|
||||
src/util.h
|
||||
src/create.h)
|
||||
src/create.h
|
||||
src/wizards.h)
|
||||
|
||||
set(l10n
|
||||
translations/ScreenPlay_de.ts
|
||||
|
@ -118,6 +118,7 @@ App::App()
|
||||
qmlRegisterAnonymousType<ScreenPlayManager>("ScreenPlay", 1);
|
||||
qmlRegisterAnonymousType<Util>("ScreenPlay", 1);
|
||||
qmlRegisterAnonymousType<Create>("ScreenPlay", 1);
|
||||
qmlRegisterAnonymousType<Wizards>("ScreenPlay", 1);
|
||||
qmlRegisterAnonymousType<Settings>("ScreenPlay", 1);
|
||||
|
||||
// ScreenPlayManager first to check if another ScreenPlay Instace is running
|
||||
@ -150,6 +151,7 @@ void App::init()
|
||||
m_mainWindowEngine = make_unique<QQmlApplicationEngine>();
|
||||
m_screenPlayManager->init(m_globalVariables, m_monitorListModel, m_telemetry, m_settings);
|
||||
|
||||
|
||||
// Only create tracker if user did not disallow!
|
||||
if (m_settings->anonymousTelemetry()) {
|
||||
m_telemetry = make_shared<GAnalytics>("UA-152830367-3");
|
||||
@ -173,6 +175,13 @@ void App::init()
|
||||
}
|
||||
|
||||
m_create = make_unique<Create>(m_globalVariables);
|
||||
m_threadPool.setMaxThreadCount(5);
|
||||
m_threadPool.reserveThread();
|
||||
m_wizards = make_unique<Wizards>(m_globalVariables);
|
||||
m_wizards->moveToThread(m_threadPool.thread());
|
||||
qInfo() << m_installedListModel->thread() << m_threadPool.thread();
|
||||
m_installedListModel->moveToThread(m_threadPool.thread());
|
||||
qInfo() << m_installedListModel->thread();
|
||||
|
||||
// When the installed storage path changed
|
||||
QObject::connect(m_settings.get(), &Settings::resetInstalledListmodel, m_installedListModel.get(), &InstalledListModel::reset);
|
||||
|
@ -11,151 +11,104 @@ import "../../Common" as Common
|
||||
|
||||
WizardPage {
|
||||
id: root
|
||||
sourceComponent: Item {
|
||||
|
||||
ColumnLayout {
|
||||
id: rightWrapper
|
||||
spacing: 10
|
||||
anchors {
|
||||
top: parent.top
|
||||
right: parent.right
|
||||
left: parent.left
|
||||
}
|
||||
sourceComponent: ColumnLayout {
|
||||
id: rightWrapper
|
||||
spacing: 10
|
||||
anchors {
|
||||
top: parent.top
|
||||
right: parent.right
|
||||
left: parent.left
|
||||
}
|
||||
|
||||
Common.Headline {
|
||||
text: qsTr("Create a QML Wallpaper")
|
||||
}
|
||||
function create() {
|
||||
ScreenPlay.wizards.createQMLWallpaper(
|
||||
tfTitle.text, previewSelector.imageSource,
|
||||
cbLicense.currentText, tagSelector.getTags())
|
||||
}
|
||||
|
||||
Common.HeadlineSection {
|
||||
text: qsTr("General")
|
||||
}
|
||||
RowLayout {
|
||||
spacing: 20
|
||||
Common.Headline {
|
||||
text: qsTr("Create a QML Wallpaper")
|
||||
}
|
||||
|
||||
Common.TextField {
|
||||
id: tfTitle
|
||||
Layout.fillWidth: true
|
||||
placeholderText: qsTr("Wallpaper name")
|
||||
onTextChanged: {
|
||||
if (text.length >= 3) {
|
||||
btnSave.enabled = true
|
||||
} else {
|
||||
btnSave.enabled = false
|
||||
}
|
||||
}
|
||||
}
|
||||
Common.TextField {
|
||||
id: tfCreatedBy
|
||||
Layout.fillWidth: true
|
||||
placeholderText: qsTr("Copyright owner")
|
||||
}
|
||||
Common.HeadlineSection {
|
||||
text: qsTr("General")
|
||||
}
|
||||
RowLayout {
|
||||
spacing: 20
|
||||
|
||||
Common.TextField {
|
||||
id: tfTitle
|
||||
Layout.fillWidth: true
|
||||
placeholderText: qsTr("Wallpaper name")
|
||||
onTextChanged: root.ready = text.length >= 1
|
||||
}
|
||||
Common.TextField {
|
||||
id: tfDescription
|
||||
id: tfCreatedBy
|
||||
Layout.fillWidth: true
|
||||
placeholderText: qsTr("Description")
|
||||
placeholderText: qsTr("Copyright owner")
|
||||
}
|
||||
}
|
||||
Common.TextField {
|
||||
id: tfDescription
|
||||
Layout.fillWidth: true
|
||||
placeholderText: qsTr("Description")
|
||||
}
|
||||
|
||||
Item {
|
||||
height: 30
|
||||
}
|
||||
Item {
|
||||
height: 30
|
||||
}
|
||||
|
||||
Common.HeadlineSection {
|
||||
text: qsTr("License & Tags")
|
||||
}
|
||||
Common.HeadlineSection {
|
||||
text: qsTr("License & Tags")
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
spacing: 20
|
||||
RowLayout {
|
||||
spacing: 20
|
||||
|
||||
ComboBox {
|
||||
id: cbLicense
|
||||
Layout.fillWidth: true
|
||||
font.family: ScreenPlay.settings.font
|
||||
model: ListModel {
|
||||
id: modelLicense
|
||||
ListElement {
|
||||
text: "Copyright by me"
|
||||
}
|
||||
ListElement {
|
||||
text: "Open Source - GPLv3"
|
||||
}
|
||||
ListElement {
|
||||
text: "Open Source - MIT/Apache2"
|
||||
}
|
||||
ComboBox {
|
||||
id: cbLicense
|
||||
Layout.fillWidth: true
|
||||
font.family: ScreenPlay.settings.font
|
||||
model: ListModel {
|
||||
id: modelLicense
|
||||
ListElement {
|
||||
text: "Copyright by me"
|
||||
}
|
||||
ListElement {
|
||||
text: "Open Source - GPLv3"
|
||||
}
|
||||
ListElement {
|
||||
text: "Open Source - MIT/Apache2"
|
||||
}
|
||||
}
|
||||
|
||||
Common.TagSelector {
|
||||
id: tagSelector
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
height: 30
|
||||
}
|
||||
|
||||
Common.HeadlineSection {
|
||||
text: qsTr("Preview Image")
|
||||
}
|
||||
|
||||
Common.ImageSelector {
|
||||
id: previewSelector
|
||||
Common.TagSelector {
|
||||
id: tagSelector
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
height: 30
|
||||
}
|
||||
Item {
|
||||
height: 30
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
spacing: 10
|
||||
Common.HeadlineSection {
|
||||
text: qsTr("Preview Image")
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: ScreenPlay.create
|
||||
function onHtmlWallpaperCreatedSuccessful(path) {
|
||||
ScreenPlay.util.openFolderInExplorer(path)
|
||||
}
|
||||
}
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
Common.ImageSelector {
|
||||
id: previewSelector
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
Button {
|
||||
id: btnExit
|
||||
text: qsTr("Abort")
|
||||
Material.background: Material.Red
|
||||
Material.foreground: "white"
|
||||
Layout.alignment: Qt.AlignRight
|
||||
font.family: ScreenPlay.settings.font
|
||||
onClicked: {
|
||||
root.decrementCurrentIndex()
|
||||
root.wizardExited()
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: btnSave
|
||||
text: qsTr("Save")
|
||||
enabled: false
|
||||
Material.background: Material.accent
|
||||
Material.foreground: "white"
|
||||
Layout.alignment: Qt.AlignRight
|
||||
font.family: ScreenPlay.settings.font
|
||||
onClicked: {
|
||||
btnSave.enabled = false
|
||||
savePopup.open()
|
||||
var tags = tagSelector.getTags()
|
||||
ScreenPlay.create.createQMLWallpaper(
|
||||
ScreenPlay.globalVariables.localStoragePath,
|
||||
tfTitle.text, previewSelector.imageSource,
|
||||
cbLicense.currentText, tags)
|
||||
}
|
||||
}
|
||||
}
|
||||
Item {
|
||||
height: 30
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*##^##
|
||||
Designer {
|
||||
D{i:0;autoSize:true;height:480;width:640}
|
||||
|
@ -84,7 +84,7 @@ WizardPage {
|
||||
Common.TextField {
|
||||
id: tfCreatedBy
|
||||
Layout.fillWidth: true
|
||||
placeholderText: qsTr("Copyright owner")
|
||||
placeholderText: qsTr("Created by")
|
||||
}
|
||||
|
||||
Text {
|
||||
|
@ -1,8 +1,9 @@
|
||||
import QtQuick 2.12
|
||||
import QtGraphicalEffects 1.0
|
||||
import QtQuick.Controls 2.2
|
||||
import QtQuick.Controls 2.15
|
||||
import QtQuick.Controls.Material 2.3
|
||||
import QtQuick.Layouts 1.12
|
||||
import QtQuick.Window 2.12
|
||||
|
||||
import ScreenPlay 1.0
|
||||
import ScreenPlay.Create 1.0
|
||||
@ -12,17 +13,21 @@ FocusScope {
|
||||
|
||||
signal wizardStarted
|
||||
signal wizardExited
|
||||
signal saveClicked
|
||||
signal saveFinished
|
||||
signal cancelClicked
|
||||
|
||||
property Component sourceComponent
|
||||
property alias savePopup: savePopup
|
||||
property bool ready: false
|
||||
|
||||
ScrollView {
|
||||
anchors {
|
||||
topMargin: 20
|
||||
top:parent.top
|
||||
right:parent.right
|
||||
bottom: parent.bottom
|
||||
left:parent.left
|
||||
margins: 20
|
||||
top: parent.top
|
||||
right: parent.right
|
||||
bottom: footer.top
|
||||
left: parent.left
|
||||
}
|
||||
|
||||
contentWidth: width
|
||||
@ -30,8 +35,8 @@ FocusScope {
|
||||
|
||||
Loader {
|
||||
id: loader
|
||||
width: Math.min(parent.width, 800)
|
||||
height: item.childrenRect.height
|
||||
width: parent.width
|
||||
Component.onCompleted: height = item.childrenRect.height
|
||||
clip: true
|
||||
sourceComponent: root.sourceComponent
|
||||
anchors {
|
||||
@ -41,13 +46,43 @@ FocusScope {
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: footer
|
||||
anchors {
|
||||
right: parent.right
|
||||
bottom: parent.bottom
|
||||
left: parent.left
|
||||
margins: 20
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
Button {
|
||||
id: btnSave
|
||||
text: qsTr("Save")
|
||||
enabled: root.ready
|
||||
Material.background: Material.accent
|
||||
Material.foreground: "white"
|
||||
Layout.alignment: Qt.AlignRight
|
||||
font.family: ScreenPlay.settings.font
|
||||
onClicked: {
|
||||
btnSave.enabled = false
|
||||
root.saveClicked()
|
||||
loader.item.create()
|
||||
savePopup.open()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Popup {
|
||||
id: savePopup
|
||||
modal: true
|
||||
focus: true
|
||||
width: 250
|
||||
height: 200
|
||||
anchors.centerIn: parent
|
||||
anchors.centerIn: Overlay.overlay
|
||||
onOpened: timerSave.start()
|
||||
|
||||
BusyIndicator {
|
||||
@ -57,6 +92,7 @@ FocusScope {
|
||||
|
||||
Text {
|
||||
text: qsTr("Saving...")
|
||||
color: Material.primaryHighlightedTextColor
|
||||
font.family: ScreenPlay.settings.font
|
||||
anchors {
|
||||
horizontalCenter: parent.horizontalCenter
|
||||
|
@ -42,171 +42,6 @@ Create::Create()
|
||||
qmlRegisterType<Create>("ScreenPlay.Create", 1, 0, "Create");
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Creates a new widget.
|
||||
*/
|
||||
void Create::createWidget(const QString& localStoragePath, const QString& title, const QString& previewThumbnail, const QString& createdBy, const QString& license, const QString& type, const QVector<QString>& tags)
|
||||
{
|
||||
QtConcurrent::run([=]() {
|
||||
QUrl localStoragePathUrl { localStoragePath };
|
||||
QDir dir;
|
||||
dir.cd(localStoragePathUrl.toLocalFile());
|
||||
// Create a temp dir so we can later alter it to the workshop id
|
||||
auto folderName = QString("_tmp_" + QTime::currentTime().toString()).replace(":", "");
|
||||
QString workingPath = dir.path() + "/" + folderName;
|
||||
|
||||
if (!dir.mkdir(folderName)) {
|
||||
qDebug() << "Could create folder: " << folderName;
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonObject obj;
|
||||
obj.insert("license", license);
|
||||
obj.insert("title", title);
|
||||
obj.insert("createdBy", createdBy);
|
||||
|
||||
if (type == "QML") {
|
||||
obj.insert("type", "qmlWidget");
|
||||
obj.insert("file", "main.qml");
|
||||
|
||||
QFile fileMainQML(workingPath + "/main.qml");
|
||||
if (!fileMainQML.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug() << "Could not open /main.qml";
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream outMainQML(&fileMainQML);
|
||||
outMainQML.setCodec("UTF-8");
|
||||
outMainQML << "import QtQuick 2.14 \n\n Item {\n id:root \n}";
|
||||
fileMainQML.close();
|
||||
|
||||
} else {
|
||||
obj.insert("type", "htmlWidget");
|
||||
obj.insert("file", "index.html");
|
||||
|
||||
QFile fileMainHTML(workingPath + "/index.html");
|
||||
if (!fileMainHTML.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug() << "Could not open /index.html";
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream outMainHTML(&fileMainHTML);
|
||||
outMainHTML.setCodec("UTF-8");
|
||||
outMainHTML << "<html>\n<head></head>\n<body></body>\n</html>";
|
||||
fileMainHTML.close();
|
||||
}
|
||||
|
||||
QJsonArray tagsJsonArray;
|
||||
for (const QString& tmp : tags) {
|
||||
tagsJsonArray.append(tmp);
|
||||
}
|
||||
obj.insert("tags", tagsJsonArray);
|
||||
|
||||
QFile file(workingPath + "/project.json");
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug() << "Could not open /project.json";
|
||||
return;
|
||||
}
|
||||
|
||||
QUrl previewThumbnailUrl { previewThumbnail };
|
||||
QFileInfo previewImageFile(previewThumbnailUrl.toLocalFile());
|
||||
|
||||
if (!previewThumbnail.isEmpty()) {
|
||||
obj.insert("previewThumbnail", previewImageFile.fileName());
|
||||
obj.insert("preview", previewImageFile.fileName());
|
||||
if (!QFile::copy(previewThumbnailUrl.toLocalFile(), workingPath + "/" + previewImageFile.fileName())) {
|
||||
qDebug() << "Could not copy" << previewThumbnailUrl.toLocalFile() << " to " << workingPath + "/" + previewImageFile.fileName();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
out.setCodec("UTF-8");
|
||||
QJsonDocument doc(obj);
|
||||
out << doc.toJson();
|
||||
file.close();
|
||||
|
||||
emit widgetCreatedSuccessful(workingPath);
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Creates a HTML wallpaper.
|
||||
*/
|
||||
void Create::createHTMLWallpaper(
|
||||
const QString& localStoragePath,
|
||||
const QString& title,
|
||||
const QString& previewThumbnail,
|
||||
const QString& license,
|
||||
const QVector<QString>& tags)
|
||||
{
|
||||
QtConcurrent::run([=]() {
|
||||
QUrl localStoragePathUrl { localStoragePath };
|
||||
QDir dir;
|
||||
dir.cd(localStoragePathUrl.toLocalFile());
|
||||
// Create a temp dir so we can later alter it to the workshop id
|
||||
auto folderName = QString("_tmp_" + QTime::currentTime().toString()).replace(":", "");
|
||||
QString workingPath = dir.path() + "/" + folderName;
|
||||
|
||||
if (!dir.mkdir(folderName)) {
|
||||
qDebug() << "Could create folder: " << folderName;
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonObject obj;
|
||||
obj.insert("license", license);
|
||||
obj.insert("title", title);
|
||||
|
||||
obj.insert("type", "htmlWallpaper");
|
||||
obj.insert("file", "index.html");
|
||||
|
||||
QFile fileMainHTML(workingPath + "/index.html");
|
||||
if (!fileMainHTML.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug() << "Could not open /index.html";
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream outMainHTML(&fileMainHTML);
|
||||
outMainHTML.setCodec("UTF-8");
|
||||
outMainHTML << "<html>\n<head></head>\n"
|
||||
"<h1>This is an empty html Wallpaper!</h1>"
|
||||
"<body></body>\n</html>";
|
||||
fileMainHTML.close();
|
||||
|
||||
QJsonArray tagsJsonArray;
|
||||
for (const QString& tmp : tags) {
|
||||
tagsJsonArray.append(tmp);
|
||||
}
|
||||
obj.insert("tags", tagsJsonArray);
|
||||
|
||||
QFile file(workingPath + "/project.json");
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug() << "Could not open /project.json";
|
||||
return;
|
||||
}
|
||||
|
||||
QUrl previewThumbnailUrl { previewThumbnail };
|
||||
QFileInfo previewImageFile(previewThumbnailUrl.toLocalFile());
|
||||
|
||||
if (!previewThumbnail.isEmpty()) {
|
||||
obj.insert("previewThumbnail", previewImageFile.fileName());
|
||||
obj.insert("preview", previewImageFile.fileName());
|
||||
if (!QFile::copy(previewThumbnailUrl.toLocalFile(), workingPath + "/" + previewImageFile.fileName())) {
|
||||
qDebug() << "Could not copy" << previewThumbnailUrl.toLocalFile() << " to " << workingPath + "/" + previewImageFile.fileName();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
out.setCodec("UTF-8");
|
||||
QJsonDocument doc(obj);
|
||||
out << doc.toJson();
|
||||
file.close();
|
||||
|
||||
emit widgetCreatedSuccessful(workingPath);
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Starts the process.
|
||||
*/
|
||||
@ -228,11 +63,7 @@ void Create::createWallpaperStart(QString videoPath, Create::VideoCodec codec)
|
||||
}
|
||||
setWorkingDir(dir.path() + "/" + folderName);
|
||||
QStringList codecs;
|
||||
if (codec == Create::VideoCodec::VP8) {
|
||||
codecs.append("vp8");
|
||||
} else {
|
||||
codecs.append("vp9");
|
||||
}
|
||||
codecs.append(codec == Create::VideoCodec::VP8 ? "vp8" : "vp9");
|
||||
|
||||
m_createImportVideoThread = new QThread(this);
|
||||
m_createImportVideo = new CreateImportVideo(videoPath, workingDir(), codecs);
|
||||
@ -293,17 +124,19 @@ void Create::saveWallpaper(QString title, QString description, QString filePath,
|
||||
}
|
||||
emit createWallpaperStateChanged(CreateImportVideo::ImportVideoState::CopyFilesFinished);
|
||||
emit createWallpaperStateChanged(CreateImportVideo::ImportVideoState::CreateProjectFile);
|
||||
QFile file(m_workingDir + "/project.json");
|
||||
|
||||
QJsonObject obj;
|
||||
obj.insert("description", description);
|
||||
obj.insert("title", title);
|
||||
obj.insert("youtube", youtube);
|
||||
if (codec == Create::VideoCodec::VP8) {
|
||||
obj.insert("videoCodec", "vp8");
|
||||
} else {
|
||||
obj.insert("videoCodec", "vp9");
|
||||
}
|
||||
obj.insert("videoCodec", codec == Create::VideoCodec::VP8 ? "vp8" : "vp9");
|
||||
obj.insert("file", filePathFile.baseName() + ".webm");
|
||||
obj.insert("previewGIF", "preview.gif");
|
||||
obj.insert("previewWEBM", "preview.webm");
|
||||
obj.insert("preview", previewImageFile.exists() ? previewImageFile.fileName() : "preview.jpg");
|
||||
obj.insert("previewThumbnail", "previewThumbnail.jpg");
|
||||
obj.insert("type", "videoWallpaper");
|
||||
obj.insert("tags", Util::fillArray(tags));
|
||||
|
||||
QFile audioFile { m_workingDir + "/audio.mp3" };
|
||||
if (audioFile.exists() && audioFile.size() > 0) {
|
||||
@ -311,43 +144,14 @@ void Create::saveWallpaper(QString title, QString description, QString filePath,
|
||||
obj.insert("audioCodec", "mp3");
|
||||
}
|
||||
|
||||
// If the input file is a webm we don't need to convert it
|
||||
if (filePath.endsWith(".webm")) {
|
||||
obj.insert("file", filePathFile.fileName());
|
||||
} else {
|
||||
obj.insert("file", filePathFile.baseName() + ".webm");
|
||||
}
|
||||
obj.insert("previewGIF", "preview.gif");
|
||||
obj.insert("previewWEBM", "preview.webm");
|
||||
if (previewImageFile.exists()) {
|
||||
obj.insert("preview", previewImageFile.fileName());
|
||||
} else {
|
||||
obj.insert("preview", "preview.jpg");
|
||||
}
|
||||
obj.insert("previewThumbnail", "previewThumbnail.jpg");
|
||||
obj.insert("type", "videoWallpaper");
|
||||
|
||||
QJsonArray tagsJsonArray;
|
||||
for (const QString& tmp : tags) {
|
||||
tagsJsonArray.append(tmp);
|
||||
}
|
||||
obj.insert("tags", tagsJsonArray);
|
||||
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug() << "Could not open /project.json";
|
||||
if (!Util::writeSettings(std::move(obj), m_workingDir + "/project.json")) {
|
||||
emit createWallpaperStateChanged(CreateImportVideo::ImportVideoState::CreateProjectFileError);
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
out.setCodec("UTF-8");
|
||||
QJsonDocument doc(obj);
|
||||
|
||||
out << doc.toJson();
|
||||
|
||||
file.close();
|
||||
emit createWallpaperStateChanged(CreateImportVideo::ImportVideoState::CreateProjectFileFinished);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief .
|
||||
*/
|
||||
@ -384,4 +188,6 @@ void Create::abortAndCleanup()
|
||||
});
|
||||
m_createImportVideoThread->requestInterruption();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -73,6 +73,7 @@ public:
|
||||
explicit Create(
|
||||
const std::shared_ptr<GlobalVariables>& globalVariables,
|
||||
QObject* parent = nullptr);
|
||||
|
||||
Create();
|
||||
|
||||
enum class VideoCodec {
|
||||
@ -107,24 +108,9 @@ signals:
|
||||
void htmlWallpaperCreatedSuccessful(QString path);
|
||||
|
||||
public slots:
|
||||
|
||||
void createWallpaperStart(QString videoPath, Create::VideoCodec codec);
|
||||
|
||||
void createWidget(
|
||||
const QString& localStoragePath,
|
||||
const QString& title,
|
||||
const QString& previewThumbnail,
|
||||
const QString& createdBy,
|
||||
const QString& license,
|
||||
const QString& type,
|
||||
const QVector<QString>& tags);
|
||||
|
||||
void createHTMLWallpaper(
|
||||
const QString& localStoragePath,
|
||||
const QString& title,
|
||||
const QString& previewThumbnail,
|
||||
const QString& license,
|
||||
const QVector<QString>& tags);
|
||||
|
||||
void saveWallpaper(
|
||||
QString title,
|
||||
QString description,
|
||||
|
282
ScreenPlay/src/wizards.cpp
Normal file
282
ScreenPlay/src/wizards.cpp
Normal file
@ -0,0 +1,282 @@
|
||||
#include "wizards.h"
|
||||
|
||||
namespace ScreenPlay {
|
||||
/*!
|
||||
\class ScreenPlay::Wizards
|
||||
\inmodule ScreenPlay
|
||||
\brief Baseclass for all wizards. Mostly for copying and creating project files.
|
||||
*/
|
||||
|
||||
/*!
|
||||
Constructor.
|
||||
*/
|
||||
Wizards::Wizards(const std::shared_ptr<GlobalVariables>& globalVariables, QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_globalVariables(globalVariables)
|
||||
{
|
||||
qRegisterMetaType<Wizards::WizardResult>("Wizards::WizardResult");
|
||||
qmlRegisterUncreatableType<Wizards>("ScreenPlay.Wizards", 1, 0, "WizardResult", "Error only for enums");
|
||||
qmlRegisterType<Wizards>("ScreenPlay.Wizards", 1, 0, "Wizards");
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Creates a new widget.
|
||||
*/
|
||||
void Wizards::createQMLWidget(const QString& localStoragePath, const QString& title, const QString& previewThumbnail, const QString& createdBy, const QString& license, const QVector<QString>& tags)
|
||||
{
|
||||
QtConcurrent::run([=]() {
|
||||
QUrl localStoragePathUrl { localStoragePath };
|
||||
QDir dir;
|
||||
dir.cd(localStoragePathUrl.toLocalFile());
|
||||
// Create a temp dir so we can later alter it to the workshop id
|
||||
auto folderName = QString("_tmp_" + QTime::currentTime().toString()).replace(":", "");
|
||||
QString workingPath = dir.path() + "/" + folderName;
|
||||
|
||||
if (!dir.mkdir(folderName)) {
|
||||
qDebug() << "Could create folder: " << folderName;
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonObject obj;
|
||||
obj.insert("license", license);
|
||||
obj.insert("title", title);
|
||||
obj.insert("tags", Util::fillArray(tags));
|
||||
obj.insert("createdBy", createdBy);
|
||||
obj.insert("type", "qmlWidget");
|
||||
obj.insert("file", "main.qml");
|
||||
|
||||
QFile fileMainQML(workingPath + "/main.qml");
|
||||
if (!fileMainQML.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug() << "Could not open /main.qml";
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream outMainQML(&fileMainQML);
|
||||
outMainQML.setCodec("UTF-8");
|
||||
outMainQML << "import QtQuick 2.14 \n\n Item {\n id:root \n}";
|
||||
fileMainQML.close();
|
||||
|
||||
QFile file(workingPath + "/project.json");
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug() << "Could not open /project.json";
|
||||
return;
|
||||
}
|
||||
|
||||
QUrl previewThumbnailUrl { previewThumbnail };
|
||||
QFileInfo previewImageFile(previewThumbnailUrl.toLocalFile());
|
||||
|
||||
if (!previewThumbnail.isEmpty()) {
|
||||
obj.insert("previewThumbnail", previewImageFile.fileName());
|
||||
obj.insert("preview", previewImageFile.fileName());
|
||||
if (!QFile::copy(previewThumbnailUrl.toLocalFile(), workingPath + "/" + previewImageFile.fileName())) {
|
||||
qDebug() << "Could not copy" << previewThumbnailUrl.toLocalFile() << " to " << workingPath + "/" + previewImageFile.fileName();
|
||||
emit widgetCreationFinished(WizardResult::CopyError);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
out.setCodec("UTF-8");
|
||||
QJsonDocument doc(obj);
|
||||
out << doc.toJson();
|
||||
file.close();
|
||||
|
||||
emit widgetCreationFinished(WizardResult::Ok, workingPath);
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Creates a new widget.
|
||||
*/
|
||||
void Wizards::createHTMLWidget(const QString& localStoragePath, const QString& title, const QString& previewThumbnail, const QString& createdBy, const QString& license, const QVector<QString>& tags)
|
||||
{
|
||||
QtConcurrent::run([=]() {
|
||||
QUrl localStoragePathUrl { localStoragePath };
|
||||
QDir dir;
|
||||
dir.cd(localStoragePathUrl.toLocalFile());
|
||||
// Create a temp dir so we can later alter it to the workshop id
|
||||
auto folderName = QString("_tmp_" + QTime::currentTime().toString()).replace(":", "");
|
||||
QString workingPath = dir.path() + "/" + folderName;
|
||||
|
||||
if (!dir.mkdir(folderName)) {
|
||||
qDebug() << "Could create folder: " << folderName;
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonObject obj;
|
||||
obj.insert("license", license);
|
||||
obj.insert("title", title);
|
||||
obj.insert("tags", Util::fillArray(tags));
|
||||
obj.insert("createdBy", createdBy);
|
||||
obj.insert("type", "htmlWidget");
|
||||
obj.insert("file", "index.html");
|
||||
|
||||
QFile fileMainHTML(workingPath + "/index.html");
|
||||
if (!fileMainHTML.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug() << "Could not open /index.html";
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream outMainHTML(&fileMainHTML);
|
||||
outMainHTML.setCodec("UTF-8");
|
||||
outMainHTML << "<html>\n<head></head>\n<body></body>\n</html>";
|
||||
fileMainHTML.close();
|
||||
|
||||
QFile file(workingPath + "/project.json");
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug() << "Could not open /project.json";
|
||||
return;
|
||||
}
|
||||
|
||||
QUrl previewThumbnailUrl { previewThumbnail };
|
||||
QFileInfo previewImageFile(previewThumbnailUrl.toLocalFile());
|
||||
|
||||
if (!previewThumbnail.isEmpty()) {
|
||||
obj.insert("previewThumbnail", previewImageFile.fileName());
|
||||
obj.insert("preview", previewImageFile.fileName());
|
||||
if (!QFile::copy(previewThumbnailUrl.toLocalFile(), workingPath + "/" + previewImageFile.fileName())) {
|
||||
qDebug() << "Could not copy" << previewThumbnailUrl.toLocalFile() << " to " << workingPath + "/" + previewImageFile.fileName();
|
||||
emit widgetCreationFinished(WizardResult::CopyError);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
out.setCodec("UTF-8");
|
||||
QJsonDocument doc(obj);
|
||||
out << doc.toJson();
|
||||
file.close();
|
||||
|
||||
emit widgetCreationFinished(WizardResult::Ok, workingPath);
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Creates a HTML wallpaper.
|
||||
*/
|
||||
void Wizards::createHTMLWallpaper(
|
||||
const QString& localStoragePath,
|
||||
const QString& title,
|
||||
const QString& previewThumbnail,
|
||||
const QString& license,
|
||||
const QVector<QString>& tags)
|
||||
{
|
||||
QtConcurrent::run([=]() {
|
||||
QUrl localStoragePathUrl { localStoragePath };
|
||||
QDir dir;
|
||||
dir.cd(localStoragePathUrl.toLocalFile());
|
||||
// Create a temp dir so we can later alter it to the workshop id
|
||||
auto folderName = QString("_tmp_" + QTime::currentTime().toString()).replace(":", "");
|
||||
QString workingPath = dir.path() + "/" + folderName;
|
||||
|
||||
if (!dir.mkdir(folderName)) {
|
||||
qDebug() << "Could create folder: " << folderName;
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonObject obj;
|
||||
obj.insert("license", license);
|
||||
obj.insert("title", title);
|
||||
obj.insert("tags", Util::fillArray(tags));
|
||||
obj.insert("type", "htmlWallpaper");
|
||||
obj.insert("file", "index.html");
|
||||
|
||||
QFile fileMainHTML(workingPath + "/index.html");
|
||||
if (!fileMainHTML.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug() << "Could not open /index.html";
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream outMainHTML(&fileMainHTML);
|
||||
outMainHTML.setCodec("UTF-8");
|
||||
outMainHTML << "<html>\n<head></head>\n"
|
||||
"<h1>This is an empty html Wallpaper!</h1>"
|
||||
"<body></body>\n</html>";
|
||||
fileMainHTML.close();
|
||||
|
||||
QUrl previewThumbnailUrl { previewThumbnail };
|
||||
QFileInfo previewImageFile(previewThumbnailUrl.toLocalFile());
|
||||
|
||||
if (!previewThumbnail.isEmpty()) {
|
||||
obj.insert("previewThumbnail", previewImageFile.fileName());
|
||||
obj.insert("preview", previewImageFile.fileName());
|
||||
if (!QFile::copy(previewThumbnailUrl.toLocalFile(), workingPath + "/" + previewImageFile.fileName())) {
|
||||
qDebug() << "Could not copy" << previewThumbnailUrl.toLocalFile() << " to " << workingPath + "/" + previewImageFile.fileName();
|
||||
emit widgetCreationFinished(WizardResult::CopyPreviewThumbnailError);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Util::writeSettings(obj, dir.path() + "/project.json")) {
|
||||
emit widgetCreationFinished(WizardResult::WriteProjectFileError);
|
||||
return;
|
||||
}
|
||||
|
||||
emit widgetCreationFinished(WizardResult::Ok, workingPath);
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief .
|
||||
*/
|
||||
void Wizards::createQMLWallpaper(const QString& title, const QString& previewThumbnail, const QString& license, const QVector<QString>& tags)
|
||||
{
|
||||
QtConcurrent::run([=]() {
|
||||
std::optional<QString> folderName = createTemporaryFolder();
|
||||
|
||||
if (!folderName.has_value()) {
|
||||
emit widgetCreationFinished(WizardResult::CreateProjectFolderError);
|
||||
return;
|
||||
}
|
||||
|
||||
const QString workingPath = Util::toLocal(m_globalVariables->localStoragePath().toString() + "/" + folderName.value());
|
||||
|
||||
QJsonObject obj;
|
||||
obj.insert("license", license);
|
||||
obj.insert("title", title);
|
||||
obj.insert("tags", Util::fillArray(tags));
|
||||
obj.insert("type", "qmlWallpaper");
|
||||
obj.insert("file", "main.qml");
|
||||
|
||||
if (!previewThumbnail.isEmpty()) {
|
||||
QUrl previewThumbnailUrl { previewThumbnail };
|
||||
if (!Util::copyPreviewThumbnail(obj, workingPath + "/" + previewThumbnailUrl.fileName(), workingPath)) {
|
||||
emit widgetCreationFinished(WizardResult::CopyPreviewThumbnailError);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Util::writeSettings(obj, workingPath + "/project.json")) {
|
||||
emit widgetCreationFinished(WizardResult::WriteProjectFileError);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Util::writeFile("import QtQuick 2.14 \n\nItem {\n id:root \n}", workingPath + "/main.qml")) {
|
||||
emit widgetCreationFinished(WizardResult::WriteProjectFileError);
|
||||
return;
|
||||
}
|
||||
|
||||
emit widgetCreationFinished(WizardResult::Ok, workingPath);
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief .
|
||||
*/
|
||||
const std::optional<QString> Wizards::createTemporaryFolder() const
|
||||
{
|
||||
QUrl localStoragePathUrl { m_globalVariables->localStoragePath() };
|
||||
QDir dir;
|
||||
dir.cd(localStoragePathUrl.toLocalFile());
|
||||
|
||||
// Create a temp dir so we can later alter it to the workshop id
|
||||
const QString folderName = QString("_tmp_" + QTime::currentTime().toString()).replace(":", "");
|
||||
|
||||
if (!dir.mkdir(folderName)) {
|
||||
qWarning() << "Could create folder: " << folderName;
|
||||
return {};
|
||||
}
|
||||
|
||||
return folderName;
|
||||
}
|
||||
}
|
121
ScreenPlay/src/wizards.h
Normal file
121
ScreenPlay/src/wizards.h
Normal file
@ -0,0 +1,121 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2020 Elias Steurer (Kelteseth)
|
||||
** Contact: https://screen-play.app
|
||||
**
|
||||
** This file is part of ScreenPlay. ScreenPlay is licensed under a dual license in
|
||||
** order to ensure its sustainability. When you contribute to ScreenPlay
|
||||
** you accept that your work will be available under the two following licenses:
|
||||
**
|
||||
** $SCREENPLAY_BEGIN_LICENSE$
|
||||
**
|
||||
** #### Affero General Public License Usage (AGPLv3)
|
||||
** Alternatively, this file may be used under the terms of the GNU Affero
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation and appearing in the file "ScreenPlay License.md" included in the
|
||||
** packaging of this App. Please review the following information to
|
||||
** ensure the GNU Affero Lesser General Public License version 3 requirements
|
||||
** will be met: https://www.gnu.org/licenses/agpl-3.0.en.html.
|
||||
**
|
||||
** #### Commercial License
|
||||
** This code is owned by Elias Steurer. By changing/adding to the code you agree to the
|
||||
** terms written in:
|
||||
** * Legal/corporate_contributor_license_agreement.md - For corporate contributors
|
||||
** * Legal/individual_contributor_license_agreement.md - For individual contributors
|
||||
**
|
||||
** #### Additional Limitations to the AGPLv3 and Commercial Lincese
|
||||
** This License does not grant any rights in the trademarks,
|
||||
** service marks, or logos.
|
||||
**
|
||||
**
|
||||
** $SCREENPLAY_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonParseError>
|
||||
#include <QObject>
|
||||
#include <QProcess>
|
||||
#include <QQmlEngine>
|
||||
#include <QScopedPointer>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QTime>
|
||||
#include <QTimer>
|
||||
#include <QUrl>
|
||||
#include <QtMath>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include "createimportvideo.h"
|
||||
#include "globalvariables.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace ScreenPlay {
|
||||
|
||||
class Wizards : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Wizards(const std::shared_ptr<GlobalVariables>& globalVariables, QObject* parent = nullptr);
|
||||
Wizards() { }
|
||||
|
||||
enum class WizardResult {
|
||||
Ok,
|
||||
CopyError,
|
||||
WriteProjectFileError,
|
||||
CreateProjectFolderError,
|
||||
CopyPreviewThumbnailError,
|
||||
};
|
||||
Q_ENUM(WizardResult)
|
||||
|
||||
public slots:
|
||||
void createQMLWidget(
|
||||
const QString& localStoragePath,
|
||||
const QString& title,
|
||||
const QString& previewThumbnail,
|
||||
const QString& createdBy,
|
||||
const QString& license,
|
||||
const QVector<QString>& tags);
|
||||
|
||||
void createHTMLWidget(
|
||||
const QString& localStoragePath,
|
||||
const QString& title,
|
||||
const QString& previewThumbnail,
|
||||
const QString& createdBy,
|
||||
const QString& license,
|
||||
const QVector<QString>& tags);
|
||||
|
||||
void createHTMLWallpaper(
|
||||
const QString& localStoragePath,
|
||||
const QString& title,
|
||||
const QString& previewThumbnail,
|
||||
const QString& license,
|
||||
const QVector<QString>& tags);
|
||||
|
||||
void createQMLWallpaper(
|
||||
const QString& title,
|
||||
const QString& previewThumbnail,
|
||||
const QString& license,
|
||||
const QVector<QString>& tags);
|
||||
|
||||
signals:
|
||||
void widgetCreationFinished(const Wizards::WizardResult result);
|
||||
void widgetCreationFinished(const Wizards::WizardResult result, const QVariant value);
|
||||
|
||||
private:
|
||||
const std::shared_ptr<GlobalVariables> m_globalVariables;
|
||||
const std::optional<QString> createTemporaryFolder() const;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user