Skip to content
Snippets Groups Projects

Design studio connector

Closed Burak Hançerli requested to merge design-studio-connector into master
12 files
+ 479
83
Compare changes
  • Side-by-side
  • Inline
Files
12
+ 93
13
@@ -32,7 +32,7 @@
@@ -32,7 +32,7 @@
#include <QFileInfo>
#include <QFileInfo>
#include <QJsonArray>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonObject>
#include <QMessageBox>
#include <QSettings>
#include <QSettings>
#include <QSslSocket>
#include <QSslSocket>
@@ -79,14 +79,8 @@ void Backend::initialize()
@@ -79,14 +79,8 @@ void Backend::initialize()
&ProjectManager::projectStateChanged,
&ProjectManager::projectStateChanged,
this,
this,
&Backend::popupTextChanged);
&Backend::popupTextChanged);
qDebug("Initialization complete");
}
void Backend::showWarning(const QString &message)
qDebug("Initialization complete");
{
QMessageBox msg(QMessageBox::Warning, "Warning", message, QMessageBox::Ok);
msg.exec();
qWarning() << message;
}
}
void Backend::updatePopup(const QString &text, bool indeterminate)
void Backend::updatePopup(const QString &text, bool indeterminate)
@@ -96,6 +90,92 @@ 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);
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, "UntitledProject35")) {
 
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)
void Backend::runDemoProject(const QString &projectName)
{
{
qDebug() << "Checking if demo project is cached for " << projectName;
qDebug() << "Checking if demo project is cached for " << projectName;
@@ -112,8 +192,8 @@ void Backend::runDemoProject(const QString &projectName)
@@ -112,8 +192,8 @@ void Backend::runDemoProject(const QString &projectName)
updatePopup("Caching demo project...");
updatePopup("Caching demo project...");
if (!m_projectManager.cacheDemoProject(project, projectName)) {
if (!m_projectManager.cacheDemoProject(project, projectName)) {
showWarning(
qCritical()
"Could not cache demo project. Please check the logs for more information.");
<< "Could not cache demo project. Please check the logs for more information.";
emit popupClose();
emit popupClose();
return;
return;
}
}
@@ -123,7 +203,7 @@ void Backend::runDemoProject(const QString &projectName)
@@ -123,7 +203,7 @@ void Backend::runDemoProject(const QString &projectName)
updatePopup("Running demo project...");
updatePopup("Running demo project...");
if (!m_projectManager.runDemoProject(projectName))
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
else
m_projectManager.showAppWindow();
m_projectManager.showAppWindow();
@@ -165,7 +245,7 @@ void Backend::runUserProject(const QString &url)
@@ -165,7 +245,7 @@ void Backend::runUserProject(const QString &url)
updatePopup("Caching user project...");
updatePopup("Caching user project...");
if (!m_projectManager.cacheProject(projectData, projectInfo)) {
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();
emit popupClose();
return;
return;
}
}
@@ -175,7 +255,7 @@ void Backend::runUserProject(const QString &url)
@@ -175,7 +255,7 @@ void Backend::runUserProject(const QString &url)
updatePopup("Running cached project...");
updatePopup("Running cached project...");
if (!m_projectManager.runCachedProject(projectInfo))
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
else
m_projectManager.showAppWindow();
m_projectManager.showAppWindow();
Loading