From 4050358462a7756f47ecba22065554239f902d1b Mon Sep 17 00:00:00 2001
From: Rafael <Syping@users.noreply.github.com>
Date: Mon, 21 Mar 2016 20:44:07 +0100
Subject: [PATCH] first json parse code

---
 PictureDialog.cpp      | 42 ++++++++++++++++++++++++++++++++++++++++++
 PictureDialog.h        |  2 ++
 PictureDialog.ui       |  8 ++++++++
 SnapmaticPicture.cpp   |  7 ++-----
 app.rc                 | 32 ++++++++++++++++++++++++++++++++
 gta5sync.pro           |  5 ++++-
 main.cpp               |  3 ++-
 qjson4/QJsonArray      |  1 +
 qjson4/QJsonDocument   |  1 +
 qjson4/QJsonObject     |  1 +
 qjson4/QJsonParseError |  1 +
 qjson4/QJsonRoot       |  1 +
 qjson4/QJsonValue      |  1 +
 qjson4/QJsonValueRef   |  1 +
 14 files changed, 99 insertions(+), 7 deletions(-)
 create mode 100755 app.rc
 create mode 100755 qjson4/QJsonArray
 create mode 100755 qjson4/QJsonDocument
 create mode 100755 qjson4/QJsonObject
 create mode 100755 qjson4/QJsonParseError
 create mode 100755 qjson4/QJsonRoot
 create mode 100755 qjson4/QJsonValue
 create mode 100755 qjson4/QJsonValueRef

diff --git a/PictureDialog.cpp b/PictureDialog.cpp
index 575d511..da576b0 100755
--- a/PictureDialog.cpp
+++ b/PictureDialog.cpp
@@ -19,11 +19,18 @@
 #include "PictureDialog.h"
 #include "ui_PictureDialog.h"
 
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QVariantMap>
+#include <QJsonArray>
+#include <QDebug>
+
 PictureDialog::PictureDialog(QWidget *parent) :
     QDialog(parent),
     ui(new Ui::PictureDialog)
 {
     ui->setupUi(this);
+    jsonDrawString = ui->labJSON->text();
 }
 
 PictureDialog::~PictureDialog()
@@ -35,3 +42,38 @@ void PictureDialog::setSnapmaticPicture(QPixmap pixmap)
 {
     ui->labPicture->setPixmap(pixmap);
 }
+
+void PictureDialog::setJsonString(QString jsonStr)
+{
+    QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonStr.toLatin1());
+    QJsonObject jsonObject = jsonDocument.object();
+    QVariantMap jsonMap = jsonObject.toVariantMap();
+
+    QString locX;
+    QString locY;
+    QString locZ;
+    QStringList plyrsList;
+
+    if (jsonMap.contains("loc"))
+    {
+        QJsonObject locObject = jsonObject["loc"].toObject();
+        QVariantMap locMap = locObject.toVariantMap();
+        if (locMap.contains("x")) { locX = locMap["x"].toString(); }
+        if (locMap.contains("y")) { locY = locMap["y"].toString(); }
+        if (locMap.contains("z")) { locZ = locMap["z"].toString(); }
+    }
+    if (jsonMap.contains("plyrs"))
+    {
+        plyrsList = jsonMap["plyrs"].toStringList();
+    }
+
+    QString plyrsStr;
+    foreach (const QString &player, plyrsList)
+    {
+        plyrsStr.append(", ");
+        plyrsStr.append(player);
+    }
+    if (plyrsStr.length() >= 1) { plyrsStr.remove(0,2); }
+
+    ui->labJSON->setText(jsonDrawString.arg(locX, locY, locZ, plyrsStr));
+}
diff --git a/PictureDialog.h b/PictureDialog.h
index 7c4933b..42ff0bf 100755
--- a/PictureDialog.h
+++ b/PictureDialog.h
@@ -32,10 +32,12 @@ class PictureDialog : public QDialog
 public:
     explicit PictureDialog(QWidget *parent = 0);
     void setSnapmaticPicture(QPixmap pixmap);
+    void setJsonString(QString jsonStr);
     ~PictureDialog();
 
 private:
     Ui::PictureDialog *ui;
+    QString jsonDrawString;
 };
 
 #endif // PICTUREDIALOG_H
diff --git a/PictureDialog.ui b/PictureDialog.ui
index 5d890f5..30c2dd8 100755
--- a/PictureDialog.ui
+++ b/PictureDialog.ui
@@ -33,6 +33,14 @@
      </property>
     </widget>
    </item>
+   <item>
+    <widget class="QLabel" name="labJSON">
+     <property name="text">
+      <string>Location: X: %1 Y: %2 Z: %3
+Players: %4</string>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <resources/>
diff --git a/SnapmaticPicture.cpp b/SnapmaticPicture.cpp
index 965dc68..6c427dc 100755
--- a/SnapmaticPicture.cpp
+++ b/SnapmaticPicture.cpp
@@ -92,15 +92,12 @@ bool SnapmaticPicture::readingPicture()
     if (!picFile->isReadable())
     {
         lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",3,NOJSON";
-        qDebug() << lastStep;
     }
     else if (picFile->read(4) != "JSON")
     {
         lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",3,CTJSON";
-        qDebug() << lastStep;
     }
     QByteArray jsonRawContent = picFile->read(jsonStreamLength);
-    qDebug() << jsonRawContent.toHex();
     jsonStr = getSnapmaticJSONString(jsonRawContent);
 
     return cachePicture.loadFromData(jpegRawContent);
@@ -111,7 +108,7 @@ QString SnapmaticPicture::getSnapmaticPictureString(QByteArray snapmaticHeader)
     QByteArray snapmaticUsefulBytes = snapmaticHeader.left(snapmaticUsefulLength);
     snapmaticUsefulBytes.replace(QByteArray::fromHex("00"),"");
     snapmaticUsefulBytes.replace(QByteArray::fromHex("01"),"");
-    return QString::fromAscii(snapmaticUsefulBytes);
+    return QString::fromLatin1(snapmaticUsefulBytes);
 }
 
 QString SnapmaticPicture::getSnapmaticJSONString(QByteArray jsonBytes)
@@ -119,7 +116,7 @@ QString SnapmaticPicture::getSnapmaticJSONString(QByteArray jsonBytes)
     QByteArray jsonUsefulBytes = jsonBytes;
     jsonUsefulBytes.replace(QByteArray::fromHex("00"),"");
     jsonUsefulBytes.replace(QByteArray::fromHex("0C"),"");
-    return QString::fromAscii(jsonUsefulBytes);
+    return QString::fromLatin1(jsonUsefulBytes);
 }
 
 bool SnapmaticPicture::readingPictureFromFile(QString fileName)
diff --git a/app.rc b/app.rc
new file mode 100755
index 0000000..0950fc4
--- /dev/null
+++ b/app.rc
@@ -0,0 +1,32 @@
+//IDI_ICON1               ICON    DISCARDABLE     "gta5sync.ico"
+
+#include <windows.h>
+
+VS_VERSION_INFO     VERSIONINFO
+FILEVERSION         1, 0, 0, 0
+PRODUCTVERSION      1, 0, 0, 0
+FILEFLAGSMASK       0x3fL
+FILEFLAGS           0
+FILEOS              VOS_NT_WINDOWS32
+FILETYPE            VFT_APP
+FILESUBTYPE         VFT2_UNKNOWN
+BEGIN
+    BLOCK   "VarFileInfo"
+    BEGIN
+        VALUE   "Translation",  0x0409,  1200
+    END
+    BLOCK   "StringFileInfo"
+    BEGIN
+        BLOCK   "040904b0"
+        BEGIN
+            VALUE   "CompanyName",      "Syping Gaming Team\0"
+            VALUE   "FileDescription",  "Grand Theft Auto V Sync\0"
+            VALUE   "FileVersion",      "1.0.0.0\0"
+            VALUE   "InternalName",     "gta5sync\0"
+            VALUE   "LegalCopyright",   "Copyright � 2015-2016 Syping Gaming Team\0"
+            VALUE   "OriginalFilename", "gta5sync.exe\0"
+            VALUE   "ProductName",      "Grand Theft Auto V Sync\0"
+            VALUE   "ProductVersion",   "1.0.0.0\0"
+        END
+    END
+END
diff --git a/gta5sync.pro b/gta5sync.pro
index c9d1aae..f7975c4 100755
--- a/gta5sync.pro
+++ b/gta5sync.pro
@@ -19,6 +19,7 @@
 QT       += core gui
 
 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets json
+isEqual(QT_MAJOR_VERSION, 5): DEFINES += QT5_MODE
 
 TARGET = gta5sync
 TEMPLATE = app
@@ -37,7 +38,9 @@ FORMS    += \
 
 RESOURCES +=
 
-OTHER_FILES +=
+OTHER_FILES += app.rc
+
+win32: RC_FILE += app.rc
 
 # QT4 ONLY STUFF
 
diff --git a/main.cpp b/main.cpp
index 104a7b0..e8b6495 100755
--- a/main.cpp
+++ b/main.cpp
@@ -48,9 +48,10 @@ int main(int argc, char *argv[])
         qDebug() << picture.readingPictureFromFile(arg1);
         qDebug() << picture.getLastStep();
         PictureDialog picDialog;
+        picDialog.setWindowFlags(picDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
         picDialog.setWindowTitle(picture.getPictureStr());
-        qDebug() << picture.getJsonStr();
         picDialog.setSnapmaticPicture(picture.getPixmap());
+        picDialog.setJsonString(picture.getJsonStr());
         picDialog.show();
 
         return a.exec();
diff --git a/qjson4/QJsonArray b/qjson4/QJsonArray
new file mode 100755
index 0000000..89dbf4e
--- /dev/null
+++ b/qjson4/QJsonArray
@@ -0,0 +1 @@
+#include "QJsonArray.h"
diff --git a/qjson4/QJsonDocument b/qjson4/QJsonDocument
new file mode 100755
index 0000000..f652bf4
--- /dev/null
+++ b/qjson4/QJsonDocument
@@ -0,0 +1 @@
+#include "QJsonDocument.h"
diff --git a/qjson4/QJsonObject b/qjson4/QJsonObject
new file mode 100755
index 0000000..fb2126e
--- /dev/null
+++ b/qjson4/QJsonObject
@@ -0,0 +1 @@
+#include "QJsonObject.h"
diff --git a/qjson4/QJsonParseError b/qjson4/QJsonParseError
new file mode 100755
index 0000000..7d30db8
--- /dev/null
+++ b/qjson4/QJsonParseError
@@ -0,0 +1 @@
+#include "QJsonParseError.h"
diff --git a/qjson4/QJsonRoot b/qjson4/QJsonRoot
new file mode 100755
index 0000000..fbcaca1
--- /dev/null
+++ b/qjson4/QJsonRoot
@@ -0,0 +1 @@
+#include "QJsonRoot.h"
diff --git a/qjson4/QJsonValue b/qjson4/QJsonValue
new file mode 100755
index 0000000..eb1b6fe
--- /dev/null
+++ b/qjson4/QJsonValue
@@ -0,0 +1 @@
+#include "QJsonValue.h"
diff --git a/qjson4/QJsonValueRef b/qjson4/QJsonValueRef
new file mode 100755
index 0000000..f3b6811
--- /dev/null
+++ b/qjson4/QJsonValueRef
@@ -0,0 +1 @@
+#include "QJsonValueRef.h"