diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 1251571bca57fa8539509a40203a3d3974986829..509e7625ae9146eb1ab484c74883da3f22538657 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -1,6 +1,6 @@ <?xml version="1.0"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="io.qt.qtdesignviewer" - android:installLocation="auto" android:versionCode="24" android:versionName="1.2"> + android:installLocation="auto" android:versionCode="25" android:versionName="1.2"> <!-- %%INSERT_PERMISSIONS --> <!-- %%INSERT_FEATURES --> <supports-screens android:anyDensity="true" android:largeScreens="true" diff --git a/src/backend.cpp b/src/backend.cpp index bc6d794bac28ab1493032e248e662e60347972c3..78ce526f42ad8ec69bf85b22ba5e5d241468322a 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -92,7 +92,9 @@ void Backend::initialize() updateUserProjectList(); } - // Check if updateInBackground is enabled + // Initialize background update + connect(&m_backgroundTimer, &QTimer::timeout, this, &Backend::updateUserProjectList); + m_backgroundTimer.setInterval(1000 * 10); enableBackgroundUpdate(updateInBackground()); qDebug() << "Initialization complete"; } @@ -100,26 +102,6 @@ void Backend::initialize() void Backend::enableBackgroundUpdate(const bool &enabled) { if (enabled) { - m_backgroundTimer.setInterval(1000 * 10); - - connect(&m_backgroundTimer, &QTimer::timeout, this, [&] { - qDebug() << "Checking for updates in background"; - - const QString userHash = Backend::userHash(); - if (userHash.isEmpty()) - return; - - QJsonArray projectList = m_serviceConnector.fetchUserProjectList(userHash); - if (projectList.isEmpty()) { - qWarning() << "Could not fetch project list. Please check your internet " - "connection and try again"; - return; - } - - qDebug() << "New projects available. Updating project list"; - updateUserProjectList(); - }); - m_backgroundTimer.start(); } else { m_backgroundTimer.stop(); @@ -150,7 +132,7 @@ void Backend::setAutoScaleProject(const bool &enabled) void Backend::setUserHash(const QString &userHash) { QSettings().setValue("user/hash", userHash); - emit userRegistered(); + emit userHashChanged(); } bool Backend::updateInBackground() @@ -504,23 +486,23 @@ void Backend::updateUserProjectList() qDebug() << "Fetching available project list for user:" << userHash; QJsonArray projectList = m_serviceConnector.fetchUserProjectList(userHash); - if (projectList.isEmpty()) { - qCritical("Could not fetch available project list"); - return; - } - if (projectList == m_projectList) { - qDebug("No new projects available"); - return; + qDebug("No new projects are available"); + } else if (projectList.isEmpty()) { + qWarning("Could not fetch project list. Either there are no projects or there is a " + "network issue"); + } else { + qDebug("List of available projects fetched:"); + for (const auto &project : projectList) { + const QString projectName{project.toObject().value("appName").toString()}; + qDebug() << "--" << projectName; + } } + // we need to set m_projectList even if it is empty + // because this triggers the onModelChanged function in the QML + // in order to update the UI m_projectList = projectList; - qDebug("List of available projects fetched:"); - for (const auto &project : projectList) { - const QString projectName{project.toObject().value("appName").toString()}; - qDebug() << "--" << projectName; - } - emit projectListChanged(); } diff --git a/src/backend.h b/src/backend.h index 980bd632f32b5db9706384dfcf7c99441354ea8f..68198b7d85336ecedb4bfa52e1d5ea7e58bddf7e 100644 --- a/src/backend.h +++ b/src/backend.h @@ -89,23 +89,29 @@ private: QTimer m_backgroundTimer; // member functions - void updateUserProjectList(); void updatePopup(const QString &text, bool indeterminate = true); signals: - // UI signals + // UI signals - Home page + void projectListChanged(); + void urlUpdated(QString); + void userHashChanged(); + + // UI signals - Logs page void logsChanged(QString); + + // UI signals - About page void buildInfoChanged(QString); + + // UI signals - Popup void downloadProgress(float); - void projectListChanged(); void popupProgressIndeterminateChanged(bool indeterminate); void popupTextChanged(QString text); void popupOpen(); void popupClose(); - void userRegistered(); + + // UI signals - Network page void networkUpdated(QString); - void urlUpdated(QString); - void userHashChanged(QString); public slots: void scanQrCode(); @@ -133,6 +139,7 @@ public slots: private slots: void initializeProjectManager(); void enableBackgroundUpdate(const bool &enabled); + void updateUserProjectList(); }; #endif // DV_ANDROID_H diff --git a/ui/HomePage.qml b/ui/HomePage.qml index 520a60e3528e60c9120b9d67e53725918c10f8b5..923d0456cbae2b92babdba51b6fbc3ffd4507e19 100644 --- a/ui/HomePage.qml +++ b/ui/HomePage.qml @@ -27,7 +27,7 @@ Item { Layout.fillWidth: true Connections { target: backend - function onUserRegistered(){ + function onUserHashChanged(){ qrCodeStatus.text = "User registration is completed.\nScan a new QR code to access the shared project from a different user."; qrCodeInstructions.text = ""; } @@ -67,11 +67,19 @@ Item { id: projectList Layout.fillWidth: true enabled: true - onCurrentIndexChanged: { - displayText = textAt(currentIndex) - } textRole: "appName" model: backend.projectList + onModelChanged: { + if (backend.projectList.length > 0) { + projectList.displayText = backend.projectList[0].appName; + projectList.enabled = true; + downloadUserProject.enabled = true; + } else { + projectList.displayText = "No projects are available"; + projectList.enabled = false; + downloadUserProject.enabled = false; + } + } displayText: "Scan QR code to access your projects"; currentIndex: -1 Layout.preferredHeight: 50 @@ -85,19 +93,6 @@ Item { Layout.fillWidth: true Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter } - - Connections { - target: backend - function onUserRegistered(){ - projectList.displayText = "No projects available for the user"; - projectList.enabled = false; - downloadUserProject.enabled = false; - } - function onProjectListChanged(){ - projectList.enabled = true; - downloadUserProject.enabled = true; - } - } } Item {