Skip to content
Snippets Groups Projects

QDS-13458 Move server to device

Merged Burak Hançerli requested to merge QDS-13458/move-server-to-device into master
2 files
+ 33
50
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 33
48
@@ -29,16 +29,23 @@
@@ -29,16 +29,23 @@
#include "logger.h"
#include "logger.h"
Q_DECLARE_JNI_CLASS(Secure, "android/provider/Settings$Secure");
#ifdef QT_DEBUG
Q_DECLARE_JNI_CLASS(String, "java/lang/String");
#define buildType "Debug"
Q_DECLARE_JNI_CLASS(ContentResolver, "android/content/ContentResolver");
#else
 
#define buildType "Release"
 
#endif
Backend::Backend(QObject *parent)
Backend::Backend(QObject *parent)
: QObject(parent)
: QObject(parent)
{
{
// This will allow us to open the app with the QR code
// register the `qtdesignstudio` url handler to the Android system
QDesktopServices::setUrlHandler("qtdesignstudio", this, "parseDesignViewerUrl");
QDesktopServices::setUrlHandler("qtdesignstudio", this, "parseDesignViewerUrl");
 
if (m_settings.deviceUuid().isEmpty()) {
 
qDebug() << "Device UUID not found. Generating a new one.";
 
m_settings.setDeviceUuid(QUuid::createUuid().toString(QUuid::WithoutBraces));
 
}
 
m_dsManagerThread.setParent(this);
m_dsManagerThread.setParent(this);
connect(&m_dsManagerThread, &QThread::started, this, &Backend::initDsManager);
connect(&m_dsManagerThread, &QThread::started, this, &Backend::initDsManager);
m_dsManagerThread.start();
m_dsManagerThread.start();
@@ -78,8 +85,7 @@ Backend::Backend(QObject *parent)
@@ -78,8 +85,7 @@ Backend::Backend(QObject *parent)
qDebug() << "-- Product version: " << QSysInfo::productVersion();
qDebug() << "-- Product version: " << QSysInfo::productVersion();
qDebug() << "-- Build ABI: " << QSysInfo::buildAbi();
qDebug() << "-- Build ABI: " << QSysInfo::buildAbi();
qDebug() << "-- Build CPU architecture: " << QSysInfo::buildCpuArchitecture();
qDebug() << "-- Build CPU architecture: " << QSysInfo::buildCpuArchitecture();
qDebug() << "-- Device serial: " << getDeviceSerial();
qDebug() << "-- Device unique ID: " << m_settings.deviceUuid();
qDebug() << "-- Device unique ID: " << getDeviceUuid();
}
}
Backend::~Backend()
Backend::~Backend()
@@ -90,40 +96,17 @@ Backend::~Backend()
@@ -90,40 +96,17 @@ Backend::~Backend()
m_projectManagerThread.wait();
m_projectManagerThread.wait();
}
}
// this function returns the device serial number (which is really unique)
// but may not be reliable on all devices. Instead we use the device UUID.
QByteArray Backend::getDeviceSerial()
{
auto context = QNativeInterface::QAndroidApplication::context();
auto contentResolver = context.callMethod<QtJniTypes::ContentResolver>("getContentResolver");
auto androidId = QtJniTypes::Secure::callStaticMethod<jstring>("getString",
contentResolver,
QStringLiteral("android_id"));
return androidId.toString().toLatin1();
}
QString Backend::getDeviceUuid()
{
if (m_settings.deviceUuid().isEmpty()) {
qDebug() << "Device UUID not found. Generating a new one.";
m_settings.setDeviceUuid(QUuid::createUuid().toString(QUuid::WithoutBraces));
}
return m_settings.deviceUuid();
}
QString Backend::buildInfo() const
QString Backend::buildInfo() const
{
{
#ifdef QT_DEBUG
// clang-format off
const QString buildType = "Debug";
return {
#else
QCoreApplication::applicationVersion() +
const QString buildType = "Release";
"\nTechnology Preview - "+ CMAKE_VAR_GIT_VERSION +
#endif
"\nQt " + QT_VERSION_STR + " - " + buildType + " Build" +
return {QCoreApplication::applicationVersion() + "\nTechnology Preview - "
"\nQt Quick Components " + CMAKE_VAR_QT_QUICK_COMPONENTS_VERSION +
+ QString(CMAKE_VAR_GIT_VERSION) + "\nQt " + QString(QT_VERSION_STR) + " - " + buildType
"\nZXing-Cpp: " + CMAKE_VAR_ZXING_VERSION +
+ " Build" + "\nQt Quick Components " + QString(CMAKE_VAR_QT_QUICK_COMPONENTS_VERSION)
"\nOpenSSL support: " + QVariant(QSslSocket::supportsSsl()).toString()};
+ "\nZXing-Cpp: " + QString(CMAKE_VAR_ZXING_VERSION)
// clang-format on
+ "\nOpenSSL support: " + QVariant(QSslSocket::supportsSsl()).toString()};
}
}
void Backend::updatePopup(const QString &text, bool indeterminate)
void Backend::updatePopup(const QString &text, bool indeterminate)
@@ -143,12 +126,14 @@ void Backend::initProjectManager()
@@ -143,12 +126,14 @@ void Backend::initProjectManager()
Qt::QueuedConnection,
Qt::QueuedConnection,
Q_ARG(QString, m_lastProjectSenderId));
Q_ARG(QString, m_lastProjectSenderId));
});
});
 
 
updatePopup("Initializing Project Manager...");
}
}
void Backend::initDsManager()
void Backend::initDsManager()
{
{
qDebug() << "Design Studio Manager thread started. Initializing Design Studio Manager";
qDebug() << "Design Studio Manager thread started. Initializing Design Studio Manager";
m_dsManager.reset(new DesignStudioManager(getDeviceUuid(), this));
m_dsManager.reset(new DesignStudioManager(m_settings.deviceUuid(), this));
connect(m_dsManager.get(), &DesignStudioManager::projectReceived, this, &Backend::runProject);
connect(m_dsManager.get(), &DesignStudioManager::projectReceived, this, &Backend::runProject);
@@ -231,18 +216,18 @@ void Backend::scanQrCode()
@@ -231,18 +216,18 @@ void Backend::scanQrCode()
void Backend::parseDesignViewerUrl(const QUrl &url)
void Backend::parseDesignViewerUrl(const QUrl &url)
{
{
if (url.scheme() == "qtdesignstudio") {
if (url.scheme() != "qtdesignstudio") {
if (url.host().isEmpty()) {
qWarning() << "No Design Studio IP address found in the QR code. URL:"
<< url.toString();
return;
}
connectDesignStudio(url.host());
} else {
qWarning() << "Unknown QR code format";
qWarning() << "Unknown QR code format";
qWarning() << "URL:" << url.toString();
qWarning() << "URL:" << url.toString();
 
return;
}
}
 
 
if (url.host().isEmpty()) {
 
qWarning() << "No Design Studio IP address found in the QR code. URL:" << url.toString();
 
return;
 
}
 
 
connectDesignStudio(url.host());
}
}
void Backend::popupInterrupted()
void Backend::popupInterrupted()
Loading