1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Code Review

This commit is contained in:
Laserlicht 2024-04-21 16:56:39 +02:00
parent eb59950186
commit 04f5ad5f89
6 changed files with 46 additions and 14 deletions

View File

@ -15,6 +15,7 @@ set(launcher_SRCS
settingsView/csettingsview_moc.cpp
firstLaunch/firstlaunch_moc.cpp
main.cpp
helper.cpp
mainwindow_moc.cpp
languages.cpp
launcherdirs.cpp
@ -39,6 +40,7 @@ set(launcher_HEADERS
jsonutils.h
updatedialog_moc.h
main.h
helper.cpp
)
set(launcher_FORMS

18
launcher/helper.cpp Normal file
View File

@ -0,0 +1,18 @@
/*
* jsonutils.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "helper.h"
#include "../lib/CConfigHandler.h"
void Helper::loadSettings()
{
settings.init("config/settings.json", "vcmi:settings");
}

17
launcher/helper.h Normal file
View File

@ -0,0 +1,17 @@
/*
* jsonutils.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
VCMI_LIB_NAMESPACE_BEGIN
namespace Helper
{
void loadSettings();
}

View File

@ -21,6 +21,7 @@
#include "updatedialog_moc.h"
#include "main.h"
#include "helper.h"
void MainWindow::load()
{
@ -45,12 +46,7 @@ void MainWindow::load()
QDir::addSearchPath("icons", pathToQString(VCMIDirs::get().userDataPath() / "launcher" / "icons"));
#endif
loadSettings();
}
void MainWindow::loadSettings()
{
settings.init("config/settings.json", "vcmi:settings");
Helper::loadSettings();
}
void MainWindow::computeSidePanelSizes()

View File

@ -47,8 +47,6 @@ public:
explicit MainWindow(QWidget * parent = nullptr);
~MainWindow() override;
void loadSettings();
const CModList & getModList() const;
CModListView * getModView();

View File

@ -23,6 +23,7 @@
#include "../settingsView/csettingsview_moc.h"
#include "../launcherdirs.h"
#include "../jsonutils.h"
#include "../helper.h"
#include "../../lib/VCMIDirs.h"
#include "../../lib/CConfigHandler.h"
@ -636,15 +637,15 @@ void CModListView::manualInstallFile(QUrl url)
QStringList configFile = configDir.entryList({fileName}, QDir::Filter::Files); // case insensitive check
if(!configFile.empty())
{
if(QMessageBox::warning(this, tr("Replace config file?"), tr("Do you want to replace %1?").arg(configFile[0]), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)
auto dialogResult = QMessageBox::warning(this, tr("Replace config file?"), tr("Do you want to replace %1?").arg(configFile[0]), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if(dialogResult == QMessageBox::Yes)
{
QFile::remove(configDir.filePath(configFile[0]));
QFile::copy(url.toLocalFile(), configDir.filePath(configFile[0]));
const auto configFilePath = configDir.filePath(configFile[0]);
QFile::remove(configFilePath);
QFile::copy(url.toLocalFile(), configFilePath);
// reload settings
for(auto widget : qApp->topLevelWidgets())
if(auto mainWindow = qobject_cast<MainWindow *>(widget))
mainWindow->loadSettings();
Helper::loadSettings();
for(auto widget : qApp->allWidgets())
if(auto settingsView = qobject_cast<CSettingsView *>(widget))
settingsView->loadSettings();