Skip to content
Snippets Groups Projects

QDS-11878 Reduce the numbers of user notification

Merged Burak Hançerli requested to merge QDS-11878/show-one-error into master
3 files
+ 61
35
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 37
19
@@ -336,16 +336,16 @@ void Backend::runDemoProject(const QString &projectName)
// sample project info
// [{"lastUpdate":1701947766739.9812,"name":"ClusterTutorial.qmlrc"}]
const QJsonArray projectList = m_serviceConnector.fetchUserDemoList();
const std::optional<QJsonArray> projectList = m_serviceConnector.fetchUserDemoList();
if (projectList.isEmpty()) {
if (projectList == std::nullopt) {
qCritical("Please check your internet connection and try again");
emit popupClose();
return;
}
QJsonObject projectInfo;
for (auto project : projectList) {
for (auto project : projectList.value()) {
if (projectName == project.toObject().value("name").toString().remove(".qmlrc")) {
projectInfo = project.toObject();
break;
@@ -359,11 +359,19 @@ void Backend::runDemoProject(const QString &projectName)
const QString url = "https://designviewer.qt.io/qmlprojects/demos/" + projectName
+ ".qmlrc";
QByteArray project = m_serviceConnector.fetchProject(url);
const std::optional<QByteArray> project = m_serviceConnector.fetchProject(url);
if (project == std::nullopt) {
qCritical() << "Could not download demo project. Please check the logs for more "
"information.";
emit popupClose();
return;
}
qDebug() << "Demo project is not cached. Trying to download from " << url << " ...";
updatePopup("Caching demo project...");
if (!m_projectManager->cacheDemoProject(project, projectInfo)) {
if (!m_projectManager->cacheDemoProject(project.value(), projectInfo)) {
qCritical()
<< "Could not cache demo project. Please check the logs for more information.";
emit popupClose();
@@ -405,9 +413,9 @@ void Backend::runUserProject(const QString &projectName)
const QString userHash = Backend::userHash();
qDebug("Checking if project is cached. Getting list of available projects...");
const QJsonArray projectList = m_serviceConnector.fetchUserProjectList(userHash);
const std::optional<QJsonArray> projectList = m_serviceConnector.fetchUserProjectList(userHash);
if (projectList.isEmpty()) {
if (projectList == std::nullopt) {
qCritical("Please check your internet connection and try again");
emit popupClose();
return;
@@ -416,7 +424,7 @@ void Backend::runUserProject(const QString &projectName)
QString projectLastModified;
QString projectId;
QJsonObject projectInfo;
for (auto project : projectList) {
for (auto project : projectList.value()) {
if (projectName == project.toObject().value("appName").toString()) {
projectInfo = project.toObject();
break;
@@ -428,10 +436,18 @@ void Backend::runUserProject(const QString &projectName)
if (!projectCached) {
qDebug("Project is not cached. Downloading...");
updatePopup("Project is not cached. Downloading...", false);
QByteArray projectData = m_serviceConnector.fetchUserProject(userHash, projectName);
const std::optional<QByteArray> projectData
= m_serviceConnector.fetchUserProject(userHash, projectName);
if (projectData == std::nullopt) {
qCritical()
<< "Could not download project. Please check the logs for more information.";
emit popupClose();
return;
}
updatePopup("Caching user project...");
if (!m_projectManager->cacheProject(projectData, projectInfo)) {
if (!m_projectManager->cacheProject(projectData.value(), projectInfo)) {
qCritical() << "Could not cache project. Please check the logs for more information.";
emit popupClose();
return;
@@ -455,14 +471,16 @@ void Backend::runOnlineProject(const QString &url)
initializeProjectManager();
emit popupOpen();
updatePopup("Downloading...", false);
QByteArray projectData = m_serviceConnector.fetchProject(url);
if (projectData.isEmpty()) {
const std::optional<QByteArray> projectData = m_serviceConnector.fetchProject(url);
if (projectData == std::nullopt) {
qCritical() << "Could not download project. Please check the logs for more information.";
emit popupClose();
return;
}
updatePopup("Unpacking project...");
QString projectPath = m_projectManager->unpackProject(projectData);
QString projectPath = m_projectManager->unpackProject(projectData.value());
updatePopup("Running project...");
if (!m_projectManager->runProject(projectPath))
@@ -484,16 +502,16 @@ void Backend::updateUserProjectList()
}
qDebug() << "Fetching available project list for user:" << userHash;
QJsonArray projectList = m_serviceConnector.fetchUserProjectList(userHash);
const std::optional<QJsonArray> projectList = m_serviceConnector.fetchUserProjectList(userHash);
if (projectList == m_projectList) {
qDebug("No new projects are available");
} else if (projectList.isEmpty()) {
if (projectList == std::nullopt) {
qWarning("Could not fetch project list. Either there are no projects or there is a "
"network issue");
} else if (projectList.value() == m_projectList) {
qDebug("No new projects are available");
} else {
qDebug("List of available projects fetched:");
for (const auto &project : projectList) {
for (const auto &project : projectList.value()) {
const QString projectName{project.toObject().value("appName").toString()};
qDebug() << "--" << projectName;
}
@@ -502,7 +520,7 @@ void Backend::updateUserProjectList()
// 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;
m_projectList = projectList.value();
emit projectListChanged();
}
Loading