Skip to content
Snippets Groups Projects

Design studio connector

Closed Burak Hançerli requested to merge design-studio-connector into master
12 files
+ 471
88
Compare changes
  • Side-by-side
  • Inline
Files
12
+ 93
13
@@ -32,7 +32,7 @@
#include <QFileInfo>
#include <QJsonArray>
#include <QJsonObject>
#include <QMessageBox>
#include <QSettings>
#include <QSslSocket>
@@ -79,14 +79,8 @@ void Backend::initialize()
&ProjectManager::projectStateChanged,
this,
&Backend::popupTextChanged);
qDebug("Initialization complete");
}
void Backend::showWarning(const QString &message)
{
QMessageBox msg(QMessageBox::Warning, "Warning", message, QMessageBox::Ok);
msg.exec();
qWarning() << message;
qDebug("Initialization complete");
}
void Backend::updatePopup(const QString &text, bool indeterminate)
@@ -96,6 +90,92 @@ void Backend::updatePopup(const QString &text, bool indeterminate)
QEventLoop().processEvents(QEventLoop::AllEvents, 100);
}
bool Backend::connectDesignStudio()
{
if (m_designStudioConnector) {
qDebug() << "Design Studio Connector is already initialized";
return true;
}
qDebug() << "Initializing Design Studio Connector";
connect(
&m_dsConnectorThread,
&QThread::started,
this,
[&] {
m_designStudioConnector.reset(new DesignStudioConnector);
connect(m_designStudioConnector.data(),
&DesignStudioConnector::networkStatusUpdated,
this,
&Backend::networkUpdated);
connect(m_designStudioConnector.data(),
&DesignStudioConnector::projectReceived,
&m_projectManager,
[this](const QByteArray &projectData) {
qDebug() << "Project received from Design Studio";
emit popupOpen();
updatePopup("Unpacking project...");
qDebug() << "Project data size: " << projectData.size();
const QString projectPath = m_projectManager.unpackProject(projectData);
if (projectPath.isEmpty()) {
qCritical()
<< "Could not unpack project. Please check the logs for more "
"information.";
emit popupClose();
return;
}
qDebug() << "Project unpacked to " << projectPath;
updatePopup("Running project...");
if (!m_projectManager.runProject(projectPath)) {
qCritical() << "Could not run project. Please check the logs for more "
"information.";
} else {
m_projectManager.showAppWindow();
}
emit popupClose();
});
if (!m_designStudioConnector->initialize()) {
qCritical()
<< "Could initialize server. Please check the logs for more information.";
m_designStudioConnector.reset();
}
},
Qt::DirectConnection);
m_dsConnectorThread.start();
qDebug() << "Design Studio Connector is initialized";
return true;
}
void Backend::disconnectDesignStudio()
{
if (!m_designStudioConnector) {
qDebug() << "Design Studio Connector is not initialized";
return;
}
qDebug() << "Disconnecting from Design Studio";
connect(
&m_dsConnectorThread,
&QThread::finished,
this,
[&] {
qDebug() << "Design Studio Connector is disconnected";
m_designStudioConnector.reset();
},
Qt::DirectConnection);
m_dsConnectorThread.quit();
m_dsConnectorThread.wait();
}
void Backend::runDemoProject(const QString &projectName)
{
qDebug() << "Checking if demo project is cached for " << projectName;
@@ -112,8 +192,8 @@ void Backend::runDemoProject(const QString &projectName)
updatePopup("Caching demo project...");
if (!m_projectManager.cacheDemoProject(project, projectName)) {
showWarning(
"Could not cache demo project. Please check the logs for more information.");
qCritical()
<< "Could not cache demo project. Please check the logs for more information.";
emit popupClose();
return;
}
@@ -123,7 +203,7 @@ void Backend::runDemoProject(const QString &projectName)
updatePopup("Running demo project...");
if (!m_projectManager.runDemoProject(projectName))
showWarning("Could not run demo project. Please check the logs for more information.");
qCritical() << "Could not run demo project. Please check the logs for more information.";
else
m_projectManager.showAppWindow();
@@ -165,7 +245,7 @@ void Backend::runUserProject(const QString &url)
updatePopup("Caching user project...");
if (!m_projectManager.cacheProject(projectData, projectInfo)) {
showWarning("Could not cache project. Please check the logs for more information.");
qCritical() << "Could not cache project. Please check the logs for more information.";
emit popupClose();
return;
}
@@ -175,7 +255,7 @@ void Backend::runUserProject(const QString &url)
updatePopup("Running cached project...");
if (!m_projectManager.runCachedProject(projectInfo))
showWarning("Could not run project. Please check the logs for more information.");
qCritical() << "Could not run project. Please check the logs for more information.";
else
m_projectManager.showAppWindow();
Loading