SavegameData, SnapmaticPicture and StringParser improved

This commit is contained in:
Rafael 2016-04-06 04:22:30 +02:00
parent cb3647df02
commit a27e699cac
7 changed files with 100 additions and 59 deletions

View File

@ -22,7 +22,7 @@
#include <QDebug>
#include <QFile>
SavegameData::SavegameData(QString fileName, QObject *parent) : QObject(parent), savegameFileName(fileName)
SavegameData::SavegameData(const QString &fileName, QObject *parent) : QObject(parent), savegameFileName(fileName)
{
// PARSE INT INIT - DO NOT CHANGE THIS VALUES
savegameHeaderLength = 260;
@ -41,7 +41,7 @@ bool SavegameData::readingSavegame()
QFile *saveFile = new QFile(savegameFileName);
if (!saveFile->open(QFile::ReadOnly))
{
lastStep = "1;/1,OpenFile," + convertDrawStringForLog(savegameFileName);
lastStep = "1;/1,OpenFile," + StringParser::convertDrawStringForLog(savegameFileName);
saveFile->deleteLater();
delete saveFile;
return false;
@ -50,7 +50,7 @@ bool SavegameData::readingSavegame()
// Reading Savegame Header
if (!saveFile->isReadable())
{
lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(savegameFileName) + ",1,NOHEADER";
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(savegameFileName) + ",1,NOHEADER";
saveFile->close();
saveFile->deleteLater();
delete saveFile;
@ -71,7 +71,7 @@ bool SavegameData::readingSavegame()
return savegameOk;
}
QString SavegameData::getSavegameDataString(QByteArray savegameHeader)
QString SavegameData::getSavegameDataString(const QByteArray &savegameHeader)
{
QByteArray savegameBytes = savegameHeader.left(savegameHeaderLength);
QList<QByteArray> savegameBytesList = savegameBytes.split(char(0x01));
@ -80,7 +80,7 @@ QString SavegameData::getSavegameDataString(QByteArray savegameHeader)
return StringParser::parseTitleString(savegameBytes, savegameBytes.length());
}
bool SavegameData::readingSavegameFromFile(QString fileName)
bool SavegameData::readingSavegameFromFile(const QString &fileName)
{
if (fileName != "")
{
@ -93,16 +93,6 @@ bool SavegameData::readingSavegameFromFile(QString fileName)
}
}
QString SavegameData::convertDrawStringForLog(QString inputStr)
{
return inputStr.replace("&","&u;").replace(",","&c;");
}
QString SavegameData::convertLogStringForDraw(QString inputStr)
{
return inputStr.replace("&c;",",").replace("&u;","&");
}
bool SavegameData::isSavegameOk()
{
return savegameOk;

View File

@ -25,8 +25,8 @@ class SavegameData : public QObject
{
Q_OBJECT
public:
explicit SavegameData(QString fileName = "", QObject *parent = 0);
bool readingSavegameFromFile(QString fileName);
explicit SavegameData(const QString &fileName = "", QObject *parent = 0);
bool readingSavegameFromFile(const QString &fileName);
bool readingSavegame();
bool isSavegameOk();
QString getLastStep();
@ -34,9 +34,7 @@ public:
QString getSavegameFileName();
private:
QString getSavegameDataString(QByteArray savegameHeader);
QString convertDrawStringForLog(QString inputStr);
QString convertLogStringForDraw(QString inputStr);
QString getSavegameDataString(const QByteArray &savegameHeader);
QString savegameFileName;
QString savegameStr;
QString lastStep;

View File

@ -20,13 +20,14 @@
#include "StringParser.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QStringList>
#include <QVariantMap>
#include <QJsonArray>
#include <QString>
#include <QImage>
#include <QFile>
SnapmaticPicture::SnapmaticPicture(QString fileName, QObject *parent) : QObject(parent), picFileName(fileName)
SnapmaticPicture::SnapmaticPicture(const QString &fileName, QObject *parent) : QObject(parent), picFileName(fileName)
{
// PARSE INT INIT - DO NOT CHANGE THIS VALUES
snapmaticHeaderLength = 278;
@ -39,8 +40,12 @@ SnapmaticPicture::SnapmaticPicture(QString fileName, QObject *parent) : QObject(
// INIT PIC
cachePicture = QImage(0, 0, QImage::Format_RGB32);
picExportFileName = "";
pictureStr = "";
lastStep = "";
sortStr = "";
titlStr = "";
descStr = "";
picOk = 0;
// INIT JSON
@ -61,7 +66,7 @@ bool SnapmaticPicture::readingPicture()
QFile *picFile = new QFile(picFileName);
if (!picFile->open(QFile::ReadOnly))
{
lastStep = "1;/1,OpenFile," + convertDrawStringForLog(picFileName);
lastStep = "1;/1,OpenFile," + StringParser::convertDrawStringForLog(picFileName);
picFile->deleteLater();
delete picFile;
return false;
@ -70,7 +75,7 @@ bool SnapmaticPicture::readingPicture()
// Reading Snapmatic Header
if (!picFile->isReadable())
{
lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",1,NOHEADER";
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",1,NOHEADER";
picFile->close();
picFile->deleteLater();
delete picFile;
@ -82,7 +87,7 @@ bool SnapmaticPicture::readingPicture()
// Reading JPEG Header Line
if (!picFile->isReadable())
{
lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",2,NOHEADER";
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",2,NOHEADER";
picFile->close();
picFile->deleteLater();
delete picFile;
@ -94,7 +99,7 @@ bool SnapmaticPicture::readingPicture()
jpegHeaderLine.remove(0, jpegHeaderLineDifStr);
if (jpegHeaderLine.left(4) != "JPEG")
{
lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",2,NOJPEG";
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",2,NOJPEG";
picFile->close();
picFile->deleteLater();
delete picFile;
@ -104,7 +109,7 @@ bool SnapmaticPicture::readingPicture()
// Read JPEG Stream
if (!picFile->isReadable())
{
lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",2,NOPIC";
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",2,NOPIC";
picFile->close();
picFile->deleteLater();
delete picFile;
@ -116,7 +121,7 @@ bool SnapmaticPicture::readingPicture()
// Read JSON Stream
if (!picFile->isReadable())
{
lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",3,NOJSON";
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",3,NOJSON";
picFile->close();
picFile->deleteLater();
delete picFile;
@ -124,7 +129,7 @@ bool SnapmaticPicture::readingPicture()
}
else if (picFile->read(4) != "JSON")
{
lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",3,CTJSON";
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",3,CTJSON";
picFile->close();
picFile->deleteLater();
delete picFile;
@ -136,7 +141,7 @@ bool SnapmaticPicture::readingPicture()
if (!picFile->isReadable())
{
lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",4,NOTITL";
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",4,NOTITL";
picFile->close();
picFile->deleteLater();
delete picFile;
@ -144,7 +149,7 @@ bool SnapmaticPicture::readingPicture()
}
else if (picFile->read(4) != "TITL")
{
lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",4,CTTITL";
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",4,CTTITL";
picFile->close();
picFile->deleteLater();
delete picFile;
@ -155,7 +160,7 @@ bool SnapmaticPicture::readingPicture()
if (!picFile->isReadable())
{
lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",5,NODESC";
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",5,NODESC";
picFile->close();
picFile->deleteLater();
delete picFile;
@ -163,7 +168,7 @@ bool SnapmaticPicture::readingPicture()
}
else if (picFile->read(4) != "DESC")
{
lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",5,CTDESC";
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",5,CTDESC";
picFile->close();
picFile->deleteLater();
delete picFile;
@ -172,13 +177,15 @@ bool SnapmaticPicture::readingPicture()
QByteArray descRawContent = picFile->read(tideStreamLength);
descStr = getSnapmaticTIDEString(descRawContent);
parseSnapmaticExportAndSortString();
picFile->close();
picFile->deleteLater();
delete picFile;
return picOk;
}
QString SnapmaticPicture::getSnapmaticPictureString(QByteArray snapmaticHeader)
QString SnapmaticPicture::getSnapmaticPictureString(const QByteArray &snapmaticHeader)
{
QByteArray snapmaticBytes = snapmaticHeader.left(snapmaticUsefulLength);
QList<QByteArray> snapmaticBytesList = snapmaticBytes.split(char(0x01));
@ -187,7 +194,7 @@ QString SnapmaticPicture::getSnapmaticPictureString(QByteArray snapmaticHeader)
return StringParser::parseTitleString(snapmaticBytes, snapmaticBytes.length());
}
QString SnapmaticPicture::getSnapmaticJSONString(QByteArray jsonBytes)
QString SnapmaticPicture::getSnapmaticJSONString(const QByteArray &jsonBytes)
{
QByteArray jsonUsefulBytes = jsonBytes;
jsonUsefulBytes.replace((char)0x00, "");
@ -195,7 +202,7 @@ QString SnapmaticPicture::getSnapmaticJSONString(QByteArray jsonBytes)
return QString::fromUtf8(jsonUsefulBytes).trimmed();
}
QString SnapmaticPicture::getSnapmaticTIDEString(QByteArray tideBytes)
QString SnapmaticPicture::getSnapmaticTIDEString(const QByteArray &tideBytes)
{
QByteArray tideUsefulBytes = tideBytes;
tideUsefulBytes.remove(0,4);
@ -203,7 +210,37 @@ QString SnapmaticPicture::getSnapmaticTIDEString(QByteArray tideBytes)
return QString::fromUtf8(tideUsefulBytesList.at(0)).trimmed();
}
bool SnapmaticPicture::readingPictureFromFile(QString fileName)
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;
cmpPicTitl.replace(" ", "_");
sortStr = yearStr + monthStr + dayStr + timeStr;
picExportFileName = sortStr + "_" + cmpPicTitl + ".jpg";
}
}
}
bool SnapmaticPicture::readingPictureFromFile(const QString &fileName)
{
if (fileName != "")
{
@ -216,16 +253,26 @@ bool SnapmaticPicture::readingPictureFromFile(QString fileName)
}
}
void SnapmaticPicture::setPicture(QImage picture)
void SnapmaticPicture::setPicture(const QImage &picture)
{
cachePicture = picture;
}
QString SnapmaticPicture::getExportPictureFileName()
{
return picExportFileName;
}
QString SnapmaticPicture::getPictureFileName()
{
return picFileName;
}
QString SnapmaticPicture::getPictureSortStr()
{
return sortStr;
}
QString SnapmaticPicture::getPictureDesc()
{
return descStr;
@ -251,16 +298,6 @@ QImage SnapmaticPicture::getPicture()
return cachePicture;
}
QString SnapmaticPicture::convertDrawStringForLog(QString inputStr)
{
return inputStr.replace("&","&u;").replace(",","&c;");
}
QString SnapmaticPicture::convertLogStringForDraw(QString inputStr)
{
return inputStr.replace("&c;",",").replace("&u;","&");
}
bool SnapmaticPicture::isPicOk()
{
return picOk;

View File

@ -29,17 +29,19 @@ class SnapmaticPicture : public QObject
{
Q_OBJECT
public:
explicit SnapmaticPicture(QString fileName = "", QObject *parent = 0);
bool readingPictureFromFile(QString fileName);
explicit SnapmaticPicture(const QString &fileName = "", QObject *parent = 0);
bool readingPictureFromFile(const QString &fileName);
bool readingPicture();
void setPicture(QImage picture);
void setPicture(const QImage &picture);
bool isPicOk();
QImage getPicture();
QString getLastStep();
QString getPictureStr();
QString getPictureTitl();
QString getPictureDesc();
QString getPictureSortStr();
QString getPictureFileName();
QString getExportPictureFileName();
// JSON
bool isJsonOk();
@ -51,15 +53,16 @@ public:
QStringList getPlayers();
private:
QString getSnapmaticPictureString(QByteArray snapmaticHeader);
QString getSnapmaticJSONString(QByteArray jsonBytes);
QString getSnapmaticTIDEString(QByteArray tideBytes);
QString convertDrawStringForLog(QString inputStr);
QString convertLogStringForDraw(QString inputStr);
QString getSnapmaticPictureString(const QByteArray &snapmaticHeader);
QString getSnapmaticJSONString(const QByteArray &jsonBytes);
QString getSnapmaticTIDEString(const QByteArray &tideBytes);
void parseSnapmaticExportAndSortString();
QImage cachePicture;
QString picExportFileName;
QString picFileName;
QString pictureStr;
QString lastStep;
QString sortStr;
QString titlStr;
QString descStr;
bool picOk;

View File

@ -16,21 +16,33 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "StringParser.h"
#include <QTextCodec>
#include <QByteArray>
#include <QString>
#include <QList>
#include "StringParser.h"
StringParser::StringParser()
{
}
QString StringParser::parseTitleString(QByteArray commitBytes, int maxLength)
QString StringParser::parseTitleString(const QByteArray &commitBytes, int maxLength)
{
Q_UNUSED(maxLength)
QString retStr = QTextCodec::codecForName("UTF-16LE")->toUnicode(commitBytes).trimmed();
retStr.remove(QChar((char)0x00));
return retStr;
}
QString StringParser::convertDrawStringForLog(const QString &inputStr)
{
QString outputStr = inputStr;
return outputStr.replace("&","&u;").replace(",","&c;");
}
QString StringParser::convertLogStringForDraw(const QString &inputStr)
{
QString outputStr = inputStr;
return outputStr.replace("&c;",",").replace("&u;","&");
}

View File

@ -26,7 +26,9 @@ class StringParser
{
public:
StringParser();
static QString parseTitleString(QByteArray commitBytes, int maxLength);
static QString parseTitleString(const QByteArray &commitBytes, int maxLength);
static QString convertDrawStringForLog(const QString &inputStr);
static QString convertLogStringForDraw(const QString &inputStr);
};
#endif // STRINGPARSER_H

View File

@ -43,7 +43,6 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D
ui->menuProfile->setEnabled(false);
defaultWindowTitle = this->windowTitle();
this->setWindowIcon(QIcon(":/img/5sync.png"));
this->setWindowTitle(defaultWindowTitle.arg(tr("Select profile")));
// init settings