1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-18 17:40:48 +02:00

Code review fixes

This commit is contained in:
nordsoft 2022-08-26 03:07:07 +04:00
parent 79f0dd7d22
commit fd25c76664
5 changed files with 24 additions and 24 deletions

View File

@ -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)

View File

@ -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);
}

View File

@ -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);

View File

@ -14,7 +14,6 @@
#include "../lib/CConfigHandler.h"
#include "../lib/GameConstants.h"
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
@ -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;
@ -54,13 +53,11 @@ UpdateDialog::UpdateDialog(QWidget *parent, bool calledManually) :
QString url = QString::fromStdString(settings["launcher"]["updateConfigUrl"].String());
QScopedPointer<QNetworkAccessManager> 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("<a href=\"");
downloadHtml += downloadLink + "\">link</a>";
ui->downloadLink->setText(downloadHtml);
ui->downloadLink->setText(QString{"<a href=\"%1\">link</a>"}.arg(downloadLink));
}

View File

@ -9,6 +9,7 @@
*/
#pragma once
#include <QDialog>
#include <QNetworkAccessManager>
class JsonNode;
@ -35,6 +36,8 @@ private:
std::string currentVersion;
std::string platformParameter = "other";
QNetworkAccessManager networkManager;
bool calledManually;
void loadFromJson(const JsonNode & node);