From c39f7265b11202ba2e71c8f6ded00d40e11c0a24 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Burak=20Han=C3=A7erli?= <burak.hancerli@qt.io>
Date: Tue, 26 Sep 2023 10:05:38 +0000
Subject: [PATCH] QDS-10704 Show download progress

---
 README.md                        |  6 ++++--
 design-viewer/src/dv_android.cpp | 34 ++++++++++++++++++++++----------
 design-viewer/src/main.cpp       |  2 +-
 3 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/README.md b/README.md
index e2cf061..249afcf 100644
--- a/README.md
+++ b/README.md
@@ -37,6 +37,7 @@ cmake \
     -B build \
     -G Ninja \
     -DCMAKE_TOOLCHAIN_FILE=<qt-android-path>/lib/cmake/Qt6/qt.toolchain.cmake \
+    -DCMAKE_INSTALL_PREFIX=<qt-android-path> \
     -DANDROID_SDK_ROOT=<android-sdk-path> \
     -DANDROID_NDK_ROOT=<android-sdk-path>/ndk/<ndk-version> \
     -DANDROID_OPENSSL_PATH=<openssl-path>
@@ -73,7 +74,7 @@ source ./emsdk_env.sh
 cd ..
 ```
 
-Then build and install QtQuickDesigner Components for Android:
+Then build and install QtQuickDesigner Components for WebAssembly:
 
 ```bash
 cd qtquickdesigner-components
@@ -81,7 +82,8 @@ cmake \
     -S . \
     -B build \
     -G Ninja \
-    -DCMAKE_TOOLCHAIN_FILE=<qt-wasm-path>/wasm/lib/cmake/Qt6/qt.toolchain.cmake
+    -DCMAKE_TOOLCHAIN_FILE=<qt-wasm-path>/wasm/lib/cmake/Qt6/qt.toolchain.cmake \
+    -DCMAKE_INSTALL_PREFIX=<qt-wasm-path>
 
 cmake --build build
 cmake --install build
diff --git a/design-viewer/src/dv_android.cpp b/design-viewer/src/dv_android.cpp
index 3ad9e51..0776708 100644
--- a/design-viewer/src/dv_android.cpp
+++ b/design-viewer/src/dv_android.cpp
@@ -77,15 +77,24 @@ QSharedPointer<QNetworkReply> DvAndroid::fetchResource(const QString &url)
                      &QNetworkReply::sslErrors,
                      this,
                      [&](const QList<QSslError> &errors) {
-                         printLog(errors.first().errorString());
+                         printErr(errors.first().errorString());
                      });
 
     QEventLoop loop;
     QObject::connect(reply.data(), &QNetworkReply::finished, &loop, &QEventLoop::quit);
+    QObject::connect(reply.data(),
+                     &QNetworkReply::downloadProgress,
+                     this,
+                     [&](qint64 bytesReceived, qint64 bytesTotal) {
+                         float percentage = roundf((float) bytesReceived / (float) bytesTotal * 100);
+                         printLog("Download progress " + QString::number(percentage) + "% - "
+                                  + QString::number(bytesReceived) + "/"
+                                  + QString::number(bytesTotal));
+                     });
     loop.exec();
 
     if (reply->error() != QNetworkReply::NoError) {
-        printLog(reply->errorString());
+        printErr(reply->errorString());
     } else {
         printLog("Resource fetched successfully");
     }
@@ -106,7 +115,11 @@ void DvAndroid::setupUi()
     m_layout->addWidget(m_button);
 
     // show build info
-    m_buildInfo->setText(QCoreApplication::applicationVersion());
+    QString buildInfo = "Qt Design Viewer for Android\n" + QCoreApplication::applicationVersion()
+                        + "\n" + "Built with Qt " + QString(QT_VERSION_STR) + "\n"
+                        + "OpenSSL support: " + QVariant(QSslSocket::supportsSsl()).toString();
+    m_buildInfo->setText(buildInfo);
+    m_buildInfo->setAlignment(Qt::AlignHCenter);
 
     // configure logs area
     m_logs->setWordWrap(true);
@@ -121,8 +134,7 @@ void DvAndroid::setupUi()
     });
 
     // configure line edit
-    m_lineEdit->setText(
-        "https://designviewer.qt.io/#17e8907b3b84b8206d45be4f551f4e25/TestTwo.qmlrc");
+    m_lineEdit->setPlaceholderText("Enter project URL here");
 
     // configure the button
     m_button->setText("Download and run project");
@@ -134,21 +146,25 @@ void DvAndroid::setupUi()
 
 void DvAndroid::printSysInfo()
 {
+    const QRect screenGeometry = QGuiApplication::primaryScreen()->geometry();
+
     printLog("Qt Design Viewer");
     printLog("System information:");
     printLog("-- Qt version: " + QString(QT_VERSION_STR));
     printLog("-- OpenSSL support: " + QVariant(QSslSocket::supportsSsl()).toString());
-    printLog("-- Window height: " + QString::number(m_mainWindow.height()));
-    printLog("-- Window width: " + QString::number(m_mainWindow.width()));
+    printLog("-- Screen height: " + QString::number(screenGeometry.height()));
+    printLog("-- Screen width: " + QString::number(screenGeometry.width()));
 }
 
 void DvAndroid::updateLogo()
 {
     printLog("Fetching logo...");
+    m_logo->setText("Fetching logo...");
     auto logoReply = fetchResource("https://designviewer.qt.io/qtdesignstudioviewer-256.png");
 
     if (logoReply->error() != QNetworkReply::NoError) {
         printErr("Could not fetch logo");
+        m_logo->setText("Could not fetch logo");
         return;
     }
 
@@ -176,8 +192,6 @@ void DvAndroid::fetchAndRunProject()
     printLog("=========================");
     printLog("Fetching a new project...");
 
-    // https://designviewer.qt.io/#17e8907b3b84b8206d45be4f551f4e25/TestTwo.qmlrc
-    // https://designviewer.qt.io/qmlprojects/17e8907b3b84b8206d45be4f551f4e25/TestTwo.qmlrc
     QString projectUrl = m_lineEdit->text();
 
     if (projectUrl.startsWith("https://designviewer.qt.io/#")) {
@@ -216,7 +230,7 @@ void DvAndroid::showAppWindow()
 
     printLog("Calculating the new size and scale...");
     const QSizeF contentSize = childItem->size();
-    const QSizeF newContentSize = contentSize.scaled(m_mainWindow.size().toSizeF(),
+    const QSizeF newContentSize = contentSize.scaled(screenGeometry.size().toSizeF(),
                                                      Qt::AspectRatioMode::KeepAspectRatio);
     const qreal newScale = newContentSize.width() / contentSize.width();
     const int leftOffset = childItem->width() - screenGeometry.width();
diff --git a/design-viewer/src/main.cpp b/design-viewer/src/main.cpp
index ce72c3b..8a3ccba 100644
--- a/design-viewer/src/main.cpp
+++ b/design-viewer/src/main.cpp
@@ -39,7 +39,7 @@ int main(int argc, char *argv[])
     QSurfaceFormat::setDefaultFormat(format);
     QScopedPointer<DvBase> dv;
 
-    QCoreApplication::setApplicationVersion(QString("Built on %1 %2\n").arg(__DATE__, __TIME__));
+    QCoreApplication::setApplicationVersion(QString("Built on %1 %2").arg(__DATE__, __TIME__));
 
 #ifdef Q_OS_WASM
     QGuiApplication app(argc, argv);
-- 
GitLab