Open Source Snapmatic picture and Savegame viewer/editor for GTA V https://gta5view.syping.de/

SnapmaticPicture.h 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*****************************************************************************
  2. * gta5spv Grand Theft Auto Snapmatic Picture Viewer
  3. * Copyright (C) 2016-2018 Syping
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *****************************************************************************/
  18. #ifndef SNAPMATICPICTURE_H
  19. #define SNAPMATICPICTURE_H
  20. #include <QStringList>
  21. #include <QDateTime>
  22. #include <QObject>
  23. #include <QString>
  24. #include <QImage>
  25. #include <QFile>
  26. enum class SnapmaticFormat : int { Auto_Format = 0, PGTA_Format = 1, JPEG_Format = 2, G5E_Format = 3 };
  27. struct SnapmaticProperties {
  28. struct SnapmaticLocation {
  29. QString area;
  30. double x;
  31. double y;
  32. double z;
  33. };
  34. int uid;
  35. int crewID;
  36. int streetID;
  37. QStringList playersList;
  38. uint createdTimestamp;
  39. QDateTime createdDateTime;
  40. bool isMeme;
  41. bool isMug;
  42. bool isSelfie;
  43. bool isFromDirector;
  44. bool isFromRSEditor;
  45. SnapmaticLocation location;
  46. };
  47. class SnapmaticPicture : public QObject
  48. {
  49. Q_OBJECT
  50. public:
  51. explicit SnapmaticPicture(const QString &fileName = "", QObject *parent = 0);
  52. ~SnapmaticPicture();
  53. void reset();
  54. bool preloadFile();
  55. bool readingPictureFromFile(const QString &fileName, bool writeEnabled = true, bool cacheEnabled = false, bool fastLoad = true, bool lowRamMode = false);
  56. bool readingPicture(bool writeEnabled = true, bool cacheEnabled = false, bool fastLoad = true, bool lowRamMode = false);
  57. bool isPicOk(); // Please use isPictureOk instead
  58. void clearCache();
  59. QImage getImage(bool fastLoad = false);
  60. QByteArray getPictureStream();
  61. QString getLastStep(bool readable = true);
  62. QString getPictureStr();
  63. QString getPictureHead();
  64. QString getPictureTitl();
  65. QString getPictureDesc();
  66. QString getPictureSortStr();
  67. QString getPictureFileName();
  68. QString getPictureFilePath();
  69. QString getExportPictureFileName();
  70. QString getOriginalPictureFileName();
  71. QString getOriginalPictureFilePath();
  72. int getContentMaxLength();
  73. bool setImage(const QImage &picture);
  74. bool setPictureTitl(const QString &newTitle); // Please use setPictureTitle instead
  75. bool setPictureStream(const QByteArray &streamArray);
  76. void updateStrings();
  77. void emitUpdate();
  78. void emitCustomSignal(const QString &signal);
  79. // FILE MANAGEMENT
  80. bool exportPicture(const QString &fileName, SnapmaticFormat format = SnapmaticFormat::Auto_Format);
  81. void setPicFileName(const QString &picFileName); // Please use setPictureFileName instead
  82. void setPicFilePath(const QString &picFilePath); // Please use setPictureFilePath instead
  83. bool deletePicFile(); // Please use deletePictureFile instead
  84. // JSON
  85. bool isJsonOk();
  86. QString getJsonStr(); // Please use getPictureJson instead
  87. SnapmaticProperties getSnapmaticProperties();
  88. bool setSnapmaticProperties(SnapmaticProperties properties);
  89. bool setJsonStr(const QString &jsonStr, bool updateProperties = false); // Please use setPictureJson instead
  90. // VISIBILITY
  91. bool isHidden(); // Please use isPictureHidden instead
  92. bool isVisible(); // Please use isPictureVisible instead
  93. bool setPictureHidden();
  94. bool setPictureVisible();
  95. // ALTERNATIVES (MORE DEVELOPER FRIENDLY FUNCTION CALLS)
  96. QString getJsonString() { return getJsonStr(); } // Please use getPictureJson instead
  97. QString getPictureJson() { return getJsonStr(); }
  98. QString getPictureTitle() { return getPictureTitl(); }
  99. QString getPictureString() { return getPictureStr(); }
  100. QString getPictureDescription() { return getPictureDesc(); }
  101. bool setJsonString(const QString &jsonString, bool updateProperties = false) { return setJsonStr(jsonString, updateProperties); } // Please use setPictureJson instead
  102. bool setPictureJson(const QString &json, bool updateProperties = false) { return setJsonStr(json, updateProperties); }
  103. bool setPictureTitle(const QString &title) { return setPictureTitl(title); }
  104. void setPictureFileName(const QString &fileName) { return setPicFileName(fileName); }
  105. void setPictureFilePath(const QString &filePath) { return setPicFilePath(filePath); }
  106. bool deletePictureFile() { return deletePicFile(); }
  107. bool isPictureOk() { return isPicOk(); }
  108. bool isPictureHidden() { return isHidden(); }
  109. bool isPictureVisible() { return isVisible(); }
  110. bool setHidden() { return setPictureHidden(); } // Please use setPictureHidden instead
  111. bool setVisible() { return setPictureVisible(); } // Please use setPictureVisible instead
  112. // PREDEFINED PROPERTIES
  113. QSize getSnapmaticResolution();
  114. // SNAPMATIC DEFAULTS
  115. bool isSnapmaticDefaultsEnforced();
  116. void setSnapmaticDefaultsEnforced(bool enforced);
  117. // SNAPMATIC FORMAT
  118. SnapmaticFormat getSnapmaticFormat();
  119. void setSnapmaticFormat(SnapmaticFormat format);
  120. bool isFormatSwitched();
  121. // VERIFY CONTENT
  122. static bool verifyTitle(const QString &title);
  123. // STRING OPERATIONS
  124. static QString parseTitleString(const QByteArray &commitBytes, int maxLength);
  125. static QString convertDrawStringForLog(const QString &inputStr);
  126. static QString convertLogStringForDraw(const QString &inputStr);
  127. private:
  128. QString getSnapmaticHeaderString(const QByteArray &snapmaticHeader);
  129. QString getSnapmaticJSONString(const QByteArray &jsonBytes);
  130. QString getSnapmaticTIDEString(const QByteArray &tideBytes);
  131. QImage cachePicture;
  132. QString picExportFileName;
  133. QString picFileName;
  134. QString picFilePath;
  135. QString pictureHead;
  136. QString pictureStr;
  137. QString lastStep;
  138. QString sortStr;
  139. QString titlStr;
  140. QString descStr;
  141. bool picOk;
  142. bool lowRamMode;
  143. bool writeEnabled;
  144. bool cacheEnabled;
  145. bool isLoadedInRAM;
  146. bool isCustomFormat;
  147. bool isFormatSwitch;
  148. bool isModernFormat;
  149. bool careSnapDefault;
  150. int jpegRawContentSize;
  151. int jpegRawContentSizeE;
  152. // PICTURE STREAM
  153. QByteArray rawPicContent;
  154. // JSON
  155. void parseJsonContent();
  156. bool jsonOk;
  157. QString jsonStr;
  158. SnapmaticProperties localProperties;
  159. // VERIFY CONTENT
  160. static bool verifyTitleChar(const QChar &titleChar);
  161. signals:
  162. void customSignal(QString signal);
  163. void preloaded();
  164. void updated();
  165. void loaded();
  166. public slots:
  167. };
  168. #endif // SNAPMATICPICTURE_H