latest changes from gta5sync

This commit is contained in:
Syping 2017-10-09 08:35:48 +02:00
parent 69777a0263
commit 0069bb0b95
128 changed files with 20971 additions and 15661 deletions

27
.gitattributes vendored Normal file
View File

@ -0,0 +1,27 @@
# Auto detect text files and perform LF normalization
* text=auto eol=lf
# Development files
*.cpp text eol=lf
*.h text eol=lf
*.ui text eol=lf
*.qrc text eol=lf
# Development resources
*.ini text eol=lf
# Linux development files
*.desktop text eol=lf
# Windows development files
*.rc text eol=crlf
*.exe.manifest text eol=crlf
# Binary files
*.png binary
*.jpg binary
*.qm binary
*.ico binary
*.icns binary
*.xcf binary
*.g5e binary

View File

@ -4,7 +4,7 @@ sudo: required
language: cpp language: cpp
env: env:
- PACKAGE_VERSION="1.4.0" - PACKAGE_VERSION="1.5.0"
before_install: before_install:
- test -n $CC && unset CC - test -n $CC && unset CC
@ -12,27 +12,42 @@ before_install:
install: install:
- sudo apt-get update -qq - sudo apt-get update -qq
- sudo apt-get install -qq checkinstall dpkg-dev g++ gcc qtbase5-dev qt5-qmake - sudo apt-get install -qq checkinstall dpkg-dev g++ gcc qtbase5-dev qt5-qmake qttranslations5-l10n libqt4-dev
before_script: before_script:
- export INSTALL_ROOT=/usr
- if [ `git name-rev --tags --name-only $(git rev-parse HEAD)` == "undefined" ]; then export APPLICATION_VERSION="$PACKAGE_VERSION.$TRAVIS_BUILD_NUMBER"; else export APPLICATION_VERSION=`git name-rev --tags --name-only $(git rev-parse HEAD)`; fi - if [ `git name-rev --tags --name-only $(git rev-parse HEAD)` == "undefined" ]; then export APPLICATION_VERSION="$PACKAGE_VERSION.$TRAVIS_BUILD_NUMBER"; else export APPLICATION_VERSION=`git name-rev --tags --name-only $(git rev-parse HEAD)`; fi
- echo "gta5view build version is $APPLICATION_VERSION" - echo "gta5view build version is $APPLICATION_VERSION"
- mkdir build - mkdir build
- mkdir package - mkdir package
- chmod -x res/gta5sync_*.qm res/gta5view.desktop res/gta5view.png
- cd build - cd build
- mkdir qt4
- cd qt4
- echo "Grand Theft Auto V Snapmatic and Savegame viewer" > ./description-pak - echo "Grand Theft Auto V Snapmatic and Savegame viewer" > ./description-pak
- cd ..
- mkdir qt5
- cd qt5
- echo "Grand Theft Auto V Snapmatic and Savegame viewer" > ./description-pak
- cd ..
script: script:
- qmake -qt=5 "DEFINES+=GTA5SYNC_BUILDTYPE=\\\\\\\"Release\\\\\\\"" "DEFINES+=GTA5SYNC_DAILYB=\\\\\\\"$APPLICATION_VERSION\\\\\\\"" ../gta5view.pro - cd qt5
- qmake -qt=5 GTA5SYNC_PREFIX=/usr QMAKE_CXXFLAGS+=-std=c++11 DEFINES+=GTA5SYNC_BUILDTYPE_DEV "DEFINES+=GTA5SYNC_APPVER=\\\\\\\"$APPLICATION_VERSION\\\\\\\"" DEFINES+=GTA5SYNC_QCONF ../../gta5view.pro
- make -j 4 - make -j 4
- sudo checkinstall -D --default --nodoc --pkgname=gta5view --pkgversion=$APPLICATION_VERSION --pkgrelease=travis1 --pkggroup=utility --maintainer="Syping on Travis \<travisci@syping.de\>" --requires=libqt5core5a,libqt5gui5,libqt5network5,libqt5widgets5 --pakdir=../package - sudo checkinstall -D --default --nodoc --install=no --pkgname=gta5view --pkgversion=$APPLICATION_VERSION --pkgrelease=travis1 --pkggroup=utility --maintainer="Syping on Travis \<travisci@syping.de\>" --requires=libqt5core5a,libqt5gui5,libqt5network5,libqt5widgets5,qttranslations5-l10n --conflicts=gta5view-qt4 --replaces=gta5view-qt4 --pakdir=../../package
- cd ..
- cd qt4
- qmake -qt=4 GTA5SYNC_PREFIX=/usr QMAKE_CXXFLAGS+=-std=c++11 DEFINES+=GTA5SYNC_BUILDTYPE_DEV "DEFINES+=GTA5SYNC_APPVER=\\\\\\\"$APPLICATION_VERSION\\\\\\\"" DEFINES+=GTA5SYNC_QCONF ../../gta5view.pro
- make -j 4
- sudo checkinstall -D --default --nodoc --install=no --pkgname=gta5view-qt4 --pkgversion=$APPLICATION_VERSION --pkgrelease=travis1 --pkggroup=utility --maintainer="Syping on Travis \<travisci@syping.de\>" --requires=libqtcore4,libqtgui4,libqt4-network,qtcore4-l10n --conflicts=gta5view --replaces=gta5view --pakdir=../../package
- cd ..
deploy: deploy:
provider: releases provider: releases
api_key: api_key:
secure: "o7VneEz1aHfdVwZvOZLfopf6uJWNrFsZaBvunTmXFzpmNFhlNS1qwqgMUkIA2yBRbZ3wIzVs4vfwIHv7W9yE/PqK+AYL+R8+AwKGrwlgT4HqJNuk6VM/LNJ6GwT/qkQuaoOVw29bUjmzzgIRdHmw53SlJv6Hh1VE8HphlTT//aex6nCfcFhUZ0BETdZDWz5FSHwL3NalUoqfKfQrJeky5RXzCyCANQC2tKt0bV46GaWIgWrDo2KCTNqPtRWWf5GDmnkXE5IYRMQ3mXvO9iYh0v5Y2jo4PiXGUiFUU6Z3aAWFAiPdGclrBO697cf3lCTzDMhuCETR153qFYsLShUlFf61ITAmCeHAWETjZDri0lmPONo3GoNB6alGfYEA51qw14kXakrTpICtTJj7gw/gtUYOabW6hrzmieNzMBIy62RikDPjyakFnuwW2qNHRlD65e0jYv+6nCpb6E+OV16Ysh1zhV2vTfpfzVmSuyu2J+ELqXD3OZCXRSPpDIih9UQ8335p8FBji6jHORcgym/TRgdgRmENibh8tLzWp+UjpWHuWfcpvZgOskjfwU0iDMCayMJ7tDpOhXHcAhDRnd6XRIiOJ5YZCzflj2nEwmt3YUd7DwXS/AU+WHOmcNQBjXBxF/FJa35XXcy3HKJM5TTKqtph3medo30us5yXHeG6NNg=" secure: "o7VneEz1aHfdVwZvOZLfopf6uJWNrFsZaBvunTmXFzpmNFhlNS1qwqgMUkIA2yBRbZ3wIzVs4vfwIHv7W9yE/PqK+AYL+R8+AwKGrwlgT4HqJNuk6VM/LNJ6GwT/qkQuaoOVw29bUjmzzgIRdHmw53SlJv6Hh1VE8HphlTT//aex6nCfcFhUZ0BETdZDWz5FSHwL3NalUoqfKfQrJeky5RXzCyCANQC2tKt0bV46GaWIgWrDo2KCTNqPtRWWf5GDmnkXE5IYRMQ3mXvO9iYh0v5Y2jo4PiXGUiFUU6Z3aAWFAiPdGclrBO697cf3lCTzDMhuCETR153qFYsLShUlFf61ITAmCeHAWETjZDri0lmPONo3GoNB6alGfYEA51qw14kXakrTpICtTJj7gw/gtUYOabW6hrzmieNzMBIy62RikDPjyakFnuwW2qNHRlD65e0jYv+6nCpb6E+OV16Ysh1zhV2vTfpfzVmSuyu2J+ELqXD3OZCXRSPpDIih9UQ8335p8FBji6jHORcgym/TRgdgRmENibh8tLzWp+UjpWHuWfcpvZgOskjfwU0iDMCayMJ7tDpOhXHcAhDRnd6XRIiOJ5YZCzflj2nEwmt3YUd7DwXS/AU+WHOmcNQBjXBxF/FJa35XXcy3HKJM5TTKqtph3medo30us5yXHeG6NNg="
file: "../package/gta5view_$APPLICATION_VERSION-travis1_amd64.deb" file_glob: true
file: "../package/gta5view*.deb"
skip_cleanup: true skip_cleanup: true
on: on:
tags: true tags: true

View File

@ -1,121 +1,125 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include <QStringBuilder> #include <QStringBuilder>
#include "AboutDialog.h" #include "AboutDialog.h"
#include "ui_AboutDialog.h" #include "ui_AboutDialog.h"
#include "AppEnv.h" #include "AppEnv.h"
#include "config.h" #include "config.h"
AboutDialog::AboutDialog(QWidget *parent) : AboutDialog::AboutDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::AboutDialog) ui(new Ui::AboutDialog)
{ {
// Set Window Flags // Set Window Flags
setWindowFlags(windowFlags()^Qt::WindowContextHelpButtonHint); setWindowFlags(windowFlags()^Qt::WindowContextHelpButtonHint);
// Build Strings // Build Strings
QString appVersion = qApp->applicationVersion(); QString appVersion = qApp->applicationVersion();
QString buildType = GTA5SYNC_BUILDTYPE; QString buildType = tr(GTA5SYNC_BUILDTYPE);
buildType.replace("_", " "); buildType.replace("_", " ");
QString projectBuild = GTA5SYNC_BUILDDATETIME; QString projectBuild = GTA5SYNC_BUILDDATETIME;
QString buildStr = GTA5SYNC_BUILDSTRING; QString buildStr = GTA5SYNC_BUILDSTRING;
// Additional Content // Translator Comments
QString usingStr = tr("Using %1 %2", "Exp. Using libmyfuck"); //: Using specific library, example Using libmyfuck
QString translatedByStr = tr("Translated by %1", "Exp. Translated by Syping"); QString usingStr = tr("Using %1 %2");
QString translatedByVal = tr("NAME_OF_TRANSLATOR", "Your Name (The person behind your screen looking at this text!)"); //: Translated by translator, example Translated by Syping
QString translatorProfile = tr("TRANSLATOR_PROFILE", "mailto: http:// https:// Exp. https://github.com/Syping/"); QString translatedByStr = tr("Translated by %1");
QString additionalContent = ""; //: Enter your name there
if (translatedByVal != "NAME_OF_TRANSLATOR") QString translatedByVal = tr("NAME_OF_TRANSLATOR");
{ //: Enter your proilfe there, example a GitHub profile, E-Mail with "mailto: afucker@sumfuck.com" or a webpage
if (translatorProfile != "TRANSLATOR_PROFILE") QString translatorProfile = tr("TRANSLATOR_PROFILE");
{ QString additionalContent = "";
additionalContent.append(translatedByStr.arg(QString("<a href=\"%1\">%2</a>").arg(translatorProfile, translatedByVal))); if (translatedByVal != "NAME_OF_TRANSLATOR")
} {
else if (translatorProfile != "TRANSLATOR_PROFILE")
{ {
additionalContent.append(translatedByStr.arg(translatedByVal)); additionalContent += translatedByStr.arg(QString("<a href=\"%1\">%2</a>").arg(translatorProfile, translatedByVal));
} }
} else
#ifdef WITH_LIBJPEGTURBO // DONT USE IT FOR NOW {
bool additionalContentClip = false; additionalContent += translatedByStr.arg(translatedByVal);
if (!additionalContent.isEmpty()) }
{ }
additionalContentClip = true; #ifdef WITH_LIBJPEGTURBO // DONT USE IT FOR NOW
additionalContent.append(" ("); bool additionalContentClip = false;
} if (!additionalContent.isEmpty())
additionalContent.append(usingStr.arg("libjpegturbo", WITH_LIBJPEGTURBO)); {
if (additionalContentClip) additionalContentClip = true;
{ additionalContent += " (";
additionalContent.append(")"); }
} additionalContent += usingStr.arg("libjpegturbo", WITH_LIBJPEGTURBO);
#else if (additionalContentClip)
Q_UNUSED(usingStr) {
#endif additionalContent += ")";
}
// Project Description #else
#ifdef GTA5SYNC_ENABLED Q_UNUSED(usingStr)
QString projectDes = tr("A project for viewing and sync Grand Theft Auto V Snapmatic<br/>\nPictures and Savegames"); #endif
#else
QString projectDes = tr("A project for viewing Grand Theft Auto V Snapmatic<br/>\nPictures and Savegames"); // Project Description
#endif #ifdef GTA5SYNC_ENABLED
QString projectDes = tr("A project for viewing and sync Grand Theft Auto V Snapmatic<br/>\nPictures and Savegames");
// Copyright Description #else
QString copyrightDes1 = tr("Copyright &copy; <a href=\"%1\">%2</a> %3"); QString projectDes = tr("A project for viewing Grand Theft Auto V Snapmatic<br/>\nPictures and Savegames");
copyrightDes1 = copyrightDes1.arg(GTA5SYNC_APPVENDORLINK, GTA5SYNC_APPVENDOR, GTA5SYNC_COPYRIGHT); #endif
QString copyrightDes2 = tr("%1 is licensed under <a href=\"https://www.gnu.org/licenses/gpl-3.0.html#content\">GNU GPLv3</a>");
copyrightDes2 = copyrightDes2.arg(GTA5SYNC_APPSTR); // Copyright Description
QString copyrightDesA; QString copyrightDes1 = tr("Copyright &copy; <a href=\"%1\">%2</a> %3");
if (!additionalContent.isEmpty()) copyrightDes1 = copyrightDes1.arg(GTA5SYNC_APPVENDORLINK, GTA5SYNC_APPVENDOR, GTA5SYNC_COPYRIGHT);
{ QString copyrightDes2 = tr("%1 is licensed under <a href=\"https://www.gnu.org/licenses/gpl-3.0.html#content\">GNU GPLv3</a>");
copyrightDesA = copyrightDes1 % "<br/>" % additionalContent % "<br/>" % copyrightDes2; copyrightDes2 = copyrightDes2.arg(GTA5SYNC_APPSTR);
} QString copyrightDesA;
else if (!additionalContent.isEmpty())
{ {
copyrightDesA = copyrightDes1 % "<br/>" % copyrightDes2; copyrightDesA = copyrightDes1 % "<br/>" % additionalContent % "<br/>" % copyrightDes2;
} }
else
// Setup User Interface {
ui->setupUi(this); copyrightDesA = copyrightDes1 % "<br/>" % copyrightDes2;
aboutStr = ui->labAbout->text(); }
titleStr = this->windowTitle();
ui->labAbout->setText(aboutStr.arg(GTA5SYNC_APPSTR, projectDes, appVersion % " (" % buildType % ")", projectBuild, buildStr, qVersion(), copyrightDesA)); // Setup User Interface
this->setWindowTitle(titleStr.arg(GTA5SYNC_APPSTR)); ui->setupUi(this);
aboutStr = ui->labAbout->text();
if (QIcon::hasThemeIcon("dialog-close")) titleStr = this->windowTitle();
{ ui->labAbout->setText(aboutStr.arg(GTA5SYNC_APPSTR, projectDes, appVersion % " (" % buildType % ")", projectBuild, buildStr, qVersion(), copyrightDesA));
ui->cmdClose->setIcon(QIcon::fromTheme("dialog-close")); this->setWindowTitle(titleStr.arg(GTA5SYNC_APPSTR));
}
if (QIcon::hasThemeIcon("dialog-close"))
// DPI calculation {
qreal screenRatio = AppEnv::screenRatio(); ui->cmdClose->setIcon(QIcon::fromTheme("dialog-close"));
if (!additionalContent.isEmpty()) }
{
resize(375 * screenRatio, 270 * screenRatio); // DPI calculation
} qreal screenRatio = AppEnv::screenRatio();
else if (!additionalContent.isEmpty())
{ {
resize(375 * screenRatio, 260 * screenRatio); resize(375 * screenRatio, 270 * screenRatio);
} }
} else
{
AboutDialog::~AboutDialog() resize(375 * screenRatio, 260 * screenRatio);
{ }
delete ui; }
}
AboutDialog::~AboutDialog()
{
delete ui;
}

View File

@ -1,44 +1,44 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef ABOUTDIALOG_H #ifndef ABOUTDIALOG_H
#define ABOUTDIALOG_H #define ABOUTDIALOG_H
#include <QDialog> #include <QDialog>
namespace Ui { namespace Ui {
class AboutDialog; class AboutDialog;
} }
class AboutDialog : public QDialog class AboutDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AboutDialog(QWidget *parent = 0); explicit AboutDialog(QWidget *parent = 0);
~AboutDialog(); ~AboutDialog();
private slots: private slots:
private: private:
Ui::AboutDialog *ui; Ui::AboutDialog *ui;
QString aboutStr; QString aboutStr;
QString titleStr; QString titleStr;
}; };
#endif // ABOUTDIALOG_H #endif // ABOUTDIALOG_H

View File

@ -1,102 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>AboutDialog</class> <class>AboutDialog</class>
<widget class="QDialog" name="AboutDialog"> <widget class="QDialog" name="AboutDialog">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>375</width> <width>375</width>
<height>260</height> <height>260</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>About %1</string> <string>About %1</string>
</property> </property>
<property name="modal"> <property name="modal">
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" name="vlAbout"> <layout class="QVBoxLayout" name="vlAbout">
<item> <item>
<widget class="QLabel" name="labAbout"> <widget class="QLabel" name="labAbout">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>&lt;span style=&quot; font-weight:600;&quot;&gt;%1&lt;/span&gt;&lt;br/&gt; <string>&lt;span style=&quot; font-weight:600;&quot;&gt;%1&lt;/span&gt;&lt;br/&gt;
&lt;br/&gt; &lt;br/&gt;
%2&lt;br/&gt; %2&lt;br/&gt;
&lt;br/&gt; &lt;br/&gt;
Version %3&lt;br/&gt; Version %3&lt;br/&gt;
Created on %4&lt;br/&gt; Created on %4&lt;br/&gt;
Built with Qt %5&lt;br/&gt; Built with Qt %5&lt;br/&gt;
Running with Qt %6&lt;br/&gt; Running with Qt %6&lt;br/&gt;
&lt;br/&gt; &lt;br/&gt;
%7</string> %7</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="openExternalLinks"> <property name="openExternalLinks">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="hlButtons"> <layout class="QHBoxLayout" name="hlButtons">
<item> <item>
<spacer name="hsButtons"> <spacer name="hsButtons">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="cmdClose"> <widget class="QPushButton" name="cmdClose">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Close</string> <string>&amp;Close</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>
<connections> <connections>
<connection> <connection>
<sender>cmdClose</sender> <sender>cmdClose</sender>
<signal>clicked()</signal> <signal>clicked()</signal>
<receiver>AboutDialog</receiver> <receiver>AboutDialog</receiver>
<slot>close()</slot> <slot>close()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>327</x> <x>327</x>
<y>228</y> <y>228</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>187</x> <x>187</x>
<y>124</y> <y>124</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
</connections> </connections>
</ui> </ui>

View File

@ -1,155 +1,178 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "config.h" #include "config.h"
#include "AppEnv.h" #include "AppEnv.h"
#include "StringParser.h" #include "StringParser.h"
#include "StandardPaths.h" #include "StandardPaths.h"
#include <QtGlobal> #include <QtGlobal>
#include <QDesktopWidget> #include <QStringBuilder>
#include <QApplication> #include <QDesktopWidget>
#include <QSettings> #include <QApplication>
#include <QScreen> #include <QSettings>
#include <QDebug> #include <QScreen>
#include <QRect> #include <QDebug>
#include <QDir> #include <QRect>
#include <iostream> #include <QDir>
using namespace std; #include <iostream>
using namespace std;
AppEnv::AppEnv()
{ AppEnv::AppEnv()
{
}
}
// Folder Stuff
// Folder Stuff
QString AppEnv::getGameFolder(bool *ok)
{ QString AppEnv::getGameFolder(bool *ok)
QDir dir; {
QString GTAV_FOLDER = QString::fromUtf8(qgetenv("GTAV_FOLDER")); QDir dir;
if (GTAV_FOLDER != "") QString GTAV_FOLDER = QString::fromUtf8(qgetenv("GTAV_FOLDER"));
{ if (GTAV_FOLDER != "")
dir.setPath(GTAV_FOLDER); {
if (dir.exists()) dir.setPath(GTAV_FOLDER);
{ if (dir.exists())
if (ok != NULL) *ok = true; {
qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8()); if (ok != NULL) *ok = true;
return dir.absolutePath(); qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8());
} return dir.absolutePath();
} }
}
QString GTAV_defaultFolder = StandardPaths::documentsLocation() + QDir::separator() + "Rockstar Games" + QDir::separator() + "GTA V";
QString GTAV_returnFolder = GTAV_defaultFolder; QString GTAV_defaultFolder = StandardPaths::documentsLocation() % QDir::separator() % "Rockstar Games" % QDir::separator() % "GTA V";
QString GTAV_returnFolder = GTAV_defaultFolder;
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("dir"); QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
bool forceDir = settings.value("force", false).toBool(); settings.beginGroup("dir");
GTAV_returnFolder = settings.value("dir", GTAV_defaultFolder).toString(); bool forceDir = settings.value("force", false).toBool();
settings.endGroup(); GTAV_returnFolder = settings.value("dir", GTAV_defaultFolder).toString();
settings.endGroup();
if (forceDir)
{ if (forceDir)
dir.setPath(GTAV_returnFolder); {
if (dir.exists()) dir.setPath(GTAV_returnFolder);
{ if (dir.exists())
if (ok != 0) *ok = true; {
qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8()); if (ok != 0) *ok = true;
return dir.absolutePath(); qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8());
} return dir.absolutePath();
} }
}
dir.setPath(GTAV_defaultFolder);
if (dir.exists()) dir.setPath(GTAV_defaultFolder);
{ if (dir.exists())
if (ok != 0) *ok = true; {
qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8()); if (ok != 0) *ok = true;
return dir.absolutePath(); qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8());
} return dir.absolutePath();
}
if (!forceDir)
{ if (!forceDir)
dir.setPath(GTAV_returnFolder); {
if (dir.exists()) dir.setPath(GTAV_returnFolder);
{ if (dir.exists())
if (ok != 0) *ok = true; {
qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8()); if (ok != 0) *ok = true;
return dir.absolutePath(); qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8());
} return dir.absolutePath();
} }
}
if (ok != 0) *ok = false;
return ""; if (ok != 0) *ok = false;
} return "";
}
bool AppEnv::setGameFolder(QString gameFolder)
{ bool AppEnv::setGameFolder(QString gameFolder)
QDir dir; {
dir.setPath(gameFolder); QDir dir;
if (dir.exists()) dir.setPath(gameFolder);
{ if (dir.exists())
qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8()); {
return true; qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8());
} return true;
return false; }
} return false;
}
QString AppEnv::getLangFolder()
{ QString AppEnv::getExLangFolder()
return StringParser::convertBuildedString(QString::fromUtf8(GTA5SYNC_LANG)); {
} return StringParser::convertBuildedString(GTA5SYNC_LANG);
}
QString AppEnv::getPluginsFolder()
{ QString AppEnv::getInLangFolder()
return StringParser::convertBuildedString(QString::fromUtf8(GTA5SYNC_PLUG)); {
} #ifdef GTA5SYNC_QCONF
#ifdef GTA5SYNC_INLANG
// Web Stuff return StringParser::convertBuildedString(GTA5SYNC_INLANG);
#else
QByteArray AppEnv::getUserAgent() return StringParser::convertBuildedString(GTA5SYNC_SHARE % QLatin1String("SEPARATOR:APPNAME:SEPARATOR:translations"));
{ #endif
return QString("Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0 %1/%2").arg(GTA5SYNC_APPSTR, GTA5SYNC_APPVER).toUtf8(); #else
} #ifdef GTA5SYNC_INLANG
return StringParser::convertBuildedString(GTA5SYNC_INLANG);
// QUrl AppEnv::getCrewFetchingUrl(QString crewID) #else
// { return QString(":/tr");
// return QUrl(QString("https://socialclub.rockstargames.com/reference/crewfeed/%1").arg(crewID)); #endif
// } #endif
}
QUrl AppEnv::getCrewFetchingUrl(QString crewID)
{ QString AppEnv::getPluginsFolder()
return QUrl(QString("https://socialclub.rockstargames.com/crew/%1/%1").arg(crewID)); {
} return StringParser::convertBuildedString(GTA5SYNC_PLUG);
}
QUrl AppEnv::getPlayerFetchingUrl(QString crewID, QString pageNumber)
{ // Web Stuff
return QUrl(QString("https://socialclub.rockstargames.com/crewsapi/GetMembersList?crewId=%1&pageNumber=%2").arg(crewID, pageNumber));
} QByteArray AppEnv::getUserAgent()
{
qreal AppEnv::screenRatio() return QString("Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0 %1/%2").arg(GTA5SYNC_APPSTR, GTA5SYNC_APPVER).toUtf8();
{ }
#if QT_VERSION >= 0x050000
qreal dpi = QGuiApplication::primaryScreen()->logicalDotsPerInch(); // QUrl AppEnv::getCrewFetchingUrl(QString crewID)
#else // {
qreal dpi = qApp->desktop()->logicalDpiX(); // return QUrl(QString("https://socialclub.rockstargames.com/reference/crewfeed/%1").arg(crewID));
#endif // }
#ifdef Q_OS_MAC
return (dpi / 72); QUrl AppEnv::getCrewFetchingUrl(QString crewID)
#else {
return (dpi / 96); return QUrl(QString("https://socialclub.rockstargames.com/crew/%1/%1").arg(crewID));
#endif }
}
QUrl AppEnv::getPlayerFetchingUrl(QString crewID, QString pageNumber)
{
return QUrl(QString("https://socialclub.rockstargames.com/crewsapi/GetMembersList?crewId=%1&pageNumber=%2").arg(crewID, pageNumber));
}
QUrl AppEnv::getPlayerFetchingUrl(QString crewID, int pageNumber)
{
return getPlayerFetchingUrl(crewID, QString::number(pageNumber));
}
qreal AppEnv::screenRatio()
{
#if QT_VERSION >= 0x050000
qreal dpi = QGuiApplication::primaryScreen()->logicalDotsPerInch();
#else
qreal dpi = qApp->desktop()->logicalDpiX();
#endif
#ifdef Q_OS_MAC
return (dpi / 72);
#else
return (dpi / 96);
#endif
}

View File

@ -1,45 +1,47 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef APPENV_H #ifndef APPENV_H
#define APPENV_H #define APPENV_H
#include <QString> #include <QString>
#include <QUrl> #include <QUrl>
class AppEnv class AppEnv
{ {
public: public:
AppEnv(); AppEnv();
// Folder Stuff // Folder Stuff
static QString getGameFolder(bool *ok = 0); static QString getGameFolder(bool *ok = 0);
static bool setGameFolder(QString gameFolder); static bool setGameFolder(QString gameFolder);
static QString getLangFolder(); static QString getExLangFolder();
static QString getPluginsFolder(); static QString getInLangFolder();
static QString getPluginsFolder();
// Web Stuff
static QByteArray getUserAgent(); // Web Stuff
static QUrl getCrewFetchingUrl(QString crewID); static QByteArray getUserAgent();
static QUrl getPlayerFetchingUrl(QString crewID, QString pageNumber); static QUrl getCrewFetchingUrl(QString crewID);
static QUrl getPlayerFetchingUrl(QString crewID, QString pageNumber);
// Screen Stuff static QUrl getPlayerFetchingUrl(QString crewID, int pageNumber);
static qreal screenRatio();
}; // Screen Stuff
static qreal screenRatio();
#endif // APPENV_H };
#endif // APPENV_H

View File

@ -1,83 +1,165 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "StandardPaths.h" #include "StandardPaths.h"
#include "CrewDatabase.h" #include "CrewDatabase.h"
#include "config.h" #include "config.h"
#include <QFile> #include <QStringBuilder>
#include <QDir> #include <QMutexLocker>
#include <QDebug>
CrewDatabase::CrewDatabase(QObject *parent) : QObject(parent) #include <QFile>
{ #include <QDir>
QDir dir;
dir.mkpath(StandardPaths::dataLocation()); CrewDatabase::CrewDatabase(QObject *parent) : QObject(parent)
dir.setPath(StandardPaths::dataLocation()); {
QString dirPath = dir.absolutePath(); QDir dir;
QString defaultConfPath = dirPath + QDir::separator() + "crews.ini"; dir.mkpath(StandardPaths::dataLocation());
dir.setPath(StandardPaths::dataLocation());
QSettings confPathSettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); QString dirPath = dir.absolutePath();
confPathSettings.beginGroup("Database"); QString defaultConfPath = dirPath % QDir::separator() % "crews.ini";
QString confPathFile = confPathSettings.value("Crews", defaultConfPath).toString();
confPathSettings.endGroup(); QSettings confPathSettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
confPathSettings.beginGroup("Database");
crewDB = new QSettings(confPathFile, QSettings::IniFormat); QString confPathFile = confPathSettings.value("Crews", defaultConfPath).toString();
crewDB->beginGroup("Crews"); confPathSettings.endGroup();
}
crewDB = new QSettings(confPathFile, QSettings::IniFormat);
CrewDatabase::~CrewDatabase() crewDB->beginGroup("Crews");
{
crewDB->endGroup(); addProcess = false;
delete crewDB; }
}
CrewDatabase::~CrewDatabase()
QStringList CrewDatabase::getCrews() {
{ crewDB->endGroup();
QStringList compatibleCrewList = crewDB->childKeys(); delete crewDB;
crewDB->endGroup(); }
crewDB->beginGroup("CrewList");
QStringList crewIDs = crewDB->value("IDs", QStringList()).toStringList(); QStringList CrewDatabase::getCrews()
crewIDs.append(compatibleCrewList); {
crewIDs.removeDuplicates(); QMutexLocker locker(&mutex);
crewDB->endGroup(); #ifdef GTA5SYNC_DEBUG
crewDB->beginGroup("Crews"); qDebug() << "getCrews";
return crewIDs; #endif
} return getCrews_p();
}
QString CrewDatabase::getCrewName(int crewID)
{ QStringList CrewDatabase::getCrews_p()
QString crewStr = crewDB->value(QString::number(crewID), crewID).toString(); {
if (crewID == 0) crewStr = tr("No Crew", ""); #ifdef GTA5SYNC_DEBUG
return crewStr; qDebug() << "getCrews_p";
} #endif
QStringList compatibleCrewList = getCompatibleCrews_p();
void CrewDatabase::setCrewName(int crewID, QString crewName) crewDB->endGroup();
{ crewDB->beginGroup("CrewList");
crewDB->setValue(QString::number(crewID), crewName); QStringList crewIDs = crewDB->value("IDs", QStringList()).toStringList();
} crewIDs += compatibleCrewList;
crewIDs.removeDuplicates();
void CrewDatabase::addCrew(int crewID) crewDB->endGroup();
{ crewDB->beginGroup("Crews");
QStringList crews = getCrews(); return crewIDs;
crews.append(QString::number(crewID)); }
crews.removeDuplicates();
crewDB->endGroup(); QStringList CrewDatabase::getCompatibleCrews()
crewDB->beginGroup("CrewList"); {
crewDB->setValue("IDs", crews); QMutexLocker locker(&mutex);
crewDB->endGroup(); #ifdef GTA5SYNC_DEBUG
crewDB->beginGroup("Crews"); qDebug() << "getCompatibleCrews";
} #endif
return getCompatibleCrews_p();
}
QStringList CrewDatabase::getCompatibleCrews_p()
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "getCompatibleCrews_p";
#endif
return crewDB->childKeys();
}
QString CrewDatabase::getCrewName(int crewID)
{
QMutexLocker locker(&mutex);
#ifdef GTA5SYNC_DEBUG
qDebug() << "getCrewName" << crewID;
#endif
QString crewStr = crewDB->value(QString::number(crewID), crewID).toString();
if (crewID == 0) crewStr = tr("No Crew", "");
return crewStr;
}
void CrewDatabase::setCrewName(int crewID, QString crewName)
{
QMutexLocker locker(&mutex);
#ifdef GTA5SYNC_DEBUG
qDebug() << "setCrewName" << crewID << crewName;
#endif
crewDB->setValue(QString::number(crewID), crewName);
}
void CrewDatabase::addCrew(int crewID)
{
QMutexLocker locker(&mutex);
#ifdef GTA5SYNC_DEBUG
qDebug() << "addCrew" << crewID;
#endif
QStringList crews = getCrews_p();
crews += QString::number(crewID);
crews.removeDuplicates();
crewDB->endGroup();
crewDB->beginGroup("CrewList");
crewDB->setValue("IDs", crews);
crewDB->endGroup();
crewDB->beginGroup("Crews");
}
bool CrewDatabase::isCompatibleCrew(QString crewNID)
{
QMutexLocker locker(&mutex);
#ifdef GTA5SYNC_DEBUG
qDebug() << "isCompatibleCrew" << crewNID;
#endif
return crewDB->contains(crewNID);
}
bool CrewDatabase::isCompatibleCrew(int crewID)
{
QMutexLocker locker(&mutex);
#ifdef GTA5SYNC_DEBUG
qDebug() << "isCompatibleCrew" << crewID;
#endif
return crewDB->contains(QString::number(crewID));
}
void CrewDatabase::setAddingCrews(bool addingCrews)
{
QMutexLocker locker(&mutex);
#ifdef GTA5SYNC_DEBUG
qDebug() << "setAddingCrews" << addingCrews;
#endif
addProcess = addingCrews;
}
bool CrewDatabase::isAddingCrews()
{
QMutexLocker locker(&mutex);
#ifdef GTA5SYNC_DEBUG
qDebug() << "isAddingCrews";
#endif
return addProcess;
}

View File

@ -1,43 +1,53 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef CREWDATABASE_H #ifndef CREWDATABASE_H
#define CREWDATABASE_H #define CREWDATABASE_H
#include <QSettings> #include <QSettings>
#include <QObject> #include <QObject>
#include <QMap> #include <QMutex>
#include <QMap>
class CrewDatabase : public QObject
{ class CrewDatabase : public QObject
Q_OBJECT {
public: Q_OBJECT
explicit CrewDatabase(QObject *parent = 0); public:
void setCrewName(int crewID, QString crewName); explicit CrewDatabase(QObject *parent = 0);
QString getCrewName(int crewID); QString getCrewName(int crewID);
QStringList getCrews(); QStringList getCompatibleCrews();
~CrewDatabase(); QStringList getCrews();
void setAddingCrews(bool addingCrews);
private: bool isCompatibleCrew(QString crewNID);
QSettings *crewDB; bool isCompatibleCrew(int crewID);
bool isAddingCrews();
public slots: ~CrewDatabase();
void addCrew(int crewID);
}; private:
mutable QMutex mutex;
#endif // CREWDATABASE_H bool addProcess;
QSettings *crewDB;
QStringList getCrews_p();
QStringList getCompatibleCrews_p();
public slots:
void setCrewName(int crewID, QString crewName);
void addCrew(int crewID);
};
#endif // CREWDATABASE_H

View File

@ -1,296 +1,276 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "DatabaseThread.h" #include "DatabaseThread.h"
#include "CrewDatabase.h" #include "CrewDatabase.h"
#include "AppEnv.h" #include "AppEnv.h"
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkRequest> #include <QNetworkRequest>
#include <QNetworkReply> #include <QNetworkReply>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QStringList> #include <QStringList>
#include <QVariantMap> #include <QVariantMap>
#include <QEventLoop> #include <QEventLoop>
#include <QTimer> #include <QTimer>
#include <QDebug> #include <QDebug>
#include <QUrl> #include <QUrl>
DatabaseThread::DatabaseThread(CrewDatabase *crewDB, QObject *parent) : QThread(parent), crewDB(crewDB) #define crewMaxPages 83
{
crewMaxPages = 83; DatabaseThread::DatabaseThread(CrewDatabase *crewDB, QObject *parent) : QThread(parent), crewDB(crewDB)
threadRunning = true; {
} threadRunning = true;
}
void DatabaseThread::run()
{ void DatabaseThread::run()
QEventLoop threadLoop; {
QStringList crewList; QEventLoop threadLoop;
// Register thread loop end signal QStringList crewList;
QObject::connect(this, SIGNAL(threadEndCommited()), &threadLoop, SLOT(quit())); QStringList crewListR;
// Quick time scan // Register thread loop end signal
if (crewList.length() <= 3) QObject::connect(this, SIGNAL(threadEndCommited()), &threadLoop, SLOT(quit()));
{
scanCrewReference(crewList, 2500); // Setup crewList for Quick time scan
scanCrewMembersList(crewList, 3, 2500); crewList = crewDB->getCrews();
emit playerNameUpdated(); if (!crewList.isEmpty())
} {
else if (crewList.length() <= 5) crewListR = deleteCompatibleCrews(crewList);
{ }
scanCrewReference(crewList, 2500); else
scanCrewMembersList(crewList, 2, 2500); {
emit playerNameUpdated(); while (crewList.isEmpty() && threadRunning)
} {
QTimer::singleShot(1000, &threadLoop, SLOT(quit()));
QEventLoop *waitingLoop = new QEventLoop(); threadLoop.exec();
QTimer::singleShot(10000, waitingLoop, SLOT(quit())); if (!crewDB->isAddingCrews())
QObject::connect(this, SIGNAL(threadEndCommited()), waitingLoop, SLOT(quit())); {
waitingLoop->exec(); crewList = crewDB->getCrews();
delete waitingLoop; }
}
while (threadRunning) if (threadRunning)
{ {
crewList = crewDB->getCrews(); crewListR = deleteCompatibleCrews(crewList);
}
// Long time scan }
scanCrewReference(crewList, 10000);
scanCrewMembersList(crewList, crewMaxPages, 10000); // Only do QTS when Thread should be run
emit playerNameUpdated(); if (threadRunning)
{
if (threadRunning) // Quick time scan
{ #ifdef GTA5SYNC_DEBUG
QTimer::singleShot(300000, &threadLoop, SLOT(quit())); qDebug() << "Start QTS";
threadLoop.exec(); #endif
} if (crewListR.length() <= 5)
} {
} scanCrewReference(crewListR, 2500);
emit crewNameUpdated();
// void DatabaseThread::scanCrewReference(QStringList crewList, int requestDelay) }
// { if (crewList.length() <= 3)
// foreach (const QString &crewID, crewList) {
// { scanCrewMembersList(crewList, 3, 2500);
// if (threadRunning && crewID != "0") emit playerNameUpdated();
// { }
// QNetworkAccessManager *netManager = new QNetworkAccessManager(); else if (crewList.length() <= 5)
{
// QNetworkRequest netRequest(AppEnv::getCrewFetchingUrl(crewID)); scanCrewMembersList(crewList, 2, 2500);
// netRequest.setRawHeader("User-Agent", AppEnv::getUserAgent()); emit playerNameUpdated();
// netRequest.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); }
// netRequest.setRawHeader("Accept-Language", "en-US;q=0.5,en;q=0.3");
// netRequest.setRawHeader("Connection", "keep-alive"); if (threadRunning)
{
// QNetworkReply *netReply = netManager->get(netRequest); QTimer::singleShot(10000, &threadLoop, SLOT(quit()));
threadLoop.exec();
// QEventLoop *downloadLoop = new QEventLoop(); }
// QObject::connect(netReply, SIGNAL(finished()), downloadLoop, SLOT(quit())); }
// QObject::connect(this, SIGNAL(threadEndCommited()), downloadLoop, SLOT(quit()));
// QTimer::singleShot(30000, downloadLoop, SLOT(quit())); while (threadRunning)
// downloadLoop->exec(); {
// delete downloadLoop; crewList = crewDB->getCrews();
crewListR = deleteCompatibleCrews(crewList);
// if (netReply->isFinished())
// { // Long time scan
// QByteArray crewJson = netReply->readAll(); #ifdef GTA5SYNC_DEBUG
// QJsonDocument crewDocument = QJsonDocument::fromJson(crewJson); qDebug() << "Start LTS";
// QJsonObject crewObject = crewDocument.object(); #endif
// QVariantMap crewMap = crewObject.toVariantMap(); scanCrewReference(crewListR, 10000);
// QString crewName; emit crewNameUpdated();
// bool isFound = false; scanCrewMembersList(crewList, crewMaxPages, 10000);
emit playerNameUpdated();
// if (crewMap.contains("activities"))
// { if (threadRunning)
// QList<QVariant> activitiesList = crewMap["activities"].toList(); {
// foreach (const QVariant &activitiesVariant, activitiesList) QTimer::singleShot(300000, &threadLoop, SLOT(quit()));
// { threadLoop.exec();
// QMap<QString, QVariant> activityRootMap = activitiesVariant.toMap(); }
// foreach(const QVariant &activityRootVariant, activityRootMap) }
// { }
// QMap<QString, QVariant> activityMap = activityRootVariant.toMap();
// foreach(const QVariant &activityVariant, activityMap) void DatabaseThread::scanCrewReference(const QStringList &crewList, const int &requestDelay)
// { {
// QMap<QString, QVariant> activityFinalMap = activityVariant.toMap(); foreach (const QString &crewID, crewList)
// if (activityFinalMap.contains("id") && activityFinalMap["id"] == crewID) {
// { if (threadRunning && crewID != "0")
// if (activityFinalMap.contains("name") && isFound == false) {
// { QNetworkAccessManager *netManager = new QNetworkAccessManager();
// isFound = true;
// crewName = activityFinalMap["name"].toString(); QNetworkRequest netRequest(AppEnv::getCrewFetchingUrl(crewID));
// } #if QT_VERSION >= 0x050600
// } netRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
// } #endif
// } netRequest.setRawHeader("User-Agent", AppEnv::getUserAgent());
// } netRequest.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
// } netRequest.setRawHeader("Accept-Language", "en-US;q=0.5,en;q=0.3");
// if (!crewName.isNull()) netRequest.setRawHeader("Connection", "keep-alive");
// {
// crewDB->setCrewName(crewID.toInt(), crewName); QNetworkReply *netReply = netManager->get(netRequest);
// }
// } QEventLoop *downloadLoop = new QEventLoop();
QObject::connect(netReply, SIGNAL(finished()), downloadLoop, SLOT(quit()));
// QEventLoop *waitingLoop = new QEventLoop(); QObject::connect(this, SIGNAL(threadEndCommited()), downloadLoop, SLOT(quit()));
// QTimer::singleShot(requestDelay, waitingLoop, SLOT(quit())); QTimer::singleShot(30000, downloadLoop, SLOT(quit()));
// QObject::connect(this, SIGNAL(threadEndCommited()), waitingLoop, SLOT(quit())); downloadLoop->exec();
// waitingLoop->exec(); delete downloadLoop;
// delete waitingLoop;
if (netReply->isFinished())
// delete netReply; {
// delete netManager; QString crewName;
// } QByteArray crewHtml = netReply->readAll();
// } QStringList crewHtmlSplit1 = QString::fromUtf8(crewHtml).split("<title>Rockstar Games Social Club - Crew : ");
// } if (crewHtmlSplit1.length() >= 2)
{
void DatabaseThread::scanCrewReference(QStringList crewList, int requestDelay) QStringList crewHtmlSplit2 = QString(crewHtmlSplit1.at(1)).split("</title>");
{ if (crewHtmlSplit2.length() >= 1)
foreach (const QString &crewID, crewList) {
{ crewName = crewHtmlSplit2.at(0);
if (threadRunning && crewID != "0") }
{ }
QNetworkAccessManager *netManager = new QNetworkAccessManager(); if (!crewName.isEmpty())
{
QNetworkRequest netRequest(AppEnv::getCrewFetchingUrl(crewID)); emit crewNameFound(crewID.toInt(), crewName);
#if QT_VERSION >= 0x050600 }
netRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); }
#endif
netRequest.setRawHeader("User-Agent", AppEnv::getUserAgent()); QEventLoop *waitingLoop = new QEventLoop();
netRequest.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); QTimer::singleShot(requestDelay, waitingLoop, SLOT(quit()));
netRequest.setRawHeader("Accept-Language", "en-US;q=0.5,en;q=0.3"); QObject::connect(this, SIGNAL(threadEndCommited()), waitingLoop, SLOT(quit()));
netRequest.setRawHeader("Connection", "keep-alive"); waitingLoop->exec();
delete waitingLoop;
QNetworkReply *netReply = netManager->get(netRequest);
delete netReply;
QEventLoop *downloadLoop = new QEventLoop(); delete netManager;
QObject::connect(netReply, SIGNAL(finished()), downloadLoop, SLOT(quit())); }
QObject::connect(this, SIGNAL(threadEndCommited()), downloadLoop, SLOT(quit())); }
QTimer::singleShot(30000, downloadLoop, SLOT(quit())); }
downloadLoop->exec();
delete downloadLoop; void DatabaseThread::scanCrewMembersList(const QStringList &crewList, const int &maxPages, const int &requestDelay)
{
if (netReply->isFinished()) foreach (const QString &crewID, crewList)
{ {
QString crewName; if (threadRunning && crewID != "0")
QByteArray crewHtml = netReply->readAll(); {
QStringList crewHtmlSplit1 = QString::fromUtf8(crewHtml).split("<title>Rockstar Games Social Club - Crew : "); int currentPage = 0;
if (crewHtmlSplit1.length() >= 2) int foundPlayers = 0;
{ int totalPlayers = 1000;
QStringList crewHtmlSplit2 = QString(crewHtmlSplit1.at(1)).split("</title>");
if (crewHtmlSplit2.length() >= 1) while(foundPlayers < totalPlayers && currentPage < maxPages)
{ {
crewName = crewHtmlSplit2.at(0); QNetworkAccessManager *netManager = new QNetworkAccessManager();
}
} QNetworkRequest netRequest(AppEnv::getPlayerFetchingUrl(crewID, currentPage));
if (!crewName.isEmpty()) #if QT_VERSION >= 0x050600
{ netRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
crewDB->setCrewName(crewID.toInt(), crewName); #endif
} netRequest.setRawHeader("User-Agent", AppEnv::getUserAgent());
} netRequest.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
netRequest.setRawHeader("Accept-Language", "en-US;q=0.5,en;q=0.3");
QEventLoop *waitingLoop = new QEventLoop(); netRequest.setRawHeader("Connection", "keep-alive");
QTimer::singleShot(requestDelay, waitingLoop, SLOT(quit()));
QObject::connect(this, SIGNAL(threadEndCommited()), waitingLoop, SLOT(quit())); QNetworkReply *netReply = netManager->get(netRequest);
waitingLoop->exec();
delete waitingLoop; QEventLoop *downloadLoop = new QEventLoop();
QObject::connect(netReply, SIGNAL(finished()), downloadLoop, SLOT(quit()));
delete netReply; QObject::connect(this, SIGNAL(threadEndCommited()), downloadLoop, SLOT(quit()));
delete netManager; QTimer::singleShot(30000, downloadLoop, SLOT(quit()));
} downloadLoop->exec();
} delete downloadLoop;
}
if (netReply->isFinished())
void DatabaseThread::scanCrewMembersList(QStringList crewList, int maxPages, int requestDelay) {
{ QByteArray crewJson = netReply->readAll();
foreach (const QString &crewID, crewList) QJsonDocument crewDocument = QJsonDocument::fromJson(crewJson);
{ QJsonObject crewObject = crewDocument.object();
if (threadRunning && crewID != "0") QVariantMap crewMap = crewObject.toVariantMap();
{
int currentPage = 0; if (crewMap.contains("Total")) { totalPlayers = crewMap["Total"].toInt(); }
int foundPlayers = 0;
int totalPlayers = 1000; if (crewMap.contains("Members"))
{
while(foundPlayers < totalPlayers && currentPage < maxPages) QList<QVariant> memberList = crewMap["Members"].toList();
{ foreach (const QVariant &memberVariant, memberList)
QNetworkAccessManager *netManager = new QNetworkAccessManager(); {
QMap<QString, QVariant> memberMap = memberVariant.toMap();
QNetworkRequest netRequest(AppEnv::getPlayerFetchingUrl(crewID, QString::number(currentPage))); foundPlayers++;
#if QT_VERSION >= 0x050600 if (memberMap.contains("RockstarId") && memberMap.contains("Name"))
netRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); {
#endif int RockstarId = memberMap["RockstarId"].toInt();
netRequest.setRawHeader("User-Agent", AppEnv::getUserAgent()); QString memberName = memberMap["Name"].toString();
netRequest.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); if (memberName != "" && RockstarId != 0)
netRequest.setRawHeader("Accept-Language", "en-US;q=0.5,en;q=0.3"); {
netRequest.setRawHeader("Connection", "keep-alive"); emit playerNameFound(RockstarId, memberName);
}
QNetworkReply *netReply = netManager->get(netRequest); }
}
QEventLoop *downloadLoop = new QEventLoop(); }
QObject::connect(netReply, SIGNAL(finished()), downloadLoop, SLOT(quit()));
QObject::connect(this, SIGNAL(threadEndCommited()), downloadLoop, SLOT(quit())); QEventLoop *waitingLoop = new QEventLoop();
QTimer::singleShot(30000, downloadLoop, SLOT(quit())); QTimer::singleShot(requestDelay, waitingLoop, SLOT(quit()));
downloadLoop->exec(); QObject::connect(this, SIGNAL(threadEndCommited()), waitingLoop, SLOT(quit()));
delete downloadLoop; waitingLoop->exec();
delete waitingLoop;
if (netReply->isFinished())
{ currentPage++;
QByteArray crewJson = netReply->readAll(); }
QJsonDocument crewDocument = QJsonDocument::fromJson(crewJson);
QJsonObject crewObject = crewDocument.object(); delete netReply;
QVariantMap crewMap = crewObject.toVariantMap(); delete netManager;
}
if (crewMap.contains("Total")) { totalPlayers = crewMap["Total"].toInt(); } }
}
if (crewMap.contains("Members")) }
{
QList<QVariant> memberList = crewMap["Members"].toList(); QStringList DatabaseThread::deleteCompatibleCrews(const QStringList &crewList)
foreach (const QVariant &memberVariant, memberList) {
{ QStringList crewListR = crewList;
QMap<QString, QVariant> memberMap = memberVariant.toMap(); foreach(const QString &crewNID, crewListR)
foundPlayers++; {
if (memberMap.contains("RockstarId") && memberMap.contains("Name")) if (crewDB->isCompatibleCrew(crewNID))
{ {
int RockstarId = memberMap["RockstarId"].toInt(); crewListR.removeAll(crewNID);
QString memberName = memberMap["Name"].toString(); }
if (memberName != "" && RockstarId != 0) }
{ return crewListR;
emit playerNameFound(RockstarId, memberName); }
}
} void DatabaseThread::doEndThread()
} {
} threadRunning = false;
emit threadEndCommited();
QEventLoop *waitingLoop = new QEventLoop(); }
QTimer::singleShot(requestDelay, waitingLoop, SLOT(quit()));
QObject::connect(this, SIGNAL(threadEndCommited()), waitingLoop, SLOT(quit()));
waitingLoop->exec();
delete waitingLoop;
currentPage++;
}
delete netReply;
delete netManager;
}
}
}
}
void DatabaseThread::doEndThread()
{
threadRunning = false;
emit threadEndCommited();
}

View File

@ -1,52 +1,54 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef DATABASETHREAD_H #ifndef DATABASETHREAD_H
#define DATABASETHREAD_H #define DATABASETHREAD_H
#include "CrewDatabase.h" #include "CrewDatabase.h"
#include <QObject> #include <QObject>
#include <QThread> #include <QThread>
class DatabaseThread : public QThread class DatabaseThread : public QThread
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DatabaseThread(CrewDatabase *crewDB, QObject *parent = 0); explicit DatabaseThread(CrewDatabase *crewDB, QObject *parent = 0);
public slots: public slots:
void doEndThread(); void doEndThread();
private: private:
CrewDatabase *crewDB; CrewDatabase *crewDB;
void scanCrewMembersList(QStringList crewList, int maxPages, int requestDelay); void scanCrewMembersList(const QStringList &crewList, const int &maxPages, const int &requestDelay);
void scanCrewReference(QStringList crewList, int requestDelay); void scanCrewReference(const QStringList &crewList, const int &requestDelay);
bool threadRunning; QStringList deleteCompatibleCrews(const QStringList &crewList);
int crewMaxPages; bool threadRunning;
int plyrPerReq; int plyrPerReq;
protected: protected:
void run(); void run();
signals: signals:
void playerNameFound(int playerID, QString playerName); void crewNameFound(int crewID, QString crewName);
void playerNameUpdated(); void crewNameUpdated();
void threadEndCommited(); void playerNameFound(int playerID, QString playerName);
}; void playerNameUpdated();
void threadEndCommited();
#endif // DATABASETHREAD_H };
#endif // DATABASETHREAD_H

View File

@ -1,48 +1,48 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "ExportDialog.h" #include "ExportDialog.h"
#include "ui_ExportDialog.h" #include "ui_ExportDialog.h"
ExportDialog::ExportDialog(QWidget *parent) : ExportDialog::ExportDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::ExportDialog) ui(new Ui::ExportDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
success = false; success = false;
} }
ExportDialog::~ExportDialog() ExportDialog::~ExportDialog()
{ {
delete ui; delete ui;
} }
bool ExportDialog::isSucceeded() bool ExportDialog::isSucceeded()
{ {
return success; return success;
} }
void ExportDialog::on_cmdSnapmaticClose_clicked() void ExportDialog::on_cmdSnapmaticClose_clicked()
{ {
this->close(); this->close();
} }
void ExportDialog::setupPictureExport() void ExportDialog::setupPictureExport()
{ {
ui->swExport->setCurrentWidget(ui->pageSnapmatic); ui->swExport->setCurrentWidget(ui->pageSnapmatic);
} }

View File

@ -1,46 +1,46 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef EXPORTDIALOG_H #ifndef EXPORTDIALOG_H
#define EXPORTDIALOG_H #define EXPORTDIALOG_H
#include <QDialog> #include <QDialog>
namespace Ui { namespace Ui {
class ExportDialog; class ExportDialog;
} }
class ExportDialog : public QDialog class ExportDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ExportDialog(QWidget *parent = 0); explicit ExportDialog(QWidget *parent = 0);
void setupPictureExport(); void setupPictureExport();
bool isSucceeded(); bool isSucceeded();
~ExportDialog(); ~ExportDialog();
private slots: private slots:
void on_cmdSnapmaticClose_clicked(); void on_cmdSnapmaticClose_clicked();
private: private:
Ui::ExportDialog *ui; Ui::ExportDialog *ui;
bool success; bool success;
}; };
#endif // EXPORTDIALOG_H #endif // EXPORTDIALOG_H

View File

@ -1,226 +1,226 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>ExportDialog</class> <class>ExportDialog</class>
<widget class="QDialog" name="ExportDialog"> <widget class="QDialog" name="ExportDialog">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>400</width>
<height>300</height> <height>300</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Dialog</string> <string>Dialog</string>
</property> </property>
<property name="modal"> <property name="modal">
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" name="vlExport"> <layout class="QVBoxLayout" name="vlExport">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QStackedWidget" name="swExport"> <widget class="QStackedWidget" name="swExport">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<widget class="QWidget" name="pageSnapmatic"> <widget class="QWidget" name="pageSnapmatic">
<layout class="QVBoxLayout" name="vlSnapmatic"> <layout class="QVBoxLayout" name="vlSnapmatic">
<item> <item>
<widget class="QGroupBox" name="gbSnapmaticFormat"> <widget class="QGroupBox" name="gbSnapmaticFormat">
<property name="title"> <property name="title">
<string>Export Format</string> <string>Export Format</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QRadioButton" name="rbSystemPicture"> <widget class="QRadioButton" name="rbSystemPicture">
<property name="text"> <property name="text">
<string>&amp;JPEG/PNG format</string> <string>&amp;JPEG/PNG format</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QRadioButton" name="rbSnapmaticPicture"> <widget class="QRadioButton" name="rbSnapmaticPicture">
<property name="text"> <property name="text">
<string>GTA &amp;Snapmatic format</string> <string>GTA &amp;Snapmatic format</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="gbSnapmaticResolution"> <widget class="QGroupBox" name="gbSnapmaticResolution">
<property name="title"> <property name="title">
<string>Export Size</string> <string>Export Size</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QRadioButton" name="rbSnapmaticDefaultSize"> <widget class="QRadioButton" name="rbSnapmaticDefaultSize">
<property name="text"> <property name="text">
<string>Default &amp;Size</string> <string>Default &amp;Size</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QRadioButton" name="rbSnapmaticDesktopSize"> <widget class="QRadioButton" name="rbSnapmaticDesktopSize">
<property name="text"> <property name="text">
<string>&amp;Desktop Size</string> <string>&amp;Desktop Size</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QRadioButton" name="rbSnapmaticCustomSize"> <widget class="QRadioButton" name="rbSnapmaticCustomSize">
<property name="text"> <property name="text">
<string>&amp;Custom Size</string> <string>&amp;Custom Size</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="hlSnapmaticResolution"> <layout class="QHBoxLayout" name="hlSnapmaticResolution">
<item> <item>
<widget class="QLabel" name="labSnapmaticResolutionSize"> <widget class="QLabel" name="labSnapmaticResolutionSize">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text"> <property name="text">
<string>Custom Size:</string> <string>Custom Size:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="sbSnapmaticResoulutionWidth"> <widget class="QSpinBox" name="sbSnapmaticResoulutionWidth">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="minimum"> <property name="minimum">
<number>1</number> <number>1</number>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>3840</number> <number>3840</number>
</property> </property>
<property name="value"> <property name="value">
<number>960</number> <number>960</number>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="labSnapmaticResolutionSizeX"> <widget class="QLabel" name="labSnapmaticResolutionSizeX">
<property name="text"> <property name="text">
<string>x</string> <string>x</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="sbSnapmaticResoulutionHeight"> <widget class="QSpinBox" name="sbSnapmaticResoulutionHeight">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="minimum"> <property name="minimum">
<number>1</number> <number>1</number>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>2160</number> <number>2160</number>
</property> </property>
<property name="value"> <property name="value">
<number>536</number> <number>536</number>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="hsSnapmaticResolution"> <spacer name="hsSnapmaticResolution">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>0</width> <width>0</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
</layout> </layout>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="vsSnapmatic"> <spacer name="vsSnapmatic">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>0</width> <width>0</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="hlSnapmaticButtons"> <layout class="QHBoxLayout" name="hlSnapmaticButtons">
<item> <item>
<spacer name="hsSnapmaticButtons"> <spacer name="hsSnapmaticButtons">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>0</width> <width>0</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="cmdSnapmaticExport"> <widget class="QPushButton" name="cmdSnapmaticExport">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Export</string> <string>&amp;Export</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="cmdSnapmaticClose"> <widget class="QPushButton" name="cmdSnapmaticClose">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Close</string> <string>&amp;Close</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="pageSavegame"/> <widget class="QWidget" name="pageSavegame"/>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -1,184 +1,185 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "SnapmaticPicture.h" #include "SnapmaticPicture.h"
#include "ProfileInterface.h" #include "ProfileInterface.h"
#include "PictureExport.h" #include "PictureExport.h"
#include "ProfileWidget.h" #include "ProfileWidget.h"
#include "ExportThread.h" #include "ExportThread.h"
#include "SavegameData.h" #include "SavegameData.h"
#include "config.h" #include "config.h"
#include <QDesktopWidget> #include <QStringBuilder>
#include <QApplication> #include <QDesktopWidget>
#include <QFileInfo> #include <QApplication>
#include <QDebug> #include <QFileInfo>
#include <QFile> #include <QDebug>
#include <QFile>
ExportThread::ExportThread(QMap<ProfileWidget*,QString> profileMap, QString exportDirectory, bool pictureCopyEnabled, bool pictureExportEnabled, int exportCount, QObject *parent) : QThread(parent),
profileMap(profileMap), exportDirectory(exportDirectory), pictureCopyEnabled(pictureCopyEnabled), pictureExportEnabled(pictureExportEnabled), exportCount(exportCount) ExportThread::ExportThread(QMap<ProfileWidget*,QString> profileMap, QString exportDirectory, bool pictureCopyEnabled, bool pictureExportEnabled, int exportCount, QObject *parent) : QThread(parent),
{ profileMap(profileMap), exportDirectory(exportDirectory), pictureCopyEnabled(pictureCopyEnabled), pictureExportEnabled(pictureExportEnabled), exportCount(exportCount)
{
}
}
void ExportThread::run()
{ void ExportThread::run()
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); {
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
// Picture Settings
// Quality Settings // Picture Settings
settings.beginGroup("Pictures"); // Quality Settings
int defaultQuality = 100; settings.beginGroup("Pictures");
QSize defExportSize = QSize(960, 536); int defaultQuality = 100;
int customQuality = settings.value("CustomQuality", defaultQuality).toInt(); QSize defExportSize = QSize(960, 536);
if (customQuality < 1 || customQuality > 100) int customQuality = settings.value("CustomQuality", defaultQuality).toInt();
{ if (customQuality < 1 || customQuality > 100)
customQuality = 100; {
} customQuality = 100;
bool useCustomQuality = settings.value("CustomQualityEnabled", false).toBool(); }
bool useCustomQuality = settings.value("CustomQualityEnabled", false).toBool();
// Size Settings
QSize cusExportSize = settings.value("CustomSize", defExportSize).toSize(); // Size Settings
if (cusExportSize.width() > 3840) QSize cusExportSize = settings.value("CustomSize", defExportSize).toSize();
{ if (cusExportSize.width() > 3840)
cusExportSize.setWidth(3840); {
} cusExportSize.setWidth(3840);
else if (cusExportSize.height() > 2160) }
{ else if (cusExportSize.height() > 2160)
cusExportSize.setHeight(2160); {
} cusExportSize.setHeight(2160);
if (cusExportSize.width() < 1) }
{ if (cusExportSize.width() < 1)
cusExportSize.setWidth(1); {
} cusExportSize.setWidth(1);
else if (cusExportSize.height() < 1) }
{ else if (cusExportSize.height() < 1)
cusExportSize.setHeight(1); {
} cusExportSize.setHeight(1);
QString sizeMode = settings.value("ExportSizeMode", "Default").toString(); }
Qt::AspectRatioMode aspectRatio = (Qt::AspectRatioMode)settings.value("AspectRatio", Qt::KeepAspectRatio).toInt(); QString sizeMode = settings.value("ExportSizeMode", "Default").toString();
settings.endGroup(); Qt::AspectRatioMode aspectRatio = (Qt::AspectRatioMode)settings.value("AspectRatio", Qt::KeepAspectRatio).toInt();
// End Picture Settings settings.endGroup();
// End Picture Settings
int intExportProgress = 0;
foreach(ProfileWidget *widget, profileMap.keys()) int intExportProgress = 0;
{ foreach(ProfileWidget *widget, profileMap.keys())
if (widget->isSelected()) {
{ if (widget->isSelected())
if (widget->getWidgetType() == "SnapmaticWidget") {
{ if (widget->getWidgetType() == "SnapmaticWidget")
SnapmaticWidget *picWidget = (SnapmaticWidget*)widget; {
SnapmaticPicture *picture = picWidget->getPicture(); SnapmaticWidget *picWidget = qobject_cast<SnapmaticWidget*>(widget);
SnapmaticPicture *picture = picWidget->getPicture();
if (pictureExportEnabled)
{ if (pictureExportEnabled)
QString exportFileName = PictureExport::getPictureFileName(picture); {
if (exportFileName.right(4) != ".jpg" && exportFileName.right(4) != ".png") QString exportFileName = PictureExport::getPictureFileName(picture);
{ if (exportFileName.right(4) != ".jpg" && exportFileName.right(4) != ".png")
exportFileName.append(".jpg"); {
} exportFileName += ".jpg";
}
intExportProgress++;
emit exportStringUpdate(ProfileInterface::tr("Export file %1 of %2 files").arg(QString::number(intExportProgress), QString::number(exportCount))); intExportProgress++;
emit exportProgressUpdate(intExportProgress); emit exportStringUpdate(ProfileInterface::tr("Export file %1 of %2 files").arg(QString::number(intExportProgress), QString::number(exportCount)));
emit exportProgressUpdate(intExportProgress);
// Scale Picture
QImage exportPicture = picture->getImage(); // Scale Picture
if (sizeMode == "Desktop") QImage exportPicture = picture->getImage();
{ if (sizeMode == "Desktop")
QRect desktopResolution = QApplication::desktop()->screenGeometry(); {
exportPicture = exportPicture.scaled(desktopResolution.width(), desktopResolution.height(), aspectRatio, Qt::SmoothTransformation); QRect desktopResolution = qApp->desktop()->screenGeometry();
} exportPicture = exportPicture.scaled(desktopResolution.width(), desktopResolution.height(), aspectRatio, Qt::SmoothTransformation);
else if (sizeMode == "Custom") }
{ else if (sizeMode == "Custom")
exportPicture = exportPicture.scaled(cusExportSize, aspectRatio, Qt::SmoothTransformation); {
} exportPicture = exportPicture.scaled(cusExportSize, aspectRatio, Qt::SmoothTransformation);
}
bool isSaved;
if (useCustomQuality) bool isSaved;
{ if (useCustomQuality)
isSaved = exportPicture.save(exportDirectory + "/" + exportFileName, "JPEG", customQuality); {
} isSaved = exportPicture.save(exportDirectory % "/" % exportFileName, "JPEG", customQuality);
else }
{ else
isSaved = exportPicture.save(exportDirectory + "/" + exportFileName, "JPEG", 100); {
} isSaved = exportPicture.save(exportDirectory % "/" % exportFileName, "JPEG", 100);
}
if (!isSaved)
{ if (!isSaved)
failedExportPictures.append(exportFileName); {
} failedExportPictures += exportFileName;
} }
if (pictureCopyEnabled) }
{ if (pictureCopyEnabled)
QString exportFileName = PictureExport::getPictureFileName(picture); {
if (exportFileName.right(4) != ".g5e") QString exportFileName = PictureExport::getPictureFileName(picture);
{ if (exportFileName.right(4) != ".g5e")
exportFileName.append(".g5e"); {
} exportFileName += ".g5e";
}
intExportProgress++;
emit exportStringUpdate(ProfileInterface::tr("Export file %1 of %2 files").arg(QString::number(intExportProgress), QString::number(exportCount))); intExportProgress++;
emit exportProgressUpdate(intExportProgress); emit exportStringUpdate(ProfileInterface::tr("Export file %1 of %2 files").arg(QString::number(intExportProgress), QString::number(exportCount)));
emit exportProgressUpdate(intExportProgress);
QString exportFilePath = exportDirectory + "/" + exportFileName;
if (QFile::exists(exportFilePath)) {QFile::remove(exportFilePath);} QString exportFilePath = exportDirectory % "/" % exportFileName;
if (!picture->exportPicture(exportDirectory + "/" + exportFileName, "G5E")) if (QFile::exists(exportFilePath)) {QFile::remove(exportFilePath);}
{ if (!picture->exportPicture(exportDirectory % "/" % exportFileName, SnapmaticFormat::G5E_Format))
failedCopyPictures.append(exportFileName); {
} failedCopyPictures += exportFileName;
} }
} }
else if (widget->getWidgetType() == "SavegameWidget") }
{ else if (widget->getWidgetType() == "SavegameWidget")
SavegameWidget *sgdWidget = (SavegameWidget*)widget; {
SavegameData *savegame = sgdWidget->getSavegame(); SavegameWidget *sgdWidget = qobject_cast<SavegameWidget*>(widget);
SavegameData *savegame = sgdWidget->getSavegame();
QString originalFileName = savegame->getSavegameFileName();
QFileInfo originalFileInfo(originalFileName); QString originalFileName = savegame->getSavegameFileName();
QString exportFileName = originalFileInfo.fileName(); QFileInfo originalFileInfo(originalFileName);
QString exportFileName = originalFileInfo.fileName();
intExportProgress++;
emit exportStringUpdate(ProfileInterface::tr("Export file %1 of %2 files").arg(QString::number(intExportProgress), QString::number(exportCount))); intExportProgress++;
emit exportProgressUpdate(intExportProgress); emit exportStringUpdate(ProfileInterface::tr("Export file %1 of %2 files").arg(QString::number(intExportProgress), QString::number(exportCount)));
emit exportProgressUpdate(intExportProgress);
QString exportFilePath = exportDirectory + "/" + exportFileName;
if (QFile::exists(exportFilePath)) {QFile::remove(exportFilePath);} QString exportFilePath = exportDirectory % "/" % exportFileName;
if (!QFile::copy(originalFileName, exportFilePath)) if (QFile::exists(exportFilePath)) {QFile::remove(exportFilePath);}
{ if (!QFile::copy(originalFileName, exportFilePath))
failedSavegames.append(exportFileName); {
} failedSavegames += exportFileName;
} }
} }
} }
emit exportFinished(); }
} emit exportFinished();
}
QStringList ExportThread::getFailedCopyPictures()
{ QStringList ExportThread::getFailedCopyPictures()
return failedCopyPictures; {
} return failedCopyPictures;
}
QStringList ExportThread::getFailedExportPictures()
{ QStringList ExportThread::getFailedExportPictures()
return failedExportPictures; {
} return failedExportPictures;
}
QStringList ExportThread::getFailedSavegames()
{ QStringList ExportThread::getFailedSavegames()
return failedSavegames; {
} return failedSavegames;
}

View File

@ -1,56 +1,56 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef EXPORTTHREAD_H #ifndef EXPORTTHREAD_H
#define EXPORTTHREAD_H #define EXPORTTHREAD_H
#include "SnapmaticWidget.h" #include "SnapmaticWidget.h"
#include "SavegameWidget.h" #include "SavegameWidget.h"
#include "ProfileWidget.h" #include "ProfileWidget.h"
#include <QThread> #include <QThread>
#include <QMap> #include <QMap>
class ExportThread : public QThread class ExportThread : public QThread
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ExportThread(QMap<ProfileWidget*,QString> profileMap, QString exportDirectory, bool pictureCopyEnabled, bool pictureExportEnabled, int exportCount, QObject *parent = 0); explicit ExportThread(QMap<ProfileWidget*,QString> profileMap, QString exportDirectory, bool pictureCopyEnabled, bool pictureExportEnabled, int exportCount, QObject *parent = 0);
QStringList getFailedSavegames(); QStringList getFailedSavegames();
QStringList getFailedCopyPictures(); QStringList getFailedCopyPictures();
QStringList getFailedExportPictures(); QStringList getFailedExportPictures();
protected: protected:
void run(); void run();
private: private:
QMap <ProfileWidget*, QString> profileMap; QMap <ProfileWidget*, QString> profileMap;
QString exportDirectory; QString exportDirectory;
bool pictureCopyEnabled; bool pictureCopyEnabled;
bool pictureExportEnabled; bool pictureExportEnabled;
int exportCount; int exportCount;
QStringList failedSavegames; QStringList failedSavegames;
QStringList failedCopyPictures; QStringList failedCopyPictures;
QStringList failedExportPictures; QStringList failedExportPictures;
signals: signals:
void exportStringUpdate(QString currentFileName); void exportStringUpdate(QString currentFileName);
void exportProgressUpdate(int currentProgressValue); void exportProgressUpdate(int currentProgressValue);
void exportFinished(); void exportFinished();
}; };
#endif // EXPORTTHREAD_H #endif // EXPORTTHREAD_H

View File

@ -1,89 +1,85 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include <QLocale> #include "TranslationClass.h"
#include <QSettings> #include "GlobalString.h"
#include <QFileInfo> #include "config.h"
#include <QStringList> #include <QStringBuilder>
#include "GlobalString.h" #include <QStringList>
#include "config.h" #include <QFileInfo>
#include <QSettings>
GlobalString::GlobalString() #include <QLocale>
{ #include <QDebug>
} GlobalString::GlobalString()
{
QMap<QString, QString> GlobalString::getGlobalMap()
{ }
QMap<QString, QString> globalMap;
QSettings globalFile(getLanguageFile(), QSettings::IniFormat); QMap<QString, QString> GlobalString::getGlobalMap()
globalFile.setIniCodec("UTF-8"); {
globalFile.beginGroup("Global"); QMap<QString, QString> globalMap;
QStringList globalStrList = globalFile.childKeys(); QSettings globalFile(getLanguageFile(), QSettings::IniFormat);
foreach(const QString &globalStr, globalStrList) globalFile.setIniCodec("UTF-8");
{ globalFile.beginGroup("Global");
globalMap[globalStr] = globalFile.value(globalStr, globalStr).toString(); QStringList globalStrList = globalFile.childKeys();
} foreach(const QString &globalStr, globalStrList)
globalFile.endGroup(); {
return globalMap; globalMap[globalStr] = globalFile.value(globalStr, globalStr).toString();
} }
globalFile.endGroup();
QString GlobalString::getString(QString valueStr, bool *ok) return globalMap;
{ }
QString globalString = valueStr;
QSettings globalFile(getLanguageFile(), QSettings::IniFormat); QString GlobalString::getString(QString valueStr, bool *ok)
globalFile.setIniCodec("UTF-8"); {
globalFile.beginGroup("Global"); QString globalString = valueStr;
QStringList globalStrList = globalFile.childKeys(); QSettings globalFile(getLanguageFile(), QSettings::IniFormat);
if (globalStrList.contains(valueStr)) globalFile.setIniCodec("UTF-8");
{ globalFile.beginGroup("Global");
if (ok != 0) *ok = true; QStringList globalStrList = globalFile.childKeys();
globalString = globalFile.value(valueStr, valueStr).toString(); if (globalStrList.contains(valueStr))
} {
globalFile.endGroup(); if (ok != NULL) *ok = true;
return globalString; globalString = globalFile.value(valueStr, valueStr).toString();
} }
globalFile.endGroup();
QString GlobalString::getLanguageFile() return globalString;
{ }
QString language = getLanguage();
QString languageFile = ":/global/global." + language + ".ini"; QString GlobalString::getLanguageFile()
if (!QFileInfo(languageFile).exists()) {
{ QString language = getLanguage();
languageFile = ":/global/global.en.ini"; QString languageFile = ":/global/global." % language % ".ini";
} if (!QFileInfo(languageFile).exists())
return languageFile; {
} languageFile = ":/global/global.en.ini";
}
QString GlobalString::getLanguage() return languageFile;
{ }
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("Interface"); QString GlobalString::getLanguage()
QString language = settings.value("Language","System").toString(); {
settings.endGroup(); QString language = TCInstance->getCurrentLanguage();
if (language == "System" || language.trimmed() == "") QStringList langList = QString(language).replace("-", "_").split("_");
{ if (langList.length() >= 1)
QString languageName = QLocale::system().name(); {
QStringList langList = languageName.split("_"); language = langList.at(0);
if (langList.length() >= 1) }
{ return language;
language = langList.at(0); }
}
}
return language;
}

View File

@ -1,35 +1,35 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef GLOBALSTRING_H #ifndef GLOBALSTRING_H
#define GLOBALSTRING_H #define GLOBALSTRING_H
#include <QString> #include <QString>
#include <QMap> #include <QMap>
class GlobalString class GlobalString
{ {
public: public:
GlobalString(); GlobalString();
static QString getString(QString valueStr, bool *ok = 0); static QString getString(QString valueStr, bool *ok = 0);
static QString getLanguageFile(); static QString getLanguageFile();
static QString getLanguage(); static QString getLanguage();
static QMap<QString, QString> getGlobalMap(); static QMap<QString, QString> getGlobalMap();
}; };
#endif // GLOBALSTRING_H #endif // GLOBALSTRING_H

View File

@ -1,40 +1,50 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "IconLoader.h" #include "IconLoader.h"
#include <QIcon> #include <QIcon>
IconLoader::IconLoader() IconLoader::IconLoader()
{ {
} }
QIcon IconLoader::loadingAppIcon() QIcon IconLoader::loadingAppIcon()
{ {
QIcon appIcon; QIcon appIcon;
appIcon.addFile(":/img/5sync-16.png", QSize(16, 16)); appIcon.addFile(":/img/5sync-16.png", QSize(16, 16));
appIcon.addFile(":/img/5sync-24.png", QSize(24, 24)); appIcon.addFile(":/img/5sync-24.png", QSize(24, 24));
appIcon.addFile(":/img/5sync-32.png", QSize(32, 32)); appIcon.addFile(":/img/5sync-32.png", QSize(32, 32));
appIcon.addFile(":/img/5sync-40.png", QSize(40, 40)); appIcon.addFile(":/img/5sync-40.png", QSize(40, 40));
appIcon.addFile(":/img/5sync-48.png", QSize(48, 48)); appIcon.addFile(":/img/5sync-48.png", QSize(48, 48));
appIcon.addFile(":/img/5sync-64.png", QSize(64, 64)); appIcon.addFile(":/img/5sync-64.png", QSize(64, 64));
appIcon.addFile(":/img/5sync-96.png", QSize(96, 96)); appIcon.addFile(":/img/5sync-96.png", QSize(96, 96));
appIcon.addFile(":/img/5sync-128.png", QSize(128, 128)); appIcon.addFile(":/img/5sync-128.png", QSize(128, 128));
appIcon.addFile(":/img/5sync-256.png", QSize(256, 256)); appIcon.addFile(":/img/5sync-256.png", QSize(256, 256));
return appIcon; return appIcon;
} }
QIcon IconLoader::loadingPointmakerIcon()
{
QIcon pointmakerIcon;
pointmakerIcon.addFile(":/img/pointmaker-8.png", QSize(8, 8));
pointmakerIcon.addFile(":/img/pointmaker-16.png", QSize(16, 16));
pointmakerIcon.addFile(":/img/pointmaker-24.png", QSize(24, 24));
pointmakerIcon.addFile(":/img/pointmaker-32.png", QSize(32, 32));
return pointmakerIcon;
}

View File

@ -1,31 +1,32 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef ICONLOADER_H #ifndef ICONLOADER_H
#define ICONLOADER_H #define ICONLOADER_H
#include <QIcon> #include <QIcon>
class IconLoader class IconLoader
{ {
public: public:
IconLoader(); IconLoader();
static QIcon loadingAppIcon(); static QIcon loadingAppIcon();
}; static QIcon loadingPointmakerIcon();
};
#endif // ICONLOADER_H
#endif // ICONLOADER_H

View File

@ -1,190 +1,219 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2017 Syping * Copyright (C) 2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "ImportDialog.h" #include "ImportDialog.h"
#include "ui_ImportDialog.h" #include "ui_ImportDialog.h"
#include "AppEnv.h" #include "AppEnv.h"
#include <QPainter> #include <QColorDialog>
#include <QPixmap> #include <QMessageBox>
#include <QImage> #include <QPainter>
#include <QDebug> #include <QPixmap>
#include <QImage>
// IMAGES VALUES #include <QDebug>
#define snapmaticResolutionW 960 #include <QRgb>
#define snapmaticResolutionH 536
#define snapmaticAvatarResolution 470 // IMAGES VALUES
#define snapmaticAvatarPlacementW 145 #define snapmaticResolutionW 960
#define snapmaticAvatarPlacementH 66 #define snapmaticResolutionH 536
#define snapmaticAvatarResolution 470
ImportDialog::ImportDialog(QWidget *parent) : #define snapmaticAvatarPlacementW 145
QDialog(parent), #define snapmaticAvatarPlacementH 66
ui(new Ui::ImportDialog)
{ ImportDialog::ImportDialog(QWidget *parent) :
ui->setupUi(this); QDialog(parent),
doImport = false; ui(new Ui::ImportDialog)
avatarAreaImage = QImage(":/img/avatarareaimport.png"); {
ui->setupUi(this);
if (QIcon::hasThemeIcon("dialog-ok")) importAgreed = false;
{ insideAvatarZone = false;
ui->cmdOK->setIcon(QIcon::fromTheme("dialog-ok")); avatarAreaImage = QImage(":/img/avatarareaimport.png");
} selectedColour = QColor::fromRgb(0, 0, 0, 255);
if (QIcon::hasThemeIcon("dialog-cancel"))
{ if (QIcon::hasThemeIcon("dialog-ok"))
ui->cmdCancel->setIcon(QIcon::fromTheme("dialog-cancel")); {
} ui->cmdOK->setIcon(QIcon::fromTheme("dialog-ok"));
}
ui->rbKeep->setChecked(true); if (QIcon::hasThemeIcon("dialog-cancel"))
{
qreal screenRatio = AppEnv::screenRatio(); ui->cmdCancel->setIcon(QIcon::fromTheme("dialog-cancel"));
snapmaticResolutionLW = 430 * screenRatio; }
snapmaticResolutionLH = 240 * screenRatio;
setMinimumSize(430 * screenRatio, 380 * screenRatio); ui->cbIgnore->setChecked(false);
setMaximumSize(430 * screenRatio, 380 * screenRatio); ui->labColour->setText(tr("Background Colour: <span style=\"color: %1\">%1</span>").arg(selectedColour.name()));
setFixedSize(430 * screenRatio, 380 * screenRatio);
ui->vlButtom->setSpacing(6 * screenRatio); qreal screenRatio = AppEnv::screenRatio();
ui->vlButtom->setContentsMargins(9 * screenRatio, 6 * screenRatio, 9 * screenRatio, 9 * screenRatio); snapmaticResolutionLW = 430 * screenRatio;
} snapmaticResolutionLH = 240 * screenRatio;
setMinimumSize(430 * screenRatio, 380 * screenRatio);
ImportDialog::~ImportDialog() setMaximumSize(430 * screenRatio, 380 * screenRatio);
{ setFixedSize(430 * screenRatio, 380 * screenRatio);
delete ui; ui->vlButtom->setSpacing(6 * screenRatio);
} ui->vlButtom->setContentsMargins(9 * screenRatio, 6 * screenRatio, 9 * screenRatio, 9 * screenRatio);
}
void ImportDialog::processImage()
{ ImportDialog::~ImportDialog()
QImage snapmaticImage = workImage; {
QPixmap snapmaticPixmap(snapmaticResolutionW, snapmaticResolutionH); delete ui;
snapmaticPixmap.fill(Qt::black); }
QPainter snapmaticPainter(&snapmaticPixmap);
if (ui->cbAvatar->isChecked()) void ImportDialog::processImage()
{ {
// Avatar mode QImage snapmaticImage = workImage;
int diffWidth = 0; QPixmap snapmaticPixmap(snapmaticResolutionW, snapmaticResolutionH);
int diffHeight = 0; snapmaticPixmap.fill(selectedColour);
if (ui->rbKeep->isChecked()) QPainter snapmaticPainter(&snapmaticPixmap);
{ if (insideAvatarZone)
snapmaticImage = snapmaticImage.scaled(snapmaticAvatarResolution, snapmaticAvatarResolution, Qt::KeepAspectRatio, Qt::SmoothTransformation); {
if (snapmaticImage.width() > snapmaticImage.height()) // Avatar mode
{ int diffWidth = 0;
diffHeight = snapmaticAvatarResolution - snapmaticImage.height(); int diffHeight = 0;
diffHeight = diffHeight / 2; if (!ui->cbIgnore->isChecked())
} {
else if (snapmaticImage.width() < snapmaticImage.height()) snapmaticImage = snapmaticImage.scaled(snapmaticAvatarResolution, snapmaticAvatarResolution, Qt::KeepAspectRatio, Qt::SmoothTransformation);
{ if (snapmaticImage.width() > snapmaticImage.height())
diffWidth = snapmaticAvatarResolution - snapmaticImage.width(); {
diffWidth = diffWidth / 2; diffHeight = snapmaticAvatarResolution - snapmaticImage.height();
} diffHeight = diffHeight / 2;
} }
else else if (snapmaticImage.width() < snapmaticImage.height())
{ {
snapmaticImage = snapmaticImage.scaled(snapmaticAvatarResolution, snapmaticAvatarResolution, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); diffWidth = snapmaticAvatarResolution - snapmaticImage.width();
} diffWidth = diffWidth / 2;
snapmaticPainter.drawImage(snapmaticAvatarPlacementW + diffWidth, snapmaticAvatarPlacementH + diffHeight, snapmaticImage); }
imageTitle = "Custom Avatar"; }
} else
else {
{ snapmaticImage = snapmaticImage.scaled(snapmaticAvatarResolution, snapmaticAvatarResolution, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
// Picture mode }
int diffWidth = 0; snapmaticPainter.drawImage(snapmaticAvatarPlacementW + diffWidth, snapmaticAvatarPlacementH + diffHeight, snapmaticImage);
int diffHeight = 0; imageTitle = "Custom Avatar";
if (ui->rbKeep->isChecked()) }
{ else
snapmaticImage = snapmaticImage.scaled(snapmaticResolutionW, snapmaticResolutionH, Qt::KeepAspectRatio, Qt::SmoothTransformation); {
if (snapmaticImage.width() != snapmaticResolutionW) // Picture mode
{ int diffWidth = 0;
diffWidth = snapmaticResolutionW - snapmaticImage.width(); int diffHeight = 0;
diffWidth = diffWidth / 2; if (!ui->cbIgnore->isChecked())
} {
else if (snapmaticImage.height() != snapmaticResolutionH) snapmaticImage = snapmaticImage.scaled(snapmaticResolutionW, snapmaticResolutionH, Qt::KeepAspectRatio, Qt::SmoothTransformation);
{ if (snapmaticImage.width() != snapmaticResolutionW)
diffHeight = snapmaticResolutionH - snapmaticImage.height(); {
diffHeight = diffHeight / 2; diffWidth = snapmaticResolutionW - snapmaticImage.width();
} diffWidth = diffWidth / 2;
} }
else else if (snapmaticImage.height() != snapmaticResolutionH)
{ {
snapmaticImage = snapmaticImage.scaled(snapmaticResolutionW, snapmaticResolutionH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); diffHeight = snapmaticResolutionH - snapmaticImage.height();
} diffHeight = diffHeight / 2;
snapmaticPainter.drawImage(0 + diffWidth, 0 + diffHeight, snapmaticImage); }
imageTitle = "Custom Picture"; }
} else
snapmaticPainter.end(); {
newImage = snapmaticPixmap.toImage(); snapmaticImage = snapmaticImage.scaled(snapmaticResolutionW, snapmaticResolutionH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
ui->labPicture->setPixmap(snapmaticPixmap.scaled(snapmaticResolutionLW, snapmaticResolutionLH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); }
} snapmaticPainter.drawImage(0 + diffWidth, 0 + diffHeight, snapmaticImage);
imageTitle = "Custom Picture";
QImage ImportDialog::image() }
{ snapmaticPainter.end();
return newImage; newImage = snapmaticPixmap.toImage();
} ui->labPicture->setPixmap(snapmaticPixmap.scaled(snapmaticResolutionLW, snapmaticResolutionLH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
}
void ImportDialog::setImage(const QImage &image_)
{ QImage ImportDialog::image()
workImage = image_; {
if (workImage.width() == workImage.height()) return newImage;
{ }
ui->cbAvatar->setChecked(true);
} void ImportDialog::setImage(const QImage &image_)
processImage(); {
} workImage = image_;
if (workImage.width() == workImage.height())
bool ImportDialog::isDoImport() {
{ insideAvatarZone = true;
return doImport; ui->cbAvatar->setChecked(true);
} }
processImage();
QString ImportDialog::getImageTitle() }
{
return imageTitle; bool ImportDialog::isImportAgreed()
} {
return importAgreed;
void ImportDialog::on_rbIgnore_clicked() }
{
processImage(); QString ImportDialog::getImageTitle()
} {
return imageTitle;
void ImportDialog::on_rbKeep_clicked() }
{
processImage(); void ImportDialog::on_cbIgnore_toggled(bool checked)
} {
Q_UNUSED(checked)
void ImportDialog::on_cbAvatar_clicked() processImage();
{ }
processImage();
} void ImportDialog::on_cbAvatar_toggled(bool checked)
{
void ImportDialog::on_cmdCancel_clicked() if (workImage.width() == workImage.height() && !checked)
{ {
close(); if (QMessageBox::No == QMessageBox::warning(this, tr("Snapmatic Avatar Zone"), tr("Are you sure to use a square image outside of the Avatar Zone?\nWhen you want to use it as Avatar the image will be detached!"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No))
} {
ui->cbAvatar->setChecked(true);
void ImportDialog::on_cmdOK_clicked() insideAvatarZone = true;
{ return;
doImport = true; }
close(); }
} insideAvatarZone = ui->cbAvatar->isChecked();
processImage();
void ImportDialog::on_labPicture_labelPainted() }
{
if (ui->cbAvatar->isChecked()) void ImportDialog::on_cmdCancel_clicked()
{ {
QPainter labelPainter(ui->labPicture); close();
labelPainter.drawImage(0, 0, avatarAreaImage.scaled(snapmaticResolutionLW, snapmaticResolutionLH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); }
labelPainter.end();
} void ImportDialog::on_cmdOK_clicked()
} {
importAgreed = true;
close();
}
void ImportDialog::on_labPicture_labelPainted()
{
if (insideAvatarZone)
{
QImage avatarAreaFinalImage(avatarAreaImage);
if (selectedColour.lightness() > 127)
{
avatarAreaFinalImage.setColor(1, qRgb(0, 0, 0));
}
QPainter labelPainter(ui->labPicture);
labelPainter.drawImage(0, 0, avatarAreaFinalImage.scaled(snapmaticResolutionLW, snapmaticResolutionLH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
labelPainter.end();
}
}
void ImportDialog::on_cmdColourChange_clicked()
{
QColor newSelectedColour = QColorDialog::getColor(selectedColour, this, tr("Select Colour..."));
if (newSelectedColour.isValid())
{
selectedColour = newSelectedColour;
ui->labColour->setText(tr("Background Colour: <span style=\"color: %1\">%1</span>").arg(selectedColour.name()));
processImage();
}
}

View File

@ -1,60 +1,62 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2017 Syping * Copyright (C) 2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef IMPORTDIALOG_H #ifndef IMPORTDIALOG_H
#define IMPORTDIALOG_H #define IMPORTDIALOG_H
#include <QDialog> #include <QDialog>
namespace Ui { namespace Ui {
class ImportDialog; class ImportDialog;
} }
class ImportDialog : public QDialog class ImportDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ImportDialog(QWidget *parent = 0); explicit ImportDialog(QWidget *parent = 0);
~ImportDialog(); ~ImportDialog();
QImage image(); QImage image();
QString getImageTitle(); QString getImageTitle();
void setImage(const QImage &image); void setImage(const QImage &image);
bool isDoImport(); bool isImportAgreed();
private slots: private slots:
void processImage(); void processImage();
void on_rbIgnore_clicked(); void on_cbIgnore_toggled(bool checked);
void on_rbKeep_clicked(); void on_cbAvatar_toggled(bool checked);
void on_cbAvatar_clicked(); void on_cmdCancel_clicked();
void on_cmdCancel_clicked(); void on_cmdOK_clicked();
void on_cmdOK_clicked(); void on_labPicture_labelPainted();
void on_labPicture_labelPainted(); void on_cmdColourChange_clicked();
private: private:
Ui::ImportDialog *ui; Ui::ImportDialog *ui;
QImage avatarAreaImage; QImage avatarAreaImage;
QString imageTitle; QString imageTitle;
QImage workImage; QImage workImage;
QImage newImage; QImage newImage;
bool doImport; QColor selectedColour;
int snapmaticResolutionLW; bool insideAvatarZone;
int snapmaticResolutionLH; bool importAgreed;
}; int snapmaticResolutionLW;
int snapmaticResolutionLH;
#endif // IMPORTDIALOG_H };
#endif // IMPORTDIALOG_H

View File

@ -1,187 +1,239 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>ImportDialog</class> <class>ImportDialog</class>
<widget class="QDialog" name="ImportDialog"> <widget class="QDialog" name="ImportDialog">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>430</width> <width>430</width>
<height>380</height> <height>380</height>
</rect> </rect>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>430</width> <width>430</width>
<height>380</height> <height>380</height>
</size> </size>
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>430</width> <width>430</width>
<height>380</height> <height>380</height>
</size> </size>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Import...</string> <string>Import...</string>
</property> </property>
<property name="modal"> <property name="modal">
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" name="vlImport"> <layout class="QVBoxLayout" name="vlImport">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="UiModLabel" name="labPicture"> <widget class="UiModLabel" name="labPicture">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>430</width> <width>430</width>
<height>240</height> <height>240</height>
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QFrame" name="buttomFrame"> <widget class="QFrame" name="buttomFrame">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding"> <sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Plain</enum> <enum>QFrame::Plain</enum>
</property> </property>
<property name="lineWidth"> <property name="lineWidth">
<number>0</number> <number>0</number>
</property> </property>
<layout class="QVBoxLayout" name="vlButtom"> <layout class="QVBoxLayout" name="vlButtom">
<property name="leftMargin"> <property name="leftMargin">
<number>9</number> <number>9</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>6</number> <number>6</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>9</number> <number>9</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>9</number> <number>9</number>
</property> </property>
<item> <item>
<widget class="QGroupBox" name="gbSettings"> <widget class="QGroupBox" name="gbSettings">
<property name="title"> <property name="title">
<string>Settings</string> <string>Settings</string>
</property> </property>
<layout class="QGridLayout" name="gdSettings"> <layout class="QVBoxLayout" name="verticalLayout">
<item row="1" column="0"> <item>
<widget class="QRadioButton" name="rbKeep"> <layout class="QHBoxLayout" name="hlColor">
<property name="text"> <item>
<string>&amp;Keep Aspect Ratio</string> <widget class="QLabel" name="labColour">
</property> <property name="text">
</widget> <string>Background Colour: &lt;span style=&quot;color: %1&quot;&gt;%1&lt;/span&gt;</string>
</item> </property>
<item row="1" column="1"> </widget>
<widget class="QRadioButton" name="rbIgnore"> </item>
<property name="text"> <item>
<string>&amp;Ignore Aspect Ratio</string> <widget class="QToolButton" name="cmdColourChange">
</property> <property name="text">
</widget> <string>...</string>
</item> </property>
<item row="0" column="0"> </widget>
<widget class="QCheckBox" name="cbAvatar"> </item>
<property name="text"> <item>
<string>&amp;Avatar</string> <spacer name="hsColourSpacer">
</property> <property name="orientation">
</widget> <enum>Qt::Horizontal</enum>
</item> </property>
</layout> <property name="sizeHint" stdset="0">
</widget> <size>
</item> <width>0</width>
<item> <height>0</height>
<spacer name="vsDialog"> </size>
<property name="orientation"> </property>
<enum>Qt::Vertical</enum> </spacer>
</property> </item>
<property name="sizeHint" stdset="0"> </layout>
<size> </item>
<width>0</width> <item>
<height>0</height> <layout class="QHBoxLayout" name="hlCheckboxes">
</size> <item>
</property> <widget class="QCheckBox" name="cbAvatar">
</spacer> <property name="sizePolicy">
</item> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<item> <horstretch>0</horstretch>
<layout class="QHBoxLayout" name="hlButtons"> <verstretch>0</verstretch>
<item> </sizepolicy>
<spacer name="hsButtons"> </property>
<property name="orientation"> <property name="text">
<enum>Qt::Horizontal</enum> <string>Avatar</string>
</property> </property>
<property name="sizeHint" stdset="0"> </widget>
<size> </item>
<width>0</width> <item>
<height>0</height> <widget class="QCheckBox" name="cbIgnore">
</size> <property name="sizePolicy">
</property> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
</spacer> <horstretch>0</horstretch>
</item> <verstretch>0</verstretch>
<item> </sizepolicy>
<widget class="QPushButton" name="cmdOK"> </property>
<property name="sizePolicy"> <property name="text">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <string>Ignore Aspect Ratio</string>
<horstretch>0</horstretch> </property>
<verstretch>0</verstretch> </widget>
</sizepolicy> </item>
</property> </layout>
<property name="text"> </item>
<string>&amp;OK</string> </layout>
</property> </widget>
</widget> </item>
</item> <item>
<item> <spacer name="vsDialog">
<widget class="QPushButton" name="cmdCancel"> <property name="orientation">
<property name="sizePolicy"> <enum>Qt::Vertical</enum>
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> </property>
<horstretch>0</horstretch> <property name="sizeHint" stdset="0">
<verstretch>0</verstretch> <size>
</sizepolicy> <width>0</width>
</property> <height>0</height>
<property name="text"> </size>
<string>&amp;Cancel</string> </property>
</property> </spacer>
</widget> </item>
</item> <item>
</layout> <layout class="QHBoxLayout" name="hlButtons">
</item> <item>
</layout> <spacer name="hsButtons">
</widget> <property name="orientation">
</item> <enum>Qt::Horizontal</enum>
</layout> </property>
</widget> <property name="sizeHint" stdset="0">
<customwidgets> <size>
<customwidget> <width>0</width>
<class>UiModLabel</class> <height>0</height>
<extends>QLabel</extends> </size>
<header>UiModLabel.h</header> </property>
</customwidget> </spacer>
</customwidgets> </item>
<resources/> <item>
<connections/> <widget class="QPushButton" name="cmdOK">
</ui> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Import picture</string>
</property>
<property name="text">
<string>&amp;OK</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdCancel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Discard picture</string>
</property>
<property name="text">
<string>&amp;Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>UiModLabel</class>
<extends>QLabel</extends>
<header>uimod/UiModLabel.h</header>
<slots>
<signal>mouseMoved()</signal>
<signal>mouseReleased()</signal>
<signal>mousePressed()</signal>
<signal>mouseDoubleClicked()</signal>
</slots>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

76
MapPreviewDialog.cpp Normal file
View File

@ -0,0 +1,76 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2017 Syping
*
* 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.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "MapPreviewDialog.h"
#include "ui_MapPreviewDialog.h"
#include "IconLoader.h"
#include "AppEnv.h"
#include <QPainter>
#include <QDebug>
#ifdef __MINGW32__
#include <cmath>
#endif
MapPreviewDialog::MapPreviewDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::MapPreviewDialog)
{
// Set Window Flags
setWindowFlags(windowFlags()^Qt::WindowContextHelpButtonHint);
ui->setupUi(this);
// DPI calculation
qreal screenRatio = AppEnv::screenRatio();
setMinimumSize(500 * screenRatio, 600 * screenRatio);
setMaximumSize(500 * screenRatio, 600 * screenRatio);
setFixedSize(500 * screenRatio, 600 * screenRatio);
}
MapPreviewDialog::~MapPreviewDialog()
{
delete ui;
}
void MapPreviewDialog::drawPointOnMap(double xpos_d, double ypos_d)
{
qreal screenRatio = AppEnv::screenRatio();
int pointMakerSize = 8 * screenRatio;
QPixmap pointMakerPixmap = IconLoader::loadingPointmakerIcon().pixmap(QSize(pointMakerSize, pointMakerSize));
QSize mapPixelSize = size();
int pointMakerHalfSize = pointMakerSize / 2;
long xpos_ms = std::round(xpos_d);
long ypos_ms = std::round(ypos_d);
double xpos_ma = xpos_ms + 4000;
double ypos_ma = ypos_ms + 4000;
double xrat = (double)mapPixelSize.width() / 10000;
double yrat = (double)mapPixelSize.height() / 12000;
long xpos_mp = std::round(xpos_ma * xrat);
long ypos_mp = std::round(ypos_ma * yrat);
long xpos_pr = xpos_mp - pointMakerHalfSize;
long ypos_pr = ypos_mp + pointMakerHalfSize;
QPixmap mapPixmap(mapPixelSize);
QPainter mapPainter(&mapPixmap);
mapPainter.drawPixmap(0, 0, mapPixelSize.width(), mapPixelSize.height(), QPixmap(":/img/mappreview.jpg").scaled(mapPixelSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
mapPainter.drawPixmap(xpos_pr, mapPixelSize.height() - ypos_pr, pointMakerSize, pointMakerSize, pointMakerPixmap);
mapPainter.end();
ui->labPicture->setPixmap(mapPixmap);
}

41
MapPreviewDialog.h Normal file
View File

@ -0,0 +1,41 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2017 Syping
*
* 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.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef MAPPREVIEWDIALOG_H
#define MAPPREVIEWDIALOG_H
#include <QDialog>
namespace Ui {
class MapPreviewDialog;
}
class MapPreviewDialog : public QDialog
{
Q_OBJECT
public:
explicit MapPreviewDialog(QWidget *parent = 0);
void drawPointOnMap(double x, double y);
~MapPreviewDialog();
private:
Ui::MapPreviewDialog *ui;
};
#endif // MAPPREVIEWDIALOG_H

71
MapPreviewDialog.ui Normal file
View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MapPreviewDialog</class>
<widget class="QDialog" name="MapPreviewDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>600</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>500</width>
<height>600</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>500</width>
<height>600</height>
</size>
</property>
<property name="windowTitle">
<string>Snapmatic Map Viewer</string>
</property>
<layout class="QVBoxLayout" name="vlMapPreview">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="UiModLabel" name="labPicture">
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>UiModLabel</class>
<extends>QLabel</extends>
<header>uimod/UiModLabel.h</header>
<slots>
<signal>mouseMoved()</signal>
<signal>mouseReleased()</signal>
<signal>mousePressed()</signal>
<signal>mouseDoubleClicked()</signal>
</slots>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -1,457 +1,439 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "OptionsDialog.h" #include "OptionsDialog.h"
#include "ui_OptionsDialog.h" #include "ui_OptionsDialog.h"
#include "StandardPaths.h" #include "TranslationClass.h"
#include "UserInterface.h" #include "StandardPaths.h"
#include "AppEnv.h" #include "UserInterface.h"
#include "config.h" #include "AppEnv.h"
#include <QDesktopWidget> #include "config.h"
#include <QApplication> #include <QStringBuilder>
#include <QFileDialog> #include <QDesktopWidget>
#include <QMessageBox> #include <QApplication>
#include <QStringList> #include <QFileDialog>
#include <QLocale> #include <QMessageBox>
#include <QString> #include <QStringList>
#include <QDebug> #include <QLocale>
#include <QList> #include <QString>
#include <QDir> #include <QDebug>
#include <QList>
OptionsDialog::OptionsDialog(ProfileDatabase *profileDB, QWidget *parent) : #include <QDir>
QDialog(parent), profileDB(profileDB),
ui(new Ui::OptionsDialog) OptionsDialog::OptionsDialog(ProfileDatabase *profileDB, QWidget *parent) :
{ QDialog(parent), profileDB(profileDB),
// Set Window Flags ui(new Ui::OptionsDialog)
setWindowFlags(windowFlags()^Qt::WindowContextHelpButtonHint); {
// Set Window Flags
// Setup User Interface setWindowFlags(windowFlags()^Qt::WindowContextHelpButtonHint);
ui->setupUi(this);
ui->tabWidget->setCurrentIndex(0); // Setup User Interface
ui->labPicCustomRes->setVisible(false); ui->setupUi(this);
ui->tabWidget->setCurrentIndex(0);
QRect desktopResolution = QApplication::desktop()->screenGeometry(parent); ui->labPicCustomRes->setVisible(false);
int desktopSizeWidth = desktopResolution.width();
int desktopSizeHeight = desktopResolution.height(); QRect desktopResolution = qApp->desktop()->screenGeometry(parent);
aspectRatio = Qt::KeepAspectRatio; int desktopSizeWidth = desktopResolution.width();
defExportSize = QSize(960, 536); int desktopSizeHeight = desktopResolution.height();
cusExportSize = defExportSize; aspectRatio = Qt::KeepAspectRatio;
defaultQuality = 100; defExportSize = QSize(960, 536);
customQuality = 100; cusExportSize = defExportSize;
contentMode = 0; defaultQuality = 100;
settings = new QSettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); customQuality = 100;
contentMode = 0;
percentString = ui->labPicQuality->text(); settings = new QSettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
ui->labPicQuality->setText(percentString.arg(QString::number(defaultQuality)));
ui->rbPicDesktopRes->setText(ui->rbPicDesktopRes->text().arg(QString::number(desktopSizeWidth), QString::number(desktopSizeHeight))); percentString = ui->labPicQuality->text();
ui->rbPicDefaultRes->setText(ui->rbPicDefaultRes->text().arg(QString::number(defExportSize.width()), QString::number(defExportSize.height()))); ui->labPicQuality->setText(percentString.arg(QString::number(defaultQuality)));
ui->rbPicDesktopRes->setText(ui->rbPicDesktopRes->text().arg(QString::number(desktopSizeWidth), QString::number(desktopSizeHeight)));
if (QIcon::hasThemeIcon("dialog-ok")) ui->rbPicDefaultRes->setText(ui->rbPicDefaultRes->text().arg(QString::number(defExportSize.width()), QString::number(defExportSize.height())));
{
ui->cmdOK->setIcon(QIcon::fromTheme("dialog-ok")); if (QIcon::hasThemeIcon("dialog-ok"))
} {
if (QIcon::hasThemeIcon("dialog-cancel")) ui->cmdOK->setIcon(QIcon::fromTheme("dialog-ok"));
{ }
ui->cmdCancel->setIcon(QIcon::fromTheme("dialog-cancel")); if (QIcon::hasThemeIcon("dialog-cancel"))
} {
ui->cmdCancel->setIcon(QIcon::fromTheme("dialog-cancel"));
// DPI calculation }
qreal screenRatio = AppEnv::screenRatio();
resize(435 * screenRatio, 405 * screenRatio); // DPI calculation
qreal screenRatio = AppEnv::screenRatio();
setupTreeWidget(); resize(435 * screenRatio, 405 * screenRatio);
setupLanguageBox();
setupRadioButtons(); setupTreeWidget();
setupDefaultProfile(); setupLanguageBox();
setupPictureSettings(); setupRadioButtons();
setupCustomGTAFolder(); setupDefaultProfile();
setupSnapmaticPictureViewer(); setupPictureSettings();
setupCustomGTAFolder();
#ifdef GTA5SYNC_DISABLED setupSnapmaticPictureViewer();
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabSync));
#endif #ifdef GTA5SYNC_DISABLED
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabSync));
this->setWindowTitle(windowTitle().arg(GTA5SYNC_APPSTR)); #endif
}
this->setWindowTitle(windowTitle().arg(GTA5SYNC_APPSTR));
OptionsDialog::~OptionsDialog() }
{
delete settings; OptionsDialog::~OptionsDialog()
foreach(QTreeWidgetItem *playerItem, playerItems) {
{ delete settings;
delete playerItem; foreach(QTreeWidgetItem *playerItem, playerItems)
} {
delete ui; delete playerItem;
} }
delete ui;
void OptionsDialog::setupTreeWidget() }
{
foreach(const QString &playerIDStr, profileDB->getPlayers()) void OptionsDialog::setupTreeWidget()
{ {
bool ok; foreach(const QString &playerIDStr, profileDB->getPlayers())
int playerID = playerIDStr.toInt(&ok); {
if (ok) bool ok;
{ int playerID = playerIDStr.toInt(&ok);
QString playerName = profileDB->getPlayerName(playerID); if (ok)
{
QStringList playerTreeViewList; QString playerName = profileDB->getPlayerName(playerID);
playerTreeViewList << playerIDStr;
playerTreeViewList << playerName; QStringList playerTreeViewList;
playerTreeViewList << playerIDStr;
QTreeWidgetItem *playerItem = new QTreeWidgetItem(playerTreeViewList); playerTreeViewList << playerName;
ui->twPlayers->addTopLevelItem(playerItem);
playerItems.append(playerItem); QTreeWidgetItem *playerItem = new QTreeWidgetItem(playerTreeViewList);
} ui->twPlayers->addTopLevelItem(playerItem);
} playerItems += playerItem;
ui->twPlayers->sortItems(1, Qt::AscendingOrder); }
} }
ui->twPlayers->sortItems(1, Qt::AscendingOrder);
void OptionsDialog::setupLanguageBox() }
{
settings->beginGroup("Interface"); void OptionsDialog::setupLanguageBox()
currentLanguage = settings->value("Language","System").toString(); {
settings->endGroup(); settings->beginGroup("Interface");
currentLanguage = settings->value("Language","System").toString();
QStringList langList = QLocale::system().name().split("_"); settings->endGroup();
if (langList.length() > 0)
{ QString cbSysStr = tr("%1 (Next Closest Language)", "First language a person can talk with a different person/application. \"Native\" or \"Not Native\".").arg(tr("System",
QString cbSysStr = tr("%1 (%2 if available)", "System like PC System = %1, System Language like Deutsch = %2").arg(tr("System", "System in context of System default"));
"System like PC System"), QLocale::languageToString(QLocale(langList.at(0)).language())); ui->cbLanguage->addItem(cbSysStr, "System");
ui->cbLanguage->addItem(cbSysStr, "System");
} QStringList availableLanguages;
availableLanguages << QString("en_GB");
QString cbEngStr = "English (English) [en]"; #ifndef GTA5SYNC_QCONF
ui->cbLanguage->addItem(QIcon::fromTheme("flag-us"), cbEngStr, "en"); availableLanguages << TCInstance->listTranslations(AppEnv::getExLangFolder());
if (currentLanguage == "en") #endif
{ availableLanguages << TCInstance->listTranslations(AppEnv::getInLangFolder());
#if QT_VERSION >= 0x050000 availableLanguages.removeDuplicates();
ui->cbLanguage->setCurrentText(cbEngStr); availableLanguages.sort();
#else
int indexOfEnglish = ui->cbLanguage->findText(cbEngStr); foreach(const QString &lang, availableLanguages)
ui->cbLanguage->setCurrentIndex(indexOfEnglish); {
#endif QLocale langLocale(lang);
} QString cbLangStr = langLocale.nativeLanguageName() % " (" % langLocale.nativeCountryName() % ") [" % lang % "]";
QDir langDir; QString langIconStr = "flag-" % TranslationClass::getCountryCode(langLocale);
langDir.setNameFilters(QStringList("gta5sync_*.qm"));
langDir.setPath(AppEnv::getLangFolder()); ui->cbLanguage->addItem(QIcon::fromTheme(langIconStr), cbLangStr, lang);
QStringList langFiles; if (currentLanguage == lang)
langFiles << langDir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::NoSort); {
langDir.setPath(":/tr"); #if QT_VERSION >= 0x050000
langFiles << langDir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::NoSort); ui->cbLanguage->setCurrentText(cbLangStr);
langFiles.removeDuplicates(); #else
int indexOfLang = ui->cbLanguage->findText(cbLangStr);
foreach(const QString &langFile, langFiles) ui->cbLanguage->setCurrentIndex(indexOfLang);
{ #endif
QString lang = langFile; }
lang.remove("gta5sync_"); }
lang.remove(".qm"); }
QLocale langLocale(lang); void OptionsDialog::setupRadioButtons()
QString languageNameInternational = QLocale::languageToString(langLocale.language()); {
QString languageNameNative = langLocale.nativeLanguageName(); bool contentModeOk;
settings->beginGroup("Profile");
QString cbLangStr = languageNameNative + " (" + languageNameInternational + ") [" + lang + "]"; contentMode = settings->value("ContentMode", 0).toInt(&contentModeOk);
QString langIconStr = "flag-" + lang; settings->endGroup();
ui->cbLanguage->addItem(QIcon::fromTheme(langIconStr), cbLangStr, lang); if (contentModeOk)
if (currentLanguage == lang) {
{ if (contentMode == 0)
#if QT_VERSION >= 0x050000 {
ui->cbLanguage->setCurrentText(cbLangStr); ui->rbOpenWithSC->setChecked(true);
#else }
int indexOfLang = ui->cbLanguage->findText(cbLangStr); else if (contentMode == 1)
ui->cbLanguage->setCurrentIndex(indexOfLang); {
#endif ui->rbOpenWithDC->setChecked(true);
} }
} else if (contentMode == 2)
} {
ui->rbSelectWithSC->setChecked(true);
void OptionsDialog::setupRadioButtons() }
{ }
bool contentModeOk; }
settings->beginGroup("Profile");
contentMode = settings->value("ContentMode", 0).toInt(&contentModeOk); void OptionsDialog::on_cmdOK_clicked()
settings->endGroup(); {
applySettings();
if (contentModeOk) close();
{ }
if (contentMode == 0)
{ void OptionsDialog::applySettings()
ui->rbOpenWithSC->setChecked(true); {
} settings->beginGroup("Interface");
else if (contentMode == 1) #if QT_VERSION >= 0x050000
{ settings->setValue("Language", ui->cbLanguage->currentData());
ui->rbOpenWithDC->setChecked(true); #else
} settings->setValue("Language", ui->cbLanguage->itemData(ui->cbLanguage->currentIndex()));
else if (contentMode == 2) #endif
{ #ifdef GTA5SYNC_WIN
ui->rbSelectWithSC->setChecked(true); #if QT_VERSION >= 0x050200
} settings->setValue("NavigationBar", ui->cbSnapmaticNavigationBar->isChecked());
} #endif
} #endif
settings->endGroup();
void OptionsDialog::on_cmdOK_clicked()
{ settings->beginGroup("Profile");
applySettings(); int newContentMode = 0;
close(); if (ui->rbOpenWithSC->isChecked())
} {
newContentMode = 0;
void OptionsDialog::applySettings() }
{ else if (ui->rbOpenWithDC->isChecked())
settings->beginGroup("Interface"); {
#if QT_VERSION >= 0x050000 newContentMode = 1;
settings->setValue("Language", ui->cbLanguage->currentData()); }
#else else if (ui->rbSelectWithSC->isChecked())
settings->setValue("Language", ui->cbLanguage->itemData(ui->cbLanguage->currentIndex())); {
#endif newContentMode = 2;
#ifdef GTA5SYNC_WIN }
#if QT_VERSION >= 0x050200 settings->setValue("ContentMode", newContentMode);
settings->setValue("NavigationBar", ui->cbSnapmaticNavigationBar->isChecked()); #if QT_VERSION >= 0x050000
#endif settings->setValue("Default", ui->cbProfiles->currentData());
#endif #else
settings->endGroup(); settings->setValue("Default", ui->cbProfiles->itemData(ui->cbProfiles->currentIndex()));
#endif
settings->beginGroup("Profile"); settings->endGroup();
int newContentMode = 0;
if (ui->rbOpenWithSC->isChecked()) settings->beginGroup("Pictures");
{ if (ui->cbPicCustomQuality->isChecked())
newContentMode = 0; {
} settings->setValue("CustomQuality", ui->hsPicQuality->value());
else if (ui->rbOpenWithDC->isChecked()) }
{ settings->setValue("CustomQualityEnabled", ui->cbPicCustomQuality->isChecked());
newContentMode = 1; QString sizeMode = "Default";
} if (ui->rbPicDesktopRes->isChecked())
else if (ui->rbSelectWithSC->isChecked()) {
{ sizeMode = "Desktop";
newContentMode = 2; }
} else if (ui->rbPicCustomRes->isChecked())
settings->setValue("ContentMode", newContentMode); {
#if QT_VERSION >= 0x050000 sizeMode = "Custom";
settings->setValue("Default", ui->cbProfiles->currentData()); settings->setValue("CustomSize", QSize(ui->sbPicExportWidth->value(), ui->sbPicExportHeight->value()));
#else }
settings->setValue("Default", ui->cbProfiles->itemData(ui->cbProfiles->currentIndex())); settings->setValue("ExportSizeMode", sizeMode);
#endif settings->setValue("AspectRatio", aspectRatio);
settings->endGroup(); settings->endGroup();
settings->beginGroup("Pictures"); bool forceCustomFolder = ui->cbForceCustomFolder->isChecked();
if (ui->cbPicCustomQuality->isChecked()) settings->beginGroup("dir");
{ settings->setValue("dir", ui->txtFolder->text());
settings->setValue("CustomQuality", ui->hsPicQuality->value()); settings->setValue("force", forceCustomFolder);
} settings->endGroup();
settings->setValue("CustomQualityEnabled", ui->cbPicCustomQuality->isChecked());
QString sizeMode = "Default"; #if QT_VERSION >= 0x050000
if (ui->rbPicDesktopRes->isChecked()) bool languageChanged = ui->cbLanguage->currentData().toString() != currentLanguage;
{ #else
sizeMode = "Desktop"; bool languageChanged = ui->cbLanguage->itemData(ui->cbLanguage->currentIndex()).toString() != currentLanguage;
} #endif
else if (ui->rbPicCustomRes->isChecked()) if (languageChanged)
{ {
sizeMode = "Custom"; TCInstance->unloadTranslation(qApp);
settings->setValue("CustomSize", QSize(ui->sbPicExportWidth->value(), ui->sbPicExportHeight->value())); TCInstance->initUserLanguage();
} TCInstance->loadTranslation(qApp);
settings->setValue("ExportSizeMode", sizeMode); }
settings->setValue("AspectRatio", aspectRatio);
settings->endGroup(); #if QT_VERSION >= 0x050000
emit settingsApplied(newContentMode, ui->cbLanguage->currentData().toString());
bool forceCustomFolder = ui->cbForceCustomFolder->isChecked(); #else
settings->beginGroup("dir"); emit settingsApplied(newContentMode, ui->cbLanguage->itemData(ui->cbLanguage->currentIndex()).toString());
settings->setValue("dir", ui->txtFolder->text()); #endif
settings->setValue("force", forceCustomFolder);
settings->endGroup(); if ((forceCustomFolder && ui->txtFolder->text() != currentCFolder) || (forceCustomFolder != currentFFolder && forceCustomFolder))
{
#if QT_VERSION >= 0x050000 QMessageBox::information(this, tr("%1", "%1").arg(GTA5SYNC_APPSTR), tr("The new Custom Folder will initialise after you restart %1.").arg(GTA5SYNC_APPSTR));
emit settingsApplied(newContentMode, ui->cbLanguage->currentData().toString()); }
#else }
emit settingsApplied(newContentMode, ui->cbLanguage->itemData(ui->cbLanguage->currentIndex()).toString());
#endif void OptionsDialog::setupDefaultProfile()
{
#if QT_VERSION >= 0x050000 settings->beginGroup("Profile");
bool languageChanged = ui->cbLanguage->currentData().toString() != currentLanguage; defaultProfile = settings->value("Default", "").toString();
#else settings->endGroup();
bool languageChanged = ui->cbLanguage->itemData(ui->cbLanguage->currentIndex()).toString() != currentLanguage;
#endif QString cbNoneStr = tr("No Profile", "No Profile, as default");
ui->cbProfiles->addItem(cbNoneStr, "");
if ((forceCustomFolder && ui->txtFolder->text() != currentCFolder) || (forceCustomFolder != currentFFolder && forceCustomFolder)) }
{
QMessageBox::information(this, tr("%1", "%1").arg(GTA5SYNC_APPSTR), tr("The new Custom Folder will initialize after you restart %1.").arg(GTA5SYNC_APPSTR)); void OptionsDialog::commitProfiles(QStringList profiles)
} {
if (languageChanged) foreach(const QString &profile, profiles)
{ {
QMessageBox::information(this, tr("%1", "%1").arg(GTA5SYNC_APPSTR), tr("The language change will take effect after you restart %1.").arg(GTA5SYNC_APPSTR)); ui->cbProfiles->addItem(tr("Profile: %1").arg(profile), profile);
} if (defaultProfile == profile)
} {
#if QT_VERSION >= 0x050000
void OptionsDialog::setupDefaultProfile() ui->cbProfiles->setCurrentText(tr("Profile: %1").arg(profile));
{ #else
settings->beginGroup("Profile"); int indexOfProfile = ui->cbProfiles->findText(tr("Profile: %1").arg(profile));
defaultProfile = settings->value("Default", "").toString(); ui->cbProfiles->setCurrentIndex(indexOfProfile);
settings->endGroup(); #endif
}
QString cbNoneStr = tr("No Profile", "No Profile, as default"); }
ui->cbProfiles->addItem(cbNoneStr, ""); }
}
void OptionsDialog::on_rbPicCustomRes_toggled(bool checked)
void OptionsDialog::commitProfiles(QStringList profiles) {
{ ui->labPicCustomRes->setEnabled(checked);
foreach(const QString &profile, profiles) ui->sbPicExportWidth->setEnabled(checked);
{ ui->sbPicExportHeight->setEnabled(checked);
ui->cbProfiles->addItem(tr("Profile: %1").arg(profile), profile); ui->labPicXDescription->setEnabled(checked);
if (defaultProfile == profile) }
{
#if QT_VERSION >= 0x050000 void OptionsDialog::on_cbPicCustomQuality_toggled(bool checked)
ui->cbProfiles->setCurrentText(tr("Profile: %1").arg(profile)); {
#else ui->hsPicQuality->setEnabled(checked);
int indexOfProfile = ui->cbProfiles->findText(tr("Profile: %1").arg(profile)); ui->labPicQuality->setEnabled(checked);
ui->cbProfiles->setCurrentIndex(indexOfProfile); ui->labPicQualityDescription->setEnabled(checked);
#endif }
}
} void OptionsDialog::on_hsPicQuality_valueChanged(int value)
} {
customQuality = value;
void OptionsDialog::on_rbPicCustomRes_toggled(bool checked) ui->labPicQuality->setText(percentString.arg(QString::number(value)));
{ }
ui->labPicCustomRes->setEnabled(checked);
ui->sbPicExportWidth->setEnabled(checked); void OptionsDialog::setupPictureSettings()
ui->sbPicExportHeight->setEnabled(checked); {
ui->labPicXDescription->setEnabled(checked); settings->beginGroup("Pictures");
}
// Quality Settings
void OptionsDialog::on_cbPicCustomQuality_toggled(bool checked) customQuality = settings->value("CustomQuality", defaultQuality).toInt();
{ if (customQuality < 1 || customQuality > 100)
ui->hsPicQuality->setEnabled(checked); {
ui->labPicQuality->setEnabled(checked); customQuality = 100;
ui->labPicQualityDescription->setEnabled(checked); }
} ui->hsPicQuality->setValue(customQuality);
ui->cbPicCustomQuality->setChecked(settings->value("CustomQualityEnabled", false).toBool());
void OptionsDialog::on_hsPicQuality_valueChanged(int value)
{ // Size Settings
customQuality = value; cusExportSize = settings->value("CustomSize", defExportSize).toSize();
ui->labPicQuality->setText(percentString.arg(QString::number(value))); if (cusExportSize.width() > 3840)
} {
cusExportSize.setWidth(3840);
void OptionsDialog::setupPictureSettings() }
{ else if (cusExportSize.height() > 2160)
settings->beginGroup("Pictures"); {
cusExportSize.setHeight(2160);
// Quality Settings }
customQuality = settings->value("CustomQuality", defaultQuality).toInt(); if (cusExportSize.width() < 1)
if (customQuality < 1 || customQuality > 100) {
{ cusExportSize.setWidth(1);
customQuality = 100; }
} else if (cusExportSize.height() < 1)
ui->hsPicQuality->setValue(customQuality); {
ui->cbPicCustomQuality->setChecked(settings->value("CustomQualityEnabled", false).toBool()); cusExportSize.setHeight(1);
}
// Size Settings ui->sbPicExportWidth->setValue(cusExportSize.width());
cusExportSize = settings->value("CustomSize", defExportSize).toSize(); ui->sbPicExportHeight->setValue(cusExportSize.height());
if (cusExportSize.width() > 3840)
{ QString sizeMode = settings->value("ExportSizeMode", "Default").toString();
cusExportSize.setWidth(3840); if (sizeMode == "Desktop")
} {
else if (cusExportSize.height() > 2160) ui->rbPicDesktopRes->setChecked(true);
{ }
cusExportSize.setHeight(2160); else if (sizeMode == "Custom")
} {
if (cusExportSize.width() < 1) ui->rbPicCustomRes->setChecked(true);
{ }
cusExportSize.setWidth(1); else
} {
else if (cusExportSize.height() < 1) ui->rbPicDefaultRes->setChecked(true);
{ }
cusExportSize.setHeight(1);
} aspectRatio = (Qt::AspectRatioMode)settings->value("AspectRatio", Qt::KeepAspectRatio).toInt();
ui->sbPicExportWidth->setValue(cusExportSize.width()); if (aspectRatio == Qt::IgnoreAspectRatio)
ui->sbPicExportHeight->setValue(cusExportSize.height()); {
ui->cbIgnoreAspectRatio->setChecked(true);
QString sizeMode = settings->value("ExportSizeMode", "Default").toString(); }
if (sizeMode == "Desktop")
{ settings->endGroup();
ui->rbPicDesktopRes->setChecked(true); }
}
else if (sizeMode == "Custom") void OptionsDialog::on_cbIgnoreAspectRatio_toggled(bool checked)
{ {
ui->rbPicCustomRes->setChecked(true); if (checked)
} {
else aspectRatio = Qt::IgnoreAspectRatio;
{ }
ui->rbPicDefaultRes->setChecked(true); else
} {
aspectRatio = Qt::KeepAspectRatio;
aspectRatio = (Qt::AspectRatioMode)settings->value("AspectRatio", Qt::KeepAspectRatio).toInt(); }
if (aspectRatio == Qt::IgnoreAspectRatio) }
{
ui->cbIgnoreAspectRatio->setChecked(true); void OptionsDialog::setupCustomGTAFolder()
} {
bool ok;
settings->endGroup(); QString defaultGameFolder = AppEnv::getGameFolder(&ok);
} settings->beginGroup("dir");
currentCFolder = settings->value("dir", "").toString();
void OptionsDialog::on_cbIgnoreAspectRatio_toggled(bool checked) currentFFolder = settings->value("force", false).toBool();
{ if (currentCFolder == "" && ok)
if (checked) {
{ currentCFolder = defaultGameFolder;
aspectRatio = Qt::IgnoreAspectRatio; }
} ui->txtFolder->setText(currentCFolder);
else ui->cbForceCustomFolder->setChecked(currentFFolder);
{ settings->endGroup();
aspectRatio = Qt::KeepAspectRatio; }
}
} void OptionsDialog::setupSnapmaticPictureViewer()
{
void OptionsDialog::setupCustomGTAFolder() #ifdef GTA5SYNC_WIN
{ #if QT_VERSION >= 0x050200
bool ok; settings->beginGroup("Interface");
QString defaultGameFolder = AppEnv::getGameFolder(&ok); ui->cbSnapmaticNavigationBar->setChecked(settings->value("NavigationBar", false).toBool());
settings->beginGroup("dir"); settings->endGroup();
currentCFolder = settings->value("dir", "").toString(); #else
currentFFolder = settings->value("force", false).toBool(); ui->cbSnapmaticNavigationBar->setVisible(false);
if (currentCFolder == "" && ok) ui->gbSnapmaticPictureViewer->setVisible(false);
{ #endif
currentCFolder = defaultGameFolder; #else
} ui->cbSnapmaticNavigationBar->setVisible(false);
ui->txtFolder->setText(currentCFolder); ui->gbSnapmaticPictureViewer->setVisible(false);
ui->cbForceCustomFolder->setChecked(currentFFolder); #endif
settings->endGroup(); }
}
void OptionsDialog::on_cmdExploreFolder_clicked()
void OptionsDialog::setupSnapmaticPictureViewer() {
{ QString GTAV_Folder = QFileDialog::getExistingDirectory(this, UserInterface::tr("Select GTA V Folder..."), StandardPaths::documentsLocation(), QFileDialog::ShowDirsOnly);
#ifdef GTA5SYNC_WIN if (QFileInfo(GTAV_Folder).exists())
#if QT_VERSION >= 0x050200 {
settings->beginGroup("Interface"); ui->txtFolder->setText(GTAV_Folder);
ui->cbSnapmaticNavigationBar->setChecked(settings->value("NavigationBar", false).toBool()); }
settings->endGroup(); }
#else
ui->cbSnapmaticNavigationBar->setVisible(false);
ui->gbSnapmaticPictureViewer->setVisible(false);
#endif
#else
ui->cbSnapmaticNavigationBar->setVisible(false);
ui->gbSnapmaticPictureViewer->setVisible(false);
#endif
}
void OptionsDialog::on_cmdExploreFolder_clicked()
{
QString GTAV_Folder = QFileDialog::getExistingDirectory(this, UserInterface::tr("Select GTA V Folder..."), StandardPaths::documentsLocation(), QFileDialog::ShowDirsOnly);
if (QFileInfo(GTAV_Folder).exists())
{
ui->txtFolder->setText(GTAV_Folder);
}
}

View File

@ -1,79 +1,79 @@
/****************************************************************************** /******************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef OPTIONSDIALOG_H #ifndef OPTIONSDIALOG_H
#define OPTIONSDIALOG_H #define OPTIONSDIALOG_H
#include <QSize> #include <QSize>
#include <QList> #include <QList>
#include <QDialog> #include <QDialog>
#include <QSettings> #include <QSettings>
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
#include "ProfileDatabase.h" #include "ProfileDatabase.h"
namespace Ui { namespace Ui {
class OptionsDialog; class OptionsDialog;
} }
class OptionsDialog : public QDialog class OptionsDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit OptionsDialog(ProfileDatabase *profileDB, QWidget *parent = 0); explicit OptionsDialog(ProfileDatabase *profileDB, QWidget *parent = 0);
void commitProfiles(QStringList profiles); void commitProfiles(QStringList profiles);
~OptionsDialog(); ~OptionsDialog();
private slots: private slots:
void on_cmdOK_clicked(); void on_cmdOK_clicked();
void on_rbPicCustomRes_toggled(bool checked); void on_rbPicCustomRes_toggled(bool checked);
void on_cbPicCustomQuality_toggled(bool checked); void on_cbPicCustomQuality_toggled(bool checked);
void on_hsPicQuality_valueChanged(int value); void on_hsPicQuality_valueChanged(int value);
void on_cbIgnoreAspectRatio_toggled(bool checked); void on_cbIgnoreAspectRatio_toggled(bool checked);
void on_cmdExploreFolder_clicked(); void on_cmdExploreFolder_clicked();
signals: signals:
void settingsApplied(int contentMode, QString language); void settingsApplied(int contentMode, QString language);
private: private:
ProfileDatabase *profileDB; ProfileDatabase *profileDB;
Ui::OptionsDialog *ui; Ui::OptionsDialog *ui;
QList<QTreeWidgetItem*> playerItems; QList<QTreeWidgetItem*> playerItems;
Qt::AspectRatioMode aspectRatio; Qt::AspectRatioMode aspectRatio;
QString currentLanguage; QString currentLanguage;
QString currentCFolder; QString currentCFolder;
QString defaultProfile; QString defaultProfile;
QString percentString; QString percentString;
QSettings *settings; QSettings *settings;
bool currentFFolder; bool currentFFolder;
int contentMode; int contentMode;
int customQuality; int customQuality;
int defaultQuality; int defaultQuality;
QSize defExportSize; QSize defExportSize;
QSize cusExportSize; QSize cusExportSize;
void setupTreeWidget(); void setupTreeWidget();
void setupLanguageBox(); void setupLanguageBox();
void setupRadioButtons(); void setupRadioButtons();
void setupDefaultProfile(); void setupDefaultProfile();
void setupPictureSettings(); void setupPictureSettings();
void setupCustomGTAFolder(); void setupCustomGTAFolder();
void setupSnapmaticPictureViewer(); void setupSnapmaticPictureViewer();
void applySettings(); void applySettings();
}; };
#endif // OPTIONSDIALOG_H #endif // OPTIONSDIALOG_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,123 +1,133 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef PICTUREDIALOG_H #ifndef PICTUREDIALOG_H
#define PICTUREDIALOG_H #define PICTUREDIALOG_H
#include "SnapmaticPicture.h" #include "SnapmaticPicture.h"
#include "ProfileDatabase.h" #include "ProfileDatabase.h"
#include "CrewDatabase.h" #include "CrewDatabase.h"
#include <QMouseEvent> #include <QMouseEvent>
#include <QDialog> #include <QDialog>
#include <QEvent> #include <QEvent>
#include <QMenu> #include <QMenu>
namespace Ui { namespace Ui {
class PictureDialog; class PictureDialog;
} }
class PictureDialog : public QDialog class PictureDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit PictureDialog(ProfileDatabase *profileDB, CrewDatabase *crewDB, QWidget *parent = 0); explicit PictureDialog(ProfileDatabase *profileDB, CrewDatabase *crewDB, QWidget *parent = 0);
explicit PictureDialog(QWidget *parent = 0); explicit PictureDialog(QWidget *parent = 0);
explicit PictureDialog(bool primaryWindow, ProfileDatabase *profileDB, CrewDatabase *crewDB, QWidget *parent = 0); explicit PictureDialog(bool primaryWindow, ProfileDatabase *profileDB, CrewDatabase *crewDB, QWidget *parent = 0);
explicit PictureDialog(bool primaryWindow, QWidget *parent = 0); explicit PictureDialog(bool primaryWindow, QWidget *parent = 0);
void setupPictureDialog(bool withDatabase); void setupPictureDialog(bool withDatabase);
void setSnapmaticPicture(SnapmaticPicture *picture, bool readOk, bool indexed, int index); void setSnapmaticPicture(SnapmaticPicture *picture, bool readOk, bool indexed, int index);
void setSnapmaticPicture(SnapmaticPicture *picture, bool readOk, int index); void setSnapmaticPicture(SnapmaticPicture *picture, bool readOk, int index);
void setSnapmaticPicture(SnapmaticPicture *picture, bool readOk); void setSnapmaticPicture(SnapmaticPicture *picture, bool readOk);
void setSnapmaticPicture(SnapmaticPicture *picture, int index); void setSnapmaticPicture(SnapmaticPicture *picture, int index);
void setSnapmaticPicture(SnapmaticPicture *picture); void setSnapmaticPicture(SnapmaticPicture *picture);
void addPreviousNextButtons(); void addPreviousNextButtons();
void stylizeDialog(); void stylizeDialog();
bool isIndexed(); bool isIndexed();
int getIndex(); int getIndex();
~PictureDialog(); ~PictureDialog();
public slots: public slots:
void playerNameUpdated(); void crewNameUpdated();
void dialogNextPictureRequested(); void playerNameUpdated();
void dialogPreviousPictureRequested(); void dialogNextPictureRequested();
void adaptNewDialogSize(QSize newLabelSize); void dialogPreviousPictureRequested();
void exportCustomContextMenuRequested(const QPoint &pos); void adaptNewDialogSize(QSize newLabelSize);
void exportCustomContextMenuRequested(const QPoint &pos);
private slots:
void copySnapmaticPicture(); private slots:
void exportSnapmaticPicture(); void copySnapmaticPicture();
void triggerFullscreenDoubeClick(); void exportSnapmaticPicture();
void on_labPicture_mouseDoubleClicked(Qt::MouseButton button); void triggerFullscreenDoubeClick();
void on_labPicture_customContextMenuRequested(const QPoint &pos); void on_labPicture_mouseDoubleClicked(Qt::MouseButton button);
void exportCustomContextMenuRequestedPrivate(const QPoint &pos, bool fullscreen); void on_labPicture_customContextMenuRequested(const QPoint &pos);
void nextPictureRequestedSlot(); void exportCustomContextMenuRequestedPrivate(const QPoint &pos, bool fullscreen);
void previousPictureRequestedSlot(); void nextPictureRequestedSlot();
void renderOverlayPicture(); void previousPictureRequestedSlot();
void renderPicture(); void editSnapmaticProperties();
void renderOverlayPicture();
signals: void renderPicture();
void nextPictureRequested(); void openPreviewMap();
void previousPictureRequested(); void updated();
void newPictureCommited(QImage picture);
void endDatabaseThread(); signals:
void nextPictureRequested();
protected: void previousPictureRequested();
void closeEvent(QCloseEvent *ev); void newPictureCommited(QImage picture);
bool eventFilter(QObject *obj, QEvent *ev); void endDatabaseThread();
void mousePressEvent(QMouseEvent *ev);
bool event(QEvent *event); protected:
void closeEvent(QCloseEvent *ev);
private: bool eventFilter(QObject *obj, QEvent *ev);
bool primaryWindow; void mousePressEvent(QMouseEvent *ev);
ProfileDatabase *profileDB; bool event(QEvent *event);
CrewDatabase *crewDB;
Ui::PictureDialog *ui; private:
QMap<QString, QString> globalMap; QString generateCrewString();
SnapmaticPicture *smpic; QString generatePlayersString();
QWidget *fullscreenWidget; bool primaryWindow;
QAction *jpegExportAction; ProfileDatabase *profileDB;
QAction *pgtaExportAction; CrewDatabase *crewDB;
QImage avatarAreaPicture; Ui::PictureDialog *ui;
QImage snapmaticPicture; QMap<QString, QString> globalMap;
QImage overlayTempImage; SnapmaticPicture *smpic;
QString jsonDrawString; QWidget *fullscreenWidget;
QString windowTitleStr; QAction *jpegExportAction;
QStringList plyrsList; QAction *pgtaExportAction;
QString picAreaStr; QAction *propEditorAction;
QString picArea; QAction *openViewerAction;
QString picTitl; QAction *manageMenuSep1;
QString picPath; QImage avatarAreaPicture;
QString created; QImage snapmaticPicture;
QString crewID; QImage overlayTempImage;
QString locX; QString jsonDrawString;
QString locY; QString windowTitleStr;
QString locZ; QStringList plyrsList;
bool overlayEnabled; QString picAreaStr;
bool withDatabase; QString picArea;
bool rqFullscreen; QString picTitl;
bool naviEnabled; QString picPath;
bool previewMode; QString created;
bool indexed; QString crewStr;
int index; QString crewID;
int avatarLocX; QString locX;
int avatarLocY; QString locY;
int avatarSize; QString locZ;
QMenu *exportMenu; bool overlayEnabled;
}; bool withDatabase;
bool rqFullscreen;
#endif // PICTUREDIALOG_H bool naviEnabled;
bool previewMode;
bool indexed;
int index;
int avatarLocX;
int avatarLocY;
int avatarSize;
QMenu *manageMenu;
};
#endif // PICTUREDIALOG_H

View File

@ -1,254 +1,254 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>PictureDialog</class> <class>PictureDialog</class>
<widget class="QDialog" name="PictureDialog"> <widget class="QDialog" name="PictureDialog">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>960</width> <width>960</width>
<height>602</height> <height>618</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>%1 - Snapmatic Picture Viewer</string> <string>%1 - Snapmatic Picture Viewer</string>
</property> </property>
<layout class="QVBoxLayout" name="vlPictureLayout"> <layout class="QVBoxLayout" name="vlPictureLayout">
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </property>
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="UiModLabel" name="labPicture"> <widget class="UiModLabel" name="labPicture">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>1</verstretch> <verstretch>1</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="contextMenuPolicy"> <property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum> <enum>Qt::CustomContextMenu</enum>
</property> </property>
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
<property name="pixmap"> <property name="pixmap">
<pixmap resource="res/app.qrc">:/img/960x536.png</pixmap> <pixmap resource="res/app.qrc">:/img/960x536.png</pixmap>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="vsJSONUpper"> <spacer name="vsJSONUpper">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>0</width> <width>0</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QFrame" name="jsonFrame"> <widget class="QFrame" name="jsonFrame">
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Plain</enum> <enum>QFrame::Plain</enum>
</property> </property>
<property name="lineWidth"> <property name="lineWidth">
<number>0</number> <number>0</number>
</property> </property>
<layout class="QHBoxLayout" name="hlJson"> <layout class="QHBoxLayout" name="hlJson">
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </property>
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<layout class="QHBoxLayout" name="jsonLayout"> <layout class="QHBoxLayout" name="jsonLayout">
<property name="leftMargin"> <property name="leftMargin">
<number>4</number> <number>4</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>10</number> <number>10</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>4</number> <number>4</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>4</number> <number>4</number>
</property> </property>
<item> <item>
<widget class="UiModLabel" name="labJSON"> <widget class="UiModLabel" name="labJSON">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"> <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>&lt;span style=&quot; font-weight:600;&quot;&gt;Title: &lt;/span&gt;%6&lt;br/&gt; <string>&lt;span style=&quot; font-weight:600;&quot;&gt;Title: &lt;/span&gt;%6&lt;br/&gt;
&lt;span style=&quot; font-weight:600;&quot;&gt;Location: &lt;/span&gt;%7 (%1, %2, %3)&lt;br/&gt; &lt;span style=&quot; font-weight:600;&quot;&gt;Location: &lt;/span&gt;%7 (%1, %2, %3)&lt;br/&gt;
&lt;span style=&quot; font-weight:600;&quot;&gt;Players: &lt;/span&gt;%4 (Crew %5)&lt;br/&gt; &lt;span style=&quot; font-weight:600;&quot;&gt;Players: &lt;/span&gt;%4 (Crew %5)&lt;br/&gt;
&lt;span style=&quot; font-weight:600;&quot;&gt;Created: &lt;/span&gt;%8</string> &lt;span style=&quot; font-weight:600;&quot;&gt;Created: &lt;/span&gt;%8</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="openExternalLinks"> <property name="openExternalLinks">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="textInteractionFlags"> <property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set> <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QVBoxLayout" name="vlButtons"> <layout class="QVBoxLayout" name="vlButtons">
<property name="spacing"> <property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>5</number> <number>5</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>5</number> <number>5</number>
</property> </property>
<item> <item>
<spacer name="vsButtons"> <spacer name="vsButtons">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeType"> <property name="sizeType">
<enum>QSizePolicy::Expanding</enum> <enum>QSizePolicy::Expanding</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>0</width> <width>0</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="hlButtons"> <layout class="QHBoxLayout" name="hlButtons">
<property name="spacing"> <property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<item> <item>
<widget class="QPushButton" name="cmdExport"> <widget class="QPushButton" name="cmdManage">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="focusPolicy"> <property name="focusPolicy">
<enum>Qt::NoFocus</enum> <enum>Qt::NoFocus</enum>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Export picture</string> <string>Manage picture</string>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Export</string> <string>&amp;Manage</string>
</property> </property>
<property name="autoDefault"> <property name="autoDefault">
<bool>false</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="cmdClose"> <widget class="QPushButton" name="cmdClose">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="focusPolicy"> <property name="focusPolicy">
<enum>Qt::NoFocus</enum> <enum>Qt::NoFocus</enum>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Close</string> <string>Close viewer</string>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Close</string> <string>&amp;Close</string>
</property> </property>
<property name="autoDefault"> <property name="autoDefault">
<bool>false</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
</layout> </layout>
</item> </item>
</layout> </layout>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>UiModLabel</class> <class>UiModLabel</class>
<extends>QLabel</extends> <extends>QLabel</extends>
<header>uimod/UiModLabel.h</header> <header>uimod/UiModLabel.h</header>
<slots> <slots>
<signal>mouseMoved()</signal> <signal>mouseMoved()</signal>
<signal>mouseReleased()</signal> <signal>mouseReleased()</signal>
<signal>mousePressed()</signal> <signal>mousePressed()</signal>
<signal>mouseDoubleClicked()</signal> <signal>mouseDoubleClicked()</signal>
</slots> </slots>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="res/app.qrc"/> <include location="res/app.qrc"/>
</resources> </resources>
<connections> <connections>
<connection> <connection>
<sender>cmdClose</sender> <sender>cmdClose</sender>
<signal>clicked()</signal> <signal>clicked()</signal>
<receiver>PictureDialog</receiver> <receiver>PictureDialog</receiver>
<slot>close()</slot> <slot>close()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>912</x> <x>912</x>
<y>514</y> <y>514</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>479</x> <x>479</x>
<y>267</y> <y>267</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
</connections> </connections>
</ui> </ui>

View File

@ -1,310 +1,312 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "config.h" #include "config.h"
#include "PictureExport.h" #include "PictureExport.h"
#include "PictureDialog.h" #include "PictureDialog.h"
#include "StandardPaths.h" #include "StandardPaths.h"
#include "SidebarGenerator.h" #include "SidebarGenerator.h"
#include <QDesktopWidget> #include <QStringBuilder>
#include <QApplication> #include <QDesktopWidget>
#include <QMessageBox> #include <QApplication>
#include <QFileDialog> #include <QMessageBox>
#include <QSettings> #include <QFileDialog>
#include <QDebug> #include <QSettings>
#include <QRegExp>
PictureExport::PictureExport() #include <QDebug>
{
PictureExport::PictureExport()
} {
void PictureExport::exportAsPicture(QWidget *parent, SnapmaticPicture *picture) }
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); void PictureExport::exportAsPicture(QWidget *parent, SnapmaticPicture *picture)
{
// Picture Settings QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
// Quality Settings
settings.beginGroup("Pictures"); // Picture Settings
int defaultQuality = 100; // Quality Settings
QSize defExportSize = QSize(960, 536); settings.beginGroup("Pictures");
int customQuality = settings.value("CustomQuality", defaultQuality).toInt(); int defaultQuality = 100;
if (customQuality < 1 || customQuality > 100) QSize defExportSize = QSize(960, 536);
{ int customQuality = settings.value("CustomQuality", defaultQuality).toInt();
customQuality = 100; if (customQuality < 1 || customQuality > 100)
} {
bool useCustomQuality = settings.value("CustomQualityEnabled", false).toBool(); customQuality = 100;
}
// Size Settings bool useCustomQuality = settings.value("CustomQualityEnabled", false).toBool();
QSize cusExportSize = settings.value("CustomSize", defExportSize).toSize();
if (cusExportSize.width() > 3840) // Size Settings
{ QSize cusExportSize = settings.value("CustomSize", defExportSize).toSize();
cusExportSize.setWidth(3840); if (cusExportSize.width() > 3840)
} {
else if (cusExportSize.height() > 2160) cusExportSize.setWidth(3840);
{ }
cusExportSize.setHeight(2160); else if (cusExportSize.height() > 2160)
} {
if (cusExportSize.width() < 1) cusExportSize.setHeight(2160);
{ }
cusExportSize.setWidth(1); if (cusExportSize.width() < 1)
} {
else if (cusExportSize.height() < 1) cusExportSize.setWidth(1);
{ }
cusExportSize.setHeight(1); else if (cusExportSize.height() < 1)
} {
QString sizeMode = settings.value("ExportSizeMode", "Default").toString(); cusExportSize.setHeight(1);
Qt::AspectRatioMode aspectRatio = (Qt::AspectRatioMode)settings.value("AspectRatio", Qt::KeepAspectRatio).toInt(); }
QString defaultExportFormat = settings.value("DefaultExportFormat", ".jpg").toString(); QString sizeMode = settings.value("ExportSizeMode", "Default").toString();
settings.endGroup(); Qt::AspectRatioMode aspectRatio = (Qt::AspectRatioMode)settings.value("AspectRatio", Qt::KeepAspectRatio).toInt();
// End Picture Settings QString defaultExportFormat = settings.value("DefaultExportFormat", ".jpg").toString();
settings.endGroup();
settings.beginGroup("FileDialogs"); // End Picture Settings
settings.beginGroup("ExportAsPicture");
settings.beginGroup("FileDialogs");
fileDialogPreSave: //Work? settings.beginGroup("ExportAsPicture");
QFileDialog fileDialog(parent);
fileDialog.setFileMode(QFileDialog::AnyFile); fileDialogPreSave: //Work?
fileDialog.setViewMode(QFileDialog::Detail); QFileDialog fileDialog(parent);
fileDialog.setAcceptMode(QFileDialog::AcceptSave); fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setOption(QFileDialog::DontUseNativeDialog, false); fileDialog.setViewMode(QFileDialog::Detail);
fileDialog.setOption(QFileDialog::DontConfirmOverwrite, true); fileDialog.setAcceptMode(QFileDialog::AcceptSave);
fileDialog.setDefaultSuffix("suffix"); fileDialog.setOption(QFileDialog::DontUseNativeDialog, false);
fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint); fileDialog.setOption(QFileDialog::DontConfirmOverwrite, true);
fileDialog.setWindowTitle(PictureDialog::tr("Export as JPG picture...")); fileDialog.setDefaultSuffix("suffix");
fileDialog.setLabelText(QFileDialog::Accept, PictureDialog::tr("Export")); fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
fileDialog.setWindowTitle(PictureDialog::tr("Export as Picture..."));
QStringList filters; fileDialog.setLabelText(QFileDialog::Accept, PictureDialog::tr("Export"));
filters << PictureDialog::tr("JPEG picture (*.jpg)");
filters << PictureDialog::tr("Portable Network Graphics (*.png)"); QStringList filters;
fileDialog.setNameFilters(filters); filters << PictureDialog::tr("JPEG Graphics (*.jpg *.jpeg)");
filters << PictureDialog::tr("Portable Network Graphics (*.png)");
QList<QUrl> sidebarUrls = SidebarGenerator::generateSidebarUrls(fileDialog.sidebarUrls()); fileDialog.setNameFilters(filters);
fileDialog.setSidebarUrls(sidebarUrls); QList<QUrl> sidebarUrls = SidebarGenerator::generateSidebarUrls(fileDialog.sidebarUrls());
fileDialog.setDirectory(settings.value("Directory", StandardPaths::picturesLocation()).toString());
fileDialog.restoreGeometry(settings.value(parent->objectName() + "+Geomtery", "").toByteArray()); fileDialog.setSidebarUrls(sidebarUrls);
fileDialog.setDirectory(settings.value("Directory", StandardPaths::picturesLocation()).toString());
QString newPictureFileName = getPictureFileName(picture) + defaultExportFormat; fileDialog.restoreGeometry(settings.value(parent->objectName() % "+Geomtery", "").toByteArray());
fileDialog.selectFile(newPictureFileName);
QString newPictureFileName = getPictureFileName(picture) % defaultExportFormat;
if (fileDialog.exec()) fileDialog.selectFile(newPictureFileName);
{
QStringList selectedFiles = fileDialog.selectedFiles(); if (fileDialog.exec())
if (selectedFiles.length() == 1) {
{ QStringList selectedFiles = fileDialog.selectedFiles();
QString saveFileFormat; if (selectedFiles.length() == 1)
QString selectedFile = selectedFiles.at(0); {
QString saveFileFormat;
if (selectedFile.right(4) == ".jpg") QString selectedFile = selectedFiles.at(0);
{
saveFileFormat = "JPEG"; if (selectedFile.right(4) == ".jpg")
} {
else if (selectedFile.right(4) == ".jpeg") saveFileFormat = "JPEG";
{ }
saveFileFormat = "JPEG"; else if (selectedFile.right(4) == ".jpeg")
} {
else if (selectedFile.right(4) == ".png") saveFileFormat = "JPEG";
{ }
saveFileFormat = "PNG"; else if (selectedFile.right(4) == ".png")
} {
else if (selectedFile.right(7) == ".suffix") saveFileFormat = "PNG";
{ }
if (fileDialog.selectedNameFilter() == "JPEG picture (*.jpg)") else if (selectedFile.right(7) == ".suffix")
{ {
selectedFile.replace(".suffix", ".jpg"); if (fileDialog.selectedNameFilter() == "JPEG picture (*.jpg)")
} {
else if (fileDialog.selectedNameFilter() == "Portable Network Graphics (*.png)") selectedFile.replace(".suffix", ".jpg");
{ }
selectedFile.replace(".suffix", ".png"); else if (fileDialog.selectedNameFilter() == "Portable Network Graphics (*.png)")
} {
else selectedFile.replace(".suffix", ".png");
{ }
selectedFile.replace(".suffix", ".jpg"); else
} {
} selectedFile.replace(".suffix", ".jpg");
}
if (QFile::exists(selectedFile)) }
{
if (QMessageBox::Yes == QMessageBox::warning(parent, PictureDialog::tr("Export as JPG picture"), PictureDialog::tr("Overwrite %1 with current Snapmatic picture?").arg("\""+selectedFile+"\""), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes)) if (QFile::exists(selectedFile))
{ {
if (!QFile::remove(selectedFile)) if (QMessageBox::Yes == QMessageBox::warning(parent, PictureDialog::tr("Export as Picture"), PictureDialog::tr("Overwrite %1 with current Snapmatic picture?").arg("\""+selectedFile+"\""), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes))
{ {
QMessageBox::warning(parent, PictureDialog::tr("Export as JPG picture"), PictureDialog::tr("Failed to overwrite %1 with current Snapmatic picture").arg("\""+selectedFile+"\"")); if (!QFile::remove(selectedFile))
goto fileDialogPreSave; //Work? {
} QMessageBox::warning(parent, PictureDialog::tr("Export as Picture"), PictureDialog::tr("Failed to overwrite %1 with current Snapmatic picture").arg("\""+selectedFile+"\""));
} goto fileDialogPreSave; //Work?
else }
{ }
goto fileDialogPreSave; //Work? else
} {
} goto fileDialogPreSave; //Work?
}
// Scale Picture }
QImage exportPicture = picture->getImage();
if (sizeMode == "Desktop") // Scale Picture
{ QImage exportPicture = picture->getImage();
QRect desktopResolution = QApplication::desktop()->screenGeometry(); if (sizeMode == "Desktop")
exportPicture = exportPicture.scaled(desktopResolution.width(), desktopResolution.height(), aspectRatio, Qt::SmoothTransformation); {
} QRect desktopResolution = QApplication::desktop()->screenGeometry();
else if (sizeMode == "Custom") exportPicture = exportPicture.scaled(desktopResolution.width(), desktopResolution.height(), aspectRatio, Qt::SmoothTransformation);
{ }
exportPicture = exportPicture.scaled(cusExportSize, aspectRatio, Qt::SmoothTransformation); else if (sizeMode == "Custom")
} {
exportPicture = exportPicture.scaled(cusExportSize, aspectRatio, Qt::SmoothTransformation);
bool isSaved; }
if (useCustomQuality)
{ bool isSaved;
isSaved = exportPicture.save(selectedFile, saveFileFormat.toStdString().c_str(), customQuality); if (useCustomQuality)
} {
else isSaved = exportPicture.save(selectedFile, saveFileFormat.toStdString().c_str(), customQuality);
{ }
isSaved = exportPicture.save(selectedFile, saveFileFormat.toStdString().c_str(), 100); else
} {
isSaved = exportPicture.save(selectedFile, saveFileFormat.toStdString().c_str(), 100);
if (!isSaved) }
{
QMessageBox::warning(parent, PictureDialog::tr("Export as JPG picture"), PictureDialog::tr("Failed to export current Snapmatic picture")); if (!isSaved)
goto fileDialogPreSave; //Work? {
} QMessageBox::warning(parent, PictureDialog::tr("Export as Picture"), PictureDialog::tr("Failed to export current Snapmatic picture"));
} goto fileDialogPreSave; //Work?
else }
{ }
QMessageBox::warning(parent, PictureDialog::tr("Export as JPG picture"), PictureDialog::tr("No valid file is selected")); else
goto fileDialogPreSave; //Work? {
} QMessageBox::warning(parent, PictureDialog::tr("Export as Picture"), PictureDialog::tr("No valid file is selected"));
} goto fileDialogPreSave; //Work?
}
settings.setValue(parent->objectName() + "+Geometry", fileDialog.saveGeometry()); }
settings.setValue("Directory", fileDialog.directory().absolutePath());
settings.endGroup(); settings.setValue(parent->objectName() % "+Geometry", fileDialog.saveGeometry());
settings.endGroup(); settings.setValue("Directory", fileDialog.directory().absolutePath());
} settings.endGroup();
settings.endGroup();
void PictureExport::exportAsSnapmatic(QWidget *parent, SnapmaticPicture *picture) }
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); void PictureExport::exportAsSnapmatic(QWidget *parent, SnapmaticPicture *picture)
settings.beginGroup("FileDialogs"); {
settings.beginGroup("ExportAsSnapmatic"); QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("FileDialogs");
QString adjustedPicPath = picture->getPictureFileName(); settings.beginGroup("ExportAsSnapmatic");
if (adjustedPicPath.right(7) == ".hidden") // for the hidden file system
{ QString adjustedPicPath = picture->getPictureFileName();
adjustedPicPath.remove(adjustedPicPath.length() - 7, 7); if (adjustedPicPath.right(7) == ".hidden") // for the hidden file system
} {
adjustedPicPath.remove(adjustedPicPath.length() - 7, 7);
fileDialogPreSave: //Work? }
QFileInfo sgdFileInfo(adjustedPicPath);
QFileDialog fileDialog(parent); fileDialogPreSave: //Work?
fileDialog.setFileMode(QFileDialog::AnyFile); QFileInfo sgdFileInfo(adjustedPicPath);
fileDialog.setViewMode(QFileDialog::Detail); QFileDialog fileDialog(parent);
fileDialog.setAcceptMode(QFileDialog::AcceptSave); fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setOption(QFileDialog::DontUseNativeDialog, false); fileDialog.setViewMode(QFileDialog::Detail);
fileDialog.setOption(QFileDialog::DontConfirmOverwrite, true); fileDialog.setAcceptMode(QFileDialog::AcceptSave);
fileDialog.setDefaultSuffix(".rem"); fileDialog.setOption(QFileDialog::DontUseNativeDialog, false);
fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint); fileDialog.setOption(QFileDialog::DontConfirmOverwrite, true);
fileDialog.setWindowTitle(PictureDialog::tr("Export as GTA Snapmatic...")); fileDialog.setDefaultSuffix(".rem");
fileDialog.setLabelText(QFileDialog::Accept, PictureDialog::tr("Export")); fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
fileDialog.setWindowTitle(PictureDialog::tr("Export as Snapmatic..."));
QStringList filters; fileDialog.setLabelText(QFileDialog::Accept, PictureDialog::tr("Export"));
filters << PictureDialog::tr("GTA V Export (*.g5e)");
filters << PictureDialog::tr("GTA V Raw Export (*.auto)"); QStringList filters;
filters << PictureDialog::tr("Snapmatic pictures (PGTA*)"); filters << PictureDialog::tr("GTA V Export (*.g5e)");
fileDialog.setNameFilters(filters); filters << PictureDialog::tr("GTA V Raw Export (*.auto)");
filters << PictureDialog::tr("Snapmatic pictures (PGTA*)");
QList<QUrl> sidebarUrls = SidebarGenerator::generateSidebarUrls(fileDialog.sidebarUrls()); fileDialog.setNameFilters(filters);
fileDialog.setSidebarUrls(sidebarUrls); QList<QUrl> sidebarUrls = SidebarGenerator::generateSidebarUrls(fileDialog.sidebarUrls());
fileDialog.setDirectory(settings.value("Directory", StandardPaths::documentsLocation()).toString());
fileDialog.selectFile(QString(picture->getExportPictureFileName() + ".g5e")); fileDialog.setSidebarUrls(sidebarUrls);
fileDialog.restoreGeometry(settings.value(parent->objectName() + "+Geomtery", "").toByteArray()); fileDialog.setDirectory(settings.value("Directory", StandardPaths::documentsLocation()).toString());
fileDialog.selectFile(QString(picture->getExportPictureFileName() % ".g5e"));
fileDialog.restoreGeometry(settings.value(parent->objectName() % "+Geomtery", "").toByteArray());
if (fileDialog.exec())
{
QStringList selectedFiles = fileDialog.selectedFiles(); if (fileDialog.exec())
if (selectedFiles.length() == 1) {
{ QStringList selectedFiles = fileDialog.selectedFiles();
QString selectedFile = selectedFiles.at(0); if (selectedFiles.length() == 1)
{
if (QFile::exists(selectedFile)) QString selectedFile = selectedFiles.at(0);
{ bool isAutoExt = false;
if (QMessageBox::Yes == QMessageBox::warning(parent, PictureDialog::tr("Export as GTA Snapmatic"), PictureDialog::tr("Overwrite %1 with current Snapmatic picture?").arg("\""+selectedFile+"\""), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes)) if (selectedFile.right(5) == ".auto")
{ {
if (!QFile::remove(selectedFile)) isAutoExt = true;
{ QString dirPath = QFileInfo(selectedFile).dir().path();
QMessageBox::warning(parent, PictureDialog::tr("Export as GTA Snapmatic"), PictureDialog::tr("Failed to overwrite %1 with current Snapmatic picture").arg("\""+selectedFile+"\"")); QString stockFileName = sgdFileInfo.fileName();
goto fileDialogPreSave; //Work? selectedFile = dirPath % "/" % stockFileName;
} }
} else if (selectedFile.right(4) == ".rem")
else {
{ selectedFile.remove(selectedFile.length() - 4, 4);
goto fileDialogPreSave; //Work? }
}
} if (QFile::exists(selectedFile))
{
if (selectedFile.right(4) == ".g5e") if (QMessageBox::Yes == QMessageBox::warning(parent, PictureDialog::tr("Export as Snapmatic"), PictureDialog::tr("Overwrite %1 with current Snapmatic picture?").arg("\""+selectedFile+"\""), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes))
{ {
bool isExported = picture->exportPicture(selectedFile, "G5E"); if (!QFile::remove(selectedFile))
if (!isExported) {
{ QMessageBox::warning(parent, PictureDialog::tr("Export as Snapmatic"), PictureDialog::tr("Failed to overwrite %1 with current Snapmatic picture").arg("\""+selectedFile+"\""));
QMessageBox::warning(parent, PictureDialog::tr("Export as GTA Snapmatic"), PictureDialog::tr("Failed to export current Snapmatic picture")); goto fileDialogPreSave; //Work?
goto fileDialogPreSave; //Work? }
} }
} else
else {
{ goto fileDialogPreSave; //Work?
bool isAutoExt = false; }
if (selectedFile.right(5) == ".auto") }
{
isAutoExt = true; if (selectedFile.right(4) == ".g5e")
QString dirPath = QFileInfo(selectedFile).dir().path(); {
QString stockFileName = sgdFileInfo.fileName(); bool isExported = picture->exportPicture(selectedFile, SnapmaticFormat::G5E_Format);
selectedFile = dirPath + "/" + stockFileName; if (!isExported)
} {
else if (selectedFile.right(4) == ".rem") QMessageBox::warning(parent, PictureDialog::tr("Export as Snapmatic"), PictureDialog::tr("Failed to export current Snapmatic picture"));
{ goto fileDialogPreSave; //Work?
selectedFile.remove(".rem"); }
} }
bool isCopied = picture->exportPicture(selectedFile, "PGTA"); else
if (!isCopied) {
{ bool isCopied = picture->exportPicture(selectedFile, SnapmaticFormat::PGTA_Format);
QMessageBox::warning(parent, PictureDialog::tr("Export as GTA Snapmatic"), PictureDialog::tr("Failed to export current Snapmatic picture")); if (!isCopied)
goto fileDialogPreSave; //Work? {
} QMessageBox::warning(parent, PictureDialog::tr("Export as Snapmatic"), PictureDialog::tr("Failed to export current Snapmatic picture"));
else goto fileDialogPreSave; //Work?
{ }
if (isAutoExt) QMessageBox::information(parent, PictureDialog::tr("Export as GTA Snapmatic"), PictureDialog::tr("Exported Snapmatic to \"%1\" because of using the .auto extension.").arg(selectedFile)); else
} {
} if (isAutoExt) QMessageBox::information(parent, PictureDialog::tr("Export as Snapmatic"), PictureDialog::tr("Exported Snapmatic to \"%1\" because of using the .auto extension.").arg(selectedFile));
} }
else }
{ }
QMessageBox::warning(parent, PictureDialog::tr("Export as GTA Snapmatic"), PictureDialog::tr("No valid file is selected")); else
goto fileDialogPreSave; //Work? {
} QMessageBox::warning(parent, PictureDialog::tr("Export as Snapmatic"), PictureDialog::tr("No valid file is selected"));
} goto fileDialogPreSave; //Work?
}
settings.setValue(parent->objectName() + "+Geometry", fileDialog.saveGeometry()); }
settings.setValue("Directory", fileDialog.directory().absolutePath());
settings.endGroup(); settings.setValue(parent->objectName() % "+Geometry", fileDialog.saveGeometry());
} settings.setValue("Directory", fileDialog.directory().absolutePath());
settings.endGroup();
QString PictureExport::getPictureFileName(SnapmaticPicture *picture) }
{
return picture->getExportPictureFileName(); QString PictureExport::getPictureFileName(SnapmaticPicture *picture)
} {
return picture->getExportPictureFileName();
}

View File

@ -1,35 +1,35 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef PICTUREEXPORT_H #ifndef PICTUREEXPORT_H
#define PICTUREEXPORT_H #define PICTUREEXPORT_H
#include "SnapmaticPicture.h" #include "SnapmaticPicture.h"
#include <QWidget> #include <QWidget>
#include <QString> #include <QString>
class PictureExport class PictureExport
{ {
public: public:
PictureExport(); PictureExport();
static void exportAsPicture(QWidget *parent, SnapmaticPicture *picture); static void exportAsPicture(QWidget *parent, SnapmaticPicture *picture);
static void exportAsSnapmatic(QWidget *parent, SnapmaticPicture *picture); static void exportAsSnapmatic(QWidget *parent, SnapmaticPicture *picture);
static QString getPictureFileName(SnapmaticPicture *picture); static QString getPictureFileName(SnapmaticPicture *picture);
}; };
#endif // PICTUREEXPORT_H #endif // PICTUREEXPORT_H

View File

@ -1,61 +1,76 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "ProfileDatabase.h" #include "ProfileDatabase.h"
#include "StandardPaths.h" #include "StandardPaths.h"
#include "config.h" #include "config.h"
#include <QFile> #include <QStringBuilder>
#include <QDir> #include <QMutexLocker>
#include <QDebug>
ProfileDatabase::ProfileDatabase(QObject *parent) : QObject(parent) #include <QFile>
{ #include <QDir>
QDir dir;
dir.mkpath(StandardPaths::dataLocation()); ProfileDatabase::ProfileDatabase(QObject *parent) : QObject(parent)
dir.setPath(StandardPaths::dataLocation()); {
QString dirPath = dir.absolutePath(); QDir dir;
QString defaultConfPath = dirPath + QDir::separator() + "players.ini"; dir.mkpath(StandardPaths::dataLocation());
dir.setPath(StandardPaths::dataLocation());
QSettings confPathSettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); QString dirPath = dir.absolutePath();
confPathSettings.beginGroup("Database"); QString defaultConfPath = dirPath % QDir::separator() % "players.ini";
QString confPathFile = confPathSettings.value("Players", defaultConfPath).toString();
confPathSettings.endGroup(); QSettings confPathSettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
confPathSettings.beginGroup("Database");
profileDB = new QSettings(confPathFile, QSettings::IniFormat); QString confPathFile = confPathSettings.value("Players", defaultConfPath).toString();
profileDB->beginGroup("Players"); confPathSettings.endGroup();
}
profileDB = new QSettings(confPathFile, QSettings::IniFormat);
ProfileDatabase::~ProfileDatabase() profileDB->beginGroup("Players");
{ }
profileDB->endGroup();
delete profileDB; ProfileDatabase::~ProfileDatabase()
} {
profileDB->endGroup();
QStringList ProfileDatabase::getPlayers() delete profileDB;
{ }
return profileDB->childKeys();
} QStringList ProfileDatabase::getPlayers()
{
QString ProfileDatabase::getPlayerName(int playerID) QMutexLocker locker(&mutex);
{ #ifdef GTA5SYNC_DEBUG
return profileDB->value(QString::number(playerID), playerID).toString(); qDebug() << "getPlayers";
} #endif
return profileDB->childKeys();
void ProfileDatabase::setPlayerName(int playerID, QString playerName) }
{
profileDB->setValue(QString::number(playerID), playerName); QString ProfileDatabase::getPlayerName(int playerID)
} {
QMutexLocker locker(&mutex);
#ifdef GTA5SYNC_DEBUG
qDebug() << "getPlayerName" << playerID;
#endif
return profileDB->value(QString::number(playerID), playerID).toString();
}
void ProfileDatabase::setPlayerName(int playerID, QString playerName)
{
QMutexLocker locker(&mutex);
#ifdef GTA5SYNC_DEBUG
qDebug() << "setPlayerName" << playerID << playerName;
#endif
profileDB->setValue(QString::number(playerID), playerName);
}

View File

@ -1,43 +1,45 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef PROFILEDATABASE_H #ifndef PROFILEDATABASE_H
#define PROFILEDATABASE_H #define PROFILEDATABASE_H
#include <QSettings> #include <QSettings>
#include <QObject> #include <QObject>
#include <QMap> #include <QMutex>
#include <QMap>
class ProfileDatabase : public QObject
{ class ProfileDatabase : public QObject
Q_OBJECT {
public: Q_OBJECT
explicit ProfileDatabase(QObject *parent = 0); public:
QString getPlayerName(int playerID); explicit ProfileDatabase(QObject *parent = 0);
QStringList getPlayers(); QString getPlayerName(int playerID);
~ProfileDatabase(); QStringList getPlayers();
~ProfileDatabase();
private:
QSettings *profileDB; private:
mutable QMutex mutex;
public slots: QSettings *profileDB;
void setPlayerName(int playerID, QString playerName);
public slots:
}; void setPlayerName(int playerID, QString playerName);
#endif // PROFILEDATABASE_H };
#endif // PROFILEDATABASE_H

View File

@ -38,6 +38,7 @@
#include <QPushButton> #include <QPushButton>
#include <QSpacerItem> #include <QSpacerItem>
#include <QMessageBox> #include <QMessageBox>
#include <QMouseEvent>
#include <QFileDialog> #include <QFileDialog>
#include <QEventLoop> #include <QEventLoop>
#include <QScrollBar> #include <QScrollBar>
@ -64,13 +65,14 @@ ProfileInterface::ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *cre
enabledPicStr = tr("Enabled pictures: %1 of %2"); enabledPicStr = tr("Enabled pictures: %1 of %2");
selectedWidgts = 0; selectedWidgts = 0;
profileFolder = ""; profileFolder = "";
profileLoader = 0; contextMenuOpened = false;
saSpacerItem = 0; isProfileLoaded = false;
previousWidget = nullptr;
profileLoader = nullptr;
saSpacerItem = nullptr;
QPalette palette; updatePalette();
QColor baseColor = palette.base().color(); ui->labVersion->setText(QString("%1 %2").arg(GTA5SYNC_APPSTR, GTA5SYNC_APPVER));
ui->labVersion->setText(ui->labVersion->text().arg(GTA5SYNC_APPSTR, GTA5SYNC_APPVER));
ui->saProfile->setStyleSheet(QString("QWidget#saProfileContent{background-color: rgb(%1, %2, %3)}").arg(QString::number(baseColor.red()),QString::number(baseColor.green()),QString::number(baseColor.blue())));
ui->saProfileContent->setFilesMode(true); ui->saProfileContent->setFilesMode(true);
if (QIcon::hasThemeIcon("dialog-close")) if (QIcon::hasThemeIcon("dialog-close"))
@ -87,6 +89,9 @@ ProfileInterface::ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *cre
ui->hlButtons->setSpacing(6 * screenRatio); ui->hlButtons->setSpacing(6 * screenRatio);
ui->hlButtons->setContentsMargins(9 * screenRatio, 15 * screenRatio, 15 * screenRatio, 17 * screenRatio); ui->hlButtons->setContentsMargins(9 * screenRatio, 15 * screenRatio, 15 * screenRatio, 17 * screenRatio);
#endif #endif
setMouseTracking(true);
installEventFilter(this);
} }
ProfileInterface::~ProfileInterface() ProfileInterface::~ProfileInterface()
@ -94,6 +99,8 @@ ProfileInterface::~ProfileInterface()
foreach(ProfileWidget *widget, widgets.keys()) foreach(ProfileWidget *widget, widgets.keys())
{ {
widgets.remove(widget); widgets.remove(widget);
widget->removeEventFilter(this);
widget->disconnect();
delete widget; delete widget;
} }
foreach(SavegameData *savegame, savegames) foreach(SavegameData *savegame, savegames)
@ -138,6 +145,8 @@ void ProfileInterface::savegameLoaded(SavegameData *savegame, QString savegamePa
SavegameWidget *sgdWidget = new SavegameWidget(this); SavegameWidget *sgdWidget = new SavegameWidget(this);
sgdWidget->setSavegameData(savegame, savegamePath); sgdWidget->setSavegameData(savegame, savegamePath);
sgdWidget->setContentMode(contentMode); sgdWidget->setContentMode(contentMode);
sgdWidget->setMouseTracking(true);
sgdWidget->installEventFilter(this);
widgets[sgdWidget] = "SGD" % QFileInfo(savegamePath).fileName(); widgets[sgdWidget] = "SGD" % QFileInfo(savegamePath).fileName();
savegames += savegame; savegames += savegame;
if (selectedWidgts != 0 || contentMode == 2) { sgdWidget->setSelectionMode(true); } if (selectedWidgts != 0 || contentMode == 2) { sgdWidget->setSelectionMode(true); }
@ -160,6 +169,8 @@ void ProfileInterface::pictureLoaded(SnapmaticPicture *picture, bool inserted)
SnapmaticWidget *picWidget = new SnapmaticWidget(profileDB, crewDB, threadDB, this); SnapmaticWidget *picWidget = new SnapmaticWidget(profileDB, crewDB, threadDB, this);
picWidget->setSnapmaticPicture(picture); picWidget->setSnapmaticPicture(picture);
picWidget->setContentMode(contentMode); picWidget->setContentMode(contentMode);
picWidget->setMouseTracking(true);
picWidget->installEventFilter(this);
widgets[picWidget] = "PIC" % picture->getPictureSortStr(); widgets[picWidget] = "PIC" % picture->getPictureSortStr();
pictures += picture; pictures += picture;
if (selectedWidgts != 0 || contentMode == 2) { picWidget->setSelectionMode(true); } if (selectedWidgts != 0 || contentMode == 2) { picWidget->setSelectionMode(true); }
@ -183,7 +194,7 @@ void ProfileInterface::loadingProgress(int value, int maximum)
void ProfileInterface::insertSnapmaticIPI(QWidget *widget) void ProfileInterface::insertSnapmaticIPI(QWidget *widget)
{ {
ProfileWidget *proWidget = (ProfileWidget*)widget; ProfileWidget *proWidget = qobject_cast<ProfileWidget*>(widget);
if (widgets.contains(proWidget)) if (widgets.contains(proWidget))
{ {
QString widgetKey = widgets[proWidget]; QString widgetKey = widgets[proWidget];
@ -204,7 +215,7 @@ void ProfileInterface::insertSnapmaticIPI(QWidget *widget)
void ProfileInterface::insertSavegameIPI(QWidget *widget) void ProfileInterface::insertSavegameIPI(QWidget *widget)
{ {
ProfileWidget *proWidget = (ProfileWidget*)widget; ProfileWidget *proWidget = qobject_cast<ProfileWidget*>(widget);
if (widgets.contains(proWidget)) if (widgets.contains(proWidget))
{ {
QString widgetKey = widgets[proWidget]; QString widgetKey = widgets[proWidget];
@ -221,8 +232,8 @@ void ProfileInterface::insertSavegameIPI(QWidget *widget)
void ProfileInterface::dialogNextPictureRequested(QWidget *dialog) void ProfileInterface::dialogNextPictureRequested(QWidget *dialog)
{ {
PictureDialog *picDialog = (PictureDialog*)dialog; PictureDialog *picDialog = qobject_cast<PictureDialog*>(dialog);
ProfileWidget *proWidget = (ProfileWidget*)sender(); ProfileWidget *proWidget = qobject_cast<ProfileWidget*>(sender());
if (widgets.contains(proWidget)) if (widgets.contains(proWidget))
{ {
QString widgetKey = widgets[proWidget]; QString widgetKey = widgets[proWidget];
@ -256,8 +267,8 @@ void ProfileInterface::dialogNextPictureRequested(QWidget *dialog)
void ProfileInterface::dialogPreviousPictureRequested(QWidget *dialog) void ProfileInterface::dialogPreviousPictureRequested(QWidget *dialog)
{ {
PictureDialog *picDialog = (PictureDialog*)dialog; PictureDialog *picDialog = qobject_cast<PictureDialog*>(dialog);
ProfileWidget *proWidget = (ProfileWidget*)sender(); ProfileWidget *proWidget = qobject_cast<ProfileWidget*>(sender());
if (widgets.contains(proWidget)) if (widgets.contains(proWidget))
{ {
QString widgetKey = widgets[proWidget]; QString widgetKey = widgets[proWidget];
@ -324,12 +335,13 @@ void ProfileInterface::profileLoaded_p()
ui->swProfile->setCurrentWidget(ui->pageProfile); ui->swProfile->setCurrentWidget(ui->pageProfile);
ui->cmdCloseProfile->setEnabled(true); ui->cmdCloseProfile->setEnabled(true);
ui->cmdImport->setEnabled(true); ui->cmdImport->setEnabled(true);
isProfileLoaded = true;
emit profileLoaded(); emit profileLoaded();
} }
void ProfileInterface::savegameDeleted_event() void ProfileInterface::savegameDeleted_event()
{ {
savegameDeleted((SavegameWidget*)sender(), true); savegameDeleted(qobject_cast<SavegameWidget*>(sender()), true);
} }
void ProfileInterface::savegameDeleted(SavegameWidget *sgdWidget, bool isRemoteEmited) void ProfileInterface::savegameDeleted(SavegameWidget *sgdWidget, bool isRemoteEmited)
@ -338,13 +350,21 @@ void ProfileInterface::savegameDeleted(SavegameWidget *sgdWidget, bool isRemoteE
if (sgdWidget->isSelected()) { sgdWidget->setSelected(false); } if (sgdWidget->isSelected()) { sgdWidget->setSelected(false); }
widgets.remove(sgdWidget); widgets.remove(sgdWidget);
sgdWidget->removeEventFilter(this);
if (sgdWidget == previousWidget)
{
previousWidget = nullptr;
}
// Deleting when the widget did send a event cause a crash // Deleting when the widget did send a event cause a crash
if (isRemoteEmited) if (isRemoteEmited)
{ {
sgdWidget->disconnect();
sgdWidget->deleteLater(); sgdWidget->deleteLater();
} }
else else
{ {
sgdWidget->disconnect();
delete sgdWidget; delete sgdWidget;
} }
@ -354,7 +374,7 @@ void ProfileInterface::savegameDeleted(SavegameWidget *sgdWidget, bool isRemoteE
void ProfileInterface::pictureDeleted_event() void ProfileInterface::pictureDeleted_event()
{ {
pictureDeleted((SnapmaticWidget*)sender(), true); pictureDeleted(qobject_cast<SnapmaticWidget*>(sender()), true);
} }
void ProfileInterface::pictureDeleted(SnapmaticWidget *picWidget, bool isRemoteEmited) void ProfileInterface::pictureDeleted(SnapmaticWidget *picWidget, bool isRemoteEmited)
@ -363,13 +383,21 @@ void ProfileInterface::pictureDeleted(SnapmaticWidget *picWidget, bool isRemoteE
if (picWidget->isSelected()) { picWidget->setSelected(false); } if (picWidget->isSelected()) { picWidget->setSelected(false); }
widgets.remove(picWidget); widgets.remove(picWidget);
picWidget->removeEventFilter(this);
if (picWidget == previousWidget)
{
previousWidget = nullptr;
}
// Deleting when the widget did send a event cause a crash // Deleting when the widget did send a event cause a crash
if (isRemoteEmited) if (isRemoteEmited)
{ {
picWidget->disconnect();
picWidget->deleteLater(); picWidget->deleteLater();
} }
else else
{ {
picWidget->disconnect();
delete picWidget; delete picWidget;
} }
@ -398,12 +426,24 @@ fileDialogPreOpen: //Work?
fileDialog.setWindowTitle(tr("Import...")); fileDialog.setWindowTitle(tr("Import..."));
fileDialog.setLabelText(QFileDialog::Accept, tr("Import")); fileDialog.setLabelText(QFileDialog::Accept, tr("Import"));
// Getting readable Image formats
QString imageFormatsStr = " ";
foreach(const QByteArray &imageFormat, QImageReader::supportedImageFormats())
{
imageFormatsStr += QString("*.") % QString::fromUtf8(imageFormat).toLower() % " ";
}
QString importableFormatsStr = QString("*.g5e SGTA* PGTA*");
if (!imageFormatsStr.trimmed().isEmpty())
{
importableFormatsStr = QString("*.g5e%1SGTA* PGTA*").arg(imageFormatsStr);
}
QStringList filters; QStringList filters;
filters << tr("Importable files (*.g5e *.jpg *.png SGTA* PGTA*)"); filters << tr("Importable files (%1)").arg(importableFormatsStr);
filters << tr("GTA V Export (*.g5e)"); filters << tr("GTA V Export (*.g5e)");
filters << tr("Savegames files (SGTA*)"); filters << tr("Savegames files (SGTA*)");
filters << tr("Snapmatic pictures (PGTA*)"); filters << tr("Snapmatic pictures (PGTA*)");
filters << tr("All image files (*.jpg *.png)"); filters << tr("All image files (%1)").arg(imageFormatsStr.trimmed());
filters << tr("All files (**)"); filters << tr("All files (**)");
fileDialog.setNameFilters(filters); fileDialog.setNameFilters(filters);
@ -520,7 +560,7 @@ bool ProfileInterface::importFile(QString selectedFile, bool notMultiple)
return false; return false;
} }
} }
else if(selectedFileName.right(4) == ".jpg" || selectedFileName.right(4) == ".png") else if(isSupportedImageFile(selectedFileName))
{ {
SnapmaticPicture *picture = new SnapmaticPicture(":/template/template.g5e"); SnapmaticPicture *picture = new SnapmaticPicture(":/template/template.g5e");
if (picture->readingPicture(true, false, true, false)) if (picture->readingPicture(true, false, true, false))
@ -631,6 +671,7 @@ bool ProfileInterface::importFile(QString selectedFile, bool notMultiple)
snapmaticImageReader.setDevice(&snapmaticFile); snapmaticImageReader.setDevice(&snapmaticFile);
if (!snapmaticImageReader.read(&snapmaticImage)) if (!snapmaticImageReader.read(&snapmaticImage))
{ {
QMessageBox::warning(this, tr("Import"), tr("Can't import %1 because file can't be parsed properly").arg("\""+selectedFileName+"\""));
delete picture; delete picture;
return false; return false;
} }
@ -640,7 +681,7 @@ bool ProfileInterface::importFile(QString selectedFile, bool notMultiple)
importDialog->setModal(true); importDialog->setModal(true);
importDialog->show(); importDialog->show();
importDialog->exec(); importDialog->exec();
if (importDialog->isDoImport()) if (importDialog->isImportAgreed())
{ {
if (picture->setImage(importDialog->image())) if (picture->setImage(importDialog->image()))
{ {
@ -705,9 +746,13 @@ bool ProfileInterface::importFile(QString selectedFile, bool notMultiple)
} }
else else
{ {
delete savegame; #ifdef GTA5SYNC_DEBUG
qDebug() << "ImportError SnapmaticPicture" << picture->getLastStep();
qDebug() << "ImportError SavegameData" << savegame->getLastStep();
#endif
delete picture; delete picture;
if (notMultiple) QMessageBox::warning(this, tr("Import"), tr("Can't import %1 because of not valid file format").arg("\""+selectedFileName+"\"")); delete savegame;
if (notMultiple) QMessageBox::warning(this, tr("Import"), tr("Can't import %1 because file format can't be detected").arg("\""+selectedFileName+"\""));
return false; return false;
} }
} }
@ -738,7 +783,7 @@ bool ProfileInterface::importSnapmaticPicture(SnapmaticPicture *picture, bool wa
if (warn) QMessageBox::warning(this, tr("Import"), tr("Failed to import the Snapmatic picture, the picture is already in the game")); if (warn) QMessageBox::warning(this, tr("Import"), tr("Failed to import the Snapmatic picture, the picture is already in the game"));
return false; return false;
} }
else if (picture->exportPicture(profileFolder % QDir::separator() % adjustedFileName, "PGTA")) else if (picture->exportPicture(profileFolder % QDir::separator() % adjustedFileName, SnapmaticFormat::PGTA_Format))
{ {
picture->setPicFilePath(profileFolder % QDir::separator() % adjustedFileName); picture->setPicFilePath(profileFolder % QDir::separator() % adjustedFileName);
pictureLoaded(picture, true); pictureLoaded(picture, true);
@ -914,8 +959,10 @@ void ProfileInterface::exportSelected()
} }
else else
{ {
pictureExportEnabled = true; // Don't export anymore when any Cancel button got clicked
pictureCopyEnabled = true; settings.endGroup();
settings.endGroup();
return;
} }
} }
@ -934,7 +981,7 @@ void ProfileInterface::exportSelected()
QProgressDialog pbDialog(this); QProgressDialog pbDialog(this);
pbDialog.setWindowFlags(pbDialog.windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint); pbDialog.setWindowFlags(pbDialog.windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint);
pbDialog.setWindowTitle(tr("Export selected...")); pbDialog.setWindowTitle(tr("Export selected..."));
pbDialog.setLabelText(tr("Initializing export...")); pbDialog.setLabelText(tr("Initialising export..."));
pbDialog.setRange(0, exportCount); pbDialog.setRange(0, exportCount);
QList<QPushButton*> pbBtn = pbDialog.findChildren<QPushButton*>(); QList<QPushButton*> pbBtn = pbDialog.findChildren<QPushButton*>();
@ -1003,7 +1050,7 @@ void ProfileInterface::deleteSelected()
{ {
if (widget->getWidgetType() == "SnapmaticWidget") if (widget->getWidgetType() == "SnapmaticWidget")
{ {
SnapmaticWidget *picWidget = (SnapmaticWidget*)widget; SnapmaticWidget *picWidget = qobject_cast<SnapmaticWidget*>(widget);
if (picWidget->getPicture()->deletePicFile()) if (picWidget->getPicture()->deletePicFile())
{ {
pictureDeleted(picWidget); pictureDeleted(picWidget);
@ -1011,7 +1058,7 @@ void ProfileInterface::deleteSelected()
} }
else if (widget->getWidgetType() == "SavegameWidget") else if (widget->getWidgetType() == "SavegameWidget")
{ {
SavegameWidget *sgdWidget = (SavegameWidget*)widget; SavegameWidget *sgdWidget = qobject_cast<SavegameWidget*>(widget);
SavegameData *savegame = sgdWidget->getSavegame(); SavegameData *savegame = sgdWidget->getSavegame();
QString fileName = savegame->getSavegameFileName(); QString fileName = savegame->getSavegameFileName();
if (!QFile::exists(fileName) || QFile::remove(fileName)) if (!QFile::exists(fileName) || QFile::remove(fileName))
@ -1038,9 +1085,15 @@ void ProfileInterface::importFiles()
on_cmdImport_clicked(); on_cmdImport_clicked();
} }
void ProfileInterface::settingsApplied(int _contentMode, QString language) void ProfileInterface::settingsApplied(int _contentMode, QString _language)
{ {
Q_UNUSED(language) bool translationUpdated = false;
if (language != _language)
{
retranslateUi();
language = _language;
translationUpdated = true;
}
contentMode = _contentMode; contentMode = _contentMode;
if (contentMode == 2) if (contentMode == 2)
@ -1049,6 +1102,7 @@ void ProfileInterface::settingsApplied(int _contentMode, QString language)
{ {
widget->setSelectionMode(true); widget->setSelectionMode(true);
widget->setContentMode(contentMode); widget->setContentMode(contentMode);
if (translationUpdated) widget->retranslate();
} }
} }
else else
@ -1060,6 +1114,7 @@ void ProfileInterface::settingsApplied(int _contentMode, QString language)
widget->setSelectionMode(false); widget->setSelectionMode(false);
} }
widget->setContentMode(contentMode); widget->setContentMode(contentMode);
if (translationUpdated) widget->retranslate();
} }
} }
} }
@ -1073,7 +1128,7 @@ void ProfileInterface::enableSelected()
{ {
if (widget->getWidgetType() == "SnapmaticWidget") if (widget->getWidgetType() == "SnapmaticWidget")
{ {
SnapmaticWidget *snapmaticWidget = (SnapmaticWidget*)widget; SnapmaticWidget *snapmaticWidget = qobject_cast<SnapmaticWidget*>(widget);
if (!snapmaticWidget->makePictureVisible()) if (!snapmaticWidget->makePictureVisible())
{ {
fails++; fails++;
@ -1092,7 +1147,7 @@ void ProfileInterface::disableSelected()
{ {
if (widget->getWidgetType() == "SnapmaticWidget") if (widget->getWidgetType() == "SnapmaticWidget")
{ {
SnapmaticWidget *snapmaticWidget = (SnapmaticWidget*)widget; SnapmaticWidget *snapmaticWidget = qobject_cast<SnapmaticWidget*>(widget);
if (!snapmaticWidget->makePictureHidden()) if (!snapmaticWidget->makePictureHidden())
{ {
fails++; fails++;
@ -1109,7 +1164,16 @@ int ProfileInterface::selectedWidgets()
void ProfileInterface::contextMenuTriggeredPIC(QContextMenuEvent *ev) void ProfileInterface::contextMenuTriggeredPIC(QContextMenuEvent *ev)
{ {
SnapmaticWidget *picWidget = (SnapmaticWidget*)sender(); SnapmaticWidget *picWidget = qobject_cast<SnapmaticWidget*>(sender());
if (picWidget != previousWidget)
{
if (previousWidget != nullptr)
{
previousWidget->setStyleSheet(QLatin1String(""));
}
picWidget->setStyleSheet(QString("QFrame#SnapmaticFrame{background-color: rgb(%1, %2, %3)}QLabel#labPicStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
previousWidget = picWidget;
}
QMenu contextMenu(picWidget); QMenu contextMenu(picWidget);
QMenu editMenu(SnapmaticWidget::tr("Edi&t"), picWidget); QMenu editMenu(SnapmaticWidget::tr("Edi&t"), picWidget);
if (picWidget->isHidden()) if (picWidget->isHidden())
@ -1122,8 +1186,8 @@ void ProfileInterface::contextMenuTriggeredPIC(QContextMenuEvent *ev)
} }
editMenu.addAction(SnapmaticWidget::tr("&Edit Properties..."), picWidget, SLOT(editSnapmaticProperties())); editMenu.addAction(SnapmaticWidget::tr("&Edit Properties..."), picWidget, SLOT(editSnapmaticProperties()));
QMenu exportMenu(SnapmaticWidget::tr("&Export"), this); QMenu exportMenu(SnapmaticWidget::tr("&Export"), this);
exportMenu.addAction(SnapmaticWidget::tr("Export as &JPG picture..."), picWidget, SLOT(on_cmdExport_clicked())); exportMenu.addAction(SnapmaticWidget::tr("Export as &Picture..."), picWidget, SLOT(on_cmdExport_clicked()));
exportMenu.addAction(SnapmaticWidget::tr("Export as &GTA Snapmatic..."), picWidget, SLOT(on_cmdCopy_clicked())); exportMenu.addAction(SnapmaticWidget::tr("Export as &Snapmatic..."), picWidget, SLOT(on_cmdCopy_clicked()));
contextMenu.addAction(SnapmaticWidget::tr("&View"), picWidget, SLOT(on_cmdView_clicked())); contextMenu.addAction(SnapmaticWidget::tr("&View"), picWidget, SLOT(on_cmdView_clicked()));
contextMenu.addMenu(&editMenu); contextMenu.addMenu(&editMenu);
contextMenu.addMenu(&exportMenu); contextMenu.addMenu(&exportMenu);
@ -1139,12 +1203,24 @@ void ProfileInterface::contextMenuTriggeredPIC(QContextMenuEvent *ev)
{ {
contextMenu.addAction(SnapmaticWidget::tr("&Deselect All"), picWidget, SLOT(deselectAllWidgets()), QKeySequence::fromString("Ctrl+D")); contextMenu.addAction(SnapmaticWidget::tr("&Deselect All"), picWidget, SLOT(deselectAllWidgets()), QKeySequence::fromString("Ctrl+D"));
} }
contextMenuOpened = true;
contextMenu.exec(ev->globalPos()); contextMenu.exec(ev->globalPos());
contextMenuOpened = false;
hoverProfileWidgetCheck();
} }
void ProfileInterface::contextMenuTriggeredSGD(QContextMenuEvent *ev) void ProfileInterface::contextMenuTriggeredSGD(QContextMenuEvent *ev)
{ {
SavegameWidget *sgdWidget = (SavegameWidget*)sender(); SavegameWidget *sgdWidget = qobject_cast<SavegameWidget*>(sender());
if (sgdWidget != previousWidget)
{
if (previousWidget != nullptr)
{
previousWidget->setStyleSheet(QLatin1String(""));
}
sgdWidget->setStyleSheet(QString("QFrame#SavegameFrame{background-color: rgb(%1, %2, %3)}QLabel#labSavegameStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
previousWidget = sgdWidget;
}
QMenu contextMenu(sgdWidget); QMenu contextMenu(sgdWidget);
contextMenu.addAction(SavegameWidget::tr("&View"), sgdWidget, SLOT(on_cmdView_clicked())); contextMenu.addAction(SavegameWidget::tr("&View"), sgdWidget, SLOT(on_cmdView_clicked()));
contextMenu.addAction(SavegameWidget::tr("&Export"), sgdWidget, SLOT(on_cmdCopy_clicked())); contextMenu.addAction(SavegameWidget::tr("&Export"), sgdWidget, SLOT(on_cmdCopy_clicked()));
@ -1160,7 +1236,10 @@ void ProfileInterface::contextMenuTriggeredSGD(QContextMenuEvent *ev)
{ {
contextMenu.addAction(SavegameWidget::tr("&Deselect All"), sgdWidget, SLOT(deselectAllWidgets()), QKeySequence::fromString("Ctrl+D")); contextMenu.addAction(SavegameWidget::tr("&Deselect All"), sgdWidget, SLOT(deselectAllWidgets()), QKeySequence::fromString("Ctrl+D"));
} }
contextMenuOpened = true;
contextMenu.exec(ev->globalPos()); contextMenu.exec(ev->globalPos());
contextMenuOpened = false;
hoverProfileWidgetCheck();
} }
void ProfileInterface::on_saProfileContent_dropped(const QMimeData *mimeData) void ProfileInterface::on_saProfileContent_dropped(const QMimeData *mimeData)
@ -1187,3 +1266,200 @@ void ProfileInterface::on_saProfileContent_dropped(const QMimeData *mimeData)
importFilesProgress(pathList); importFilesProgress(pathList);
} }
} }
void ProfileInterface::retranslateUi()
{
ui->retranslateUi(this);
ui->labVersion->setText(QString("%1 %2").arg(GTA5SYNC_APPSTR, GTA5SYNC_APPVER));
}
bool ProfileInterface::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::MouseMove)
{
if ((watched->objectName() == "SavegameWidget" || watched->objectName() == "SnapmaticWidget") && isProfileLoaded)
{
ProfileWidget *pWidget = qobject_cast<ProfileWidget*>(watched);
if (pWidget->underMouse())
{
bool styleSheetChanged = false;
if (pWidget->getWidgetType() == "SnapmaticWidget")
{
if (pWidget != previousWidget)
{
pWidget->setStyleSheet(QString("QFrame#SnapmaticFrame{background-color: rgb(%1, %2, %3)}QLabel#labPicStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
styleSheetChanged = true;
}
}
else if (pWidget->getWidgetType() == "SavegameWidget")
{
if (pWidget != previousWidget)
{
pWidget->setStyleSheet(QString("QFrame#SavegameFrame{background-color: rgb(%1, %2, %3)}QLabel#labSavegameStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
styleSheetChanged = true;
}
}
if (styleSheetChanged)
{
if (previousWidget != nullptr)
{
previousWidget->setStyleSheet(QLatin1String(""));
}
previousWidget = pWidget;
}
}
return true;
}
}
else if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::WindowActivate)
{
if ((watched->objectName() == "SavegameWidget" || watched->objectName() == "SnapmaticWidget") && isProfileLoaded)
{
ProfileWidget *pWidget = nullptr;
foreach(ProfileWidget *widget, widgets.keys())
{
QPoint mousePos = widget->mapFromGlobal(QCursor::pos());
if (widget->rect().contains(mousePos))
{
pWidget = widget;
break;
}
}
if (pWidget != nullptr)
{
bool styleSheetChanged = false;
if (pWidget->getWidgetType() == "SnapmaticWidget")
{
if (pWidget != previousWidget)
{
pWidget->setStyleSheet(QString("QFrame#SnapmaticFrame{background-color: rgb(%1, %2, %3)}QLabel#labPicStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
styleSheetChanged = true;
}
}
else if (pWidget->getWidgetType() == "SavegameWidget")
{
if (pWidget != previousWidget)
{
pWidget->setStyleSheet(QString("QFrame#SavegameFrame{background-color: rgb(%1, %2, %3)}QLabel#labSavegameStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
styleSheetChanged = true;
}
}
if (styleSheetChanged)
{
if (previousWidget != nullptr)
{
previousWidget->setStyleSheet(QLatin1String(""));
}
previousWidget = pWidget;
}
}
}
}
else if (event->type() == QEvent::WindowDeactivate && isProfileLoaded)
{
if (previousWidget != nullptr)
{
previousWidget->setStyleSheet(QLatin1String(""));
previousWidget = nullptr;
}
}
else if (event->type() == QEvent::Leave && isProfileLoaded && !contextMenuOpened)
{
if (watched->objectName() == "SavegameWidget" || watched->objectName() == "SnapmaticWidget")
{
ProfileWidget *pWidget = qobject_cast<ProfileWidget*>(watched);
QPoint mousePos = pWidget->mapFromGlobal(QCursor::pos());
if (!pWidget->geometry().contains(mousePos))
{
if (previousWidget != nullptr)
{
previousWidget->setStyleSheet(QLatin1String(""));
previousWidget = nullptr;
}
}
}
}
return false;
}
void ProfileInterface::hoverProfileWidgetCheck()
{
ProfileWidget *pWidget = nullptr;
foreach(ProfileWidget *widget, widgets.keys())
{
if (widget->underMouse())
{
pWidget = widget;
break;
}
}
if (pWidget != nullptr)
{
bool styleSheetChanged = false;
if (pWidget->getWidgetType() == "SnapmaticWidget")
{
if (pWidget != previousWidget)
{
pWidget->setStyleSheet(QString("QFrame#SnapmaticFrame{background-color: rgb(%1, %2, %3)}QLabel#labPicStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
styleSheetChanged = true;
}
}
else if (pWidget->getWidgetType() == "SavegameWidget")
{
if (pWidget != previousWidget)
{
pWidget->setStyleSheet(QString("QFrame#SavegameFrame{background-color: rgb(%1, %2, %3)}QLabel#labSavegameStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
styleSheetChanged = true;
}
}
if (styleSheetChanged)
{
if (previousWidget != nullptr)
{
previousWidget->setStyleSheet(QLatin1String(""));
}
previousWidget = pWidget;
}
}
else
{
if (previousWidget != nullptr)
{
previousWidget->setStyleSheet(QLatin1String(""));
previousWidget = nullptr;
}
}
}
void ProfileInterface::updatePalette()
{
QPalette palette;
QColor baseColor = palette.base().color();
highlightBackColor = palette.highlight().color();
highlightTextColor = palette.highlightedText().color();
ui->saProfile->setStyleSheet(QString("QWidget#saProfileContent{background-color: rgb(%1, %2, %3)}").arg(QString::number(baseColor.red()), QString::number(baseColor.green()), QString::number(baseColor.blue())));
if (previousWidget != nullptr)
{
if (previousWidget->getWidgetType() == "SnapmaticWidget")
{
previousWidget->setStyleSheet(QString("QFrame#SnapmaticFrame{background-color: rgb(%1, %2, %3)}QLabel#labPicStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
}
else if (previousWidget->getWidgetType() == "SavegameWidget")
{
previousWidget->setStyleSheet(QString("QFrame#SavegameFrame{background-color: rgb(%1, %2, %3)}QLabel#labSavegameStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
}
}
}
bool ProfileInterface::isSupportedImageFile(QString selectedFileName)
{
foreach(const QByteArray &imageFormat, QImageReader::supportedImageFormats())
{
QString imageFormatStr = QString(".") % QString::fromUtf8(imageFormat).toLower();
if (selectedFileName.length() >= imageFormatStr.length() && selectedFileName.toLower().right(imageFormatStr.length()) == imageFormatStr)
{
return true;
}
}
return false;
}

View File

@ -1,114 +1,127 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef PROFILEINTERFACE_H #ifndef PROFILEINTERFACE_H
#define PROFILEINTERFACE_H #define PROFILEINTERFACE_H
#include "SnapmaticPicture.h" #include "SnapmaticPicture.h"
#include "SnapmaticWidget.h" #include "SnapmaticWidget.h"
#include "ProfileDatabase.h" #include "ProfileDatabase.h"
#include "DatabaseThread.h" #include "DatabaseThread.h"
#include "SavegameWidget.h" #include "SavegameWidget.h"
#include "ProfileLoader.h" #include "ProfileLoader.h"
#include "ProfileWidget.h" #include "ProfileWidget.h"
#include "ExportThread.h" #include "ExportThread.h"
#include "SavegameData.h" #include "SavegameData.h"
#include "CrewDatabase.h" #include "CrewDatabase.h"
#include <QProgressDialog> #include <QProgressDialog>
#include <QSpacerItem> #include <QSpacerItem>
#include <QWidget> #include <QWidget>
#include <QList> #include <QList>
#include <QMap> #include <QMap>
namespace Ui { namespace Ui {
class ProfileInterface; class ProfileInterface;
} }
class ProfileInterface : public QWidget class ProfileInterface : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0); explicit ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0);
void setProfileFolder(QString folder, QString profile); void setProfileFolder(QString folder, QString profile);
void settingsApplied(int contentMode, QString language); void settingsApplied(int contentMode, QString language);
void setupProfileInterface(); void setupProfileInterface();
void disableSelected(); void disableSelected();
void enableSelected(); void enableSelected();
int selectedWidgets(); int selectedWidgets();
~ProfileInterface(); void retranslateUi();
~ProfileInterface();
public slots:
void contextMenuTriggeredPIC(QContextMenuEvent* ev); public slots:
void contextMenuTriggeredSGD(QContextMenuEvent* ev); void contextMenuTriggeredPIC(QContextMenuEvent* ev);
void selectAllWidgets(); void contextMenuTriggeredSGD(QContextMenuEvent* ev);
void deselectAllWidgets(); void hoverProfileWidgetCheck();
void exportSelected(); void selectAllWidgets();
void deleteSelected(); void deselectAllWidgets();
void importFiles(); void exportSelected();
void deleteSelected();
private slots: void updatePalette();
void on_cmdCloseProfile_clicked(); void importFiles();
void on_cmdImport_clicked();
void pictureLoaded_event(SnapmaticPicture *picture); private slots:
void savegameLoaded_event(SavegameData *savegame, QString savegamePath); void on_cmdCloseProfile_clicked();
void loadingProgress(int value, int maximum); void on_cmdImport_clicked();
void pictureDeleted_event(); void pictureLoaded_event(SnapmaticPicture *picture);
void savegameDeleted_event(); void savegameLoaded_event(SavegameData *savegame, QString savegamePath);
void profileLoaded_p(); void loadingProgress(int value, int maximum);
void profileWidgetSelected(); void pictureDeleted_event();
void profileWidgetDeselected(); void savegameDeleted_event();
void dialogNextPictureRequested(QWidget *dialog); void profileLoaded_p();
void dialogPreviousPictureRequested(QWidget *dialog); void profileWidgetSelected();
void on_saProfileContent_dropped(const QMimeData *mimeData); void profileWidgetDeselected();
void dialogNextPictureRequested(QWidget *dialog);
private: void dialogPreviousPictureRequested(QWidget *dialog);
ProfileDatabase *profileDB; void on_saProfileContent_dropped(const QMimeData *mimeData);
CrewDatabase *crewDB;
DatabaseThread *threadDB; protected:
Ui::ProfileInterface *ui; bool eventFilter(QObject *watched, QEvent *event);
ProfileLoader *profileLoader; private:
QList<SavegameData*> savegames; ProfileDatabase *profileDB;
QList<SnapmaticPicture*> pictures; CrewDatabase *crewDB;
QMap<ProfileWidget*,QString> widgets; DatabaseThread *threadDB;
QSpacerItem *saSpacerItem; Ui::ProfileInterface *ui;
QString enabledPicStr;
QString profileFolder; ProfileLoader *profileLoader;
QString profileName; ProfileWidget *previousWidget;
QString loadingStr; QList<SavegameData*> savegames;
int selectedWidgts; QList<SnapmaticPicture*> pictures;
int contentMode; QMap<ProfileWidget*,QString> widgets;
QSpacerItem *saSpacerItem;
bool importFile(QString selectedFile, bool notMultiple); QColor highlightBackColor;
void importFilesProgress(QStringList selectedFiles); QColor highlightTextColor;
bool importSnapmaticPicture(SnapmaticPicture *picture, bool warn = true); QString enabledPicStr;
bool importSavegameData(SavegameData *savegame, QString sgdPath, bool warn = true); QString profileFolder;
void pictureLoaded(SnapmaticPicture *picture, bool inserted); QString profileName;
void savegameLoaded(SavegameData *savegame, QString savegamePath, bool inserted); QString loadingStr;
void savegameDeleted(SavegameWidget *sgdWidget, bool isRemoteEmited = false); QString language;
void pictureDeleted(SnapmaticWidget *picWidget, bool isRemoteEmited = false); bool contextMenuOpened;
void insertSnapmaticIPI(QWidget *widget); bool isProfileLoaded;
void insertSavegameIPI(QWidget *widget); int selectedWidgts;
void sortingProfileInterface(); int contentMode;
signals: bool isSupportedImageFile(QString selectedFileName);
void profileLoaded(); bool importFile(QString selectedFile, bool notMultiple);
void profileClosed(); void importFilesProgress(QStringList selectedFiles);
}; bool importSnapmaticPicture(SnapmaticPicture *picture, bool warn = true);
bool importSavegameData(SavegameData *savegame, QString sgdPath, bool warn = true);
#endif // PROFILEINTERFACE_H void pictureLoaded(SnapmaticPicture *picture, bool inserted);
void savegameLoaded(SavegameData *savegame, QString savegamePath, bool inserted);
void savegameDeleted(SavegameWidget *sgdWidget, bool isRemoteEmited = false);
void pictureDeleted(SnapmaticWidget *picWidget, bool isRemoteEmited = false);
void insertSnapmaticIPI(QWidget *widget);
void insertSavegameIPI(QWidget *widget);
void sortingProfileInterface();
signals:
void profileLoaded();
void profileClosed();
};
#endif // PROFILEINTERFACE_H

View File

@ -1,244 +1,244 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>ProfileInterface</class> <class>ProfileInterface</class>
<widget class="QWidget" name="ProfileInterface"> <widget class="QWidget" name="ProfileInterface">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>400</width>
<height>300</height> <height>300</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Profile Interface</string> <string>Profile Interface</string>
</property> </property>
<layout class="QVBoxLayout" name="vlProfileInterface"> <layout class="QVBoxLayout" name="vlProfileInterface">
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </property>
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QStackedWidget" name="swProfile"> <widget class="QStackedWidget" name="swProfile">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="pageLoading"> <widget class="QWidget" name="pageLoading">
<layout class="QVBoxLayout" name="vlLoadingPage"> <layout class="QVBoxLayout" name="vlLoadingPage">
<item> <item>
<spacer name="vsLoading1"> <spacer name="vsLoading1">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>0</width> <width>0</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QLabel" name="labProfileLoading"> <widget class="QLabel" name="labProfileLoading">
<property name="text"> <property name="text">
<string>Loading file %1 of %2 files</string> <string>Loading file %1 of %2 files</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QProgressBar" name="pbPictureLoading"> <widget class="QProgressBar" name="pbPictureLoading">
<property name="value"> <property name="value">
<number>0</number> <number>0</number>
</property> </property>
<property name="textVisible"> <property name="textVisible">
<bool>false</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="vsLoading2"> <spacer name="vsLoading2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>0</width> <width>0</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="pageProfile"> <widget class="QWidget" name="pageProfile">
<layout class="QVBoxLayout" name="vlProfilePage"> <layout class="QVBoxLayout" name="vlProfilePage">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QScrollArea" name="saProfile"> <widget class="QScrollArea" name="saProfile">
<property name="widgetResizable"> <property name="widgetResizable">
<bool>true</bool> <bool>true</bool>
</property> </property>
<widget class="UiModWidget" name="saProfileContent"> <widget class="UiModWidget" name="saProfileContent">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>398</width> <width>398</width>
<height>257</height> <height>257</height>
</rect> </rect>
</property> </property>
<property name="acceptDrops"> <property name="acceptDrops">
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" name="vlProfile"> <layout class="QVBoxLayout" name="vlProfile">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<layout class="QVBoxLayout" name="vlContent"> <layout class="QVBoxLayout" name="vlContent">
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<layout class="QVBoxLayout" name="vlSavegame"/> <layout class="QVBoxLayout" name="vlSavegame"/>
</item> </item>
<item> <item>
<layout class="QVBoxLayout" name="vlSnapmatic"/> <layout class="QVBoxLayout" name="vlSnapmatic"/>
</item> </item>
</layout> </layout>
</item> </item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="hlButtons"> <layout class="QHBoxLayout" name="hlButtons">
<property name="spacing"> <property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin"> <property name="leftMargin">
<number>9</number> <number>9</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>9</number> <number>9</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>9</number> <number>9</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>9</number> <number>9</number>
</property> </property>
<item> <item>
<widget class="QLabel" name="labVersion"> <widget class="QLabel" name="labVersion">
<property name="text"> <property name="text">
<string>%1 %2</string> <string>%1 %2</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="hsProfile"> <spacer name="hsProfile">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="cmdImport"> <widget class="QPushButton" name="cmdImport">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Import exported file</string> <string>Import file</string>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Import...</string> <string>&amp;Import...</string>
</property> </property>
<property name="autoDefault"> <property name="autoDefault">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="cmdCloseProfile"> <widget class="QPushButton" name="cmdCloseProfile">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Close profile</string> <string>Close profile</string>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Close</string> <string>&amp;Close</string>
</property> </property>
<property name="autoDefault"> <property name="autoDefault">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>UiModWidget</class> <class>UiModWidget</class>
<extends>QWidget</extends> <extends>QWidget</extends>
<header>UiModWidget.h</header> <header>UiModWidget.h</header>
<container>1</container> <container>1</container>
<slots> <slots>
<signal>dropped(QMimeData*)</signal> <signal>dropped(QMimeData*)</signal>
</slots> </slots>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -1,103 +1,106 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "ProfileLoader.h" #include "ProfileLoader.h"
#include "SnapmaticPicture.h" #include "SnapmaticPicture.h"
#include "SavegameData.h" #include "SavegameData.h"
#include "CrewDatabase.h" #include "CrewDatabase.h"
#include <QStringList> #include <QStringBuilder>
#include <QString> #include <QStringList>
#include <QFile> #include <QString>
#include <QDir> #include <QFile>
#include <QDir>
ProfileLoader::ProfileLoader(QString profileFolder, CrewDatabase *crewDB, QObject *parent) : QThread(parent), profileFolder(profileFolder), crewDB(crewDB)
{ ProfileLoader::ProfileLoader(QString profileFolder, CrewDatabase *crewDB, QObject *parent) : QThread(parent), profileFolder(profileFolder), crewDB(crewDB)
{
}
}
void ProfileLoader::run()
{ void ProfileLoader::run()
int curFile = 1; {
QDir profileDir; int curFile = 1;
QList<int> crewList; QDir profileDir;
profileDir.setPath(profileFolder); QList<int> crewList;
profileDir.setPath(profileFolder);
// Seek pictures and savegames
profileDir.setNameFilters(QStringList("SGTA*")); // Seek pictures and savegames
QStringList SavegameFiles = profileDir.entryList(QDir::Files | QDir::NoDot, QDir::NoSort); profileDir.setNameFilters(QStringList("SGTA*"));
QStringList BackupFiles = SavegameFiles.filter(".bak", Qt::CaseInsensitive); QStringList SavegameFiles = profileDir.entryList(QDir::Files | QDir::NoDot, QDir::NoSort);
profileDir.setNameFilters(QStringList("PGTA*")); QStringList BackupFiles = SavegameFiles.filter(".bak", Qt::CaseInsensitive);
QStringList SnapmaticPics = profileDir.entryList(QDir::Files | QDir::NoDot, QDir::NoSort); profileDir.setNameFilters(QStringList("PGTA*"));
BackupFiles.append(SnapmaticPics.filter(".bak", Qt::CaseInsensitive)); QStringList SnapmaticPics = profileDir.entryList(QDir::Files | QDir::NoDot, QDir::NoSort);
BackupFiles += SnapmaticPics.filter(".bak", Qt::CaseInsensitive);
SavegameFiles.removeDuplicates();
SnapmaticPics.removeDuplicates(); SavegameFiles.removeDuplicates();
foreach(const QString &BackupFile, BackupFiles) SnapmaticPics.removeDuplicates();
{ foreach(const QString &BackupFile, BackupFiles)
SavegameFiles.removeAll(BackupFile); {
SnapmaticPics.removeAll(BackupFile); SavegameFiles.removeAll(BackupFile);
} SnapmaticPics.removeAll(BackupFile);
}
int maximumV = SavegameFiles.length() + SnapmaticPics.length();
int maximumV = SavegameFiles.length() + SnapmaticPics.length();
// Loading pictures and savegames
emit loadingProgress(curFile, maximumV); // Loading pictures and savegames
foreach(const QString &SavegameFile, SavegameFiles) emit loadingProgress(curFile, maximumV);
{ foreach(const QString &SavegameFile, SavegameFiles)
emit loadingProgress(curFile, maximumV); {
QString sgdPath = profileFolder + QDir::separator() + SavegameFile; emit loadingProgress(curFile, maximumV);
SavegameData *savegame = new SavegameData(sgdPath); QString sgdPath = profileFolder % QDir::separator() % SavegameFile;
if (savegame->readingSavegame()) SavegameData *savegame = new SavegameData(sgdPath);
{ if (savegame->readingSavegame())
emit savegameLoaded(savegame, sgdPath); {
} emit savegameLoaded(savegame, sgdPath);
curFile++; }
} curFile++;
foreach(const QString &SnapmaticPic, SnapmaticPics) }
{ foreach(const QString &SnapmaticPic, SnapmaticPics)
emit loadingProgress(curFile, maximumV); {
QString picturePath = profileFolder + QDir::separator() + SnapmaticPic; emit loadingProgress(curFile, maximumV);
SnapmaticPicture *picture = new SnapmaticPicture(picturePath); QString picturePath = profileFolder % QDir::separator() % SnapmaticPic;
if (picture->readingPicture(true, true, true)) SnapmaticPicture *picture = new SnapmaticPicture(picturePath);
{ if (picture->readingPicture(true, true, true))
emit pictureLoaded(picture); {
int crewNumber = picture->getSnapmaticProperties().crewID; emit pictureLoaded(picture);
if (!crewList.contains(crewNumber)) int crewNumber = picture->getSnapmaticProperties().crewID;
{ if (!crewList.contains(crewNumber))
crewList.append(crewNumber); {
} crewList += crewNumber;
} }
curFile++; }
} curFile++;
}
// adding found crews
foreach(int crewID, crewList) // adding found crews
{ crewDB->setAddingCrews(true);
crewDB->addCrew(crewID); foreach(int crewID, crewList)
} {
} crewDB->addCrew(crewID);
}
void ProfileLoader::preloaded() crewDB->setAddingCrews(false);
{ }
} void ProfileLoader::preloaded()
{
void ProfileLoader::loaded()
{ }
} void ProfileLoader::loaded()
{
}

View File

@ -1,52 +1,52 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef PROFILELOADER_H #ifndef PROFILELOADER_H
#define PROFILELOADER_H #define PROFILELOADER_H
#include "SnapmaticPicture.h" #include "SnapmaticPicture.h"
#include "SavegameData.h" #include "SavegameData.h"
#include "CrewDatabase.h" #include "CrewDatabase.h"
#include <QThread> #include <QThread>
#include <QDir> #include <QDir>
class ProfileLoader : public QThread class ProfileLoader : public QThread
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ProfileLoader(QString profileFolder, CrewDatabase *crewDB, QObject *parent = 0); explicit ProfileLoader(QString profileFolder, CrewDatabase *crewDB, QObject *parent = 0);
protected: protected:
void run(); void run();
private: private:
QString profileFolder; QString profileFolder;
CrewDatabase *crewDB; CrewDatabase *crewDB;
ProfileLoader *profileLoader; ProfileLoader *profileLoader;
private slots: private slots:
void preloaded(); void preloaded();
void loaded(); void loaded();
signals: signals:
void pictureLoaded(SnapmaticPicture *picture); void pictureLoaded(SnapmaticPicture *picture);
void savegameLoaded(SavegameData *savegame, QString savegamePath); void savegameLoaded(SavegameData *savegame, QString savegamePath);
void loadingProgress(int value, int maximum); void loadingProgress(int value, int maximum);
}; };
#endif // PROFILELOADER_H #endif // PROFILELOADER_H

View File

@ -1,61 +1,66 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "ProfileWidget.h" #include "ProfileWidget.h"
#include <QDebug> #include <QDebug>
ProfileWidget::ProfileWidget(QWidget *parent) : QWidget(parent) ProfileWidget::ProfileWidget(QWidget *parent) : QWidget(parent)
{ {
contentMode = 0; contentMode = 0;
} }
ProfileWidget::~ProfileWidget() ProfileWidget::~ProfileWidget()
{ {
} }
bool ProfileWidget::isSelected() void ProfileWidget::retranslate()
{ {
qDebug() << "ProfileWidget::isSelected got used without overwrite"; qDebug() << "ProfileWidget::retranslate got used without overwrite";
return false; }
}
bool ProfileWidget::isSelected()
void ProfileWidget::setSelected(bool isSelected) {
{ qDebug() << "ProfileWidget::isSelected got used without overwrite";
qDebug() << "ProfileWidget::setSelected got used without overwrite, result" << isSelected; return false;
} }
void ProfileWidget::setSelectionMode(bool selectionMode) void ProfileWidget::setSelected(bool isSelected)
{ {
qDebug() << "ProfileWidget::setSelectionMode got used without overwrite, result:" << selectionMode; qDebug() << "ProfileWidget::setSelected got used without overwrite, result" << isSelected;
} }
QString ProfileWidget::getWidgetType() void ProfileWidget::setSelectionMode(bool selectionMode)
{ {
qDebug() << "ProfileWidget::getWidgetType got used without overwrite"; qDebug() << "ProfileWidget::setSelectionMode got used without overwrite, result:" << selectionMode;
return "ProfileWidget"; }
}
QString ProfileWidget::getWidgetType()
int ProfileWidget::getContentMode() {
{ qDebug() << "ProfileWidget::getWidgetType got used without overwrite";
return contentMode; return "ProfileWidget";
} }
void ProfileWidget::setContentMode(int _contentMode) int ProfileWidget::getContentMode()
{ {
contentMode = _contentMode; return contentMode;
} }
void ProfileWidget::setContentMode(int _contentMode)
{
contentMode = _contentMode;
}

View File

@ -1,45 +1,46 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef PROFILEWIDGET_H #ifndef PROFILEWIDGET_H
#define PROFILEWIDGET_H #define PROFILEWIDGET_H
#include <QWidget> #include <QWidget>
class ProfileWidget : public QWidget class ProfileWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ProfileWidget(QWidget *parent = 0); explicit ProfileWidget(QWidget *parent = 0);
virtual void setSelectionMode(bool selectionMode); virtual void setSelectionMode(bool selectionMode);
virtual void setContentMode(int contentMode); virtual void setContentMode(int contentMode);
virtual void setSelected(bool isSelected); virtual void setSelected(bool isSelected);
virtual bool isSelected(); virtual bool isSelected();
virtual QString getWidgetType(); virtual QString getWidgetType();
virtual int getContentMode(); virtual int getContentMode();
~ProfileWidget(); virtual void retranslate();
~ProfileWidget();
private:
int contentMode; private:
int contentMode;
signals:
signals:
public slots:
}; public slots:
};
#endif // PROFILEWIDGET_H
#endif // PROFILEWIDGET_H

View File

@ -1,100 +1,100 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "SidebarGenerator.h" #include "SidebarGenerator.h"
#include "SavegameWidget.h" #include "SavegameWidget.h"
#include "SavegameCopy.h" #include "SavegameCopy.h"
#include "config.h" #include "config.h"
#include <QMessageBox> #include <QMessageBox>
#include <QFileDialog> #include <QFileDialog>
#include <QSettings> #include <QSettings>
SavegameCopy::SavegameCopy() SavegameCopy::SavegameCopy()
{ {
} }
void SavegameCopy::copySavegame(QWidget *parent, QString sgdPath) void SavegameCopy::copySavegame(QWidget *parent, QString sgdPath)
{ {
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("FileDialogs"); settings.beginGroup("FileDialogs");
fileDialogPreSave: //Work? fileDialogPreSave: //Work?
QFileInfo sgdFileInfo(sgdPath); QFileInfo sgdFileInfo(sgdPath);
QFileDialog fileDialog(parent); QFileDialog fileDialog(parent);
fileDialog.setFileMode(QFileDialog::AnyFile); fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setViewMode(QFileDialog::Detail); fileDialog.setViewMode(QFileDialog::Detail);
fileDialog.setAcceptMode(QFileDialog::AcceptSave); fileDialog.setAcceptMode(QFileDialog::AcceptSave);
fileDialog.setOption(QFileDialog::DontUseNativeDialog, false); fileDialog.setOption(QFileDialog::DontUseNativeDialog, false);
fileDialog.setOption(QFileDialog::DontConfirmOverwrite, true); fileDialog.setOption(QFileDialog::DontConfirmOverwrite, true);
fileDialog.setDefaultSuffix(""); fileDialog.setDefaultSuffix("");
fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint); fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
fileDialog.setWindowTitle(SavegameWidget::tr(("Export Savegame..."))); fileDialog.setWindowTitle(SavegameWidget::tr(("Export Savegame...")));
fileDialog.setLabelText(QFileDialog::Accept, SavegameWidget::tr("Export")); fileDialog.setLabelText(QFileDialog::Accept, SavegameWidget::tr("Export"));
QStringList filters; QStringList filters;
filters << SavegameWidget::tr("Savegame files (SGTA*)"); filters << SavegameWidget::tr("Savegame files (SGTA*)");
filters << SavegameWidget::tr("All files (**)"); filters << SavegameWidget::tr("All files (**)");
fileDialog.setNameFilters(filters); fileDialog.setNameFilters(filters);
QList<QUrl> sidebarUrls = SidebarGenerator::generateSidebarUrls(fileDialog.sidebarUrls()); QList<QUrl> sidebarUrls = SidebarGenerator::generateSidebarUrls(fileDialog.sidebarUrls());
fileDialog.setSidebarUrls(sidebarUrls); fileDialog.setSidebarUrls(sidebarUrls);
fileDialog.restoreState(settings.value("CopySavegame","").toByteArray()); fileDialog.restoreState(settings.value("CopySavegame","").toByteArray());
fileDialog.selectFile(sgdFileInfo.fileName()); fileDialog.selectFile(sgdFileInfo.fileName());
if (fileDialog.exec()) if (fileDialog.exec())
{ {
QStringList selectedFiles = fileDialog.selectedFiles(); QStringList selectedFiles = fileDialog.selectedFiles();
if (selectedFiles.length() == 1) if (selectedFiles.length() == 1)
{ {
QString selectedFile = selectedFiles.at(0); QString selectedFile = selectedFiles.at(0);
if (QFile::exists(selectedFile)) if (QFile::exists(selectedFile))
{ {
if (QMessageBox::Yes == QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("Overwrite %1 with current Savegame?").arg("\""+selectedFile+"\""), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes)) if (QMessageBox::Yes == QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("Overwrite %1 with current Savegame?").arg("\""+selectedFile+"\""), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes))
{ {
if (!QFile::remove(selectedFile)) if (!QFile::remove(selectedFile))
{ {
QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("Failed to overwrite %1 with current Savegame").arg("\""+selectedFile+"\"")); QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("Failed to overwrite %1 with current Savegame").arg("\""+selectedFile+"\""));
goto fileDialogPreSave; //Work? goto fileDialogPreSave; //Work?
} }
} }
else else
{ {
goto fileDialogPreSave; //Work? goto fileDialogPreSave; //Work?
} }
} }
bool isCopied = QFile::copy(sgdPath, selectedFile); bool isCopied = QFile::copy(sgdPath, selectedFile);
if (!isCopied) if (!isCopied)
{ {
QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("Failed to export current Savegame")); QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("Failed to export current Savegame"));
goto fileDialogPreSave; //Work? goto fileDialogPreSave; //Work?
} }
} }
else else
{ {
QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("No valid file is selected")); QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("No valid file is selected"));
goto fileDialogPreSave; //Work? goto fileDialogPreSave; //Work?
} }
} }
settings.setValue("CopySavegame", fileDialog.saveState()); settings.setValue("CopySavegame", fileDialog.saveState());
settings.endGroup(); settings.endGroup();
} }

View File

@ -1,32 +1,32 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef SAVEGAMECOPY_H #ifndef SAVEGAMECOPY_H
#define SAVEGAMECOPY_H #define SAVEGAMECOPY_H
#include <QWidget> #include <QWidget>
#include <QString> #include <QString>
class SavegameCopy class SavegameCopy
{ {
public: public:
SavegameCopy(); SavegameCopy();
static void copySavegame(QWidget *parent, QString sgdPath); static void copySavegame(QWidget *parent, QString sgdPath);
}; };
#endif // SAVEGAMECOPY_H #endif // SAVEGAMECOPY_H

View File

@ -1,119 +1,120 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "StringParser.h" #include "StringParser.h"
#include "SavegameData.h" #include "SavegameData.h"
#include <QTextCodec> #include <QStringBuilder>
#include <QByteArray> #include <QTextCodec>
#include <QDebug> #include <QByteArray>
#include <QFile> #include <QDebug>
#include <QFile>
#define savegameHeaderLength 260
#define verificationValue QByteArray::fromHex("00000001") #define savegameHeaderLength 260
#define verificationValue QByteArray::fromHex("00000001")
SavegameData::SavegameData(const QString &fileName, QObject *parent) : QObject(parent), savegameFileName(fileName)
{ SavegameData::SavegameData(const QString &fileName, QObject *parent) : QObject(parent), savegameFileName(fileName)
// INIT SAVEGAME {
savegameStr = ""; // INIT SAVEGAME
savegameOk = 0; savegameStr = "";
} savegameOk = 0;
}
bool SavegameData::readingSavegame()
{ bool SavegameData::readingSavegame()
// Start opening file {
// lastStep is like currentStep // Start opening file
// lastStep is like currentStep
QFile *saveFile = new QFile(savegameFileName);
if (!saveFile->open(QFile::ReadOnly)) QFile *saveFile = new QFile(savegameFileName);
{ if (!saveFile->open(QFile::ReadOnly))
lastStep = "1;/1,OpenFile," + StringParser::convertDrawStringForLog(savegameFileName); {
saveFile->deleteLater(); lastStep = "1;/1,OpenFile," % StringParser::convertDrawStringForLog(savegameFileName);
delete saveFile; saveFile->deleteLater();
return false; delete saveFile;
} return false;
}
// Reading Savegame Header
if (!saveFile->isReadable()) // Reading Savegame Header
{ if (!saveFile->isReadable())
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(savegameFileName) + ",1,NOHEADER"; {
saveFile->close(); lastStep = "2;/3,ReadingFile," % StringParser::convertDrawStringForLog(savegameFileName) % ",1,NOHEADER";
saveFile->deleteLater(); saveFile->close();
delete saveFile; saveFile->deleteLater();
return false; delete saveFile;
} return false;
QByteArray savegameHeaderLine = saveFile->read(savegameHeaderLength); }
if (savegameHeaderLine.left(4) == verificationValue) QByteArray savegameHeaderLine = saveFile->read(savegameHeaderLength);
{ if (savegameHeaderLine.left(4) == verificationValue)
savegameStr = getSavegameDataString(savegameHeaderLine); {
if (savegameStr.length() >= 1) savegameStr = getSavegameDataString(savegameHeaderLine);
{ if (savegameStr.length() >= 1)
savegameOk = true; {
} savegameOk = true;
} }
saveFile->close(); }
saveFile->deleteLater(); saveFile->close();
delete saveFile; saveFile->deleteLater();
return savegameOk; delete saveFile;
} return savegameOk;
}
QString SavegameData::getSavegameDataString(const QByteArray &savegameHeader)
{ QString SavegameData::getSavegameDataString(const QByteArray &savegameHeader)
QByteArray savegameBytes = savegameHeader.left(savegameHeaderLength); {
QList<QByteArray> savegameBytesList = savegameBytes.split(char(0x01)); QByteArray savegameBytes = savegameHeader.left(savegameHeaderLength);
savegameBytes = savegameBytesList.at(1); QList<QByteArray> savegameBytesList = savegameBytes.split(char(0x01));
savegameBytesList.clear(); savegameBytes = savegameBytesList.at(1);
return StringParser::parseTitleString(savegameBytes, savegameBytes.length()); savegameBytesList.clear();
} return StringParser::parseTitleString(savegameBytes, savegameBytes.length());
}
bool SavegameData::readingSavegameFromFile(const QString &fileName)
{ bool SavegameData::readingSavegameFromFile(const QString &fileName)
if (fileName != "") {
{ if (fileName != "")
savegameFileName = fileName; {
return readingSavegame(); savegameFileName = fileName;
} return readingSavegame();
else }
{ else
return false; {
} return false;
} }
}
bool SavegameData::isSavegameOk()
{ bool SavegameData::isSavegameOk()
return savegameOk; {
} return savegameOk;
}
QString SavegameData::getSavegameFileName()
{ QString SavegameData::getSavegameFileName()
return savegameFileName; {
} return savegameFileName;
}
QString SavegameData::getSavegameStr()
{ QString SavegameData::getSavegameStr()
return savegameStr; {
} return savegameStr;
}
QString SavegameData::getLastStep()
{ QString SavegameData::getLastStep()
return lastStep; {
} return lastStep;
}
void SavegameData::setSavegameFileName(QString savegameFileName_)
{ void SavegameData::setSavegameFileName(QString savegameFileName_)
savegameFileName = savegameFileName_; {
} savegameFileName = savegameFileName_;
}

View File

@ -1,45 +1,45 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef SAVEGAMEDATA_H #ifndef SAVEGAMEDATA_H
#define SAVEGAMEDATA_H #define SAVEGAMEDATA_H
#include <QObject> #include <QObject>
class SavegameData : public QObject class SavegameData : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SavegameData(const QString &fileName = "", QObject *parent = 0); explicit SavegameData(const QString &fileName = "", QObject *parent = 0);
bool readingSavegameFromFile(const QString &fileName); bool readingSavegameFromFile(const QString &fileName);
bool readingSavegame(); bool readingSavegame();
bool isSavegameOk(); bool isSavegameOk();
QString getLastStep(); QString getLastStep();
QString getSavegameStr(); QString getSavegameStr();
QString getSavegameFileName(); QString getSavegameFileName();
void setSavegameFileName(QString savegameFileName); void setSavegameFileName(QString savegameFileName);
private: private:
QString getSavegameDataString(const QByteArray &savegameHeader); QString getSavegameDataString(const QByteArray &savegameHeader);
QString savegameFileName; QString savegameFileName;
QString savegameStr; QString savegameStr;
QString lastStep; QString lastStep;
bool savegameOk; bool savegameOk;
}; };
#endif // SAVEGAMEDATA_H #endif // SAVEGAMEDATA_H

View File

@ -1,53 +1,53 @@
#include "SavegameDialog.h" #include "SavegameDialog.h"
#include "ui_SavegameDialog.h" #include "ui_SavegameDialog.h"
#include "SavegameCopy.h" #include "SavegameCopy.h"
#include "AppEnv.h" #include "AppEnv.h"
#include <QMessageBox> #include <QMessageBox>
SavegameDialog::SavegameDialog(QWidget *parent) : SavegameDialog::SavegameDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::SavegameDialog) ui(new Ui::SavegameDialog)
{ {
// Set Window Flags // Set Window Flags
setWindowFlags(windowFlags()^Qt::WindowContextHelpButtonHint); setWindowFlags(windowFlags()^Qt::WindowContextHelpButtonHint);
// Setup User Interface // Setup User Interface
ui->setupUi(this); ui->setupUi(this);
savegameLabStr = ui->labSavegameText->text(); savegameLabStr = ui->labSavegameText->text();
if (QIcon::hasThemeIcon("dialog-close")) if (QIcon::hasThemeIcon("dialog-close"))
{ {
ui->cmdClose->setIcon(QIcon::fromTheme("dialog-close")); ui->cmdClose->setIcon(QIcon::fromTheme("dialog-close"));
} }
// DPI calculation // DPI calculation
qreal screenRatio = AppEnv::screenRatio(); qreal screenRatio = AppEnv::screenRatio();
resize(400 * screenRatio, 105 * screenRatio); resize(400 * screenRatio, 105 * screenRatio);
} }
SavegameDialog::~SavegameDialog() SavegameDialog::~SavegameDialog()
{ {
delete ui; delete ui;
} }
void SavegameDialog::setSavegameData(SavegameData *savegame, QString savegamePath, bool readOk) void SavegameDialog::setSavegameData(SavegameData *savegame, QString savegamePath, bool readOk)
{ {
// Showing error if reading error // Showing error if reading error
if (!readOk) if (!readOk)
{ {
QMessageBox::warning(this,tr("Savegame Viewer"),tr("Failed at %1").arg(savegame->getLastStep())); QMessageBox::warning(this,tr("Savegame Viewer"),tr("Failed at %1").arg(savegame->getLastStep()));
return; return;
} }
sgdPath = savegamePath; sgdPath = savegamePath;
ui->labSavegameText->setText(savegameLabStr.arg(savegame->getSavegameStr())); ui->labSavegameText->setText(savegameLabStr.arg(savegame->getSavegameStr()));
} }
void SavegameDialog::on_cmdClose_clicked() void SavegameDialog::on_cmdClose_clicked()
{ {
this->close(); this->close();
} }
void SavegameDialog::on_cmdCopy_clicked() void SavegameDialog::on_cmdCopy_clicked()
{ {
SavegameCopy::copySavegame(this, sgdPath); SavegameCopy::copySavegame(this, sgdPath);
} }

View File

@ -1,29 +1,29 @@
#ifndef SAVEGAMEDIALOG_H #ifndef SAVEGAMEDIALOG_H
#define SAVEGAMEDIALOG_H #define SAVEGAMEDIALOG_H
#include "SavegameData.h" #include "SavegameData.h"
#include <QDialog> #include <QDialog>
namespace Ui { namespace Ui {
class SavegameDialog; class SavegameDialog;
} }
class SavegameDialog : public QDialog class SavegameDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SavegameDialog(QWidget *parent = 0); explicit SavegameDialog(QWidget *parent = 0);
void setSavegameData(SavegameData *savegame, QString sgdPath, bool readOk); void setSavegameData(SavegameData *savegame, QString sgdPath, bool readOk);
~SavegameDialog(); ~SavegameDialog();
private slots: private slots:
void on_cmdClose_clicked(); void on_cmdClose_clicked();
void on_cmdCopy_clicked(); void on_cmdCopy_clicked();
private: private:
Ui::SavegameDialog *ui; Ui::SavegameDialog *ui;
QString savegameLabStr; QString savegameLabStr;
QString sgdPath; QString sgdPath;
}; };
#endif // SAVEGAMEDIALOG_H #endif // SAVEGAMEDIALOG_H

View File

@ -1,86 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>SavegameDialog</class> <class>SavegameDialog</class>
<widget class="QDialog" name="SavegameDialog"> <widget class="QDialog" name="SavegameDialog">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>400</width>
<height>105</height> <height>105</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Savegame Viewer</string> <string>Savegame Viewer</string>
</property> </property>
<property name="modal"> <property name="modal">
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" name="vlSavegameDialog"> <layout class="QVBoxLayout" name="vlSavegameDialog">
<item> <item>
<widget class="QLabel" name="labSavegameText"> <widget class="QLabel" name="labSavegameText">
<property name="sizePolicy"> <property name="text">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <string>&lt;span style=&quot; font-weight:600;&quot;&gt;Savegame&lt;/span&gt;&lt;br&gt;&lt;br&gt;%1</string>
<horstretch>0</horstretch> </property>
<verstretch>0</verstretch> <property name="alignment">
</sizepolicy> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property> </property>
<property name="text"> <property name="wordWrap">
<string>&lt;span style=&quot; font-weight:600;&quot;&gt;Savegame&lt;/span&gt;&lt;br&gt;&lt;br&gt;%1</string> <bool>true</bool>
</property> </property>
<property name="alignment"> </widget>
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> </item>
</property> <item>
<property name="wordWrap"> <spacer name="vsSavegame">
<bool>true</bool> <property name="orientation">
</property> <enum>Qt::Vertical</enum>
</widget> </property>
</item> <property name="sizeHint" stdset="0">
<item> <size>
<layout class="QHBoxLayout" name="hlButtons"> <width>0</width>
<item> <height>0</height>
<spacer name="hsButtons"> </size>
<property name="orientation"> </property>
<enum>Qt::Horizontal</enum> </spacer>
</property> </item>
<property name="sizeHint" stdset="0"> <item>
<size> <layout class="QHBoxLayout" name="hlButtons">
<width>0</width> <item>
<height>0</height> <spacer name="hsButtons">
</size> <property name="orientation">
</property> <enum>Qt::Horizontal</enum>
</spacer> </property>
</item> <property name="sizeHint" stdset="0">
<item> <size>
<widget class="QPushButton" name="cmdCopy"> <width>0</width>
<property name="sizePolicy"> <height>0</height>
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> </size>
<horstretch>0</horstretch> </property>
<verstretch>0</verstretch> </spacer>
</sizepolicy> </item>
</property> <item>
<property name="text"> <widget class="QPushButton" name="cmdCopy">
<string>&amp;Export</string> <property name="sizePolicy">
</property> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
</widget> <horstretch>0</horstretch>
</item> <verstretch>0</verstretch>
<item> </sizepolicy>
<widget class="QPushButton" name="cmdClose"> </property>
<property name="sizePolicy"> <property name="text">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <string>&amp;Export</string>
<horstretch>0</horstretch> </property>
<verstretch>0</verstretch> </widget>
</sizepolicy> </item>
</property> <item>
<property name="text"> <widget class="QPushButton" name="cmdClose">
<string>&amp;Close</string> <property name="sizePolicy">
</property> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
</widget> <horstretch>0</horstretch>
</item> <verstretch>0</verstretch>
</layout> </sizepolicy>
</item> </property>
</layout> <property name="text">
</widget> <string>&amp;Close</string>
<resources/> </property>
<connections/> </widget>
</ui> </item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -1,261 +1,264 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "SavegameWidget.h" #include "SavegameWidget.h"
#include "ui_SavegameWidget.h" #include "ui_SavegameWidget.h"
#include "SidebarGenerator.h" #include "SidebarGenerator.h"
#include "SavegameDialog.h" #include "SavegameDialog.h"
#include "StandardPaths.h" #include "StandardPaths.h"
#include "SavegameData.h" #include "SavegameData.h"
#include "SavegameCopy.h" #include "SavegameCopy.h"
#include "AppEnv.h" #include "AppEnv.h"
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QSettings> #include <QSettings>
#include <QFileInfo> #include <QFileInfo>
#include <QPalette> #include <QPalette>
#include <QColor> #include <QColor>
#include <QBrush> #include <QBrush>
#include <QTimer> #include <QTimer>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QMenu> #include <QMenu>
#include <QUrl> #include <QUrl>
SavegameWidget::SavegameWidget(QWidget *parent) : SavegameWidget::SavegameWidget(QWidget *parent) :
ProfileWidget(parent), ProfileWidget(parent),
ui(new Ui::SavegameWidget) ui(new Ui::SavegameWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->cmdCopy->setVisible(false); ui->cmdCopy->setVisible(false);
ui->cmdView->setVisible(false); ui->cmdView->setVisible(false);
ui->cmdDelete->setVisible(false); ui->cmdDelete->setVisible(false);
ui->cbSelected->setVisible(false); ui->cbSelected->setVisible(false);
qreal screenRatio = AppEnv::screenRatio(); qreal screenRatio = AppEnv::screenRatio();
ui->labSavegamePic->setFixedSize(48 * screenRatio, 27 * screenRatio); ui->labSavegamePic->setFixedSize(48 * screenRatio, 27 * screenRatio);
QPixmap savegamePixmap(":/img/savegame.png"); QPixmap savegamePixmap(":/img/savegame.png");
if (screenRatio != 1) savegamePixmap = savegamePixmap.scaledToHeight(ui->labSavegamePic->height(), Qt::SmoothTransformation); if (screenRatio != 1) savegamePixmap = savegamePixmap.scaledToHeight(ui->labSavegamePic->height(), Qt::SmoothTransformation);
ui->labSavegamePic->setPixmap(savegamePixmap); ui->labSavegamePic->setPixmap(savegamePixmap);
QString exportSavegameStr = tr("Export Savegame..."); QString exportSavegameStr = tr("Export Savegame...");
Q_UNUSED(exportSavegameStr) Q_UNUSED(exportSavegameStr)
QPalette palette; labelAutosaveStr = tr("AUTOSAVE - %1\n%2");
highlightBackColor = palette.highlight().color(); labelSaveStr = tr("SAVE %3 - %1\n%2");
highlightTextColor = palette.highlightedText().color();
ui->SavegameFrame->setMouseTracking(true);
labelAutosaveStr = tr("AUTOSAVE - %1\n%2"); ui->labSavegamePic->setMouseTracking(true);
labelSaveStr = tr("SAVE %3 - %1\n%2"); ui->labSavegameStr->setMouseTracking(true);
snwgt = parent; ui->cbSelected->setMouseTracking(true);
sgdPath = ""; sgdata = nullptr;
sgdStr = ""; }
sgdata = 0;
SavegameWidget::~SavegameWidget()
installEventFilter(this); {
} delete ui;
}
SavegameWidget::~SavegameWidget()
{ void SavegameWidget::setSavegameData(SavegameData *savegame, QString savegamePath)
delete ui; {
} // BETA CODE
QString savegameString = savegame->getSavegameStr();
bool SavegameWidget::eventFilter(QObject *obj, QEvent *ev) QString fileName = QFileInfo(savegame->getSavegameFileName()).fileName();
{ renderString(savegameString, fileName);
if (obj == this) sgdStr = savegameString;
{ sgdPath = savegamePath;
if (ev->type() == QEvent::Enter) sgdata = savegame;
{ }
setStyleSheet(QString("QFrame#SavegameFrame{background-color: rgb(%1, %2, %3)}QLabel#labSavegameStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
return true; void SavegameWidget::renderString(const QString &savegameString, const QString &fileName)
} {
else if(ev->type() == QEvent::Leave) bool validNumber;
{ QString savegameName = tr("WRONG FORMAT");
setStyleSheet(""); QString savegameDate = tr("WRONG FORMAT");
return true; QStringList savegameNDL = QString(savegameString).split(" - ");
} if (savegameNDL.length() >= 2)
} {
return false; savegameDate = savegameNDL.at(savegameNDL.length() - 1);
} savegameName = QString(savegameString).remove(savegameString.length() - savegameDate.length() - 3, savegameDate.length() + 3);
}
void SavegameWidget::setSavegameData(SavegameData *savegame, QString savegamePath) int savegameNumber = QString(fileName).remove(0,5).toInt(&validNumber) + 1;
{ if (validNumber)
// BETA CODE {
bool validNumber; if (savegameNumber == 16)
QString savegameName = tr("WRONG FORMAT"); {
QString savegameDate = tr("WRONG FORMAT"); ui->labSavegameStr->setText(labelAutosaveStr.arg(savegameDate, savegameName));
QString savegameString = savegame->getSavegameStr(); }
QString fileName = QFileInfo(savegame->getSavegameFileName()).fileName(); else
QStringList savegameNDL = QString(savegameString).split(" - "); {
if (savegameNDL.length() >= 2) ui->labSavegameStr->setText(labelSaveStr.arg(savegameDate, savegameName, QString::number(savegameNumber)));
{ }
savegameDate = savegameNDL.at(savegameNDL.length() - 1); }
savegameName = QString(savegameString).remove(savegameString.length() - savegameDate.length() - 3, savegameDate.length() + 3); else
} {
int savegameNumber = QString(fileName).remove(0,5).toInt(&validNumber) + 1; ui->labSavegameStr->setText(labelSaveStr.arg(savegameDate, savegameName, tr("UNKNOWN")));
if (validNumber) }
{ }
if (savegameNumber == 16)
{ void SavegameWidget::retranslate()
ui->labSavegameStr->setText(labelAutosaveStr.arg(savegameDate, savegameName)); {
} labelAutosaveStr = tr("AUTOSAVE - %1\n%2");
else labelSaveStr = tr("SAVE %3 - %1\n%2");
{
ui->labSavegameStr->setText(labelSaveStr.arg(savegameDate, savegameName, QString::number(savegameNumber))); QString fileName = QFileInfo(sgdata->getSavegameFileName()).fileName();
} renderString(sgdStr, fileName);
} }
else
{ void SavegameWidget::on_cmdCopy_clicked()
ui->labSavegameStr->setText(labelSaveStr.arg(savegameDate, savegameName, tr("UNKNOWN"))); {
} SavegameCopy::copySavegame(this, sgdPath);
sgdStr = savegameString; }
sgdPath = savegamePath;
sgdata = savegame; void SavegameWidget::on_cmdDelete_clicked()
} {
int uchoice = QMessageBox::question(this, tr("Delete savegame"), tr("Are you sure to delete %1 from your savegames?").arg("\""+sgdStr+"\""), QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
void SavegameWidget::on_cmdCopy_clicked() if (uchoice == QMessageBox::Yes)
{ {
SavegameCopy::copySavegame(this, sgdPath); if (!QFile::exists(sgdPath))
} {
emit savegameDeleted();
void SavegameWidget::on_cmdDelete_clicked() }
{ else if(QFile::remove(sgdPath))
int uchoice = QMessageBox::question(this, tr("Delete savegame"), tr("Are you sure to delete %1 from your savegames?").arg("\""+sgdStr+"\""), QMessageBox::No | QMessageBox::Yes, QMessageBox::No); {
if (uchoice == QMessageBox::Yes) emit savegameDeleted();
{ }
if (!QFile::exists(sgdPath)) else
{ {
emit savegameDeleted(); QMessageBox::warning(this, tr("Delete savegame"), tr("Failed at deleting %1 from your savegames").arg("\""+sgdStr+"\""));
} }
else if(QFile::remove(sgdPath)) }
{ }
emit savegameDeleted();
} void SavegameWidget::on_cmdView_clicked()
else {
{ SavegameDialog *savegameDialog = new SavegameDialog(this);
QMessageBox::warning(this, tr("Delete savegame"), tr("Failed at deleting %1 from your savegames").arg("\""+sgdStr+"\"")); savegameDialog->setSavegameData(sgdata, sgdPath, true);
} savegameDialog->setModal(true);
} #ifdef Q_OS_ANDROID
} // Android ...
savegameDialog->showMaximized();
void SavegameWidget::on_cmdView_clicked() #else
{ savegameDialog->show();
SavegameDialog *savegameDialog = new SavegameDialog(this); #endif
savegameDialog->setSavegameData(sgdata, sgdPath, true); savegameDialog->exec();
savegameDialog->setModal(true); delete savegameDialog;
#ifdef Q_OS_ANDROID }
// Android ...
savegameDialog->showMaximized(); void SavegameWidget::mousePressEvent(QMouseEvent *ev)
#else {
savegameDialog->show(); ProfileWidget::mousePressEvent(ev);
#endif }
savegameDialog->exec();
delete savegameDialog; void SavegameWidget::mouseReleaseEvent(QMouseEvent *ev)
} {
ProfileWidget::mouseReleaseEvent(ev);
void SavegameWidget::mousePressEvent(QMouseEvent *ev) if (ui->cbSelected->isVisible())
{ {
ProfileWidget::mousePressEvent(ev); if (rect().contains(ev->pos()) && ev->button() == Qt::LeftButton)
} {
ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
void SavegameWidget::mouseReleaseEvent(QMouseEvent *ev) }
{ }
ProfileWidget::mouseReleaseEvent(ev); else
if (ui->cbSelected->isVisible()) {
{ if (getContentMode() == 0 && rect().contains(ev->pos()) && ev->button() == Qt::LeftButton)
if (rect().contains(ev->pos()) && ev->button() == Qt::LeftButton) {
{ if (ev->modifiers().testFlag(Qt::ShiftModifier))
ui->cbSelected->setChecked(!ui->cbSelected->isChecked()); {
} ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
} }
else else
{ {
if (getContentMode() == 0 && rect().contains(ev->pos()) && ev->button() == Qt::LeftButton) on_cmdView_clicked();
{ }
on_cmdView_clicked(); }
} else if (!ui->cbSelected->isVisible() && getContentMode() == 1 && ev->button() == Qt::LeftButton && ev->modifiers().testFlag(Qt::ShiftModifier))
} {
} ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
}
void SavegameWidget::mouseDoubleClickEvent(QMouseEvent *ev) }
{ }
ProfileWidget::mouseDoubleClickEvent(ev);
void SavegameWidget::mouseDoubleClickEvent(QMouseEvent *ev)
if (!ui->cbSelected->isVisible() && getContentMode() == 1 && ev->button() == Qt::LeftButton) {
{ ProfileWidget::mouseDoubleClickEvent(ev);
on_cmdView_clicked();
} if (!ui->cbSelected->isVisible() && getContentMode() == 1 && ev->button() == Qt::LeftButton)
} {
on_cmdView_clicked();
void SavegameWidget::setSelected(bool isSelected) }
{ }
ui->cbSelected->setChecked(isSelected);
} void SavegameWidget::setSelected(bool isSelected)
{
void SavegameWidget::savegameSelected() ui->cbSelected->setChecked(isSelected);
{ }
setSelected(!ui->cbSelected->isChecked());
} void SavegameWidget::savegameSelected()
{
void SavegameWidget::contextMenuEvent(QContextMenuEvent *ev) setSelected(!ui->cbSelected->isChecked());
{ }
emit contextMenuTriggered(ev);
} void SavegameWidget::contextMenuEvent(QContextMenuEvent *ev)
{
void SavegameWidget::on_cbSelected_stateChanged(int arg1) emit contextMenuTriggered(ev);
{ }
if (arg1 == Qt::Checked)
{ void SavegameWidget::on_cbSelected_stateChanged(int arg1)
emit widgetSelected(); {
} if (arg1 == Qt::Checked)
else if (arg1 == Qt::Unchecked) {
{ emit widgetSelected();
emit widgetDeselected(); }
} else if (arg1 == Qt::Unchecked)
} {
emit widgetDeselected();
bool SavegameWidget::isSelected() }
{ }
return ui->cbSelected->isChecked();
} bool SavegameWidget::isSelected()
{
void SavegameWidget::setSelectionMode(bool selectionMode) return ui->cbSelected->isChecked();
{ }
ui->cbSelected->setVisible(selectionMode);
} void SavegameWidget::setSelectionMode(bool selectionMode)
{
void SavegameWidget::selectAllWidgets() ui->cbSelected->setVisible(selectionMode);
{ }
emit allWidgetsSelected();
} void SavegameWidget::selectAllWidgets()
{
void SavegameWidget::deselectAllWidgets() emit allWidgetsSelected();
{ }
emit allWidgetsDeselected();
} void SavegameWidget::deselectAllWidgets()
{
SavegameData* SavegameWidget::getSavegame() emit allWidgetsDeselected();
{ }
return sgdata;
} SavegameData* SavegameWidget::getSavegame()
{
QString SavegameWidget::getWidgetType() return sgdata;
{ }
return "SavegameWidget";
} QString SavegameWidget::getWidgetType()
{
return "SavegameWidget";
}

View File

@ -1,82 +1,80 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef SAVEGAMEWIDGET_H #ifndef SAVEGAMEWIDGET_H
#define SAVEGAMEWIDGET_H #define SAVEGAMEWIDGET_H
#include "ProfileWidget.h" #include "ProfileWidget.h"
#include "SavegameData.h" #include "SavegameData.h"
#include <QContextMenuEvent> #include <QContextMenuEvent>
#include <QMouseEvent> #include <QMouseEvent>
#include <QWidget> #include <QWidget>
#include <QColor> #include <QColor>
namespace Ui { namespace Ui {
class SavegameWidget; class SavegameWidget;
} }
class SavegameWidget : public ProfileWidget class SavegameWidget : public ProfileWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
SavegameWidget(QWidget *parent = 0); SavegameWidget(QWidget *parent = 0);
void setSavegameData(SavegameData *savegame, QString savegamePath); void setSavegameData(SavegameData *savegame, QString savegamePath);
void setSelectionMode(bool selectionMode); void setSelectionMode(bool selectionMode);
void setSelected(bool isSelected); void setSelected(bool isSelected);
SavegameData* getSavegame(); SavegameData* getSavegame();
QString getWidgetType(); QString getWidgetType();
bool isSelected(); bool isSelected();
~SavegameWidget(); void retranslate();
~SavegameWidget();
private slots:
void on_cmdView_clicked(); private slots:
void on_cmdCopy_clicked(); void on_cmdView_clicked();
void on_cmdDelete_clicked(); void on_cmdCopy_clicked();
void on_cbSelected_stateChanged(int arg1); void on_cmdDelete_clicked();
void savegameSelected(); void on_cbSelected_stateChanged(int arg1);
void selectAllWidgets(); void savegameSelected();
void deselectAllWidgets(); void selectAllWidgets();
void deselectAllWidgets();
protected:
bool eventFilter(QObject *obj, QEvent *ev); protected:
void mouseDoubleClickEvent(QMouseEvent *ev); void mouseDoubleClickEvent(QMouseEvent *ev);
void mouseReleaseEvent(QMouseEvent *ev); void mouseReleaseEvent(QMouseEvent *ev);
void mousePressEvent(QMouseEvent *ev); void mousePressEvent(QMouseEvent *ev);
void contextMenuEvent(QContextMenuEvent *ev); void contextMenuEvent(QContextMenuEvent *ev);
private: private:
Ui::SavegameWidget *ui; Ui::SavegameWidget *ui;
SavegameData *sgdata; SavegameData *sgdata;
QColor highlightBackColor; QString labelAutosaveStr;
QColor highlightTextColor; QString labelSaveStr;
QString labelAutosaveStr; QString sgdPath;
QString labelSaveStr; QString sgdStr;
QString sgdPath; void renderString(const QString &savegameString, const QString &fileName);
QString sgdStr;
QWidget *snwgt; signals:
void savegameDeleted();
signals: void widgetSelected();
void savegameDeleted(); void widgetDeselected();
void widgetSelected(); void allWidgetsSelected();
void widgetDeselected(); void allWidgetsDeselected();
void allWidgetsSelected(); void contextMenuTriggered(QContextMenuEvent *ev);
void allWidgetsDeselected(); };
void contextMenuTriggered(QContextMenuEvent *ev);
}; #endif // SAVEGAMEWIDGET_H
#endif // SAVEGAMEWIDGET_H

View File

@ -1,135 +1,135 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>SavegameWidget</class> <class>SavegameWidget</class>
<widget class="QWidget" name="SavegameWidget"> <widget class="QWidget" name="SavegameWidget">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>405</width> <width>405</width>
<height>46</height> <height>46</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Savegame Widget</string> <string>Savegame Widget</string>
</property> </property>
<layout class="QHBoxLayout" name="hlSavegameContent"> <layout class="QHBoxLayout" name="hlSavegameContent">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QFrame" name="SavegameFrame"> <widget class="QFrame" name="SavegameFrame">
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Plain</enum> <enum>QFrame::Plain</enum>
</property> </property>
<property name="lineWidth"> <property name="lineWidth">
<number>0</number> <number>0</number>
</property> </property>
<layout class="QHBoxLayout" name="hlSavegame"> <layout class="QHBoxLayout" name="hlSavegame">
<item> <item>
<widget class="QCheckBox" name="cbSelected"> <widget class="QCheckBox" name="cbSelected">
<property name="focusPolicy"> <property name="focusPolicy">
<enum>Qt::NoFocus</enum> <enum>Qt::NoFocus</enum>
</property> </property>
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="labSavegamePic"> <widget class="QLabel" name="labSavegamePic">
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="labSavegameStr"> <widget class="QLabel" name="labSavegameStr">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"> <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>SAVE %3 - %1&lt;br&gt;%2</string> <string>SAVE %3 - %1&lt;br&gt;%2</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="cmdView"> <widget class="QPushButton" name="cmdView">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>View savegame</string> <string>View savegame</string>
</property> </property>
<property name="text"> <property name="text">
<string>View</string> <string>View</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="cmdCopy"> <widget class="QPushButton" name="cmdCopy">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Copy savegame</string> <string>Copy savegame</string>
</property> </property>
<property name="text"> <property name="text">
<string>Export</string> <string>Export</string>
</property> </property>
<property name="autoDefault"> <property name="autoDefault">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="cmdDelete"> <widget class="QPushButton" name="cmdDelete">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Delete savegame</string> <string>Delete savegame</string>
</property> </property>
<property name="text"> <property name="text">
<string>Delete</string> <string>Delete</string>
</property> </property>
<property name="autoDefault"> <property name="autoDefault">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -1,61 +1,61 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "SidebarGenerator.h" #include "SidebarGenerator.h"
#include "StandardPaths.h" #include "StandardPaths.h"
#include "AppEnv.h" #include "AppEnv.h"
#include <QList> #include <QList>
#include <QUrl> #include <QUrl>
#include <QDir> #include <QDir>
SidebarGenerator::SidebarGenerator() SidebarGenerator::SidebarGenerator()
{ {
} }
QList<QUrl> SidebarGenerator::generateSidebarUrls(QList<QUrl> sidebarUrls) QList<QUrl> SidebarGenerator::generateSidebarUrls(QList<QUrl> sidebarUrls)
{ {
QDir dir; QDir dir;
dir.setPath(StandardPaths::picturesLocation()); dir.setPath(StandardPaths::picturesLocation());
if (dir.exists()) if (dir.exists())
{ {
sidebarUrls << QUrl::fromLocalFile(dir.absolutePath()); sidebarUrls += QUrl::fromLocalFile(dir.absolutePath());
} }
dir.setPath(StandardPaths::documentsLocation()); dir.setPath(StandardPaths::documentsLocation());
if (dir.exists()) if (dir.exists())
{ {
sidebarUrls << QUrl::fromLocalFile(dir.absolutePath()); sidebarUrls += QUrl::fromLocalFile(dir.absolutePath());
} }
bool gameFolderExists; bool gameFolderExists;
QString gameFolder = AppEnv::getGameFolder(&gameFolderExists); QString gameFolder = AppEnv::getGameFolder(&gameFolderExists);
if (gameFolderExists) if (gameFolderExists)
{ {
sidebarUrls << QUrl::fromLocalFile(gameFolder); sidebarUrls += QUrl::fromLocalFile(gameFolder);
} }
dir.setPath(StandardPaths::desktopLocation()); dir.setPath(StandardPaths::desktopLocation());
if (dir.exists()) if (dir.exists())
{ {
sidebarUrls << QUrl::fromLocalFile(dir.absolutePath()); sidebarUrls += QUrl::fromLocalFile(dir.absolutePath());
} }
return sidebarUrls; return sidebarUrls;
} }

View File

@ -1,32 +1,32 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef SIDEBARGENERATOR_H #ifndef SIDEBARGENERATOR_H
#define SIDEBARGENERATOR_H #define SIDEBARGENERATOR_H
#include <QList> #include <QList>
#include <QUrl> #include <QUrl>
class SidebarGenerator class SidebarGenerator
{ {
public: public:
SidebarGenerator(); SidebarGenerator();
static QList<QUrl> generateSidebarUrls(QList<QUrl> sidebarUrls); static QList<QUrl> generateSidebarUrls(QList<QUrl> sidebarUrls);
}; };
#endif // SIDEBARGENERATOR_H #endif // SIDEBARGENERATOR_H

View File

@ -1,340 +1,340 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "SnapmaticEditor.h" #include "SnapmaticEditor.h"
#include "ui_SnapmaticEditor.h" #include "ui_SnapmaticEditor.h"
#include "SnapmaticPicture.h" #include "SnapmaticPicture.h"
#include "StringParser.h" #include "StringParser.h"
#include "AppEnv.h" #include "AppEnv.h"
#include <QStringBuilder> #include <QStringBuilder>
#include <QTextDocument> #include <QTextDocument>
#include <QInputDialog> #include <QInputDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
SnapmaticEditor::SnapmaticEditor(CrewDatabase *crewDB, QWidget *parent) : SnapmaticEditor::SnapmaticEditor(CrewDatabase *crewDB, QWidget *parent) :
QDialog(parent), crewDB(crewDB), QDialog(parent), crewDB(crewDB),
ui(new Ui::SnapmaticEditor) ui(new Ui::SnapmaticEditor)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->cmdApply->setDefault(true); ui->cmdApply->setDefault(true);
if (QIcon::hasThemeIcon("dialog-apply")) if (QIcon::hasThemeIcon("dialog-apply"))
{ {
ui->cmdApply->setIcon(QIcon::fromTheme("dialog-apply")); ui->cmdApply->setIcon(QIcon::fromTheme("dialog-apply"));
} }
if (QIcon::hasThemeIcon("dialog-cancel")) if (QIcon::hasThemeIcon("dialog-cancel"))
{ {
ui->cmdCancel->setIcon(QIcon::fromTheme("dialog-cancel")); ui->cmdCancel->setIcon(QIcon::fromTheme("dialog-cancel"));
} }
snapmaticTitle = ""; snapmaticTitle = "";
smpic = 0; smpic = 0;
// DPI calculation // DPI calculation
qreal screenRatio = AppEnv::screenRatio(); qreal screenRatio = AppEnv::screenRatio();
resize(400 * screenRatio, 360 * screenRatio); resize(400 * screenRatio, 360 * screenRatio);
} }
SnapmaticEditor::~SnapmaticEditor() SnapmaticEditor::~SnapmaticEditor()
{ {
delete ui; delete ui;
} }
void SnapmaticEditor::selfie_toggled(bool checked) void SnapmaticEditor::selfie_toggled(bool checked)
{ {
if (checked) if (checked)
{ {
isSelfie = true; isSelfie = true;
} }
else else
{ {
isSelfie = false; isSelfie = false;
} }
} }
void SnapmaticEditor::mugshot_toggled(bool checked) void SnapmaticEditor::mugshot_toggled(bool checked)
{ {
if (checked) if (checked)
{ {
isMugshot = true; isMugshot = true;
ui->cbDirector->setEnabled(false); ui->cbDirector->setEnabled(false);
ui->cbDirector->setChecked(false); ui->cbDirector->setChecked(false);
} }
else else
{ {
isMugshot = false; isMugshot = false;
ui->cbDirector->setEnabled(true); ui->cbDirector->setEnabled(true);
} }
} }
void SnapmaticEditor::editor_toggled(bool checked) void SnapmaticEditor::editor_toggled(bool checked)
{ {
if (checked) if (checked)
{ {
isEditor = true; isEditor = true;
ui->cbDirector->setEnabled(false); ui->cbDirector->setEnabled(false);
ui->cbDirector->setChecked(false); ui->cbDirector->setChecked(false);
} }
else else
{ {
isEditor = false; isEditor = false;
ui->cbDirector->setEnabled(true); ui->cbDirector->setEnabled(true);
} }
} }
void SnapmaticEditor::on_rbSelfie_toggled(bool checked) void SnapmaticEditor::on_rbSelfie_toggled(bool checked)
{ {
if (checked) if (checked)
{ {
mugshot_toggled(false); mugshot_toggled(false);
editor_toggled(false); editor_toggled(false);
selfie_toggled(true); selfie_toggled(true);
} }
} }
void SnapmaticEditor::on_rbMugshot_toggled(bool checked) void SnapmaticEditor::on_rbMugshot_toggled(bool checked)
{ {
if (checked) if (checked)
{ {
selfie_toggled(false); selfie_toggled(false);
editor_toggled(false); editor_toggled(false);
mugshot_toggled(true); mugshot_toggled(true);
} }
} }
void SnapmaticEditor::on_rbEditor_toggled(bool checked) void SnapmaticEditor::on_rbEditor_toggled(bool checked)
{ {
if (checked) if (checked)
{ {
selfie_toggled(false); selfie_toggled(false);
mugshot_toggled(false); mugshot_toggled(false);
editor_toggled(true); editor_toggled(true);
} }
} }
void SnapmaticEditor::on_rbCustom_toggled(bool checked) void SnapmaticEditor::on_rbCustom_toggled(bool checked)
{ {
if (checked) if (checked)
{ {
selfie_toggled(false); selfie_toggled(false);
mugshot_toggled(false); mugshot_toggled(false);
editor_toggled(false); editor_toggled(false);
} }
} }
void SnapmaticEditor::setSnapmaticPicture(SnapmaticPicture *picture) void SnapmaticEditor::setSnapmaticPicture(SnapmaticPicture *picture)
{ {
smpic = picture; smpic = picture;
localSpJson = smpic->getSnapmaticProperties(); localSpJson = smpic->getSnapmaticProperties();
ui->rbCustom->setChecked(true); ui->rbCustom->setChecked(true);
crewID = localSpJson.crewID; crewID = localSpJson.crewID;
isSelfie = localSpJson.isSelfie; isSelfie = localSpJson.isSelfie;
isMugshot = localSpJson.isMug; isMugshot = localSpJson.isMug;
isEditor = localSpJson.isFromRSEditor; isEditor = localSpJson.isFromRSEditor;
ui->cbDirector->setChecked(localSpJson.isFromDirector); ui->cbDirector->setChecked(localSpJson.isFromDirector);
ui->cbMeme->setChecked(localSpJson.isMeme); ui->cbMeme->setChecked(localSpJson.isMeme);
if (isSelfie) if (isSelfie)
{ {
ui->rbSelfie->setChecked(true); ui->rbSelfie->setChecked(true);
} }
else if (isMugshot) else if (isMugshot)
{ {
ui->rbMugshot->setChecked(true); ui->rbMugshot->setChecked(true);
} }
else if (isEditor) else if (isEditor)
{ {
ui->rbEditor->setChecked(true); ui->rbEditor->setChecked(true);
} }
else else
{ {
ui->rbCustom->setChecked(true); ui->rbCustom->setChecked(true);
} }
setSnapmaticCrew(returnCrewName(crewID)); setSnapmaticCrew(returnCrewName(crewID));
setSnapmaticTitle(picture->getPictureTitle()); setSnapmaticTitle(picture->getPictureTitle());
} }
void SnapmaticEditor::setSnapmaticTitle(const QString &title) void SnapmaticEditor::setSnapmaticTitle(const QString &title)
{ {
if (title.length() > 39) if (title.length() > 39)
{ {
snapmaticTitle = title.left(39); snapmaticTitle = title.left(39);
} }
else else
{ {
snapmaticTitle = title; snapmaticTitle = title;
} }
QString editStr = QString("<a href=\"g5e://edittitle\" style=\"text-decoration: none;\">%1</a>").arg(tr("Edit")); QString editStr = QString("<a href=\"g5e://edittitle\" style=\"text-decoration: none;\">%1</a>").arg(tr("Edit"));
QString titleStr = tr("Title: %1 (%2)").arg(StringParser::escapeString(snapmaticTitle), editStr); QString titleStr = tr("Title: %1 (%2)").arg(StringParser::escapeString(snapmaticTitle), editStr);
ui->labTitle->setText(titleStr); ui->labTitle->setText(titleStr);
if (SnapmaticPicture::verifyTitle(snapmaticTitle)) if (SnapmaticPicture::verifyTitle(snapmaticTitle))
{ {
ui->labAppropriate->setText(tr("Appropriate: %1").arg(QString("<span style=\"color: green\">%1</a>").arg(tr("Yes", "Yes, should work fine")))); ui->labAppropriate->setText(tr("Appropriate: %1").arg(QString("<span style=\"color: green\">%1</a>").arg(tr("Yes", "Yes, should work fine"))));
} }
else else
{ {
ui->labAppropriate->setText(tr("Appropriate: %1").arg(QString("<span style=\"color: red\">%1</a>").arg(tr("No", "No, could lead to issues")))); ui->labAppropriate->setText(tr("Appropriate: %1").arg(QString("<span style=\"color: red\">%1</a>").arg(tr("No", "No, could lead to issues"))));
} }
} }
void SnapmaticEditor::setSnapmaticCrew(const QString &crew) void SnapmaticEditor::setSnapmaticCrew(const QString &crew)
{ {
QString editStr = QString("<a href=\"g5e://editcrew\" style=\"text-decoration: none;\">%1</a>").arg(tr("Edit")); QString editStr = QString("<a href=\"g5e://editcrew\" style=\"text-decoration: none;\">%1</a>").arg(tr("Edit"));
QString crewStr = tr("Crew: %1 (%2)").arg(StringParser::escapeString(crew), editStr); QString crewStr = tr("Crew: %1 (%2)").arg(StringParser::escapeString(crew), editStr);
ui->labCrew->setText(crewStr); ui->labCrew->setText(crewStr);
} }
QString SnapmaticEditor::returnCrewName(int crewID_) QString SnapmaticEditor::returnCrewName(int crewID_)
{ {
return crewDB->getCrewName(crewID_); return crewDB->getCrewName(crewID_);
} }
void SnapmaticEditor::on_cmdCancel_clicked() void SnapmaticEditor::on_cmdCancel_clicked()
{ {
close(); close();
} }
void SnapmaticEditor::on_cmdApply_clicked() void SnapmaticEditor::on_cmdApply_clicked()
{ {
if (ui->cbQualify->isChecked()) if (ui->cbQualify->isChecked())
{ {
qualifyAvatar(); qualifyAvatar();
} }
localSpJson.crewID = crewID; localSpJson.crewID = crewID;
localSpJson.isSelfie = isSelfie; localSpJson.isSelfie = isSelfie;
localSpJson.isMug = isMugshot; localSpJson.isMug = isMugshot;
localSpJson.isFromRSEditor = isEditor; localSpJson.isFromRSEditor = isEditor;
localSpJson.isFromDirector = ui->cbDirector->isChecked(); localSpJson.isFromDirector = ui->cbDirector->isChecked();
localSpJson.isMeme = ui->cbMeme->isChecked(); localSpJson.isMeme = ui->cbMeme->isChecked();
if (smpic) if (smpic)
{ {
QString originalFileName = smpic->getPictureFilePath(); QString originalFileName = smpic->getPictureFilePath();
QString adjustedFileName = originalFileName; QString adjustedFileName = originalFileName;
if (adjustedFileName.right(7) == ".hidden") // for the hidden file system if (adjustedFileName.right(7) == ".hidden") // for the hidden file system
{ {
adjustedFileName.remove(adjustedFileName.length() - 7, 7); adjustedFileName.remove(adjustedFileName.length() - 7, 7);
} }
QString backupFileName = adjustedFileName % ".bak"; QString backupFileName = adjustedFileName % ".bak";
if (!QFile::exists(backupFileName)) if (!QFile::exists(backupFileName))
{ {
QFile::copy(adjustedFileName, backupFileName); QFile::copy(adjustedFileName, backupFileName);
} }
SnapmaticProperties fallbackProperties = smpic->getSnapmaticProperties(); SnapmaticProperties fallbackProperties = smpic->getSnapmaticProperties();
QString fallbackTitle = smpic->getPictureTitle(); QString fallbackTitle = smpic->getPictureTitle();
smpic->setSnapmaticProperties(localSpJson); smpic->setSnapmaticProperties(localSpJson);
smpic->setPictureTitle(snapmaticTitle); smpic->setPictureTitle(snapmaticTitle);
if (!smpic->exportPicture(originalFileName)) if (!smpic->exportPicture(originalFileName))
{ {
QMessageBox::warning(this, tr("Snapmatic Properties"), tr("Patching of Snapmatic Properties failed because of I/O Error")); QMessageBox::warning(this, tr("Snapmatic Properties"), tr("Patching of Snapmatic Properties failed because of I/O Error"));
smpic->setSnapmaticProperties(fallbackProperties); smpic->setSnapmaticProperties(fallbackProperties);
smpic->setPictureTitle(fallbackTitle); smpic->setPictureTitle(fallbackTitle);
} }
else else
{ {
smpic->emitUpdate(); smpic->emitUpdate();
} }
} }
close(); close();
} }
void SnapmaticEditor::qualifyAvatar() void SnapmaticEditor::qualifyAvatar()
{ {
ui->rbSelfie->setChecked(true); ui->rbSelfie->setChecked(true);
ui->cbDirector->setChecked(false); ui->cbDirector->setChecked(false);
ui->cbMeme->setChecked(false); ui->cbMeme->setChecked(false);
ui->cmdApply->setDefault(true); ui->cmdApply->setDefault(true);
} }
void SnapmaticEditor::on_cbQualify_toggled(bool checked) void SnapmaticEditor::on_cbQualify_toggled(bool checked)
{ {
if (checked) if (checked)
{ {
ui->cbMeme->setEnabled(false); ui->cbMeme->setEnabled(false);
ui->cbDirector->setEnabled(false); ui->cbDirector->setEnabled(false);
ui->rbCustom->setEnabled(false); ui->rbCustom->setEnabled(false);
ui->rbSelfie->setEnabled(false); ui->rbSelfie->setEnabled(false);
ui->rbEditor->setEnabled(false); ui->rbEditor->setEnabled(false);
ui->rbMugshot->setEnabled(false); ui->rbMugshot->setEnabled(false);
} }
else else
{ {
ui->cbMeme->setEnabled(true); ui->cbMeme->setEnabled(true);
ui->rbCustom->setEnabled(true); ui->rbCustom->setEnabled(true);
ui->rbSelfie->setEnabled(true); ui->rbSelfie->setEnabled(true);
ui->rbEditor->setEnabled(true); ui->rbEditor->setEnabled(true);
ui->rbMugshot->setEnabled(true); ui->rbMugshot->setEnabled(true);
if (ui->rbSelfie->isChecked() || ui->rbCustom->isChecked()) if (ui->rbSelfie->isChecked() || ui->rbCustom->isChecked())
{ {
ui->cbDirector->setEnabled(true); ui->cbDirector->setEnabled(true);
} }
} }
} }
void SnapmaticEditor::on_labTitle_linkActivated(const QString &link) void SnapmaticEditor::on_labTitle_linkActivated(const QString &link)
{ {
if (link == "g5e://edittitle") if (link == "g5e://edittitle")
{ {
bool ok; bool ok;
QString newTitle = QInputDialog::getText(this, tr("Snapmatic Title"), tr("New Snapmatic title:"), QLineEdit::Normal, snapmaticTitle, &ok, windowFlags()); QString newTitle = QInputDialog::getText(this, tr("Snapmatic Title"), tr("New Snapmatic title:"), QLineEdit::Normal, snapmaticTitle, &ok, windowFlags());
if (ok && !newTitle.isEmpty()) if (ok && !newTitle.isEmpty())
{ {
setSnapmaticTitle(newTitle); setSnapmaticTitle(newTitle);
} }
} }
} }
void SnapmaticEditor::on_labCrew_linkActivated(const QString &link) void SnapmaticEditor::on_labCrew_linkActivated(const QString &link)
{ {
if (link == "g5e://editcrew") if (link == "g5e://editcrew")
{ {
bool ok; bool ok;
int indexNum = 0; int indexNum = 0;
QStringList itemList; QStringList itemList;
QStringList crewList = crewDB->getCrews(); QStringList crewList = crewDB->getCrews();
if (!crewList.contains(QLatin1String("0"))) if (!crewList.contains(QLatin1String("0")))
{ {
crewList.append(QLatin1String("0")); crewList += QLatin1String("0");
} }
crewList.sort(); crewList.sort();
foreach(const QString &crew, crewList) foreach(const QString &crew, crewList)
{ {
itemList.append(QString("%1 (%2)").arg(crew, returnCrewName(crew.toInt()))); itemList += QString("%1 (%2)").arg(crew, returnCrewName(crew.toInt()));
} }
if (crewList.contains(QString::number(crewID))) if (crewList.contains(QString::number(crewID)))
{ {
indexNum = crewList.indexOf(QRegExp(QString::number(crewID))); indexNum = crewList.indexOf(QRegExp(QString::number(crewID)));
} }
QString newCrew = QInputDialog::getItem(this, tr("Snapmatic Crew"), tr("New Snapmatic crew:"), itemList, indexNum, true, &ok, windowFlags()); QString newCrew = QInputDialog::getItem(this, tr("Snapmatic Crew"), tr("New Snapmatic crew:"), itemList, indexNum, true, &ok, windowFlags());
if (ok && !newCrew.isEmpty()) if (ok && !newCrew.isEmpty())
{ {
if (newCrew.contains(" ")) newCrew = newCrew.split(" ").at(0); if (newCrew.contains(" ")) newCrew = newCrew.split(" ").at(0);
if (newCrew.length() > 10) return; if (newCrew.length() > 10) return;
foreach (const QChar &crewChar, newCrew) foreach (const QChar &crewChar, newCrew)
{ {
if (!crewChar.isNumber()) if (!crewChar.isNumber())
{ {
return; return;
} }
} }
crewID = newCrew.toInt(); crewID = newCrew.toInt();
setSnapmaticCrew(returnCrewName(crewID)); setSnapmaticCrew(returnCrewName(crewID));
} }
} }
} }

View File

@ -1,69 +1,69 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef SNAPMATICEDITOR_H #ifndef SNAPMATICEDITOR_H
#define SNAPMATICEDITOR_H #define SNAPMATICEDITOR_H
#include <QDialog> #include <QDialog>
#include "CrewDatabase.h" #include "CrewDatabase.h"
#include "SnapmaticPicture.h" #include "SnapmaticPicture.h"
namespace Ui { namespace Ui {
class SnapmaticEditor; class SnapmaticEditor;
} }
class SnapmaticEditor : public QDialog class SnapmaticEditor : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SnapmaticEditor(CrewDatabase *crewDB, QWidget *parent = 0); explicit SnapmaticEditor(CrewDatabase *crewDB, QWidget *parent = 0);
void setSnapmaticPicture(SnapmaticPicture *picture); void setSnapmaticPicture(SnapmaticPicture *picture);
void setSnapmaticTitle(const QString &title); void setSnapmaticTitle(const QString &title);
void setSnapmaticCrew(const QString &crew = ""); void setSnapmaticCrew(const QString &crew = "");
QString returnCrewName(int crewID); QString returnCrewName(int crewID);
~SnapmaticEditor(); ~SnapmaticEditor();
private slots: private slots:
void on_rbSelfie_toggled(bool checked); void on_rbSelfie_toggled(bool checked);
void on_rbMugshot_toggled(bool checked); void on_rbMugshot_toggled(bool checked);
void on_rbEditor_toggled(bool checked); void on_rbEditor_toggled(bool checked);
void on_rbCustom_toggled(bool checked); void on_rbCustom_toggled(bool checked);
void on_cmdCancel_clicked(); void on_cmdCancel_clicked();
void on_cmdApply_clicked(); void on_cmdApply_clicked();
void on_cbQualify_toggled(bool checked); void on_cbQualify_toggled(bool checked);
void on_labTitle_linkActivated(const QString &link); void on_labTitle_linkActivated(const QString &link);
void on_labCrew_linkActivated(const QString &link); void on_labCrew_linkActivated(const QString &link);
private: private:
CrewDatabase *crewDB; CrewDatabase *crewDB;
Ui::SnapmaticEditor *ui; Ui::SnapmaticEditor *ui;
SnapmaticProperties localSpJson; SnapmaticProperties localSpJson;
SnapmaticPicture *smpic; SnapmaticPicture *smpic;
QString snapmaticTitle; QString snapmaticTitle;
int crewID; int crewID;
bool isSelfie; bool isSelfie;
bool isMugshot; bool isMugshot;
bool isEditor; bool isEditor;
void selfie_toggled(bool checked); void selfie_toggled(bool checked);
void mugshot_toggled(bool checked); void mugshot_toggled(bool checked);
void editor_toggled(bool checked); void editor_toggled(bool checked);
void qualifyAvatar(); void qualifyAvatar();
}; };
#endif // SNAPMATICEDITOR_H #endif // SNAPMATICEDITOR_H

View File

@ -1,248 +1,248 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>SnapmaticEditor</class> <class>SnapmaticEditor</class>
<widget class="QDialog" name="SnapmaticEditor"> <widget class="QDialog" name="SnapmaticEditor">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>400</width>
<height>362</height> <height>362</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Snapmatic Properties</string> <string>Snapmatic Properties</string>
</property> </property>
<property name="modal"> <property name="modal">
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" name="vlEditor"> <layout class="QVBoxLayout" name="vlEditor">
<item> <item>
<widget class="QWidget" name="frameWidget" native="true"> <widget class="QWidget" name="frameWidget" native="true">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<layout class="QVBoxLayout" name="vlFrame"> <layout class="QVBoxLayout" name="vlFrame">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QGroupBox" name="gbMode"> <widget class="QGroupBox" name="gbMode">
<property name="title"> <property name="title">
<string>Snapmatic Type</string> <string>Snapmatic Type</string>
</property> </property>
<layout class="QGridLayout" name="gdType"> <layout class="QGridLayout" name="gdType">
<item row="2" column="1"> <item row="2" column="1">
<widget class="QRadioButton" name="rbEditor"> <widget class="QRadioButton" name="rbEditor">
<property name="text"> <property name="text">
<string>Editor</string> <string>Editor</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QRadioButton" name="rbSelfie"> <widget class="QRadioButton" name="rbSelfie">
<property name="text"> <property name="text">
<string>Selfie</string> <string>Selfie</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QRadioButton" name="rbCustom"> <widget class="QRadioButton" name="rbCustom">
<property name="text"> <property name="text">
<string>Regular</string> <string>Regular</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QRadioButton" name="rbMugshot"> <widget class="QRadioButton" name="rbMugshot">
<property name="text"> <property name="text">
<string>Mugshot</string> <string>Mugshot</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="gbProperties"> <widget class="QGroupBox" name="gbProperties">
<property name="title"> <property name="title">
<string>Snapmatic Properties</string> <string>Snapmatic Properties</string>
</property> </property>
<layout class="QGridLayout" name="gdProperties"> <layout class="QGridLayout" name="gdProperties">
<item row="0" column="1"> <item row="0" column="1">
<widget class="QCheckBox" name="cbMeme"> <widget class="QCheckBox" name="cbMeme">
<property name="text"> <property name="text">
<string>Meme</string> <string>Meme</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2"> <item row="0" column="2">
<widget class="QCheckBox" name="cbDirector"> <widget class="QCheckBox" name="cbDirector">
<property name="text"> <property name="text">
<string>Director</string> <string>Director</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="gbValues"> <widget class="QGroupBox" name="gbValues">
<property name="title"> <property name="title">
<string>Snapmatic Values</string> <string>Snapmatic Values</string>
</property> </property>
<layout class="QVBoxLayout" name="vlTitle"> <layout class="QVBoxLayout" name="vlTitle">
<item> <item>
<widget class="UiModLabel" name="labCrew"> <widget class="UiModLabel" name="labCrew">
<property name="contextMenuPolicy"> <property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum> <enum>Qt::NoContextMenu</enum>
</property> </property>
<property name="text"> <property name="text">
<string>Crew: %1 (%2)</string> <string>Crew: %1 (%2)</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="UiModLabel" name="labTitle"> <widget class="UiModLabel" name="labTitle">
<property name="contextMenuPolicy"> <property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum> <enum>Qt::NoContextMenu</enum>
</property> </property>
<property name="text"> <property name="text">
<string>Title: %1 (%2)</string> <string>Title: %1 (%2)</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="UiModLabel" name="labAppropriate"> <widget class="UiModLabel" name="labAppropriate">
<property name="text"> <property name="text">
<string>Appropriate: %1</string> <string>Appropriate: %1</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="gbExtras"> <widget class="QGroupBox" name="gbExtras">
<property name="title"> <property name="title">
<string>Extras</string> <string>Extras</string>
</property> </property>
<layout class="QVBoxLayout" name="vlExtras"> <layout class="QVBoxLayout" name="vlExtras">
<item> <item>
<widget class="QCheckBox" name="cbQualify"> <widget class="QCheckBox" name="cbQualify">
<property name="text"> <property name="text">
<string>Qualify as Avatar automatically at apply</string> <string>Qualify as Avatar automatically at apply</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="UiModLabel" name="labQualify"> <widget class="UiModLabel" name="labQualify">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum"> <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Qualify as Avatar allows you to use this Snapmatic as a Social Club profile picture</string> <string>Qualify as Avatar allows you to use this Snapmatic as a Social Club profile picture</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="vsEditor"> <spacer name="vsEditor">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>0</width> <width>0</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="hlButtons"> <layout class="QHBoxLayout" name="hlButtons">
<item> <item>
<spacer name="hsButtons"> <spacer name="hsButtons">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>0</width> <width>0</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="cmdApply"> <widget class="QPushButton" name="cmdApply">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Apply</string> <string>&amp;Apply</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="cmdCancel"> <widget class="QPushButton" name="cmdCancel">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Cancel</string> <string>&amp;Cancel</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>UiModLabel</class> <class>UiModLabel</class>
<extends>QLabel</extends> <extends>QLabel</extends>
<header>UiModLabel.h</header> <header>UiModLabel.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

File diff suppressed because it is too large Load Diff

View File

@ -1,150 +1,158 @@
/***************************************************************************** /*****************************************************************************
* gta5sync-spv Grand Theft Auto Snapmatic Picture Viewer * gta5sync-spv Grand Theft Auto Snapmatic Picture Viewer
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef SNAPMATICPICTURE_H #ifndef SNAPMATICPICTURE_H
#define SNAPMATICPICTURE_H #define SNAPMATICPICTURE_H
#include <QStringList> #include <QStringList>
#include <QDateTime> #include <QDateTime>
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QImage> #include <QImage>
#include <QFile> #include <QFile>
struct SnapmaticProperties { enum class SnapmaticFormat : int { Auto_Format = 0, PGTA_Format = 1, JPEG_Format = 2, G5E_Format = 3 };
struct SnapmaticLocation {
QString area; struct SnapmaticProperties {
double x; struct SnapmaticLocation {
double y; QString area;
double z; double x;
}; double y;
int uid; double z;
int crewID; };
QStringList playersList; int uid;
uint createdTimestamp; int crewID;
QDateTime createdDateTime; QStringList playersList;
bool isMeme; uint createdTimestamp;
bool isMug; QDateTime createdDateTime;
bool isSelfie; bool isMeme;
bool isFromDirector; bool isMug;
bool isFromRSEditor; bool isSelfie;
SnapmaticLocation location; bool isFromDirector;
}; bool isFromRSEditor;
SnapmaticLocation location;
class SnapmaticPicture : public QObject };
{
Q_OBJECT class SnapmaticPicture : public QObject
public: {
explicit SnapmaticPicture(const QString &fileName = "", QObject *parent = 0); Q_OBJECT
~SnapmaticPicture(); public:
void reset(); explicit SnapmaticPicture(const QString &fileName = "", QObject *parent = 0);
bool preloadFile(); ~SnapmaticPicture();
bool readingPictureFromFile(const QString &fileName, bool writeEnabled = true, bool cacheEnabled = false, bool fastLoad = true, bool lowRamMode = false); void reset();
bool readingPicture(bool writeEnabled = true, bool cacheEnabled = false, bool fastLoad = true, bool lowRamMode = false); bool preloadFile();
bool isPicOk(); bool readingPictureFromFile(const QString &fileName, bool writeEnabled = true, bool cacheEnabled = false, bool fastLoad = true, bool lowRamMode = false);
void clearCache(); bool readingPicture(bool writeEnabled = true, bool cacheEnabled = false, bool fastLoad = true, bool lowRamMode = false);
QImage getImage(); bool isPicOk();
QString getLastStep(); void clearCache();
QString getPictureStr(); QImage getImage(bool fastLoad = false);
QString getPictureHead(); QString getLastStep();
QString getPictureTitl(); QString getPictureStr();
QString getPictureDesc(); QString getPictureHead();
QString getPictureSortStr(); QString getPictureTitl();
QString getPictureFileName(); QString getPictureDesc();
QString getPictureFilePath(); QString getPictureSortStr();
QString getExportPictureFileName(); QString getPictureFileName();
int getContentMaxLength(); QString getPictureFilePath();
bool setImage(const QImage &picture); QString getExportPictureFileName();
bool setPictureTitl(const QString &newTitle); int getContentMaxLength();
bool setPictureStream(const QByteArray &picByteArray); bool setImage(const QImage &picture);
void updateStrings(); bool setPictureTitl(const QString &newTitle);
void emitUpdate(); bool setPictureStream(const QByteArray &picByteArray);
void updateStrings();
// FILE MANAGEMENT void emitUpdate();
bool exportPicture(const QString &fileName, const QString format = "PGTA");
void setPicFileName(const QString &picFileName); // FILE MANAGEMENT
void setPicFilePath(const QString &picFilePath); bool exportPicture(const QString &fileName, SnapmaticFormat format = SnapmaticFormat::Auto_Format);
bool deletePicFile(); void setPicFileName(const QString &picFileName);
void setPicFilePath(const QString &picFilePath);
// ALTERNATIVES bool deletePicFile();
QString getPictureTitle() { return getPictureTitl(); }
QString getPictureString() { return getPictureStr(); } // ALTERNATIVES
QString getPictureDescription() { return getPictureDesc(); } QString getPictureTitle() { return getPictureTitl(); }
bool setPictureTitle(const QString &newTitle) { return setPictureTitl(newTitle); } QString getPictureString() { return getPictureStr(); }
QString getPictureDescription() { return getPictureDesc(); }
// JSON bool setPictureTitle(const QString &newTitle) { return setPictureTitl(newTitle); }
bool isJsonOk();
QString getJsonStr(); // JSON
SnapmaticProperties getSnapmaticProperties(); bool isJsonOk();
bool setSnapmaticProperties(SnapmaticProperties newSpJson); QString getJsonStr();
SnapmaticProperties getSnapmaticProperties();
// VISIBILITY bool setSnapmaticProperties(SnapmaticProperties newSpJson);
bool isHidden(); bool setJsonStr(const QString &jsonStr);
bool setPictureHidden();
bool setPictureVisible(); // VISIBILITY
bool isHidden();
// PREDEFINED PROPERTIES bool setPictureHidden();
QSize getSnapmaticResolution(); bool setPictureVisible();
// VERIFY CONTENT // PREDEFINED PROPERTIES
static bool verifyTitle(const QString &title); QSize getSnapmaticResolution();
private: // SNAPMATIC DEFAULTS
QString getSnapmaticHeaderString(const QByteArray &snapmaticHeader); bool isSnapmaticDefaultsEnforced();
QString getSnapmaticJSONString(const QByteArray &jsonBytes); void setSnapmaticDefaultsEnforced(bool enforced);
QString getSnapmaticTIDEString(const QByteArray &tideBytes);
QImage cachePicture; // VERIFY CONTENT
QString picExportFileName; static bool verifyTitle(const QString &title);
QString picFileName;
QString picFilePath; private:
QString pictureHead; QString getSnapmaticHeaderString(const QByteArray &snapmaticHeader);
QString pictureStr; QString getSnapmaticJSONString(const QByteArray &jsonBytes);
QString lastStep; QString getSnapmaticTIDEString(const QByteArray &tideBytes);
QString sortStr; QImage cachePicture;
QString titlStr; QString picExportFileName;
QString descStr; QString picFileName;
bool picOk; QString picFilePath;
bool lowRamMode; QString pictureHead;
bool writeEnabled; QString pictureStr;
bool cacheEnabled; QString lastStep;
bool isLoadedInRAM; QString sortStr;
bool isCustomFormat; QString titlStr;
int jpegRawContentSize; QString descStr;
int jpegRawContentSizeE; bool picOk;
bool lowRamMode;
// PICTURE STREAM bool writeEnabled;
QByteArray rawPicContent; bool cacheEnabled;
bool isLoadedInRAM;
// JSON bool isCustomFormat;
void parseJsonContent(); bool careSnapDefault;
bool jsonOk; int jpegRawContentSize;
QString jsonStr; int jpegRawContentSizeE;
SnapmaticProperties localSpJson;
// PICTURE STREAM
// VERIFY CONTENT QByteArray rawPicContent;
static bool verifyTitleChar(const QChar &titleChar);
// JSON
signals: void parseJsonContent();
void preloaded(); bool jsonOk;
void updated(); QString jsonStr;
void loaded(); SnapmaticProperties localSpJson;
public slots: // VERIFY CONTENT
}; static bool verifyTitleChar(const QChar &titleChar);
#endif // SNAPMATICPICTURE_H signals:
void preloaded();
void updated();
void loaded();
public slots:
};
#endif // SNAPMATICPICTURE_H

View File

@ -1,345 +1,331 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "SnapmaticWidget.h" #include "SnapmaticWidget.h"
#include "ui_SnapmaticWidget.h" #include "ui_SnapmaticWidget.h"
#include "SnapmaticPicture.h" #include "SnapmaticPicture.h"
#include "SnapmaticEditor.h" #include "SnapmaticEditor.h"
#include "DatabaseThread.h" #include "DatabaseThread.h"
#include "PictureDialog.h" #include "PictureDialog.h"
#include "PictureExport.h" #include "PictureExport.h"
#include "StringParser.h" #include "StringParser.h"
#include "AppEnv.h" #include "AppEnv.h"
#include "config.h" #include "config.h"
#include <QMessageBox> #include <QStringBuilder>
#include <QPixmap> #include <QMessageBox>
#include <QTimer> #include <QPixmap>
#include <QDebug> #include <QTimer>
#include <QMenu> #include <QDebug>
#include <QFile> #include <QMenu>
#include <QFile>
SnapmaticWidget::SnapmaticWidget(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent) :
ProfileWidget(parent), profileDB(profileDB), crewDB(crewDB), threadDB(threadDB), SnapmaticWidget::SnapmaticWidget(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent) :
ui(new Ui::SnapmaticWidget) ProfileWidget(parent), profileDB(profileDB), crewDB(crewDB), threadDB(threadDB),
{ ui(new Ui::SnapmaticWidget)
ui->setupUi(this); {
ui->cmdView->setVisible(false); ui->setupUi(this);
ui->cmdCopy->setVisible(false); ui->cmdView->setVisible(false);
ui->cmdExport->setVisible(false); ui->cmdCopy->setVisible(false);
ui->cmdDelete->setVisible(false); ui->cmdExport->setVisible(false);
ui->cbSelected->setVisible(false); ui->cmdDelete->setVisible(false);
ui->cbSelected->setVisible(false);
QPalette palette;
highlightBackColor = palette.highlight().color(); QPalette palette;
highlightTextColor = palette.highlightedText().color(); palette.setCurrentColorGroup(QPalette::Disabled);
palette.setCurrentColorGroup(QPalette::Disabled); highlightHiddenColor = palette.text().color();
highlightHiddenColor = palette.text().color();
ui->SnapmaticFrame->setMouseTracking(true);
picPath = ""; ui->labPicture->setMouseTracking(true);
picStr = ""; ui->labPicStr->setMouseTracking(true);
smpic = 0; ui->cbSelected->setMouseTracking(true);
smpic = nullptr;
installEventFilter(this); }
}
SnapmaticWidget::~SnapmaticWidget()
SnapmaticWidget::~SnapmaticWidget() {
{ delete ui;
delete ui; }
}
void SnapmaticWidget::setSnapmaticPicture(SnapmaticPicture *picture)
bool SnapmaticWidget::eventFilter(QObject *obj, QEvent *ev) {
{ smpic = picture;
if (obj == this) QObject::connect(picture, SIGNAL(updated()), this, SLOT(snapmaticUpdated()));
{
if (ev->type() == QEvent::Enter) qreal screenRatio = AppEnv::screenRatio();
{ ui->labPicture->setFixedSize(48 * screenRatio, 27 * screenRatio);
setStyleSheet(QString("QFrame#SnapmaticFrame{background-color: rgb(%1, %2, %3)}QLabel#labPicStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
return true; QPixmap SnapmaticPixmap = QPixmap::fromImage(picture->getImage().scaled(ui->labPicture->width(), ui->labPicture->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation), Qt::AutoColor);
} ui->labPicStr->setText(smpic->getPictureStr() % "\n" % smpic->getPictureTitl() % "");
else if(ev->type() == QEvent::Leave) ui->labPicture->setPixmap(SnapmaticPixmap);
{
setStyleSheet(""); picture->clearCache();
return true;
} adjustTextColor();
} }
return false;
} void SnapmaticWidget::snapmaticUpdated()
{
void SnapmaticWidget::setSnapmaticPicture(SnapmaticPicture *picture) ui->labPicStr->setText(smpic->getPictureStr() % "\n" % smpic->getPictureTitl() % "");
{ }
smpic = picture;
picPath = picture->getPictureFilePath(); void SnapmaticWidget::retranslate()
picTitl = picture->getPictureTitl(); {
picStr = picture->getPictureStr(); smpic->updateStrings();
QObject::connect(picture, SIGNAL(updated()), this, SLOT(snapmaticUpdated())); ui->labPicStr->setText(smpic->getPictureStr() % "\n" % smpic->getPictureTitl() % "");
}
qreal screenRatio = AppEnv::screenRatio();
ui->labPicture->setFixedSize(48 * screenRatio, 27 * screenRatio); void SnapmaticWidget::on_cmdView_clicked()
{
QPixmap SnapmaticPixmap = QPixmap::fromImage(picture->getImage().scaled(ui->labPicture->width(), ui->labPicture->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation), Qt::AutoColor); QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
ui->labPicStr->setText(picStr + "\n" + picTitl + ""); settings.beginGroup("Interface");
ui->labPicture->setPixmap(SnapmaticPixmap); bool navigationBar = settings.value("NavigationBar", false).toBool();
settings.endGroup();
picture->clearCache();
PictureDialog *picDialog = new PictureDialog(profileDB, crewDB, this);
adjustTextColor(); picDialog->setSnapmaticPicture(smpic, true);
} picDialog->setModal(true);
void SnapmaticWidget::snapmaticUpdated() // be ready for crewName and playerName updated
{ QObject::connect(threadDB, SIGNAL(crewNameUpdated()), picDialog, SLOT(crewNameUpdated()));
// Current only strings get updated QObject::connect(threadDB, SIGNAL(playerNameUpdated()), picDialog, SLOT(playerNameUpdated()));
picPath = smpic->getPictureFilePath(); QObject::connect(picDialog, SIGNAL(nextPictureRequested()), this, SLOT(dialogNextPictureRequested()));
picTitl = smpic->getPictureTitl(); QObject::connect(picDialog, SIGNAL(previousPictureRequested()), this, SLOT(dialogPreviousPictureRequested()));
picStr = smpic->getPictureStr();
ui->labPicStr->setText(picStr + "\n" + picTitl + ""); // add previous next buttons
} if (navigationBar) picDialog->addPreviousNextButtons();
void SnapmaticWidget::on_cmdView_clicked() // show picture dialog
{ #ifdef Q_OS_ANDROID
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); // Android ...
settings.beginGroup("Interface"); picDialog->showMaximized();
bool navigationBar = settings.value("NavigationBar", false).toBool(); #else
settings.endGroup(); picDialog->show();
if (navigationBar) picDialog->stylizeDialog();
PictureDialog *picDialog = new PictureDialog(profileDB, crewDB, this); //picDialog->adaptNewDialogSize();
picDialog->setSnapmaticPicture(smpic, true); picDialog->setMinimumSize(picDialog->size());
picDialog->setModal(true); picDialog->setMaximumSize(picDialog->size());
#endif
// be ready for playerName updated picDialog->exec();
QObject::connect(threadDB, SIGNAL(playerNameUpdated()), picDialog, SLOT(playerNameUpdated())); delete picDialog;
QObject::connect(picDialog, SIGNAL(nextPictureRequested()), this, SLOT(dialogNextPictureRequested())); }
QObject::connect(picDialog, SIGNAL(previousPictureRequested()), this, SLOT(dialogPreviousPictureRequested()));
void SnapmaticWidget::on_cmdCopy_clicked()
// add previous next buttons {
if (navigationBar) picDialog->addPreviousNextButtons(); PictureExport::exportAsSnapmatic(this, smpic);
}
// show picture dialog
#ifdef Q_OS_ANDROID void SnapmaticWidget::on_cmdExport_clicked()
// Android ... {
picDialog->showMaximized(); PictureExport::exportAsPicture(this, smpic);
#else }
picDialog->show();
if (navigationBar) picDialog->stylizeDialog(); void SnapmaticWidget::on_cmdDelete_clicked()
//picDialog->adaptNewDialogSize(); {
picDialog->setMinimumSize(picDialog->size()); if (deletePicture()) emit pictureDeleted();
picDialog->setMaximumSize(picDialog->size()); }
#endif
picDialog->exec(); bool SnapmaticWidget::deletePicture()
delete picDialog; {
} int uchoice = QMessageBox::question(this, tr("Delete picture"), tr("Are you sure to delete %1 from your Snapmatic pictures?").arg("\""+smpic->getPictureStr()+"\""), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (uchoice == QMessageBox::Yes)
void SnapmaticWidget::on_cmdCopy_clicked() {
{ if (smpic->deletePicFile())
PictureExport::exportAsSnapmatic(this, smpic); {
} return true;
}
void SnapmaticWidget::on_cmdExport_clicked() else
{ {
PictureExport::exportAsPicture(this, smpic); QMessageBox::warning(this, tr("Delete picture"), tr("Failed at deleting %1 from your Snapmatic pictures").arg("\""+smpic->getPictureStr()+"\""));
} }
}
void SnapmaticWidget::on_cmdDelete_clicked() return false;
{ }
if (deletePicture()) emit pictureDeleted();
} void SnapmaticWidget::mousePressEvent(QMouseEvent *ev)
{
bool SnapmaticWidget::deletePicture() ProfileWidget::mousePressEvent(ev);
{ }
int uchoice = QMessageBox::question(this, tr("Delete picture"), tr("Are you sure to delete %1 from your Snapmatic pictures?").arg("\""+picStr+"\""), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (uchoice == QMessageBox::Yes) void SnapmaticWidget::mouseReleaseEvent(QMouseEvent *ev)
{ {
if (smpic->deletePicFile()) ProfileWidget::mouseReleaseEvent(ev);
{ if (ui->cbSelected->isVisible())
return true; {
} if (rect().contains(ev->pos()) && ev->button() == Qt::LeftButton)
else {
{ ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
QMessageBox::warning(this, tr("Delete picture"), tr("Failed at deleting %1 from your Snapmatic pictures").arg("\""+picStr+"\"")); }
} }
} else
return false; {
} if (getContentMode() == 0 && rect().contains(ev->pos()) && ev->button() == Qt::LeftButton)
{
void SnapmaticWidget::mousePressEvent(QMouseEvent *ev) if (ev->modifiers().testFlag(Qt::ShiftModifier))
{ {
ProfileWidget::mousePressEvent(ev); ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
} }
else
void SnapmaticWidget::mouseReleaseEvent(QMouseEvent *ev) {
{ on_cmdView_clicked();
ProfileWidget::mouseReleaseEvent(ev); }
if (ui->cbSelected->isVisible()) }
{ else if (!ui->cbSelected->isVisible() && getContentMode() == 1 && ev->button() == Qt::LeftButton && ev->modifiers().testFlag(Qt::ShiftModifier))
if (rect().contains(ev->pos()) && ev->button() == Qt::LeftButton) {
{ ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
ui->cbSelected->setChecked(!ui->cbSelected->isChecked()); }
} }
} }
else
{ void SnapmaticWidget::mouseDoubleClickEvent(QMouseEvent *ev)
if (getContentMode() == 0 && rect().contains(ev->pos()) && ev->button() == Qt::LeftButton) {
{ ProfileWidget::mouseDoubleClickEvent(ev);
on_cmdView_clicked();
} if (!ui->cbSelected->isVisible() && getContentMode() == 1 && ev->button() == Qt::LeftButton)
} {
} on_cmdView_clicked();
}
void SnapmaticWidget::mouseDoubleClickEvent(QMouseEvent *ev) }
{
ProfileWidget::mouseDoubleClickEvent(ev); void SnapmaticWidget::setSelected(bool isSelected)
{
if (!ui->cbSelected->isVisible() && getContentMode() == 1 && ev->button() == Qt::LeftButton) ui->cbSelected->setChecked(isSelected);
{ }
on_cmdView_clicked();
} void SnapmaticWidget::pictureSelected()
} {
setSelected(!ui->cbSelected->isChecked());
void SnapmaticWidget::setSelected(bool isSelected) }
{
ui->cbSelected->setChecked(isSelected); void SnapmaticWidget::contextMenuEvent(QContextMenuEvent *ev)
} {
emit contextMenuTriggered(ev);
void SnapmaticWidget::pictureSelected() }
{
setSelected(!ui->cbSelected->isChecked()); void SnapmaticWidget::dialogNextPictureRequested()
} {
emit nextPictureRequested((QWidget*)sender());
void SnapmaticWidget::contextMenuEvent(QContextMenuEvent *ev) }
{
emit contextMenuTriggered(ev); void SnapmaticWidget::dialogPreviousPictureRequested()
} {
emit previousPictureRequested((QWidget*)sender());
void SnapmaticWidget::dialogNextPictureRequested() }
{
emit nextPictureRequested((QWidget*)sender()); void SnapmaticWidget::on_cbSelected_stateChanged(int arg1)
} {
if (arg1 == Qt::Checked)
void SnapmaticWidget::dialogPreviousPictureRequested() {
{ emit widgetSelected();
emit previousPictureRequested((QWidget*)sender()); }
} else if (arg1 == Qt::Unchecked)
{
void SnapmaticWidget::on_cbSelected_stateChanged(int arg1) emit widgetDeselected();
{ }
if (arg1 == Qt::Checked) }
{
emit widgetSelected(); void SnapmaticWidget::adjustTextColor()
} {
else if (arg1 == Qt::Unchecked) if (isHidden())
{ {
emit widgetDeselected(); ui->labPicStr->setStyleSheet(QString("QLabel{color: rgb(%1, %2, %3);}").arg(QString::number(highlightHiddenColor.red()), QString::number(highlightHiddenColor.green()), QString::number(highlightHiddenColor.blue())));
} }
} else
{
void SnapmaticWidget::adjustTextColor() ui->labPicStr->setStyleSheet("");
{ }
if (isHidden()) }
{
ui->labPicStr->setStyleSheet(QString("QLabel{color: rgb(%1, %2, %3);}").arg(QString::number(highlightHiddenColor.red()), QString::number(highlightHiddenColor.green()), QString::number(highlightHiddenColor.blue()))); bool SnapmaticWidget::makePictureHidden()
} {
else if (smpic->setPictureHidden())
{ {
ui->labPicStr->setStyleSheet(""); adjustTextColor();
} return true;
} }
return false;
bool SnapmaticWidget::makePictureHidden() }
{
if (smpic->setPictureHidden()) bool SnapmaticWidget::makePictureVisible()
{ {
picPath = smpic->getPictureFilePath(); if (smpic->setPictureVisible())
adjustTextColor(); {
return true; adjustTextColor();
} return true;
return false; }
} return false;
}
bool SnapmaticWidget::makePictureVisible()
{ void SnapmaticWidget::makePictureHiddenSlot()
if (smpic->setPictureVisible()) {
{ makePictureHidden();
picPath = smpic->getPictureFilePath(); }
adjustTextColor();
return true; void SnapmaticWidget::makePictureVisibleSlot()
} {
return false; makePictureVisible();
} }
void SnapmaticWidget::makePictureHiddenSlot() void SnapmaticWidget::editSnapmaticProperties()
{ {
makePictureHidden(); SnapmaticEditor *snapmaticEditor = new SnapmaticEditor(crewDB, this);
} snapmaticEditor->setWindowFlags(snapmaticEditor->windowFlags()^Qt::WindowContextHelpButtonHint);
snapmaticEditor->setSnapmaticPicture(smpic);
void SnapmaticWidget::makePictureVisibleSlot() snapmaticEditor->setModal(true);
{ snapmaticEditor->exec();
makePictureVisible(); delete snapmaticEditor;
} }
void SnapmaticWidget::editSnapmaticProperties() bool SnapmaticWidget::isSelected()
{ {
SnapmaticEditor *snapmaticEditor = new SnapmaticEditor(crewDB, this); return ui->cbSelected->isChecked();
snapmaticEditor->setWindowFlags(snapmaticEditor->windowFlags()^Qt::WindowContextHelpButtonHint); }
snapmaticEditor->setSnapmaticPicture(smpic);
snapmaticEditor->setModal(true); bool SnapmaticWidget::isHidden()
snapmaticEditor->exec(); {
delete snapmaticEditor; return smpic->isHidden();
} }
bool SnapmaticWidget::isSelected() void SnapmaticWidget::setSelectionMode(bool selectionMode)
{ {
return ui->cbSelected->isChecked(); ui->cbSelected->setVisible(selectionMode);
} }
bool SnapmaticWidget::isHidden() void SnapmaticWidget::selectAllWidgets()
{ {
if (picPath.right(7) == ".hidden") emit allWidgetsSelected();
{ }
return true;
} void SnapmaticWidget::deselectAllWidgets()
return false; {
} emit allWidgetsDeselected();
}
void SnapmaticWidget::setSelectionMode(bool selectionMode)
{ SnapmaticPicture* SnapmaticWidget::getPicture()
ui->cbSelected->setVisible(selectionMode); {
} return smpic;
}
void SnapmaticWidget::selectAllWidgets()
{ QString SnapmaticWidget::getPicturePath()
emit allWidgetsSelected(); {
} return smpic->getPictureFilePath();
}
void SnapmaticWidget::deselectAllWidgets()
{ QString SnapmaticWidget::getWidgetType()
emit allWidgetsDeselected(); {
} return "SnapmaticWidget";
}
SnapmaticPicture* SnapmaticWidget::getPicture()
{
return smpic;
}
QString SnapmaticWidget::getPicturePath()
{
return picPath;
}
QString SnapmaticWidget::getWidgetType()
{
return "SnapmaticWidget";
}

View File

@ -1,104 +1,98 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef SNAPMATICWIDGET_H #ifndef SNAPMATICWIDGET_H
#define SNAPMATICWIDGET_H #define SNAPMATICWIDGET_H
#include "SnapmaticPicture.h" #include "SnapmaticPicture.h"
#include "ProfileDatabase.h" #include "ProfileDatabase.h"
#include "DatabaseThread.h" #include "DatabaseThread.h"
#include "ProfileWidget.h" #include "ProfileWidget.h"
#include "CrewDatabase.h" #include "CrewDatabase.h"
#include <QContextMenuEvent> #include <QContextMenuEvent>
#include <QMouseEvent> #include <QMouseEvent>
#include <QWidget> #include <QWidget>
#include <QColor> #include <QColor>
namespace Ui { namespace Ui {
class SnapmaticWidget; class SnapmaticWidget;
} }
class SnapmaticWidget : public ProfileWidget class SnapmaticWidget : public ProfileWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
SnapmaticWidget(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0); SnapmaticWidget(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0);
void setSnapmaticPicture(SnapmaticPicture *picture); void setSnapmaticPicture(SnapmaticPicture *picture);
void setSelectionMode(bool selectionMode); void setSelectionMode(bool selectionMode);
void setSelected(bool isSelected); void setSelected(bool isSelected);
bool deletePicture(); bool deletePicture();
bool makePictureVisible(); bool makePictureVisible();
bool makePictureHidden(); bool makePictureHidden();
SnapmaticPicture *getPicture(); SnapmaticPicture *getPicture();
QString getPicturePath(); QString getPicturePath();
QString getWidgetType(); QString getWidgetType();
bool isSelected(); bool isSelected();
bool isHidden(); bool isHidden();
~SnapmaticWidget(); void retranslate();
~SnapmaticWidget();
private slots:
void on_cmdView_clicked(); private slots:
void on_cmdCopy_clicked(); void on_cmdView_clicked();
void on_cmdExport_clicked(); void on_cmdCopy_clicked();
void on_cmdDelete_clicked(); void on_cmdExport_clicked();
void on_cbSelected_stateChanged(int arg1); void on_cmdDelete_clicked();
void adjustTextColor(); void on_cbSelected_stateChanged(int arg1);
void pictureSelected(); void adjustTextColor();
void selectAllWidgets(); void pictureSelected();
void deselectAllWidgets(); void selectAllWidgets();
void dialogNextPictureRequested(); void deselectAllWidgets();
void dialogPreviousPictureRequested(); void dialogNextPictureRequested();
void makePictureVisibleSlot(); void dialogPreviousPictureRequested();
void makePictureHiddenSlot(); void makePictureVisibleSlot();
void editSnapmaticProperties(); void makePictureHiddenSlot();
void snapmaticUpdated(); void editSnapmaticProperties();
void snapmaticUpdated();
protected:
bool eventFilter(QObject *obj, QEvent *ev); protected:
void mouseDoubleClickEvent(QMouseEvent *ev); void mouseDoubleClickEvent(QMouseEvent *ev);
void mouseReleaseEvent(QMouseEvent *ev); void mouseReleaseEvent(QMouseEvent *ev);
void mousePressEvent(QMouseEvent *ev); void mousePressEvent(QMouseEvent *ev);
void contextMenuEvent(QContextMenuEvent *ev); void contextMenuEvent(QContextMenuEvent *ev);
private: private:
ProfileDatabase *profileDB; ProfileDatabase *profileDB;
CrewDatabase *crewDB; CrewDatabase *crewDB;
DatabaseThread *threadDB; DatabaseThread *threadDB;
Ui::SnapmaticWidget *ui; Ui::SnapmaticWidget *ui;
SnapmaticPicture *smpic; SnapmaticPicture *smpic;
QColor highlightBackColor; QColor highlightHiddenColor;
QColor highlightTextColor;
QColor highlightHiddenColor; signals:
QString picPath; void pictureDeleted();
QString picTitl; void widgetSelected();
QString picStr; void widgetDeselected();
QWidget *snwgt; void allWidgetsSelected();
void allWidgetsDeselected();
signals: void nextPictureRequested(QWidget *dialog);
void pictureDeleted(); void previousPictureRequested(QWidget *dialog);
void widgetSelected(); void contextMenuTriggered(QContextMenuEvent *ev);
void widgetDeselected(); };
void allWidgetsSelected();
void allWidgetsDeselected(); #endif // SNAPMATICWIDGET_H
void nextPictureRequested(QWidget *dialog);
void previousPictureRequested(QWidget *dialog);
void contextMenuTriggered(QContextMenuEvent *ev);
};
#endif // SNAPMATICWIDGET_H

View File

@ -1,169 +1,169 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>SnapmaticWidget</class> <class>SnapmaticWidget</class>
<widget class="QWidget" name="SnapmaticWidget"> <widget class="QWidget" name="SnapmaticWidget">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>490</width> <width>490</width>
<height>45</height> <height>45</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Snapmatic Widget</string> <string>Snapmatic Widget</string>
</property> </property>
<layout class="QHBoxLayout" name="hlSnapmaticContent"> <layout class="QHBoxLayout" name="hlSnapmaticContent">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QFrame" name="SnapmaticFrame"> <widget class="QFrame" name="SnapmaticFrame">
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Plain</enum> <enum>QFrame::Plain</enum>
</property> </property>
<property name="lineWidth"> <property name="lineWidth">
<number>0</number> <number>0</number>
</property> </property>
<layout class="QHBoxLayout" name="hlSnapmatic"> <layout class="QHBoxLayout" name="hlSnapmatic">
<item> <item>
<widget class="QCheckBox" name="cbSelected"> <widget class="QCheckBox" name="cbSelected">
<property name="focusPolicy"> <property name="focusPolicy">
<enum>Qt::NoFocus</enum> <enum>Qt::NoFocus</enum>
</property> </property>
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="labPicture"> <widget class="QLabel" name="labPicture">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>48</width> <width>48</width>
<height>27</height> <height>27</height>
</size> </size>
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>48</width> <width>48</width>
<height>27</height> <height>27</height>
</size> </size>
</property> </property>
<property name="lineWidth"> <property name="lineWidth">
<number>0</number> <number>0</number>
</property> </property>
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
<property name="scaledContents"> <property name="scaledContents">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="labPicStr"> <widget class="QLabel" name="labPicStr">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"> <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>PHOTO - 00/00/00 00:00:00</string> <string>PHOTO - 00/00/00 00:00:00</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="cmdView"> <widget class="QPushButton" name="cmdView">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>View picture</string> <string>View picture</string>
</property> </property>
<property name="text"> <property name="text">
<string>View</string> <string>View</string>
</property> </property>
<property name="autoDefault"> <property name="autoDefault">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="cmdCopy"> <widget class="QPushButton" name="cmdCopy">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Copy picture</string> <string>Copy picture</string>
</property> </property>
<property name="text"> <property name="text">
<string>Copy</string> <string>Copy</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="cmdExport"> <widget class="QPushButton" name="cmdExport">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Export picture</string> <string>Export picture</string>
</property> </property>
<property name="text"> <property name="text">
<string>Export</string> <string>Export</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="cmdDelete"> <widget class="QPushButton" name="cmdDelete">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Delete picture</string> <string>Delete picture</string>
</property> </property>
<property name="text"> <property name="text">
<string>Delete</string> <string>Delete</string>
</property> </property>
<property name="autoDefault"> <property name="autoDefault">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -1,128 +1,128 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "StandardPaths.h" #include "StandardPaths.h"
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
#include <QStandardPaths> #include <QStandardPaths>
#else #else
#include <QDesktopServices> #include <QDesktopServices>
#endif #endif
StandardPaths::StandardPaths() StandardPaths::StandardPaths()
{ {
} }
QString StandardPaths::applicationsLocation() QString StandardPaths::applicationsLocation()
{ {
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation); return QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation);
#else #else
return QDesktopServices::storageLocation(QDesktopServices::ApplicationsLocation); return QDesktopServices::storageLocation(QDesktopServices::ApplicationsLocation);
#endif #endif
} }
QString StandardPaths::cacheLocation() QString StandardPaths::cacheLocation()
{ {
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::CacheLocation); return QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
#else #else
return QDesktopServices::storageLocation(QDesktopServices::CacheLocation); return QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
#endif #endif
} }
QString StandardPaths::dataLocation() QString StandardPaths::dataLocation()
{ {
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::DataLocation); return QStandardPaths::writableLocation(QStandardPaths::DataLocation);
#else #else
return QDesktopServices::storageLocation(QDesktopServices::DataLocation); return QDesktopServices::storageLocation(QDesktopServices::DataLocation);
#endif #endif
} }
QString StandardPaths::desktopLocation() QString StandardPaths::desktopLocation()
{ {
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
#else #else
return QDesktopServices::storageLocation(QDesktopServices::DesktopLocation); return QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
#endif #endif
} }
QString StandardPaths::documentsLocation() QString StandardPaths::documentsLocation()
{ {
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); return QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
#else #else
return QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation); return QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
#endif #endif
} }
QString StandardPaths::moviesLocation() QString StandardPaths::moviesLocation()
{ {
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::MoviesLocation); return QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
#else #else
return QDesktopServices::storageLocation(QDesktopServices::MoviesLocation); return QDesktopServices::storageLocation(QDesktopServices::MoviesLocation);
#endif #endif
} }
QString StandardPaths::picturesLocation() QString StandardPaths::picturesLocation()
{ {
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); return QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
#else #else
return QDesktopServices::storageLocation(QDesktopServices::PicturesLocation); return QDesktopServices::storageLocation(QDesktopServices::PicturesLocation);
#endif #endif
} }
QString StandardPaths::fontsLocation() QString StandardPaths::fontsLocation()
{ {
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::FontsLocation); return QStandardPaths::writableLocation(QStandardPaths::FontsLocation);
#else #else
return QDesktopServices::storageLocation(QDesktopServices::FontsLocation); return QDesktopServices::storageLocation(QDesktopServices::FontsLocation);
#endif #endif
} }
QString StandardPaths::homeLocation() QString StandardPaths::homeLocation()
{ {
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::HomeLocation); return QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
#else #else
return QDesktopServices::storageLocation(QDesktopServices::HomeLocation); return QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
#endif #endif
} }
QString StandardPaths::musicLocation() QString StandardPaths::musicLocation()
{ {
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::MusicLocation); return QStandardPaths::writableLocation(QStandardPaths::MusicLocation);
#else #else
return QDesktopServices::storageLocation(QDesktopServices::MusicLocation); return QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
#endif #endif
} }
QString StandardPaths::tempLocation() QString StandardPaths::tempLocation()
{ {
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::TempLocation); return QStandardPaths::writableLocation(QStandardPaths::TempLocation);
#else #else
return QDesktopServices::storageLocation(QDesktopServices::TempLocation); return QDesktopServices::storageLocation(QDesktopServices::TempLocation);
#endif #endif
} }

View File

@ -1,41 +1,41 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef STANDARDPATHS_H #ifndef STANDARDPATHS_H
#define STANDARDPATHS_H #define STANDARDPATHS_H
#include <QString> #include <QString>
class StandardPaths class StandardPaths
{ {
public: public:
StandardPaths(); StandardPaths();
static QString applicationsLocation(); static QString applicationsLocation();
static QString cacheLocation(); static QString cacheLocation();
static QString dataLocation(); static QString dataLocation();
static QString desktopLocation(); static QString desktopLocation();
static QString documentsLocation(); static QString documentsLocation();
static QString fontsLocation(); static QString fontsLocation();
static QString homeLocation(); static QString homeLocation();
static QString moviesLocation(); static QString moviesLocation();
static QString picturesLocation(); static QString picturesLocation();
static QString musicLocation(); static QString musicLocation();
static QString tempLocation(); static QString tempLocation();
}; };
#endif // STANDARDPATHS_H #endif // STANDARDPATHS_H

View File

@ -1,76 +1,80 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "StringParser.h" #include "StringParser.h"
#include "config.h" #include "config.h"
#include <QTextDocument> #include <QTextDocument>
#ifndef GTA5VIEW_CMD #include <QLibraryInfo>
#include <QApplication> #ifndef GTA5VIEW_CMD
#endif #include <QApplication>
#include <QTextCodec> #endif
#include <QByteArray> #include <QTextCodec>
#include <QFileInfo> #include <QByteArray>
#include <QString> #include <QFileInfo>
#include <QList> #include <QString>
#include <QDir> #include <QList>
#include <QDir>
StringParser::StringParser()
{ StringParser::StringParser()
{
}
}
QString StringParser::parseTitleString(const QByteArray &commitBytes, int maxLength)
{ QString StringParser::parseTitleString(const QByteArray &commitBytes, int maxLength)
Q_UNUSED(maxLength) {
QString retStr = QTextCodec::codecForName("UTF-16LE")->toUnicode(commitBytes).trimmed(); Q_UNUSED(maxLength)
retStr.remove(QChar('\x00')); QString retStr = QTextCodec::codecForName("UTF-16LE")->toUnicode(commitBytes).trimmed();
return retStr; retStr.remove(QChar('\x00'));
} return retStr;
}
QString StringParser::convertDrawStringForLog(const QString &inputStr)
{ QString StringParser::convertDrawStringForLog(const QString &inputStr)
QString outputStr = inputStr; {
return outputStr.replace("&","&u;").replace(",","&c;"); QString outputStr = inputStr;
} return outputStr.replace("&","&u;").replace(",","&c;");
}
QString StringParser::convertLogStringForDraw(const QString &inputStr)
{ QString StringParser::convertLogStringForDraw(const QString &inputStr)
QString outputStr = inputStr; {
return outputStr.replace("&c;",",").replace("&u;","&"); QString outputStr = inputStr;
} return outputStr.replace("&c;",",").replace("&u;","&");
}
#ifndef GTA5VIEW_CMD
QString StringParser::convertBuildedString(const QString &buildedStr) #ifndef GTA5VIEW_CMD
{ QString StringParser::convertBuildedString(const QString &buildedStr)
QString outputStr = buildedStr; {
QByteArray sharePath = GTA5SYNC_SHARE; QString outputStr = buildedStr;
outputStr.replace("$SHAREDIR", QString::fromUtf8(sharePath)); QByteArray sharePath = GTA5SYNC_SHARE;
outputStr.replace("$RUNDIR", QFileInfo(qApp->applicationFilePath()).absoluteDir().absolutePath()); outputStr.replace("APPNAME:", GTA5SYNC_APPSTR);
outputStr.replace("$SEPARATOR", QDir::separator()); outputStr.replace("SHAREDDIR:", QString::fromUtf8(sharePath));
return outputStr; outputStr.replace("RUNDIR:", QFileInfo(qApp->applicationFilePath()).absoluteDir().absolutePath());
} outputStr.replace("QCONFLANG:", QLibraryInfo::location(QLibraryInfo::TranslationsPath));
#endif outputStr.replace("QCONFPLUG:", QLibraryInfo::location(QLibraryInfo::PluginsPath));
outputStr.replace("SEPARATOR:", QDir::separator());
QString StringParser::escapeString(const QString &toEscape) return outputStr;
{ }
#if QT_VERSION >= 0x050000 #endif
return toEscape.toHtmlEscaped();
#else QString StringParser::escapeString(const QString &toEscape)
return Qt::escape(toEscape); {
#endif #if QT_VERSION >= 0x050000
} return toEscape.toHtmlEscaped();
#else
return Qt::escape(toEscape);
#endif
}

View File

@ -1,38 +1,38 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef STRINGPARSER_H #ifndef STRINGPARSER_H
#define STRINGPARSER_H #define STRINGPARSER_H
#include <QByteArray> #include <QByteArray>
#include <QString> #include <QString>
class StringParser class StringParser
{ {
public: public:
StringParser(); StringParser();
static QString parseTitleString(const QByteArray &commitBytes, int maxLength); static QString parseTitleString(const QByteArray &commitBytes, int maxLength);
static QString convertDrawStringForLog(const QString &inputStr); static QString convertDrawStringForLog(const QString &inputStr);
static QString convertLogStringForDraw(const QString &inputStr); static QString convertLogStringForDraw(const QString &inputStr);
#ifndef GTA5VIEW_CMD #ifndef GTA5VIEW_CMD
static QString convertBuildedString(const QString &buildedStr); static QString convertBuildedString(const QString &buildedStr);
#endif #endif
static QString escapeString(const QString &toEscape); static QString escapeString(const QString &toEscape);
}; };
#endif // STRINGPARSER_H #endif // STRINGPARSER_H

543
TranslationClass.cpp Normal file
View File

@ -0,0 +1,543 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2017 Syping
*
* 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.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "TranslationClass.h"
#include "AppEnv.h"
#include "config.h"
#include <QStringBuilder>
#include <QApplication>
#include <QStringList>
#include <QTranslator>
#include <QSettings>
#include <QLocale>
#include <QDebug>
#include <QFile>
#include <QDir>
#if QT_VERSION >= 0x050000
#define QtBaseTranslationFormat "qtbase_"
#else
#define QtBaseTranslationFormat "qt_"
#endif
TranslationClass TranslationClass::translationClassInstance;
void TranslationClass::initUserLanguage()
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("Interface");
userLanguage = settings.value("Language", "System").toString();
settings.endGroup();
}
void TranslationClass::loadTranslation(QApplication *app)
{
if (isLangLoaded) { unloadTranslation(app); }
else { currentLangIndex = 0; }
QString exLangPath = AppEnv::getExLangFolder();
QString inLangPath = AppEnv::getInLangFolder();
if (userLanguage == "en" || userLanguage == "en_GB")
{
currentLanguage = "en_GB";
if (loadQtTranslation_p(exLangPath, &exQtTranslator))
{
app->installTranslator(&exQtTranslator);
}
else if (loadQtTranslation_p(inLangPath, &inQtTranslator))
{
app->installTranslator(&inQtTranslator);
}
QLocale::setDefault(currentLanguage);
isLangLoaded = true;
return;
}
#ifndef GTA5SYNC_QCONF // Classic modable loading method
QString externalLanguageStr;
bool externalLanguageReady = false;
bool loadInternalLang = false;
bool trLoadSuccess = false;
if (isUserLanguageSystem_p())
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadExSystemLanguage";
#endif
trLoadSuccess = loadSystemTranslation_p(exLangPath, &exAppTranslator);
}
else
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadExUserLanguage";
#endif
trLoadSuccess = loadUserTranslation_p(exLangPath, &exAppTranslator);
if (!trLoadSuccess)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadInUserLanguage";
#endif
trLoadSuccess = loadUserTranslation_p(inLangPath, &inAppTranslator);
if (!trLoadSuccess)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadUserLanguageFailed";
#endif
}
else
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadUserLanguageSuccess";
#endif
loadInternalLang = true;
isLangLoaded = true;
}
}
else
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadUserLanguageSuccess";
#endif
isLangLoaded = true;
}
}
if (trLoadSuccess)
{
if (currentLangIndex != 0) // Don't install the language until we know we not have a better language for the user
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "externalLanguageReady" << currentLanguage;
#endif
externalLanguageStr = currentLanguage;
externalLanguageReady = true;
}
else
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "installTranslation";
#endif
if (loadInternalLang)
{
app->installTranslator(&inAppTranslator);
}
else
{
app->installTranslator(&exAppTranslator);
}
if (loadQtTranslation_p(exLangPath, &exQtTranslator))
{
app->installTranslator(&exQtTranslator);
}
else if (loadQtTranslation_p(inLangPath, &inQtTranslator))
{
app->installTranslator(&inQtTranslator);
}
QLocale::setDefault(currentLanguage);
isLangLoaded = true;
}
}
if (externalLanguageReady)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadInSystemLanguage";
#endif
int externalLangIndex = currentLangIndex;
trLoadSuccess = loadSystemTranslation_p(inLangPath, &inAppTranslator);
#ifdef GTA5SYNC_DEBUG
qDebug() << "externalLangIndex" << externalLangIndex << "internalLangIndex" << currentLangIndex;
#endif
if (trLoadSuccess && externalLangIndex > currentLangIndex)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "installInternalTranslation";
#endif
app->installTranslator(&inAppTranslator);
if (loadQtTranslation_p(exLangPath, &exQtTranslator))
{
app->installTranslator(&exQtTranslator);
}
else if (loadQtTranslation_p(inLangPath, &inQtTranslator))
{
app->installTranslator(&inQtTranslator);
}
QLocale::setDefault(currentLanguage);
isLangLoaded = true;
}
else
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "installExternalTranslation";
#endif
currentLanguage = externalLanguageStr;
app->installTranslator(&exAppTranslator);
if (loadQtTranslation_p(exLangPath, &exQtTranslator))
{
app->installTranslator(&exQtTranslator);
}
else if (loadQtTranslation_p(inLangPath, &inQtTranslator))
{
app->installTranslator(&inQtTranslator);
}
QLocale::setDefault(currentLanguage);
isLangLoaded = true;
}
}
else if (!isLangLoaded)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadInSystemLanguage";
#endif
trLoadSuccess = loadSystemTranslation_p(inLangPath, &inAppTranslator);
if (trLoadSuccess)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "installInternalTranslation";
#endif
app->installTranslator(&inAppTranslator);
if (loadQtTranslation_p(exLangPath, &exQtTranslator))
{
app->installTranslator(&exQtTranslator);
}
else if (loadQtTranslation_p(inLangPath, &inQtTranslator))
{
app->installTranslator(&inQtTranslator);
}
QLocale::setDefault(currentLanguage);
isLangLoaded = true;
}
else if (!trLoadSuccess)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "fallbackToDefaultApplicationLanguage";
#endif
currentLanguage = "en_GB";
if (loadQtTranslation_p(exLangPath, &exQtTranslator))
{
app->installTranslator(&exQtTranslator);
}
else if (loadQtTranslation_p(inLangPath, &inQtTranslator))
{
app->installTranslator(&inQtTranslator);
}
QLocale::setDefault(currentLanguage);
isLangLoaded = true;
}
}
#else // New qconf loading method
bool trLoadSuccess;
if (isUserLanguageSystem_p())
{
trLoadSuccess = loadSystemTranslation_p(inLangPath, &inAppTranslator);
}
else
{
trLoadSuccess = loadUserTranslation_p(inLangPath, &inAppTranslator);
}
if (!trLoadSuccess && !isUserLanguageSystem_p())
{
trLoadSuccess = loadSystemTranslation_p(inLangPath, &inAppTranslator);
}
if (trLoadSuccess)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "installTranslation" << currentLanguage;
#endif
app->installTranslator(&inAppTranslator);
if (loadQtTranslation_p(exLangPath, &exQtTranslator))
{
app->installTranslator(&exQtTranslator);
}
else if (loadQtTranslation_p(inLangPath, &inQtTranslator))
{
app->installTranslator(&inQtTranslator);
}
QLocale::setDefault(currentLanguage);
isLangLoaded = true;
}
#endif
}
QStringList TranslationClass::listTranslations(const QString &langPath)
{
QDir langDir;
langDir.setNameFilters(QStringList("gta5sync_*.qm"));
langDir.setPath(langPath);
QStringList availableLanguages;
foreach(const QString &lang, langDir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::NoSort))
{
availableLanguages << QString(lang).remove("gta5sync_").remove(".qm");
}
return availableLanguages;
}
bool TranslationClass::loadSystemTranslation_p(const QString &langPath, QTranslator *appTranslator)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadSystemTranslation_p";
#endif
int currentLangCounter = 0;
foreach(const QString &languageName, QLocale::system().uiLanguages())
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguage" << languageName;
#endif
QStringList langList = QString(languageName).replace("-","_").split("_");
if (langList.length() == 2)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFile" << QString(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm");
#endif
if (QFile::exists(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm"))
{
if (appTranslator->load(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm"))
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFileSuccess" << QString(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm");
#endif
currentLanguage = languageName;
currentLangIndex = currentLangCounter;
return true;
}
}
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFile" << QString(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % ".qm");
#endif
if (QFile::exists(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % ".qm"))
{
if (appTranslator->load(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % ".qm"))
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFileSuccess" << QString(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % ".qm");
#endif
currentLanguage = languageName;
currentLangIndex = currentLangCounter;
return true;
}
}
if (langList.at(0) == "en")
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "languageEnglishMode index" << currentLangCounter;
#endif
currentLanguage = languageName;
currentLangIndex = currentLangCounter;
return true;
}
}
else if (langList.length() == 1)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFile" << QString(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % ".qm");
#endif
if (QFile::exists(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % ".qm"))
{
if (appTranslator->load(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % ".qm"))
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFileSuccess" << QString(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % ".qm");
#endif
currentLanguage = languageName;
return true;
}
}
}
#ifdef GTA5SYNC_DEBUG
qDebug() << "currentLangCounter bump";
#endif
currentLangCounter++;
}
return false;
}
bool TranslationClass::loadUserTranslation_p(const QString &langPath, QTranslator *appTranslator)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadUserTranslation_p";
#endif
QString languageName = userLanguage;
QStringList langList = QString(languageName).replace("-","_").split("_");
if (langList.length() == 2)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFile" << QString(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm");
#endif
if (QFile::exists(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm"))
{
if (appTranslator->load(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm"))
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFileSuccess" << QString(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm");
#endif
currentLanguage = languageName;
return true;
}
}
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFile" << QString(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % ".qm");
#endif
if (QFile::exists(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % ".qm"))
{
if (appTranslator->load(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % ".qm"))
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFileSuccess" << QString(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % ".qm");
#endif
currentLanguage = languageName;
return true;
}
}
}
else if (langList.length() == 1)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFile" << QString(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % ".qm");
#endif
if (QFile::exists(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % ".qm"))
{
if (appTranslator->load(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % ".qm"))
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFileSuccess" << QString(langPath % QDir::separator() % "gta5sync_" % langList.at(0) % ".qm");
#endif
currentLanguage = languageName;
return true;
}
}
}
return false;
}
bool TranslationClass::loadQtTranslation_p(const QString &langPath, QTranslator *qtTranslator)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadQtTranslation_p" << currentLanguage;
#endif
QString languageName = currentLanguage;
QStringList langList = QString(languageName).replace("-","_").split("_");
if (langList.length() == 2)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFile" << QString(langPath % QDir::separator() % QtBaseTranslationFormat % langList.at(0) % "_" % langList.at(1) % ".qm");
#endif
if (QFile::exists(langPath % QDir::separator() % QtBaseTranslationFormat % langList.at(0) % "_" % langList.at(1) % ".qm"))
{
if (qtTranslator->load(langPath % QDir::separator() % QtBaseTranslationFormat % langList.at(0) % "_" % langList.at(1) % ".qm"))
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFileSuccess" << QString(langPath % QDir::separator() % QtBaseTranslationFormat % langList.at(0) % "_" % langList.at(1) % ".qm");
#endif
return true;
}
}
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFile" << QString(langPath % QDir::separator() % QtBaseTranslationFormat % langList.at(0) % ".qm");
#endif
if (QFile::exists(langPath % QDir::separator() % QtBaseTranslationFormat % langList.at(0) % ".qm"))
{
if (qtTranslator->load(langPath % QDir::separator() % QtBaseTranslationFormat % langList.at(0) % ".qm"))
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFileSuccess" << QString(langPath % QDir::separator() % QtBaseTranslationFormat % langList.at(0) % ".qm");
#endif
return true;
}
}
}
else if (langList.length() == 1)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFile" << QString(langPath % QDir::separator() % QtBaseTranslationFormat % langList.at(0) % ".qm");
#endif
if (QFile::exists(langPath % QDir::separator() % QtBaseTranslationFormat % langList.at(0) % ".qm"))
{
if (qtTranslator->load(langPath % QDir::separator() % QtBaseTranslationFormat % langList.at(0) % ".qm"))
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFileSuccess" << QString(langPath % QDir::separator() % QtBaseTranslationFormat % langList.at(0) % ".qm");
#endif
return true;
}
}
}
return false;
}
bool TranslationClass::isUserLanguageSystem_p()
{
return (userLanguage == "System" || userLanguage.trimmed().isEmpty());
}
QString TranslationClass::getCurrentLanguage()
{
return currentLanguage;
}
bool TranslationClass::isLanguageLoaded()
{
return isLangLoaded;
}
void TranslationClass::unloadTranslation(QApplication *app)
{
if (isLangLoaded)
{
#ifndef GTA5SYNC_QCONF
app->removeTranslator(&exAppTranslator);
app->removeTranslator(&exQtTranslator);
app->removeTranslator(&inAppTranslator);
app->removeTranslator(&inQtTranslator);
#else
app->removeTranslator(&inAppTranslator);
app->removeTranslator(&exQtTranslator);
#endif
currentLangIndex = 0;
currentLanguage = QString();
QLocale::setDefault(QLocale::c());
isLangLoaded = false;
}
#ifdef _MSC_VER // Fix dumb Microsoft compiler warning
Q_UNUSED(app)
#endif
}
QString TranslationClass::getCountryCode(QLocale::Country country)
{
QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage,
QLocale::AnyScript,
country);
if (locales.isEmpty()) return QString();
QStringList localeStrList = locales.at(0).name().split("_");
if (localeStrList.length() <= 2)
{
return localeStrList.at(1).toLower();
}
else
{
return QString();
}
}
QString TranslationClass::getCountryCode(QLocale locale)
{
QStringList localeStrList = locale.name().split("_");
if (localeStrList.length() <= 2)
{
return localeStrList.at(1).toLower();
}
else
{
return QString();
}
}

63
TranslationClass.h Normal file
View File

@ -0,0 +1,63 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2017 Syping
*
* 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.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef TRANSLATIONCLASS_H
#define TRANSLATIONCLASS_H
#include <QApplication>
#include <QTranslator>
#include <QStringList>
#include <QString>
#include <QObject>
#include <QLocale>
class TranslationClass : public QObject
{
Q_OBJECT
public:
static TranslationClass* getInstance() { return &translationClassInstance; }
static QString getCountryCode(QLocale::Country country);
static QString getCountryCode(QLocale locale);
void initUserLanguage();
void loadTranslation(QApplication *app);
void unloadTranslation(QApplication *app);
QStringList listTranslations(const QString &langPath);
QString getCurrentLanguage();
bool isLanguageLoaded();
private:
static TranslationClass translationClassInstance;
bool loadSystemTranslation_p(const QString &langPath, QTranslator *appTranslator);
bool loadUserTranslation_p(const QString &langPath, QTranslator *appTranslator);
bool loadQtTranslation_p(const QString &langPath, QTranslator *qtTranslator);
bool isUserLanguageSystem_p();
QTranslator exAppTranslator;
QTranslator exQtTranslator;
QTranslator inAppTranslator;
QTranslator inQtTranslator;
QString currentLanguage;
QString userLanguage;
int currentLangIndex;
bool isLangLoaded;
};
extern TranslationClass translationClass;
#define TCInstance TranslationClass::getInstance()
#endif // TRANSLATIONCLASS_H

File diff suppressed because it is too large Load Diff

View File

@ -1,93 +1,96 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef USERINTERFACE_H #ifndef USERINTERFACE_H
#define USERINTERFACE_H #define USERINTERFACE_H
#include "SnapmaticPicture.h" #include "SnapmaticPicture.h"
#include "ProfileInterface.h" #include "ProfileInterface.h"
#include "ProfileDatabase.h" #include "ProfileDatabase.h"
#include "DatabaseThread.h" #include "DatabaseThread.h"
#include "CrewDatabase.h" #include "CrewDatabase.h"
#include "SavegameData.h" #include "SavegameData.h"
#include <QMainWindow> #include <QMainWindow>
#include <QCloseEvent> #include <QMouseEvent>
#include <QString> #include <QCloseEvent>
#include <QMap> #include <QString>
#include <QMap>
namespace Ui {
class UserInterface; namespace Ui {
} class UserInterface;
}
class UserInterface : public QMainWindow
{ class UserInterface : public QMainWindow
Q_OBJECT {
public: Q_OBJECT
explicit UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0); public:
void setupDirEnv(); explicit UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0);
~UserInterface(); void setupDirEnv();
~UserInterface();
private slots:
void closeProfile(); private slots:
void profileLoaded(); void closeProfile();
void changeFolder_clicked(); void profileLoaded();
void profileButton_clicked(); void changeFolder_clicked();
void on_cmdReload_clicked(); void profileButton_clicked();
void on_actionExit_triggered(); void on_cmdReload_clicked();
void on_actionSelect_profile_triggered(); void on_actionExit_triggered();
void on_actionAbout_gta5sync_triggered(); void on_actionSelect_profile_triggered();
void on_actionSelect_all_triggered(); void on_actionAbout_gta5sync_triggered();
void on_actionDeselect_all_triggered(); void on_actionSelect_all_triggered();
void on_actionExport_selected_triggered(); void on_actionDeselect_all_triggered();
void on_actionDelete_selected_triggered(); void on_actionExport_selected_triggered();
void on_actionOptions_triggered(); void on_actionDelete_selected_triggered();
void on_action_Import_triggered(); void on_actionOptions_triggered();
void on_actionOpen_File_triggered(); void on_action_Import_triggered();
void on_actionSelect_GTA_Folder_triggered(); void on_actionOpen_File_triggered();
void on_action_Enable_In_game_triggered(); void on_actionSelect_GTA_Folder_triggered();
void on_action_Disable_In_game_triggered(); void on_action_Enable_In_game_triggered();
void settingsApplied(int contentMode, QString language); void on_action_Disable_In_game_triggered();
void settingsApplied(int contentMode, QString language);
protected:
void closeEvent(QCloseEvent *ev); protected:
void closeEvent(QCloseEvent *ev);
private:
ProfileDatabase *profileDB; private:
CrewDatabase *crewDB; ProfileDatabase *profileDB;
DatabaseThread *threadDB; CrewDatabase *crewDB;
Ui::UserInterface *ui; DatabaseThread *threadDB;
ProfileInterface *profileUI; Ui::UserInterface *ui;
QList<QPushButton*> profileBtns; ProfileInterface *profileUI;
bool profileOpen; QList<QPushButton*> profileBtns;
int contentMode; QString profileName;
QString language; bool profileOpen;
QString defaultWindowTitle; int contentMode;
QString GTAV_Folder; QString language;
QString GTAV_ProfilesFolder; QString defaultWindowTitle;
QStringList GTAV_Profiles; QString GTAV_Folder;
void setupProfileUi(); QString GTAV_ProfilesFolder;
void openProfile(QString profileName); QStringList GTAV_Profiles;
void openSelectProfile(); void setupProfileUi();
void openProfile(const QString &profileName);
// Open File void openSelectProfile();
bool openFile(QString selectedFile, bool warn = true); void retranslateUi();
void openSavegameFile(SavegameData *savegame);
void openSnapmaticFile(SnapmaticPicture *picture); // Open File
}; bool openFile(QString selectedFile, bool warn = true);
void openSavegameFile(SavegameData *savegame);
#endif // USERINTERFACE_H void openSnapmaticFile(SnapmaticPicture *picture);
};
#endif // USERINTERFACE_H

View File

@ -1,348 +1,354 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>UserInterface</class> <class>UserInterface</class>
<widget class="QMainWindow" name="UserInterface"> <widget class="QMainWindow" name="UserInterface">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>625</width> <width>625</width>
<height>500</height> <height>500</height>
</rect> </rect>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>625</width> <width>625</width>
<height>500</height> <height>500</height>
</size> </size>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>%2 - %1</string> <string>%2 - %1</string>
</property> </property>
<widget class="QWidget" name="cwUI"> <widget class="QWidget" name="cwUI">
<layout class="QVBoxLayout" name="vlUI"> <layout class="QVBoxLayout" name="vlUI">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QStackedWidget" name="swProfile"> <widget class="QStackedWidget" name="swProfile">
<property name="lineWidth"> <property name="lineWidth">
<number>0</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="swSelection"> <widget class="QWidget" name="swSelection">
<layout class="QVBoxLayout" name="vlUserInterface"> <layout class="QVBoxLayout" name="vlUserInterface">
<property name="spacing"> <property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin"> <property name="leftMargin">
<number>9</number> <number>9</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>9</number> <number>9</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>9</number> <number>9</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>9</number> <number>9</number>
</property> </property>
<item> <item>
<spacer name="vsUpper"> <spacer name="vsUpper">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>0</width> <width>0</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QLabel" name="labSelectProfile"> <widget class="QLabel" name="labSelectProfile">
<property name="text"> <property name="text">
<string>Select profile</string> <string>Select profile</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QVBoxLayout" name="vlButtons"/> <layout class="QVBoxLayout" name="vlButtons"/>
</item> </item>
<item> <item>
<spacer name="vsFooter"> <spacer name="vsFooter">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>0</width> <width>0</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="hlButtons"> <layout class="QHBoxLayout" name="hlButtons">
<item> <item>
<widget class="QLabel" name="labVersion"> <widget class="QLabel" name="labVersion">
<property name="text"> <property name="text">
<string>%1 %2</string> <string>%1 %2</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="hsButtons"> <spacer name="hsButtons">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>0</width> <width>0</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="cmdReload"> <widget class="QPushButton" name="cmdReload">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="toolTip">
<string>&amp;Reload</string> <string>Reload profile overview</string>
</property> </property>
<property name="autoDefault"> <property name="text">
<bool>true</bool> <string>&amp;Reload</string>
</property> </property>
</widget> <property name="autoDefault">
</item> <bool>true</bool>
<item> </property>
<widget class="QPushButton" name="cmdClose"> </widget>
<property name="sizePolicy"> </item>
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <item>
<horstretch>0</horstretch> <widget class="QPushButton" name="cmdClose">
<verstretch>0</verstretch> <property name="sizePolicy">
</sizepolicy> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
</property> <horstretch>0</horstretch>
<property name="text"> <verstretch>0</verstretch>
<string>&amp;Close</string> </sizepolicy>
</property> </property>
<property name="autoDefault"> <property name="toolTip">
<bool>true</bool> <string extracomment="Close %1 &lt;- (gta5view/gta5sync) - %1 will be replaced automatically">Close %1</string>
</property> </property>
</widget> <property name="text">
</item> <string>&amp;Close</string>
</layout> </property>
</item> <property name="autoDefault">
</layout> <bool>true</bool>
</widget> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </item>
<widget class="QMenuBar" name="menuBar"> </layout>
<property name="geometry"> </widget>
<rect> </widget>
<x>0</x> </item>
<y>0</y> </layout>
<width>625</width> </widget>
<height>21</height> <widget class="QMenuBar" name="menuBar">
</rect> <property name="geometry">
</property> <rect>
<widget class="QMenu" name="menuFile"> <x>0</x>
<property name="title"> <y>0</y>
<string>&amp;File</string> <width>625</width>
</property> <height>21</height>
<addaction name="actionSelect_GTA_Folder"/> </rect>
<addaction name="actionOpen_File"/> </property>
<addaction name="actionSelect_profile"/> <widget class="QMenu" name="menuFile">
<addaction name="separator"/> <property name="title">
<addaction name="actionExit"/> <string>&amp;File</string>
</widget> </property>
<widget class="QMenu" name="menuHelp"> <addaction name="actionSelect_GTA_Folder"/>
<property name="title"> <addaction name="actionOpen_File"/>
<string>&amp;Help</string> <addaction name="actionSelect_profile"/>
</property> <addaction name="separator"/>
<addaction name="actionAbout_gta5sync"/> <addaction name="actionExit"/>
</widget> </widget>
<widget class="QMenu" name="menuEdit"> <widget class="QMenu" name="menuHelp">
<property name="title"> <property name="title">
<string>&amp;Edit</string> <string>&amp;Help</string>
</property> </property>
<addaction name="actionOptions"/> <addaction name="actionAbout_gta5sync"/>
</widget> </widget>
<widget class="QMenu" name="menuProfile"> <widget class="QMenu" name="menuEdit">
<property name="title"> <property name="title">
<string>&amp;Profile</string> <string>&amp;Edit</string>
</property> </property>
<widget class="QMenu" name="menuSelection_visibility"> <addaction name="actionOptions"/>
<property name="title"> </widget>
<string>&amp;Selection visibility</string> <widget class="QMenu" name="menuProfile">
</property> <property name="title">
<addaction name="action_Enable_In_game"/> <string>&amp;Profile</string>
<addaction name="action_Disable_In_game"/> </property>
</widget> <widget class="QMenu" name="menuSelection_visibility">
<addaction name="action_Import"/> <property name="title">
<addaction name="actionExport_selected"/> <string>&amp;Selection visibility</string>
<addaction name="actionDelete_selected"/> </property>
<addaction name="separator"/> <addaction name="action_Enable_In_game"/>
<addaction name="menuSelection_visibility"/> <addaction name="action_Disable_In_game"/>
<addaction name="separator"/> </widget>
<addaction name="actionSelect_all"/> <addaction name="action_Import"/>
<addaction name="actionDeselect_all"/> <addaction name="actionExport_selected"/>
</widget> <addaction name="actionDelete_selected"/>
<addaction name="menuFile"/> <addaction name="separator"/>
<addaction name="menuEdit"/> <addaction name="menuSelection_visibility"/>
<addaction name="menuProfile"/> <addaction name="separator"/>
<addaction name="menuHelp"/> <addaction name="actionSelect_all"/>
</widget> <addaction name="actionDeselect_all"/>
<action name="actionAbout_gta5sync"> </widget>
<property name="text"> <addaction name="menuFile"/>
<string>&amp;About %1</string> <addaction name="menuEdit"/>
</property> <addaction name="menuProfile"/>
<property name="shortcut"> <addaction name="menuHelp"/>
<string>Ctrl+P</string> </widget>
</property> <action name="actionAbout_gta5sync">
</action> <property name="text">
<action name="actionExit"> <string>&amp;About %1</string>
<property name="text"> </property>
<string>&amp;Exit</string> <property name="shortcut">
</property> <string>Ctrl+P</string>
<property name="toolTip"> </property>
<string>Exit</string> </action>
</property> <action name="actionExit">
<property name="shortcut"> <property name="text">
<string>Ctrl+Q</string> <string>&amp;Exit</string>
</property> </property>
</action> <property name="toolTip">
<action name="actionSelect_profile"> <string>Exit</string>
<property name="text"> </property>
<string>Close &amp;Profile</string> <property name="shortcut">
</property> <string>Ctrl+Q</string>
<property name="shortcut"> </property>
<string>Ctrl+End</string> </action>
</property> <action name="actionSelect_profile">
</action> <property name="text">
<action name="actionOptions"> <string>Close &amp;Profile</string>
<property name="text"> </property>
<string>&amp;Settings</string> <property name="shortcut">
</property> <string>Ctrl+End</string>
<property name="shortcut"> </property>
<string>Ctrl+S</string> </action>
</property> <action name="actionOptions">
</action> <property name="text">
<action name="actionSelect_all"> <string>&amp;Settings</string>
<property name="text"> </property>
<string>Select &amp;All</string> <property name="shortcut">
</property> <string>Ctrl+S</string>
<property name="shortcut"> </property>
<string>Ctrl+A</string> </action>
</property> <action name="actionSelect_all">
</action> <property name="text">
<action name="actionDeselect_all"> <string>Select &amp;All</string>
<property name="text"> </property>
<string>&amp;Deselect All</string> <property name="shortcut">
</property> <string>Ctrl+A</string>
<property name="shortcut"> </property>
<string>Ctrl+D</string> </action>
</property> <action name="actionDeselect_all">
</action> <property name="text">
<action name="actionExport_selected"> <string>&amp;Deselect All</string>
<property name="text"> </property>
<string>&amp;Export selected...</string> <property name="shortcut">
</property> <string>Ctrl+D</string>
<property name="shortcut"> </property>
<string>Ctrl+E</string> </action>
</property> <action name="actionExport_selected">
</action> <property name="text">
<action name="actionDelete_selected"> <string>&amp;Export selected...</string>
<property name="text"> </property>
<string>&amp;Remove selected</string> <property name="shortcut">
</property> <string>Ctrl+E</string>
<property name="shortcut"> </property>
<string>Ctrl+Del</string> </action>
</property> <action name="actionDelete_selected">
</action> <property name="text">
<action name="action_Import"> <string>&amp;Remove selected</string>
<property name="text"> </property>
<string>&amp;Import files...</string> <property name="shortcut">
</property> <string>Ctrl+Del</string>
<property name="shortcut"> </property>
<string>Ctrl+I</string> </action>
</property> <action name="action_Import">
</action> <property name="text">
<action name="actionOpen_File"> <string>&amp;Import files...</string>
<property name="text"> </property>
<string>&amp;Open File...</string> <property name="shortcut">
</property> <string>Ctrl+I</string>
<property name="shortcut"> </property>
<string>Ctrl+O</string> </action>
</property> <action name="actionOpen_File">
</action> <property name="text">
<action name="actionSelect_GTA_Folder"> <string>&amp;Open File...</string>
<property name="text"> </property>
<string>Select &amp;GTA V Folder...</string> <property name="shortcut">
</property> <string>Ctrl+O</string>
<property name="toolTip"> </property>
<string>Select GTA V Folder...</string> </action>
</property> <action name="actionSelect_GTA_Folder">
<property name="shortcut"> <property name="text">
<string>Ctrl+G</string> <string>Select &amp;GTA V Folder...</string>
</property> </property>
</action> <property name="toolTip">
<action name="action_Enable_In_game"> <string>Select GTA V Folder...</string>
<property name="text"> </property>
<string>Show In-gam&amp;e</string> <property name="shortcut">
</property> <string>Ctrl+G</string>
<property name="shortcut"> </property>
<string>Shift+E</string> </action>
</property> <action name="action_Enable_In_game">
</action> <property name="text">
<action name="action_Disable_In_game"> <string>Show In-gam&amp;e</string>
<property name="text"> </property>
<string>Hi&amp;de In-game</string> <property name="shortcut">
</property> <string>Shift+E</string>
<property name="shortcut"> </property>
<string>Shift+D</string> </action>
</property> <action name="action_Disable_In_game">
</action> <property name="text">
</widget> <string>Hi&amp;de In-game</string>
<resources/> </property>
<connections> <property name="shortcut">
<connection> <string>Shift+D</string>
<sender>cmdClose</sender> </property>
<signal>clicked()</signal> </action>
<receiver>UserInterface</receiver> </widget>
<slot>close()</slot> <resources/>
<hints> <connections>
<hint type="sourcelabel"> <connection>
<x>572</x> <sender>cmdClose</sender>
<y>476</y> <signal>clicked()</signal>
</hint> <receiver>UserInterface</receiver>
<hint type="destinationlabel"> <slot>close()</slot>
<x>312</x> <hints>
<y>249</y> <hint type="sourcelabel">
</hint> <x>572</x>
</hints> <y>476</y>
</connection> </hint>
</connections> <hint type="destinationlabel">
</ui> <x>312</x>
<y>249</y>
</hint>
</hints>
</connection>
</connections>
</ui>

262
config.h
View File

@ -1,101 +1,161 @@
/***************************************************************************** /*****************************************************************************
* gta5view Grand Theft Auto V Profile Viewer * gta5view Grand Theft Auto V Profile Viewer
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef CONFIG_H #ifndef CONFIG_H
#define CONFIG_H #define CONFIG_H
#include <QString> #include <QtGlobal>
#include <QString>
#ifndef GTA5SYNC_APPVENDOR
#define GTA5SYNC_APPVENDOR "Syping" #ifndef GTA5SYNC_APPVENDOR
#endif #define GTA5SYNC_APPVENDOR "Syping"
#endif
#ifndef GTA5SYNC_APPVENDORLINK
#define GTA5SYNC_APPVENDORLINK "https://github.com/Syping/" #ifndef GTA5SYNC_APPVENDORLINK
#endif #define GTA5SYNC_APPVENDORLINK "https://github.com/Syping/"
#endif
#ifndef GTA5SYNC_DISABLED
#define GTA5SYNC_ENABLED #ifndef GTA5SYNC_DISABLED
#endif #define GTA5SYNC_ENABLED
#endif
#ifndef GTA5SYNC_APPSTR
#ifdef GTA5SYNC_ENABLED #ifndef GTA5SYNC_APPSTR
#define GTA5SYNC_APPSTR "gta5sync" #ifdef GTA5SYNC_ENABLED
#else #define GTA5SYNC_APPSTR "gta5sync"
#define GTA5SYNC_APPSTR "gta5view" #else
#endif #define GTA5SYNC_APPSTR "gta5view"
#endif #endif
#endif
#ifndef GTA5SYNC_APPDES
#define GTA5SYNC_APPDES "INSERT YOUR APPLICATION DESCRIPTION HERE" #ifndef GTA5SYNC_APPDES
#endif #define GTA5SYNC_APPDES "INSERT YOUR APPLICATION DESCRIPTION HERE"
#endif
#ifndef GTA5SYNC_COPYRIGHT
#define GTA5SYNC_COPYRIGHT "2016-2017" #ifndef GTA5SYNC_COPYRIGHT
#endif #define GTA5SYNC_COPYRIGHT "2016-2017"
#endif
#ifndef GTA5SYNC_APPVER
#ifndef GTA5SYNC_DAILYB #ifndef GTA5SYNC_APPVER
#define GTA5SYNC_APPVER "1.4.4" #ifndef GTA5SYNC_DAILYB
#else #define GTA5SYNC_APPVER "1.5.0-dev1"
#define GTA5SYNC_APPVER QString("%1").arg(GTA5SYNC_DAILYB) #else
#endif #define GTA5SYNC_APPVER GTA5SYNC_DAILYB
#endif #endif
#endif
#ifndef GTA5SYNC_BUILDTYPE
#define GTA5SYNC_BUILDTYPE "Custom" #ifdef GTA5SYNC_BUILDTYPE_REL
#endif #ifndef GTA5SYNC_BUILDTYPE
#define GTA5SYNC_BUILDTYPE QT_TRANSLATE_NOOP("AboutDialog", "Release")
#ifndef GTA5SYNC_SHARE #endif
#define GTA5SYNC_SHARE "$RUNDIR" #endif
#endif
#ifdef GTA5SYNC_BUILDTYPE_RC
#ifndef GTA5SYNC_LANG #ifndef GTA5SYNC_BUILDTYPE
#define GTA5SYNC_LANG "$SHAREDIR$SEPARATORlang" #define GTA5SYNC_BUILDTYPE QT_TRANSLATE_NOOP("AboutDialog", "Release Candidate")
#endif #endif
#endif
#ifndef GTA5SYNC_PLUG
#define GTA5SYNC_PLUG "$RUNDIR$SEPARATORplugins" #ifdef GTA5SYNC_BUILDTYPE_DAILY
#endif #ifndef GTA5SYNC_BUILDTYPE
#define GTA5SYNC_BUILDTYPE QT_TRANSLATE_NOOP("AboutDialog", "Daily Build")
#ifdef GTA5SYNC_WINRT #endif
#undef GTA5SYNC_WIN #endif
#endif
#ifdef GTA5SYNC_BUILDTYPE_DEV
#ifndef GTA5SYNC_COMPILER #ifndef GTA5SYNC_BUILDTYPE
#ifdef __clang__ #define GTA5SYNC_BUILDTYPE QT_TRANSLATE_NOOP("AboutDialog", "Developer")
#define GTA5SYNC_COMPILER QString("Clang %1.%2.%3").arg(QString::number(__clang_major__), QString::number(__clang_minor__), QString::number(__clang_patchlevel__)) #endif
#elif defined(__GNUC__) #endif
#define GTA5SYNC_COMPILER QString("GCC %1.%2.%3").arg(QString::number(__GNUC__), QString::number(__GNUC_MINOR__), QString::number(__GNUC_PATCHLEVEL__))
#elif defined(__GNUG__) #ifdef GTA5SYNC_BUILDTYPE_BETA
#define GTA5SYNC_COMPILER QString("GCC %1.%2.%3").arg(QString::number(__GNUG__), QString::number(__GNUC_MINOR__), QString::number(__GNUC_PATCHLEVEL__)) #ifndef GTA5SYNC_BUILDTYPE
#elif defined(_MSC_VER) #define GTA5SYNC_BUILDTYPE QT_TRANSLATE_NOOP("AboutDialog", "Beta")
#define GTA5SYNC_COMPILER QString("MSVC %1").arg(QString::number(_MSC_VER).insert(2, ".")) #endif
#else #endif
#define GTA5SYNC_COMPILER QString("Unknown Compiler")
#endif #ifdef GTA5SYNC_BUILDTYPE_ALPHA
#endif #ifndef GTA5SYNC_BUILDTYPE
#define GTA5SYNC_BUILDTYPE QT_TRANSLATE_NOOP("AboutDialog", "Alpha")
#ifndef GTA5SYNC_BUILDDATETIME #endif
#define GTA5SYNC_BUILDDATETIME QString("%1, %2").arg(__DATE__, __TIME__); #endif
#endif
#ifdef GTA5SYNC_DAILYB
#ifndef GTA5SYNC_BUILDSTRING #ifndef GTA5SYNC_BUILDTYPE
#define GTA5SYNC_BUILDSTRING QString("%1, %2").arg(QT_VERSION_STR, GTA5SYNC_COMPILER); #define GTA5SYNC_BUILDTYPE "Daily Build"
#endif #endif
#endif
#endif // CONFIG_H
#ifndef GTA5SYNC_BUILDTYPE
#define GTA5SYNC_BUILDTYPE "Custom"
#endif
#ifdef GTA5SYNC_QCONF
#ifndef GTA5SYNC_SHARE
#define GTA5SYNC_SHARE "RUNDIR:SEPARATOR:..SEPARATOR:share"
#endif
#ifndef GTA5SYNC_LANG
#define GTA5SYNC_LANG "QCONFLANG:"
#endif
#ifndef GTA5SYNC_PLUG
#define GTA5SYNC_PLUG "QCONFPLUG:"
#endif
#ifdef GTA5SYNC_QCONF_IN
#ifndef GTA5SYNC_INLANG
#define GTA5SYNC_INLANG ":/tr"
#endif
#endif
#endif
#ifndef GTA5SYNC_SHARE
#define GTA5SYNC_SHARE "RUNDIR:"
#endif
#ifndef GTA5SYNC_LANG
#define GTA5SYNC_LANG "SHAREDDIR:SEPARATOR:lang"
#endif
#ifndef GTA5SYNC_PLUG
#define GTA5SYNC_PLUG "RUNDIR:SEPARATOR:plugins"
#endif
#ifdef GTA5SYNC_WINRT
#undef GTA5SYNC_WIN
#endif
#ifndef GTA5SYNC_COMPILER
#ifdef __clang__
#define GTA5SYNC_COMPILER QString("Clang %1.%2.%3").arg(QString::number(__clang_major__), QString::number(__clang_minor__), QString::number(__clang_patchlevel__))
#elif defined(__GNUC__)
#define GTA5SYNC_COMPILER QString("GCC %1.%2.%3").arg(QString::number(__GNUC__), QString::number(__GNUC_MINOR__), QString::number(__GNUC_PATCHLEVEL__))
#elif defined(__GNUG__)
#define GTA5SYNC_COMPILER QString("GCC %1.%2.%3").arg(QString::number(__GNUG__), QString::number(__GNUC_MINOR__), QString::number(__GNUC_PATCHLEVEL__))
#elif defined(_MSC_VER)
#define GTA5SYNC_COMPILER QString("MSVC %1").arg(QString::number(_MSC_VER).insert(2, "."))
#else
#define GTA5SYNC_COMPILER QString("Unknown Compiler")
#endif
#endif
#ifndef GTA5SYNC_BUILDDATETIME
#define GTA5SYNC_BUILDDATETIME QString("%1, %2").arg(__DATE__, __TIME__)
#endif
#ifndef GTA5SYNC_BUILDSTRING
#define GTA5SYNC_BUILDSTRING QString("%1, %2").arg(QT_VERSION_STR, GTA5SYNC_COMPILER)
#endif
#endif // CONFIG_H

View File

@ -1,172 +1,196 @@
#/***************************************************************************** #/*****************************************************************************
#* gta5view Grand Theft Auto V Profile Viewer #* gta5view Grand Theft Auto V Profile Viewer
#* Copyright (C) 2015-2017 Syping #* Copyright (C) 2015-2017 Syping
#* #*
#* This program is free software: you can redistribute it and/or modify #* 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 #* it under the terms of the GNU General Public License as published by
#* the Free Software Foundation, either version 3 of the License, or #* the Free Software Foundation, either version 3 of the License, or
#* (at your option) any later version. #* (at your option) any later version.
#* #*
#* This program is distributed in the hope that it will be useful, #* This program is distributed in the hope that it will be useful,
#* but WITHOUT ANY WARRANTY; without even the implied warranty of #* but WITHOUT ANY WARRANTY; without even the implied warranty of
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#* GNU General Public License for more details. #* GNU General Public License for more details.
#* #*
#* You should have received a copy of the GNU General Public License #* You should have received a copy of the GNU General Public License
#* along with this program. If not, see <http://www.gnu.org/licenses/>. #* along with this program. If not, see <http://www.gnu.org/licenses/>.
#*****************************************************************************/ #*****************************************************************************/
QT += core gui network QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 4): greaterThan(QT_MINOR_VERSION, 1): win32: QT += winextras greaterThan(QT_MAJOR_VERSION, 4): greaterThan(QT_MINOR_VERSION, 1): win32: QT += winextras
DEFINES += GTA5SYNC_DISABLED DEFINES += GTA5SYNC_DISABLED
DEPLOYMENT.display_name = gta5view DEPLOYMENT.display_name = gta5view
TARGET = gta5view TARGET = gta5view
TEMPLATE = app TEMPLATE = app
SOURCES += main.cpp \ DEFINES += GTA5SYNC_CSDF # Not assisting at proper usage of SnapmaticPicture class
AboutDialog.cpp \ HEADERS += config.h
AppEnv.cpp \ PRECOMPILED_HEADER += config.h
CrewDatabase.cpp \
DatabaseThread.cpp \ SOURCES += main.cpp \
ExportDialog.cpp \ AboutDialog.cpp \
ExportThread.cpp \ AppEnv.cpp \
GlobalString.cpp \ CrewDatabase.cpp \
IconLoader.cpp \ DatabaseThread.cpp \
ImportDialog.cpp \ ExportDialog.cpp \
OptionsDialog.cpp \ ExportThread.cpp \
PictureDialog.cpp \ GlobalString.cpp \
PictureExport.cpp \ IconLoader.cpp \
PictureWidget.cpp \ ImportDialog.cpp \
ProfileDatabase.cpp \ MapPreviewDialog.cpp \
ProfileInterface.cpp \ OptionsDialog.cpp \
ProfileLoader.cpp \ PictureDialog.cpp \
ProfileWidget.cpp \ PictureExport.cpp \
SavegameCopy.cpp \ PictureWidget.cpp \
SavegameData.cpp \ ProfileDatabase.cpp \
SavegameDialog.cpp \ ProfileInterface.cpp \
SavegameWidget.cpp \ ProfileLoader.cpp \
SidebarGenerator.cpp \ ProfileWidget.cpp \
SnapmaticEditor.cpp \ SavegameCopy.cpp \
SnapmaticPicture.cpp \ SavegameData.cpp \
SnapmaticWidget.cpp \ SavegameDialog.cpp \
StandardPaths.cpp \ SavegameWidget.cpp \
StringParser.cpp \ SidebarGenerator.cpp \
UserInterface.cpp \ SnapmaticEditor.cpp \
uimod/UiModLabel.cpp \ SnapmaticPicture.cpp \
uimod/UiModWidget.cpp SnapmaticWidget.cpp \
StandardPaths.cpp \
HEADERS += \ StringParser.cpp \
AboutDialog.h \ TranslationClass.cpp \
AppEnv.h \ UserInterface.cpp \
CrewDatabase.h \ uimod/UiModLabel.cpp \
DatabaseThread.h \ uimod/UiModWidget.cpp
ExportDialog.h \
ExportThread.h \ HEADERS += \
GlobalString.h \ AboutDialog.h \
IconLoader.h \ AppEnv.h \
ImportDialog.h \ CrewDatabase.h \
OptionsDialog.h \ DatabaseThread.h \
PictureDialog.h \ ExportDialog.h \
PictureExport.h \ ExportThread.h \
PictureWidget.h \ GlobalString.h \
ProfileDatabase.h \ IconLoader.h \
ProfileInterface.h \ ImportDialog.h \
ProfileLoader.h \ MapPreviewDialog.h \
ProfileWidget.h \ OptionsDialog.h \
SavegameCopy.h \ PictureDialog.h \
SavegameData.h \ PictureExport.h \
SavegameDialog.h \ PictureWidget.h \
SavegameWidget.h \ ProfileDatabase.h \
SidebarGenerator.h \ ProfileInterface.h \
SnapmaticEditor.h \ ProfileLoader.h \
SnapmaticPicture.h \ ProfileWidget.h \
SnapmaticWidget.h \ SavegameCopy.h \
StandardPaths.h \ SavegameData.h \
StringParser.h \ SavegameDialog.h \
UserInterface.h \ SavegameWidget.h \
uimod/UiModLabel.h \ SidebarGenerator.h \
uimod/UiModWidget.h SnapmaticEditor.h \
SnapmaticPicture.h \
PRECOMPILED_HEADER += config.h SnapmaticWidget.h \
StandardPaths.h \
FORMS += \ StringParser.h \
AboutDialog.ui \ TranslationClass.h \
ExportDialog.ui \ UserInterface.h \
ImportDialog.ui \ uimod/UiModLabel.h \
OptionsDialog.ui \ uimod/UiModWidget.h
PictureDialog.ui \
ProfileInterface.ui \ FORMS += \
SavegameDialog.ui \ AboutDialog.ui \
SavegameWidget.ui \ ExportDialog.ui \
SnapmaticEditor.ui \ ImportDialog.ui \
SnapmaticWidget.ui \ MapPreviewDialog.ui \
UserInterface.ui OptionsDialog.ui \
PictureDialog.ui \
TRANSLATIONS += \ ProfileInterface.ui \
res/gta5sync_de.ts \ SavegameDialog.ui \
res/gta5sync_fr.ts \ SavegameWidget.ui \
res/gta5sync_ru.ts SnapmaticEditor.ui \
SnapmaticWidget.ui \
RESOURCES += \ UserInterface.ui
res/tr_g5p.qrc \
res/app.qrc TRANSLATIONS += \
res/gta5sync_en_US.ts \
DISTFILES += res/app.rc \ res/gta5sync_de.ts \
res/gta5sync.desktop \ res/gta5sync_fr.ts \
res/gta5sync_de.ts \ res/gta5sync_ru.ts \
res/gta5sync_fr.ts \ lang/gta5sync_no.ts
res/gta5sync_ru.ts \
res/gta5view.exe.manifest \ RESOURCES += \
res/gta5view.png \ res/tr_g5p.qrc \
lang/README.txt res/app.qrc
INCLUDEPATH += ./uimod DISTFILES += res/app.rc \
res/gta5view.desktop \
# WINDOWS ONLY res/gta5sync_de.ts \
res/gta5sync_fr.ts \
win32: DEFINES += GTA5SYNC_WIN res/gta5sync_ru.ts \
win32: RC_FILE += res/app.rc res/gta5view.exe.manifest \
win32: LIBS += -luser32 res/gta5view.png \
win32: CONFIG -= embed_manifest_exe lang/gta5sync_no.ts \
lang/README.txt
# MAC OS X ONLY
macx: ICON = res/5sync.icns INCLUDEPATH += ./uimod
# QT4 ONLY STUFF # WINDOWS ONLY
isEqual(QT_MAJOR_VERSION, 4): INCLUDEPATH += ./qjson4 win32: DEFINES += GTA5SYNC_WIN
isEqual(QT_MAJOR_VERSION, 4): HEADERS += qjson4/QJsonArray.h \ win32: RC_FILE += res/app.rc
qjson4/QJsonDocument.h \ win32: LIBS += -luser32
qjson4/QJsonObject.h \ win32: CONFIG -= embed_manifest_exe
qjson4/QJsonParseError.h \
qjson4/QJsonValue.h \ # MAC OS X ONLY
qjson4/QJsonValueRef.h \ macx: ICON = res/5sync.icns
qjson4/QJsonParser.h \
qjson4/QJsonRoot.h # QT4 ONLY STUFF
isEqual(QT_MAJOR_VERSION, 4): SOURCES += qjson4/QJsonArray.cpp \ isEqual(QT_MAJOR_VERSION, 4): INCLUDEPATH += ./qjson4
qjson4/QJsonDocument.cpp \ isEqual(QT_MAJOR_VERSION, 4): HEADERS += qjson4/QJsonArray.h \
qjson4/QJsonObject.cpp \ qjson4/QJsonDocument.h \
qjson4/QJsonParseError.cpp \ qjson4/QJsonObject.h \
qjson4/QJsonValue.cpp \ qjson4/QJsonParseError.h \
qjson4/QJsonValueRef.cpp \ qjson4/QJsonValue.h \
qjson4/QJsonParser.cpp qjson4/QJsonValueRef.h \
qjson4/QJsonParser.h \
isEqual(QT_MAJOR_VERSION, 4): RESOURCES += res/tr_qt4.qrc qjson4/QJsonRoot.h
# QT5 ONLY STUFF isEqual(QT_MAJOR_VERSION, 4): SOURCES += qjson4/QJsonArray.cpp \
qjson4/QJsonDocument.cpp \
isEqual(QT_MAJOR_VERSION, 5): RESOURCES += res/tr_qt5.qrc qjson4/QJsonObject.cpp \
qjson4/QJsonParseError.cpp \
# UNIX SYSTEM STUFF qjson4/QJsonValue.cpp \
qjson4/QJsonValueRef.cpp \
unix: !macx: appfiles.path = $$(INSTALL_PATH)/share/applications qjson4/QJsonParser.cpp
unix: !macx: appfiles.files = $$PWD/res/gta5view.desktop
unix: !macx: pixmaps.path = $$(INSTALL_PATH)/share/pixmaps isEqual(QT_MAJOR_VERSION, 4): RESOURCES += res/tr_qt4.qrc
unix: !macx: pixmaps.files = $$PWD/res/gta5view.png
unix: !macx: target.path = $$(INSTALL_PATH)/bin # QT5 ONLY STUFF
unix: !macx: INSTALLS += target pixmaps appfiles isEqual(QT_MAJOR_VERSION, 5): RESOURCES += res/tr_qt5.qrc
# PROJECT INSTALLATION
isEmpty(GTA5SYNC_PREFIX): GTA5SYNC_PREFIX = /usr/local
appfiles.path = $$GTA5SYNC_PREFIX/share/applications
appfiles.files = $$PWD/res/gta5view.desktop
pixmaps.path = $$GTA5SYNC_PREFIX/share/pixmaps
pixmaps.files = $$PWD/res/gta5view.png
target.path = $$GTA5SYNC_PREFIX/bin
INSTALLS += target pixmaps appfiles
# QCONF BASED BUILD STUFF
contains(DEFINES, GTA5SYNC_QCONF){
isEqual(QT_MAJOR_VERSION, 4): RESOURCES -= res/tr_qt4.qrc
isEqual(QT_MAJOR_VERSION, 5): RESOURCES -= res/tr_qt5.qrc
!contains(DEFINES, GTA5SYNC_QCONF_IN){
RESOURCES -= res/tr_g5p.qrc
langfiles.path = $$GTA5SYNC_PREFIX/share/gta5view/translations
langfiles.files = $$PWD/res/gta5sync_en_US.qm $$PWD/res/gta5sync_de.qm $$PWD/res/gta5sync_fr.qm $$PWD/res/gta5sync_ru.qm $$PWD/res/qtbase_en_GB.qm
INSTALLS += langfiles
}
}

BIN
lang/gta5sync_no.qm Normal file

Binary file not shown.

1619
lang/gta5sync_no.ts Normal file

File diff suppressed because it is too large Load Diff

696
main.cpp
View File

@ -1,493 +1,203 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping * Copyright (C) 2016-2017 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "SnapmaticPicture.h" #include "TranslationClass.h"
#include "ProfileDatabase.h" #include "SnapmaticPicture.h"
#include "DatabaseThread.h" #include "ProfileDatabase.h"
#include "SavegameDialog.h" #include "DatabaseThread.h"
#include "PictureDialog.h" #include "SavegameDialog.h"
#include "UserInterface.h" #include "PictureDialog.h"
#include "CrewDatabase.h" #include "UserInterface.h"
#include "SavegameData.h" #include "CrewDatabase.h"
#include "IconLoader.h" #include "SavegameData.h"
#include "AppEnv.h" #include "IconLoader.h"
#include "config.h" #include "AppEnv.h"
#include <QDesktopWidget> #include "config.h"
#include <QApplication> #include <QStringBuilder>
#include <QStringList> #include <QApplication>
#include <QTranslator> #include <QStringList>
#include <QMessageBox> #include <QTranslator>
#include <QFileInfo> #include <QFileInfo>
#include <QSysInfo> #include <QSysInfo>
#include <QRawFont> #include <QObject>
#include <QObject> #include <QString>
#include <QString> #include <QDebug>
#include <QDebug> #include <QFont>
#include <QFont> #include <QFile>
#include <QFile>
#include <QDir> #ifdef GTA5SYNC_WIN
#include "windows.h"
#ifdef GTA5SYNC_WIN #include <iostream>
#include "windows.h" #endif
#include <iostream>
#endif int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) QApplication a(argc, argv);
{ a.setApplicationName(GTA5SYNC_APPSTR);
QApplication a(argc, argv); a.setApplicationVersion(GTA5SYNC_APPVER);
a.setApplicationName(GTA5SYNC_APPSTR);
a.setApplicationVersion(GTA5SYNC_APPVER); #ifdef GTA5SYNC_WIN
#if QT_VERSION >= 0x050400
#ifdef GTA5SYNC_WIN if (QSysInfo::windowsVersion() >= 0x0080)
#if QT_VERSION >= 0x050400 {
if (QSysInfo::windowsVersion() >= 0x0080) // Get Windows Font
{ NONCLIENTMETRICS ncm;
// Get Windows Font ncm.cbSize = sizeof(ncm);
NONCLIENTMETRICS ncm; SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0);
ncm.cbSize = sizeof(ncm); LOGFONTW uiFont = ncm.lfMessageFont;
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0); QString uiFontStr(QString::fromStdWString(std::wstring(uiFont.lfFaceName)));
LOGFONTW uiFont = ncm.lfMessageFont;
QString uiFontStr(QString::fromStdWString(std::wstring(uiFont.lfFaceName))); #ifdef GTA5SYNC_DEBUG
qDebug() << QApplication::tr("Font") << QApplication::tr("Selected Font: %1").arg(uiFontStr);
#ifdef GTA5SYNC_DEBUG #endif
QMessageBox::information(a.desktop(), QApplication::tr("Font"), QApplication::tr("Selected Font: %1").arg(uiFontStr));
#endif // Set Application Font
QFont appFont(uiFontStr, 9);
// Set Application Font a.setFont(appFont);
QFont appFont(uiFontStr, 9); }
a.setFont(appFont); #endif
} #endif
#endif
#endif QString pluginsDir = AppEnv::getPluginsFolder();
if (QFileInfo(pluginsDir).exists())
QString pluginsDir = AppEnv::getPluginsFolder(); {
if (QFileInfo(pluginsDir).exists()) a.addLibraryPath(pluginsDir);
{ }
a.addLibraryPath(pluginsDir);
} TCInstance->initUserLanguage();
TCInstance->loadTranslation(&a);
// Loading translation settings
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); QStringList applicationArgs = a.arguments();
settings.beginGroup("Interface"); QString selectedAction;
QString language = settings.value("Language","System").toString(); QString arg1;
settings.endGroup(); applicationArgs.removeAt(0);
// Start external translate loading foreach(QString currentArg, applicationArgs)
QString langpath = AppEnv::getLangFolder(); {
bool trsf = false; QString reworkedArg;
bool svlp = false; if (currentArg.left(9) == "-showpic=" && selectedAction == "")
QTranslator EappTranslator; {
if (language == "System" || language.trimmed() == "") reworkedArg = currentArg.remove(0,9);
{ arg1 = reworkedArg;
QString languageName = QLocale::system().name(); selectedAction = "showpic";
QStringList langList = languageName.split("_"); }
if (langList.length() >= 1) else if (currentArg.left(9) == "-showsgd=" && selectedAction == "")
{ {
if (QFile::exists(langpath + QDir::separator() + "gta5sync_" + langList.at(0) + ".qm")) reworkedArg = currentArg.remove(0,9);
{ arg1 = reworkedArg;
EappTranslator.load(langpath + QDir::separator() + "/gta5sync_" + langList.at(0) + ".qm"); selectedAction = "showsgd";
QLocale::setDefault(QLocale::system()); }
} else if (selectedAction == "")
} {
} QFile argumentFile(currentArg);
else QFileInfo argumentFileInfo(argumentFile);
{ if (argumentFile.exists())
QString languageName = language; {
QStringList langList = languageName.split("_"); QString argumentFileName = argumentFileInfo.fileName();
if (langList.length() >= 1) QString argumentFileType = argumentFileName.left(4);
{ QString argumentFileExt = argumentFileName.right(4);
if (QFile::exists(langpath + QDir::separator() + "gta5sync_" + langList.at(0) + ".qm"))
{ if (argumentFileType == "PGTA" || argumentFileExt == ".g5e")
if (!EappTranslator.load(langpath + QDir::separator() + "gta5sync_" + langList.at(0) + ".qm")) {
{ arg1 = currentArg;
if (langList.at(0) != "en") selectedAction = "showpic";
{ }
trsf = true; else if (argumentFileType == "SGTA")
} {
} arg1 = currentArg;
else selectedAction = "showsgd";
{ }
QLocale::setDefault(QLocale(langList.at(0))); else if (argumentFileType == "MISR")
svlp = true; {
} arg1 = currentArg;
} selectedAction = "showsgd";
else }
{ }
if (langList.at(0) != "en") }
{ }
trsf = true;
} if (selectedAction == "showpic")
} {
} CrewDatabase crewDB;
} ProfileDatabase profileDB;
if (trsf) DatabaseThread threadDB(&crewDB);
{ PictureDialog picDialog(true, &profileDB, &crewDB);
QString languageName = QLocale::system().name(); SnapmaticPicture picture;
QStringList langList = languageName.split("_");
if (langList.length() >= 1) bool readOk = picture.readingPictureFromFile(arg1);
{ picDialog.setWindowIcon(IconLoader::loadingAppIcon());
if (QFile::exists(langpath + QDir::separator() + "gta5sync_" + langList.at(0) + ".qm")) picDialog.setSnapmaticPicture(&picture, readOk);
{
EappTranslator.load(langpath + QDir::separator() + "gta5sync_" + langList.at(0) + ".qm"); int crewID = picture.getSnapmaticProperties().crewID;
QLocale::setDefault(QLocale(langList.at(0))); if (crewID != 0) { crewDB.addCrew(crewID); }
} if (!readOk) { return 1; }
}
} QEventLoop threadLoop;
a.installTranslator(&EappTranslator); QObject::connect(&threadDB, SIGNAL(crewNameFound(int, QString)), &crewDB, SLOT(setCrewName(int, QString)));
#if QT_VERSION >= 0x050000 QObject::connect(&threadDB, SIGNAL(crewNameUpdated()), &picDialog, SLOT(crewNameUpdated()));
QTranslator EqtTranslator1; QObject::connect(&threadDB, SIGNAL(playerNameFound(int, QString)), &profileDB, SLOT(setPlayerName(int, QString)));
if (language == "System" || language.trimmed() == "") QObject::connect(&threadDB, SIGNAL(playerNameUpdated()), &picDialog, SLOT(playerNameUpdated()));
{ QObject::connect(&threadDB, SIGNAL(finished()), &threadLoop, SLOT(quit()));
QString languageName = QLocale::system().name(); QObject::connect(&picDialog, SIGNAL(endDatabaseThread()), &threadDB, SLOT(doEndThread()));
QStringList langList = languageName.split("_"); threadDB.start();
if (langList.length() >= 1)
{ picDialog.show();
if (QFile::exists(langpath + QDir::separator() + "qtbase_" + langList.at(0) + ".qm"))
{ threadLoop.exec();
EqtTranslator1.load(langpath + QDir::separator() + "qtbase_" + langList.at(0) + ".qm");
} return 0;
} }
} else if (selectedAction == "showsgd")
else {
{ SavegameDialog savegameDialog;
QString languageName = language; SavegameData savegame;
QStringList langList = languageName.split("_");
if (langList.length() >= 1) bool readOk = savegame.readingSavegameFromFile(arg1);
{ savegameDialog.setWindowIcon(IconLoader::loadingAppIcon());
if (QFile::exists(langpath + QDir::separator() + "qtbase_" + langList.at(0) + ".qm")) savegameDialog.setSavegameData(&savegame, arg1, readOk);
{
EqtTranslator1.load(langpath + QDir::separator() + "qtbase_" + langList.at(0) + ".qm"); if (!readOk) { return 1; }
}
} savegameDialog.show();
}
if (trsf) return a.exec();
{ }
QString languageName = QLocale::system().name();
QStringList langList = languageName.split("_"); CrewDatabase crewDB;
if (langList.length() >= 1) ProfileDatabase profileDB;
{ DatabaseThread threadDB(&crewDB);
if (QFile::exists(langpath + QDir::separator() + "qtbase_" + langList.at(0) + ".qm"))
{ QEventLoop threadLoop;
EqtTranslator1.load(langpath + QDir::separator() + "qtbase_" + langList.at(0) + ".qm"); QObject::connect(&threadDB, SIGNAL(crewNameFound(int,QString)), &crewDB, SLOT(setCrewName(int, QString)));
} QObject::connect(&threadDB, SIGNAL(playerNameFound(int, QString)), &profileDB, SLOT(setPlayerName(int, QString)));
} QObject::connect(&threadDB, SIGNAL(finished()), &threadLoop, SLOT(quit()));
} threadDB.start();
a.installTranslator(&EqtTranslator1);
#else UserInterface uiWindow(&profileDB, &crewDB, &threadDB);
QTranslator EqtTranslator; uiWindow.setWindowIcon(IconLoader::loadingAppIcon());
if (language == "System" || language.trimmed() == "") uiWindow.setupDirEnv();
{ #ifdef Q_OS_ANDROID
QString languageName = QLocale::system().name(); uiWindow.showMaximized();
QStringList langList = languageName.split("_"); #else
if (langList.length() >= 1) uiWindow.show();
{ #endif
if (QFile::exists(langpath + QDir::separator() + "qt_" + langList.at(0) + ".qm"))
{ threadLoop.exec();
EqtTranslator.load(langpath + QDir::separator() + "qt_" + langList.at(0) + ".qm");
} return 0;
} }
}
else
{
QString languageName = language;
QStringList langList = languageName.split("_");
if (langList.length() >= 1)
{
if (QFile::exists(langpath + QDir::separator() + "qt_" + langList.at(0) + ".qm"))
{
EqtTranslator.load(langpath + QDir::separator() + "qt_" + langList.at(0) + ".qm");
}
}
}
if (trsf)
{
QString languageName = QLocale::system().name();
QStringList langList = languageName.split("_");
if (langList.length() >= 1)
{
if (QFile::exists(langpath + QDir::separator() + "qt_" + langList.at(0) + ".qm"))
{
EqtTranslator.load(langpath + QDir::separator() + "qt_" + langList.at(0) + ".qm");
}
}
}
a.installTranslator(&EqtTranslator);
#endif
// End external translate loading
// Start internal translate loading
QTranslator appTranslator;
trsf = false;
if (language == "System" || language.trimmed() == "")
{
QString languageName = QLocale::system().name();
QStringList langList = languageName.split("_");
if (langList.length() >= 1)
{
if (QFile::exists(":/tr/gta5sync_" + langList.at(0) + ".qm"))
{
if (!appTranslator.load(":/tr/gta5sync_" + langList.at(0) + ".qm"))
{
if (langList.at(0) != "en")
{
if (svlp) { trsf = true; }
}
}
else
{
QLocale::setDefault(QLocale(langList.at(0)));
}
}
else
{
if (langList.at(0) != "en")
{
if (svlp) { trsf = true; }
}
}
}
}
else if (language == "en" || language == "English")
{
QLocale::setDefault(QLocale(QLocale::English, QLocale::AnyCountry));
}
else
{
QString languageName = language;
QStringList langList = languageName.split("_");
if (langList.length() >= 1)
{
if (QFile::exists(":/tr/gta5sync_" + langList.at(0) + ".qm"))
{
appTranslator.load(":/tr/gta5sync_" + langList.at(0) + ".qm");
QLocale::setDefault(QLocale(langList.at(0)));
}
}
}
if (trsf)
{
QString languageName = QLocale::system().name();
QStringList langList = languageName.split("_");
if (langList.length() >= 1)
{
if (QFile::exists(":/tr/gta5sync_" + langList.at(0) + ".qm"))
{
appTranslator.load(":/tr/gta5sync_" + langList.at(0) + ".qm");
QLocale::setDefault(QLocale(langList.at(0)));
}
}
}
a.installTranslator(&appTranslator);
#if QT_VERSION >= 0x050000
QTranslator qtTranslator1;
if (language == "System" || language.trimmed() == "")
{
QString languageName = QLocale::system().name();
QStringList langList = languageName.split("_");
if (langList.length() >= 1)
{
if (QFile::exists(":/tr/qtbase_" + langList.at(0) + ".qm"))
{
qtTranslator1.load(":/tr/qtbase_" + langList.at(0) + ".qm");
}
}
}
else
{
QString languageName = language;
QStringList langList = languageName.split("_");
if (langList.length() >= 1)
{
if (QFile::exists(":/tr/qtbase_" + langList.at(0) + ".qm"))
{
qtTranslator1.load(":/tr/qtbase_" + langList.at(0) + ".qm");
}
}
}
if (trsf)
{
QString languageName = QLocale::system().name();
QStringList langList = languageName.split("_");
if (langList.length() >= 1)
{
if (QFile::exists(":/tr/qtbase_" + langList.at(0) + ".qm"))
{
qtTranslator1.load(":/tr/qtbase_" + langList.at(0) + ".qm");
}
}
}
a.installTranslator(&qtTranslator1);
#else
QTranslator qtTranslator1;
if (language == "System" || language.trimmed() == "")
{
QString languageName = QLocale::system().name();
QStringList langList = languageName.split("_");
if (langList.length() >= 1)
{
if (QFile::exists(":/tr/qt_" + langList.at(0) + ".qm"))
{
qtTranslator1.load(":/tr/qt_" + langList.at(0) + ".qm");
}
}
}
else
{
QString languageName = language;
QStringList langList = languageName.split("_");
if (langList.length() >= 1)
{
if (QFile::exists(":/tr/qt_" + langList.at(0) + ".qm"))
{
qtTranslator1.load(":/tr/qt_" + langList.at(0) + ".qm");
}
}
}
if (trsf)
{
QString languageName = QLocale::system().name();
QStringList langList = languageName.split("_");
if (langList.length() >= 1)
{
if (QFile::exists(":/tr/qt_" + langList.at(0) + ".qm"))
{
qtTranslator1.load(":/tr/qt_" + langList.at(0) + ".qm");
}
}
}
a.installTranslator(&qtTranslator1);
#endif
// End internal translate loading
QStringList applicationArgs = a.arguments();
QString selectedAction;
QString arg1;
applicationArgs.removeAt(0);
foreach(QString currentArg, applicationArgs)
{
QString reworkedArg;
if (currentArg.left(9) == "-showpic=" && selectedAction == "")
{
reworkedArg = currentArg.remove(0,9);
arg1 = reworkedArg;
selectedAction = "showpic";
}
else if (currentArg.left(9) == "-showsgd=" && selectedAction == "")
{
reworkedArg = currentArg.remove(0,9);
arg1 = reworkedArg;
selectedAction = "showsgd";
}
else if (selectedAction == "")
{
QFile argumentFile(currentArg);
QFileInfo argumentFileInfo(argumentFile);
if (argumentFile.exists())
{
QString argumentFileName = argumentFileInfo.fileName();
QString argumentFileType = argumentFileName.left(4);
QString argumentFileExt = argumentFileName.right(4);
if (argumentFileType == "PGTA" || argumentFileExt == ".g5e")
{
arg1 = currentArg;
selectedAction = "showpic";
}
else if (argumentFileType == "SGTA")
{
arg1 = currentArg;
selectedAction = "showsgd";
}
else if (argumentFileType == "MISR")
{
arg1 = currentArg;
selectedAction = "showsgd";
}
}
}
}
if (selectedAction == "showpic")
{
CrewDatabase crewDB;
ProfileDatabase profileDB;
DatabaseThread threadDB(&crewDB);
PictureDialog picDialog(true, &profileDB, &crewDB);
SnapmaticPicture picture;
bool readOk = picture.readingPictureFromFile(arg1);
picDialog.setWindowIcon(IconLoader::loadingAppIcon());
picDialog.setSnapmaticPicture(&picture, readOk);
int crewID = picture.getSnapmaticProperties().crewID;
if (crewID != 0) { crewDB.addCrew(crewID); }
if (!readOk) { return 1; }
QEventLoop threadLoop;
QObject::connect(&threadDB, SIGNAL(playerNameFound(int, QString)), &profileDB, SLOT(setPlayerName(int, QString)));
QObject::connect(&threadDB, SIGNAL(playerNameUpdated()), &picDialog, SLOT(playerNameUpdated()));
QObject::connect(&threadDB, SIGNAL(finished()), &threadLoop, SLOT(quit()));
QObject::connect(&picDialog, SIGNAL(endDatabaseThread()), &threadDB, SLOT(doEndThread()));
threadDB.start();
picDialog.show();
threadLoop.exec();
return 0;
}
else if (selectedAction == "showsgd")
{
SavegameDialog savegameDialog;
SavegameData savegame;
bool readOk = savegame.readingSavegameFromFile(arg1);
savegameDialog.setWindowIcon(IconLoader::loadingAppIcon());
savegameDialog.setSavegameData(&savegame, arg1, readOk);
if (!readOk) { return 1; }
savegameDialog.show();
return a.exec();
}
CrewDatabase crewDB;
ProfileDatabase profileDB;
DatabaseThread threadDB(&crewDB);
QEventLoop threadLoop;
QObject::connect(&threadDB, SIGNAL(playerNameFound(int, QString)), &profileDB, SLOT(setPlayerName(int, QString)));
QObject::connect(&threadDB, SIGNAL(finished()), &threadLoop, SLOT(quit()));
threadDB.start();
UserInterface uiWindow(&profileDB, &crewDB, &threadDB);
uiWindow.setWindowIcon(IconLoader::loadingAppIcon());
uiWindow.setupDirEnv();
#ifdef Q_OS_ANDROID
uiWindow.showMaximized();
#else
uiWindow.show();
#endif
threadLoop.exec();
return 0;
}

View File

@ -1 +1 @@
#include "QJsonArray.h" #include "QJsonArray.h"

View File

@ -1,410 +1,410 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping * Copyright (C) 2016 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "QJsonArray.h" #include "QJsonArray.h"
#include "QJsonValueRef.h" #include "QJsonValueRef.h"
#include "QJsonValue.h" #include "QJsonValue.h"
#include <QtCore/QStringList> #include <QtCore/QStringList>
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonArray // Name: QJsonArray
// Desc: default constructor // Desc: default constructor
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray::QJsonArray() { QJsonArray::QJsonArray() {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonArray // Name: QJsonArray
// Desc: copy constructor // Desc: copy constructor
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray::QJsonArray(const QJsonArray &other) : values_(other.values_) { QJsonArray::QJsonArray(const QJsonArray &other) : values_(other.values_) {
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonArray // Name: QJsonArray
// Desc: Creates an array initialized from args initialization list. // Desc: Creates an array initialized from args initialization list.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray::QJsonArray(std::initializer_list<QJsonValue> args) { QJsonArray::QJsonArray(std::initializer_list<QJsonValue> args) {
for(const QJsonValue &arg : args) { for(const QJsonValue &arg : args) {
values_.append(arg); values_.append(arg);
} }
} }
#endif #endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: ~QJsonArray // Name: ~QJsonArray
// Desc: destructor // Desc: destructor
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray::~QJsonArray() { QJsonArray::~QJsonArray() {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator= // Name: operator=
// Desc: assignment operator // Desc: assignment operator
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray &QJsonArray::operator=(const QJsonArray &other) { QJsonArray &QJsonArray::operator=(const QJsonArray &other) {
QJsonArray(other).swap(*this); QJsonArray(other).swap(*this);
return *this; return *this;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator+= // Name: operator+=
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray &QJsonArray::operator+=(const QJsonValue &value) { QJsonArray &QJsonArray::operator+=(const QJsonValue &value) {
values_.append(value); values_.append(value);
return *this; return *this;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator<< // Name: operator<<
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray &QJsonArray::operator<<(const QJsonValue &value) { QJsonArray &QJsonArray::operator<<(const QJsonValue &value) {
values_.append(value); values_.append(value);
return *this; return *this;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator+ // Name: operator+
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray QJsonArray::operator+(const QJsonValue &value) const { QJsonArray QJsonArray::operator+(const QJsonValue &value) const {
QJsonArray arr(*this); QJsonArray arr(*this);
arr.append(value); arr.append(value);
return arr; return arr;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator!= // Name: operator!=
// Desc: returns true if the compared array IS NOT equal to this // Desc: returns true if the compared array IS NOT equal to this
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonArray::operator!=(const QJsonArray &other) const { bool QJsonArray::operator!=(const QJsonArray &other) const {
return values_ != other.values_; return values_ != other.values_;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator== // Name: operator==
// Desc: returns true if the compared array IS equal to this // Desc: returns true if the compared array IS equal to this
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonArray::operator==(const QJsonArray &other) const { bool QJsonArray::operator==(const QJsonArray &other) const {
return values_ == other.values_; return values_ == other.values_;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: begin // Name: begin
// Desc: returns an iterator to the first contained element // Desc: returns an iterator to the first contained element
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray::const_iterator QJsonArray::begin() const { QJsonArray::const_iterator QJsonArray::begin() const {
return values_.begin(); return values_.begin();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: end // Name: end
// Desc: returns an iterator to one past the last contained element // Desc: returns an iterator to one past the last contained element
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray::const_iterator QJsonArray::end() const { QJsonArray::const_iterator QJsonArray::end() const {
return values_.end(); return values_.end();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: begin // Name: begin
// Desc: returns an iterator to the first contained element // Desc: returns an iterator to the first contained element
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray::iterator QJsonArray::begin() { QJsonArray::iterator QJsonArray::begin() {
return values_.begin(); return values_.begin();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: end // Name: end
// Desc: returns an iterator to one past the last contained element // Desc: returns an iterator to one past the last contained element
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray::iterator QJsonArray::end() { QJsonArray::iterator QJsonArray::end() {
return values_.end(); return values_.end();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: constBegin // Name: constBegin
// Desc: returns an iterator to the first contained element // Desc: returns an iterator to the first contained element
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray::const_iterator QJsonArray::constBegin() const { QJsonArray::const_iterator QJsonArray::constBegin() const {
return begin(); return begin();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: constEnd // Name: constEnd
// Desc: returns an iterator to one past the last contained element // Desc: returns an iterator to one past the last contained element
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray::const_iterator QJsonArray::constEnd() const { QJsonArray::const_iterator QJsonArray::constEnd() const {
return end(); return end();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: first // Name: first
// Desc: returns the first element by value // Desc: returns the first element by value
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue QJsonArray::first() const { QJsonValue QJsonArray::first() const {
Q_ASSERT(!empty()); Q_ASSERT(!empty());
return values_.first(); return values_.first();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: last // Name: last
// Desc: returns the last element by value // Desc: returns the last element by value
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue QJsonArray::last() const { QJsonValue QJsonArray::last() const {
Q_ASSERT(!empty()); Q_ASSERT(!empty());
return values_.last(); return values_.last();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator[] // Name: operator[]
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValueRef QJsonArray::operator[](int i) { QJsonValueRef QJsonArray::operator[](int i) {
return QJsonValueRef(this, i); return QJsonValueRef(this, i);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator[] // Name: operator[]
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue QJsonArray::operator[](int i) const { QJsonValue QJsonArray::operator[](int i) const {
return values_[i]; return values_[i];
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: at // Name: at
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue QJsonArray::at(int i) const { QJsonValue QJsonArray::at(int i) const {
return values_.at(i); return values_.at(i);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: size // Name: size
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int QJsonArray::size() const { int QJsonArray::size() const {
return values_.size(); return values_.size();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: count // Name: count
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int QJsonArray::count() const { int QJsonArray::count() const {
return size(); return size();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: empty // Name: empty
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonArray::empty() const { bool QJsonArray::empty() const {
return values_.empty(); return values_.empty();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isEmpty // Name: isEmpty
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonArray::isEmpty() const { bool QJsonArray::isEmpty() const {
return empty(); return empty();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: pop_back // Name: pop_back
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonArray::pop_back() { void QJsonArray::pop_back() {
values_.pop_back(); values_.pop_back();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: pop_front // Name: pop_front
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonArray::pop_front() { void QJsonArray::pop_front() {
values_.pop_front(); values_.pop_front();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: push_back // Name: push_back
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonArray::push_back(const QJsonValue &value) { void QJsonArray::push_back(const QJsonValue &value) {
values_.push_back(value); values_.push_back(value);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: push_front // Name: push_front
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonArray::push_front(const QJsonValue &value) { void QJsonArray::push_front(const QJsonValue &value) {
values_.push_front(value); values_.push_front(value);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonArray::append(const QJsonValue &value) { void QJsonArray::append(const QJsonValue &value) {
values_.append(value); values_.append(value);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonArray::contains(const QJsonValue &value) const { bool QJsonArray::contains(const QJsonValue &value) const {
return values_.contains(value); return values_.contains(value);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray::iterator QJsonArray::erase(iterator it) { QJsonArray::iterator QJsonArray::erase(iterator it) {
return values_.erase(it); return values_.erase(it);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonArray::insert(int i, const QJsonValue &value) { void QJsonArray::insert(int i, const QJsonValue &value) {
values_.insert(i, value); values_.insert(i, value);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray::iterator QJsonArray::insert(iterator before, const QJsonValue &value) { QJsonArray::iterator QJsonArray::insert(iterator before, const QJsonValue &value) {
return values_.insert(before, value); return values_.insert(before, value);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonArray::prepend(const QJsonValue &value) { void QJsonArray::prepend(const QJsonValue &value) {
values_.prepend(value); values_.prepend(value);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonArray::removeAt(int i) { void QJsonArray::removeAt(int i) {
values_.removeAt(i); values_.removeAt(i);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonArray::removeFirst() { void QJsonArray::removeFirst() {
values_.removeFirst(); values_.removeFirst();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonArray::removeLast() { void QJsonArray::removeLast() {
values_.removeLast(); values_.removeLast();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonArray::replace(int i, const QJsonValue &value) { void QJsonArray::replace(int i, const QJsonValue &value) {
values_.replace(i, value); values_.replace(i, value);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue QJsonArray::takeAt(int i) { QJsonValue QJsonArray::takeAt(int i) {
return values_.takeAt(i); return values_.takeAt(i);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toVariantList // Name: toVariantList
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QVariantList QJsonArray::toVariantList() const { QVariantList QJsonArray::toVariantList() const {
QVariantList a; QVariantList a;
Q_FOREACH(const QJsonValue &v, *this) { Q_FOREACH(const QJsonValue &v, *this) {
a.push_back(v.toVariant()); a.push_back(v.toVariant());
} }
return a; return a;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray QJsonArray::fromStringList(const QStringList &list) { QJsonArray QJsonArray::fromStringList(const QStringList &list) {
QJsonArray a; QJsonArray a;
Q_FOREACH(const QString &s, list) { Q_FOREACH(const QString &s, list) {
a.push_back(QJsonValue(s)); a.push_back(QJsonValue(s));
} }
return a; return a;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray QJsonArray::fromVariantList(const QVariantList &list) { QJsonArray QJsonArray::fromVariantList(const QVariantList &list) {
QJsonArray a; QJsonArray a;
Q_FOREACH(const QVariant &v, list) { Q_FOREACH(const QVariant &v, list) {
a.push_back(QJsonValue::fromVariant(v)); a.push_back(QJsonValue::fromVariant(v));
} }
return a; return a;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonRoot *QJsonArray::clone() const { QJsonRoot *QJsonArray::clone() const {
return new QJsonArray(*this); return new QJsonArray(*this);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
const QJsonObject *QJsonArray::toObject() const { const QJsonObject *QJsonArray::toObject() const {
return 0; return 0;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject *QJsonArray::toObject() { QJsonObject *QJsonArray::toObject() {
return 0; return 0;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray *QJsonArray::toArray() { QJsonArray *QJsonArray::toArray() {
return this; return this;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
const QJsonArray *QJsonArray::toArray() const { const QJsonArray *QJsonArray::toArray() const {
return this; return this;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonArray::swap(QJsonArray &other) { void QJsonArray::swap(QJsonArray &other) {
qSwap(values_, other.values_); qSwap(values_, other.values_);
} }
#endif #endif

View File

@ -1,139 +1,139 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping * Copyright (C) 2016 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef QJSON_ARRAY_H_ #ifndef QJSON_ARRAY_H_
#define QJSON_ARRAY_H_ #define QJSON_ARRAY_H_
#include <QtCore/QtGlobal> #include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
#include <QtCore/QJsonArray> #include <QtCore/QJsonArray>
#else #else
#include "QJsonRoot.h" #include "QJsonRoot.h"
#include <QtCore/QList> #include <QtCore/QList>
#include <QtCore/QVariantList> #include <QtCore/QVariantList>
class QJsonValue; class QJsonValue;
class QJsonValueRef; class QJsonValueRef;
class QJsonArray : public QJsonRoot { class QJsonArray : public QJsonRoot {
friend class QJsonDocument; friend class QJsonDocument;
friend class QJsonValue; friend class QJsonValue;
friend class QJsonValueRef; friend class QJsonValueRef;
friend class QJsonParser; friend class QJsonParser;
public: public:
// TODO(eteran): manually implement the array, for now we use QList // TODO(eteran): manually implement the array, for now we use QList
// but the real thing has a custom implementation // but the real thing has a custom implementation
// I guess for the purposes of less interdependancies? // I guess for the purposes of less interdependancies?
// maybe so it's easier to forward declare the iterators? // maybe so it's easier to forward declare the iterators?
typedef QList<QJsonValue>::const_iterator const_iterator; typedef QList<QJsonValue>::const_iterator const_iterator;
typedef QList<QJsonValue>::iterator iterator; typedef QList<QJsonValue>::iterator iterator;
typedef const_iterator ConstIterator; typedef const_iterator ConstIterator;
typedef iterator Iterator; typedef iterator Iterator;
typedef QList<QJsonValue>::const_pointer const_pointer; typedef QList<QJsonValue>::const_pointer const_pointer;
typedef QList<QJsonValue>::const_reference const_reference; typedef QList<QJsonValue>::const_reference const_reference;
typedef QList<QJsonValue>::difference_type difference_type; typedef QList<QJsonValue>::difference_type difference_type;
typedef QList<QJsonValue>::pointer pointer; typedef QList<QJsonValue>::pointer pointer;
typedef QList<QJsonValue>::reference reference; typedef QList<QJsonValue>::reference reference;
typedef QList<QJsonValue>::size_type size_type; typedef QList<QJsonValue>::size_type size_type;
typedef QList<QJsonValue>::value_type value_type; typedef QList<QJsonValue>::value_type value_type;
public: public:
QJsonArray(); QJsonArray();
QJsonArray(const QJsonArray &other); QJsonArray(const QJsonArray &other);
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
QJsonArray(std::initializer_list<QJsonValue> args); QJsonArray(std::initializer_list<QJsonValue> args);
#endif #endif
~QJsonArray(); ~QJsonArray();
public: public:
QJsonArray &operator=(const QJsonArray &other); QJsonArray &operator=(const QJsonArray &other);
public: public:
bool operator!=(const QJsonArray &other) const; bool operator!=(const QJsonArray &other) const;
bool operator==(const QJsonArray &other) const; bool operator==(const QJsonArray &other) const;
QJsonArray operator+(const QJsonValue &value) const; QJsonArray operator+(const QJsonValue &value) const;
QJsonArray &operator+=(const QJsonValue &value); QJsonArray &operator+=(const QJsonValue &value);
QJsonArray &operator<<(const QJsonValue &value); QJsonArray &operator<<(const QJsonValue &value);
public: public:
const_iterator begin() const; const_iterator begin() const;
const_iterator end() const; const_iterator end() const;
iterator begin(); iterator begin();
iterator end(); iterator end();
const_iterator constBegin() const; const_iterator constBegin() const;
const_iterator constEnd() const; const_iterator constEnd() const;
public: public:
QJsonValueRef operator[](int i); QJsonValueRef operator[](int i);
QJsonValue operator[](int i) const; QJsonValue operator[](int i) const;
QJsonValue at(int i) const; QJsonValue at(int i) const;
QJsonValue first() const; QJsonValue first() const;
QJsonValue last() const; QJsonValue last() const;
public: public:
int size() const; int size() const;
int count() const; int count() const;
bool empty() const; bool empty() const;
bool isEmpty() const; bool isEmpty() const;
public: public:
void pop_back(); void pop_back();
void pop_front(); void pop_front();
void push_back(const QJsonValue &value); void push_back(const QJsonValue &value);
void push_front(const QJsonValue &value); void push_front(const QJsonValue &value);
public: public:
void append(const QJsonValue &value); void append(const QJsonValue &value);
bool contains(const QJsonValue &value) const; bool contains(const QJsonValue &value) const;
iterator erase(iterator it); iterator erase(iterator it);
void insert(int i, const QJsonValue &value); void insert(int i, const QJsonValue &value);
iterator insert(iterator before, const QJsonValue &value); iterator insert(iterator before, const QJsonValue &value);
void prepend(const QJsonValue &value); void prepend(const QJsonValue &value);
void removeAt(int i); void removeAt(int i);
void removeFirst(); void removeFirst();
void removeLast(); void removeLast();
void replace(int i, const QJsonValue &value); void replace(int i, const QJsonValue &value);
QJsonValue takeAt(int i); QJsonValue takeAt(int i);
public: public:
QVariantList toVariantList() const; QVariantList toVariantList() const;
public: public:
static QJsonArray fromStringList(const QStringList &list); static QJsonArray fromStringList(const QStringList &list);
static QJsonArray fromVariantList(const QVariantList &list); static QJsonArray fromVariantList(const QVariantList &list);
private: private:
virtual QJsonRoot *clone() const; virtual QJsonRoot *clone() const;
virtual QJsonArray *toArray(); virtual QJsonArray *toArray();
virtual QJsonObject *toObject(); virtual QJsonObject *toObject();
virtual const QJsonArray *toArray() const; virtual const QJsonArray *toArray() const;
virtual const QJsonObject *toObject() const; virtual const QJsonObject *toObject() const;
private: private:
void swap(QJsonArray &other); void swap(QJsonArray &other);
private: private:
QList<QJsonValue> values_; QList<QJsonValue> values_;
}; };
#endif #endif
#endif #endif

View File

@ -1 +1 @@
#include "QJsonDocument.h" #include "QJsonDocument.h"

View File

@ -1,417 +1,417 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping * Copyright (C) 2016 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "QJsonDocument.h" #include "QJsonDocument.h"
#include "QJsonObject.h" #include "QJsonObject.h"
#include "QJsonArray.h" #include "QJsonArray.h"
#include "QJsonParser.h" #include "QJsonParser.h"
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include <QtCore/QByteArray> #include <QtCore/QByteArray>
#include <QtCore/QTextStream> #include <QtCore/QTextStream>
#include <QtCore/QTextCodec> #include <QtCore/QTextCodec>
#include <QtCore/QtCore> #include <QtCore/QtCore>
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonDocument // Name: QJsonDocument
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument::QJsonDocument() : root_(0) { QJsonDocument::QJsonDocument() : root_(0) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonDocument // Name: QJsonDocument
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument::QJsonDocument(const QJsonObject &object) : root_(0) { QJsonDocument::QJsonDocument(const QJsonObject &object) : root_(0) {
setObject(object); setObject(object);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonDocument // Name: QJsonDocument
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument::QJsonDocument(const QJsonArray &array) : root_(0) { QJsonDocument::QJsonDocument(const QJsonArray &array) : root_(0) {
setArray(array); setArray(array);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonDocument // Name: QJsonDocument
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument::QJsonDocument(const QJsonDocument &other) : root_(0) { QJsonDocument::QJsonDocument(const QJsonDocument &other) : root_(0) {
if(other.root_) { if(other.root_) {
root_ = other.root_->clone(); root_ = other.root_->clone();
} }
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: ~QJsonDocument // Name: ~QJsonDocument
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument::~QJsonDocument() { QJsonDocument::~QJsonDocument() {
delete root_; delete root_;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator= // Name: operator=
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument &QJsonDocument::operator=(const QJsonDocument &other) { QJsonDocument &QJsonDocument::operator=(const QJsonDocument &other) {
QJsonDocument(other).swap(*this); QJsonDocument(other).swap(*this);
return *this; return *this;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator!= // Name: operator!=
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonDocument::operator!=(const QJsonDocument &other) const { bool QJsonDocument::operator!=(const QJsonDocument &other) const {
return !(*this == other); return !(*this == other);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator== // Name: operator==
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonDocument::operator==(const QJsonDocument &other) const { bool QJsonDocument::operator==(const QJsonDocument &other) const {
if(isArray() && other.isArray()) { if(isArray() && other.isArray()) {
return array() == other.array(); return array() == other.array();
} }
if(isObject() && other.isObject()) { if(isObject() && other.isObject()) {
return object() == other.object(); return object() == other.object();
} }
if(isEmpty() && other.isEmpty()) { if(isEmpty() && other.isEmpty()) {
return true; return true;
} }
if(isNull() && other.isNull()) { if(isNull() && other.isNull()) {
return true; return true;
} }
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isArray // Name: isArray
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonDocument::isArray() const { bool QJsonDocument::isArray() const {
return root_ && root_->toArray(); return root_ && root_->toArray();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isEmpty // Name: isEmpty
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonDocument::isEmpty() const { bool QJsonDocument::isEmpty() const {
// TODO(eteran): figure out the rules here that Qt5 uses // TODO(eteran): figure out the rules here that Qt5 uses
// it *looks* like they define empty as being NULL // it *looks* like they define empty as being NULL
// which is obviously different than this // which is obviously different than this
return !root_; return !root_;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isNull // Name: isNull
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonDocument::isNull() const { bool QJsonDocument::isNull() const {
return !root_; return !root_;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isObject // Name: isObject
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonDocument::isObject() const { bool QJsonDocument::isObject() const {
return root_ && root_->toObject(); return root_ && root_->toObject();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: setArray // Name: setArray
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonDocument::setArray(const QJsonArray &array) { void QJsonDocument::setArray(const QJsonArray &array) {
setRoot(array); setRoot(array);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: setObject // Name: setObject
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonDocument::setObject(const QJsonObject &object) { void QJsonDocument::setObject(const QJsonObject &object) {
setRoot(object); setRoot(object);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: setRoot // Name: setRoot
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonDocument::setRoot(const QJsonRoot &root) { void QJsonDocument::setRoot(const QJsonRoot &root) {
delete root_; delete root_;
root_ = root.clone(); root_ = root.clone();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toBinaryData // Name: toBinaryData
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QByteArray QJsonDocument::toBinaryData() const { QByteArray QJsonDocument::toBinaryData() const {
QByteArray r; QByteArray r;
// TODO(eteran): implement this // TODO(eteran): implement this
return r; return r;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: escapeString // Name: escapeString
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QString QJsonDocument::escapeString(const QString &s) const { QString QJsonDocument::escapeString(const QString &s) const {
QString r; QString r;
Q_FOREACH(QChar ch, s) { Q_FOREACH(QChar ch, s) {
switch(ch.toLatin1()) { switch(ch.toLatin1()) {
case '\"': r.append("\\\""); break; case '\"': r.append("\\\""); break;
case '\\': r.append("\\\\"); break; case '\\': r.append("\\\\"); break;
#if 0 #if 0
case '/': r.append("\\/"); break; case '/': r.append("\\/"); break;
#endif #endif
case '\b': r.append("\\b"); break; case '\b': r.append("\\b"); break;
case '\f': r.append("\\f"); break; case '\f': r.append("\\f"); break;
case '\n': r.append("\\n"); break; case '\n': r.append("\\n"); break;
case '\r': r.append("\\r"); break; case '\r': r.append("\\r"); break;
case '\t': r.append("\\t"); break; case '\t': r.append("\\t"); break;
default: default:
r += ch; r += ch;
break; break;
} }
} }
return r; return r;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toJson // Name: toJson
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QString QJsonDocument::toJson(const QJsonValue &v, JsonFormat format) const { QString QJsonDocument::toJson(const QJsonValue &v, JsonFormat format) const {
QString b; QString b;
QTextStream ss(&b, QIODevice::WriteOnly | QIODevice::Text); QTextStream ss(&b, QIODevice::WriteOnly | QIODevice::Text);
switch(v.type()) { switch(v.type()) {
case QJsonValue::Null: case QJsonValue::Null:
ss << "null"; ss << "null";
break; break;
case QJsonValue::Bool: case QJsonValue::Bool:
ss << (v.toBool() ? "true" : "false"); ss << (v.toBool() ? "true" : "false");
break; break;
case QJsonValue::Double: case QJsonValue::Double:
{ {
double d = v.toDouble (); double d = v.toDouble ();
if (qIsFinite(d)) { if (qIsFinite(d)) {
// +2 to format to ensure the expected precision // +2 to format to ensure the expected precision
ss << QByteArray::number(d, 'g', 15 + 2); // ::digits10 is 15 ss << QByteArray::number(d, 'g', 15 + 2); // ::digits10 is 15
} else { } else {
ss << "null"; // +INF || -INF || NaN (see RFC4627#section2.4) ss << "null"; // +INF || -INF || NaN (see RFC4627#section2.4)
} }
} }
break; break;
case QJsonValue::String: case QJsonValue::String:
ss << '"' << escapeString(v.toString()) << '"'; ss << '"' << escapeString(v.toString()) << '"';
break; break;
case QJsonValue::Array: case QJsonValue::Array:
{ {
const QJsonArray a = v.toArray(); const QJsonArray a = v.toArray();
ss << "["; ss << "[";
if(!a.empty()) { if(!a.empty()) {
QJsonArray::const_iterator it = a.begin(); QJsonArray::const_iterator it = a.begin();
QJsonArray::const_iterator e = a.end(); QJsonArray::const_iterator e = a.end();
ss << toJson(*it++, format); ss << toJson(*it++, format);
for(;it != e; ++it) { for(;it != e; ++it) {
ss << ','; ss << ',';
ss << toJson(*it, format); ss << toJson(*it, format);
} }
} }
ss << "]"; ss << "]";
} }
break; break;
case QJsonValue::Object: case QJsonValue::Object:
{ {
const QJsonObject o = v.toObject(); const QJsonObject o = v.toObject();
ss << "{"; ss << "{";
if(!o.empty()) { if(!o.empty()) {
QJsonObject::const_iterator it = o.begin(); QJsonObject::const_iterator it = o.begin();
QJsonObject::const_iterator e = o.end(); QJsonObject::const_iterator e = o.end();
ss << '"' << escapeString(it.key()) << "\": " << toJson(it.value(), format); ss << '"' << escapeString(it.key()) << "\": " << toJson(it.value(), format);
++it; ++it;
for(;it != e; ++it) { for(;it != e; ++it) {
ss << ','; ss << ',';
ss << '"' << escapeString(it.key()) << "\": " << toJson(it.value(), format); ss << '"' << escapeString(it.key()) << "\": " << toJson(it.value(), format);
} }
} }
ss << "}"; ss << "}";
} }
break; break;
case QJsonValue::Undefined: case QJsonValue::Undefined:
Q_ASSERT(0); Q_ASSERT(0);
break; break;
} }
return b; return b;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toJson // Name: toJson
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QByteArray QJsonDocument::toJson(JsonFormat format) const { QByteArray QJsonDocument::toJson(JsonFormat format) const {
Q_UNUSED(format); Q_UNUSED(format);
if(isArray()) { if(isArray()) {
QString s = toJson(array(), format); QString s = toJson(array(), format);
return s.toUtf8(); return s.toUtf8();
} }
if(isObject()) { if(isObject()) {
QString s = toJson(object(), format); QString s = toJson(object(), format);
return s.toUtf8(); return s.toUtf8();
} }
return QByteArray(); return QByteArray();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toVariant // Name: toVariant
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QVariant QJsonDocument::toVariant() const { QVariant QJsonDocument::toVariant() const {
if(!isEmpty()) { if(!isEmpty()) {
if(QJsonObject *const object = root_->toObject()) { if(QJsonObject *const object = root_->toObject()) {
return object->toVariantMap(); return object->toVariantMap();
} }
if(QJsonArray *const array = root_->toArray()) { if(QJsonArray *const array = root_->toArray()) {
return array->toVariantList(); return array->toVariantList();
} }
} }
return QVariant(); return QVariant();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: array // Name: array
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray QJsonDocument::array() const { QJsonArray QJsonDocument::array() const {
if(!isEmpty()) { if(!isEmpty()) {
if(QJsonArray *const array = root_->toArray()) { if(QJsonArray *const array = root_->toArray()) {
return *array; return *array;
} }
} }
return QJsonArray(); return QJsonArray();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: object // Name: object
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject QJsonDocument::object() const { QJsonObject QJsonDocument::object() const {
if(!isEmpty()) { if(!isEmpty()) {
if(QJsonObject *const object = root_->toObject()) { if(QJsonObject *const object = root_->toObject()) {
return *object; return *object;
} }
} }
return QJsonObject(); return QJsonObject();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: rawData // Name: rawData
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
const char *QJsonDocument::rawData(int *size) const { const char *QJsonDocument::rawData(int *size) const {
Q_UNUSED(size); Q_UNUSED(size);
// TODO(eteran): implement this // TODO(eteran): implement this
return 0; return 0;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: fromBinaryData // Name: fromBinaryData
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument QJsonDocument::fromBinaryData(const QByteArray &data, DataValidation validation) { QJsonDocument QJsonDocument::fromBinaryData(const QByteArray &data, DataValidation validation) {
Q_UNUSED(data); Q_UNUSED(data);
Q_UNUSED(validation); Q_UNUSED(validation);
QJsonDocument doc; QJsonDocument doc;
// TODO(eteran): implement this // TODO(eteran): implement this
return doc; return doc;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: fromJson // Name: fromJson
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument QJsonDocument::fromJson(const QByteArray &json, QJsonParseError *error) { QJsonDocument QJsonDocument::fromJson(const QByteArray &json, QJsonParseError *error) {
QJsonDocument doc; QJsonDocument doc;
const char *const begin = json.constData(); const char *const begin = json.constData();
const char *const end = begin + json.size(); const char *const end = begin + json.size();
QJsonParser parser(begin, end); QJsonParser parser(begin, end);
doc.root_ = parser.parse(); doc.root_ = parser.parse();
if(error) { if(error) {
*error = parser.state(); *error = parser.state();
} }
return doc; return doc;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: fromRawData // Name: fromRawData
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument QJsonDocument::fromRawData(const char *data, int size, DataValidation validation) { QJsonDocument QJsonDocument::fromRawData(const char *data, int size, DataValidation validation) {
// data has to be aligned to a 4 byte boundary. // data has to be aligned to a 4 byte boundary.
Q_ASSERT(!(reinterpret_cast<quintptr>(data) % 3)); Q_ASSERT(!(reinterpret_cast<quintptr>(data) % 3));
return fromBinaryData(QByteArray::fromRawData(data, size), validation); return fromBinaryData(QByteArray::fromRawData(data, size), validation);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: fromVariant // Name: fromVariant
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument QJsonDocument::fromVariant(const QVariant &variant) { QJsonDocument QJsonDocument::fromVariant(const QVariant &variant) {
QJsonDocument doc; QJsonDocument doc;
if (variant.type() == QVariant::Map) { if (variant.type() == QVariant::Map) {
doc.setObject(QJsonObject::fromVariantMap(variant.toMap())); doc.setObject(QJsonObject::fromVariantMap(variant.toMap()));
} else if (variant.type() == QVariant::Hash) { } else if (variant.type() == QVariant::Hash) {
doc.setObject(QJsonObject::fromVariantHash(variant.toHash())); doc.setObject(QJsonObject::fromVariantHash(variant.toHash()));
} else if (variant.type() == QVariant::List) { } else if (variant.type() == QVariant::List) {
doc.setArray(QJsonArray::fromVariantList(variant.toList())); doc.setArray(QJsonArray::fromVariantList(variant.toList()));
} else if (variant.type() == QVariant::StringList) { } else if (variant.type() == QVariant::StringList) {
doc.setArray(QJsonArray::fromStringList(variant.toStringList())); doc.setArray(QJsonArray::fromStringList(variant.toStringList()));
} }
return doc; return doc;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: swap // Name: swap
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonDocument::swap(QJsonDocument &other) { void QJsonDocument::swap(QJsonDocument &other) {
qSwap(root_, other.root_); qSwap(root_, other.root_);
} }
#endif #endif

View File

@ -1,103 +1,103 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping * Copyright (C) 2016 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef QJSON_DOCUMENT_H_ #ifndef QJSON_DOCUMENT_H_
#define QJSON_DOCUMENT_H_ #define QJSON_DOCUMENT_H_
#include <QtCore/QtGlobal> #include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
#include <QtCore/QJsonDocument> #include <QtCore/QJsonDocument>
#else #else
class QVariant; class QVariant;
class QByteArray; class QByteArray;
class QTextStream; class QTextStream;
class QJsonObject; class QJsonObject;
class QJsonValue; class QJsonValue;
class QJsonArray; class QJsonArray;
class QJsonParseError; class QJsonParseError;
class QJsonRoot; class QJsonRoot;
class QJsonDocument { class QJsonDocument {
public: public:
enum DataValidation { enum DataValidation {
Validate = 0, Validate = 0,
BypassValidation = 1 BypassValidation = 1
}; };
enum JsonFormat { enum JsonFormat {
Indented, Indented,
Compact Compact
}; };
public: public:
QJsonDocument(); QJsonDocument();
QJsonDocument(const QJsonObject &object); QJsonDocument(const QJsonObject &object);
QJsonDocument(const QJsonArray &array); QJsonDocument(const QJsonArray &array);
QJsonDocument(const QJsonDocument &other); QJsonDocument(const QJsonDocument &other);
~QJsonDocument(); ~QJsonDocument();
public: public:
QJsonDocument &operator=(const QJsonDocument &other); QJsonDocument &operator=(const QJsonDocument &other);
public: public:
bool operator!=(const QJsonDocument &other) const; bool operator!=(const QJsonDocument &other) const;
bool operator==(const QJsonDocument &other) const; bool operator==(const QJsonDocument &other) const;
public: public:
bool isArray() const; bool isArray() const;
bool isEmpty() const; bool isEmpty() const;
bool isNull() const; bool isNull() const;
bool isObject() const; bool isObject() const;
public: public:
QByteArray toBinaryData() const; QByteArray toBinaryData() const;
QByteArray toJson(JsonFormat format = Indented) const; QByteArray toJson(JsonFormat format = Indented) const;
QVariant toVariant() const; QVariant toVariant() const;
public: public:
QJsonArray array() const; QJsonArray array() const;
QJsonObject object() const; QJsonObject object() const;
const char *rawData(int *size) const; const char *rawData(int *size) const;
public: public:
void setArray(const QJsonArray &array); void setArray(const QJsonArray &array);
void setObject(const QJsonObject &object); void setObject(const QJsonObject &object);
public: public:
static QJsonDocument fromBinaryData(const QByteArray &data, DataValidation validation = Validate); static QJsonDocument fromBinaryData(const QByteArray &data, DataValidation validation = Validate);
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error = 0); static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error = 0);
static QJsonDocument fromRawData(const char *data, int size, DataValidation validation = Validate); static QJsonDocument fromRawData(const char *data, int size, DataValidation validation = Validate);
static QJsonDocument fromVariant(const QVariant &variant); static QJsonDocument fromVariant(const QVariant &variant);
private: private:
void setRoot(const QJsonRoot &root); void setRoot(const QJsonRoot &root);
QString toJson(const QJsonValue &v, JsonFormat format) const; QString toJson(const QJsonValue &v, JsonFormat format) const;
QString escapeString(const QString &s) const; QString escapeString(const QString &s) const;
private: private:
void swap(QJsonDocument &other); void swap(QJsonDocument &other);
private: private:
QJsonRoot *root_; QJsonRoot *root_;
}; };
#endif #endif
#endif #endif

View File

@ -1 +1 @@
#include "QJsonObject.h" #include "QJsonObject.h"

View File

@ -1,322 +1,322 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping * Copyright (C) 2016 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "QJsonObject.h" #include "QJsonObject.h"
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonObject // Name: QJsonObject
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject::QJsonObject() { QJsonObject::QJsonObject() {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonObject // Name: QJsonObject
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject::QJsonObject(const QJsonObject &other) : values_(other.values_) { QJsonObject::QJsonObject(const QJsonObject &other) : values_(other.values_) {
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonObject // Name: QJsonObject
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject::QJsonObject(std::initializer_list<QPair<QString, QJsonValue> > args) { QJsonObject::QJsonObject(std::initializer_list<QPair<QString, QJsonValue> > args) {
for(const QPair<QString, QJsonValue> &arg : args) { for(const QPair<QString, QJsonValue> &arg : args) {
values_.insert(arg.first, arg.second); values_.insert(arg.first, arg.second);
} }
} }
#endif #endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: ~QJsonObject // Name: ~QJsonObject
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject::~QJsonObject() { QJsonObject::~QJsonObject() {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject &QJsonObject::operator=(const QJsonObject &other) { QJsonObject &QJsonObject::operator=(const QJsonObject &other) {
QJsonObject(other).swap(*this); QJsonObject(other).swap(*this);
return *this; return *this;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject::iterator QJsonObject::begin() { QJsonObject::iterator QJsonObject::begin() {
return values_.begin(); return values_.begin();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::begin() const { QJsonObject::const_iterator QJsonObject::begin() const {
return values_.begin(); return values_.begin();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject::iterator QJsonObject::end() { QJsonObject::iterator QJsonObject::end() {
return values_.end(); return values_.end();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::end() const { QJsonObject::const_iterator QJsonObject::end() const {
return values_.end(); return values_.end();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::constBegin() const { QJsonObject::const_iterator QJsonObject::constBegin() const {
return begin(); return begin();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::constEnd() const { QJsonObject::const_iterator QJsonObject::constEnd() const {
return end(); return end();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int QJsonObject::count() const { int QJsonObject::count() const {
return size(); return size();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int QJsonObject::length() const { int QJsonObject::length() const {
return size(); return size();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int QJsonObject::size() const { int QJsonObject::size() const {
return values_.size(); return values_.size();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonObject::empty() const { bool QJsonObject::empty() const {
return values_.empty(); return values_.empty();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonObject::isEmpty() const { bool QJsonObject::isEmpty() const {
return empty(); return empty();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const { QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const {
return values_.find(key); return values_.find(key);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonObject::contains(const QString &key) const { bool QJsonObject::contains(const QString &key) const {
return values_.contains(key); return values_.contains(key);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject::iterator QJsonObject::find(const QString &key) { QJsonObject::iterator QJsonObject::find(const QString &key) {
return values_.find(key); return values_.find(key);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::find(const QString &key) const { QJsonObject::const_iterator QJsonObject::find(const QString &key) const {
return values_.find(key); return values_.find(key);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject::iterator QJsonObject::erase(iterator it) { QJsonObject::iterator QJsonObject::erase(iterator it) {
return values_.erase(it); return values_.erase(it);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue &value) { QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue &value) {
return values_.insert(key, value); return values_.insert(key, value);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QStringList QJsonObject::keys() const { QStringList QJsonObject::keys() const {
return values_.keys(); return values_.keys();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonObject::remove(const QString &key) { void QJsonObject::remove(const QString &key) {
values_.remove(key); values_.remove(key);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue QJsonObject::take(const QString &key) { QJsonValue QJsonObject::take(const QString &key) {
return values_.take(key); return values_.take(key);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue QJsonObject::value(const QString &key) const { QJsonValue QJsonObject::value(const QString &key) const {
return values_.value(key); return values_.value(key);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonObject::operator!=(const QJsonObject &other) const { bool QJsonObject::operator!=(const QJsonObject &other) const {
return values_ != other.values_; return values_ != other.values_;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonObject::operator==(const QJsonObject &other) const { bool QJsonObject::operator==(const QJsonObject &other) const {
return values_ != other.values_; return values_ != other.values_;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue QJsonObject::operator[](const QString &key) const { QJsonValue QJsonObject::operator[](const QString &key) const {
return values_[key]; return values_[key];
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValueRef QJsonObject::operator[](const QString &key) { QJsonValueRef QJsonObject::operator[](const QString &key) {
return QJsonValueRef(this, key); return QJsonValueRef(this, key);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QVariantMap QJsonObject::toVariantMap() const { QVariantMap QJsonObject::toVariantMap() const {
QVariantMap a; QVariantMap a;
for(const_iterator it = begin(); it != end(); ++it) { for(const_iterator it = begin(); it != end(); ++it) {
a.insert(it.key(), it.value().toVariant()); a.insert(it.key(), it.value().toVariant());
} }
return a; return a;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QVariantHash QJsonObject::toVariantHash() const { QVariantHash QJsonObject::toVariantHash() const {
QVariantHash a; QVariantHash a;
for(const_iterator it = begin(); it != end(); ++it) { for(const_iterator it = begin(); it != end(); ++it) {
a.insert(it.key(), it.value().toVariant()); a.insert(it.key(), it.value().toVariant());
} }
return a; return a;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject QJsonObject::fromVariantMap(const QVariantMap &map) { QJsonObject QJsonObject::fromVariantMap(const QVariantMap &map) {
QJsonObject o; QJsonObject o;
for(QVariantMap::const_iterator it = map.begin(); it != map.end(); ++it) { for(QVariantMap::const_iterator it = map.begin(); it != map.end(); ++it) {
o.insert(it.key(), QJsonValue::fromVariant(it.value())); o.insert(it.key(), QJsonValue::fromVariant(it.value()));
} }
return o; return o;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject QJsonObject::fromVariantHash(const QVariantHash &hash) { QJsonObject QJsonObject::fromVariantHash(const QVariantHash &hash) {
QJsonObject o; QJsonObject o;
for(QVariantHash::const_iterator it = hash.begin(); it != hash.end(); ++it) { for(QVariantHash::const_iterator it = hash.begin(); it != hash.end(); ++it) {
o.insert(it.key(), QJsonValue::fromVariant(it.value())); o.insert(it.key(), QJsonValue::fromVariant(it.value()));
} }
return o; return o;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonRoot *QJsonObject::clone() const { QJsonRoot *QJsonObject::clone() const {
return new QJsonObject(*this); return new QJsonObject(*this);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
const QJsonObject *QJsonObject::toObject() const { const QJsonObject *QJsonObject::toObject() const {
return this; return this;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject *QJsonObject::toObject() { QJsonObject *QJsonObject::toObject() {
return this; return this;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray *QJsonObject::toArray() { QJsonArray *QJsonObject::toArray() {
return 0; return 0;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
const QJsonArray *QJsonObject::toArray() const { const QJsonArray *QJsonObject::toArray() const {
return 0; return 0;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: swap // Name: swap
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonObject::swap(QJsonObject &other) { void QJsonObject::swap(QJsonObject &other) {
qSwap(values_, other.values_); qSwap(values_, other.values_);
} }
#endif #endif

View File

@ -1,121 +1,121 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping * Copyright (C) 2016 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef QJSON_OBJECT_H_ #ifndef QJSON_OBJECT_H_
#define QJSON_OBJECT_H_ #define QJSON_OBJECT_H_
#include <QtCore/QtGlobal> #include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
#include <QtCore/QJsonObject> #include <QtCore/QJsonObject>
#else #else
#include "QJsonRoot.h" #include "QJsonRoot.h"
#include "QJsonValueRef.h" #include "QJsonValueRef.h"
#include "QJsonValue.h" #include "QJsonValue.h"
#include <QtCore/QString> #include <QtCore/QString>
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include <QtCore/QVariantMap> #include <QtCore/QVariantMap>
#include <QtCore/QMap> #include <QtCore/QMap>
class QJsonObject : public QJsonRoot { class QJsonObject : public QJsonRoot {
friend class QJsonDocument; friend class QJsonDocument;
friend class QJsonValue; friend class QJsonValue;
friend class QJsonValueRef; friend class QJsonValueRef;
friend class QJsonParser; friend class QJsonParser;
public: public:
// TODO(eteran): manually implement the map, for now we use QMap // TODO(eteran): manually implement the map, for now we use QMap
// but the real thing has a custom implementation // but the real thing has a custom implementation
// I guess for the purposes of less interdependancies? // I guess for the purposes of less interdependancies?
// maybe so it's easier to forward declare the iterators? // maybe so it's easier to forward declare the iterators?
typedef QMap<QString, QJsonValue>::const_iterator const_iterator; typedef QMap<QString, QJsonValue>::const_iterator const_iterator;
typedef QMap<QString, QJsonValue>::iterator iterator; typedef QMap<QString, QJsonValue>::iterator iterator;
typedef const_iterator ConstIterator; typedef const_iterator ConstIterator;
typedef iterator Iterator; typedef iterator Iterator;
typedef QMap<QString, QJsonValue>::key_type key_type; typedef QMap<QString, QJsonValue>::key_type key_type;
typedef QMap<QString, QJsonValue>::mapped_type mapped_type; typedef QMap<QString, QJsonValue>::mapped_type mapped_type;
typedef QMap<QString, QJsonValue>::size_type size_type; typedef QMap<QString, QJsonValue>::size_type size_type;
public: public:
QJsonObject(); QJsonObject();
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
QJsonObject(std::initializer_list<QPair<QString, QJsonValue> > args); QJsonObject(std::initializer_list<QPair<QString, QJsonValue> > args);
#endif #endif
QJsonObject(const QJsonObject &other); QJsonObject(const QJsonObject &other);
~QJsonObject(); ~QJsonObject();
QJsonObject &operator=(const QJsonObject &other); QJsonObject &operator=(const QJsonObject &other);
public: public:
iterator begin(); iterator begin();
const_iterator begin() const; const_iterator begin() const;
iterator end(); iterator end();
const_iterator end() const; const_iterator end() const;
const_iterator constBegin() const; const_iterator constBegin() const;
const_iterator constEnd() const; const_iterator constEnd() const;
public: public:
int count() const; int count() const;
int length() const; int length() const;
int size() const; int size() const;
bool empty() const; bool empty() const;
bool isEmpty() const; bool isEmpty() const;
public: public:
const_iterator constFind(const QString &key) const; const_iterator constFind(const QString &key) const;
bool contains(const QString &key) const; bool contains(const QString &key) const;
iterator find(const QString &key); iterator find(const QString &key);
const_iterator find(const QString &key) const; const_iterator find(const QString &key) const;
public: public:
iterator erase(iterator it); iterator erase(iterator it);
iterator insert(const QString &key, const QJsonValue &value); iterator insert(const QString &key, const QJsonValue &value);
QStringList keys() const; QStringList keys() const;
void remove(const QString &key); void remove(const QString &key);
QJsonValue take(const QString &key); QJsonValue take(const QString &key);
QJsonValue value(const QString &key) const; QJsonValue value(const QString &key) const;
bool operator!=(const QJsonObject &other) const; bool operator!=(const QJsonObject &other) const;
bool operator==(const QJsonObject &other) const; bool operator==(const QJsonObject &other) const;
QJsonValue operator[](const QString &key) const; QJsonValue operator[](const QString &key) const;
QJsonValueRef operator[](const QString &key); QJsonValueRef operator[](const QString &key);
public: public:
QVariantMap toVariantMap() const; QVariantMap toVariantMap() const;
QVariantHash toVariantHash() const; QVariantHash toVariantHash() const;
public: public:
static QJsonObject fromVariantMap(const QVariantMap &map); static QJsonObject fromVariantMap(const QVariantMap &map);
static QJsonObject fromVariantHash(const QVariantHash &hash); static QJsonObject fromVariantHash(const QVariantHash &hash);
private: private:
virtual QJsonRoot *clone() const; virtual QJsonRoot *clone() const;
virtual QJsonArray *toArray(); virtual QJsonArray *toArray();
virtual QJsonObject *toObject(); virtual QJsonObject *toObject();
virtual const QJsonArray *toArray() const; virtual const QJsonArray *toArray() const;
virtual const QJsonObject *toObject() const; virtual const QJsonObject *toObject() const;
private: private:
void swap(QJsonObject &other); void swap(QJsonObject &other);
private: private:
QMap<QString, QJsonValue> values_; QMap<QString, QJsonValue> values_;
}; };
#endif #endif
#endif #endif

View File

@ -1 +1 @@
#include "QJsonParseError.h" #include "QJsonParseError.h"

View File

@ -1,64 +1,64 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping * Copyright (C) 2016 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "QJsonParseError.h" #include "QJsonParseError.h"
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: errorString // Name: errorString
// Desc: The QJsonParseError class is used to report errors during JSON parsing. // Desc: The QJsonParseError class is used to report errors during JSON parsing.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QString QJsonParseError::errorString() const { QString QJsonParseError::errorString() const {
switch(error) { switch(error) {
case NoError: case NoError:
return "No error occurred"; return "No error occurred";
case UnterminatedObject: case UnterminatedObject:
return "unterminated object"; return "unterminated object";
case MissingNameSeparator: case MissingNameSeparator:
return "missing name separator"; return "missing name separator";
case UnterminatedArray: case UnterminatedArray:
return "unterminated array"; return "unterminated array";
case MissingValueSeparator: case MissingValueSeparator:
return "missing value separator"; return "missing value separator";
case IllegalValue: case IllegalValue:
return "illegal value"; return "illegal value";
case TerminationByNumber: case TerminationByNumber:
return "invalid termination by number"; return "invalid termination by number";
case IllegalNumber: case IllegalNumber:
return "illegal number"; return "illegal number";
case IllegalEscapeSequence: case IllegalEscapeSequence:
return "illegal escape sequence"; return "illegal escape sequence";
case IllegalUTF8String: case IllegalUTF8String:
return "invalid UTF8 string"; return "invalid UTF8 string";
case UnterminatedString: case UnterminatedString:
return "unterminated string"; return "unterminated string";
case MissingObject: case MissingObject:
return "object is missing after a comma"; return "object is missing after a comma";
case DeepNesting: case DeepNesting:
return "too deeply nested document"; return "too deeply nested document";
case DocumentTooLarge: case DocumentTooLarge:
return "too large document"; return "too large document";
case GarbageAtEnd: case GarbageAtEnd:
return "garbage at the end of the document"; return "garbage at the end of the document";
} }
return QString(); return QString();
} }
#endif #endif

View File

@ -1,60 +1,60 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping * Copyright (C) 2016 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef QJSON_PARSE_ERROR_H_ #ifndef QJSON_PARSE_ERROR_H_
#define QJSON_PARSE_ERROR_H_ #define QJSON_PARSE_ERROR_H_
#include <QtCore/QtGlobal> #include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
#include <QtCore/QJsonParseError> #include <QtCore/QJsonParseError>
#else #else
#include <QtCore/QString> #include <QtCore/QString>
class QJsonParseError { class QJsonParseError {
public: public:
enum ParseError { enum ParseError {
NoError = 0, NoError = 0,
UnterminatedObject = 1, UnterminatedObject = 1,
MissingNameSeparator = 2, MissingNameSeparator = 2,
UnterminatedArray = 3, UnterminatedArray = 3,
MissingValueSeparator = 4, MissingValueSeparator = 4,
IllegalValue = 5, IllegalValue = 5,
TerminationByNumber = 6, TerminationByNumber = 6,
IllegalNumber = 7, IllegalNumber = 7,
IllegalEscapeSequence = 8, IllegalEscapeSequence = 8,
IllegalUTF8String = 9, IllegalUTF8String = 9,
UnterminatedString = 10, UnterminatedString = 10,
MissingObject = 11, MissingObject = 11,
DeepNesting = 12, DeepNesting = 12,
DocumentTooLarge = 13, DocumentTooLarge = 13,
GarbageAtEnd = 14 GarbageAtEnd = 14
}; };
public: public:
QString errorString() const; QString errorString() const;
public: public:
ParseError error; ParseError error;
int offset; int offset;
}; };
#endif #endif
#endif #endif

View File

@ -1,455 +1,455 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping * Copyright (C) 2016 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "QJsonParser.h" #include "QJsonParser.h"
#include "QJsonArray.h" #include "QJsonArray.h"
#include "QJsonObject.h" #include "QJsonObject.h"
#include "QJsonValue.h" #include "QJsonValue.h"
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
#include <cctype> #include <cctype>
#include <QScopedPointer> #include <QScopedPointer>
#include <QVector> #include <QVector>
namespace { namespace {
unsigned int to_hex(int ch) { unsigned int to_hex(int ch) {
static const int hexval[256] = { static const int hexval[256] = {
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 0x0, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
}; };
if(static_cast<unsigned int>(ch) < 256) { if(static_cast<unsigned int>(ch) < 256) {
return hexval[static_cast<unsigned int>(ch)]; return hexval[static_cast<unsigned int>(ch)];
} else { } else {
return 0; return 0;
} }
} }
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonParser // Name: QJsonParser
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonParser::QJsonParser(const char *begin, const char *end) : begin_(begin), end_(end), p_(begin) { QJsonParser::QJsonParser(const char *begin, const char *end) : begin_(begin), end_(end), p_(begin) {
state_.error = QJsonParseError::NoError; state_.error = QJsonParseError::NoError;
state_.offset = 0; state_.offset = 0;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: parse // Name: parse
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonRoot *QJsonParser::parse() { QJsonRoot *QJsonParser::parse() {
if(begin_ == end_) { if(begin_ == end_) {
return 0; return 0;
} }
QJsonRoot *ret = 0; QJsonRoot *ret = 0;
try { try {
const char ch = peek(); const char ch = peek();
switch(ch) { switch(ch) {
case ArrayBegin: case ArrayBegin:
ret = getArray(); ret = getArray();
break; break;
case ObjectBegin: case ObjectBegin:
ret = getObject(); ret = getObject();
break; break;
default: default:
state_.error = QJsonParseError::IllegalValue; state_.error = QJsonParseError::IllegalValue;
state_.offset = p_ - begin_; state_.offset = p_ - begin_;
break; break;
} }
} catch(const QJsonParseError &e) { } catch(const QJsonParseError &e) {
state_ = e; state_ = e;
} }
if(ret) { if(ret) {
// eat up trailing white space... // eat up trailing white space...
while(p_ != end_ && std::isspace(*p_)) { while(p_ != end_ && std::isspace(*p_)) {
++p_; ++p_;
} }
//detect trailing garbage //detect trailing garbage
if(p_ != end_) { if(p_ != end_) {
state_.error = QJsonParseError::GarbageAtEnd; state_.error = QJsonParseError::GarbageAtEnd;
state_.offset = p_ - begin_; state_.offset = p_ - begin_;
} }
} }
return ret; return ret;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: peek // Name: peek
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
char QJsonParser::peek() { char QJsonParser::peek() {
// first eat up some whitespace // first eat up some whitespace
while(p_ != end_ && std::isspace(*p_)) { while(p_ != end_ && std::isspace(*p_)) {
++p_; ++p_;
} }
return *p_; return *p_;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: getValue // Name: getValue
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue QJsonParser::getValue() { QJsonValue QJsonParser::getValue() {
switch(peek()) { switch(peek()) {
case ObjectBegin: case ObjectBegin:
{ {
QScopedPointer<QJsonObject> obj(getObject()); QScopedPointer<QJsonObject> obj(getObject());
return QJsonValue(*obj); return QJsonValue(*obj);
} }
case ArrayBegin: case ArrayBegin:
{ {
QScopedPointer<QJsonArray> arr(getArray()); QScopedPointer<QJsonArray> arr(getArray());
return QJsonValue(*arr); return QJsonValue(*arr);
} }
case Quote: case Quote:
return QJsonValue(getString()); return QJsonValue(getString());
case 't': case 't':
return getTrue(); return getTrue();
case 'f': case 'f':
return getFalse(); return getFalse();
case 'n': case 'n':
return getNull(); return getNull();
default: default:
return getNumber(); return getNumber();
} }
throwError(QJsonParseError::MissingObject); throwError(QJsonParseError::MissingObject);
return QJsonValue(); return QJsonValue();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: getObject // Name: getObject
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject *QJsonParser::getObject() { QJsonObject *QJsonParser::getObject() {
QScopedPointer<QJsonObject> obj(new QJsonObject); QScopedPointer<QJsonObject> obj(new QJsonObject);
char tok = peek(); char tok = peek();
if(tok != ObjectBegin) { if(tok != ObjectBegin) {
throwError(QJsonParseError::IllegalValue); throwError(QJsonParseError::IllegalValue);
} }
++p_; ++p_;
// handle empty object // handle empty object
tok = peek(); tok = peek();
if(peek() == ObjectEnd) { if(peek() == ObjectEnd) {
++p_; ++p_;
} else { } else {
do { do {
QPair<QString, QJsonValue> p = getPair(); QPair<QString, QJsonValue> p = getPair();
obj->values_.insert(p.first, p.second); obj->values_.insert(p.first, p.second);
tok = peek(); tok = peek();
++p_; ++p_;
} while(tok == ValueSeparator); } while(tok == ValueSeparator);
} }
if(tok != ObjectEnd) { if(tok != ObjectEnd) {
throwError(QJsonParseError::UnterminatedObject); throwError(QJsonParseError::UnterminatedObject);
} }
return obj.take(); return obj.take();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: getArray // Name: getArray
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray *QJsonParser::getArray() { QJsonArray *QJsonParser::getArray() {
QScopedPointer<QJsonArray> arr(new QJsonArray); QScopedPointer<QJsonArray> arr(new QJsonArray);
char tok = peek(); char tok = peek();
if(tok != ArrayBegin) { if(tok != ArrayBegin) {
throwError(QJsonParseError::IllegalValue); throwError(QJsonParseError::IllegalValue);
} }
++p_; ++p_;
// handle empty object // handle empty object
tok = peek(); tok = peek();
if(tok == ArrayEnd) { if(tok == ArrayEnd) {
++p_; ++p_;
} else { } else {
do { do {
arr->values_.push_back(getValue()); arr->values_.push_back(getValue());
tok = peek(); tok = peek();
++p_; ++p_;
} while(tok == ValueSeparator); } while(tok == ValueSeparator);
} }
if(tok != ArrayEnd) { if(tok != ArrayEnd) {
throwError(QJsonParseError::MissingValueSeparator); throwError(QJsonParseError::MissingValueSeparator);
} }
return arr.take(); return arr.take();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: getPair // Name: getPair
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QPair<QString, QJsonValue> QJsonParser::getPair() { QPair<QString, QJsonValue> QJsonParser::getPair() {
QString key = getString(); QString key = getString();
if(peek() != NameSeparator) { if(peek() != NameSeparator) {
throwError(QJsonParseError::MissingNameSeparator); throwError(QJsonParseError::MissingNameSeparator);
} }
++p_; ++p_;
return qMakePair(key, getValue()); return qMakePair(key, getValue());
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: getString // Name: getString
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QString QJsonParser::getString() { QString QJsonParser::getString() {
if(peek() != Quote) { if(peek() != Quote) {
throwError(QJsonParseError::IllegalUTF8String); throwError(QJsonParseError::IllegalUTF8String);
} }
++p_; ++p_;
QByteArray s; QByteArray s;
while(p_ != end_ && *p_ != Quote && *p_ != '\n') { while(p_ != end_ && *p_ != Quote && *p_ != '\n') {
if(*p_ == '\\') { if(*p_ == '\\') {
++p_; ++p_;
if(p_ != end_) { if(p_ != end_) {
switch(*p_) { switch(*p_) {
case '"': s.append('"'); break; case '"': s.append('"'); break;
case '\\': s.append('\\'); break; case '\\': s.append('\\'); break;
case '/': s.append('/'); break; case '/': s.append('/'); break;
case 'b': s.append('\b'); break; case 'b': s.append('\b'); break;
case 'f': s.append('\f'); break; case 'f': s.append('\f'); break;
case 'n': s.append('\n'); break; case 'n': s.append('\n'); break;
case 'r': s.append('\r'); break; case 'r': s.append('\r'); break;
case 't': s.append('\t'); break; case 't': s.append('\t'); break;
case 'u': case 'u':
{ {
QString hexChar; QString hexChar;
// convert \uXXXX escape sequences to UTF-8 // convert \uXXXX escape sequences to UTF-8
char hex[4]; char hex[4];
if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[0] = *++p_; if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[0] = *++p_;
if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[1] = *++p_; if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[1] = *++p_;
if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[2] = *++p_; if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[2] = *++p_;
if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[3] = *++p_; if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[3] = *++p_;
if(!std::isxdigit(hex[0])) throwError(QJsonParseError::IllegalUTF8String); if(!std::isxdigit(hex[0])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[1])) throwError(QJsonParseError::IllegalUTF8String); if(!std::isxdigit(hex[1])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[2])) throwError(QJsonParseError::IllegalUTF8String); if(!std::isxdigit(hex[2])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[3])) throwError(QJsonParseError::IllegalUTF8String); if(!std::isxdigit(hex[3])) throwError(QJsonParseError::IllegalUTF8String);
quint16 w1 = 0; quint16 w1 = 0;
quint16 w2 = 0; quint16 w2 = 0;
w1 |= (to_hex(hex[0]) << 12); w1 |= (to_hex(hex[0]) << 12);
w1 |= (to_hex(hex[1]) << 8); w1 |= (to_hex(hex[1]) << 8);
w1 |= (to_hex(hex[2]) << 4); w1 |= (to_hex(hex[2]) << 4);
w1 |= (to_hex(hex[3])); w1 |= (to_hex(hex[3]));
hexChar.append(QChar(w1)); hexChar.append(QChar(w1));
if((w1 & 0xfc00) == 0xdc00) { if((w1 & 0xfc00) == 0xdc00) {
throwError(QJsonParseError::IllegalUTF8String); throwError(QJsonParseError::IllegalUTF8String);
} }
if((w1 & 0xfc00) == 0xd800) { if((w1 & 0xfc00) == 0xd800) {
// part of a surrogate pair // part of a surrogate pair
if(p_ == end_ || *++p_ != '\\') { throwError(QJsonParseError::IllegalEscapeSequence); } if(p_ == end_ || *++p_ != '\\') { throwError(QJsonParseError::IllegalEscapeSequence); }
if(p_ == end_ || *++p_ != 'u') { throwError(QJsonParseError::IllegalEscapeSequence); } if(p_ == end_ || *++p_ != 'u') { throwError(QJsonParseError::IllegalEscapeSequence); }
// convert \uXXXX escape sequences to UTF-8 // convert \uXXXX escape sequences to UTF-8
if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[0] = *++p_; if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[0] = *++p_;
if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[1] = *++p_; if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[1] = *++p_;
if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[2] = *++p_; if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[2] = *++p_;
if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[3] = *++p_; if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[3] = *++p_;
if(!std::isxdigit(hex[0])) throwError(QJsonParseError::IllegalUTF8String); if(!std::isxdigit(hex[0])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[1])) throwError(QJsonParseError::IllegalUTF8String); if(!std::isxdigit(hex[1])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[2])) throwError(QJsonParseError::IllegalUTF8String); if(!std::isxdigit(hex[2])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[3])) throwError(QJsonParseError::IllegalUTF8String); if(!std::isxdigit(hex[3])) throwError(QJsonParseError::IllegalUTF8String);
w2 |= (to_hex(hex[0]) << 12); w2 |= (to_hex(hex[0]) << 12);
w2 |= (to_hex(hex[1]) << 8); w2 |= (to_hex(hex[1]) << 8);
w2 |= (to_hex(hex[2]) << 4); w2 |= (to_hex(hex[2]) << 4);
w2 |= (to_hex(hex[3])); w2 |= (to_hex(hex[3]));
hexChar.append(QChar(w2)); hexChar.append(QChar(w2));
} }
s.append(hexChar.toUtf8()); s.append(hexChar.toUtf8());
} }
break; break;
default: default:
s.append('\\'); s.append('\\');
break; break;
} }
} }
} else { } else {
s.append(*p_); s.append(*p_);
} }
++p_; ++p_;
} }
if(*p_ != Quote || p_ == end_) { if(*p_ != Quote || p_ == end_) {
throwError(QJsonParseError::UnterminatedString); throwError(QJsonParseError::UnterminatedString);
} }
++p_; ++p_;
return QString::fromUtf8(s, s.size()); return QString::fromUtf8(s, s.size());
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: getNull // Name: getNull
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue QJsonParser::getNull() { QJsonValue QJsonParser::getNull() {
if(p_ == end_ || *p_++ != 'n') { throwError(QJsonParseError::IllegalValue); } if(p_ == end_ || *p_++ != 'n') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'u') { throwError(QJsonParseError::IllegalValue); } if(p_ == end_ || *p_++ != 'u') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'l') { throwError(QJsonParseError::IllegalValue); } if(p_ == end_ || *p_++ != 'l') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'l') { throwError(QJsonParseError::IllegalValue); } if(p_ == end_ || *p_++ != 'l') { throwError(QJsonParseError::IllegalValue); }
return QJsonValue(); return QJsonValue();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: getTrue // Name: getTrue
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue QJsonParser::getTrue() { QJsonValue QJsonParser::getTrue() {
if(p_ == end_ || *p_++ != 't') { throwError(QJsonParseError::IllegalValue); } if(p_ == end_ || *p_++ != 't') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'r') { throwError(QJsonParseError::IllegalValue); } if(p_ == end_ || *p_++ != 'r') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'u') { throwError(QJsonParseError::IllegalValue); } if(p_ == end_ || *p_++ != 'u') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'e') { throwError(QJsonParseError::IllegalValue); } if(p_ == end_ || *p_++ != 'e') { throwError(QJsonParseError::IllegalValue); }
return QJsonValue(true); return QJsonValue(true);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: getFalse // Name: getFalse
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue QJsonParser::getFalse() { QJsonValue QJsonParser::getFalse() {
if(p_ == end_ || *p_++ != 'f') { throwError(QJsonParseError::IllegalValue); } if(p_ == end_ || *p_++ != 'f') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'a') { throwError(QJsonParseError::IllegalValue); } if(p_ == end_ || *p_++ != 'a') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'l') { throwError(QJsonParseError::IllegalValue); } if(p_ == end_ || *p_++ != 'l') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 's') { throwError(QJsonParseError::IllegalValue); } if(p_ == end_ || *p_++ != 's') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'e') { throwError(QJsonParseError::IllegalValue); } if(p_ == end_ || *p_++ != 'e') { throwError(QJsonParseError::IllegalValue); }
return QJsonValue(false); return QJsonValue(false);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: getNumber // Name: getNumber
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue QJsonParser::getNumber() { QJsonValue QJsonParser::getNumber() {
// JSON numbers fit the regex: -?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)? // JSON numbers fit the regex: -?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?
const char *const first = p_; const char *const first = p_;
// -? // -?
if(p_ != end_ && *p_ == '-') { if(p_ != end_ && *p_ == '-') {
++p_; ++p_;
} }
// (0|[1-9][0-9]*) // (0|[1-9][0-9]*)
if(p_ != end_) { if(p_ != end_) {
if(*p_ >= '1' && *p_ <= '9') { if(*p_ >= '1' && *p_ <= '9') {
while(p_ != end_ && std::isdigit(*p_)) { while(p_ != end_ && std::isdigit(*p_)) {
++p_; ++p_;
} }
} else if(*p_ == '0') { } else if(*p_ == '0') {
++p_; ++p_;
} else { } else {
throwError(QJsonParseError::IllegalNumber); throwError(QJsonParseError::IllegalNumber);
} }
} }
// (\.[0-9]+)? // (\.[0-9]+)?
if(p_ != end_ && *p_ == '.') { if(p_ != end_ && *p_ == '.') {
++p_; ++p_;
if(!std::isdigit(*p_)) { if(!std::isdigit(*p_)) {
throwError(QJsonParseError::IllegalNumber); throwError(QJsonParseError::IllegalNumber);
} }
while(p_ != end_ && std::isdigit(*p_)) { while(p_ != end_ && std::isdigit(*p_)) {
++p_; ++p_;
} }
} }
// ([eE][+-]?[0-9]+)? // ([eE][+-]?[0-9]+)?
if(p_ != end_ && (*p_ == 'e' || *p_ == 'E')) { if(p_ != end_ && (*p_ == 'e' || *p_ == 'E')) {
++p_; ++p_;
if(p_ != end_ && (*p_ == '+' || *p_ == '-')) { if(p_ != end_ && (*p_ == '+' || *p_ == '-')) {
++p_; ++p_;
} }
if(!std::isdigit(*p_)) { if(!std::isdigit(*p_)) {
throwError(QJsonParseError::IllegalNumber); throwError(QJsonParseError::IllegalNumber);
} }
while(p_ != end_ && std::isdigit(*p_)) { while(p_ != end_ && std::isdigit(*p_)) {
++p_; ++p_;
} }
} }
if(p_ == end_) { if(p_ == end_) {
throwError(QJsonParseError::TerminationByNumber); throwError(QJsonParseError::TerminationByNumber);
} }
return QJsonValue(QByteArray::fromRawData(first, p_ - first).toDouble()); return QJsonValue(QByteArray::fromRawData(first, p_ - first).toDouble());
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: state // Name: state
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonParseError QJsonParser::state() const { QJsonParseError QJsonParser::state() const {
return state_; return state_;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: throwError // Name: throwError
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonParser::throwError(QJsonParseError::ParseError e) { void QJsonParser::throwError(QJsonParseError::ParseError e) {
QJsonParseError err; QJsonParseError err;
err.error = e; err.error = e;
err.offset = p_ - begin_; err.offset = p_ - begin_;
throw err; throw err;
} }
#endif #endif

View File

@ -1,81 +1,81 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping * Copyright (C) 2016 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
// NOTE: this is not part of the "public" Qt API, so using this class directly // NOTE: this is not part of the "public" Qt API, so using this class directly
// is not recomended // is not recomended
#ifndef QJSON_PARSER_H_ #ifndef QJSON_PARSER_H_
#define QJSON_PARSER_H_ #define QJSON_PARSER_H_
#include <QtCore/QtGlobal> #include <QtCore/QtGlobal>
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
#include "QJsonParseError.h" #include "QJsonParseError.h"
#include <QPair> #include <QPair>
class QJsonRoot; class QJsonRoot;
class QJsonObject; class QJsonObject;
class QJsonArray; class QJsonArray;
class QJsonValue; class QJsonValue;
class QJsonParser { class QJsonParser {
friend class QJsonDocument; friend class QJsonDocument;
public: public:
QJsonParser(const char *begin, const char *end); QJsonParser(const char *begin, const char *end);
public: public:
QJsonRoot *parse(); QJsonRoot *parse();
public: public:
QJsonParseError state() const; QJsonParseError state() const;
private: private:
static const char ArrayBegin = '['; static const char ArrayBegin = '[';
static const char ArrayEnd = ']'; static const char ArrayEnd = ']';
static const char NameSeparator = ':'; static const char NameSeparator = ':';
static const char ValueSeparator = ','; static const char ValueSeparator = ',';
static const char ObjectBegin = '{'; static const char ObjectBegin = '{';
static const char ObjectEnd = '}'; static const char ObjectEnd = '}';
static const char Quote = '"'; static const char Quote = '"';
private: private:
char peek(); char peek();
QJsonObject *getObject(); QJsonObject *getObject();
QJsonArray *getArray(); QJsonArray *getArray();
QJsonValue getValue(); QJsonValue getValue();
QString getString(); QString getString();
QJsonValue getTrue(); QJsonValue getTrue();
QJsonValue getFalse(); QJsonValue getFalse();
QJsonValue getNull(); QJsonValue getNull();
QJsonValue getNumber(); QJsonValue getNumber();
QPair<QString, QJsonValue> getPair(); QPair<QString, QJsonValue> getPair();
private: private:
void throwError(QJsonParseError::ParseError e); void throwError(QJsonParseError::ParseError e);
private: private:
QJsonParseError state_; QJsonParseError state_;
const char *const begin_; const char *const begin_;
const char *const end_; const char *const end_;
const char * p_; const char * p_;
}; };
#endif #endif
#endif #endif

View File

@ -1 +1 @@
#include "QJsonRoot.h" #include "QJsonRoot.h"

View File

@ -1,45 +1,45 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping * Copyright (C) 2016 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef QJSON_ROOT_H_ #ifndef QJSON_ROOT_H_
#define QJSON_ROOT_H_ #define QJSON_ROOT_H_
#include <QtCore/QtGlobal> #include <QtCore/QtGlobal>
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
class QJsonObject; class QJsonObject;
class QJsonArray; class QJsonArray;
class QJsonRoot { class QJsonRoot {
public: public:
virtual ~QJsonRoot() {}; virtual ~QJsonRoot() {};
public: public:
virtual QJsonRoot *clone() const = 0; virtual QJsonRoot *clone() const = 0;
public: public:
virtual QJsonArray *toArray() = 0; virtual QJsonArray *toArray() = 0;
virtual QJsonObject *toObject() = 0; virtual QJsonObject *toObject() = 0;
virtual const QJsonArray *toArray() const = 0; virtual const QJsonArray *toArray() const = 0;
virtual const QJsonObject *toObject() const = 0; virtual const QJsonObject *toObject() const = 0;
}; };
#endif #endif
#endif #endif

View File

@ -1 +1 @@
#include "QJsonValue.h" #include "QJsonValue.h"

View File

@ -1,391 +1,391 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping * Copyright (C) 2016 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "QJsonValue.h" #include "QJsonValue.h"
#include "QJsonArray.h" #include "QJsonArray.h"
#include "QJsonObject.h" #include "QJsonObject.h"
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
#include <QtCore/QtAlgorithms> #include <QtCore/QtAlgorithms>
#include <QtCore/qmath.h> #include <QtCore/qmath.h>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonValue // Name: QJsonValue
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue::QJsonValue(Type type) : type_(type) { QJsonValue::QJsonValue(Type type) : type_(type) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonValue // Name: QJsonValue
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue::QJsonValue(bool b) : type_(Bool) { QJsonValue::QJsonValue(bool b) : type_(Bool) {
value_.b = b; value_.b = b;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonValue // Name: QJsonValue
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue::QJsonValue(double n) : type_(Double) { QJsonValue::QJsonValue(double n) : type_(Double) {
value_.n = n; value_.n = n;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonValue // Name: QJsonValue
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue::QJsonValue(const QString &s) : type_(String) { QJsonValue::QJsonValue(const QString &s) : type_(String) {
value_.s = new QString(s); value_.s = new QString(s);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonValue // Name: QJsonValue
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue::QJsonValue(QLatin1String s) : type_(String) { QJsonValue::QJsonValue(QLatin1String s) : type_(String) {
value_.s = new QString(s); value_.s = new QString(s);
} }
#ifndef QT_NO_CAST_FROM_ASCII #ifndef QT_NO_CAST_FROM_ASCII
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonValue // Name: QJsonValue
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue::QJsonValue(const char *s) : type_(String) { QJsonValue::QJsonValue(const char *s) : type_(String) {
value_.s = new QString(QString::fromUtf8(s)); value_.s = new QString(QString::fromUtf8(s));
} }
#endif #endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonValue // Name: QJsonValue
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue::QJsonValue(const QJsonArray &a) : type_(Array) { QJsonValue::QJsonValue(const QJsonArray &a) : type_(Array) {
value_.r = a.clone(); value_.r = a.clone();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonValue // Name: QJsonValue
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue::QJsonValue(const QJsonObject &o) : type_(Object) { QJsonValue::QJsonValue(const QJsonObject &o) : type_(Object) {
value_.r = o.clone(); value_.r = o.clone();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonValue // Name: QJsonValue
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue::QJsonValue(int n) : type_(Double) { QJsonValue::QJsonValue(int n) : type_(Double) {
value_.n = n; value_.n = n;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonValue // Name: QJsonValue
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue::QJsonValue(qint64 n) : type_(Double) { QJsonValue::QJsonValue(qint64 n) : type_(Double) {
value_.n = n; value_.n = n;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonValue // Name: QJsonValue
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue::QJsonValue(const QJsonValue &other) : type_(other.type_) { QJsonValue::QJsonValue(const QJsonValue &other) : type_(other.type_) {
switch(other.type_) { switch(other.type_) {
case Bool: case Bool:
value_.b = other.value_.b; value_.b = other.value_.b;
break; break;
case Double: case Double:
value_.n = other.value_.n; value_.n = other.value_.n;
break; break;
case String: case String:
value_.s = new QString(*other.value_.s); value_.s = new QString(*other.value_.s);
break; break;
case Array: case Array:
case Object: case Object:
value_.r = other.value_.r->clone(); value_.r = other.value_.r->clone();
break; break;
case Undefined: case Undefined:
case Null: case Null:
value_ = other.value_; value_ = other.value_;
break; break;
} }
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: ~QJsonValue // Name: ~QJsonValue
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue::~QJsonValue() { QJsonValue::~QJsonValue() {
switch(type_) { switch(type_) {
case Null: case Null:
case Bool: case Bool:
case Double: case Double:
case Undefined: case Undefined:
break; break;
case String: case String:
delete value_.s; delete value_.s;
break; break;
case Object: case Object:
case Array: case Array:
delete value_.r; delete value_.r;
break; break;
} }
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator= // Name: operator=
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue &QJsonValue::operator=(const QJsonValue &other) { QJsonValue &QJsonValue::operator=(const QJsonValue &other) {
QJsonValue(other).swap(*this); QJsonValue(other).swap(*this);
return *this; return *this;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator!= // Name: operator!=
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValue::operator!=(const QJsonValue &other) const { bool QJsonValue::operator!=(const QJsonValue &other) const {
return !(*this == other); return !(*this == other);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator== // Name: operator==
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValue::operator==(const QJsonValue &other) const { bool QJsonValue::operator==(const QJsonValue &other) const {
if(type_ == other.type_) { if(type_ == other.type_) {
switch(type_) { switch(type_) {
case Null: case Null:
return true; return true;
case Bool: case Bool:
return value_.b == other.value_.b; return value_.b == other.value_.b;
case Double: case Double:
return value_.n == other.value_.n; return value_.n == other.value_.n;
case Undefined: case Undefined:
return true; return true;
case String: case String:
return *value_.s == *other.value_.s; return *value_.s == *other.value_.s;
case Array: case Array:
return *(value_.r->toArray()) == *(other.value_.r->toArray()); return *(value_.r->toArray()) == *(other.value_.r->toArray());
case Object: case Object:
return *(value_.r->toObject()) == *(other.value_.r->toObject()); return *(value_.r->toObject()) == *(other.value_.r->toObject());
} }
} }
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isArray // Name: isArray
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValue::isArray() const { bool QJsonValue::isArray() const {
return type_ == Array; return type_ == Array;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isBool // Name: isBool
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValue::isBool() const { bool QJsonValue::isBool() const {
return type_ == Bool; return type_ == Bool;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isDouble // Name: isDouble
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValue::isDouble() const { bool QJsonValue::isDouble() const {
return type_ == Double; return type_ == Double;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isNull // Name: isNull
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValue::isNull() const { bool QJsonValue::isNull() const {
return type_ == Null; return type_ == Null;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isObject // Name: isObject
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValue::isObject() const { bool QJsonValue::isObject() const {
return type_ == Object; return type_ == Object;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isString // Name: isString
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValue::isString() const { bool QJsonValue::isString() const {
return type_ == String; return type_ == String;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isUndefined // Name: isUndefined
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValue::isUndefined() const { bool QJsonValue::isUndefined() const {
return type_ == Undefined; return type_ == Undefined;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: type // Name: type
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue::Type QJsonValue::type() const { QJsonValue::Type QJsonValue::type() const {
return type_; return type_;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toArray // Name: toArray
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray QJsonValue::toArray(const QJsonArray &defaultValue) const { QJsonArray QJsonValue::toArray(const QJsonArray &defaultValue) const {
if(isArray()) { if(isArray()) {
return *(value_.r->toArray()); return *(value_.r->toArray());
} }
return defaultValue; return defaultValue;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toArray // Name: toArray
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray QJsonValue::toArray() const { QJsonArray QJsonValue::toArray() const {
return toArray(QJsonArray()); return toArray(QJsonArray());
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toBool // Name: toBool
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValue::toBool(bool defaultValue) const { bool QJsonValue::toBool(bool defaultValue) const {
if(isBool()) { if(isBool()) {
return value_.b; return value_.b;
} }
return defaultValue; return defaultValue;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toDouble // Name: toDouble
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
double QJsonValue::toDouble(double defaultValue) const { double QJsonValue::toDouble(double defaultValue) const {
if(isDouble()) { if(isDouble()) {
return value_.n; return value_.n;
} }
return defaultValue; return defaultValue;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toInt // Name: toInt
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int QJsonValue::toInt(int defaultValue) const { int QJsonValue::toInt(int defaultValue) const {
if(isDouble() && qFloor(value_.n) == value_.n) { if(isDouble() && qFloor(value_.n) == value_.n) {
return value_.n; return value_.n;
} }
return defaultValue; return defaultValue;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toObject // Name: toObject
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject QJsonValue::toObject(const QJsonObject &defaultValue) const { QJsonObject QJsonValue::toObject(const QJsonObject &defaultValue) const {
if(isObject()) { if(isObject()) {
return *(value_.r->toObject()); return *(value_.r->toObject());
} }
return defaultValue; return defaultValue;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toObject // Name: toObject
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject QJsonValue::toObject() const { QJsonObject QJsonValue::toObject() const {
return toObject(QJsonObject()); return toObject(QJsonObject());
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toString // Name: toString
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QString QJsonValue::toString(const QString &defaultValue) const { QString QJsonValue::toString(const QString &defaultValue) const {
if(isString()) { if(isString()) {
return *value_.s; return *value_.s;
} }
return defaultValue; return defaultValue;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toVariant // Name: toVariant
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QVariant QJsonValue::toVariant() const { QVariant QJsonValue::toVariant() const {
switch(type_) { switch(type_) {
case Null: case Null:
return QVariant(); return QVariant();
case Bool: case Bool:
return QVariant::fromValue(value_.b); return QVariant::fromValue(value_.b);
case Double: case Double:
return QVariant::fromValue(value_.n); return QVariant::fromValue(value_.n);
case String: case String:
return QVariant::fromValue(*value_.s); return QVariant::fromValue(*value_.s);
case Array: case Array:
return value_.r->toArray()->toVariantList(); return value_.r->toArray()->toVariantList();
case Object: case Object:
return value_.r->toObject()->toVariantMap(); return value_.r->toObject()->toVariantMap();
case Undefined: case Undefined:
return QVariant(); return QVariant();
} }
return QVariant(); return QVariant();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: fromVariant // Name: fromVariant
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue QJsonValue::fromVariant(const QVariant &variant) { QJsonValue QJsonValue::fromVariant(const QVariant &variant) {
if(variant.isNull()) { if(variant.isNull()) {
return QJsonValue(Null); return QJsonValue(Null);
} }
switch(variant.type()) { switch(variant.type()) {
case QVariant::Bool: case QVariant::Bool:
return QJsonValue(variant.toBool()); return QJsonValue(variant.toBool());
case QVariant::Int: case QVariant::Int:
return QJsonValue(variant.toInt()); return QJsonValue(variant.toInt());
case QVariant::Double: case QVariant::Double:
case QVariant::LongLong: case QVariant::LongLong:
case QVariant::ULongLong: case QVariant::ULongLong:
case QVariant::UInt: case QVariant::UInt:
return QJsonValue(variant.toDouble()); return QJsonValue(variant.toDouble());
case QVariant::String: case QVariant::String:
return QJsonValue(variant.toString()); return QJsonValue(variant.toString());
case QVariant::List: case QVariant::List:
return QJsonArray::fromVariantList(variant.toList()); return QJsonArray::fromVariantList(variant.toList());
case QVariant::StringList: case QVariant::StringList:
return QJsonArray::fromStringList(variant.toStringList()); return QJsonArray::fromStringList(variant.toStringList());
case QVariant::Map: case QVariant::Map:
return QJsonObject::fromVariantMap(variant.toMap()); return QJsonObject::fromVariantMap(variant.toMap());
default: default:
const QString s = variant.toString(); const QString s = variant.toString();
if(!s.isEmpty()) { if(!s.isEmpty()) {
return QJsonValue(s); return QJsonValue(s);
} }
break; break;
} }
return QJsonValue(Null); return QJsonValue(Null);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: swap // Name: swap
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonValue::swap(QJsonValue &other) { void QJsonValue::swap(QJsonValue &other) {
qSwap(type_, other.type_); qSwap(type_, other.type_);
qSwap(value_, other.value_); qSwap(value_, other.value_);
} }
#endif #endif

View File

@ -1,120 +1,120 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping * Copyright (C) 2016 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef QJSON_VALUE_H_ #ifndef QJSON_VALUE_H_
#define QJSON_VALUE_H_ #define QJSON_VALUE_H_
#include <QtCore/QtGlobal> #include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
#include <QtCore/QJsonValue> #include <QtCore/QJsonValue>
#else #else
class QString; class QString;
#include <QtCore/QVariant> #include <QtCore/QVariant>
class QJsonRoot; class QJsonRoot;
class QJsonArray; class QJsonArray;
class QJsonObject; class QJsonObject;
class QJsonValue { class QJsonValue {
public: public:
enum Type { enum Type {
Null = 0x0, Null = 0x0,
Bool = 0x1, Bool = 0x1,
Double = 0x2, Double = 0x2,
String = 0x3, String = 0x3,
Array = 0x4, Array = 0x4,
Object = 0x5, Object = 0x5,
Undefined = 0x80 Undefined = 0x80
}; };
public: public:
QJsonValue(Type type = Null); QJsonValue(Type type = Null);
QJsonValue(bool b); QJsonValue(bool b);
QJsonValue(double n); QJsonValue(double n);
QJsonValue(int n); QJsonValue(int n);
QJsonValue(qint64 n); QJsonValue(qint64 n);
QJsonValue(const QString &s); QJsonValue(const QString &s);
QJsonValue(QLatin1String s); QJsonValue(QLatin1String s);
#ifndef QT_NO_CAST_FROM_ASCII #ifndef QT_NO_CAST_FROM_ASCII
QJsonValue(const char *s); QJsonValue(const char *s);
#endif #endif
QJsonValue(const QJsonArray &a); QJsonValue(const QJsonArray &a);
QJsonValue(const QJsonObject &o); QJsonValue(const QJsonObject &o);
QJsonValue(const QJsonValue &other); QJsonValue(const QJsonValue &other);
~QJsonValue(); ~QJsonValue();
private: private:
// to protect against incorrect usage due to passing a const char * // to protect against incorrect usage due to passing a const char *
QJsonValue(const void *); QJsonValue(const void *);
public: public:
QJsonValue &operator=(const QJsonValue &other); QJsonValue &operator=(const QJsonValue &other);
public: public:
bool operator!=(const QJsonValue &other) const; bool operator!=(const QJsonValue &other) const;
bool operator==(const QJsonValue &other) const; bool operator==(const QJsonValue &other) const;
public: public:
bool isArray() const; bool isArray() const;
bool isBool() const; bool isBool() const;
bool isDouble() const; bool isDouble() const;
bool isNull() const; bool isNull() const;
bool isObject() const; bool isObject() const;
bool isString() const; bool isString() const;
bool isUndefined() const; bool isUndefined() const;
public: public:
QJsonArray toArray(const QJsonArray &defaultValue) const; QJsonArray toArray(const QJsonArray &defaultValue) const;
QJsonArray toArray() const; QJsonArray toArray() const;
bool toBool(bool defaultValue = false) const; bool toBool(bool defaultValue = false) const;
double toDouble(double defaultValue = 0) const; double toDouble(double defaultValue = 0) const;
int toInt(int defaultValue = 0) const; int toInt(int defaultValue = 0) const;
QJsonObject toObject(const QJsonObject &defaultValue) const; QJsonObject toObject(const QJsonObject &defaultValue) const;
QJsonObject toObject() const; QJsonObject toObject() const;
QString toString(const QString &defaultValue = QString()) const; QString toString(const QString &defaultValue = QString()) const;
QVariant toVariant() const; QVariant toVariant() const;
public: public:
Type type() const; Type type() const;
public: public:
static QJsonValue fromVariant(const QVariant &variant); static QJsonValue fromVariant(const QVariant &variant);
private: private:
void swap(QJsonValue &other); void swap(QJsonValue &other);
private: private:
Type type_; Type type_;
union ValueType { union ValueType {
bool b; bool b;
double n; double n;
QString *s; QString *s;
QJsonRoot *r; // OJsonObject or QJsonArray QJsonRoot *r; // OJsonObject or QJsonArray
}; };
ValueType value_; ValueType value_;
}; };
#endif #endif
#endif #endif

View File

@ -1 +1 @@
#include "QJsonValueRef.h" #include "QJsonValueRef.h"

View File

@ -1,228 +1,228 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping * Copyright (C) 2016 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "QJsonValueRef.h" #include "QJsonValueRef.h"
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
#include "QJsonArray.h" #include "QJsonArray.h"
#include "QJsonObject.h" #include "QJsonObject.h"
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValueRef::QJsonValueRef(QJsonArray *array, int idx) : p_(array), index_(idx) { QJsonValueRef::QJsonValueRef(QJsonArray *array, int idx) : p_(array), index_(idx) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValueRef::QJsonValueRef(QJsonObject *object, const QString &key) : p_(object), index_(0), key_(key) { QJsonValueRef::QJsonValueRef(QJsonObject *object, const QString &key) : p_(object), index_(0), key_(key) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValueRef::operator QJsonValue() const { QJsonValueRef::operator QJsonValue() const {
return toValue(); return toValue();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValueRef &QJsonValueRef::operator=(const QJsonValue &val) { QJsonValueRef &QJsonValueRef::operator=(const QJsonValue &val) {
if(QJsonObject *const o = p_->toObject()) { if(QJsonObject *const o = p_->toObject()) {
o->values_[key_] = val; o->values_[key_] = val;
} else if(QJsonArray *const a = p_->toArray()) { } else if(QJsonArray *const a = p_->toArray()) {
a->values_[index_] = val; a->values_[index_] = val;
} }
return *this; return *this;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: // Name:
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValueRef &QJsonValueRef::operator=(const QJsonValueRef &ref) { QJsonValueRef &QJsonValueRef::operator=(const QJsonValueRef &ref) {
if(QJsonObject *const o = p_->toObject()) { if(QJsonObject *const o = p_->toObject()) {
o->values_[key_] = ref; o->values_[key_] = ref;
} else if(QJsonArray *const a = p_->toArray()) { } else if(QJsonArray *const a = p_->toArray()) {
a->values_[index_] = ref; a->values_[index_] = ref;
} }
return *this; return *this;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: type // Name: type
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue::Type QJsonValueRef::type() const { QJsonValue::Type QJsonValueRef::type() const {
return toValue().type(); return toValue().type();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isNull // Name: isNull
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValueRef::isNull() const { bool QJsonValueRef::isNull() const {
return toValue().isNull(); return toValue().isNull();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isBool // Name: isBool
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValueRef::isBool() const { bool QJsonValueRef::isBool() const {
return toValue().isBool(); return toValue().isBool();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isDouble // Name: isDouble
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValueRef::isDouble() const { bool QJsonValueRef::isDouble() const {
return toValue().isDouble(); return toValue().isDouble();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isString // Name: isString
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValueRef::isString() const { bool QJsonValueRef::isString() const {
return toValue().isString(); return toValue().isString();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isArray // Name: isArray
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValueRef::isArray() const { bool QJsonValueRef::isArray() const {
return toValue().isArray(); return toValue().isArray();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isObject // Name: isObject
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValueRef::isObject() const { bool QJsonValueRef::isObject() const {
return toValue().isObject(); return toValue().isObject();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isUndefined // Name: isUndefined
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValueRef::isUndefined() const { bool QJsonValueRef::isUndefined() const {
return toValue().isUndefined(); return toValue().isUndefined();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toBool // Name: toBool
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValueRef::toBool() const { bool QJsonValueRef::toBool() const {
return toValue().toBool(); return toValue().toBool();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toDouble // Name: toDouble
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
double QJsonValueRef::toDouble() const { double QJsonValueRef::toDouble() const {
return toValue().toDouble(); return toValue().toDouble();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toInt // Name: toInt
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int QJsonValueRef::toInt(int defaultValue) const { int QJsonValueRef::toInt(int defaultValue) const {
return toValue().toInt(defaultValue); return toValue().toInt(defaultValue);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toString // Name: toString
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QString QJsonValueRef::toString() const { QString QJsonValueRef::toString() const {
return toValue().toString(); return toValue().toString();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toArray // Name: toArray
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray QJsonValueRef::toArray() const { QJsonArray QJsonValueRef::toArray() const {
return toValue().toArray(); return toValue().toArray();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toObject // Name: toObject
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject QJsonValueRef::toObject() const { QJsonObject QJsonValueRef::toObject() const {
return toValue().toObject(); return toValue().toObject();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator== // Name: operator==
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValueRef::operator==(const QJsonValue &other) const { bool QJsonValueRef::operator==(const QJsonValue &other) const {
return toValue() == other; return toValue() == other;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator!= // Name: operator!=
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonValueRef::operator!=(const QJsonValue &other) const { bool QJsonValueRef::operator!=(const QJsonValue &other) const {
return toValue() != other; return toValue() != other;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toValue // Name: toValue
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonValue QJsonValueRef::toValue() const { QJsonValue QJsonValueRef::toValue() const {
if(QJsonObject *const o = p_->toObject()) { if(QJsonObject *const o = p_->toObject()) {
return o->values_[key_]; return o->values_[key_];
} else if(QJsonArray *const a = p_->toArray()) { } else if(QJsonArray *const a = p_->toArray()) {
return a->values_[index_]; return a->values_[index_];
} }
return QJsonValue(); return QJsonValue();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: swap // Name: swap
// Desc: // Desc:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonValueRef::swap(QJsonValueRef &other) { void QJsonValueRef::swap(QJsonValueRef &other) {
qSwap(p_, other.p_); qSwap(p_, other.p_);
qSwap(key_, other.key_); qSwap(key_, other.key_);
qSwap(index_, other.index_); qSwap(index_, other.index_);
} }
#endif #endif

View File

@ -1,79 +1,79 @@
/***************************************************************************** /*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC * gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping * Copyright (C) 2016 Syping
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#ifndef QJSON_VALUEREF_H_ #ifndef QJSON_VALUEREF_H_
#define QJSON_VALUEREF_H_ #define QJSON_VALUEREF_H_
#include <QtCore/QtGlobal> #include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
#include <QtCore/QJsonValueRef> #include <QtCore/QJsonValueRef>
#else #else
#include "QJsonValue.h" #include "QJsonValue.h"
class QJsonRoot; class QJsonRoot;
class QJsonValueRef { class QJsonValueRef {
public: public:
QJsonValueRef(QJsonArray *array, int idx); QJsonValueRef(QJsonArray *array, int idx);
// slight variant from official APIs implementation // slight variant from official APIs implementation
QJsonValueRef(QJsonObject *object, const QString &key); QJsonValueRef(QJsonObject *object, const QString &key);
public: public:
operator QJsonValue() const; operator QJsonValue() const;
public: public:
QJsonValueRef &operator=(const QJsonValue &val); QJsonValueRef &operator=(const QJsonValue &val);
QJsonValueRef &operator=(const QJsonValueRef &val); QJsonValueRef &operator=(const QJsonValueRef &val);
public: public:
QJsonValue::Type type() const; QJsonValue::Type type() const;
bool isNull() const; bool isNull() const;
bool isBool() const; bool isBool() const;
bool isDouble() const; bool isDouble() const;
bool isString() const; bool isString() const;
bool isArray() const; bool isArray() const;
bool isObject() const; bool isObject() const;
bool isUndefined() const; bool isUndefined() const;
public: public:
bool toBool() const; bool toBool() const;
double toDouble() const; double toDouble() const;
QString toString() const; QString toString() const;
QJsonArray toArray() const; QJsonArray toArray() const;
QJsonObject toObject() const; QJsonObject toObject() const;
int toInt(int defaultValue = 0) const; int toInt(int defaultValue = 0) const;
public: public:
bool operator==(const QJsonValue &other) const; bool operator==(const QJsonValue &other) const;
bool operator!=(const QJsonValue &other) const; bool operator!=(const QJsonValue &other) const;
private: private:
QJsonValue toValue() const; QJsonValue toValue() const;
void swap(QJsonValueRef &other); void swap(QJsonValueRef &other);
private: private:
QJsonRoot *p_; QJsonRoot *p_;
int index_; int index_;
QString key_; QString key_;
}; };
#endif #endif
#endif #endif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Some files were not shown because too many files have changed in this diff Show More