forked from qt-creator/qt-creator
DesignViewer: Make resource creation async
Change-Id: Ida366c3f6ec89b2d8b9e9cf09338f27af16447b2 Reviewed-by: Henning Gründl <henning.gruendl@qt.io>
This commit is contained in:
@@ -3,9 +3,11 @@
|
|||||||
|
|
||||||
#include "dvconnector.h"
|
#include "dvconnector.h"
|
||||||
|
|
||||||
|
#include <projectexplorer/project.h>
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
#include <projectexplorer/projectmanager.h>
|
#include <projectexplorer/projectmanager.h>
|
||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
|
|
||||||
#include <qmldesigner/qmldesignerconstants.h>
|
#include <qmldesigner/qmldesignerconstants.h>
|
||||||
#include <qmldesigner/qmldesignerplugin.h>
|
#include <qmldesigner/qmldesignerplugin.h>
|
||||||
|
|
||||||
@@ -15,8 +17,6 @@
|
|||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QWebEngineCookieStore>
|
#include <QWebEngineCookieStore>
|
||||||
|
|
||||||
#include "resourcegeneratorproxy.h"
|
|
||||||
|
|
||||||
namespace QmlDesigner::DesignViewer {
|
namespace QmlDesigner::DesignViewer {
|
||||||
Q_LOGGING_CATEGORY(deploymentPluginLog, "qtc.designer.deploymentPlugin", QtWarningMsg)
|
Q_LOGGING_CATEGORY(deploymentPluginLog, "qtc.designer.deploymentPlugin", QtWarningMsg)
|
||||||
|
|
||||||
@@ -145,6 +145,22 @@ DVConnector::DVConnector(QObject *parent)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(&m_resourceGenerator,
|
||||||
|
&ResourceGeneratorProxy::resourceFileCreated,
|
||||||
|
this,
|
||||||
|
[this](const std::optional<Utils::FilePath> &resourcePath) {
|
||||||
|
emit projectIsUploading();
|
||||||
|
QString projectName = ProjectExplorer::ProjectManager::startupProject()->displayName();
|
||||||
|
uploadProject(projectName, resourcePath->toString());
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(&m_resourceGenerator,
|
||||||
|
&ResourceGeneratorProxy::errorOccurred,
|
||||||
|
[this](const QString &errorString) {
|
||||||
|
qCWarning(deploymentPluginLog) << "Error occurred while packing the project";
|
||||||
|
emit projectPackingFailed(errorString);
|
||||||
|
});
|
||||||
|
|
||||||
fetchUserInfo();
|
fetchUserInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,16 +206,9 @@ void DVConnector::projectList()
|
|||||||
|
|
||||||
void DVConnector::uploadCurrentProject()
|
void DVConnector::uploadCurrentProject()
|
||||||
{
|
{
|
||||||
ResourceGeneratorProxy resourceGenerator;
|
|
||||||
QString projectName = ProjectExplorer::ProjectManager::startupProject()->displayName();
|
QString projectName = ProjectExplorer::ProjectManager::startupProject()->displayName();
|
||||||
QString resourcePath = resourceGenerator.createResourceFileSync(projectName);
|
m_resourceGenerator.createResourceFileAsync(projectName);
|
||||||
|
emit projectIsPacking();
|
||||||
if (resourcePath.isEmpty()) {
|
|
||||||
qCWarning(deploymentPluginLog) << "Failed to create resource file";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uploadProject(projectName, resourcePath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DVConnector::uploadProject(const QString &projectId, const QString &filePath)
|
void DVConnector::uploadProject(const QString &projectId, const QString &filePath)
|
||||||
|
@@ -9,6 +9,8 @@
|
|||||||
#include <QWebEngineProfile>
|
#include <QWebEngineProfile>
|
||||||
#include <QWebEngineView>
|
#include <QWebEngineView>
|
||||||
|
|
||||||
|
#include "resourcegeneratorproxy.h"
|
||||||
|
|
||||||
namespace QmlDesigner::DesignViewer {
|
namespace QmlDesigner::DesignViewer {
|
||||||
|
|
||||||
class CustomWebEnginePage : public QWebEnginePage
|
class CustomWebEnginePage : public QWebEnginePage
|
||||||
@@ -95,6 +97,9 @@ private:
|
|||||||
ConnectorStatus m_connectorStatus;
|
ConnectorStatus m_connectorStatus;
|
||||||
QByteArray m_userInfo;
|
QByteArray m_userInfo;
|
||||||
|
|
||||||
|
// other internals
|
||||||
|
ResourceGeneratorProxy m_resourceGenerator;
|
||||||
|
|
||||||
struct ReplyEvaluatorData
|
struct ReplyEvaluatorData
|
||||||
{
|
{
|
||||||
QNetworkReply *reply = nullptr;
|
QNetworkReply *reply = nullptr;
|
||||||
@@ -150,10 +155,15 @@ signals:
|
|||||||
void sharedProjectThumbnailDownloaded();
|
void sharedProjectThumbnailDownloaded();
|
||||||
void sharedProjectThumbnailDownloadError(const int errorCode, const QString &message);
|
void sharedProjectThumbnailDownloadError(const int errorCode, const QString &message);
|
||||||
|
|
||||||
// UI integration - login/user related signals
|
// UI integration - login/user
|
||||||
void userInfoReceived(const QByteArray &reply);
|
void userInfoReceived(const QByteArray &reply);
|
||||||
void webViewerVisibleChanged();
|
void webViewerVisibleChanged();
|
||||||
|
|
||||||
|
// UI integration - project packing/uploading
|
||||||
|
void projectIsPacking();
|
||||||
|
void projectPackingFailed(const QString &errorString);
|
||||||
|
void projectIsUploading();
|
||||||
|
|
||||||
// internal signals
|
// internal signals
|
||||||
void connectorStatusUpdated(const ConnectorStatus status);
|
void connectorStatusUpdated(const ConnectorStatus status);
|
||||||
};
|
};
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include <coreplugin/messagemanager.h>
|
#include <coreplugin/messagemanager.h>
|
||||||
|
|
||||||
|
#include <projectexplorer/project.h>
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
#include <projectexplorer/projectmanager.h>
|
#include <projectexplorer/projectmanager.h>
|
||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
@@ -31,34 +32,34 @@ ResourceGeneratorProxy::~ResourceGeneratorProxy()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceGeneratorProxy::createResourceFileAsync()
|
void ResourceGeneratorProxy::createResourceFileAsync(const QString &projectName)
|
||||||
{
|
{
|
||||||
m_future = QtConcurrent::run([&]() {
|
m_future = QtConcurrent::run([&]() {
|
||||||
const QString filePath = createResourceFileSync();
|
const std::optional<Utils::FilePath> filePath = createResourceFileSync(projectName);
|
||||||
|
|
||||||
if (filePath.isEmpty()) {
|
if (filePath->isEmpty()) {
|
||||||
emit errorOccurred("Failed to create resource file");
|
emit errorOccurred("Failed to create resource file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit resourceFileCreated(filePath);
|
emit resourceFileCreated(filePath.value());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ResourceGeneratorProxy::createResourceFileSync(const QString &projectName)
|
std::optional<Utils::FilePath> ResourceGeneratorProxy::createResourceFileSync(const QString &projectName)
|
||||||
{
|
{
|
||||||
const auto project = ProjectExplorer::ProjectManager::startupProject();
|
const auto project = ProjectExplorer::ProjectManager::startupProject();
|
||||||
const Utils::FilePath tempFilePath = project->projectDirectory().pathAppended(projectName
|
std::optional<Utils::FilePath> resourcePath = project->projectDirectory().pathAppended(
|
||||||
+ ".qmlrc");
|
projectName + ".qmlrc");
|
||||||
|
|
||||||
const bool retVal = ResourceGenerator::createQmlrcFile(tempFilePath);
|
const bool retVal = ResourceGenerator::createQmlrcFile(resourcePath.value());
|
||||||
|
|
||||||
if (!retVal || tempFilePath.fileSize() == 0) {
|
if (!retVal || resourcePath->fileSize() == 0) {
|
||||||
Core::MessageManager::writeDisrupting(tr("Failed to create resource file"));
|
Core::MessageManager::writeDisrupting(tr("Failed to create resource file"));
|
||||||
return "";
|
resourcePath.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
return tempFilePath.toString();
|
return resourcePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace QmlDesigner::DesignViewer
|
} // namespace QmlDesigner::DesignViewer
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <projectexplorer/project.h>
|
#include <utils/filepath.h>
|
||||||
|
|
||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
|
|
||||||
@@ -14,15 +14,15 @@ class ResourceGeneratorProxy : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
~ResourceGeneratorProxy();
|
~ResourceGeneratorProxy();
|
||||||
Q_INVOKABLE void createResourceFileAsync();
|
Q_INVOKABLE void createResourceFileAsync(const QString &projectName = "share");
|
||||||
Q_INVOKABLE QString createResourceFileSync(const QString &projectName = "share");
|
Q_INVOKABLE std::optional<Utils::FilePath> createResourceFileSync(const QString &projectName = "share");
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QFuture<void> m_future;
|
QFuture<void> m_future;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void errorOccurred(const QString &error);
|
void errorOccurred(const QString &error);
|
||||||
void resourceFileCreated(const QString &filename);
|
void resourceFileCreated(const Utils::FilePath &filePath);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner::DesignViewer
|
} // namespace QmlDesigner::DesignViewer
|
||||||
|
@@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
#include <projectexplorer/kitmanager.h>
|
#include <projectexplorer/kitmanager.h>
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <qmldesigner/qmldesignerplugin.h>
|
|
||||||
|
|
||||||
|
#include <qmldesigner/qmldesignerplugin.h>
|
||||||
#include <resourcegeneratorproxy.h>
|
#include <resourcegeneratorproxy.h>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
@@ -332,7 +332,7 @@ bool AndroidTarget::enabled() const
|
|||||||
void AndroidTarget::run() const
|
void AndroidTarget::run() const
|
||||||
{
|
{
|
||||||
auto qmlrcPath = DesignViewer::ResourceGeneratorProxy().createResourceFileSync();
|
auto qmlrcPath = DesignViewer::ResourceGeneratorProxy().createResourceFileSync();
|
||||||
deviceManager()->sendProjectFile(m_deviceId, qmlrcPath);
|
deviceManager()->sendProjectFile(m_deviceId, qmlrcPath->toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
Reference in New Issue
Block a user