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 <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
#include <projectexplorer/target.h>
|
||||
|
||||
#include <qmldesigner/qmldesignerconstants.h>
|
||||
#include <qmldesigner/qmldesignerplugin.h>
|
||||
|
||||
@@ -15,8 +17,6 @@
|
||||
#include <QNetworkRequest>
|
||||
#include <QWebEngineCookieStore>
|
||||
|
||||
#include "resourcegeneratorproxy.h"
|
||||
|
||||
namespace QmlDesigner::DesignViewer {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -190,16 +206,9 @@ void DVConnector::projectList()
|
||||
|
||||
void DVConnector::uploadCurrentProject()
|
||||
{
|
||||
ResourceGeneratorProxy resourceGenerator;
|
||||
QString projectName = ProjectExplorer::ProjectManager::startupProject()->displayName();
|
||||
QString resourcePath = resourceGenerator.createResourceFileSync(projectName);
|
||||
|
||||
if (resourcePath.isEmpty()) {
|
||||
qCWarning(deploymentPluginLog) << "Failed to create resource file";
|
||||
return;
|
||||
}
|
||||
|
||||
uploadProject(projectName, resourcePath);
|
||||
m_resourceGenerator.createResourceFileAsync(projectName);
|
||||
emit projectIsPacking();
|
||||
}
|
||||
|
||||
void DVConnector::uploadProject(const QString &projectId, const QString &filePath)
|
||||
|
@@ -9,6 +9,8 @@
|
||||
#include <QWebEngineProfile>
|
||||
#include <QWebEngineView>
|
||||
|
||||
#include "resourcegeneratorproxy.h"
|
||||
|
||||
namespace QmlDesigner::DesignViewer {
|
||||
|
||||
class CustomWebEnginePage : public QWebEnginePage
|
||||
@@ -95,6 +97,9 @@ private:
|
||||
ConnectorStatus m_connectorStatus;
|
||||
QByteArray m_userInfo;
|
||||
|
||||
// other internals
|
||||
ResourceGeneratorProxy m_resourceGenerator;
|
||||
|
||||
struct ReplyEvaluatorData
|
||||
{
|
||||
QNetworkReply *reply = nullptr;
|
||||
@@ -150,10 +155,15 @@ signals:
|
||||
void sharedProjectThumbnailDownloaded();
|
||||
void sharedProjectThumbnailDownloadError(const int errorCode, const QString &message);
|
||||
|
||||
// UI integration - login/user related signals
|
||||
// UI integration - login/user
|
||||
void userInfoReceived(const QByteArray &reply);
|
||||
void webViewerVisibleChanged();
|
||||
|
||||
// UI integration - project packing/uploading
|
||||
void projectIsPacking();
|
||||
void projectPackingFailed(const QString &errorString);
|
||||
void projectIsUploading();
|
||||
|
||||
// internal signals
|
||||
void connectorStatusUpdated(const ConnectorStatus status);
|
||||
};
|
||||
|
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <coreplugin/messagemanager.h>
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
#include <projectexplorer/target.h>
|
||||
@@ -31,34 +32,34 @@ ResourceGeneratorProxy::~ResourceGeneratorProxy()
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceGeneratorProxy::createResourceFileAsync()
|
||||
void ResourceGeneratorProxy::createResourceFileAsync(const QString &projectName)
|
||||
{
|
||||
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");
|
||||
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 Utils::FilePath tempFilePath = project->projectDirectory().pathAppended(projectName
|
||||
+ ".qmlrc");
|
||||
std::optional<Utils::FilePath> resourcePath = project->projectDirectory().pathAppended(
|
||||
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"));
|
||||
return "";
|
||||
resourcePath.reset();
|
||||
}
|
||||
|
||||
return tempFilePath.toString();
|
||||
return resourcePath;
|
||||
}
|
||||
|
||||
} // namespace QmlDesigner::DesignViewer
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
#include <utils/filepath.h>
|
||||
|
||||
#include <QFuture>
|
||||
|
||||
@@ -14,15 +14,15 @@ class ResourceGeneratorProxy : public QObject
|
||||
Q_OBJECT
|
||||
public:
|
||||
~ResourceGeneratorProxy();
|
||||
Q_INVOKABLE void createResourceFileAsync();
|
||||
Q_INVOKABLE QString createResourceFileSync(const QString &projectName = "share");
|
||||
Q_INVOKABLE void createResourceFileAsync(const QString &projectName = "share");
|
||||
Q_INVOKABLE std::optional<Utils::FilePath> createResourceFileSync(const QString &projectName = "share");
|
||||
|
||||
private:
|
||||
QFuture<void> m_future;
|
||||
|
||||
signals:
|
||||
void errorOccurred(const QString &error);
|
||||
void resourceFileCreated(const QString &filename);
|
||||
void resourceFileCreated(const Utils::FilePath &filePath);
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner::DesignViewer
|
||||
|
@@ -5,8 +5,8 @@
|
||||
|
||||
#include <projectexplorer/kitmanager.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <qmldesigner/qmldesignerplugin.h>
|
||||
|
||||
#include <qmldesigner/qmldesignerplugin.h>
|
||||
#include <resourcegeneratorproxy.h>
|
||||
|
||||
namespace QmlDesigner {
|
||||
@@ -332,7 +332,7 @@ bool AndroidTarget::enabled() const
|
||||
void AndroidTarget::run() const
|
||||
{
|
||||
auto qmlrcPath = DesignViewer::ResourceGeneratorProxy().createResourceFileSync();
|
||||
deviceManager()->sendProjectFile(m_deviceId, qmlrcPath);
|
||||
deviceManager()->sendProjectFile(m_deviceId, qmlrcPath->toString());
|
||||
}
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
Reference in New Issue
Block a user