diff --git a/src/backend.cpp b/src/backend.cpp index c8dee26ab7440302ea5057b93529558eba37b309..bc6d794bac28ab1493032e248e662e60347972c3 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -150,7 +150,7 @@ void Backend::setAutoScaleProject(const bool &enabled) void Backend::setUserHash(const QString &userHash) { QSettings().setValue("user/hash", userHash); - updateUserProjectList(); + emit userRegistered(); } bool Backend::updateInBackground() @@ -494,8 +494,6 @@ void Backend::runOnlineProject(const QString &url) void Backend::updateUserProjectList() { - emit userRegistered(); - const QString userHash = Backend::userHash(); if (userHash.isEmpty()) { @@ -511,17 +509,16 @@ void Backend::updateUserProjectList() return; } - if (projectList == m_projectListArray) { + if (projectList == m_projectList) { qDebug("No new projects available"); return; } - m_projectListArray = projectList; - m_projectList.clear(); + + m_projectList = projectList; qDebug("List of available projects fetched:"); for (const auto &project : projectList) { const QString projectName{project.toObject().value("appName").toString()}; qDebug() << "--" << projectName; - m_projectList << projectName; } emit projectListChanged(); @@ -534,7 +531,7 @@ void Backend::parseDesignViewerUrl(const QUrl &url) // If it is a user hash, we register the user and fetch the project list // If it is a project url, we submit the url to the text field // sample url: https://<url>/<project_name>.qmlrc - // sample user hash: qtdesignviewer://17e8907b3b84029384hs8djshdu38476 + // sample user hash: qtdesignviewer://19f8907b6t84029384hs8djshdu38476 if (urlData.isEmpty()) return; else if (urlData.startsWith("https//")) { @@ -545,6 +542,7 @@ void Backend::parseDesignViewerUrl(const QUrl &url) } else if (urlData.startsWith("qtdesignviewer://")) { qDebug() << "Registering user from QR code"; setUserHash(url.toString().remove("qtdesignviewer://")); + updateUserProjectList(); } else { qWarning() << "Unknown QR code data: " << urlData; } diff --git a/src/backend.h b/src/backend.h index 3363acd874112102d2153b32d74be7b47776ea26..980bd632f32b5db9706384dfcf7c99441354ea8f 100644 --- a/src/backend.h +++ b/src/backend.h @@ -58,7 +58,7 @@ signals: class Backend : public QObject { Q_OBJECT - Q_PROPERTY(QStringList projectList READ projectList NOTIFY projectListChanged FINAL) + Q_PROPERTY(QJsonArray projectList READ projectList NOTIFY projectListChanged) public: explicit Backend(QObject *parent = nullptr); @@ -69,13 +69,12 @@ public: emit logsChanged(m_logs); } - QStringList projectList() const { return m_projectList; } + QJsonArray projectList() const { return m_projectList; } private: // UI data QString m_logs; - QStringList m_projectList; - QJsonArray m_projectListArray; + QJsonArray m_projectList; // Other members ServiceConnector m_serviceConnector; diff --git a/ui/HomePage.qml b/ui/HomePage.qml index 44f0f14d59f1a3206035a8aa4f62f3beda9509c6..520a60e3528e60c9120b9d67e53725918c10f8b5 100644 --- a/ui/HomePage.qml +++ b/ui/HomePage.qml @@ -62,33 +62,42 @@ Item { ColumnLayout { id: column2 Layout.fillWidth: true + ComboBox { id: projectList Layout.fillWidth: true - enabled: backend.userHash() !== '' + enabled: true onCurrentIndexChanged: { displayText = textAt(currentIndex) } + textRole: "appName" model: backend.projectList displayText: "Scan QR code to access your projects"; currentIndex: -1 Layout.preferredHeight: 50 - Connections { - target: backend - function onUserRegistered(){ - projectList.enabled = true; - } - } } Button { id: downloadUserProject text: qsTr("Run Project") onClicked: backend.runUserProject(projectList.currentText) - enabled: backend.userHash() !== '' + enabled: false 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 { diff --git a/ui/SettingsPage.qml b/ui/SettingsPage.qml index dc582594193457d45afbb71474435c88267cac21..894afb5ddd2b19d1859f62890d46d000d60e6b35 100644 --- a/ui/SettingsPage.qml +++ b/ui/SettingsPage.qml @@ -45,8 +45,9 @@ Item { Text{ leftPadding: 45 - text: qsTr("Scales the project to fit it to the current display and orientation") + text: qsTr("Scales the project to fit it to the current\ndisplay and orientation") font.pointSize: 12 + wrapMode: Text.WordWrap } }