Bladeren bron

Code Review

Laserlicht 1 jaar geleden
bovenliggende
commit
04f5ad5f89

+ 2 - 0
launcher/CMakeLists.txt

@@ -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 - 0
launcher/helper.cpp

@@ -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 - 0
launcher/helper.h

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

+ 2 - 6
launcher/mainwindow_moc.cpp

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

+ 0 - 2
launcher/mainwindow_moc.h

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

+ 7 - 6
launcher/modManager/cmodlistview_moc.cpp

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