QTfrontend/net/tcpBase.cpp
branchui-scaling
changeset 15283 c4fd2813b127
parent 15258 1ce9b717bb41
--- a/QTfrontend/net/tcpBase.cpp	Wed May 16 18:22:28 2018 +0200
+++ b/QTfrontend/net/tcpBase.cpp	Wed Jul 31 23:14:27 2019 +0200
@@ -21,10 +21,12 @@
 #include <QImage>
 #include <QThread>
 #include <QApplication>
+#include <QProcessEnvironment>
 
 #include "tcpBase.h"
 #include "hwconsts.h"
 #include "MessageDialog.h"
+#include "gameuiconfig.h"
 
 #ifdef HWLIBRARY
 extern "C" {
@@ -104,11 +106,12 @@
 
 }
 
-TCPBase::TCPBase(bool demoMode, QObject *parent) :
+TCPBase::TCPBase(bool demoMode, bool usesCustomLanguage, QObject *parent) :
     QObject(parent),
     m_hasStarted(false),
     m_isDemoMode(demoMode),
     m_connected(false),
+    m_usesCustomLanguage(usesCustomLanguage),
     IPCSocket(0)
 {
     process = 0;
@@ -183,6 +186,18 @@
     process->setProcessChannelMode(QProcess::ForwardedChannels);
 #endif
 
+    // If game config uses non-system locale, we set the environment
+    // of the engine first
+    if(m_usesCustomLanguage)
+    {
+        QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
+        QString hwengineLang = QLocale().name() + ".UTF8";
+        qDebug("Setting hwengine environment: LANG=%s", qPrintable(hwengineLang));
+        // TODO: Check if this is correct and works on all systems
+        env.insert("LANG", QLocale().name() + ".UTF8");
+        process->setProcessEnvironment(env);
+    }
+    qDebug("Starting hwengine ...");
     process->start(bindir->absolutePath() + "/hwengine", arguments);
 #endif
     m_hasStarted = true;
@@ -235,7 +250,7 @@
 
     // show error message if there was an error that was not an engine's
     // fatal error - because that one already sent a info via IPC
-    if ((exitCode != 0) && (exitCode != 2))
+    if ((exitCode != HWENGINE_EXITCODE_OK) && (exitCode != HWENGINE_EXITCODE_FATAL))
     {
         // inform user that something bad happened
         MessageDialog::ShowFatalMessage(
@@ -244,16 +259,22 @@
             "We are very sorry for the inconvenience :(\n\n"
             "If this keeps happening, please click the '%2' button in the main menu!")
             .arg(exitCode)
-            .arg("Feedback"));
+            .arg(QCoreApplication::translate("PageMain", "Feedback")));
 
     }
 }
 
 void TCPBase::tcpServerReady()
 {
-    disconnect(srvsList.first(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady()));
-
-    RealStart();
+    if (!srvsList.isEmpty())
+    {
+        disconnect(srvsList.first(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady()));
+        RealStart();
+    }
+    else
+    {
+        qDebug("tcpServerReady() called while srvsList was empty. Not starting TCP server");
+    }
 }
 
 void TCPBase::Start(bool couldCancelPreviousRequest)