From fd25c7666453749e979909e8111f7921768892e7 Mon Sep 17 00:00:00 2001 From: nordsoft Date: Fri, 26 Aug 2022 03:07:07 +0400 Subject: [PATCH] Code review fixes --- launcher/CMakeLists.txt | 6 ++-- launcher/mainwindow_moc.cpp | 2 +- launcher/settingsView/csettingsview_moc.cpp | 2 +- launcher/updatedialog_moc.cpp | 35 ++++++++++----------- launcher/updatedialog_moc.h | 3 ++ 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 130990a5e..e9fd1ec00 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -32,7 +32,7 @@ set(launcher_SRCS mainwindow_moc.cpp launcherdirs.cpp jsonutils.cpp - updatedialog_moc.cpp + updatedialog_moc.cpp ) set(launcher_HEADERS @@ -42,7 +42,7 @@ set(launcher_HEADERS mainwindow_moc.h launcherdirs.h jsonutils.h - updatedialog_moc.h + updatedialog_moc.h ) set(launcher_FORMS @@ -50,7 +50,7 @@ set(launcher_FORMS modManager/imageviewer_moc.ui settingsView/csettingsview_moc.ui mainwindow_moc.ui - updatedialog_moc.ui + updatedialog_moc.ui ) assign_source_group(${launcher_SRCS} ${launcher_HEADERS} VCMI_launcher.rc) diff --git a/launcher/mainwindow_moc.cpp b/launcher/mainwindow_moc.cpp index 006544f75..8aa817664 100644 --- a/launcher/mainwindow_moc.cpp +++ b/launcher/mainwindow_moc.cpp @@ -83,7 +83,7 @@ MainWindow::MainWindow(QWidget * parent) connect(ui->tabSelectList, SIGNAL(currentRowChanged(int)), ui->tabListWidget, SLOT(setCurrentIndex(int))); - if(settings["launcher"]["updateOnStartup"].Bool() == true) + if(settings["launcher"]["updateOnStartup"].Bool()) UpdateDialog::showUpdateDialog(false); } diff --git a/launcher/settingsView/csettingsview_moc.cpp b/launcher/settingsView/csettingsview_moc.cpp index 5103cf73f..106666988 100644 --- a/launcher/settingsView/csettingsview_moc.cpp +++ b/launcher/settingsView/csettingsview_moc.cpp @@ -103,7 +103,7 @@ void CSettingsView::loadSettings() } CSettingsView::CSettingsView(QWidget * parent) - : QWidget(parent), ui(new Ui::CSettingsView) + : QWidget(parent), ui(new Ui::CSettingsView) { ui->setupUi(this); diff --git a/launcher/updatedialog_moc.cpp b/launcher/updatedialog_moc.cpp index fc4df6068..d43c555a6 100644 --- a/launcher/updatedialog_moc.cpp +++ b/launcher/updatedialog_moc.cpp @@ -14,7 +14,6 @@ #include "../lib/CConfigHandler.h" #include "../lib/GameConstants.h" -#include #include #include @@ -33,7 +32,7 @@ UpdateDialog::UpdateDialog(QWidget *parent, bool calledManually) : connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(close())); - if(settings["launcher"]["updateOnStartup"].Bool() == true) + if(settings["launcher"]["updateOnStartup"].Bool()) ui->checkOnStartup->setCheckState(Qt::CheckState::Checked); currentVersion = GameConstants::VCMI_VERSION; @@ -53,14 +52,12 @@ UpdateDialog::UpdateDialog(QWidget *parent, bool calledManually) : #endif QString url = QString::fromStdString(settings["launcher"]["updateConfigUrl"].String()); - - QScopedPointer manager(new QNetworkAccessManager); - - QNetworkReply *response = manager->get(QNetworkRequest(QUrl(url))); + + QNetworkReply *response = networkManager.get(QNetworkRequest(QUrl(url))); QObject::connect(response, &QNetworkReply::finished, [&, response]{ response->deleteLater(); - response->manager()->deleteLater(); + if(response->error() != QNetworkReply::NoError) { ui->versionLabel->setStyleSheet("QLabel { background-color : red; color : black; }"); @@ -72,8 +69,7 @@ UpdateDialog::UpdateDialog(QWidget *parent, bool calledManually) : auto byteArray = response->readAll(); JsonNode node(byteArray.constData(), byteArray.size()); loadFromJson(node); - - }) && manager.take(); + }); } UpdateDialog::~UpdateDialog() @@ -122,13 +118,17 @@ void UpdateDialog::loadFromJson(const JsonNode & node) show(); } - if(node["updateType"].String() == "minor") - ui->versionLabel->setStyleSheet("QLabel { background-color : gray; color : black; }"); - if(node["updateType"].String() == "major") - ui->versionLabel->setStyleSheet("QLabel { background-color : orange; color : black; }"); - if(node["updateType"].String() == "critical") - ui->versionLabel->setStyleSheet("QLabel { background-color : red; color : black; }"); + const auto updateType = node["updateType"].String(); + QString bgColor; + if(updateType == "minor") + bgColor = "gray"; + else if(updateType == "major") + bgColor = "orange"; + else if(updateType == "critical") + bgColor = "red"; + + ui->versionLabel->setStyleSheet(QLatin1String("QLabel { background-color : %1; color : black; }").arg(bgColor)); ui->versionLabel->setText(QString::fromStdString(newVersion)); ui->plainTextEdit->setPlainText(QString::fromStdString(node["changeLog"].String())); @@ -136,8 +136,5 @@ void UpdateDialog::loadFromJson(const JsonNode & node) if(node["downloadLinks"][platformParameter].getType() == JsonNode::JsonType::DATA_STRING) downloadLink = QString::fromStdString(node["downloadLinks"][platformParameter].String()); - QString downloadHtml("link"; - - ui->downloadLink->setText(downloadHtml); + ui->downloadLink->setText(QString{"link"}.arg(downloadLink)); } diff --git a/launcher/updatedialog_moc.h b/launcher/updatedialog_moc.h index ca0d41f4d..6aa8e475e 100644 --- a/launcher/updatedialog_moc.h +++ b/launcher/updatedialog_moc.h @@ -9,6 +9,7 @@ */ #pragma once #include +#include class JsonNode; @@ -35,6 +36,8 @@ private: std::string currentVersion; std::string platformParameter = "other"; + QNetworkAccessManager networkManager; + bool calledManually; void loadFromJson(const JsonNode & node);