2016-02-26 22:22:34 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* gta5sync GRAND THEFT AUTO V SYNC
|
2016-03-27 09:52:23 +02:00
|
|
|
* Copyright (C) 2016 Syping
|
2016-02-26 22:22:34 +01:00
|
|
|
*
|
2016-03-21 07:54:14 +01:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2016-02-26 22:22:34 +01:00
|
|
|
*
|
2016-03-21 07:54:14 +01:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2016-02-26 22:22:34 +01:00
|
|
|
*
|
2016-03-21 07:54:14 +01:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-02-26 22:22:34 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2016-03-20 21:57:18 +01:00
|
|
|
#include "SnapmaticPicture.h"
|
2016-03-31 23:41:53 +02:00
|
|
|
#include "StringParser.h"
|
2016-03-21 21:33:22 +01:00
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
2016-04-06 04:22:30 +02:00
|
|
|
#include <QStringList>
|
2016-03-21 21:33:22 +01:00
|
|
|
#include <QVariantMap>
|
|
|
|
#include <QJsonArray>
|
2016-03-21 03:10:28 +01:00
|
|
|
#include <QString>
|
2016-07-22 16:06:36 +02:00
|
|
|
#include <QBuffer>
|
|
|
|
#include <QDebug>
|
2016-03-27 09:52:23 +02:00
|
|
|
#include <QImage>
|
2016-03-21 03:10:28 +01:00
|
|
|
#include <QFile>
|
2016-02-26 22:22:34 +01:00
|
|
|
|
2016-04-06 04:22:30 +02:00
|
|
|
SnapmaticPicture::SnapmaticPicture(const QString &fileName, QObject *parent) : QObject(parent), picFileName(fileName)
|
2016-02-26 22:22:34 +01:00
|
|
|
{
|
2016-03-21 21:46:36 +01:00
|
|
|
// PARSE INT INIT - DO NOT CHANGE THIS VALUES
|
|
|
|
snapmaticHeaderLength = 278;
|
2016-03-23 01:09:27 +01:00
|
|
|
snapmaticUsefulLength = 260;
|
2016-07-22 16:06:36 +02:00
|
|
|
snapmaticFileMaxSize = 528192;
|
2016-03-21 21:46:36 +01:00
|
|
|
jpegHeaderLineDifStr = 2;
|
|
|
|
jpegPreHeaderLength = 14;
|
|
|
|
jpegPicStreamLength = 524288;
|
|
|
|
jsonStreamLength = 3076;
|
2016-03-29 13:17:38 +02:00
|
|
|
tideStreamLength = 260;
|
2016-03-21 21:46:36 +01:00
|
|
|
|
2016-07-22 16:06:36 +02:00
|
|
|
// PARSE EDITOR INIT
|
|
|
|
jpegStreamEditorBegin = 292;
|
|
|
|
jsonStreamEditorBegin = 524588;
|
|
|
|
jsonStreamEditorLength = 3072;
|
|
|
|
rawPicContent = "";
|
|
|
|
|
2016-03-21 21:46:36 +01:00
|
|
|
// INIT PIC
|
2016-03-27 09:52:23 +02:00
|
|
|
cachePicture = QImage(0, 0, QImage::Format_RGB32);
|
2016-04-06 04:22:30 +02:00
|
|
|
picExportFileName = "";
|
2016-03-21 03:10:28 +01:00
|
|
|
pictureStr = "";
|
|
|
|
lastStep = "";
|
2016-04-06 04:22:30 +02:00
|
|
|
sortStr = "";
|
|
|
|
titlStr = "";
|
|
|
|
descStr = "";
|
2016-03-21 22:29:57 +01:00
|
|
|
picOk = 0;
|
2016-03-21 21:46:36 +01:00
|
|
|
|
|
|
|
// INIT JSON
|
2016-03-21 22:29:57 +01:00
|
|
|
jsonOk = 0;
|
2016-03-21 03:10:28 +01:00
|
|
|
jsonStr = "";
|
2016-03-21 21:46:36 +01:00
|
|
|
jsonLocX = 0;
|
|
|
|
jsonLocY = 0;
|
|
|
|
jsonLocZ = 0;
|
|
|
|
jsonCrewID = 0;
|
2016-04-23 20:15:59 +02:00
|
|
|
jsonArea = "";
|
2016-05-08 19:34:10 +02:00
|
|
|
jsonCreatedTimestamp = 0;
|
2016-03-21 21:46:36 +01:00
|
|
|
jsonPlyrsList = QStringList();
|
2016-12-09 23:13:21 +01:00
|
|
|
jsonMeme = 0;
|
|
|
|
jsonMug = 0;
|
|
|
|
jsonSelfie = 0;
|
|
|
|
jsonDirector = 0;
|
|
|
|
jsonRockstarEditor = 0;
|
2016-03-21 03:10:28 +01:00
|
|
|
}
|
|
|
|
|
2016-12-09 23:13:21 +01:00
|
|
|
SnapmaticPicture::~SnapmaticPicture()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SnapmaticPicture::readingPicture(bool writeEnabled_, bool cacheEnabled_)
|
2016-03-21 03:10:28 +01:00
|
|
|
{
|
|
|
|
// Start opening file
|
|
|
|
// lastStep is like currentStep
|
|
|
|
|
2016-07-23 00:13:57 +02:00
|
|
|
// Set boolean values
|
|
|
|
writeEnabled = writeEnabled_;
|
2016-12-09 23:13:21 +01:00
|
|
|
cacheEnabled = cacheEnabled_;
|
2016-07-23 00:13:57 +02:00
|
|
|
|
2016-03-21 03:10:28 +01:00
|
|
|
QFile *picFile = new QFile(picFileName);
|
2016-07-22 16:06:36 +02:00
|
|
|
QIODevice *picStream;
|
|
|
|
|
2016-03-21 03:10:28 +01:00
|
|
|
if (!picFile->open(QFile::ReadOnly))
|
|
|
|
{
|
2016-04-06 04:22:30 +02:00
|
|
|
lastStep = "1;/1,OpenFile," + StringParser::convertDrawStringForLog(picFileName);
|
2016-03-28 15:24:09 +02:00
|
|
|
picFile->deleteLater();
|
|
|
|
delete picFile;
|
2016-03-21 03:10:28 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-22 16:06:36 +02:00
|
|
|
rawPicContent = picFile->read(snapmaticFileMaxSize);
|
2016-12-09 23:13:21 +01:00
|
|
|
picFile->close();
|
|
|
|
delete picFile;
|
|
|
|
|
2016-07-22 16:06:36 +02:00
|
|
|
picStream = new QBuffer(&rawPicContent);
|
|
|
|
picStream->open(QIODevice::ReadWrite);
|
2016-03-21 03:10:28 +01:00
|
|
|
|
|
|
|
// Reading Snapmatic Header
|
2016-07-22 16:06:36 +02:00
|
|
|
if (!picStream->isReadable())
|
2016-03-21 03:10:28 +01:00
|
|
|
{
|
2016-04-06 04:22:30 +02:00
|
|
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",1,NOHEADER";
|
2016-07-22 16:06:36 +02:00
|
|
|
picStream->close();
|
|
|
|
picStream->deleteLater();
|
2016-12-09 23:13:21 +01:00
|
|
|
delete picStream;
|
2016-03-21 03:10:28 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-22 16:06:36 +02:00
|
|
|
QByteArray snapmaticHeaderLine = picStream->read(snapmaticHeaderLength);
|
2016-03-21 03:10:28 +01:00
|
|
|
pictureStr = getSnapmaticPictureString(snapmaticHeaderLine);
|
|
|
|
|
|
|
|
// Reading JPEG Header Line
|
2016-07-22 16:06:36 +02:00
|
|
|
if (!picStream->isReadable())
|
2016-03-21 03:10:28 +01:00
|
|
|
{
|
2016-04-06 04:22:30 +02:00
|
|
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",2,NOHEADER";
|
2016-07-22 16:06:36 +02:00
|
|
|
picStream->close();
|
|
|
|
picStream->deleteLater();
|
2016-12-09 23:13:21 +01:00
|
|
|
delete picStream;
|
2016-03-21 03:10:28 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-22 16:06:36 +02:00
|
|
|
QByteArray jpegHeaderLine = picStream->read(jpegPreHeaderLength);
|
2016-03-21 03:10:28 +01:00
|
|
|
|
|
|
|
// Checking for JPEG
|
2016-03-21 21:46:36 +01:00
|
|
|
jpegHeaderLine.remove(0, jpegHeaderLineDifStr);
|
2016-03-21 03:10:28 +01:00
|
|
|
if (jpegHeaderLine.left(4) != "JPEG")
|
|
|
|
{
|
2016-04-06 04:22:30 +02:00
|
|
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",2,NOJPEG";
|
2016-07-22 16:06:36 +02:00
|
|
|
picStream->close();
|
|
|
|
picStream->deleteLater();
|
2016-12-09 23:13:21 +01:00
|
|
|
delete picStream;
|
2016-03-21 03:10:28 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-21 07:54:14 +01:00
|
|
|
// Read JPEG Stream
|
2016-07-22 16:06:36 +02:00
|
|
|
if (!picStream->isReadable())
|
2016-03-21 07:54:14 +01:00
|
|
|
{
|
2016-04-06 04:22:30 +02:00
|
|
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",2,NOPIC";
|
2016-07-22 16:06:36 +02:00
|
|
|
picStream->close();
|
|
|
|
picStream->deleteLater();
|
2016-12-09 23:13:21 +01:00
|
|
|
delete picStream;
|
2016-03-21 07:54:14 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-22 16:06:36 +02:00
|
|
|
QByteArray jpegRawContent = picStream->read(jpegPicStreamLength);
|
2016-12-09 23:13:21 +01:00
|
|
|
if (cacheEnabled) picOk = cachePicture.loadFromData(jpegRawContent, "JPEG");
|
|
|
|
if (!cacheEnabled)
|
|
|
|
{
|
|
|
|
QImage tempPicture;
|
|
|
|
picOk = tempPicture.loadFromData(jpegRawContent, "JPEG");
|
|
|
|
}
|
2016-03-21 07:54:14 +01:00
|
|
|
|
|
|
|
// Read JSON Stream
|
2016-07-22 16:06:36 +02:00
|
|
|
if (!picStream->isReadable())
|
2016-03-21 07:54:14 +01:00
|
|
|
{
|
2016-04-06 04:22:30 +02:00
|
|
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",3,NOJSON";
|
2016-07-22 16:06:36 +02:00
|
|
|
picStream->close();
|
|
|
|
picStream->deleteLater();
|
2016-12-09 23:13:21 +01:00
|
|
|
delete picStream;
|
2016-03-21 22:29:57 +01:00
|
|
|
return picOk;
|
2016-03-21 07:54:14 +01:00
|
|
|
}
|
2016-07-22 16:06:36 +02:00
|
|
|
else if (picStream->read(4) != "JSON")
|
2016-03-21 07:54:14 +01:00
|
|
|
{
|
2016-04-06 04:22:30 +02:00
|
|
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",3,CTJSON";
|
2016-07-22 16:06:36 +02:00
|
|
|
picStream->close();
|
|
|
|
picStream->deleteLater();
|
2016-12-09 23:13:21 +01:00
|
|
|
delete picStream;
|
2016-03-21 22:29:57 +01:00
|
|
|
return picOk;
|
2016-03-21 07:54:14 +01:00
|
|
|
}
|
2016-07-22 16:06:36 +02:00
|
|
|
QByteArray jsonRawContent = picStream->read(jsonStreamLength);
|
2016-03-21 07:54:14 +01:00
|
|
|
jsonStr = getSnapmaticJSONString(jsonRawContent);
|
2016-03-21 21:33:22 +01:00
|
|
|
parseJsonContent(); // JSON parsing is own function
|
2016-03-21 07:54:14 +01:00
|
|
|
|
2016-07-22 16:06:36 +02:00
|
|
|
if (!picStream->isReadable())
|
2016-03-29 13:17:38 +02:00
|
|
|
{
|
2016-04-06 04:22:30 +02:00
|
|
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",4,NOTITL";
|
2016-07-22 16:06:36 +02:00
|
|
|
picStream->close();
|
|
|
|
picStream->deleteLater();
|
2016-12-09 23:13:21 +01:00
|
|
|
delete picStream;
|
2016-03-29 13:17:38 +02:00
|
|
|
return picOk;
|
|
|
|
}
|
2016-07-22 16:06:36 +02:00
|
|
|
else if (picStream->read(4) != "TITL")
|
2016-03-29 13:17:38 +02:00
|
|
|
{
|
2016-04-06 04:22:30 +02:00
|
|
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",4,CTTITL";
|
2016-07-22 16:06:36 +02:00
|
|
|
picStream->close();
|
|
|
|
picStream->deleteLater();
|
2016-12-09 23:13:21 +01:00
|
|
|
delete picStream;
|
2016-03-29 13:17:38 +02:00
|
|
|
return picOk;
|
|
|
|
}
|
2016-07-22 16:06:36 +02:00
|
|
|
QByteArray titlRawContent = picStream->read(tideStreamLength);
|
2016-03-29 13:17:38 +02:00
|
|
|
titlStr = getSnapmaticTIDEString(titlRawContent);
|
|
|
|
|
2016-07-22 16:06:36 +02:00
|
|
|
if (!picStream->isReadable())
|
2016-03-29 13:17:38 +02:00
|
|
|
{
|
2016-04-06 04:22:30 +02:00
|
|
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",5,NODESC";
|
2016-07-22 16:06:36 +02:00
|
|
|
picStream->close();
|
|
|
|
picStream->deleteLater();
|
2016-12-09 23:13:21 +01:00
|
|
|
delete picStream;
|
2016-03-29 13:17:38 +02:00
|
|
|
return picOk;
|
|
|
|
}
|
2016-07-22 16:06:36 +02:00
|
|
|
else if (picStream->read(4) != "DESC")
|
2016-03-29 13:17:38 +02:00
|
|
|
{
|
2016-04-06 04:22:30 +02:00
|
|
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",5,CTDESC";
|
2016-07-22 16:06:36 +02:00
|
|
|
picStream->close();
|
|
|
|
picStream->deleteLater();
|
2016-12-09 23:13:21 +01:00
|
|
|
delete picStream;
|
2016-03-29 13:17:38 +02:00
|
|
|
return picOk;
|
|
|
|
}
|
2016-07-22 16:06:36 +02:00
|
|
|
QByteArray descRawContent = picStream->read(tideStreamLength);
|
2016-03-29 13:17:38 +02:00
|
|
|
descStr = getSnapmaticTIDEString(descRawContent);
|
|
|
|
|
2016-04-06 04:22:30 +02:00
|
|
|
parseSnapmaticExportAndSortString();
|
|
|
|
|
2016-07-22 16:06:36 +02:00
|
|
|
picStream->close();
|
|
|
|
picStream->deleteLater();
|
|
|
|
delete picStream;
|
|
|
|
if (!writeEnabled) { rawPicContent.clear(); }
|
2016-03-21 22:29:57 +01:00
|
|
|
return picOk;
|
2016-03-21 03:10:28 +01:00
|
|
|
}
|
|
|
|
|
2016-04-06 04:22:30 +02:00
|
|
|
QString SnapmaticPicture::getSnapmaticPictureString(const QByteArray &snapmaticHeader)
|
2016-03-21 03:10:28 +01:00
|
|
|
{
|
2016-03-31 23:41:53 +02:00
|
|
|
QByteArray snapmaticBytes = snapmaticHeader.left(snapmaticUsefulLength);
|
|
|
|
QList<QByteArray> snapmaticBytesList = snapmaticBytes.split(char(0x01));
|
|
|
|
snapmaticBytes = snapmaticBytesList.at(1);
|
|
|
|
snapmaticBytesList.clear();
|
|
|
|
return StringParser::parseTitleString(snapmaticBytes, snapmaticBytes.length());
|
2016-03-21 03:10:28 +01:00
|
|
|
}
|
|
|
|
|
2016-04-06 04:22:30 +02:00
|
|
|
QString SnapmaticPicture::getSnapmaticJSONString(const QByteArray &jsonBytes)
|
2016-03-21 07:54:14 +01:00
|
|
|
{
|
|
|
|
QByteArray jsonUsefulBytes = jsonBytes;
|
2016-03-29 13:27:21 +02:00
|
|
|
jsonUsefulBytes.replace((char)0x00, "");
|
|
|
|
jsonUsefulBytes.replace((char)0x0c, "");
|
2016-04-01 02:07:00 +02:00
|
|
|
return QString::fromUtf8(jsonUsefulBytes).trimmed();
|
2016-03-21 07:54:14 +01:00
|
|
|
}
|
|
|
|
|
2016-04-06 04:22:30 +02:00
|
|
|
QString SnapmaticPicture::getSnapmaticTIDEString(const QByteArray &tideBytes)
|
2016-03-29 13:17:38 +02:00
|
|
|
{
|
|
|
|
QByteArray tideUsefulBytes = tideBytes;
|
2016-04-01 02:07:00 +02:00
|
|
|
tideUsefulBytes.remove(0,4);
|
2016-03-29 13:29:14 +02:00
|
|
|
QList<QByteArray> tideUsefulBytesList = tideUsefulBytes.split(char(0x00));
|
2016-04-01 02:07:00 +02:00
|
|
|
return QString::fromUtf8(tideUsefulBytesList.at(0)).trimmed();
|
2016-03-29 13:17:38 +02:00
|
|
|
}
|
|
|
|
|
2016-04-06 04:22:30 +02:00
|
|
|
void SnapmaticPicture::parseSnapmaticExportAndSortString()
|
|
|
|
{
|
|
|
|
QStringList pictureStrList = pictureStr.split(" - ");
|
|
|
|
if (pictureStrList.length() <= 2)
|
|
|
|
{
|
|
|
|
QString dtStr = pictureStrList.at(1);
|
|
|
|
QStringList dtStrList = dtStr.split(" ");
|
|
|
|
if (dtStrList.length() <= 2)
|
|
|
|
{
|
|
|
|
QString dayStr;
|
|
|
|
QString yearStr;
|
|
|
|
QString monthStr;
|
|
|
|
QString dateStr = dtStrList.at(0);
|
|
|
|
QString timeStr = dtStrList.at(1);
|
|
|
|
timeStr.replace(":","");
|
|
|
|
QStringList dateStrList = dateStr.split("/");
|
|
|
|
if (dateStrList.length() <= 3)
|
|
|
|
{
|
|
|
|
dayStr = dateStrList.at(1);
|
|
|
|
yearStr = dateStrList.at(2);
|
|
|
|
monthStr = dateStrList.at(0);
|
|
|
|
}
|
|
|
|
QString cmpPicTitl = titlStr;
|
2016-04-20 12:14:19 +02:00
|
|
|
cmpPicTitl.replace("\"", "''");
|
2016-04-06 04:22:30 +02:00
|
|
|
cmpPicTitl.replace(" ", "_");
|
2016-04-20 12:14:19 +02:00
|
|
|
cmpPicTitl.replace(":", "-");
|
|
|
|
cmpPicTitl.replace("\\", "");
|
|
|
|
cmpPicTitl.replace("/", "");
|
|
|
|
cmpPicTitl.replace("<", "");
|
|
|
|
cmpPicTitl.replace(">", "");
|
|
|
|
cmpPicTitl.replace("*", "");
|
|
|
|
cmpPicTitl.replace("?", "");
|
|
|
|
cmpPicTitl.replace(".", "");
|
2016-04-06 04:22:30 +02:00
|
|
|
sortStr = yearStr + monthStr + dayStr + timeStr;
|
|
|
|
picExportFileName = sortStr + "_" + cmpPicTitl + ".jpg";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 23:13:21 +01:00
|
|
|
bool SnapmaticPicture::readingPictureFromFile(const QString &fileName, bool writeEnabled_, bool cacheEnabled_)
|
2016-03-21 03:10:28 +01:00
|
|
|
{
|
|
|
|
if (fileName != "")
|
|
|
|
{
|
|
|
|
picFileName = fileName;
|
2016-12-09 23:13:21 +01:00
|
|
|
return readingPicture(writeEnabled_, cacheEnabled_);
|
2016-03-21 03:10:28 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:13:57 +02:00
|
|
|
bool SnapmaticPicture::setPicture(const QImage &picture)
|
2016-03-21 03:10:28 +01:00
|
|
|
{
|
2016-07-23 00:13:57 +02:00
|
|
|
if (writeEnabled)
|
|
|
|
{
|
|
|
|
QByteArray picByteArray;
|
|
|
|
QBuffer snapmaticStream(&rawPicContent);
|
|
|
|
snapmaticStream.open(QIODevice::ReadWrite);
|
|
|
|
if (snapmaticStream.seek(jpegStreamEditorBegin))
|
|
|
|
{
|
|
|
|
bool saveSuccess;
|
|
|
|
QByteArray picByteArray1;
|
|
|
|
QBuffer picStream1(&picByteArray1);
|
|
|
|
picStream1.open(QIODevice::WriteOnly);
|
|
|
|
saveSuccess = picture.save(&picStream1, "JPEG", 100);
|
|
|
|
picStream1.close();
|
|
|
|
|
|
|
|
if (picByteArray1.length() > jpegPicStreamLength)
|
|
|
|
{
|
|
|
|
QByteArray picByteArray2;
|
|
|
|
QBuffer picStream2(&picByteArray2);
|
|
|
|
picStream2.open(QIODevice::WriteOnly);
|
|
|
|
saveSuccess = picture.save(&picStream2, "JPEG", 90);
|
|
|
|
picStream2.close();
|
|
|
|
if (picByteArray2.length() > jpegPicStreamLength)
|
|
|
|
{
|
|
|
|
snapmaticStream.close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
picByteArray = picByteArray2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
picByteArray = picByteArray1;
|
|
|
|
}
|
2016-07-24 04:58:10 +02:00
|
|
|
Q_UNUSED(saveSuccess)
|
2016-07-23 00:13:57 +02:00
|
|
|
}
|
|
|
|
int result = snapmaticStream.write(picByteArray);
|
|
|
|
if (result != 0)
|
|
|
|
{
|
2016-12-10 03:40:42 +01:00
|
|
|
if (cacheEnabled)
|
|
|
|
{
|
|
|
|
cachePicture = picture;
|
|
|
|
}
|
2016-07-23 00:13:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SnapmaticPicture::exportPicture(const QString &fileName)
|
|
|
|
{
|
|
|
|
QFile *picFile = new QFile(fileName);
|
|
|
|
if (picFile->open(QIODevice::WriteOnly))
|
|
|
|
{
|
|
|
|
picFile->write(rawPicContent);
|
|
|
|
picFile->close();
|
|
|
|
picFile->deleteLater();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-21 03:10:28 +01:00
|
|
|
}
|
|
|
|
|
2016-04-06 04:22:30 +02:00
|
|
|
QString SnapmaticPicture::getExportPictureFileName()
|
|
|
|
{
|
|
|
|
return picExportFileName;
|
|
|
|
}
|
|
|
|
|
2016-04-03 10:17:01 +02:00
|
|
|
QString SnapmaticPicture::getPictureFileName()
|
|
|
|
{
|
|
|
|
return picFileName;
|
|
|
|
}
|
|
|
|
|
2016-04-06 04:22:30 +02:00
|
|
|
QString SnapmaticPicture::getPictureSortStr()
|
|
|
|
{
|
|
|
|
return sortStr;
|
|
|
|
}
|
|
|
|
|
2016-03-29 13:17:38 +02:00
|
|
|
QString SnapmaticPicture::getPictureDesc()
|
|
|
|
{
|
|
|
|
return descStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SnapmaticPicture::getPictureTitl()
|
|
|
|
{
|
|
|
|
return titlStr;
|
|
|
|
}
|
|
|
|
|
2016-03-21 03:10:28 +01:00
|
|
|
QString SnapmaticPicture::getPictureStr()
|
|
|
|
{
|
|
|
|
return pictureStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SnapmaticPicture::getLastStep()
|
|
|
|
{
|
|
|
|
return lastStep;
|
|
|
|
}
|
|
|
|
|
2016-03-27 09:52:23 +02:00
|
|
|
QImage SnapmaticPicture::getPicture()
|
2016-03-21 03:10:28 +01:00
|
|
|
{
|
2016-12-09 23:13:21 +01:00
|
|
|
if (cacheEnabled)
|
|
|
|
{
|
|
|
|
return cachePicture;
|
|
|
|
}
|
|
|
|
else if (writeEnabled)
|
|
|
|
{
|
|
|
|
bool returnOk;
|
|
|
|
QImage returnPicture;
|
|
|
|
|
|
|
|
QBuffer snapmaticStream(&rawPicContent);
|
|
|
|
snapmaticStream.open(QIODevice::ReadOnly);
|
|
|
|
if (snapmaticStream.seek(jpegStreamEditorBegin))
|
|
|
|
{
|
|
|
|
QByteArray jpegRawContent = snapmaticStream.read(jpegPicStreamLength);
|
|
|
|
returnOk = returnPicture.loadFromData(jpegRawContent, "JPEG");
|
|
|
|
}
|
|
|
|
snapmaticStream.close();
|
|
|
|
|
|
|
|
if (returnOk)
|
|
|
|
{
|
|
|
|
return returnPicture;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool returnOk;
|
|
|
|
QImage returnPicture;
|
|
|
|
QIODevice *picStream;
|
|
|
|
|
|
|
|
QFile *picFile = new QFile(picFileName);
|
|
|
|
if (!picFile->open(QFile::ReadOnly))
|
|
|
|
{
|
|
|
|
lastStep = "1;/1,OpenFile," + StringParser::convertDrawStringForLog(picFileName);
|
|
|
|
picFile->deleteLater();
|
|
|
|
delete picFile;
|
|
|
|
return QImage(0, 0, QImage::Format_RGB32);
|
|
|
|
}
|
|
|
|
rawPicContent = picFile->read(snapmaticFileMaxSize);
|
|
|
|
picFile->close();
|
|
|
|
delete picFile;
|
|
|
|
|
|
|
|
picStream = new QBuffer(&rawPicContent);
|
|
|
|
picStream->open(QIODevice::ReadWrite);
|
|
|
|
if (picStream->seek(jpegStreamEditorBegin))
|
|
|
|
{
|
|
|
|
QByteArray jpegRawContent = picStream->read(jpegPicStreamLength);
|
|
|
|
returnOk = returnPicture.loadFromData(jpegRawContent, "JPEG");
|
|
|
|
}
|
|
|
|
picStream->close();
|
|
|
|
delete picStream;
|
|
|
|
|
|
|
|
if (returnOk)
|
|
|
|
{
|
|
|
|
return returnPicture;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QImage(0, 0, QImage::Format_RGB32);
|
2016-03-21 03:10:28 +01:00
|
|
|
}
|
|
|
|
|
2016-03-21 22:29:57 +01:00
|
|
|
bool SnapmaticPicture::isPicOk()
|
|
|
|
{
|
|
|
|
return picOk;
|
|
|
|
}
|
|
|
|
|
2016-04-13 00:32:14 +02:00
|
|
|
void SnapmaticPicture::setPicFileName(QString picFileName_)
|
|
|
|
{
|
|
|
|
picFileName = picFileName_;
|
|
|
|
}
|
|
|
|
|
2016-12-09 23:13:21 +01:00
|
|
|
void SnapmaticPicture::clearCache()
|
|
|
|
{
|
|
|
|
cacheEnabled = false;
|
|
|
|
cachePicture = QImage(0, 0, QImage::Format_RGB32);
|
|
|
|
}
|
|
|
|
|
2016-03-21 21:33:22 +01:00
|
|
|
// JSON part
|
|
|
|
|
|
|
|
void SnapmaticPicture::parseJsonContent()
|
|
|
|
{
|
|
|
|
QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonStr.toLatin1());
|
|
|
|
QJsonObject jsonObject = jsonDocument.object();
|
|
|
|
QVariantMap jsonMap = jsonObject.toVariantMap();
|
|
|
|
|
|
|
|
if (jsonMap.contains("loc"))
|
|
|
|
{
|
|
|
|
QJsonObject locObject = jsonObject["loc"].toObject();
|
|
|
|
QVariantMap locMap = locObject.toVariantMap();
|
|
|
|
if (locMap.contains("x")) { jsonLocX = locMap["x"].toDouble(); }
|
|
|
|
if (locMap.contains("y")) { jsonLocY = locMap["y"].toDouble(); }
|
|
|
|
if (locMap.contains("z")) { jsonLocZ = locMap["z"].toDouble(); }
|
|
|
|
}
|
2016-04-23 20:15:59 +02:00
|
|
|
if (jsonMap.contains("area"))
|
|
|
|
{
|
|
|
|
jsonArea = jsonMap["area"].toString();
|
|
|
|
}
|
2016-03-21 21:46:36 +01:00
|
|
|
if (jsonMap.contains("crewid"))
|
|
|
|
{
|
|
|
|
jsonCrewID = jsonMap["crewid"].toInt();
|
|
|
|
}
|
2016-05-08 19:07:55 +02:00
|
|
|
if (jsonMap.contains("creat"))
|
|
|
|
{
|
|
|
|
QDateTime createdTimestamp;
|
2016-05-08 19:34:10 +02:00
|
|
|
jsonCreatedTimestamp = jsonMap["creat"].toUInt();
|
|
|
|
createdTimestamp.setTime_t(jsonCreatedTimestamp);
|
2016-05-08 19:07:55 +02:00
|
|
|
jsonCreatedDateTime = createdTimestamp;
|
|
|
|
}
|
2016-03-21 21:33:22 +01:00
|
|
|
if (jsonMap.contains("plyrs"))
|
|
|
|
{
|
|
|
|
jsonPlyrsList = jsonMap["plyrs"].toStringList();
|
|
|
|
}
|
2016-12-09 23:13:21 +01:00
|
|
|
if (jsonMap.contains("meme"))
|
|
|
|
{
|
|
|
|
jsonMeme = jsonMap["meme"].toBool();
|
|
|
|
}
|
|
|
|
if (jsonMap.contains("mug"))
|
|
|
|
{
|
|
|
|
jsonMug = jsonMap["mug"].toBool();
|
|
|
|
}
|
|
|
|
if (jsonMap.contains("slf"))
|
|
|
|
{
|
|
|
|
jsonSelfie = jsonMap["slf"].toBool();
|
|
|
|
}
|
|
|
|
if (jsonMap.contains("drctr"))
|
|
|
|
{
|
|
|
|
jsonDirector = jsonMap["drctr"].toBool();
|
|
|
|
}
|
|
|
|
if (jsonMap.contains("rsedtr"))
|
|
|
|
{
|
|
|
|
jsonRockstarEditor = jsonMap["rsedtr"].toBool();
|
|
|
|
}
|
2016-03-21 22:29:57 +01:00
|
|
|
|
|
|
|
jsonOk = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SnapmaticPicture::isJsonOk()
|
|
|
|
{
|
|
|
|
return jsonOk;
|
2016-03-21 21:33:22 +01:00
|
|
|
}
|
|
|
|
|
2016-04-23 20:15:59 +02:00
|
|
|
QString SnapmaticPicture::getArea()
|
|
|
|
{
|
|
|
|
return jsonArea;
|
|
|
|
}
|
|
|
|
|
2016-03-21 21:33:22 +01:00
|
|
|
QString SnapmaticPicture::getJsonStr()
|
|
|
|
{
|
|
|
|
return jsonStr;
|
|
|
|
}
|
|
|
|
|
2016-03-21 21:46:36 +01:00
|
|
|
int SnapmaticPicture::getCrewNumber()
|
|
|
|
{
|
|
|
|
return jsonCrewID;
|
|
|
|
}
|
|
|
|
|
2016-03-21 21:33:22 +01:00
|
|
|
double SnapmaticPicture::getLocationX()
|
|
|
|
{
|
|
|
|
return jsonLocX;
|
|
|
|
}
|
|
|
|
|
|
|
|
double SnapmaticPicture::getLocationY()
|
|
|
|
{
|
|
|
|
return jsonLocY;
|
|
|
|
}
|
|
|
|
|
|
|
|
double SnapmaticPicture::getLocationZ()
|
|
|
|
{
|
|
|
|
return jsonLocZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList SnapmaticPicture::getPlayers()
|
|
|
|
{
|
|
|
|
return jsonPlyrsList;
|
|
|
|
}
|
2016-05-08 19:07:55 +02:00
|
|
|
|
|
|
|
QDateTime SnapmaticPicture::getCreatedDateTime()
|
|
|
|
{
|
|
|
|
return jsonCreatedDateTime;
|
|
|
|
}
|
2016-10-27 08:59:08 +02:00
|
|
|
|
|
|
|
// VISIBILITY
|
|
|
|
|
|
|
|
bool SnapmaticPicture::isHidden()
|
|
|
|
{
|
|
|
|
if (picFileName.right(7) == ".hidden")
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SnapmaticPicture::setPictureHidden()
|
|
|
|
{
|
|
|
|
if (!isHidden())
|
|
|
|
{
|
|
|
|
QString newPicFileName = QString(picFileName + ".hidden");
|
|
|
|
if (QFile::rename(picFileName, newPicFileName))
|
|
|
|
{
|
|
|
|
picFileName = newPicFileName;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SnapmaticPicture::setPictureVisible()
|
|
|
|
{
|
|
|
|
if (isHidden())
|
|
|
|
{
|
|
|
|
QString newPicFileName = QString(picFileName).remove(picFileName.length() - 7, 7);
|
|
|
|
if (QFile::rename(picFileName, newPicFileName))
|
|
|
|
{
|
|
|
|
picFileName = newPicFileName;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|