1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-23 03:02:30 +01:00

Make all wizards consitent

Use same parameters and functions to copy
files and create folder
This commit is contained in:
Elias Steurer 2020-12-12 14:41:32 +01:00
parent 6d65791976
commit 6939ee2b92
10 changed files with 257 additions and 254 deletions

View File

@ -23,8 +23,10 @@ WizardPage {
function create() { function create() {
ScreenPlay.wizards.createHTMLWallpaper(tfTitle.text, ScreenPlay.wizards.createHTMLWallpaper(tfTitle.text,
cbLicense.name,
cbLicense.licenseFile,
previewSelector.imageSource, previewSelector.imageSource,
cbLicense.currentText, tfCreatedBy.text,
tagSelector.getTags()) tagSelector.getTags())
} }

View File

@ -14,9 +14,10 @@ WizardPage {
function create() { function create() {
ScreenPlay.wizards.createHTMLWidget(tfTitle.text, ScreenPlay.wizards.createHTMLWidget(tfTitle.text,
cbLicense.name,
cbLicense.licenseFile,
previewSelector.imageSource, previewSelector.imageSource,
tfCreatedBy.text, tfCreatedBy.text,
cbLicense.currentText,
tagSelector.getTags()) tagSelector.getTags())
} }
@ -57,7 +58,7 @@ WizardPage {
} }
Common.ImageSelector { Common.ImageSelector {
id: imageSelector id: previewSelector
Layout.fillWidth: true Layout.fillWidth: true
} }
} }
@ -77,13 +78,7 @@ WizardPage {
Layout.fillWidth: true Layout.fillWidth: true
required: true required: true
placeholderText: qsTr("Widget name") placeholderText: qsTr("Widget name")
onTextChanged: { onTextChanged: root.ready = text.length >= 1
if (text.length >= 3) {
btnSave.enabled = true
} else {
btnSave.enabled = false
}
}
} }
Common.TextField { Common.TextField {
id: tfCreatedBy id: tfCreatedBy

View File

@ -22,9 +22,12 @@ WizardPage {
} }
function create() { function create() {
ScreenPlay.wizards.createQMLWallpaper( ScreenPlay.wizards.createQMLWallpaper(tfTitle.text,
tfTitle.text, previewSelector.imageSource, cbLicense.name,
cbLicense.currentText, tagSelector.getTags()) cbLicense.licenseFile,
previewSelector.imageSource,
tfCreatedBy.text,
tagSelector.getTags())
} }
Common.Headline { Common.Headline {

View File

@ -13,10 +13,10 @@ WizardPage {
sourceComponent: ColumnLayout { sourceComponent: ColumnLayout {
function create() { function create() {
ScreenPlay.wizards.createQMLWidget(tfTitle.text, ScreenPlay.wizards.createQMLWidget(tfTitle.text, cbLicense.name,
cbLicense.licenseFile,
previewSelector.imageSource, previewSelector.imageSource,
tfCreatedBy.text, tfCreatedBy.text,
cbLicense.currentText,
tagSelector.getTags()) tagSelector.getTags())
} }
@ -57,7 +57,7 @@ WizardPage {
} }
Common.ImageSelector { Common.ImageSelector {
id: imageSelector id: previewSelector
Layout.fillWidth: true Layout.fillWidth: true
} }
} }
@ -77,13 +77,7 @@ WizardPage {
Layout.fillWidth: true Layout.fillWidth: true
required: true required: true
placeholderText: qsTr("Widget name") placeholderText: qsTr("Widget name")
onTextChanged: { onTextChanged: root.ready = text.length >= 1
if (text.length >= 3) {
btnSave.enabled = true
} else {
btnSave.enabled = false
}
}
} }
Common.TextField { Common.TextField {
id: tfCreatedBy id: tfCreatedBy

View File

@ -0,0 +1,12 @@
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,12 @@
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
</head>
<body>
</body>
</html>

View File

@ -1,5 +1,5 @@
import QtQuick 2.0 import QtQuick 2.14
Item { Item {
id: root
} }

View File

@ -1,5 +1,5 @@
import QtQuick 2.0 import QtQuick 2.14
Item { Item {
id: root
} }

View File

@ -24,214 +24,10 @@ Wizards::Wizards(const std::shared_ptr<GlobalVariables>& globalVariables, QObjec
*/ */
void Wizards::createQMLWidget( void Wizards::createQMLWidget(
const QString& title, const QString& title,
const QString& licenseName,
const QString& licenseFile,
const QString& previewThumbnail, const QString& previewThumbnail,
const QString& createdBy, const QString& createdBy,
const QString& license,
const QVector<QString>& tags)
{
QtConcurrent::run([=]() {
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
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& title,
const QString& previewThumbnail,
const QString& createdBy,
const QString& license,
const QVector<QString>& tags)
{
QtConcurrent::run([=]() {
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
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& title,
const QString& previewThumbnail,
const QString& license,
const QVector<QString>& tags)
{
QtConcurrent::run([=]() {
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
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) const QVector<QString>& tags)
{ {
QtConcurrent::run([=]() { QtConcurrent::run([=]() {
@ -245,9 +41,197 @@ void Wizards::createQMLWallpaper(
const QString workingPath = Util::toLocal(m_globalVariables->localStoragePath().toString() + "/" + folderName.value()); const QString workingPath = Util::toLocal(m_globalVariables->localStoragePath().toString() + "/" + folderName.value());
QJsonObject obj; QJsonObject obj;
obj.insert("license", license); obj.insert("license", licenseName);
obj.insert("title", title); obj.insert("title", title);
obj.insert("tags", Util::fillArray(tags)); obj.insert("tags", Util::fillArray(tags));
obj.insert("createdBy", createdBy);
obj.insert("type", "qmlWidget");
obj.insert("file", "main.qml");
if (!Util::writeFileFromQrc(":/assets/wizards/" + licenseFile, workingPath + "/" + licenseFile)) {
qWarning() << "Could not write " << licenseFile;
return;
}
if (!Util::writeFileFromQrc(":/qml/Create/WizardsFiles/QMLWidgetMain.qml", workingPath + "main.qml")) {
qWarning() << "Could not write main.qml";
return;
}
if (!previewThumbnail.isEmpty()) {
QUrl previewThumbnailUrl { previewThumbnail };
QFileInfo previewImageFile(previewThumbnailUrl.toLocalFile());
obj.insert("previewThumbnail", previewImageFile.fileName());
obj.insert("preview", previewImageFile.fileName());
if (!QFile::copy(previewThumbnailUrl.toLocalFile(), workingPath + "/" + previewImageFile.fileName())) {
qWarning() << "Could not copy" << previewThumbnailUrl.toLocalFile() << " to " << workingPath + "/" + previewImageFile.fileName();
emit widgetCreationFinished(WizardResult::CopyError);
return;
}
}
if (!Util::writeSettings(obj, workingPath + "/project.json")) {
emit widgetCreationFinished(WizardResult::WriteProjectFileError);
return;
}
emit widgetCreationFinished(WizardResult::Ok, workingPath);
});
}
/*!
\brief Creates a new widget.
*/
void Wizards::createHTMLWidget(
const QString& title,
const QString& licenseName,
const QString& licenseFile,
const QString& previewThumbnail,
const QString& createdBy,
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", licenseName);
obj.insert("createdBy", createdBy);
obj.insert("title", title);
obj.insert("tags", Util::fillArray(tags));
obj.insert("type", "htmlWidget");
obj.insert("file", "index.html");
if (!Util::writeFileFromQrc(":/assets/wizards/" + licenseFile, workingPath + "/" + licenseFile)) {
qWarning() << "Could not write " << licenseFile;
return;
}
if (!Util::writeFileFromQrc(":/qml/Create/WizardsFiles/HTMLWidgetMain.html", workingPath + "/index.html")) {
qWarning() << "Could not write HTMLWidgetMain.html";
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())) {
qWarning() << "Could not copy" << previewThumbnailUrl.toLocalFile() << " to " << workingPath + "/" + previewImageFile.fileName();
emit widgetCreationFinished(WizardResult::CopyError);
return;
}
}
QFile file(workingPath + "/project.json");
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qWarning() << "Could not open /project.json";
return;
}
if (!Util::writeSettings(obj, workingPath + "/project.json")) {
emit widgetCreationFinished(WizardResult::WriteProjectFileError);
return;
}
emit widgetCreationFinished(WizardResult::Ok, workingPath);
});
}
/*!
\brief Creates a HTML wallpaper.
*/
void Wizards::createHTMLWallpaper(
const QString& title,
const QString& licenseName,
const QString& licenseFile,
const QString& createdBy,
const QString& previewThumbnail,
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", licenseName);
obj.insert("createdBy", createdBy);
obj.insert("title", title);
obj.insert("tags", Util::fillArray(tags));
obj.insert("type", "htmlWallpaper");
obj.insert("file", "index.html");
if (!Util::writeFileFromQrc(":/assets/wizards/" + licenseFile, workingPath + "/" + licenseFile)) {
qWarning() << "Could not write " << licenseFile;
return;
}
if (!Util::writeFileFromQrc(":/qml/Create/WizardsFiles/HTMLWallpaperMain.html", workingPath + "/index.html")) {
qWarning() << "Could not write HTMLWallpaperMain.html";
return;
}
if (!previewThumbnail.isEmpty()) {
QUrl previewThumbnailUrl { previewThumbnail };
QFileInfo previewImageFile(previewThumbnailUrl.toLocalFile());
obj.insert("previewThumbnail", previewImageFile.fileName());
obj.insert("preview", previewImageFile.fileName());
if (!QFile::copy(previewThumbnailUrl.toLocalFile(), workingPath + "/" + previewImageFile.fileName())) {
qWarning() << "Could not copy" << previewThumbnailUrl.toLocalFile() << " to " << workingPath + "/" + previewImageFile.fileName();
emit widgetCreationFinished(WizardResult::CopyPreviewThumbnailError);
return;
}
}
if (!Util::writeSettings(obj, workingPath + "/project.json")) {
emit widgetCreationFinished(WizardResult::WriteProjectFileError);
return;
}
emit widgetCreationFinished(WizardResult::Ok, workingPath);
});
}
/*!
\brief .
*/
void Wizards::createQMLWallpaper(
const QString& title,
const QString& licenseName,
const QString& licenseFile,
const QString& createdBy,
const QString& previewThumbnail,
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", licenseName);
obj.insert("title", title);
obj.insert("createdBy", createdBy);
obj.insert("tags", Util::fillArray(tags));
obj.insert("type", "qmlWallpaper"); obj.insert("type", "qmlWallpaper");
obj.insert("file", "main.qml"); obj.insert("file", "main.qml");
@ -259,13 +243,18 @@ void Wizards::createQMLWallpaper(
} }
} }
if (!Util::writeFileFromQrc(":/assets/wizards/" + licenseFile, workingPath + "/" + licenseFile)) {
qWarning() << "Could not write " << licenseFile;
return;
}
if (!Util::writeSettings(obj, workingPath + "/project.json")) { if (!Util::writeSettings(obj, workingPath + "/project.json")) {
emit widgetCreationFinished(WizardResult::WriteProjectFileError); emit widgetCreationFinished(WizardResult::WriteProjectFileError);
return; return;
} }
if (!Util::writeFile("import QtQuick 2.14 \n\nItem {\n id:root \n}", workingPath + "/main.qml")) { if (!Util::writeFileFromQrc(":/qml/Create/WizardsFiles/QMLWallpaperMain.qml", workingPath + "/main.qml")) {
emit widgetCreationFinished(WizardResult::WriteProjectFileError); qWarning() << "Could not write main.qml";
return; return;
} }
@ -327,7 +316,6 @@ void Wizards::createGifWallpaper(
void Wizards::createWebsiteWallpaper( void Wizards::createWebsiteWallpaper(
const QString& title, const QString& title,
const QString& previewThumbnail, const QString& previewThumbnail,
const QString& license,
const QUrl& url, const QUrl& url,
const QVector<QString>& tags) const QVector<QString>& tags)
{ {
@ -342,11 +330,10 @@ void Wizards::createWebsiteWallpaper(
const QString workingPath = Util::toLocal(m_globalVariables->localStoragePath().toString() + "/" + folderName.value()); const QString workingPath = Util::toLocal(m_globalVariables->localStoragePath().toString() + "/" + folderName.value());
QJsonObject obj; QJsonObject obj;
obj.insert("license", license);
obj.insert("title", title); obj.insert("title", title);
obj.insert("tags", Util::fillArray(tags)); obj.insert("tags", Util::fillArray(tags));
obj.insert("type", "qmlWallpaper"); obj.insert("type", "websiteWallpaper");
obj.insert("file", "main.qml"); obj.insert("source", url.toString());
if (!previewThumbnail.isEmpty()) { if (!previewThumbnail.isEmpty()) {
QUrl previewThumbnailUrl { previewThumbnail }; QUrl previewThumbnailUrl { previewThumbnail };
@ -361,11 +348,6 @@ void Wizards::createWebsiteWallpaper(
return; 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); emit widgetCreationFinished(WizardResult::Ok, workingPath);
}); });
} }

View File

@ -84,28 +84,32 @@ public:
public slots: public slots:
void createQMLWidget( void createQMLWidget(
const QString& title, const QString& title,
const QString& licenseName,
const QString& licenseFile,
const QString& previewThumbnail, const QString& previewThumbnail,
const QString& createdBy, const QString& createdBy,
const QString& license,
const QVector<QString>& tags); const QVector<QString>& tags);
void createHTMLWidget( void createHTMLWidget(
const QString& title, const QString& title,
const QString& licenseName,
const QString& licenseFile,
const QString& previewThumbnail, const QString& previewThumbnail,
const QString& createdBy, const QString& createdBy,
const QString& license,
const QVector<QString>& tags); const QVector<QString>& tags);
void createHTMLWallpaper( void createHTMLWallpaper(const QString& title,
const QString& title, const QString& licenseName,
const QString& licenseFile,
const QString& createdBy,
const QString& previewThumbnail, const QString& previewThumbnail,
const QString& license,
const QVector<QString>& tags); const QVector<QString>& tags);
void createQMLWallpaper( void createQMLWallpaper(const QString& title,
const QString& title, const QString& licenseName,
const QString& licenseFile,
const QString& createdBy,
const QString& previewThumbnail, const QString& previewThumbnail,
const QString& license,
const QVector<QString>& tags); const QVector<QString>& tags);
void createGifWallpaper( void createGifWallpaper(
@ -119,7 +123,6 @@ public slots:
void createWebsiteWallpaper( void createWebsiteWallpaper(
const QString& title, const QString& title,
const QString& previewThumbnail, const QString& previewThumbnail,
const QString& license,
const QUrl& url, const QUrl& url,
const QVector<QString>& tags); const QVector<QString>& tags);