More Qt-ish code, fix couple warnings.
authorunc0rr
Tue, 04 Sep 2012 12:25:55 +0400
changeset 7665 e556b44f5bd8
parent 7664 4bc4b739f6e0
child 7666 8212121cf6a1
More Qt-ish code, fix couple warnings.
QTfrontend/game.cpp
QTfrontend/game.h
--- a/QTfrontend/game.cpp	Tue Sep 04 12:16:36 2012 +0400
+++ b/QTfrontend/game.cpp	Tue Sep 04 12:25:55 2012 +0400
@@ -431,7 +431,7 @@
     RawSendIPC(buf);
 }
 
-void HWGame::sendCampaignVar(QByteArray varToSend)
+void HWGame::sendCampaignVar(const QByteArray &varToSend)
 {
     QString varToFind(varToSend);
     QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + campaignTeam + ".hwt", QSettings::IniFormat, 0);
@@ -442,22 +442,14 @@
     RawSendIPC(command);
 }
 
-void HWGame::writeCampaignVar(QByteArray varVal)
+void HWGame::writeCampaignVar(const QByteArray & varVal)
 {
-    QString varToWrite("");
-    QString varValue("");
-    unsigned int i = 0;
-    while (i < varVal.size() && varVal.at(i) != ' ')
-    {
-      varToWrite.append(varVal.at(i));
-      i++;
-    }
-    i++;
-    while (i < varVal.size() && varVal.at(i) != '\0')
-    {
-      varValue.append(varVal.at(i));
-      i++;
-    }
+    int i = varVal.indexOf(" ");
+    if(i < 0)
+        return;
+
+    QString varToWrite = QString::fromUtf8(varVal.left(i));
+    QString varValue = QString::fromUtf8(varVal.mid(i + 1));
 
     QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + campaignTeam + ".hwt", QSettings::IniFormat, 0);
     teamfile.setIniCodec("UTF-8");
--- a/QTfrontend/game.h	Tue Sep 04 12:16:36 2012 +0400
+++ b/QTfrontend/game.h	Tue Sep 04 12:25:55 2012 +0400
@@ -111,8 +111,8 @@
         void SendCampaignConfig();
         void ParseMessage(const QByteArray & msg);
         void SetGameState(GameState state);
-        void sendCampaignVar(QByteArray varToSend);
-        void writeCampaignVar(QByteArray varVal);
+        void sendCampaignVar(const QByteArray & varToSend);
+        void writeCampaignVar(const QByteArray &varVal);
 };
 
 #endif