Commit a8620f15 authored by Elias Steurer's avatar Elias Steurer 🇩🇪

Fix qml and html preview image copy

Add errors emit to all returns
parent 4c2b6dbd
Pipeline #237619140 canceled with stages
......@@ -495,14 +495,15 @@ bool Util::writeFileFromQrc(const QString& qrcPath, const QString& absolutePath)
\brief Takes reference to \a obj. If the copy of the thumbnail is successful,
it adds the corresponding settings entry to the json object reference.
*/
bool Util::copyPreviewThumbnail(QJsonObject& obj, const QString& name, const QString& destination)
bool Util::copyPreviewThumbnail(QJsonObject& obj, const QString& previewThumbnail, const QString& destination)
{
QUrl previewThumbnailUrl { name };
QFileInfo previewImageFile(previewThumbnailUrl.toLocalFile());
const QUrl previewThumbnailUrl { previewThumbnail };
const QFileInfo previewImageFile(previewThumbnailUrl.toString());
const QString destinationFilePath = destination + "/" + previewImageFile.fileName();
if (!name.isEmpty()) {
if (!QFile::copy(previewThumbnailUrl.toLocalFile(), destination)) {
qDebug() << "Could not copy" << previewThumbnailUrl.toLocalFile() << " to " << name;
if (!previewThumbnail.isEmpty()) {
if (!QFile::copy(previewThumbnailUrl.toLocalFile(), destinationFilePath)) {
qDebug() << "Could not copy" << previewThumbnailUrl.toLocalFile() << " to " << destinationFilePath;
return false;
}
}
......
......@@ -118,7 +118,7 @@ public slots:
static bool writeSettings(const QJsonObject& obj, const QString& absolutePath);
static bool writeFile(const QString& text, const QString& absolutePath);
static bool writeFileFromQrc(const QString& qrcPath, const QString& absolutePath);
static bool copyPreviewThumbnail(QJsonObject& obj, const QString& name, const QString& destination);
static bool copyPreviewThumbnail(QJsonObject& obj, const QString& previewThumbnail, const QString& destination);
static QString toString(const QStringList& list);
static QString toLocal(const QString& url);
static QString generateRandomString(quint32 length = 32);
......
......@@ -49,11 +49,13 @@ void Wizards::createQMLWidget(const QString& title,
if (!Util::writeFileFromQrc(":/assets/wizards/" + licenseFile, workingPath + "/" + licenseFile)) {
qWarning() << "Could not write " << licenseFile;
emit widgetCreationFinished(WizardResult::WriteLicenseFileError);
return;
}
if (!Util::writeFileFromQrc(":/qml/Create/WizardsFiles/QMLWidgetMain.qml", workingPath + "main.qml")) {
qWarning() << "Could not write main.qml";
emit widgetCreationFinished(WizardResult::WriteProjectFileError);
return;
}
......@@ -108,11 +110,13 @@ void Wizards::createHTMLWidget(const QString& title,
if (!Util::writeFileFromQrc(":/assets/wizards/" + licenseFile, workingPath + "/" + licenseFile)) {
qWarning() << "Could not write " << licenseFile;
emit widgetCreationFinished(WizardResult::WriteLicenseFileError);
return;
}
if (!Util::writeFileFromQrc(":/qml/Create/WizardsFiles/HTMLWidgetMain.html", workingPath + "/index.html")) {
qWarning() << "Could not write HTMLWidgetMain.html";
emit widgetCreationFinished(WizardResult::WriteProjectFileError);
return;
}
......@@ -129,12 +133,6 @@ void Wizards::createHTMLWidget(const QString& title,
}
}
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;
......@@ -175,11 +173,13 @@ void Wizards::createHTMLWallpaper(
if (!Util::writeFileFromQrc(":/assets/wizards/" + licenseFile, workingPath + "/" + licenseFile)) {
qWarning() << "Could not write " << licenseFile;
emit widgetCreationFinished(WizardResult::WriteLicenseFileError);
return;
}
if (!Util::writeFileFromQrc(":/qml/Create/WizardsFiles/HTMLWallpaperMain.html", workingPath + "/index.html")) {
qWarning() << "Could not write HTMLWallpaperMain.html";
emit widgetCreationFinished(WizardResult::WriteProjectFileError);
return;
}
......@@ -234,8 +234,7 @@ void Wizards::createQMLWallpaper(
obj.insert("file", "main.qml");
if (!previewThumbnail.isEmpty()) {
QUrl previewThumbnailUrl { previewThumbnail };
if (!Util::copyPreviewThumbnail(obj, workingPath + "/" + previewThumbnailUrl.fileName(), workingPath)) {
if (!Util::copyPreviewThumbnail(obj, previewThumbnail, workingPath)) {
emit widgetCreationFinished(WizardResult::CopyPreviewThumbnailError);
return;
}
......@@ -243,6 +242,7 @@ void Wizards::createQMLWallpaper(
if (!Util::writeFileFromQrc(":/assets/wizards/" + licenseFile, workingPath + "/" + licenseFile)) {
qWarning() << "Could not write " << licenseFile;
emit widgetCreationFinished(WizardResult::WriteLicenseFileError);
return;
}
......@@ -290,6 +290,7 @@ void Wizards::createGifWallpaper(
if (!Util::writeFileFromQrc(":/assets/wizards/" + licenseFile, workingPath + "/" + licenseFile)) {
qWarning() << "Could not write " << licenseFile;
emit widgetCreationFinished(WizardResult::WriteLicenseFileError);
return;
}
......@@ -334,8 +335,7 @@ void Wizards::createWebsiteWallpaper(
obj.insert("url", url.toString());
if (!previewThumbnail.isEmpty()) {
QUrl previewThumbnailUrl { previewThumbnail };
if (!Util::copyPreviewThumbnail(obj, workingPath + "/" + previewThumbnailUrl.fileName(), workingPath)) {
if (!Util::copyPreviewThumbnail(obj, previewThumbnail, workingPath)) {
emit widgetCreationFinished(WizardResult::CopyPreviewThumbnailError);
return;
}
......@@ -355,9 +355,8 @@ void Wizards::createWebsiteWallpaper(
*/
const std::optional<QString> Wizards::createTemporaryFolder() const
{
QUrl localStoragePathUrl { m_globalVariables->localStoragePath() };
QDir dir;
dir.cd(localStoragePathUrl.toLocalFile());
const QUrl localStoragePathUrl { m_globalVariables->localStoragePath() };
const QDir dir { 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(":", "");
......
......@@ -75,6 +75,7 @@ public:
Ok,
CopyError,
WriteProjectFileError,
WriteLicenseFileError,
CreateProjectFolderError,
CopyPreviewThumbnailError,
CopyFileError,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment