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
env:
- PACKAGE_VERSION="1.4.0"
- PACKAGE_VERSION="1.5.0"
before_install:
- test -n $CC && unset CC
@ -12,27 +12,42 @@ before_install:
install:
- 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:
- 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
- echo "gta5view build version is $APPLICATION_VERSION"
- mkdir build
- mkdir package
- chmod -x res/gta5sync_*.qm res/gta5view.desktop res/gta5view.png
- cd build
- mkdir qt4
- cd qt4
- 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:
- 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
- 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:
provider: releases
api_key:
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
on:
tags: true

View file

@ -1,121 +1,125 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 <QStringBuilder>
#include "AboutDialog.h"
#include "ui_AboutDialog.h"
#include "AppEnv.h"
#include "config.h"
AboutDialog::AboutDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::AboutDialog)
{
// Set Window Flags
setWindowFlags(windowFlags()^Qt::WindowContextHelpButtonHint);
// Build Strings
QString appVersion = qApp->applicationVersion();
QString buildType = GTA5SYNC_BUILDTYPE;
buildType.replace("_", " ");
QString projectBuild = GTA5SYNC_BUILDDATETIME;
QString buildStr = GTA5SYNC_BUILDSTRING;
// Additional Content
QString usingStr = tr("Using %1 %2", "Exp. Using libmyfuck");
QString translatedByStr = tr("Translated by %1", "Exp. Translated by Syping");
QString translatedByVal = tr("NAME_OF_TRANSLATOR", "Your Name (The person behind your screen looking at this text!)");
QString translatorProfile = tr("TRANSLATOR_PROFILE", "mailto: http:// https:// Exp. https://github.com/Syping/");
QString additionalContent = "";
if (translatedByVal != "NAME_OF_TRANSLATOR")
{
if (translatorProfile != "TRANSLATOR_PROFILE")
{
additionalContent.append(translatedByStr.arg(QString("<a href=\"%1\">%2</a>").arg(translatorProfile, translatedByVal)));
}
else
{
additionalContent.append(translatedByStr.arg(translatedByVal));
}
}
#ifdef WITH_LIBJPEGTURBO // DONT USE IT FOR NOW
bool additionalContentClip = false;
if (!additionalContent.isEmpty())
{
additionalContentClip = true;
additionalContent.append(" (");
}
additionalContent.append(usingStr.arg("libjpegturbo", WITH_LIBJPEGTURBO));
if (additionalContentClip)
{
additionalContent.append(")");
}
#else
Q_UNUSED(usingStr)
#endif
// Project Description
#ifdef GTA5SYNC_ENABLED
QString projectDes = tr("A project for viewing and sync Grand Theft Auto V Snapmatic<br/>\nPictures and Savegames");
#else
QString projectDes = tr("A project for viewing Grand Theft Auto V Snapmatic<br/>\nPictures and Savegames");
#endif
// Copyright Description
QString copyrightDes1 = tr("Copyright &copy; <a href=\"%1\">%2</a> %3");
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>");
copyrightDes2 = copyrightDes2.arg(GTA5SYNC_APPSTR);
QString copyrightDesA;
if (!additionalContent.isEmpty())
{
copyrightDesA = copyrightDes1 % "<br/>" % additionalContent % "<br/>" % copyrightDes2;
}
else
{
copyrightDesA = copyrightDes1 % "<br/>" % copyrightDes2;
}
// Setup User Interface
ui->setupUi(this);
aboutStr = ui->labAbout->text();
titleStr = this->windowTitle();
ui->labAbout->setText(aboutStr.arg(GTA5SYNC_APPSTR, projectDes, appVersion % " (" % buildType % ")", projectBuild, buildStr, qVersion(), copyrightDesA));
this->setWindowTitle(titleStr.arg(GTA5SYNC_APPSTR));
if (QIcon::hasThemeIcon("dialog-close"))
{
ui->cmdClose->setIcon(QIcon::fromTheme("dialog-close"));
}
// DPI calculation
qreal screenRatio = AppEnv::screenRatio();
if (!additionalContent.isEmpty())
{
resize(375 * screenRatio, 270 * screenRatio);
}
else
{
resize(375 * screenRatio, 260 * screenRatio);
}
}
AboutDialog::~AboutDialog()
{
delete ui;
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 <QStringBuilder>
#include "AboutDialog.h"
#include "ui_AboutDialog.h"
#include "AppEnv.h"
#include "config.h"
AboutDialog::AboutDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::AboutDialog)
{
// Set Window Flags
setWindowFlags(windowFlags()^Qt::WindowContextHelpButtonHint);
// Build Strings
QString appVersion = qApp->applicationVersion();
QString buildType = tr(GTA5SYNC_BUILDTYPE);
buildType.replace("_", " ");
QString projectBuild = GTA5SYNC_BUILDDATETIME;
QString buildStr = GTA5SYNC_BUILDSTRING;
// Translator Comments
//: Using specific library, example Using libmyfuck
QString usingStr = tr("Using %1 %2");
//: Translated by translator, example Translated by Syping
QString translatedByStr = tr("Translated by %1");
//: Enter your name there
QString translatedByVal = tr("NAME_OF_TRANSLATOR");
//: Enter your proilfe there, example a GitHub profile, E-Mail with "mailto: afucker@sumfuck.com" or a webpage
QString translatorProfile = tr("TRANSLATOR_PROFILE");
QString additionalContent = "";
if (translatedByVal != "NAME_OF_TRANSLATOR")
{
if (translatorProfile != "TRANSLATOR_PROFILE")
{
additionalContent += translatedByStr.arg(QString("<a href=\"%1\">%2</a>").arg(translatorProfile, translatedByVal));
}
else
{
additionalContent += translatedByStr.arg(translatedByVal);
}
}
#ifdef WITH_LIBJPEGTURBO // DONT USE IT FOR NOW
bool additionalContentClip = false;
if (!additionalContent.isEmpty())
{
additionalContentClip = true;
additionalContent += " (";
}
additionalContent += usingStr.arg("libjpegturbo", WITH_LIBJPEGTURBO);
if (additionalContentClip)
{
additionalContent += ")";
}
#else
Q_UNUSED(usingStr)
#endif
// Project Description
#ifdef GTA5SYNC_ENABLED
QString projectDes = tr("A project for viewing and sync Grand Theft Auto V Snapmatic<br/>\nPictures and Savegames");
#else
QString projectDes = tr("A project for viewing Grand Theft Auto V Snapmatic<br/>\nPictures and Savegames");
#endif
// Copyright Description
QString copyrightDes1 = tr("Copyright &copy; <a href=\"%1\">%2</a> %3");
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>");
copyrightDes2 = copyrightDes2.arg(GTA5SYNC_APPSTR);
QString copyrightDesA;
if (!additionalContent.isEmpty())
{
copyrightDesA = copyrightDes1 % "<br/>" % additionalContent % "<br/>" % copyrightDes2;
}
else
{
copyrightDesA = copyrightDes1 % "<br/>" % copyrightDes2;
}
// Setup User Interface
ui->setupUi(this);
aboutStr = ui->labAbout->text();
titleStr = this->windowTitle();
ui->labAbout->setText(aboutStr.arg(GTA5SYNC_APPSTR, projectDes, appVersion % " (" % buildType % ")", projectBuild, buildStr, qVersion(), copyrightDesA));
this->setWindowTitle(titleStr.arg(GTA5SYNC_APPSTR));
if (QIcon::hasThemeIcon("dialog-close"))
{
ui->cmdClose->setIcon(QIcon::fromTheme("dialog-close"));
}
// DPI calculation
qreal screenRatio = AppEnv::screenRatio();
if (!additionalContent.isEmpty())
{
resize(375 * screenRatio, 270 * screenRatio);
}
else
{
resize(375 * screenRatio, 260 * screenRatio);
}
}
AboutDialog::~AboutDialog()
{
delete ui;
}

View file

@ -1,44 +1,44 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 ABOUTDIALOG_H
#define ABOUTDIALOG_H
#include <QDialog>
namespace Ui {
class AboutDialog;
}
class AboutDialog : public QDialog
{
Q_OBJECT
public:
explicit AboutDialog(QWidget *parent = 0);
~AboutDialog();
private slots:
private:
Ui::AboutDialog *ui;
QString aboutStr;
QString titleStr;
};
#endif // ABOUTDIALOG_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 ABOUTDIALOG_H
#define ABOUTDIALOG_H
#include <QDialog>
namespace Ui {
class AboutDialog;
}
class AboutDialog : public QDialog
{
Q_OBJECT
public:
explicit AboutDialog(QWidget *parent = 0);
~AboutDialog();
private slots:
private:
Ui::AboutDialog *ui;
QString aboutStr;
QString titleStr;
};
#endif // ABOUTDIALOG_H

View file

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

View file

@ -1,155 +1,178 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "config.h"
#include "AppEnv.h"
#include "StringParser.h"
#include "StandardPaths.h"
#include <QtGlobal>
#include <QDesktopWidget>
#include <QApplication>
#include <QSettings>
#include <QScreen>
#include <QDebug>
#include <QRect>
#include <QDir>
#include <iostream>
using namespace std;
AppEnv::AppEnv()
{
}
// Folder Stuff
QString AppEnv::getGameFolder(bool *ok)
{
QDir dir;
QString GTAV_FOLDER = QString::fromUtf8(qgetenv("GTAV_FOLDER"));
if (GTAV_FOLDER != "")
{
dir.setPath(GTAV_FOLDER);
if (dir.exists())
{
if (ok != NULL) *ok = true;
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;
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("dir");
bool forceDir = settings.value("force", false).toBool();
GTAV_returnFolder = settings.value("dir", GTAV_defaultFolder).toString();
settings.endGroup();
if (forceDir)
{
dir.setPath(GTAV_returnFolder);
if (dir.exists())
{
if (ok != 0) *ok = true;
qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8());
return dir.absolutePath();
}
}
dir.setPath(GTAV_defaultFolder);
if (dir.exists())
{
if (ok != 0) *ok = true;
qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8());
return dir.absolutePath();
}
if (!forceDir)
{
dir.setPath(GTAV_returnFolder);
if (dir.exists())
{
if (ok != 0) *ok = true;
qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8());
return dir.absolutePath();
}
}
if (ok != 0) *ok = false;
return "";
}
bool AppEnv::setGameFolder(QString gameFolder)
{
QDir dir;
dir.setPath(gameFolder);
if (dir.exists())
{
qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8());
return true;
}
return false;
}
QString AppEnv::getLangFolder()
{
return StringParser::convertBuildedString(QString::fromUtf8(GTA5SYNC_LANG));
}
QString AppEnv::getPluginsFolder()
{
return StringParser::convertBuildedString(QString::fromUtf8(GTA5SYNC_PLUG));
}
// Web Stuff
QByteArray AppEnv::getUserAgent()
{
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();
}
// QUrl AppEnv::getCrewFetchingUrl(QString crewID)
// {
// return QUrl(QString("https://socialclub.rockstargames.com/reference/crewfeed/%1").arg(crewID));
// }
QUrl AppEnv::getCrewFetchingUrl(QString crewID)
{
return QUrl(QString("https://socialclub.rockstargames.com/crew/%1/%1").arg(crewID));
}
QUrl AppEnv::getPlayerFetchingUrl(QString crewID, QString pageNumber)
{
return QUrl(QString("https://socialclub.rockstargames.com/crewsapi/GetMembersList?crewId=%1&pageNumber=%2").arg(crewID, 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
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "config.h"
#include "AppEnv.h"
#include "StringParser.h"
#include "StandardPaths.h"
#include <QtGlobal>
#include <QStringBuilder>
#include <QDesktopWidget>
#include <QApplication>
#include <QSettings>
#include <QScreen>
#include <QDebug>
#include <QRect>
#include <QDir>
#include <iostream>
using namespace std;
AppEnv::AppEnv()
{
}
// Folder Stuff
QString AppEnv::getGameFolder(bool *ok)
{
QDir dir;
QString GTAV_FOLDER = QString::fromUtf8(qgetenv("GTAV_FOLDER"));
if (GTAV_FOLDER != "")
{
dir.setPath(GTAV_FOLDER);
if (dir.exists())
{
if (ok != NULL) *ok = true;
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;
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("dir");
bool forceDir = settings.value("force", false).toBool();
GTAV_returnFolder = settings.value("dir", GTAV_defaultFolder).toString();
settings.endGroup();
if (forceDir)
{
dir.setPath(GTAV_returnFolder);
if (dir.exists())
{
if (ok != 0) *ok = true;
qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8());
return dir.absolutePath();
}
}
dir.setPath(GTAV_defaultFolder);
if (dir.exists())
{
if (ok != 0) *ok = true;
qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8());
return dir.absolutePath();
}
if (!forceDir)
{
dir.setPath(GTAV_returnFolder);
if (dir.exists())
{
if (ok != 0) *ok = true;
qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8());
return dir.absolutePath();
}
}
if (ok != 0) *ok = false;
return "";
}
bool AppEnv::setGameFolder(QString gameFolder)
{
QDir dir;
dir.setPath(gameFolder);
if (dir.exists())
{
qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8());
return true;
}
return false;
}
QString AppEnv::getExLangFolder()
{
return StringParser::convertBuildedString(GTA5SYNC_LANG);
}
QString AppEnv::getInLangFolder()
{
#ifdef GTA5SYNC_QCONF
#ifdef GTA5SYNC_INLANG
return StringParser::convertBuildedString(GTA5SYNC_INLANG);
#else
return StringParser::convertBuildedString(GTA5SYNC_SHARE % QLatin1String("SEPARATOR:APPNAME:SEPARATOR:translations"));
#endif
#else
#ifdef GTA5SYNC_INLANG
return StringParser::convertBuildedString(GTA5SYNC_INLANG);
#else
return QString(":/tr");
#endif
#endif
}
QString AppEnv::getPluginsFolder()
{
return StringParser::convertBuildedString(GTA5SYNC_PLUG);
}
// Web Stuff
QByteArray AppEnv::getUserAgent()
{
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();
}
// QUrl AppEnv::getCrewFetchingUrl(QString crewID)
// {
// return QUrl(QString("https://socialclub.rockstargames.com/reference/crewfeed/%1").arg(crewID));
// }
QUrl AppEnv::getCrewFetchingUrl(QString crewID)
{
return QUrl(QString("https://socialclub.rockstargames.com/crew/%1/%1").arg(crewID));
}
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
* Copyright (C) 2016-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 APPENV_H
#define APPENV_H
#include <QString>
#include <QUrl>
class AppEnv
{
public:
AppEnv();
// Folder Stuff
static QString getGameFolder(bool *ok = 0);
static bool setGameFolder(QString gameFolder);
static QString getLangFolder();
static QString getPluginsFolder();
// Web Stuff
static QByteArray getUserAgent();
static QUrl getCrewFetchingUrl(QString crewID);
static QUrl getPlayerFetchingUrl(QString crewID, QString pageNumber);
// Screen Stuff
static qreal screenRatio();
};
#endif // APPENV_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 APPENV_H
#define APPENV_H
#include <QString>
#include <QUrl>
class AppEnv
{
public:
AppEnv();
// Folder Stuff
static QString getGameFolder(bool *ok = 0);
static bool setGameFolder(QString gameFolder);
static QString getExLangFolder();
static QString getInLangFolder();
static QString getPluginsFolder();
// Web Stuff
static QByteArray getUserAgent();
static QUrl getCrewFetchingUrl(QString crewID);
static QUrl getPlayerFetchingUrl(QString crewID, QString pageNumber);
static QUrl getPlayerFetchingUrl(QString crewID, int pageNumber);
// Screen Stuff
static qreal screenRatio();
};
#endif // APPENV_H

View file

@ -1,83 +1,165 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "StandardPaths.h"
#include "CrewDatabase.h"
#include "config.h"
#include <QFile>
#include <QDir>
CrewDatabase::CrewDatabase(QObject *parent) : QObject(parent)
{
QDir dir;
dir.mkpath(StandardPaths::dataLocation());
dir.setPath(StandardPaths::dataLocation());
QString dirPath = dir.absolutePath();
QString defaultConfPath = dirPath + QDir::separator() + "crews.ini";
QSettings confPathSettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
confPathSettings.beginGroup("Database");
QString confPathFile = confPathSettings.value("Crews", defaultConfPath).toString();
confPathSettings.endGroup();
crewDB = new QSettings(confPathFile, QSettings::IniFormat);
crewDB->beginGroup("Crews");
}
CrewDatabase::~CrewDatabase()
{
crewDB->endGroup();
delete crewDB;
}
QStringList CrewDatabase::getCrews()
{
QStringList compatibleCrewList = crewDB->childKeys();
crewDB->endGroup();
crewDB->beginGroup("CrewList");
QStringList crewIDs = crewDB->value("IDs", QStringList()).toStringList();
crewIDs.append(compatibleCrewList);
crewIDs.removeDuplicates();
crewDB->endGroup();
crewDB->beginGroup("Crews");
return crewIDs;
}
QString CrewDatabase::getCrewName(int crewID)
{
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)
{
crewDB->setValue(QString::number(crewID), crewName);
}
void CrewDatabase::addCrew(int crewID)
{
QStringList crews = getCrews();
crews.append(QString::number(crewID));
crews.removeDuplicates();
crewDB->endGroup();
crewDB->beginGroup("CrewList");
crewDB->setValue("IDs", crews);
crewDB->endGroup();
crewDB->beginGroup("Crews");
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "StandardPaths.h"
#include "CrewDatabase.h"
#include "config.h"
#include <QStringBuilder>
#include <QMutexLocker>
#include <QDebug>
#include <QFile>
#include <QDir>
CrewDatabase::CrewDatabase(QObject *parent) : QObject(parent)
{
QDir dir;
dir.mkpath(StandardPaths::dataLocation());
dir.setPath(StandardPaths::dataLocation());
QString dirPath = dir.absolutePath();
QString defaultConfPath = dirPath % QDir::separator() % "crews.ini";
QSettings confPathSettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
confPathSettings.beginGroup("Database");
QString confPathFile = confPathSettings.value("Crews", defaultConfPath).toString();
confPathSettings.endGroup();
crewDB = new QSettings(confPathFile, QSettings::IniFormat);
crewDB->beginGroup("Crews");
addProcess = false;
}
CrewDatabase::~CrewDatabase()
{
crewDB->endGroup();
delete crewDB;
}
QStringList CrewDatabase::getCrews()
{
QMutexLocker locker(&mutex);
#ifdef GTA5SYNC_DEBUG
qDebug() << "getCrews";
#endif
return getCrews_p();
}
QStringList CrewDatabase::getCrews_p()
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "getCrews_p";
#endif
QStringList compatibleCrewList = getCompatibleCrews_p();
crewDB->endGroup();
crewDB->beginGroup("CrewList");
QStringList crewIDs = crewDB->value("IDs", QStringList()).toStringList();
crewIDs += compatibleCrewList;
crewIDs.removeDuplicates();
crewDB->endGroup();
crewDB->beginGroup("Crews");
return crewIDs;
}
QStringList CrewDatabase::getCompatibleCrews()
{
QMutexLocker locker(&mutex);
#ifdef GTA5SYNC_DEBUG
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
* Copyright (C) 2016-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 CREWDATABASE_H
#define CREWDATABASE_H
#include <QSettings>
#include <QObject>
#include <QMap>
class CrewDatabase : public QObject
{
Q_OBJECT
public:
explicit CrewDatabase(QObject *parent = 0);
void setCrewName(int crewID, QString crewName);
QString getCrewName(int crewID);
QStringList getCrews();
~CrewDatabase();
private:
QSettings *crewDB;
public slots:
void addCrew(int crewID);
};
#endif // CREWDATABASE_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 CREWDATABASE_H
#define CREWDATABASE_H
#include <QSettings>
#include <QObject>
#include <QMutex>
#include <QMap>
class CrewDatabase : public QObject
{
Q_OBJECT
public:
explicit CrewDatabase(QObject *parent = 0);
QString getCrewName(int crewID);
QStringList getCompatibleCrews();
QStringList getCrews();
void setAddingCrews(bool addingCrews);
bool isCompatibleCrew(QString crewNID);
bool isCompatibleCrew(int crewID);
bool isAddingCrews();
~CrewDatabase();
private:
mutable QMutex mutex;
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
* Copyright (C) 2016-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 "DatabaseThread.h"
#include "CrewDatabase.h"
#include "AppEnv.h"
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QJsonDocument>
#include <QJsonObject>
#include <QStringList>
#include <QVariantMap>
#include <QEventLoop>
#include <QTimer>
#include <QDebug>
#include <QUrl>
DatabaseThread::DatabaseThread(CrewDatabase *crewDB, QObject *parent) : QThread(parent), crewDB(crewDB)
{
crewMaxPages = 83;
threadRunning = true;
}
void DatabaseThread::run()
{
QEventLoop threadLoop;
QStringList crewList;
// Register thread loop end signal
QObject::connect(this, SIGNAL(threadEndCommited()), &threadLoop, SLOT(quit()));
// Quick time scan
if (crewList.length() <= 3)
{
scanCrewReference(crewList, 2500);
scanCrewMembersList(crewList, 3, 2500);
emit playerNameUpdated();
}
else if (crewList.length() <= 5)
{
scanCrewReference(crewList, 2500);
scanCrewMembersList(crewList, 2, 2500);
emit playerNameUpdated();
}
QEventLoop *waitingLoop = new QEventLoop();
QTimer::singleShot(10000, waitingLoop, SLOT(quit()));
QObject::connect(this, SIGNAL(threadEndCommited()), waitingLoop, SLOT(quit()));
waitingLoop->exec();
delete waitingLoop;
while (threadRunning)
{
crewList = crewDB->getCrews();
// Long time scan
scanCrewReference(crewList, 10000);
scanCrewMembersList(crewList, crewMaxPages, 10000);
emit playerNameUpdated();
if (threadRunning)
{
QTimer::singleShot(300000, &threadLoop, SLOT(quit()));
threadLoop.exec();
}
}
}
// void DatabaseThread::scanCrewReference(QStringList crewList, int requestDelay)
// {
// foreach (const QString &crewID, crewList)
// {
// if (threadRunning && crewID != "0")
// {
// QNetworkAccessManager *netManager = new QNetworkAccessManager();
// QNetworkRequest netRequest(AppEnv::getCrewFetchingUrl(crewID));
// 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");
// netRequest.setRawHeader("Connection", "keep-alive");
// 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()));
// QTimer::singleShot(30000, downloadLoop, SLOT(quit()));
// downloadLoop->exec();
// delete downloadLoop;
// if (netReply->isFinished())
// {
// QByteArray crewJson = netReply->readAll();
// QJsonDocument crewDocument = QJsonDocument::fromJson(crewJson);
// QJsonObject crewObject = crewDocument.object();
// QVariantMap crewMap = crewObject.toVariantMap();
// QString crewName;
// bool isFound = false;
// if (crewMap.contains("activities"))
// {
// QList<QVariant> activitiesList = crewMap["activities"].toList();
// foreach (const QVariant &activitiesVariant, activitiesList)
// {
// QMap<QString, QVariant> activityRootMap = activitiesVariant.toMap();
// foreach(const QVariant &activityRootVariant, activityRootMap)
// {
// QMap<QString, QVariant> activityMap = activityRootVariant.toMap();
// foreach(const QVariant &activityVariant, activityMap)
// {
// QMap<QString, QVariant> activityFinalMap = activityVariant.toMap();
// if (activityFinalMap.contains("id") && activityFinalMap["id"] == crewID)
// {
// if (activityFinalMap.contains("name") && isFound == false)
// {
// isFound = true;
// crewName = activityFinalMap["name"].toString();
// }
// }
// }
// }
// }
// }
// if (!crewName.isNull())
// {
// crewDB->setCrewName(crewID.toInt(), crewName);
// }
// }
// QEventLoop *waitingLoop = new QEventLoop();
// QTimer::singleShot(requestDelay, waitingLoop, SLOT(quit()));
// QObject::connect(this, SIGNAL(threadEndCommited()), waitingLoop, SLOT(quit()));
// waitingLoop->exec();
// delete waitingLoop;
// delete netReply;
// delete netManager;
// }
// }
// }
void DatabaseThread::scanCrewReference(QStringList crewList, int requestDelay)
{
foreach (const QString &crewID, crewList)
{
if (threadRunning && crewID != "0")
{
QNetworkAccessManager *netManager = new QNetworkAccessManager();
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");
netRequest.setRawHeader("Connection", "keep-alive");
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()));
QTimer::singleShot(30000, downloadLoop, SLOT(quit()));
downloadLoop->exec();
delete downloadLoop;
if (netReply->isFinished())
{
QString crewName;
QByteArray crewHtml = netReply->readAll();
QStringList crewHtmlSplit1 = QString::fromUtf8(crewHtml).split("<title>Rockstar Games Social Club - Crew : ");
if (crewHtmlSplit1.length() >= 2)
{
QStringList crewHtmlSplit2 = QString(crewHtmlSplit1.at(1)).split("</title>");
if (crewHtmlSplit2.length() >= 1)
{
crewName = crewHtmlSplit2.at(0);
}
}
if (!crewName.isEmpty())
{
crewDB->setCrewName(crewID.toInt(), crewName);
}
}
QEventLoop *waitingLoop = new QEventLoop();
QTimer::singleShot(requestDelay, waitingLoop, SLOT(quit()));
QObject::connect(this, SIGNAL(threadEndCommited()), waitingLoop, SLOT(quit()));
waitingLoop->exec();
delete waitingLoop;
delete netReply;
delete netManager;
}
}
}
void DatabaseThread::scanCrewMembersList(QStringList crewList, int maxPages, int requestDelay)
{
foreach (const QString &crewID, crewList)
{
if (threadRunning && crewID != "0")
{
int currentPage = 0;
int foundPlayers = 0;
int totalPlayers = 1000;
while(foundPlayers < totalPlayers && currentPage < maxPages)
{
QNetworkAccessManager *netManager = new QNetworkAccessManager();
QNetworkRequest netRequest(AppEnv::getPlayerFetchingUrl(crewID, QString::number(currentPage)));
#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");
netRequest.setRawHeader("Connection", "keep-alive");
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()));
QTimer::singleShot(30000, downloadLoop, SLOT(quit()));
downloadLoop->exec();
delete downloadLoop;
if (netReply->isFinished())
{
QByteArray crewJson = netReply->readAll();
QJsonDocument crewDocument = QJsonDocument::fromJson(crewJson);
QJsonObject crewObject = crewDocument.object();
QVariantMap crewMap = crewObject.toVariantMap();
if (crewMap.contains("Total")) { totalPlayers = crewMap["Total"].toInt(); }
if (crewMap.contains("Members"))
{
QList<QVariant> memberList = crewMap["Members"].toList();
foreach (const QVariant &memberVariant, memberList)
{
QMap<QString, QVariant> memberMap = memberVariant.toMap();
foundPlayers++;
if (memberMap.contains("RockstarId") && memberMap.contains("Name"))
{
int RockstarId = memberMap["RockstarId"].toInt();
QString memberName = memberMap["Name"].toString();
if (memberName != "" && RockstarId != 0)
{
emit playerNameFound(RockstarId, memberName);
}
}
}
}
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();
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "DatabaseThread.h"
#include "CrewDatabase.h"
#include "AppEnv.h"
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QJsonDocument>
#include <QJsonObject>
#include <QStringList>
#include <QVariantMap>
#include <QEventLoop>
#include <QTimer>
#include <QDebug>
#include <QUrl>
#define crewMaxPages 83
DatabaseThread::DatabaseThread(CrewDatabase *crewDB, QObject *parent) : QThread(parent), crewDB(crewDB)
{
threadRunning = true;
}
void DatabaseThread::run()
{
QEventLoop threadLoop;
QStringList crewList;
QStringList crewListR;
// Register thread loop end signal
QObject::connect(this, SIGNAL(threadEndCommited()), &threadLoop, SLOT(quit()));
// Setup crewList for Quick time scan
crewList = crewDB->getCrews();
if (!crewList.isEmpty())
{
crewListR = deleteCompatibleCrews(crewList);
}
else
{
while (crewList.isEmpty() && threadRunning)
{
QTimer::singleShot(1000, &threadLoop, SLOT(quit()));
threadLoop.exec();
if (!crewDB->isAddingCrews())
{
crewList = crewDB->getCrews();
}
}
if (threadRunning)
{
crewListR = deleteCompatibleCrews(crewList);
}
}
// Only do QTS when Thread should be run
if (threadRunning)
{
// Quick time scan
#ifdef GTA5SYNC_DEBUG
qDebug() << "Start QTS";
#endif
if (crewListR.length() <= 5)
{
scanCrewReference(crewListR, 2500);
emit crewNameUpdated();
}
if (crewList.length() <= 3)
{
scanCrewMembersList(crewList, 3, 2500);
emit playerNameUpdated();
}
else if (crewList.length() <= 5)
{
scanCrewMembersList(crewList, 2, 2500);
emit playerNameUpdated();
}
if (threadRunning)
{
QTimer::singleShot(10000, &threadLoop, SLOT(quit()));
threadLoop.exec();
}
}
while (threadRunning)
{
crewList = crewDB->getCrews();
crewListR = deleteCompatibleCrews(crewList);
// Long time scan
#ifdef GTA5SYNC_DEBUG
qDebug() << "Start LTS";
#endif
scanCrewReference(crewListR, 10000);
emit crewNameUpdated();
scanCrewMembersList(crewList, crewMaxPages, 10000);
emit playerNameUpdated();
if (threadRunning)
{
QTimer::singleShot(300000, &threadLoop, SLOT(quit()));
threadLoop.exec();
}
}
}
void DatabaseThread::scanCrewReference(const QStringList &crewList, const int &requestDelay)
{
foreach (const QString &crewID, crewList)
{
if (threadRunning && crewID != "0")
{
QNetworkAccessManager *netManager = new QNetworkAccessManager();
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");
netRequest.setRawHeader("Connection", "keep-alive");
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()));
QTimer::singleShot(30000, downloadLoop, SLOT(quit()));
downloadLoop->exec();
delete downloadLoop;
if (netReply->isFinished())
{
QString crewName;
QByteArray crewHtml = netReply->readAll();
QStringList crewHtmlSplit1 = QString::fromUtf8(crewHtml).split("<title>Rockstar Games Social Club - Crew : ");
if (crewHtmlSplit1.length() >= 2)
{
QStringList crewHtmlSplit2 = QString(crewHtmlSplit1.at(1)).split("</title>");
if (crewHtmlSplit2.length() >= 1)
{
crewName = crewHtmlSplit2.at(0);
}
}
if (!crewName.isEmpty())
{
emit crewNameFound(crewID.toInt(), crewName);
}
}
QEventLoop *waitingLoop = new QEventLoop();
QTimer::singleShot(requestDelay, waitingLoop, SLOT(quit()));
QObject::connect(this, SIGNAL(threadEndCommited()), waitingLoop, SLOT(quit()));
waitingLoop->exec();
delete waitingLoop;
delete netReply;
delete netManager;
}
}
}
void DatabaseThread::scanCrewMembersList(const QStringList &crewList, const int &maxPages, const int &requestDelay)
{
foreach (const QString &crewID, crewList)
{
if (threadRunning && crewID != "0")
{
int currentPage = 0;
int foundPlayers = 0;
int totalPlayers = 1000;
while(foundPlayers < totalPlayers && currentPage < maxPages)
{
QNetworkAccessManager *netManager = new QNetworkAccessManager();
QNetworkRequest netRequest(AppEnv::getPlayerFetchingUrl(crewID, currentPage));
#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");
netRequest.setRawHeader("Connection", "keep-alive");
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()));
QTimer::singleShot(30000, downloadLoop, SLOT(quit()));
downloadLoop->exec();
delete downloadLoop;
if (netReply->isFinished())
{
QByteArray crewJson = netReply->readAll();
QJsonDocument crewDocument = QJsonDocument::fromJson(crewJson);
QJsonObject crewObject = crewDocument.object();
QVariantMap crewMap = crewObject.toVariantMap();
if (crewMap.contains("Total")) { totalPlayers = crewMap["Total"].toInt(); }
if (crewMap.contains("Members"))
{
QList<QVariant> memberList = crewMap["Members"].toList();
foreach (const QVariant &memberVariant, memberList)
{
QMap<QString, QVariant> memberMap = memberVariant.toMap();
foundPlayers++;
if (memberMap.contains("RockstarId") && memberMap.contains("Name"))
{
int RockstarId = memberMap["RockstarId"].toInt();
QString memberName = memberMap["Name"].toString();
if (memberName != "" && RockstarId != 0)
{
emit playerNameFound(RockstarId, memberName);
}
}
}
}
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;
}
}
}
}
QStringList DatabaseThread::deleteCompatibleCrews(const QStringList &crewList)
{
QStringList crewListR = crewList;
foreach(const QString &crewNID, crewListR)
{
if (crewDB->isCompatibleCrew(crewNID))
{
crewListR.removeAll(crewNID);
}
}
return crewListR;
}
void DatabaseThread::doEndThread()
{
threadRunning = false;
emit threadEndCommited();
}

View file

@ -1,52 +1,54 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 DATABASETHREAD_H
#define DATABASETHREAD_H
#include "CrewDatabase.h"
#include <QObject>
#include <QThread>
class DatabaseThread : public QThread
{
Q_OBJECT
public:
explicit DatabaseThread(CrewDatabase *crewDB, QObject *parent = 0);
public slots:
void doEndThread();
private:
CrewDatabase *crewDB;
void scanCrewMembersList(QStringList crewList, int maxPages, int requestDelay);
void scanCrewReference(QStringList crewList, int requestDelay);
bool threadRunning;
int crewMaxPages;
int plyrPerReq;
protected:
void run();
signals:
void playerNameFound(int playerID, QString playerName);
void playerNameUpdated();
void threadEndCommited();
};
#endif // DATABASETHREAD_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 DATABASETHREAD_H
#define DATABASETHREAD_H
#include "CrewDatabase.h"
#include <QObject>
#include <QThread>
class DatabaseThread : public QThread
{
Q_OBJECT
public:
explicit DatabaseThread(CrewDatabase *crewDB, QObject *parent = 0);
public slots:
void doEndThread();
private:
CrewDatabase *crewDB;
void scanCrewMembersList(const QStringList &crewList, const int &maxPages, const int &requestDelay);
void scanCrewReference(const QStringList &crewList, const int &requestDelay);
QStringList deleteCompatibleCrews(const QStringList &crewList);
bool threadRunning;
int plyrPerReq;
protected:
void run();
signals:
void crewNameFound(int crewID, QString crewName);
void crewNameUpdated();
void playerNameFound(int playerID, QString playerName);
void playerNameUpdated();
void threadEndCommited();
};
#endif // DATABASETHREAD_H

View file

@ -1,48 +1,48 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "ExportDialog.h"
#include "ui_ExportDialog.h"
ExportDialog::ExportDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ExportDialog)
{
ui->setupUi(this);
success = false;
}
ExportDialog::~ExportDialog()
{
delete ui;
}
bool ExportDialog::isSucceeded()
{
return success;
}
void ExportDialog::on_cmdSnapmaticClose_clicked()
{
this->close();
}
void ExportDialog::setupPictureExport()
{
ui->swExport->setCurrentWidget(ui->pageSnapmatic);
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "ExportDialog.h"
#include "ui_ExportDialog.h"
ExportDialog::ExportDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ExportDialog)
{
ui->setupUi(this);
success = false;
}
ExportDialog::~ExportDialog()
{
delete ui;
}
bool ExportDialog::isSucceeded()
{
return success;
}
void ExportDialog::on_cmdSnapmaticClose_clicked()
{
this->close();
}
void ExportDialog::setupPictureExport()
{
ui->swExport->setCurrentWidget(ui->pageSnapmatic);
}

View file

@ -1,46 +1,46 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 EXPORTDIALOG_H
#define EXPORTDIALOG_H
#include <QDialog>
namespace Ui {
class ExportDialog;
}
class ExportDialog : public QDialog
{
Q_OBJECT
public:
explicit ExportDialog(QWidget *parent = 0);
void setupPictureExport();
bool isSucceeded();
~ExportDialog();
private slots:
void on_cmdSnapmaticClose_clicked();
private:
Ui::ExportDialog *ui;
bool success;
};
#endif // EXPORTDIALOG_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 EXPORTDIALOG_H
#define EXPORTDIALOG_H
#include <QDialog>
namespace Ui {
class ExportDialog;
}
class ExportDialog : public QDialog
{
Q_OBJECT
public:
explicit ExportDialog(QWidget *parent = 0);
void setupPictureExport();
bool isSucceeded();
~ExportDialog();
private slots:
void on_cmdSnapmaticClose_clicked();
private:
Ui::ExportDialog *ui;
bool success;
};
#endif // EXPORTDIALOG_H

View file

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

View file

@ -1,184 +1,185 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "SnapmaticPicture.h"
#include "ProfileInterface.h"
#include "PictureExport.h"
#include "ProfileWidget.h"
#include "ExportThread.h"
#include "SavegameData.h"
#include "config.h"
#include <QDesktopWidget>
#include <QApplication>
#include <QFileInfo>
#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)
{
}
void ExportThread::run()
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
// Picture Settings
// Quality Settings
settings.beginGroup("Pictures");
int defaultQuality = 100;
QSize defExportSize = QSize(960, 536);
int customQuality = settings.value("CustomQuality", defaultQuality).toInt();
if (customQuality < 1 || customQuality > 100)
{
customQuality = 100;
}
bool useCustomQuality = settings.value("CustomQualityEnabled", false).toBool();
// Size Settings
QSize cusExportSize = settings.value("CustomSize", defExportSize).toSize();
if (cusExportSize.width() > 3840)
{
cusExportSize.setWidth(3840);
}
else if (cusExportSize.height() > 2160)
{
cusExportSize.setHeight(2160);
}
if (cusExportSize.width() < 1)
{
cusExportSize.setWidth(1);
}
else if (cusExportSize.height() < 1)
{
cusExportSize.setHeight(1);
}
QString sizeMode = settings.value("ExportSizeMode", "Default").toString();
Qt::AspectRatioMode aspectRatio = (Qt::AspectRatioMode)settings.value("AspectRatio", Qt::KeepAspectRatio).toInt();
settings.endGroup();
// End Picture Settings
int intExportProgress = 0;
foreach(ProfileWidget *widget, profileMap.keys())
{
if (widget->isSelected())
{
if (widget->getWidgetType() == "SnapmaticWidget")
{
SnapmaticWidget *picWidget = (SnapmaticWidget*)widget;
SnapmaticPicture *picture = picWidget->getPicture();
if (pictureExportEnabled)
{
QString exportFileName = PictureExport::getPictureFileName(picture);
if (exportFileName.right(4) != ".jpg" && exportFileName.right(4) != ".png")
{
exportFileName.append(".jpg");
}
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();
if (sizeMode == "Desktop")
{
QRect desktopResolution = QApplication::desktop()->screenGeometry();
exportPicture = exportPicture.scaled(desktopResolution.width(), desktopResolution.height(), aspectRatio, Qt::SmoothTransformation);
}
else if (sizeMode == "Custom")
{
exportPicture = exportPicture.scaled(cusExportSize, aspectRatio, Qt::SmoothTransformation);
}
bool isSaved;
if (useCustomQuality)
{
isSaved = exportPicture.save(exportDirectory + "/" + exportFileName, "JPEG", customQuality);
}
else
{
isSaved = exportPicture.save(exportDirectory + "/" + exportFileName, "JPEG", 100);
}
if (!isSaved)
{
failedExportPictures.append(exportFileName);
}
}
if (pictureCopyEnabled)
{
QString exportFileName = PictureExport::getPictureFileName(picture);
if (exportFileName.right(4) != ".g5e")
{
exportFileName.append(".g5e");
}
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);}
if (!picture->exportPicture(exportDirectory + "/" + exportFileName, "G5E"))
{
failedCopyPictures.append(exportFileName);
}
}
}
else if (widget->getWidgetType() == "SavegameWidget")
{
SavegameWidget *sgdWidget = (SavegameWidget*)widget;
SavegameData *savegame = sgdWidget->getSavegame();
QString originalFileName = savegame->getSavegameFileName();
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)));
emit exportProgressUpdate(intExportProgress);
QString exportFilePath = exportDirectory + "/" + exportFileName;
if (QFile::exists(exportFilePath)) {QFile::remove(exportFilePath);}
if (!QFile::copy(originalFileName, exportFilePath))
{
failedSavegames.append(exportFileName);
}
}
}
}
emit exportFinished();
}
QStringList ExportThread::getFailedCopyPictures()
{
return failedCopyPictures;
}
QStringList ExportThread::getFailedExportPictures()
{
return failedExportPictures;
}
QStringList ExportThread::getFailedSavegames()
{
return failedSavegames;
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "SnapmaticPicture.h"
#include "ProfileInterface.h"
#include "PictureExport.h"
#include "ProfileWidget.h"
#include "ExportThread.h"
#include "SavegameData.h"
#include "config.h"
#include <QStringBuilder>
#include <QDesktopWidget>
#include <QApplication>
#include <QFileInfo>
#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)
{
}
void ExportThread::run()
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
// Picture Settings
// Quality Settings
settings.beginGroup("Pictures");
int defaultQuality = 100;
QSize defExportSize = QSize(960, 536);
int customQuality = settings.value("CustomQuality", defaultQuality).toInt();
if (customQuality < 1 || customQuality > 100)
{
customQuality = 100;
}
bool useCustomQuality = settings.value("CustomQualityEnabled", false).toBool();
// Size Settings
QSize cusExportSize = settings.value("CustomSize", defExportSize).toSize();
if (cusExportSize.width() > 3840)
{
cusExportSize.setWidth(3840);
}
else if (cusExportSize.height() > 2160)
{
cusExportSize.setHeight(2160);
}
if (cusExportSize.width() < 1)
{
cusExportSize.setWidth(1);
}
else if (cusExportSize.height() < 1)
{
cusExportSize.setHeight(1);
}
QString sizeMode = settings.value("ExportSizeMode", "Default").toString();
Qt::AspectRatioMode aspectRatio = (Qt::AspectRatioMode)settings.value("AspectRatio", Qt::KeepAspectRatio).toInt();
settings.endGroup();
// End Picture Settings
int intExportProgress = 0;
foreach(ProfileWidget *widget, profileMap.keys())
{
if (widget->isSelected())
{
if (widget->getWidgetType() == "SnapmaticWidget")
{
SnapmaticWidget *picWidget = qobject_cast<SnapmaticWidget*>(widget);
SnapmaticPicture *picture = picWidget->getPicture();
if (pictureExportEnabled)
{
QString exportFileName = PictureExport::getPictureFileName(picture);
if (exportFileName.right(4) != ".jpg" && exportFileName.right(4) != ".png")
{
exportFileName += ".jpg";
}
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();
if (sizeMode == "Desktop")
{
QRect desktopResolution = qApp->desktop()->screenGeometry();
exportPicture = exportPicture.scaled(desktopResolution.width(), desktopResolution.height(), aspectRatio, Qt::SmoothTransformation);
}
else if (sizeMode == "Custom")
{
exportPicture = exportPicture.scaled(cusExportSize, aspectRatio, Qt::SmoothTransformation);
}
bool isSaved;
if (useCustomQuality)
{
isSaved = exportPicture.save(exportDirectory % "/" % exportFileName, "JPEG", customQuality);
}
else
{
isSaved = exportPicture.save(exportDirectory % "/" % exportFileName, "JPEG", 100);
}
if (!isSaved)
{
failedExportPictures += exportFileName;
}
}
if (pictureCopyEnabled)
{
QString exportFileName = PictureExport::getPictureFileName(picture);
if (exportFileName.right(4) != ".g5e")
{
exportFileName += ".g5e";
}
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);}
if (!picture->exportPicture(exportDirectory % "/" % exportFileName, SnapmaticFormat::G5E_Format))
{
failedCopyPictures += exportFileName;
}
}
}
else if (widget->getWidgetType() == "SavegameWidget")
{
SavegameWidget *sgdWidget = qobject_cast<SavegameWidget*>(widget);
SavegameData *savegame = sgdWidget->getSavegame();
QString originalFileName = savegame->getSavegameFileName();
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)));
emit exportProgressUpdate(intExportProgress);
QString exportFilePath = exportDirectory % "/" % exportFileName;
if (QFile::exists(exportFilePath)) {QFile::remove(exportFilePath);}
if (!QFile::copy(originalFileName, exportFilePath))
{
failedSavegames += exportFileName;
}
}
}
}
emit exportFinished();
}
QStringList ExportThread::getFailedCopyPictures()
{
return failedCopyPictures;
}
QStringList ExportThread::getFailedExportPictures()
{
return failedExportPictures;
}
QStringList ExportThread::getFailedSavegames()
{
return failedSavegames;
}

View file

@ -1,56 +1,56 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 EXPORTTHREAD_H
#define EXPORTTHREAD_H
#include "SnapmaticWidget.h"
#include "SavegameWidget.h"
#include "ProfileWidget.h"
#include <QThread>
#include <QMap>
class ExportThread : public QThread
{
Q_OBJECT
public:
explicit ExportThread(QMap<ProfileWidget*,QString> profileMap, QString exportDirectory, bool pictureCopyEnabled, bool pictureExportEnabled, int exportCount, QObject *parent = 0);
QStringList getFailedSavegames();
QStringList getFailedCopyPictures();
QStringList getFailedExportPictures();
protected:
void run();
private:
QMap <ProfileWidget*, QString> profileMap;
QString exportDirectory;
bool pictureCopyEnabled;
bool pictureExportEnabled;
int exportCount;
QStringList failedSavegames;
QStringList failedCopyPictures;
QStringList failedExportPictures;
signals:
void exportStringUpdate(QString currentFileName);
void exportProgressUpdate(int currentProgressValue);
void exportFinished();
};
#endif // EXPORTTHREAD_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 EXPORTTHREAD_H
#define EXPORTTHREAD_H
#include "SnapmaticWidget.h"
#include "SavegameWidget.h"
#include "ProfileWidget.h"
#include <QThread>
#include <QMap>
class ExportThread : public QThread
{
Q_OBJECT
public:
explicit ExportThread(QMap<ProfileWidget*,QString> profileMap, QString exportDirectory, bool pictureCopyEnabled, bool pictureExportEnabled, int exportCount, QObject *parent = 0);
QStringList getFailedSavegames();
QStringList getFailedCopyPictures();
QStringList getFailedExportPictures();
protected:
void run();
private:
QMap <ProfileWidget*, QString> profileMap;
QString exportDirectory;
bool pictureCopyEnabled;
bool pictureExportEnabled;
int exportCount;
QStringList failedSavegames;
QStringList failedCopyPictures;
QStringList failedExportPictures;
signals:
void exportStringUpdate(QString currentFileName);
void exportProgressUpdate(int currentProgressValue);
void exportFinished();
};
#endif // EXPORTTHREAD_H

View file

@ -1,89 +1,85 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 <QLocale>
#include <QSettings>
#include <QFileInfo>
#include <QStringList>
#include "GlobalString.h"
#include "config.h"
GlobalString::GlobalString()
{
}
QMap<QString, QString> GlobalString::getGlobalMap()
{
QMap<QString, QString> globalMap;
QSettings globalFile(getLanguageFile(), QSettings::IniFormat);
globalFile.setIniCodec("UTF-8");
globalFile.beginGroup("Global");
QStringList globalStrList = globalFile.childKeys();
foreach(const QString &globalStr, globalStrList)
{
globalMap[globalStr] = globalFile.value(globalStr, globalStr).toString();
}
globalFile.endGroup();
return globalMap;
}
QString GlobalString::getString(QString valueStr, bool *ok)
{
QString globalString = valueStr;
QSettings globalFile(getLanguageFile(), QSettings::IniFormat);
globalFile.setIniCodec("UTF-8");
globalFile.beginGroup("Global");
QStringList globalStrList = globalFile.childKeys();
if (globalStrList.contains(valueStr))
{
if (ok != 0) *ok = true;
globalString = globalFile.value(valueStr, valueStr).toString();
}
globalFile.endGroup();
return globalString;
}
QString GlobalString::getLanguageFile()
{
QString language = getLanguage();
QString languageFile = ":/global/global." + language + ".ini";
if (!QFileInfo(languageFile).exists())
{
languageFile = ":/global/global.en.ini";
}
return languageFile;
}
QString GlobalString::getLanguage()
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("Interface");
QString language = settings.value("Language","System").toString();
settings.endGroup();
if (language == "System" || language.trimmed() == "")
{
QString languageName = QLocale::system().name();
QStringList langList = languageName.split("_");
if (langList.length() >= 1)
{
language = langList.at(0);
}
}
return language;
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "GlobalString.h"
#include "config.h"
#include <QStringBuilder>
#include <QStringList>
#include <QFileInfo>
#include <QSettings>
#include <QLocale>
#include <QDebug>
GlobalString::GlobalString()
{
}
QMap<QString, QString> GlobalString::getGlobalMap()
{
QMap<QString, QString> globalMap;
QSettings globalFile(getLanguageFile(), QSettings::IniFormat);
globalFile.setIniCodec("UTF-8");
globalFile.beginGroup("Global");
QStringList globalStrList = globalFile.childKeys();
foreach(const QString &globalStr, globalStrList)
{
globalMap[globalStr] = globalFile.value(globalStr, globalStr).toString();
}
globalFile.endGroup();
return globalMap;
}
QString GlobalString::getString(QString valueStr, bool *ok)
{
QString globalString = valueStr;
QSettings globalFile(getLanguageFile(), QSettings::IniFormat);
globalFile.setIniCodec("UTF-8");
globalFile.beginGroup("Global");
QStringList globalStrList = globalFile.childKeys();
if (globalStrList.contains(valueStr))
{
if (ok != NULL) *ok = true;
globalString = globalFile.value(valueStr, valueStr).toString();
}
globalFile.endGroup();
return globalString;
}
QString GlobalString::getLanguageFile()
{
QString language = getLanguage();
QString languageFile = ":/global/global." % language % ".ini";
if (!QFileInfo(languageFile).exists())
{
languageFile = ":/global/global.en.ini";
}
return languageFile;
}
QString GlobalString::getLanguage()
{
QString language = TCInstance->getCurrentLanguage();
QStringList langList = QString(language).replace("-", "_").split("_");
if (langList.length() >= 1)
{
language = langList.at(0);
}
return language;
}

View file

@ -1,35 +1,35 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 GLOBALSTRING_H
#define GLOBALSTRING_H
#include <QString>
#include <QMap>
class GlobalString
{
public:
GlobalString();
static QString getString(QString valueStr, bool *ok = 0);
static QString getLanguageFile();
static QString getLanguage();
static QMap<QString, QString> getGlobalMap();
};
#endif // GLOBALSTRING_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 GLOBALSTRING_H
#define GLOBALSTRING_H
#include <QString>
#include <QMap>
class GlobalString
{
public:
GlobalString();
static QString getString(QString valueStr, bool *ok = 0);
static QString getLanguageFile();
static QString getLanguage();
static QMap<QString, QString> getGlobalMap();
};
#endif // GLOBALSTRING_H

View file

@ -1,40 +1,50 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "IconLoader.h"
#include <QIcon>
IconLoader::IconLoader()
{
}
QIcon IconLoader::loadingAppIcon()
{
QIcon appIcon;
appIcon.addFile(":/img/5sync-16.png", QSize(16, 16));
appIcon.addFile(":/img/5sync-24.png", QSize(24, 24));
appIcon.addFile(":/img/5sync-32.png", QSize(32, 32));
appIcon.addFile(":/img/5sync-40.png", QSize(40, 40));
appIcon.addFile(":/img/5sync-48.png", QSize(48, 48));
appIcon.addFile(":/img/5sync-64.png", QSize(64, 64));
appIcon.addFile(":/img/5sync-96.png", QSize(96, 96));
appIcon.addFile(":/img/5sync-128.png", QSize(128, 128));
appIcon.addFile(":/img/5sync-256.png", QSize(256, 256));
return appIcon;
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "IconLoader.h"
#include <QIcon>
IconLoader::IconLoader()
{
}
QIcon IconLoader::loadingAppIcon()
{
QIcon appIcon;
appIcon.addFile(":/img/5sync-16.png", QSize(16, 16));
appIcon.addFile(":/img/5sync-24.png", QSize(24, 24));
appIcon.addFile(":/img/5sync-32.png", QSize(32, 32));
appIcon.addFile(":/img/5sync-40.png", QSize(40, 40));
appIcon.addFile(":/img/5sync-48.png", QSize(48, 48));
appIcon.addFile(":/img/5sync-64.png", QSize(64, 64));
appIcon.addFile(":/img/5sync-96.png", QSize(96, 96));
appIcon.addFile(":/img/5sync-128.png", QSize(128, 128));
appIcon.addFile(":/img/5sync-256.png", QSize(256, 256));
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
* Copyright (C) 2016-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 ICONLOADER_H
#define ICONLOADER_H
#include <QIcon>
class IconLoader
{
public:
IconLoader();
static QIcon loadingAppIcon();
};
#endif // ICONLOADER_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 ICONLOADER_H
#define ICONLOADER_H
#include <QIcon>
class IconLoader
{
public:
IconLoader();
static QIcon loadingAppIcon();
static QIcon loadingPointmakerIcon();
};
#endif // ICONLOADER_H

View file

@ -1,190 +1,219 @@
/*****************************************************************************
* 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 "ImportDialog.h"
#include "ui_ImportDialog.h"
#include "AppEnv.h"
#include <QPainter>
#include <QPixmap>
#include <QImage>
#include <QDebug>
// IMAGES VALUES
#define snapmaticResolutionW 960
#define snapmaticResolutionH 536
#define snapmaticAvatarResolution 470
#define snapmaticAvatarPlacementW 145
#define snapmaticAvatarPlacementH 66
ImportDialog::ImportDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ImportDialog)
{
ui->setupUi(this);
doImport = false;
avatarAreaImage = QImage(":/img/avatarareaimport.png");
if (QIcon::hasThemeIcon("dialog-ok"))
{
ui->cmdOK->setIcon(QIcon::fromTheme("dialog-ok"));
}
if (QIcon::hasThemeIcon("dialog-cancel"))
{
ui->cmdCancel->setIcon(QIcon::fromTheme("dialog-cancel"));
}
ui->rbKeep->setChecked(true);
qreal screenRatio = AppEnv::screenRatio();
snapmaticResolutionLW = 430 * screenRatio;
snapmaticResolutionLH = 240 * screenRatio;
setMinimumSize(430 * screenRatio, 380 * screenRatio);
setMaximumSize(430 * screenRatio, 380 * screenRatio);
setFixedSize(430 * screenRatio, 380 * screenRatio);
ui->vlButtom->setSpacing(6 * screenRatio);
ui->vlButtom->setContentsMargins(9 * screenRatio, 6 * screenRatio, 9 * screenRatio, 9 * screenRatio);
}
ImportDialog::~ImportDialog()
{
delete ui;
}
void ImportDialog::processImage()
{
QImage snapmaticImage = workImage;
QPixmap snapmaticPixmap(snapmaticResolutionW, snapmaticResolutionH);
snapmaticPixmap.fill(Qt::black);
QPainter snapmaticPainter(&snapmaticPixmap);
if (ui->cbAvatar->isChecked())
{
// Avatar mode
int diffWidth = 0;
int diffHeight = 0;
if (ui->rbKeep->isChecked())
{
snapmaticImage = snapmaticImage.scaled(snapmaticAvatarResolution, snapmaticAvatarResolution, Qt::KeepAspectRatio, Qt::SmoothTransformation);
if (snapmaticImage.width() > snapmaticImage.height())
{
diffHeight = snapmaticAvatarResolution - snapmaticImage.height();
diffHeight = diffHeight / 2;
}
else if (snapmaticImage.width() < snapmaticImage.height())
{
diffWidth = snapmaticAvatarResolution - snapmaticImage.width();
diffWidth = diffWidth / 2;
}
}
else
{
snapmaticImage = snapmaticImage.scaled(snapmaticAvatarResolution, snapmaticAvatarResolution, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
snapmaticPainter.drawImage(snapmaticAvatarPlacementW + diffWidth, snapmaticAvatarPlacementH + diffHeight, snapmaticImage);
imageTitle = "Custom Avatar";
}
else
{
// Picture mode
int diffWidth = 0;
int diffHeight = 0;
if (ui->rbKeep->isChecked())
{
snapmaticImage = snapmaticImage.scaled(snapmaticResolutionW, snapmaticResolutionH, Qt::KeepAspectRatio, Qt::SmoothTransformation);
if (snapmaticImage.width() != snapmaticResolutionW)
{
diffWidth = snapmaticResolutionW - snapmaticImage.width();
diffWidth = diffWidth / 2;
}
else if (snapmaticImage.height() != snapmaticResolutionH)
{
diffHeight = snapmaticResolutionH - snapmaticImage.height();
diffHeight = diffHeight / 2;
}
}
else
{
snapmaticImage = snapmaticImage.scaled(snapmaticResolutionW, snapmaticResolutionH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
snapmaticPainter.drawImage(0 + diffWidth, 0 + diffHeight, snapmaticImage);
imageTitle = "Custom Picture";
}
snapmaticPainter.end();
newImage = snapmaticPixmap.toImage();
ui->labPicture->setPixmap(snapmaticPixmap.scaled(snapmaticResolutionLW, snapmaticResolutionLH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
}
QImage ImportDialog::image()
{
return newImage;
}
void ImportDialog::setImage(const QImage &image_)
{
workImage = image_;
if (workImage.width() == workImage.height())
{
ui->cbAvatar->setChecked(true);
}
processImage();
}
bool ImportDialog::isDoImport()
{
return doImport;
}
QString ImportDialog::getImageTitle()
{
return imageTitle;
}
void ImportDialog::on_rbIgnore_clicked()
{
processImage();
}
void ImportDialog::on_rbKeep_clicked()
{
processImage();
}
void ImportDialog::on_cbAvatar_clicked()
{
processImage();
}
void ImportDialog::on_cmdCancel_clicked()
{
close();
}
void ImportDialog::on_cmdOK_clicked()
{
doImport = true;
close();
}
void ImportDialog::on_labPicture_labelPainted()
{
if (ui->cbAvatar->isChecked())
{
QPainter labelPainter(ui->labPicture);
labelPainter.drawImage(0, 0, avatarAreaImage.scaled(snapmaticResolutionLW, snapmaticResolutionLH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
labelPainter.end();
}
}
/*****************************************************************************
* 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 "ImportDialog.h"
#include "ui_ImportDialog.h"
#include "AppEnv.h"
#include <QColorDialog>
#include <QMessageBox>
#include <QPainter>
#include <QPixmap>
#include <QImage>
#include <QDebug>
#include <QRgb>
// IMAGES VALUES
#define snapmaticResolutionW 960
#define snapmaticResolutionH 536
#define snapmaticAvatarResolution 470
#define snapmaticAvatarPlacementW 145
#define snapmaticAvatarPlacementH 66
ImportDialog::ImportDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ImportDialog)
{
ui->setupUi(this);
importAgreed = false;
insideAvatarZone = false;
avatarAreaImage = QImage(":/img/avatarareaimport.png");
selectedColour = QColor::fromRgb(0, 0, 0, 255);
if (QIcon::hasThemeIcon("dialog-ok"))
{
ui->cmdOK->setIcon(QIcon::fromTheme("dialog-ok"));
}
if (QIcon::hasThemeIcon("dialog-cancel"))
{
ui->cmdCancel->setIcon(QIcon::fromTheme("dialog-cancel"));
}
ui->cbIgnore->setChecked(false);
ui->labColour->setText(tr("Background Colour: <span style=\"color: %1\">%1</span>").arg(selectedColour.name()));
qreal screenRatio = AppEnv::screenRatio();
snapmaticResolutionLW = 430 * screenRatio;
snapmaticResolutionLH = 240 * screenRatio;
setMinimumSize(430 * screenRatio, 380 * screenRatio);
setMaximumSize(430 * screenRatio, 380 * screenRatio);
setFixedSize(430 * screenRatio, 380 * screenRatio);
ui->vlButtom->setSpacing(6 * screenRatio);
ui->vlButtom->setContentsMargins(9 * screenRatio, 6 * screenRatio, 9 * screenRatio, 9 * screenRatio);
}
ImportDialog::~ImportDialog()
{
delete ui;
}
void ImportDialog::processImage()
{
QImage snapmaticImage = workImage;
QPixmap snapmaticPixmap(snapmaticResolutionW, snapmaticResolutionH);
snapmaticPixmap.fill(selectedColour);
QPainter snapmaticPainter(&snapmaticPixmap);
if (insideAvatarZone)
{
// Avatar mode
int diffWidth = 0;
int diffHeight = 0;
if (!ui->cbIgnore->isChecked())
{
snapmaticImage = snapmaticImage.scaled(snapmaticAvatarResolution, snapmaticAvatarResolution, Qt::KeepAspectRatio, Qt::SmoothTransformation);
if (snapmaticImage.width() > snapmaticImage.height())
{
diffHeight = snapmaticAvatarResolution - snapmaticImage.height();
diffHeight = diffHeight / 2;
}
else if (snapmaticImage.width() < snapmaticImage.height())
{
diffWidth = snapmaticAvatarResolution - snapmaticImage.width();
diffWidth = diffWidth / 2;
}
}
else
{
snapmaticImage = snapmaticImage.scaled(snapmaticAvatarResolution, snapmaticAvatarResolution, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
snapmaticPainter.drawImage(snapmaticAvatarPlacementW + diffWidth, snapmaticAvatarPlacementH + diffHeight, snapmaticImage);
imageTitle = "Custom Avatar";
}
else
{
// Picture mode
int diffWidth = 0;
int diffHeight = 0;
if (!ui->cbIgnore->isChecked())
{
snapmaticImage = snapmaticImage.scaled(snapmaticResolutionW, snapmaticResolutionH, Qt::KeepAspectRatio, Qt::SmoothTransformation);
if (snapmaticImage.width() != snapmaticResolutionW)
{
diffWidth = snapmaticResolutionW - snapmaticImage.width();
diffWidth = diffWidth / 2;
}
else if (snapmaticImage.height() != snapmaticResolutionH)
{
diffHeight = snapmaticResolutionH - snapmaticImage.height();
diffHeight = diffHeight / 2;
}
}
else
{
snapmaticImage = snapmaticImage.scaled(snapmaticResolutionW, snapmaticResolutionH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
snapmaticPainter.drawImage(0 + diffWidth, 0 + diffHeight, snapmaticImage);
imageTitle = "Custom Picture";
}
snapmaticPainter.end();
newImage = snapmaticPixmap.toImage();
ui->labPicture->setPixmap(snapmaticPixmap.scaled(snapmaticResolutionLW, snapmaticResolutionLH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
}
QImage ImportDialog::image()
{
return newImage;
}
void ImportDialog::setImage(const QImage &image_)
{
workImage = image_;
if (workImage.width() == workImage.height())
{
insideAvatarZone = true;
ui->cbAvatar->setChecked(true);
}
processImage();
}
bool ImportDialog::isImportAgreed()
{
return importAgreed;
}
QString ImportDialog::getImageTitle()
{
return imageTitle;
}
void ImportDialog::on_cbIgnore_toggled(bool checked)
{
Q_UNUSED(checked)
processImage();
}
void ImportDialog::on_cbAvatar_toggled(bool checked)
{
if (workImage.width() == workImage.height() && !checked)
{
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);
insideAvatarZone = true;
return;
}
}
insideAvatarZone = ui->cbAvatar->isChecked();
processImage();
}
void ImportDialog::on_cmdCancel_clicked()
{
close();
}
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
* 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 IMPORTDIALOG_H
#define IMPORTDIALOG_H
#include <QDialog>
namespace Ui {
class ImportDialog;
}
class ImportDialog : public QDialog
{
Q_OBJECT
public:
explicit ImportDialog(QWidget *parent = 0);
~ImportDialog();
QImage image();
QString getImageTitle();
void setImage(const QImage &image);
bool isDoImport();
private slots:
void processImage();
void on_rbIgnore_clicked();
void on_rbKeep_clicked();
void on_cbAvatar_clicked();
void on_cmdCancel_clicked();
void on_cmdOK_clicked();
void on_labPicture_labelPainted();
private:
Ui::ImportDialog *ui;
QImage avatarAreaImage;
QString imageTitle;
QImage workImage;
QImage newImage;
bool doImport;
int snapmaticResolutionLW;
int snapmaticResolutionLH;
};
#endif // IMPORTDIALOG_H
/*****************************************************************************
* 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 IMPORTDIALOG_H
#define IMPORTDIALOG_H
#include <QDialog>
namespace Ui {
class ImportDialog;
}
class ImportDialog : public QDialog
{
Q_OBJECT
public:
explicit ImportDialog(QWidget *parent = 0);
~ImportDialog();
QImage image();
QString getImageTitle();
void setImage(const QImage &image);
bool isImportAgreed();
private slots:
void processImage();
void on_cbIgnore_toggled(bool checked);
void on_cbAvatar_toggled(bool checked);
void on_cmdCancel_clicked();
void on_cmdOK_clicked();
void on_labPicture_labelPainted();
void on_cmdColourChange_clicked();
private:
Ui::ImportDialog *ui;
QImage avatarAreaImage;
QString imageTitle;
QImage workImage;
QImage newImage;
QColor selectedColour;
bool insideAvatarZone;
bool importAgreed;
int snapmaticResolutionLW;
int snapmaticResolutionLH;
};
#endif // IMPORTDIALOG_H

View file

@ -1,187 +1,239 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ImportDialog</class>
<widget class="QDialog" name="ImportDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>430</width>
<height>380</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>430</width>
<height>380</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>430</width>
<height>380</height>
</size>
</property>
<property name="windowTitle">
<string>Import...</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="vlImport">
<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="minimumSize">
<size>
<width>430</width>
<height>240</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="buttomFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="vlButtom">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<widget class="QGroupBox" name="gbSettings">
<property name="title">
<string>Settings</string>
</property>
<layout class="QGridLayout" name="gdSettings">
<item row="1" column="0">
<widget class="QRadioButton" name="rbKeep">
<property name="text">
<string>&amp;Keep Aspect Ratio</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QRadioButton" name="rbIgnore">
<property name="text">
<string>&amp;Ignore Aspect Ratio</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="cbAvatar">
<property name="text">
<string>&amp;Avatar</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="vsDialog">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="hlButtons">
<item>
<spacer name="hsButtons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="cmdOK">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</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="text">
<string>&amp;Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>UiModLabel</class>
<extends>QLabel</extends>
<header>UiModLabel.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ImportDialog</class>
<widget class="QDialog" name="ImportDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>430</width>
<height>380</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>430</width>
<height>380</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>430</width>
<height>380</height>
</size>
</property>
<property name="windowTitle">
<string>Import...</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="vlImport">
<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="minimumSize">
<size>
<width>430</width>
<height>240</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="buttomFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="vlButtom">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<widget class="QGroupBox" name="gbSettings">
<property name="title">
<string>Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="hlColor">
<item>
<widget class="QLabel" name="labColour">
<property name="text">
<string>Background Colour: &lt;span style=&quot;color: %1&quot;&gt;%1&lt;/span&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="cmdColourChange">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<spacer name="hsColourSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="hlCheckboxes">
<item>
<widget class="QCheckBox" name="cbAvatar">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Avatar</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbIgnore">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Ignore Aspect Ratio</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="vsDialog">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="hlButtons">
<item>
<spacer name="hsButtons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="cmdOK">
<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
* Copyright (C) 2016-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 "OptionsDialog.h"
#include "ui_OptionsDialog.h"
#include "StandardPaths.h"
#include "UserInterface.h"
#include "AppEnv.h"
#include "config.h"
#include <QDesktopWidget>
#include <QApplication>
#include <QFileDialog>
#include <QMessageBox>
#include <QStringList>
#include <QLocale>
#include <QString>
#include <QDebug>
#include <QList>
#include <QDir>
OptionsDialog::OptionsDialog(ProfileDatabase *profileDB, QWidget *parent) :
QDialog(parent), profileDB(profileDB),
ui(new Ui::OptionsDialog)
{
// Set Window Flags
setWindowFlags(windowFlags()^Qt::WindowContextHelpButtonHint);
// Setup User Interface
ui->setupUi(this);
ui->tabWidget->setCurrentIndex(0);
ui->labPicCustomRes->setVisible(false);
QRect desktopResolution = QApplication::desktop()->screenGeometry(parent);
int desktopSizeWidth = desktopResolution.width();
int desktopSizeHeight = desktopResolution.height();
aspectRatio = Qt::KeepAspectRatio;
defExportSize = QSize(960, 536);
cusExportSize = defExportSize;
defaultQuality = 100;
customQuality = 100;
contentMode = 0;
settings = new QSettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
percentString = ui->labPicQuality->text();
ui->labPicQuality->setText(percentString.arg(QString::number(defaultQuality)));
ui->rbPicDesktopRes->setText(ui->rbPicDesktopRes->text().arg(QString::number(desktopSizeWidth), QString::number(desktopSizeHeight)));
ui->rbPicDefaultRes->setText(ui->rbPicDefaultRes->text().arg(QString::number(defExportSize.width()), QString::number(defExportSize.height())));
if (QIcon::hasThemeIcon("dialog-ok"))
{
ui->cmdOK->setIcon(QIcon::fromTheme("dialog-ok"));
}
if (QIcon::hasThemeIcon("dialog-cancel"))
{
ui->cmdCancel->setIcon(QIcon::fromTheme("dialog-cancel"));
}
// DPI calculation
qreal screenRatio = AppEnv::screenRatio();
resize(435 * screenRatio, 405 * screenRatio);
setupTreeWidget();
setupLanguageBox();
setupRadioButtons();
setupDefaultProfile();
setupPictureSettings();
setupCustomGTAFolder();
setupSnapmaticPictureViewer();
#ifdef GTA5SYNC_DISABLED
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabSync));
#endif
this->setWindowTitle(windowTitle().arg(GTA5SYNC_APPSTR));
}
OptionsDialog::~OptionsDialog()
{
delete settings;
foreach(QTreeWidgetItem *playerItem, playerItems)
{
delete playerItem;
}
delete ui;
}
void OptionsDialog::setupTreeWidget()
{
foreach(const QString &playerIDStr, profileDB->getPlayers())
{
bool ok;
int playerID = playerIDStr.toInt(&ok);
if (ok)
{
QString playerName = profileDB->getPlayerName(playerID);
QStringList playerTreeViewList;
playerTreeViewList << playerIDStr;
playerTreeViewList << playerName;
QTreeWidgetItem *playerItem = new QTreeWidgetItem(playerTreeViewList);
ui->twPlayers->addTopLevelItem(playerItem);
playerItems.append(playerItem);
}
}
ui->twPlayers->sortItems(1, Qt::AscendingOrder);
}
void OptionsDialog::setupLanguageBox()
{
settings->beginGroup("Interface");
currentLanguage = settings->value("Language","System").toString();
settings->endGroup();
QStringList langList = QLocale::system().name().split("_");
if (langList.length() > 0)
{
QString cbSysStr = tr("%1 (%2 if available)", "System like PC System = %1, System Language like Deutsch = %2").arg(tr("System",
"System like PC System"), QLocale::languageToString(QLocale(langList.at(0)).language()));
ui->cbLanguage->addItem(cbSysStr, "System");
}
QString cbEngStr = "English (English) [en]";
ui->cbLanguage->addItem(QIcon::fromTheme("flag-us"), cbEngStr, "en");
if (currentLanguage == "en")
{
#if QT_VERSION >= 0x050000
ui->cbLanguage->setCurrentText(cbEngStr);
#else
int indexOfEnglish = ui->cbLanguage->findText(cbEngStr);
ui->cbLanguage->setCurrentIndex(indexOfEnglish);
#endif
}
QDir langDir;
langDir.setNameFilters(QStringList("gta5sync_*.qm"));
langDir.setPath(AppEnv::getLangFolder());
QStringList langFiles;
langFiles << langDir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::NoSort);
langDir.setPath(":/tr");
langFiles << langDir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::NoSort);
langFiles.removeDuplicates();
foreach(const QString &langFile, langFiles)
{
QString lang = langFile;
lang.remove("gta5sync_");
lang.remove(".qm");
QLocale langLocale(lang);
QString languageNameInternational = QLocale::languageToString(langLocale.language());
QString languageNameNative = langLocale.nativeLanguageName();
QString cbLangStr = languageNameNative + " (" + languageNameInternational + ") [" + lang + "]";
QString langIconStr = "flag-" + lang;
ui->cbLanguage->addItem(QIcon::fromTheme(langIconStr), cbLangStr, lang);
if (currentLanguage == lang)
{
#if QT_VERSION >= 0x050000
ui->cbLanguage->setCurrentText(cbLangStr);
#else
int indexOfLang = ui->cbLanguage->findText(cbLangStr);
ui->cbLanguage->setCurrentIndex(indexOfLang);
#endif
}
}
}
void OptionsDialog::setupRadioButtons()
{
bool contentModeOk;
settings->beginGroup("Profile");
contentMode = settings->value("ContentMode", 0).toInt(&contentModeOk);
settings->endGroup();
if (contentModeOk)
{
if (contentMode == 0)
{
ui->rbOpenWithSC->setChecked(true);
}
else if (contentMode == 1)
{
ui->rbOpenWithDC->setChecked(true);
}
else if (contentMode == 2)
{
ui->rbSelectWithSC->setChecked(true);
}
}
}
void OptionsDialog::on_cmdOK_clicked()
{
applySettings();
close();
}
void OptionsDialog::applySettings()
{
settings->beginGroup("Interface");
#if QT_VERSION >= 0x050000
settings->setValue("Language", ui->cbLanguage->currentData());
#else
settings->setValue("Language", ui->cbLanguage->itemData(ui->cbLanguage->currentIndex()));
#endif
#ifdef GTA5SYNC_WIN
#if QT_VERSION >= 0x050200
settings->setValue("NavigationBar", ui->cbSnapmaticNavigationBar->isChecked());
#endif
#endif
settings->endGroup();
settings->beginGroup("Profile");
int newContentMode = 0;
if (ui->rbOpenWithSC->isChecked())
{
newContentMode = 0;
}
else if (ui->rbOpenWithDC->isChecked())
{
newContentMode = 1;
}
else if (ui->rbSelectWithSC->isChecked())
{
newContentMode = 2;
}
settings->setValue("ContentMode", newContentMode);
#if QT_VERSION >= 0x050000
settings->setValue("Default", ui->cbProfiles->currentData());
#else
settings->setValue("Default", ui->cbProfiles->itemData(ui->cbProfiles->currentIndex()));
#endif
settings->endGroup();
settings->beginGroup("Pictures");
if (ui->cbPicCustomQuality->isChecked())
{
settings->setValue("CustomQuality", ui->hsPicQuality->value());
}
settings->setValue("CustomQualityEnabled", ui->cbPicCustomQuality->isChecked());
QString sizeMode = "Default";
if (ui->rbPicDesktopRes->isChecked())
{
sizeMode = "Desktop";
}
else if (ui->rbPicCustomRes->isChecked())
{
sizeMode = "Custom";
settings->setValue("CustomSize", QSize(ui->sbPicExportWidth->value(), ui->sbPicExportHeight->value()));
}
settings->setValue("ExportSizeMode", sizeMode);
settings->setValue("AspectRatio", aspectRatio);
settings->endGroup();
bool forceCustomFolder = ui->cbForceCustomFolder->isChecked();
settings->beginGroup("dir");
settings->setValue("dir", ui->txtFolder->text());
settings->setValue("force", forceCustomFolder);
settings->endGroup();
#if QT_VERSION >= 0x050000
emit settingsApplied(newContentMode, ui->cbLanguage->currentData().toString());
#else
emit settingsApplied(newContentMode, ui->cbLanguage->itemData(ui->cbLanguage->currentIndex()).toString());
#endif
#if QT_VERSION >= 0x050000
bool languageChanged = ui->cbLanguage->currentData().toString() != currentLanguage;
#else
bool languageChanged = ui->cbLanguage->itemData(ui->cbLanguage->currentIndex()).toString() != currentLanguage;
#endif
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));
}
if (languageChanged)
{
QMessageBox::information(this, tr("%1", "%1").arg(GTA5SYNC_APPSTR), tr("The language change will take effect after you restart %1.").arg(GTA5SYNC_APPSTR));
}
}
void OptionsDialog::setupDefaultProfile()
{
settings->beginGroup("Profile");
defaultProfile = settings->value("Default", "").toString();
settings->endGroup();
QString cbNoneStr = tr("No Profile", "No Profile, as default");
ui->cbProfiles->addItem(cbNoneStr, "");
}
void OptionsDialog::commitProfiles(QStringList profiles)
{
foreach(const QString &profile, profiles)
{
ui->cbProfiles->addItem(tr("Profile: %1").arg(profile), profile);
if (defaultProfile == profile)
{
#if QT_VERSION >= 0x050000
ui->cbProfiles->setCurrentText(tr("Profile: %1").arg(profile));
#else
int indexOfProfile = ui->cbProfiles->findText(tr("Profile: %1").arg(profile));
ui->cbProfiles->setCurrentIndex(indexOfProfile);
#endif
}
}
}
void OptionsDialog::on_rbPicCustomRes_toggled(bool checked)
{
ui->labPicCustomRes->setEnabled(checked);
ui->sbPicExportWidth->setEnabled(checked);
ui->sbPicExportHeight->setEnabled(checked);
ui->labPicXDescription->setEnabled(checked);
}
void OptionsDialog::on_cbPicCustomQuality_toggled(bool checked)
{
ui->hsPicQuality->setEnabled(checked);
ui->labPicQuality->setEnabled(checked);
ui->labPicQualityDescription->setEnabled(checked);
}
void OptionsDialog::on_hsPicQuality_valueChanged(int value)
{
customQuality = value;
ui->labPicQuality->setText(percentString.arg(QString::number(value)));
}
void OptionsDialog::setupPictureSettings()
{
settings->beginGroup("Pictures");
// Quality Settings
customQuality = settings->value("CustomQuality", defaultQuality).toInt();
if (customQuality < 1 || customQuality > 100)
{
customQuality = 100;
}
ui->hsPicQuality->setValue(customQuality);
ui->cbPicCustomQuality->setChecked(settings->value("CustomQualityEnabled", false).toBool());
// Size Settings
cusExportSize = settings->value("CustomSize", defExportSize).toSize();
if (cusExportSize.width() > 3840)
{
cusExportSize.setWidth(3840);
}
else if (cusExportSize.height() > 2160)
{
cusExportSize.setHeight(2160);
}
if (cusExportSize.width() < 1)
{
cusExportSize.setWidth(1);
}
else if (cusExportSize.height() < 1)
{
cusExportSize.setHeight(1);
}
ui->sbPicExportWidth->setValue(cusExportSize.width());
ui->sbPicExportHeight->setValue(cusExportSize.height());
QString sizeMode = settings->value("ExportSizeMode", "Default").toString();
if (sizeMode == "Desktop")
{
ui->rbPicDesktopRes->setChecked(true);
}
else if (sizeMode == "Custom")
{
ui->rbPicCustomRes->setChecked(true);
}
else
{
ui->rbPicDefaultRes->setChecked(true);
}
aspectRatio = (Qt::AspectRatioMode)settings->value("AspectRatio", Qt::KeepAspectRatio).toInt();
if (aspectRatio == Qt::IgnoreAspectRatio)
{
ui->cbIgnoreAspectRatio->setChecked(true);
}
settings->endGroup();
}
void OptionsDialog::on_cbIgnoreAspectRatio_toggled(bool checked)
{
if (checked)
{
aspectRatio = Qt::IgnoreAspectRatio;
}
else
{
aspectRatio = Qt::KeepAspectRatio;
}
}
void OptionsDialog::setupCustomGTAFolder()
{
bool ok;
QString defaultGameFolder = AppEnv::getGameFolder(&ok);
settings->beginGroup("dir");
currentCFolder = settings->value("dir", "").toString();
currentFFolder = settings->value("force", false).toBool();
if (currentCFolder == "" && ok)
{
currentCFolder = defaultGameFolder;
}
ui->txtFolder->setText(currentCFolder);
ui->cbForceCustomFolder->setChecked(currentFFolder);
settings->endGroup();
}
void OptionsDialog::setupSnapmaticPictureViewer()
{
#ifdef GTA5SYNC_WIN
#if QT_VERSION >= 0x050200
settings->beginGroup("Interface");
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);
}
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "OptionsDialog.h"
#include "ui_OptionsDialog.h"
#include "TranslationClass.h"
#include "StandardPaths.h"
#include "UserInterface.h"
#include "AppEnv.h"
#include "config.h"
#include <QStringBuilder>
#include <QDesktopWidget>
#include <QApplication>
#include <QFileDialog>
#include <QMessageBox>
#include <QStringList>
#include <QLocale>
#include <QString>
#include <QDebug>
#include <QList>
#include <QDir>
OptionsDialog::OptionsDialog(ProfileDatabase *profileDB, QWidget *parent) :
QDialog(parent), profileDB(profileDB),
ui(new Ui::OptionsDialog)
{
// Set Window Flags
setWindowFlags(windowFlags()^Qt::WindowContextHelpButtonHint);
// Setup User Interface
ui->setupUi(this);
ui->tabWidget->setCurrentIndex(0);
ui->labPicCustomRes->setVisible(false);
QRect desktopResolution = qApp->desktop()->screenGeometry(parent);
int desktopSizeWidth = desktopResolution.width();
int desktopSizeHeight = desktopResolution.height();
aspectRatio = Qt::KeepAspectRatio;
defExportSize = QSize(960, 536);
cusExportSize = defExportSize;
defaultQuality = 100;
customQuality = 100;
contentMode = 0;
settings = new QSettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
percentString = ui->labPicQuality->text();
ui->labPicQuality->setText(percentString.arg(QString::number(defaultQuality)));
ui->rbPicDesktopRes->setText(ui->rbPicDesktopRes->text().arg(QString::number(desktopSizeWidth), QString::number(desktopSizeHeight)));
ui->rbPicDefaultRes->setText(ui->rbPicDefaultRes->text().arg(QString::number(defExportSize.width()), QString::number(defExportSize.height())));
if (QIcon::hasThemeIcon("dialog-ok"))
{
ui->cmdOK->setIcon(QIcon::fromTheme("dialog-ok"));
}
if (QIcon::hasThemeIcon("dialog-cancel"))
{
ui->cmdCancel->setIcon(QIcon::fromTheme("dialog-cancel"));
}
// DPI calculation
qreal screenRatio = AppEnv::screenRatio();
resize(435 * screenRatio, 405 * screenRatio);
setupTreeWidget();
setupLanguageBox();
setupRadioButtons();
setupDefaultProfile();
setupPictureSettings();
setupCustomGTAFolder();
setupSnapmaticPictureViewer();
#ifdef GTA5SYNC_DISABLED
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabSync));
#endif
this->setWindowTitle(windowTitle().arg(GTA5SYNC_APPSTR));
}
OptionsDialog::~OptionsDialog()
{
delete settings;
foreach(QTreeWidgetItem *playerItem, playerItems)
{
delete playerItem;
}
delete ui;
}
void OptionsDialog::setupTreeWidget()
{
foreach(const QString &playerIDStr, profileDB->getPlayers())
{
bool ok;
int playerID = playerIDStr.toInt(&ok);
if (ok)
{
QString playerName = profileDB->getPlayerName(playerID);
QStringList playerTreeViewList;
playerTreeViewList << playerIDStr;
playerTreeViewList << playerName;
QTreeWidgetItem *playerItem = new QTreeWidgetItem(playerTreeViewList);
ui->twPlayers->addTopLevelItem(playerItem);
playerItems += playerItem;
}
}
ui->twPlayers->sortItems(1, Qt::AscendingOrder);
}
void OptionsDialog::setupLanguageBox()
{
settings->beginGroup("Interface");
currentLanguage = settings->value("Language","System").toString();
settings->endGroup();
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",
"System in context of System default"));
ui->cbLanguage->addItem(cbSysStr, "System");
QStringList availableLanguages;
availableLanguages << QString("en_GB");
#ifndef GTA5SYNC_QCONF
availableLanguages << TCInstance->listTranslations(AppEnv::getExLangFolder());
#endif
availableLanguages << TCInstance->listTranslations(AppEnv::getInLangFolder());
availableLanguages.removeDuplicates();
availableLanguages.sort();
foreach(const QString &lang, availableLanguages)
{
QLocale langLocale(lang);
QString cbLangStr = langLocale.nativeLanguageName() % " (" % langLocale.nativeCountryName() % ") [" % lang % "]";
QString langIconStr = "flag-" % TranslationClass::getCountryCode(langLocale);
ui->cbLanguage->addItem(QIcon::fromTheme(langIconStr), cbLangStr, lang);
if (currentLanguage == lang)
{
#if QT_VERSION >= 0x050000
ui->cbLanguage->setCurrentText(cbLangStr);
#else
int indexOfLang = ui->cbLanguage->findText(cbLangStr);
ui->cbLanguage->setCurrentIndex(indexOfLang);
#endif
}
}
}
void OptionsDialog::setupRadioButtons()
{
bool contentModeOk;
settings->beginGroup("Profile");
contentMode = settings->value("ContentMode", 0).toInt(&contentModeOk);
settings->endGroup();
if (contentModeOk)
{
if (contentMode == 0)
{
ui->rbOpenWithSC->setChecked(true);
}
else if (contentMode == 1)
{
ui->rbOpenWithDC->setChecked(true);
}
else if (contentMode == 2)
{
ui->rbSelectWithSC->setChecked(true);
}
}
}
void OptionsDialog::on_cmdOK_clicked()
{
applySettings();
close();
}
void OptionsDialog::applySettings()
{
settings->beginGroup("Interface");
#if QT_VERSION >= 0x050000
settings->setValue("Language", ui->cbLanguage->currentData());
#else
settings->setValue("Language", ui->cbLanguage->itemData(ui->cbLanguage->currentIndex()));
#endif
#ifdef GTA5SYNC_WIN
#if QT_VERSION >= 0x050200
settings->setValue("NavigationBar", ui->cbSnapmaticNavigationBar->isChecked());
#endif
#endif
settings->endGroup();
settings->beginGroup("Profile");
int newContentMode = 0;
if (ui->rbOpenWithSC->isChecked())
{
newContentMode = 0;
}
else if (ui->rbOpenWithDC->isChecked())
{
newContentMode = 1;
}
else if (ui->rbSelectWithSC->isChecked())
{
newContentMode = 2;
}
settings->setValue("ContentMode", newContentMode);
#if QT_VERSION >= 0x050000
settings->setValue("Default", ui->cbProfiles->currentData());
#else
settings->setValue("Default", ui->cbProfiles->itemData(ui->cbProfiles->currentIndex()));
#endif
settings->endGroup();
settings->beginGroup("Pictures");
if (ui->cbPicCustomQuality->isChecked())
{
settings->setValue("CustomQuality", ui->hsPicQuality->value());
}
settings->setValue("CustomQualityEnabled", ui->cbPicCustomQuality->isChecked());
QString sizeMode = "Default";
if (ui->rbPicDesktopRes->isChecked())
{
sizeMode = "Desktop";
}
else if (ui->rbPicCustomRes->isChecked())
{
sizeMode = "Custom";
settings->setValue("CustomSize", QSize(ui->sbPicExportWidth->value(), ui->sbPicExportHeight->value()));
}
settings->setValue("ExportSizeMode", sizeMode);
settings->setValue("AspectRatio", aspectRatio);
settings->endGroup();
bool forceCustomFolder = ui->cbForceCustomFolder->isChecked();
settings->beginGroup("dir");
settings->setValue("dir", ui->txtFolder->text());
settings->setValue("force", forceCustomFolder);
settings->endGroup();
#if QT_VERSION >= 0x050000
bool languageChanged = ui->cbLanguage->currentData().toString() != currentLanguage;
#else
bool languageChanged = ui->cbLanguage->itemData(ui->cbLanguage->currentIndex()).toString() != currentLanguage;
#endif
if (languageChanged)
{
TCInstance->unloadTranslation(qApp);
TCInstance->initUserLanguage();
TCInstance->loadTranslation(qApp);
}
#if QT_VERSION >= 0x050000
emit settingsApplied(newContentMode, ui->cbLanguage->currentData().toString());
#else
emit settingsApplied(newContentMode, ui->cbLanguage->itemData(ui->cbLanguage->currentIndex()).toString());
#endif
if ((forceCustomFolder && ui->txtFolder->text() != currentCFolder) || (forceCustomFolder != currentFFolder && forceCustomFolder))
{
QMessageBox::information(this, tr("%1", "%1").arg(GTA5SYNC_APPSTR), tr("The new Custom Folder will initialise after you restart %1.").arg(GTA5SYNC_APPSTR));
}
}
void OptionsDialog::setupDefaultProfile()
{
settings->beginGroup("Profile");
defaultProfile = settings->value("Default", "").toString();
settings->endGroup();
QString cbNoneStr = tr("No Profile", "No Profile, as default");
ui->cbProfiles->addItem(cbNoneStr, "");
}
void OptionsDialog::commitProfiles(QStringList profiles)
{
foreach(const QString &profile, profiles)
{
ui->cbProfiles->addItem(tr("Profile: %1").arg(profile), profile);
if (defaultProfile == profile)
{
#if QT_VERSION >= 0x050000
ui->cbProfiles->setCurrentText(tr("Profile: %1").arg(profile));
#else
int indexOfProfile = ui->cbProfiles->findText(tr("Profile: %1").arg(profile));
ui->cbProfiles->setCurrentIndex(indexOfProfile);
#endif
}
}
}
void OptionsDialog::on_rbPicCustomRes_toggled(bool checked)
{
ui->labPicCustomRes->setEnabled(checked);
ui->sbPicExportWidth->setEnabled(checked);
ui->sbPicExportHeight->setEnabled(checked);
ui->labPicXDescription->setEnabled(checked);
}
void OptionsDialog::on_cbPicCustomQuality_toggled(bool checked)
{
ui->hsPicQuality->setEnabled(checked);
ui->labPicQuality->setEnabled(checked);
ui->labPicQualityDescription->setEnabled(checked);
}
void OptionsDialog::on_hsPicQuality_valueChanged(int value)
{
customQuality = value;
ui->labPicQuality->setText(percentString.arg(QString::number(value)));
}
void OptionsDialog::setupPictureSettings()
{
settings->beginGroup("Pictures");
// Quality Settings
customQuality = settings->value("CustomQuality", defaultQuality).toInt();
if (customQuality < 1 || customQuality > 100)
{
customQuality = 100;
}
ui->hsPicQuality->setValue(customQuality);
ui->cbPicCustomQuality->setChecked(settings->value("CustomQualityEnabled", false).toBool());
// Size Settings
cusExportSize = settings->value("CustomSize", defExportSize).toSize();
if (cusExportSize.width() > 3840)
{
cusExportSize.setWidth(3840);
}
else if (cusExportSize.height() > 2160)
{
cusExportSize.setHeight(2160);
}
if (cusExportSize.width() < 1)
{
cusExportSize.setWidth(1);
}
else if (cusExportSize.height() < 1)
{
cusExportSize.setHeight(1);
}
ui->sbPicExportWidth->setValue(cusExportSize.width());
ui->sbPicExportHeight->setValue(cusExportSize.height());
QString sizeMode = settings->value("ExportSizeMode", "Default").toString();
if (sizeMode == "Desktop")
{
ui->rbPicDesktopRes->setChecked(true);
}
else if (sizeMode == "Custom")
{
ui->rbPicCustomRes->setChecked(true);
}
else
{
ui->rbPicDefaultRes->setChecked(true);
}
aspectRatio = (Qt::AspectRatioMode)settings->value("AspectRatio", Qt::KeepAspectRatio).toInt();
if (aspectRatio == Qt::IgnoreAspectRatio)
{
ui->cbIgnoreAspectRatio->setChecked(true);
}
settings->endGroup();
}
void OptionsDialog::on_cbIgnoreAspectRatio_toggled(bool checked)
{
if (checked)
{
aspectRatio = Qt::IgnoreAspectRatio;
}
else
{
aspectRatio = Qt::KeepAspectRatio;
}
}
void OptionsDialog::setupCustomGTAFolder()
{
bool ok;
QString defaultGameFolder = AppEnv::getGameFolder(&ok);
settings->beginGroup("dir");
currentCFolder = settings->value("dir", "").toString();
currentFFolder = settings->value("force", false).toBool();
if (currentCFolder == "" && ok)
{
currentCFolder = defaultGameFolder;
}
ui->txtFolder->setText(currentCFolder);
ui->cbForceCustomFolder->setChecked(currentFFolder);
settings->endGroup();
}
void OptionsDialog::setupSnapmaticPictureViewer()
{
#ifdef GTA5SYNC_WIN
#if QT_VERSION >= 0x050200
settings->beginGroup("Interface");
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
* Copyright (C) 2016-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 OPTIONSDIALOG_H
#define OPTIONSDIALOG_H
#include <QSize>
#include <QList>
#include <QDialog>
#include <QSettings>
#include <QTreeWidgetItem>
#include "ProfileDatabase.h"
namespace Ui {
class OptionsDialog;
}
class OptionsDialog : public QDialog
{
Q_OBJECT
public:
explicit OptionsDialog(ProfileDatabase *profileDB, QWidget *parent = 0);
void commitProfiles(QStringList profiles);
~OptionsDialog();
private slots:
void on_cmdOK_clicked();
void on_rbPicCustomRes_toggled(bool checked);
void on_cbPicCustomQuality_toggled(bool checked);
void on_hsPicQuality_valueChanged(int value);
void on_cbIgnoreAspectRatio_toggled(bool checked);
void on_cmdExploreFolder_clicked();
signals:
void settingsApplied(int contentMode, QString language);
private:
ProfileDatabase *profileDB;
Ui::OptionsDialog *ui;
QList<QTreeWidgetItem*> playerItems;
Qt::AspectRatioMode aspectRatio;
QString currentLanguage;
QString currentCFolder;
QString defaultProfile;
QString percentString;
QSettings *settings;
bool currentFFolder;
int contentMode;
int customQuality;
int defaultQuality;
QSize defExportSize;
QSize cusExportSize;
void setupTreeWidget();
void setupLanguageBox();
void setupRadioButtons();
void setupDefaultProfile();
void setupPictureSettings();
void setupCustomGTAFolder();
void setupSnapmaticPictureViewer();
void applySettings();
};
#endif // OPTIONSDIALOG_H
/******************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 OPTIONSDIALOG_H
#define OPTIONSDIALOG_H
#include <QSize>
#include <QList>
#include <QDialog>
#include <QSettings>
#include <QTreeWidgetItem>
#include "ProfileDatabase.h"
namespace Ui {
class OptionsDialog;
}
class OptionsDialog : public QDialog
{
Q_OBJECT
public:
explicit OptionsDialog(ProfileDatabase *profileDB, QWidget *parent = 0);
void commitProfiles(QStringList profiles);
~OptionsDialog();
private slots:
void on_cmdOK_clicked();
void on_rbPicCustomRes_toggled(bool checked);
void on_cbPicCustomQuality_toggled(bool checked);
void on_hsPicQuality_valueChanged(int value);
void on_cbIgnoreAspectRatio_toggled(bool checked);
void on_cmdExploreFolder_clicked();
signals:
void settingsApplied(int contentMode, QString language);
private:
ProfileDatabase *profileDB;
Ui::OptionsDialog *ui;
QList<QTreeWidgetItem*> playerItems;
Qt::AspectRatioMode aspectRatio;
QString currentLanguage;
QString currentCFolder;
QString defaultProfile;
QString percentString;
QSettings *settings;
bool currentFFolder;
int contentMode;
int customQuality;
int defaultQuality;
QSize defExportSize;
QSize cusExportSize;
void setupTreeWidget();
void setupLanguageBox();
void setupRadioButtons();
void setupDefaultProfile();
void setupPictureSettings();
void setupCustomGTAFolder();
void setupSnapmaticPictureViewer();
void applySettings();
};
#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
* Copyright (C) 2016-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 PICTUREDIALOG_H
#define PICTUREDIALOG_H
#include "SnapmaticPicture.h"
#include "ProfileDatabase.h"
#include "CrewDatabase.h"
#include <QMouseEvent>
#include <QDialog>
#include <QEvent>
#include <QMenu>
namespace Ui {
class PictureDialog;
}
class PictureDialog : public QDialog
{
Q_OBJECT
public:
explicit PictureDialog(ProfileDatabase *profileDB, CrewDatabase *crewDB, QWidget *parent = 0);
explicit PictureDialog(QWidget *parent = 0);
explicit PictureDialog(bool primaryWindow, ProfileDatabase *profileDB, CrewDatabase *crewDB, QWidget *parent = 0);
explicit PictureDialog(bool primaryWindow, QWidget *parent = 0);
void setupPictureDialog(bool withDatabase);
void setSnapmaticPicture(SnapmaticPicture *picture, bool readOk, bool indexed, int index);
void setSnapmaticPicture(SnapmaticPicture *picture, bool readOk, int index);
void setSnapmaticPicture(SnapmaticPicture *picture, bool readOk);
void setSnapmaticPicture(SnapmaticPicture *picture, int index);
void setSnapmaticPicture(SnapmaticPicture *picture);
void addPreviousNextButtons();
void stylizeDialog();
bool isIndexed();
int getIndex();
~PictureDialog();
public slots:
void playerNameUpdated();
void dialogNextPictureRequested();
void dialogPreviousPictureRequested();
void adaptNewDialogSize(QSize newLabelSize);
void exportCustomContextMenuRequested(const QPoint &pos);
private slots:
void copySnapmaticPicture();
void exportSnapmaticPicture();
void triggerFullscreenDoubeClick();
void on_labPicture_mouseDoubleClicked(Qt::MouseButton button);
void on_labPicture_customContextMenuRequested(const QPoint &pos);
void exportCustomContextMenuRequestedPrivate(const QPoint &pos, bool fullscreen);
void nextPictureRequestedSlot();
void previousPictureRequestedSlot();
void renderOverlayPicture();
void renderPicture();
signals:
void nextPictureRequested();
void previousPictureRequested();
void newPictureCommited(QImage picture);
void endDatabaseThread();
protected:
void closeEvent(QCloseEvent *ev);
bool eventFilter(QObject *obj, QEvent *ev);
void mousePressEvent(QMouseEvent *ev);
bool event(QEvent *event);
private:
bool primaryWindow;
ProfileDatabase *profileDB;
CrewDatabase *crewDB;
Ui::PictureDialog *ui;
QMap<QString, QString> globalMap;
SnapmaticPicture *smpic;
QWidget *fullscreenWidget;
QAction *jpegExportAction;
QAction *pgtaExportAction;
QImage avatarAreaPicture;
QImage snapmaticPicture;
QImage overlayTempImage;
QString jsonDrawString;
QString windowTitleStr;
QStringList plyrsList;
QString picAreaStr;
QString picArea;
QString picTitl;
QString picPath;
QString created;
QString crewID;
QString locX;
QString locY;
QString locZ;
bool overlayEnabled;
bool withDatabase;
bool rqFullscreen;
bool naviEnabled;
bool previewMode;
bool indexed;
int index;
int avatarLocX;
int avatarLocY;
int avatarSize;
QMenu *exportMenu;
};
#endif // PICTUREDIALOG_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 PICTUREDIALOG_H
#define PICTUREDIALOG_H
#include "SnapmaticPicture.h"
#include "ProfileDatabase.h"
#include "CrewDatabase.h"
#include <QMouseEvent>
#include <QDialog>
#include <QEvent>
#include <QMenu>
namespace Ui {
class PictureDialog;
}
class PictureDialog : public QDialog
{
Q_OBJECT
public:
explicit PictureDialog(ProfileDatabase *profileDB, CrewDatabase *crewDB, QWidget *parent = 0);
explicit PictureDialog(QWidget *parent = 0);
explicit PictureDialog(bool primaryWindow, ProfileDatabase *profileDB, CrewDatabase *crewDB, QWidget *parent = 0);
explicit PictureDialog(bool primaryWindow, QWidget *parent = 0);
void setupPictureDialog(bool withDatabase);
void setSnapmaticPicture(SnapmaticPicture *picture, bool readOk, bool indexed, int index);
void setSnapmaticPicture(SnapmaticPicture *picture, bool readOk, int index);
void setSnapmaticPicture(SnapmaticPicture *picture, bool readOk);
void setSnapmaticPicture(SnapmaticPicture *picture, int index);
void setSnapmaticPicture(SnapmaticPicture *picture);
void addPreviousNextButtons();
void stylizeDialog();
bool isIndexed();
int getIndex();
~PictureDialog();
public slots:
void crewNameUpdated();
void playerNameUpdated();
void dialogNextPictureRequested();
void dialogPreviousPictureRequested();
void adaptNewDialogSize(QSize newLabelSize);
void exportCustomContextMenuRequested(const QPoint &pos);
private slots:
void copySnapmaticPicture();
void exportSnapmaticPicture();
void triggerFullscreenDoubeClick();
void on_labPicture_mouseDoubleClicked(Qt::MouseButton button);
void on_labPicture_customContextMenuRequested(const QPoint &pos);
void exportCustomContextMenuRequestedPrivate(const QPoint &pos, bool fullscreen);
void nextPictureRequestedSlot();
void previousPictureRequestedSlot();
void editSnapmaticProperties();
void renderOverlayPicture();
void renderPicture();
void openPreviewMap();
void updated();
signals:
void nextPictureRequested();
void previousPictureRequested();
void newPictureCommited(QImage picture);
void endDatabaseThread();
protected:
void closeEvent(QCloseEvent *ev);
bool eventFilter(QObject *obj, QEvent *ev);
void mousePressEvent(QMouseEvent *ev);
bool event(QEvent *event);
private:
QString generateCrewString();
QString generatePlayersString();
bool primaryWindow;
ProfileDatabase *profileDB;
CrewDatabase *crewDB;
Ui::PictureDialog *ui;
QMap<QString, QString> globalMap;
SnapmaticPicture *smpic;
QWidget *fullscreenWidget;
QAction *jpegExportAction;
QAction *pgtaExportAction;
QAction *propEditorAction;
QAction *openViewerAction;
QAction *manageMenuSep1;
QImage avatarAreaPicture;
QImage snapmaticPicture;
QImage overlayTempImage;
QString jsonDrawString;
QString windowTitleStr;
QStringList plyrsList;
QString picAreaStr;
QString picArea;
QString picTitl;
QString picPath;
QString created;
QString crewStr;
QString crewID;
QString locX;
QString locY;
QString locZ;
bool overlayEnabled;
bool withDatabase;
bool rqFullscreen;
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"?>
<ui version="4.0">
<class>PictureDialog</class>
<widget class="QDialog" name="PictureDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>960</width>
<height>602</height>
</rect>
</property>
<property name="windowTitle">
<string>%1 - Snapmatic Picture Viewer</string>
</property>
<layout class="QVBoxLayout" name="vlPictureLayout">
<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="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="res/app.qrc">:/img/960x536.png</pixmap>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="vsJSONUpper">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QFrame" name="jsonFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="hlJson">
<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>
<layout class="QHBoxLayout" name="jsonLayout">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="UiModLabel" name="labJSON">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<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;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>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="vlButtons">
<property name="spacing">
<number>6</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<spacer name="vsButtons">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="hlButtons">
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="cmdExport">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Export picture</string>
</property>
<property name="text">
<string>&amp;Export</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdClose">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Close</string>
</property>
<property name="text">
<string>&amp;Close</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</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>
<include location="res/app.qrc"/>
</resources>
<connections>
<connection>
<sender>cmdClose</sender>
<signal>clicked()</signal>
<receiver>PictureDialog</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>912</x>
<y>514</y>
</hint>
<hint type="destinationlabel">
<x>479</x>
<y>267</y>
</hint>
</hints>
</connection>
</connections>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PictureDialog</class>
<widget class="QDialog" name="PictureDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>960</width>
<height>618</height>
</rect>
</property>
<property name="windowTitle">
<string>%1 - Snapmatic Picture Viewer</string>
</property>
<layout class="QVBoxLayout" name="vlPictureLayout">
<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="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="res/app.qrc">:/img/960x536.png</pixmap>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="vsJSONUpper">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QFrame" name="jsonFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="hlJson">
<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>
<layout class="QHBoxLayout" name="jsonLayout">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="UiModLabel" name="labJSON">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<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;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>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="vlButtons">
<property name="spacing">
<number>6</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<spacer name="vsButtons">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="hlButtons">
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="cmdManage">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Manage picture</string>
</property>
<property name="text">
<string>&amp;Manage</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdClose">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Close viewer</string>
</property>
<property name="text">
<string>&amp;Close</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</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>
<include location="res/app.qrc"/>
</resources>
<connections>
<connection>
<sender>cmdClose</sender>
<signal>clicked()</signal>
<receiver>PictureDialog</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>912</x>
<y>514</y>
</hint>
<hint type="destinationlabel">
<x>479</x>
<y>267</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View file

@ -1,310 +1,312 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "config.h"
#include "PictureExport.h"
#include "PictureDialog.h"
#include "StandardPaths.h"
#include "SidebarGenerator.h"
#include <QDesktopWidget>
#include <QApplication>
#include <QMessageBox>
#include <QFileDialog>
#include <QSettings>
#include <QDebug>
PictureExport::PictureExport()
{
}
void PictureExport::exportAsPicture(QWidget *parent, SnapmaticPicture *picture)
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
// Picture Settings
// Quality Settings
settings.beginGroup("Pictures");
int defaultQuality = 100;
QSize defExportSize = QSize(960, 536);
int customQuality = settings.value("CustomQuality", defaultQuality).toInt();
if (customQuality < 1 || customQuality > 100)
{
customQuality = 100;
}
bool useCustomQuality = settings.value("CustomQualityEnabled", false).toBool();
// Size Settings
QSize cusExportSize = settings.value("CustomSize", defExportSize).toSize();
if (cusExportSize.width() > 3840)
{
cusExportSize.setWidth(3840);
}
else if (cusExportSize.height() > 2160)
{
cusExportSize.setHeight(2160);
}
if (cusExportSize.width() < 1)
{
cusExportSize.setWidth(1);
}
else if (cusExportSize.height() < 1)
{
cusExportSize.setHeight(1);
}
QString sizeMode = settings.value("ExportSizeMode", "Default").toString();
Qt::AspectRatioMode aspectRatio = (Qt::AspectRatioMode)settings.value("AspectRatio", Qt::KeepAspectRatio).toInt();
QString defaultExportFormat = settings.value("DefaultExportFormat", ".jpg").toString();
settings.endGroup();
// End Picture Settings
settings.beginGroup("FileDialogs");
settings.beginGroup("ExportAsPicture");
fileDialogPreSave: //Work?
QFileDialog fileDialog(parent);
fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setViewMode(QFileDialog::Detail);
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
fileDialog.setOption(QFileDialog::DontUseNativeDialog, false);
fileDialog.setOption(QFileDialog::DontConfirmOverwrite, true);
fileDialog.setDefaultSuffix("suffix");
fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
fileDialog.setWindowTitle(PictureDialog::tr("Export as JPG picture..."));
fileDialog.setLabelText(QFileDialog::Accept, PictureDialog::tr("Export"));
QStringList filters;
filters << PictureDialog::tr("JPEG picture (*.jpg)");
filters << PictureDialog::tr("Portable Network Graphics (*.png)");
fileDialog.setNameFilters(filters);
QList<QUrl> sidebarUrls = SidebarGenerator::generateSidebarUrls(fileDialog.sidebarUrls());
fileDialog.setSidebarUrls(sidebarUrls);
fileDialog.setDirectory(settings.value("Directory", StandardPaths::picturesLocation()).toString());
fileDialog.restoreGeometry(settings.value(parent->objectName() + "+Geomtery", "").toByteArray());
QString newPictureFileName = getPictureFileName(picture) + defaultExportFormat;
fileDialog.selectFile(newPictureFileName);
if (fileDialog.exec())
{
QStringList selectedFiles = fileDialog.selectedFiles();
if (selectedFiles.length() == 1)
{
QString saveFileFormat;
QString selectedFile = selectedFiles.at(0);
if (selectedFile.right(4) == ".jpg")
{
saveFileFormat = "JPEG";
}
else if (selectedFile.right(4) == ".jpeg")
{
saveFileFormat = "JPEG";
}
else if (selectedFile.right(4) == ".png")
{
saveFileFormat = "PNG";
}
else if (selectedFile.right(7) == ".suffix")
{
if (fileDialog.selectedNameFilter() == "JPEG picture (*.jpg)")
{
selectedFile.replace(".suffix", ".jpg");
}
else if (fileDialog.selectedNameFilter() == "Portable Network Graphics (*.png)")
{
selectedFile.replace(".suffix", ".png");
}
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::remove(selectedFile))
{
QMessageBox::warning(parent, PictureDialog::tr("Export as JPG picture"), PictureDialog::tr("Failed to overwrite %1 with current Snapmatic picture").arg("\""+selectedFile+"\""));
goto fileDialogPreSave; //Work?
}
}
else
{
goto fileDialogPreSave; //Work?
}
}
// Scale Picture
QImage exportPicture = picture->getImage();
if (sizeMode == "Desktop")
{
QRect desktopResolution = QApplication::desktop()->screenGeometry();
exportPicture = exportPicture.scaled(desktopResolution.width(), desktopResolution.height(), aspectRatio, Qt::SmoothTransformation);
}
else if (sizeMode == "Custom")
{
exportPicture = exportPicture.scaled(cusExportSize, aspectRatio, Qt::SmoothTransformation);
}
bool isSaved;
if (useCustomQuality)
{
isSaved = exportPicture.save(selectedFile, saveFileFormat.toStdString().c_str(), customQuality);
}
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"));
goto fileDialogPreSave; //Work?
}
}
else
{
QMessageBox::warning(parent, PictureDialog::tr("Export as JPG 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.endGroup();
}
void PictureExport::exportAsSnapmatic(QWidget *parent, SnapmaticPicture *picture)
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("FileDialogs");
settings.beginGroup("ExportAsSnapmatic");
QString adjustedPicPath = picture->getPictureFileName();
if (adjustedPicPath.right(7) == ".hidden") // for the hidden file system
{
adjustedPicPath.remove(adjustedPicPath.length() - 7, 7);
}
fileDialogPreSave: //Work?
QFileInfo sgdFileInfo(adjustedPicPath);
QFileDialog fileDialog(parent);
fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setViewMode(QFileDialog::Detail);
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
fileDialog.setOption(QFileDialog::DontUseNativeDialog, false);
fileDialog.setOption(QFileDialog::DontConfirmOverwrite, true);
fileDialog.setDefaultSuffix(".rem");
fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
fileDialog.setWindowTitle(PictureDialog::tr("Export as GTA Snapmatic..."));
fileDialog.setLabelText(QFileDialog::Accept, PictureDialog::tr("Export"));
QStringList filters;
filters << PictureDialog::tr("GTA V Export (*.g5e)");
filters << PictureDialog::tr("GTA V Raw Export (*.auto)");
filters << PictureDialog::tr("Snapmatic pictures (PGTA*)");
fileDialog.setNameFilters(filters);
QList<QUrl> sidebarUrls = SidebarGenerator::generateSidebarUrls(fileDialog.sidebarUrls());
fileDialog.setSidebarUrls(sidebarUrls);
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 (selectedFiles.length() == 1)
{
QString selectedFile = selectedFiles.at(0);
if (QFile::exists(selectedFile))
{
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 (!QFile::remove(selectedFile))
{
QMessageBox::warning(parent, PictureDialog::tr("Export as GTA Snapmatic"), PictureDialog::tr("Failed to overwrite %1 with current Snapmatic picture").arg("\""+selectedFile+"\""));
goto fileDialogPreSave; //Work?
}
}
else
{
goto fileDialogPreSave; //Work?
}
}
if (selectedFile.right(4) == ".g5e")
{
bool isExported = picture->exportPicture(selectedFile, "G5E");
if (!isExported)
{
QMessageBox::warning(parent, PictureDialog::tr("Export as GTA Snapmatic"), PictureDialog::tr("Failed to export current Snapmatic picture"));
goto fileDialogPreSave; //Work?
}
}
else
{
bool isAutoExt = false;
if (selectedFile.right(5) == ".auto")
{
isAutoExt = true;
QString dirPath = QFileInfo(selectedFile).dir().path();
QString stockFileName = sgdFileInfo.fileName();
selectedFile = dirPath + "/" + stockFileName;
}
else if (selectedFile.right(4) == ".rem")
{
selectedFile.remove(".rem");
}
bool isCopied = picture->exportPicture(selectedFile, "PGTA");
if (!isCopied)
{
QMessageBox::warning(parent, PictureDialog::tr("Export as GTA Snapmatic"), PictureDialog::tr("Failed to export current Snapmatic picture"));
goto fileDialogPreSave; //Work?
}
else
{
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
{
QMessageBox::warning(parent, PictureDialog::tr("Export as GTA 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();
}
QString PictureExport::getPictureFileName(SnapmaticPicture *picture)
{
return picture->getExportPictureFileName();
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "config.h"
#include "PictureExport.h"
#include "PictureDialog.h"
#include "StandardPaths.h"
#include "SidebarGenerator.h"
#include <QStringBuilder>
#include <QDesktopWidget>
#include <QApplication>
#include <QMessageBox>
#include <QFileDialog>
#include <QSettings>
#include <QRegExp>
#include <QDebug>
PictureExport::PictureExport()
{
}
void PictureExport::exportAsPicture(QWidget *parent, SnapmaticPicture *picture)
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
// Picture Settings
// Quality Settings
settings.beginGroup("Pictures");
int defaultQuality = 100;
QSize defExportSize = QSize(960, 536);
int customQuality = settings.value("CustomQuality", defaultQuality).toInt();
if (customQuality < 1 || customQuality > 100)
{
customQuality = 100;
}
bool useCustomQuality = settings.value("CustomQualityEnabled", false).toBool();
// Size Settings
QSize cusExportSize = settings.value("CustomSize", defExportSize).toSize();
if (cusExportSize.width() > 3840)
{
cusExportSize.setWidth(3840);
}
else if (cusExportSize.height() > 2160)
{
cusExportSize.setHeight(2160);
}
if (cusExportSize.width() < 1)
{
cusExportSize.setWidth(1);
}
else if (cusExportSize.height() < 1)
{
cusExportSize.setHeight(1);
}
QString sizeMode = settings.value("ExportSizeMode", "Default").toString();
Qt::AspectRatioMode aspectRatio = (Qt::AspectRatioMode)settings.value("AspectRatio", Qt::KeepAspectRatio).toInt();
QString defaultExportFormat = settings.value("DefaultExportFormat", ".jpg").toString();
settings.endGroup();
// End Picture Settings
settings.beginGroup("FileDialogs");
settings.beginGroup("ExportAsPicture");
fileDialogPreSave: //Work?
QFileDialog fileDialog(parent);
fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setViewMode(QFileDialog::Detail);
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
fileDialog.setOption(QFileDialog::DontUseNativeDialog, false);
fileDialog.setOption(QFileDialog::DontConfirmOverwrite, true);
fileDialog.setDefaultSuffix("suffix");
fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
fileDialog.setWindowTitle(PictureDialog::tr("Export as Picture..."));
fileDialog.setLabelText(QFileDialog::Accept, PictureDialog::tr("Export"));
QStringList filters;
filters << PictureDialog::tr("JPEG Graphics (*.jpg *.jpeg)");
filters << PictureDialog::tr("Portable Network Graphics (*.png)");
fileDialog.setNameFilters(filters);
QList<QUrl> sidebarUrls = SidebarGenerator::generateSidebarUrls(fileDialog.sidebarUrls());
fileDialog.setSidebarUrls(sidebarUrls);
fileDialog.setDirectory(settings.value("Directory", StandardPaths::picturesLocation()).toString());
fileDialog.restoreGeometry(settings.value(parent->objectName() % "+Geomtery", "").toByteArray());
QString newPictureFileName = getPictureFileName(picture) % defaultExportFormat;
fileDialog.selectFile(newPictureFileName);
if (fileDialog.exec())
{
QStringList selectedFiles = fileDialog.selectedFiles();
if (selectedFiles.length() == 1)
{
QString saveFileFormat;
QString selectedFile = selectedFiles.at(0);
if (selectedFile.right(4) == ".jpg")
{
saveFileFormat = "JPEG";
}
else if (selectedFile.right(4) == ".jpeg")
{
saveFileFormat = "JPEG";
}
else if (selectedFile.right(4) == ".png")
{
saveFileFormat = "PNG";
}
else if (selectedFile.right(7) == ".suffix")
{
if (fileDialog.selectedNameFilter() == "JPEG picture (*.jpg)")
{
selectedFile.replace(".suffix", ".jpg");
}
else if (fileDialog.selectedNameFilter() == "Portable Network Graphics (*.png)")
{
selectedFile.replace(".suffix", ".png");
}
else
{
selectedFile.replace(".suffix", ".jpg");
}
}
if (QFile::exists(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))
{
if (!QFile::remove(selectedFile))
{
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?
}
}
// Scale Picture
QImage exportPicture = picture->getImage();
if (sizeMode == "Desktop")
{
QRect desktopResolution = QApplication::desktop()->screenGeometry();
exportPicture = exportPicture.scaled(desktopResolution.width(), desktopResolution.height(), aspectRatio, Qt::SmoothTransformation);
}
else if (sizeMode == "Custom")
{
exportPicture = exportPicture.scaled(cusExportSize, aspectRatio, Qt::SmoothTransformation);
}
bool isSaved;
if (useCustomQuality)
{
isSaved = exportPicture.save(selectedFile, saveFileFormat.toStdString().c_str(), customQuality);
}
else
{
isSaved = exportPicture.save(selectedFile, saveFileFormat.toStdString().c_str(), 100);
}
if (!isSaved)
{
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 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.endGroup();
}
void PictureExport::exportAsSnapmatic(QWidget *parent, SnapmaticPicture *picture)
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("FileDialogs");
settings.beginGroup("ExportAsSnapmatic");
QString adjustedPicPath = picture->getPictureFileName();
if (adjustedPicPath.right(7) == ".hidden") // for the hidden file system
{
adjustedPicPath.remove(adjustedPicPath.length() - 7, 7);
}
fileDialogPreSave: //Work?
QFileInfo sgdFileInfo(adjustedPicPath);
QFileDialog fileDialog(parent);
fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setViewMode(QFileDialog::Detail);
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
fileDialog.setOption(QFileDialog::DontUseNativeDialog, false);
fileDialog.setOption(QFileDialog::DontConfirmOverwrite, true);
fileDialog.setDefaultSuffix(".rem");
fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
fileDialog.setWindowTitle(PictureDialog::tr("Export as Snapmatic..."));
fileDialog.setLabelText(QFileDialog::Accept, PictureDialog::tr("Export"));
QStringList filters;
filters << PictureDialog::tr("GTA V Export (*.g5e)");
filters << PictureDialog::tr("GTA V Raw Export (*.auto)");
filters << PictureDialog::tr("Snapmatic pictures (PGTA*)");
fileDialog.setNameFilters(filters);
QList<QUrl> sidebarUrls = SidebarGenerator::generateSidebarUrls(fileDialog.sidebarUrls());
fileDialog.setSidebarUrls(sidebarUrls);
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 (selectedFiles.length() == 1)
{
QString selectedFile = selectedFiles.at(0);
bool isAutoExt = false;
if (selectedFile.right(5) == ".auto")
{
isAutoExt = true;
QString dirPath = QFileInfo(selectedFile).dir().path();
QString stockFileName = sgdFileInfo.fileName();
selectedFile = dirPath % "/" % stockFileName;
}
else if (selectedFile.right(4) == ".rem")
{
selectedFile.remove(selectedFile.length() - 4, 4);
}
if (QFile::exists(selectedFile))
{
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))
{
if (!QFile::remove(selectedFile))
{
QMessageBox::warning(parent, PictureDialog::tr("Export as Snapmatic"), PictureDialog::tr("Failed to overwrite %1 with current Snapmatic picture").arg("\""+selectedFile+"\""));
goto fileDialogPreSave; //Work?
}
}
else
{
goto fileDialogPreSave; //Work?
}
}
if (selectedFile.right(4) == ".g5e")
{
bool isExported = picture->exportPicture(selectedFile, SnapmaticFormat::G5E_Format);
if (!isExported)
{
QMessageBox::warning(parent, PictureDialog::tr("Export as Snapmatic"), PictureDialog::tr("Failed to export current Snapmatic picture"));
goto fileDialogPreSave; //Work?
}
}
else
{
bool isCopied = picture->exportPicture(selectedFile, SnapmaticFormat::PGTA_Format);
if (!isCopied)
{
QMessageBox::warning(parent, PictureDialog::tr("Export as Snapmatic"), PictureDialog::tr("Failed to export current Snapmatic picture"));
goto fileDialogPreSave; //Work?
}
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 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();
}
QString PictureExport::getPictureFileName(SnapmaticPicture *picture)
{
return picture->getExportPictureFileName();
}

View file

@ -1,35 +1,35 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 PICTUREEXPORT_H
#define PICTUREEXPORT_H
#include "SnapmaticPicture.h"
#include <QWidget>
#include <QString>
class PictureExport
{
public:
PictureExport();
static void exportAsPicture(QWidget *parent, SnapmaticPicture *picture);
static void exportAsSnapmatic(QWidget *parent, SnapmaticPicture *picture);
static QString getPictureFileName(SnapmaticPicture *picture);
};
#endif // PICTUREEXPORT_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 PICTUREEXPORT_H
#define PICTUREEXPORT_H
#include "SnapmaticPicture.h"
#include <QWidget>
#include <QString>
class PictureExport
{
public:
PictureExport();
static void exportAsPicture(QWidget *parent, SnapmaticPicture *picture);
static void exportAsSnapmatic(QWidget *parent, SnapmaticPicture *picture);
static QString getPictureFileName(SnapmaticPicture *picture);
};
#endif // PICTUREEXPORT_H

View file

@ -1,61 +1,76 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "ProfileDatabase.h"
#include "StandardPaths.h"
#include "config.h"
#include <QFile>
#include <QDir>
ProfileDatabase::ProfileDatabase(QObject *parent) : QObject(parent)
{
QDir dir;
dir.mkpath(StandardPaths::dataLocation());
dir.setPath(StandardPaths::dataLocation());
QString dirPath = dir.absolutePath();
QString defaultConfPath = dirPath + QDir::separator() + "players.ini";
QSettings confPathSettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
confPathSettings.beginGroup("Database");
QString confPathFile = confPathSettings.value("Players", defaultConfPath).toString();
confPathSettings.endGroup();
profileDB = new QSettings(confPathFile, QSettings::IniFormat);
profileDB->beginGroup("Players");
}
ProfileDatabase::~ProfileDatabase()
{
profileDB->endGroup();
delete profileDB;
}
QStringList ProfileDatabase::getPlayers()
{
return profileDB->childKeys();
}
QString ProfileDatabase::getPlayerName(int playerID)
{
return profileDB->value(QString::number(playerID), playerID).toString();
}
void ProfileDatabase::setPlayerName(int playerID, QString playerName)
{
profileDB->setValue(QString::number(playerID), playerName);
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "ProfileDatabase.h"
#include "StandardPaths.h"
#include "config.h"
#include <QStringBuilder>
#include <QMutexLocker>
#include <QDebug>
#include <QFile>
#include <QDir>
ProfileDatabase::ProfileDatabase(QObject *parent) : QObject(parent)
{
QDir dir;
dir.mkpath(StandardPaths::dataLocation());
dir.setPath(StandardPaths::dataLocation());
QString dirPath = dir.absolutePath();
QString defaultConfPath = dirPath % QDir::separator() % "players.ini";
QSettings confPathSettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
confPathSettings.beginGroup("Database");
QString confPathFile = confPathSettings.value("Players", defaultConfPath).toString();
confPathSettings.endGroup();
profileDB = new QSettings(confPathFile, QSettings::IniFormat);
profileDB->beginGroup("Players");
}
ProfileDatabase::~ProfileDatabase()
{
profileDB->endGroup();
delete profileDB;
}
QStringList ProfileDatabase::getPlayers()
{
QMutexLocker locker(&mutex);
#ifdef GTA5SYNC_DEBUG
qDebug() << "getPlayers";
#endif
return profileDB->childKeys();
}
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
* Copyright (C) 2016-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 PROFILEDATABASE_H
#define PROFILEDATABASE_H
#include <QSettings>
#include <QObject>
#include <QMap>
class ProfileDatabase : public QObject
{
Q_OBJECT
public:
explicit ProfileDatabase(QObject *parent = 0);
QString getPlayerName(int playerID);
QStringList getPlayers();
~ProfileDatabase();
private:
QSettings *profileDB;
public slots:
void setPlayerName(int playerID, QString playerName);
};
#endif // PROFILEDATABASE_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 PROFILEDATABASE_H
#define PROFILEDATABASE_H
#include <QSettings>
#include <QObject>
#include <QMutex>
#include <QMap>
class ProfileDatabase : public QObject
{
Q_OBJECT
public:
explicit ProfileDatabase(QObject *parent = 0);
QString getPlayerName(int playerID);
QStringList getPlayers();
~ProfileDatabase();
private:
mutable QMutex mutex;
QSettings *profileDB;
public slots:
void setPlayerName(int playerID, QString playerName);
};
#endif // PROFILEDATABASE_H

View file

@ -38,6 +38,7 @@
#include <QPushButton>
#include <QSpacerItem>
#include <QMessageBox>
#include <QMouseEvent>
#include <QFileDialog>
#include <QEventLoop>
#include <QScrollBar>
@ -64,13 +65,14 @@ ProfileInterface::ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *cre
enabledPicStr = tr("Enabled pictures: %1 of %2");
selectedWidgts = 0;
profileFolder = "";
profileLoader = 0;
saSpacerItem = 0;
contextMenuOpened = false;
isProfileLoaded = false;
previousWidget = nullptr;
profileLoader = nullptr;
saSpacerItem = nullptr;
QPalette palette;
QColor baseColor = palette.base().color();
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())));
updatePalette();
ui->labVersion->setText(QString("%1 %2").arg(GTA5SYNC_APPSTR, GTA5SYNC_APPVER));
ui->saProfileContent->setFilesMode(true);
if (QIcon::hasThemeIcon("dialog-close"))
@ -87,6 +89,9 @@ ProfileInterface::ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *cre
ui->hlButtons->setSpacing(6 * screenRatio);
ui->hlButtons->setContentsMargins(9 * screenRatio, 15 * screenRatio, 15 * screenRatio, 17 * screenRatio);
#endif
setMouseTracking(true);
installEventFilter(this);
}
ProfileInterface::~ProfileInterface()
@ -94,6 +99,8 @@ ProfileInterface::~ProfileInterface()
foreach(ProfileWidget *widget, widgets.keys())
{
widgets.remove(widget);
widget->removeEventFilter(this);
widget->disconnect();
delete widget;
}
foreach(SavegameData *savegame, savegames)
@ -138,6 +145,8 @@ void ProfileInterface::savegameLoaded(SavegameData *savegame, QString savegamePa
SavegameWidget *sgdWidget = new SavegameWidget(this);
sgdWidget->setSavegameData(savegame, savegamePath);
sgdWidget->setContentMode(contentMode);
sgdWidget->setMouseTracking(true);
sgdWidget->installEventFilter(this);
widgets[sgdWidget] = "SGD" % QFileInfo(savegamePath).fileName();
savegames += savegame;
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);
picWidget->setSnapmaticPicture(picture);
picWidget->setContentMode(contentMode);
picWidget->setMouseTracking(true);
picWidget->installEventFilter(this);
widgets[picWidget] = "PIC" % picture->getPictureSortStr();
pictures += picture;
if (selectedWidgts != 0 || contentMode == 2) { picWidget->setSelectionMode(true); }
@ -183,7 +194,7 @@ void ProfileInterface::loadingProgress(int value, int maximum)
void ProfileInterface::insertSnapmaticIPI(QWidget *widget)
{
ProfileWidget *proWidget = (ProfileWidget*)widget;
ProfileWidget *proWidget = qobject_cast<ProfileWidget*>(widget);
if (widgets.contains(proWidget))
{
QString widgetKey = widgets[proWidget];
@ -204,7 +215,7 @@ void ProfileInterface::insertSnapmaticIPI(QWidget *widget)
void ProfileInterface::insertSavegameIPI(QWidget *widget)
{
ProfileWidget *proWidget = (ProfileWidget*)widget;
ProfileWidget *proWidget = qobject_cast<ProfileWidget*>(widget);
if (widgets.contains(proWidget))
{
QString widgetKey = widgets[proWidget];
@ -221,8 +232,8 @@ void ProfileInterface::insertSavegameIPI(QWidget *widget)
void ProfileInterface::dialogNextPictureRequested(QWidget *dialog)
{
PictureDialog *picDialog = (PictureDialog*)dialog;
ProfileWidget *proWidget = (ProfileWidget*)sender();
PictureDialog *picDialog = qobject_cast<PictureDialog*>(dialog);
ProfileWidget *proWidget = qobject_cast<ProfileWidget*>(sender());
if (widgets.contains(proWidget))
{
QString widgetKey = widgets[proWidget];
@ -256,8 +267,8 @@ void ProfileInterface::dialogNextPictureRequested(QWidget *dialog)
void ProfileInterface::dialogPreviousPictureRequested(QWidget *dialog)
{
PictureDialog *picDialog = (PictureDialog*)dialog;
ProfileWidget *proWidget = (ProfileWidget*)sender();
PictureDialog *picDialog = qobject_cast<PictureDialog*>(dialog);
ProfileWidget *proWidget = qobject_cast<ProfileWidget*>(sender());
if (widgets.contains(proWidget))
{
QString widgetKey = widgets[proWidget];
@ -324,12 +335,13 @@ void ProfileInterface::profileLoaded_p()
ui->swProfile->setCurrentWidget(ui->pageProfile);
ui->cmdCloseProfile->setEnabled(true);
ui->cmdImport->setEnabled(true);
isProfileLoaded = true;
emit profileLoaded();
}
void ProfileInterface::savegameDeleted_event()
{
savegameDeleted((SavegameWidget*)sender(), true);
savegameDeleted(qobject_cast<SavegameWidget*>(sender()), true);
}
void ProfileInterface::savegameDeleted(SavegameWidget *sgdWidget, bool isRemoteEmited)
@ -338,13 +350,21 @@ void ProfileInterface::savegameDeleted(SavegameWidget *sgdWidget, bool isRemoteE
if (sgdWidget->isSelected()) { sgdWidget->setSelected(false); }
widgets.remove(sgdWidget);
sgdWidget->removeEventFilter(this);
if (sgdWidget == previousWidget)
{
previousWidget = nullptr;
}
// Deleting when the widget did send a event cause a crash
if (isRemoteEmited)
{
sgdWidget->disconnect();
sgdWidget->deleteLater();
}
else
{
sgdWidget->disconnect();
delete sgdWidget;
}
@ -354,7 +374,7 @@ void ProfileInterface::savegameDeleted(SavegameWidget *sgdWidget, bool isRemoteE
void ProfileInterface::pictureDeleted_event()
{
pictureDeleted((SnapmaticWidget*)sender(), true);
pictureDeleted(qobject_cast<SnapmaticWidget*>(sender()), true);
}
void ProfileInterface::pictureDeleted(SnapmaticWidget *picWidget, bool isRemoteEmited)
@ -363,13 +383,21 @@ void ProfileInterface::pictureDeleted(SnapmaticWidget *picWidget, bool isRemoteE
if (picWidget->isSelected()) { picWidget->setSelected(false); }
widgets.remove(picWidget);
picWidget->removeEventFilter(this);
if (picWidget == previousWidget)
{
previousWidget = nullptr;
}
// Deleting when the widget did send a event cause a crash
if (isRemoteEmited)
{
picWidget->disconnect();
picWidget->deleteLater();
}
else
{
picWidget->disconnect();
delete picWidget;
}
@ -398,12 +426,24 @@ fileDialogPreOpen: //Work?
fileDialog.setWindowTitle(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;
filters << tr("Importable files (*.g5e *.jpg *.png SGTA* PGTA*)");
filters << tr("Importable files (%1)").arg(importableFormatsStr);
filters << tr("GTA V Export (*.g5e)");
filters << tr("Savegames files (SGTA*)");
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 (**)");
fileDialog.setNameFilters(filters);
@ -520,7 +560,7 @@ bool ProfileInterface::importFile(QString selectedFile, bool notMultiple)
return false;
}
}
else if(selectedFileName.right(4) == ".jpg" || selectedFileName.right(4) == ".png")
else if(isSupportedImageFile(selectedFileName))
{
SnapmaticPicture *picture = new SnapmaticPicture(":/template/template.g5e");
if (picture->readingPicture(true, false, true, false))
@ -631,6 +671,7 @@ bool ProfileInterface::importFile(QString selectedFile, bool notMultiple)
snapmaticImageReader.setDevice(&snapmaticFile);
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;
return false;
}
@ -640,7 +681,7 @@ bool ProfileInterface::importFile(QString selectedFile, bool notMultiple)
importDialog->setModal(true);
importDialog->show();
importDialog->exec();
if (importDialog->isDoImport())
if (importDialog->isImportAgreed())
{
if (picture->setImage(importDialog->image()))
{
@ -705,9 +746,13 @@ bool ProfileInterface::importFile(QString selectedFile, bool notMultiple)
}
else
{
delete savegame;
#ifdef GTA5SYNC_DEBUG
qDebug() << "ImportError SnapmaticPicture" << picture->getLastStep();
qDebug() << "ImportError SavegameData" << savegame->getLastStep();
#endif
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;
}
}
@ -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"));
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);
pictureLoaded(picture, true);
@ -914,8 +959,10 @@ void ProfileInterface::exportSelected()
}
else
{
pictureExportEnabled = true;
pictureCopyEnabled = true;
// Don't export anymore when any Cancel button got clicked
settings.endGroup();
settings.endGroup();
return;
}
}
@ -934,7 +981,7 @@ void ProfileInterface::exportSelected()
QProgressDialog pbDialog(this);
pbDialog.setWindowFlags(pbDialog.windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint);
pbDialog.setWindowTitle(tr("Export selected..."));
pbDialog.setLabelText(tr("Initializing export..."));
pbDialog.setLabelText(tr("Initialising export..."));
pbDialog.setRange(0, exportCount);
QList<QPushButton*> pbBtn = pbDialog.findChildren<QPushButton*>();
@ -1003,7 +1050,7 @@ void ProfileInterface::deleteSelected()
{
if (widget->getWidgetType() == "SnapmaticWidget")
{
SnapmaticWidget *picWidget = (SnapmaticWidget*)widget;
SnapmaticWidget *picWidget = qobject_cast<SnapmaticWidget*>(widget);
if (picWidget->getPicture()->deletePicFile())
{
pictureDeleted(picWidget);
@ -1011,7 +1058,7 @@ void ProfileInterface::deleteSelected()
}
else if (widget->getWidgetType() == "SavegameWidget")
{
SavegameWidget *sgdWidget = (SavegameWidget*)widget;
SavegameWidget *sgdWidget = qobject_cast<SavegameWidget*>(widget);
SavegameData *savegame = sgdWidget->getSavegame();
QString fileName = savegame->getSavegameFileName();
if (!QFile::exists(fileName) || QFile::remove(fileName))
@ -1038,9 +1085,15 @@ void ProfileInterface::importFiles()
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;
if (contentMode == 2)
@ -1049,6 +1102,7 @@ void ProfileInterface::settingsApplied(int _contentMode, QString language)
{
widget->setSelectionMode(true);
widget->setContentMode(contentMode);
if (translationUpdated) widget->retranslate();
}
}
else
@ -1060,6 +1114,7 @@ void ProfileInterface::settingsApplied(int _contentMode, QString language)
widget->setSelectionMode(false);
}
widget->setContentMode(contentMode);
if (translationUpdated) widget->retranslate();
}
}
}
@ -1073,7 +1128,7 @@ void ProfileInterface::enableSelected()
{
if (widget->getWidgetType() == "SnapmaticWidget")
{
SnapmaticWidget *snapmaticWidget = (SnapmaticWidget*)widget;
SnapmaticWidget *snapmaticWidget = qobject_cast<SnapmaticWidget*>(widget);
if (!snapmaticWidget->makePictureVisible())
{
fails++;
@ -1092,7 +1147,7 @@ void ProfileInterface::disableSelected()
{
if (widget->getWidgetType() == "SnapmaticWidget")
{
SnapmaticWidget *snapmaticWidget = (SnapmaticWidget*)widget;
SnapmaticWidget *snapmaticWidget = qobject_cast<SnapmaticWidget*>(widget);
if (!snapmaticWidget->makePictureHidden())
{
fails++;
@ -1109,7 +1164,16 @@ int ProfileInterface::selectedWidgets()
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 editMenu(SnapmaticWidget::tr("Edi&t"), picWidget);
if (picWidget->isHidden())
@ -1122,8 +1186,8 @@ void ProfileInterface::contextMenuTriggeredPIC(QContextMenuEvent *ev)
}
editMenu.addAction(SnapmaticWidget::tr("&Edit Properties..."), picWidget, SLOT(editSnapmaticProperties()));
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 &GTA Snapmatic..."), picWidget, SLOT(on_cmdCopy_clicked()));
exportMenu.addAction(SnapmaticWidget::tr("Export as &Picture..."), picWidget, SLOT(on_cmdExport_clicked()));
exportMenu.addAction(SnapmaticWidget::tr("Export as &Snapmatic..."), picWidget, SLOT(on_cmdCopy_clicked()));
contextMenu.addAction(SnapmaticWidget::tr("&View"), picWidget, SLOT(on_cmdView_clicked()));
contextMenu.addMenu(&editMenu);
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"));
}
contextMenuOpened = true;
contextMenu.exec(ev->globalPos());
contextMenuOpened = false;
hoverProfileWidgetCheck();
}
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);
contextMenu.addAction(SavegameWidget::tr("&View"), sgdWidget, SLOT(on_cmdView_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"));
}
contextMenuOpened = true;
contextMenu.exec(ev->globalPos());
contextMenuOpened = false;
hoverProfileWidgetCheck();
}
void ProfileInterface::on_saProfileContent_dropped(const QMimeData *mimeData)
@ -1187,3 +1266,200 @@ void ProfileInterface::on_saProfileContent_dropped(const QMimeData *mimeData)
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
* Copyright (C) 2016-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 PROFILEINTERFACE_H
#define PROFILEINTERFACE_H
#include "SnapmaticPicture.h"
#include "SnapmaticWidget.h"
#include "ProfileDatabase.h"
#include "DatabaseThread.h"
#include "SavegameWidget.h"
#include "ProfileLoader.h"
#include "ProfileWidget.h"
#include "ExportThread.h"
#include "SavegameData.h"
#include "CrewDatabase.h"
#include <QProgressDialog>
#include <QSpacerItem>
#include <QWidget>
#include <QList>
#include <QMap>
namespace Ui {
class ProfileInterface;
}
class ProfileInterface : public QWidget
{
Q_OBJECT
public:
explicit ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0);
void setProfileFolder(QString folder, QString profile);
void settingsApplied(int contentMode, QString language);
void setupProfileInterface();
void disableSelected();
void enableSelected();
int selectedWidgets();
~ProfileInterface();
public slots:
void contextMenuTriggeredPIC(QContextMenuEvent* ev);
void contextMenuTriggeredSGD(QContextMenuEvent* ev);
void selectAllWidgets();
void deselectAllWidgets();
void exportSelected();
void deleteSelected();
void importFiles();
private slots:
void on_cmdCloseProfile_clicked();
void on_cmdImport_clicked();
void pictureLoaded_event(SnapmaticPicture *picture);
void savegameLoaded_event(SavegameData *savegame, QString savegamePath);
void loadingProgress(int value, int maximum);
void pictureDeleted_event();
void savegameDeleted_event();
void profileLoaded_p();
void profileWidgetSelected();
void profileWidgetDeselected();
void dialogNextPictureRequested(QWidget *dialog);
void dialogPreviousPictureRequested(QWidget *dialog);
void on_saProfileContent_dropped(const QMimeData *mimeData);
private:
ProfileDatabase *profileDB;
CrewDatabase *crewDB;
DatabaseThread *threadDB;
Ui::ProfileInterface *ui;
ProfileLoader *profileLoader;
QList<SavegameData*> savegames;
QList<SnapmaticPicture*> pictures;
QMap<ProfileWidget*,QString> widgets;
QSpacerItem *saSpacerItem;
QString enabledPicStr;
QString profileFolder;
QString profileName;
QString loadingStr;
int selectedWidgts;
int contentMode;
bool importFile(QString selectedFile, bool notMultiple);
void importFilesProgress(QStringList selectedFiles);
bool importSnapmaticPicture(SnapmaticPicture *picture, bool warn = true);
bool importSavegameData(SavegameData *savegame, QString sgdPath, bool warn = true);
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
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 PROFILEINTERFACE_H
#define PROFILEINTERFACE_H
#include "SnapmaticPicture.h"
#include "SnapmaticWidget.h"
#include "ProfileDatabase.h"
#include "DatabaseThread.h"
#include "SavegameWidget.h"
#include "ProfileLoader.h"
#include "ProfileWidget.h"
#include "ExportThread.h"
#include "SavegameData.h"
#include "CrewDatabase.h"
#include <QProgressDialog>
#include <QSpacerItem>
#include <QWidget>
#include <QList>
#include <QMap>
namespace Ui {
class ProfileInterface;
}
class ProfileInterface : public QWidget
{
Q_OBJECT
public:
explicit ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0);
void setProfileFolder(QString folder, QString profile);
void settingsApplied(int contentMode, QString language);
void setupProfileInterface();
void disableSelected();
void enableSelected();
int selectedWidgets();
void retranslateUi();
~ProfileInterface();
public slots:
void contextMenuTriggeredPIC(QContextMenuEvent* ev);
void contextMenuTriggeredSGD(QContextMenuEvent* ev);
void hoverProfileWidgetCheck();
void selectAllWidgets();
void deselectAllWidgets();
void exportSelected();
void deleteSelected();
void updatePalette();
void importFiles();
private slots:
void on_cmdCloseProfile_clicked();
void on_cmdImport_clicked();
void pictureLoaded_event(SnapmaticPicture *picture);
void savegameLoaded_event(SavegameData *savegame, QString savegamePath);
void loadingProgress(int value, int maximum);
void pictureDeleted_event();
void savegameDeleted_event();
void profileLoaded_p();
void profileWidgetSelected();
void profileWidgetDeselected();
void dialogNextPictureRequested(QWidget *dialog);
void dialogPreviousPictureRequested(QWidget *dialog);
void on_saProfileContent_dropped(const QMimeData *mimeData);
protected:
bool eventFilter(QObject *watched, QEvent *event);
private:
ProfileDatabase *profileDB;
CrewDatabase *crewDB;
DatabaseThread *threadDB;
Ui::ProfileInterface *ui;
ProfileLoader *profileLoader;
ProfileWidget *previousWidget;
QList<SavegameData*> savegames;
QList<SnapmaticPicture*> pictures;
QMap<ProfileWidget*,QString> widgets;
QSpacerItem *saSpacerItem;
QColor highlightBackColor;
QColor highlightTextColor;
QString enabledPicStr;
QString profileFolder;
QString profileName;
QString loadingStr;
QString language;
bool contextMenuOpened;
bool isProfileLoaded;
int selectedWidgts;
int contentMode;
bool isSupportedImageFile(QString selectedFileName);
bool importFile(QString selectedFile, bool notMultiple);
void importFilesProgress(QStringList selectedFiles);
bool importSnapmaticPicture(SnapmaticPicture *picture, bool warn = true);
bool importSavegameData(SavegameData *savegame, QString sgdPath, bool warn = true);
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"?>
<ui version="4.0">
<class>ProfileInterface</class>
<widget class="QWidget" name="ProfileInterface">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Profile Interface</string>
</property>
<layout class="QVBoxLayout" name="vlProfileInterface">
<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="QStackedWidget" name="swProfile">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="pageLoading">
<layout class="QVBoxLayout" name="vlLoadingPage">
<item>
<spacer name="vsLoading1">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labProfileLoading">
<property name="text">
<string>Loading file %1 of %2 files</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="pbPictureLoading">
<property name="value">
<number>0</number>
</property>
<property name="textVisible">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="vsLoading2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="pageProfile">
<layout class="QVBoxLayout" name="vlProfilePage">
<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="QScrollArea" name="saProfile">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="UiModWidget" name="saProfileContent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>398</width>
<height>257</height>
</rect>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="vlProfile">
<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>
<layout class="QVBoxLayout" name="vlContent">
<property name="spacing">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="vlSavegame"/>
</item>
<item>
<layout class="QVBoxLayout" name="vlSnapmatic"/>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="hlButtons">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<widget class="QLabel" name="labVersion">
<property name="text">
<string>%1 %2</string>
</property>
</widget>
</item>
<item>
<spacer name="hsProfile">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="cmdImport">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Import exported file</string>
</property>
<property name="text">
<string>&amp;Import...</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdCloseProfile">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Close profile</string>
</property>
<property name="text">
<string>&amp;Close</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>UiModWidget</class>
<extends>QWidget</extends>
<header>UiModWidget.h</header>
<container>1</container>
<slots>
<signal>dropped(QMimeData*)</signal>
</slots>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ProfileInterface</class>
<widget class="QWidget" name="ProfileInterface">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Profile Interface</string>
</property>
<layout class="QVBoxLayout" name="vlProfileInterface">
<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="QStackedWidget" name="swProfile">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="pageLoading">
<layout class="QVBoxLayout" name="vlLoadingPage">
<item>
<spacer name="vsLoading1">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labProfileLoading">
<property name="text">
<string>Loading file %1 of %2 files</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="pbPictureLoading">
<property name="value">
<number>0</number>
</property>
<property name="textVisible">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="vsLoading2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="pageProfile">
<layout class="QVBoxLayout" name="vlProfilePage">
<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="QScrollArea" name="saProfile">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="UiModWidget" name="saProfileContent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>398</width>
<height>257</height>
</rect>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="vlProfile">
<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>
<layout class="QVBoxLayout" name="vlContent">
<property name="spacing">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="vlSavegame"/>
</item>
<item>
<layout class="QVBoxLayout" name="vlSnapmatic"/>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="hlButtons">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<widget class="QLabel" name="labVersion">
<property name="text">
<string>%1 %2</string>
</property>
</widget>
</item>
<item>
<spacer name="hsProfile">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="cmdImport">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Import file</string>
</property>
<property name="text">
<string>&amp;Import...</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdCloseProfile">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Close profile</string>
</property>
<property name="text">
<string>&amp;Close</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>UiModWidget</class>
<extends>QWidget</extends>
<header>UiModWidget.h</header>
<container>1</container>
<slots>
<signal>dropped(QMimeData*)</signal>
</slots>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View file

@ -1,103 +1,106 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "ProfileLoader.h"
#include "SnapmaticPicture.h"
#include "SavegameData.h"
#include "CrewDatabase.h"
#include <QStringList>
#include <QString>
#include <QFile>
#include <QDir>
ProfileLoader::ProfileLoader(QString profileFolder, CrewDatabase *crewDB, QObject *parent) : QThread(parent), profileFolder(profileFolder), crewDB(crewDB)
{
}
void ProfileLoader::run()
{
int curFile = 1;
QDir profileDir;
QList<int> crewList;
profileDir.setPath(profileFolder);
// Seek pictures and savegames
profileDir.setNameFilters(QStringList("SGTA*"));
QStringList SavegameFiles = profileDir.entryList(QDir::Files | QDir::NoDot, QDir::NoSort);
QStringList BackupFiles = SavegameFiles.filter(".bak", Qt::CaseInsensitive);
profileDir.setNameFilters(QStringList("PGTA*"));
QStringList SnapmaticPics = profileDir.entryList(QDir::Files | QDir::NoDot, QDir::NoSort);
BackupFiles.append(SnapmaticPics.filter(".bak", Qt::CaseInsensitive));
SavegameFiles.removeDuplicates();
SnapmaticPics.removeDuplicates();
foreach(const QString &BackupFile, BackupFiles)
{
SavegameFiles.removeAll(BackupFile);
SnapmaticPics.removeAll(BackupFile);
}
int maximumV = SavegameFiles.length() + SnapmaticPics.length();
// Loading pictures and savegames
emit loadingProgress(curFile, maximumV);
foreach(const QString &SavegameFile, SavegameFiles)
{
emit loadingProgress(curFile, maximumV);
QString sgdPath = profileFolder + QDir::separator() + SavegameFile;
SavegameData *savegame = new SavegameData(sgdPath);
if (savegame->readingSavegame())
{
emit savegameLoaded(savegame, sgdPath);
}
curFile++;
}
foreach(const QString &SnapmaticPic, SnapmaticPics)
{
emit loadingProgress(curFile, maximumV);
QString picturePath = profileFolder + QDir::separator() + SnapmaticPic;
SnapmaticPicture *picture = new SnapmaticPicture(picturePath);
if (picture->readingPicture(true, true, true))
{
emit pictureLoaded(picture);
int crewNumber = picture->getSnapmaticProperties().crewID;
if (!crewList.contains(crewNumber))
{
crewList.append(crewNumber);
}
}
curFile++;
}
// adding found crews
foreach(int crewID, crewList)
{
crewDB->addCrew(crewID);
}
}
void ProfileLoader::preloaded()
{
}
void ProfileLoader::loaded()
{
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "ProfileLoader.h"
#include "SnapmaticPicture.h"
#include "SavegameData.h"
#include "CrewDatabase.h"
#include <QStringBuilder>
#include <QStringList>
#include <QString>
#include <QFile>
#include <QDir>
ProfileLoader::ProfileLoader(QString profileFolder, CrewDatabase *crewDB, QObject *parent) : QThread(parent), profileFolder(profileFolder), crewDB(crewDB)
{
}
void ProfileLoader::run()
{
int curFile = 1;
QDir profileDir;
QList<int> crewList;
profileDir.setPath(profileFolder);
// Seek pictures and savegames
profileDir.setNameFilters(QStringList("SGTA*"));
QStringList SavegameFiles = profileDir.entryList(QDir::Files | QDir::NoDot, QDir::NoSort);
QStringList BackupFiles = SavegameFiles.filter(".bak", Qt::CaseInsensitive);
profileDir.setNameFilters(QStringList("PGTA*"));
QStringList SnapmaticPics = profileDir.entryList(QDir::Files | QDir::NoDot, QDir::NoSort);
BackupFiles += SnapmaticPics.filter(".bak", Qt::CaseInsensitive);
SavegameFiles.removeDuplicates();
SnapmaticPics.removeDuplicates();
foreach(const QString &BackupFile, BackupFiles)
{
SavegameFiles.removeAll(BackupFile);
SnapmaticPics.removeAll(BackupFile);
}
int maximumV = SavegameFiles.length() + SnapmaticPics.length();
// Loading pictures and savegames
emit loadingProgress(curFile, maximumV);
foreach(const QString &SavegameFile, SavegameFiles)
{
emit loadingProgress(curFile, maximumV);
QString sgdPath = profileFolder % QDir::separator() % SavegameFile;
SavegameData *savegame = new SavegameData(sgdPath);
if (savegame->readingSavegame())
{
emit savegameLoaded(savegame, sgdPath);
}
curFile++;
}
foreach(const QString &SnapmaticPic, SnapmaticPics)
{
emit loadingProgress(curFile, maximumV);
QString picturePath = profileFolder % QDir::separator() % SnapmaticPic;
SnapmaticPicture *picture = new SnapmaticPicture(picturePath);
if (picture->readingPicture(true, true, true))
{
emit pictureLoaded(picture);
int crewNumber = picture->getSnapmaticProperties().crewID;
if (!crewList.contains(crewNumber))
{
crewList += crewNumber;
}
}
curFile++;
}
// adding found crews
crewDB->setAddingCrews(true);
foreach(int crewID, crewList)
{
crewDB->addCrew(crewID);
}
crewDB->setAddingCrews(false);
}
void ProfileLoader::preloaded()
{
}
void ProfileLoader::loaded()
{
}

View file

@ -1,52 +1,52 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 PROFILELOADER_H
#define PROFILELOADER_H
#include "SnapmaticPicture.h"
#include "SavegameData.h"
#include "CrewDatabase.h"
#include <QThread>
#include <QDir>
class ProfileLoader : public QThread
{
Q_OBJECT
public:
explicit ProfileLoader(QString profileFolder, CrewDatabase *crewDB, QObject *parent = 0);
protected:
void run();
private:
QString profileFolder;
CrewDatabase *crewDB;
ProfileLoader *profileLoader;
private slots:
void preloaded();
void loaded();
signals:
void pictureLoaded(SnapmaticPicture *picture);
void savegameLoaded(SavegameData *savegame, QString savegamePath);
void loadingProgress(int value, int maximum);
};
#endif // PROFILELOADER_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 PROFILELOADER_H
#define PROFILELOADER_H
#include "SnapmaticPicture.h"
#include "SavegameData.h"
#include "CrewDatabase.h"
#include <QThread>
#include <QDir>
class ProfileLoader : public QThread
{
Q_OBJECT
public:
explicit ProfileLoader(QString profileFolder, CrewDatabase *crewDB, QObject *parent = 0);
protected:
void run();
private:
QString profileFolder;
CrewDatabase *crewDB;
ProfileLoader *profileLoader;
private slots:
void preloaded();
void loaded();
signals:
void pictureLoaded(SnapmaticPicture *picture);
void savegameLoaded(SavegameData *savegame, QString savegamePath);
void loadingProgress(int value, int maximum);
};
#endif // PROFILELOADER_H

View file

@ -1,61 +1,66 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "ProfileWidget.h"
#include <QDebug>
ProfileWidget::ProfileWidget(QWidget *parent) : QWidget(parent)
{
contentMode = 0;
}
ProfileWidget::~ProfileWidget()
{
}
bool ProfileWidget::isSelected()
{
qDebug() << "ProfileWidget::isSelected got used without overwrite";
return false;
}
void ProfileWidget::setSelected(bool isSelected)
{
qDebug() << "ProfileWidget::setSelected got used without overwrite, result" << isSelected;
}
void ProfileWidget::setSelectionMode(bool selectionMode)
{
qDebug() << "ProfileWidget::setSelectionMode got used without overwrite, result:" << selectionMode;
}
QString ProfileWidget::getWidgetType()
{
qDebug() << "ProfileWidget::getWidgetType got used without overwrite";
return "ProfileWidget";
}
int ProfileWidget::getContentMode()
{
return contentMode;
}
void ProfileWidget::setContentMode(int _contentMode)
{
contentMode = _contentMode;
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "ProfileWidget.h"
#include <QDebug>
ProfileWidget::ProfileWidget(QWidget *parent) : QWidget(parent)
{
contentMode = 0;
}
ProfileWidget::~ProfileWidget()
{
}
void ProfileWidget::retranslate()
{
qDebug() << "ProfileWidget::retranslate got used without overwrite";
}
bool ProfileWidget::isSelected()
{
qDebug() << "ProfileWidget::isSelected got used without overwrite";
return false;
}
void ProfileWidget::setSelected(bool isSelected)
{
qDebug() << "ProfileWidget::setSelected got used without overwrite, result" << isSelected;
}
void ProfileWidget::setSelectionMode(bool selectionMode)
{
qDebug() << "ProfileWidget::setSelectionMode got used without overwrite, result:" << selectionMode;
}
QString ProfileWidget::getWidgetType()
{
qDebug() << "ProfileWidget::getWidgetType got used without overwrite";
return "ProfileWidget";
}
int ProfileWidget::getContentMode()
{
return contentMode;
}
void ProfileWidget::setContentMode(int _contentMode)
{
contentMode = _contentMode;
}

View file

@ -1,45 +1,46 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 PROFILEWIDGET_H
#define PROFILEWIDGET_H
#include <QWidget>
class ProfileWidget : public QWidget
{
Q_OBJECT
public:
explicit ProfileWidget(QWidget *parent = 0);
virtual void setSelectionMode(bool selectionMode);
virtual void setContentMode(int contentMode);
virtual void setSelected(bool isSelected);
virtual bool isSelected();
virtual QString getWidgetType();
virtual int getContentMode();
~ProfileWidget();
private:
int contentMode;
signals:
public slots:
};
#endif // PROFILEWIDGET_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 PROFILEWIDGET_H
#define PROFILEWIDGET_H
#include <QWidget>
class ProfileWidget : public QWidget
{
Q_OBJECT
public:
explicit ProfileWidget(QWidget *parent = 0);
virtual void setSelectionMode(bool selectionMode);
virtual void setContentMode(int contentMode);
virtual void setSelected(bool isSelected);
virtual bool isSelected();
virtual QString getWidgetType();
virtual int getContentMode();
virtual void retranslate();
~ProfileWidget();
private:
int contentMode;
signals:
public slots:
};
#endif // PROFILEWIDGET_H

View file

@ -1,100 +1,100 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "SidebarGenerator.h"
#include "SavegameWidget.h"
#include "SavegameCopy.h"
#include "config.h"
#include <QMessageBox>
#include <QFileDialog>
#include <QSettings>
SavegameCopy::SavegameCopy()
{
}
void SavegameCopy::copySavegame(QWidget *parent, QString sgdPath)
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("FileDialogs");
fileDialogPreSave: //Work?
QFileInfo sgdFileInfo(sgdPath);
QFileDialog fileDialog(parent);
fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setViewMode(QFileDialog::Detail);
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
fileDialog.setOption(QFileDialog::DontUseNativeDialog, false);
fileDialog.setOption(QFileDialog::DontConfirmOverwrite, true);
fileDialog.setDefaultSuffix("");
fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
fileDialog.setWindowTitle(SavegameWidget::tr(("Export Savegame...")));
fileDialog.setLabelText(QFileDialog::Accept, SavegameWidget::tr("Export"));
QStringList filters;
filters << SavegameWidget::tr("Savegame files (SGTA*)");
filters << SavegameWidget::tr("All files (**)");
fileDialog.setNameFilters(filters);
QList<QUrl> sidebarUrls = SidebarGenerator::generateSidebarUrls(fileDialog.sidebarUrls());
fileDialog.setSidebarUrls(sidebarUrls);
fileDialog.restoreState(settings.value("CopySavegame","").toByteArray());
fileDialog.selectFile(sgdFileInfo.fileName());
if (fileDialog.exec())
{
QStringList selectedFiles = fileDialog.selectedFiles();
if (selectedFiles.length() == 1)
{
QString selectedFile = selectedFiles.at(0);
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 (!QFile::remove(selectedFile))
{
QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("Failed to overwrite %1 with current Savegame").arg("\""+selectedFile+"\""));
goto fileDialogPreSave; //Work?
}
}
else
{
goto fileDialogPreSave; //Work?
}
}
bool isCopied = QFile::copy(sgdPath, selectedFile);
if (!isCopied)
{
QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("Failed to export current Savegame"));
goto fileDialogPreSave; //Work?
}
}
else
{
QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("No valid file is selected"));
goto fileDialogPreSave; //Work?
}
}
settings.setValue("CopySavegame", fileDialog.saveState());
settings.endGroup();
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "SidebarGenerator.h"
#include "SavegameWidget.h"
#include "SavegameCopy.h"
#include "config.h"
#include <QMessageBox>
#include <QFileDialog>
#include <QSettings>
SavegameCopy::SavegameCopy()
{
}
void SavegameCopy::copySavegame(QWidget *parent, QString sgdPath)
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("FileDialogs");
fileDialogPreSave: //Work?
QFileInfo sgdFileInfo(sgdPath);
QFileDialog fileDialog(parent);
fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setViewMode(QFileDialog::Detail);
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
fileDialog.setOption(QFileDialog::DontUseNativeDialog, false);
fileDialog.setOption(QFileDialog::DontConfirmOverwrite, true);
fileDialog.setDefaultSuffix("");
fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
fileDialog.setWindowTitle(SavegameWidget::tr(("Export Savegame...")));
fileDialog.setLabelText(QFileDialog::Accept, SavegameWidget::tr("Export"));
QStringList filters;
filters << SavegameWidget::tr("Savegame files (SGTA*)");
filters << SavegameWidget::tr("All files (**)");
fileDialog.setNameFilters(filters);
QList<QUrl> sidebarUrls = SidebarGenerator::generateSidebarUrls(fileDialog.sidebarUrls());
fileDialog.setSidebarUrls(sidebarUrls);
fileDialog.restoreState(settings.value("CopySavegame","").toByteArray());
fileDialog.selectFile(sgdFileInfo.fileName());
if (fileDialog.exec())
{
QStringList selectedFiles = fileDialog.selectedFiles();
if (selectedFiles.length() == 1)
{
QString selectedFile = selectedFiles.at(0);
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 (!QFile::remove(selectedFile))
{
QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("Failed to overwrite %1 with current Savegame").arg("\""+selectedFile+"\""));
goto fileDialogPreSave; //Work?
}
}
else
{
goto fileDialogPreSave; //Work?
}
}
bool isCopied = QFile::copy(sgdPath, selectedFile);
if (!isCopied)
{
QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("Failed to export current Savegame"));
goto fileDialogPreSave; //Work?
}
}
else
{
QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("No valid file is selected"));
goto fileDialogPreSave; //Work?
}
}
settings.setValue("CopySavegame", fileDialog.saveState());
settings.endGroup();
}

View file

@ -1,32 +1,32 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 SAVEGAMECOPY_H
#define SAVEGAMECOPY_H
#include <QWidget>
#include <QString>
class SavegameCopy
{
public:
SavegameCopy();
static void copySavegame(QWidget *parent, QString sgdPath);
};
#endif // SAVEGAMECOPY_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 SAVEGAMECOPY_H
#define SAVEGAMECOPY_H
#include <QWidget>
#include <QString>
class SavegameCopy
{
public:
SavegameCopy();
static void copySavegame(QWidget *parent, QString sgdPath);
};
#endif // SAVEGAMECOPY_H

View file

@ -1,119 +1,120 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "StringParser.h"
#include "SavegameData.h"
#include <QTextCodec>
#include <QByteArray>
#include <QDebug>
#include <QFile>
#define savegameHeaderLength 260
#define verificationValue QByteArray::fromHex("00000001")
SavegameData::SavegameData(const QString &fileName, QObject *parent) : QObject(parent), savegameFileName(fileName)
{
// INIT SAVEGAME
savegameStr = "";
savegameOk = 0;
}
bool SavegameData::readingSavegame()
{
// Start opening file
// lastStep is like currentStep
QFile *saveFile = new QFile(savegameFileName);
if (!saveFile->open(QFile::ReadOnly))
{
lastStep = "1;/1,OpenFile," + StringParser::convertDrawStringForLog(savegameFileName);
saveFile->deleteLater();
delete saveFile;
return false;
}
// Reading Savegame Header
if (!saveFile->isReadable())
{
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(savegameFileName) + ",1,NOHEADER";
saveFile->close();
saveFile->deleteLater();
delete saveFile;
return false;
}
QByteArray savegameHeaderLine = saveFile->read(savegameHeaderLength);
if (savegameHeaderLine.left(4) == verificationValue)
{
savegameStr = getSavegameDataString(savegameHeaderLine);
if (savegameStr.length() >= 1)
{
savegameOk = true;
}
}
saveFile->close();
saveFile->deleteLater();
delete saveFile;
return savegameOk;
}
QString SavegameData::getSavegameDataString(const QByteArray &savegameHeader)
{
QByteArray savegameBytes = savegameHeader.left(savegameHeaderLength);
QList<QByteArray> savegameBytesList = savegameBytes.split(char(0x01));
savegameBytes = savegameBytesList.at(1);
savegameBytesList.clear();
return StringParser::parseTitleString(savegameBytes, savegameBytes.length());
}
bool SavegameData::readingSavegameFromFile(const QString &fileName)
{
if (fileName != "")
{
savegameFileName = fileName;
return readingSavegame();
}
else
{
return false;
}
}
bool SavegameData::isSavegameOk()
{
return savegameOk;
}
QString SavegameData::getSavegameFileName()
{
return savegameFileName;
}
QString SavegameData::getSavegameStr()
{
return savegameStr;
}
QString SavegameData::getLastStep()
{
return lastStep;
}
void SavegameData::setSavegameFileName(QString savegameFileName_)
{
savegameFileName = savegameFileName_;
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "StringParser.h"
#include "SavegameData.h"
#include <QStringBuilder>
#include <QTextCodec>
#include <QByteArray>
#include <QDebug>
#include <QFile>
#define savegameHeaderLength 260
#define verificationValue QByteArray::fromHex("00000001")
SavegameData::SavegameData(const QString &fileName, QObject *parent) : QObject(parent), savegameFileName(fileName)
{
// INIT SAVEGAME
savegameStr = "";
savegameOk = 0;
}
bool SavegameData::readingSavegame()
{
// Start opening file
// lastStep is like currentStep
QFile *saveFile = new QFile(savegameFileName);
if (!saveFile->open(QFile::ReadOnly))
{
lastStep = "1;/1,OpenFile," % StringParser::convertDrawStringForLog(savegameFileName);
saveFile->deleteLater();
delete saveFile;
return false;
}
// Reading Savegame Header
if (!saveFile->isReadable())
{
lastStep = "2;/3,ReadingFile," % StringParser::convertDrawStringForLog(savegameFileName) % ",1,NOHEADER";
saveFile->close();
saveFile->deleteLater();
delete saveFile;
return false;
}
QByteArray savegameHeaderLine = saveFile->read(savegameHeaderLength);
if (savegameHeaderLine.left(4) == verificationValue)
{
savegameStr = getSavegameDataString(savegameHeaderLine);
if (savegameStr.length() >= 1)
{
savegameOk = true;
}
}
saveFile->close();
saveFile->deleteLater();
delete saveFile;
return savegameOk;
}
QString SavegameData::getSavegameDataString(const QByteArray &savegameHeader)
{
QByteArray savegameBytes = savegameHeader.left(savegameHeaderLength);
QList<QByteArray> savegameBytesList = savegameBytes.split(char(0x01));
savegameBytes = savegameBytesList.at(1);
savegameBytesList.clear();
return StringParser::parseTitleString(savegameBytes, savegameBytes.length());
}
bool SavegameData::readingSavegameFromFile(const QString &fileName)
{
if (fileName != "")
{
savegameFileName = fileName;
return readingSavegame();
}
else
{
return false;
}
}
bool SavegameData::isSavegameOk()
{
return savegameOk;
}
QString SavegameData::getSavegameFileName()
{
return savegameFileName;
}
QString SavegameData::getSavegameStr()
{
return savegameStr;
}
QString SavegameData::getLastStep()
{
return lastStep;
}
void SavegameData::setSavegameFileName(QString savegameFileName_)
{
savegameFileName = savegameFileName_;
}

View file

@ -1,45 +1,45 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 SAVEGAMEDATA_H
#define SAVEGAMEDATA_H
#include <QObject>
class SavegameData : public QObject
{
Q_OBJECT
public:
explicit SavegameData(const QString &fileName = "", QObject *parent = 0);
bool readingSavegameFromFile(const QString &fileName);
bool readingSavegame();
bool isSavegameOk();
QString getLastStep();
QString getSavegameStr();
QString getSavegameFileName();
void setSavegameFileName(QString savegameFileName);
private:
QString getSavegameDataString(const QByteArray &savegameHeader);
QString savegameFileName;
QString savegameStr;
QString lastStep;
bool savegameOk;
};
#endif // SAVEGAMEDATA_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 SAVEGAMEDATA_H
#define SAVEGAMEDATA_H
#include <QObject>
class SavegameData : public QObject
{
Q_OBJECT
public:
explicit SavegameData(const QString &fileName = "", QObject *parent = 0);
bool readingSavegameFromFile(const QString &fileName);
bool readingSavegame();
bool isSavegameOk();
QString getLastStep();
QString getSavegameStr();
QString getSavegameFileName();
void setSavegameFileName(QString savegameFileName);
private:
QString getSavegameDataString(const QByteArray &savegameHeader);
QString savegameFileName;
QString savegameStr;
QString lastStep;
bool savegameOk;
};
#endif // SAVEGAMEDATA_H

View file

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

View file

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

View file

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

View file

@ -1,261 +1,264 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "SavegameWidget.h"
#include "ui_SavegameWidget.h"
#include "SidebarGenerator.h"
#include "SavegameDialog.h"
#include "StandardPaths.h"
#include "SavegameData.h"
#include "SavegameCopy.h"
#include "AppEnv.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
#include <QFileInfo>
#include <QPalette>
#include <QColor>
#include <QBrush>
#include <QTimer>
#include <QDebug>
#include <QFile>
#include <QMenu>
#include <QUrl>
SavegameWidget::SavegameWidget(QWidget *parent) :
ProfileWidget(parent),
ui(new Ui::SavegameWidget)
{
ui->setupUi(this);
ui->cmdCopy->setVisible(false);
ui->cmdView->setVisible(false);
ui->cmdDelete->setVisible(false);
ui->cbSelected->setVisible(false);
qreal screenRatio = AppEnv::screenRatio();
ui->labSavegamePic->setFixedSize(48 * screenRatio, 27 * screenRatio);
QPixmap savegamePixmap(":/img/savegame.png");
if (screenRatio != 1) savegamePixmap = savegamePixmap.scaledToHeight(ui->labSavegamePic->height(), Qt::SmoothTransformation);
ui->labSavegamePic->setPixmap(savegamePixmap);
QString exportSavegameStr = tr("Export Savegame...");
Q_UNUSED(exportSavegameStr)
QPalette palette;
highlightBackColor = palette.highlight().color();
highlightTextColor = palette.highlightedText().color();
labelAutosaveStr = tr("AUTOSAVE - %1\n%2");
labelSaveStr = tr("SAVE %3 - %1\n%2");
snwgt = parent;
sgdPath = "";
sgdStr = "";
sgdata = 0;
installEventFilter(this);
}
SavegameWidget::~SavegameWidget()
{
delete ui;
}
bool SavegameWidget::eventFilter(QObject *obj, QEvent *ev)
{
if (obj == this)
{
if (ev->type() == QEvent::Enter)
{
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;
}
else if(ev->type() == QEvent::Leave)
{
setStyleSheet("");
return true;
}
}
return false;
}
void SavegameWidget::setSavegameData(SavegameData *savegame, QString savegamePath)
{
// BETA CODE
bool validNumber;
QString savegameName = tr("WRONG FORMAT");
QString savegameDate = tr("WRONG FORMAT");
QString savegameString = savegame->getSavegameStr();
QString fileName = QFileInfo(savegame->getSavegameFileName()).fileName();
QStringList savegameNDL = QString(savegameString).split(" - ");
if (savegameNDL.length() >= 2)
{
savegameDate = savegameNDL.at(savegameNDL.length() - 1);
savegameName = QString(savegameString).remove(savegameString.length() - savegameDate.length() - 3, savegameDate.length() + 3);
}
int savegameNumber = QString(fileName).remove(0,5).toInt(&validNumber) + 1;
if (validNumber)
{
if (savegameNumber == 16)
{
ui->labSavegameStr->setText(labelAutosaveStr.arg(savegameDate, savegameName));
}
else
{
ui->labSavegameStr->setText(labelSaveStr.arg(savegameDate, savegameName, QString::number(savegameNumber)));
}
}
else
{
ui->labSavegameStr->setText(labelSaveStr.arg(savegameDate, savegameName, tr("UNKNOWN")));
}
sgdStr = savegameString;
sgdPath = savegamePath;
sgdata = savegame;
}
void SavegameWidget::on_cmdCopy_clicked()
{
SavegameCopy::copySavegame(this, sgdPath);
}
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);
if (uchoice == QMessageBox::Yes)
{
if (!QFile::exists(sgdPath))
{
emit savegameDeleted();
}
else if(QFile::remove(sgdPath))
{
emit savegameDeleted();
}
else
{
QMessageBox::warning(this, tr("Delete savegame"), tr("Failed at deleting %1 from your savegames").arg("\""+sgdStr+"\""));
}
}
}
void SavegameWidget::on_cmdView_clicked()
{
SavegameDialog *savegameDialog = new SavegameDialog(this);
savegameDialog->setSavegameData(sgdata, sgdPath, true);
savegameDialog->setModal(true);
#ifdef Q_OS_ANDROID
// Android ...
savegameDialog->showMaximized();
#else
savegameDialog->show();
#endif
savegameDialog->exec();
delete savegameDialog;
}
void SavegameWidget::mousePressEvent(QMouseEvent *ev)
{
ProfileWidget::mousePressEvent(ev);
}
void SavegameWidget::mouseReleaseEvent(QMouseEvent *ev)
{
ProfileWidget::mouseReleaseEvent(ev);
if (ui->cbSelected->isVisible())
{
if (rect().contains(ev->pos()) && ev->button() == Qt::LeftButton)
{
ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
}
}
else
{
if (getContentMode() == 0 && rect().contains(ev->pos()) && ev->button() == Qt::LeftButton)
{
on_cmdView_clicked();
}
}
}
void SavegameWidget::mouseDoubleClickEvent(QMouseEvent *ev)
{
ProfileWidget::mouseDoubleClickEvent(ev);
if (!ui->cbSelected->isVisible() && getContentMode() == 1 && ev->button() == Qt::LeftButton)
{
on_cmdView_clicked();
}
}
void SavegameWidget::setSelected(bool isSelected)
{
ui->cbSelected->setChecked(isSelected);
}
void SavegameWidget::savegameSelected()
{
setSelected(!ui->cbSelected->isChecked());
}
void SavegameWidget::contextMenuEvent(QContextMenuEvent *ev)
{
emit contextMenuTriggered(ev);
}
void SavegameWidget::on_cbSelected_stateChanged(int arg1)
{
if (arg1 == Qt::Checked)
{
emit widgetSelected();
}
else if (arg1 == Qt::Unchecked)
{
emit widgetDeselected();
}
}
bool SavegameWidget::isSelected()
{
return ui->cbSelected->isChecked();
}
void SavegameWidget::setSelectionMode(bool selectionMode)
{
ui->cbSelected->setVisible(selectionMode);
}
void SavegameWidget::selectAllWidgets()
{
emit allWidgetsSelected();
}
void SavegameWidget::deselectAllWidgets()
{
emit allWidgetsDeselected();
}
SavegameData* SavegameWidget::getSavegame()
{
return sgdata;
}
QString SavegameWidget::getWidgetType()
{
return "SavegameWidget";
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "SavegameWidget.h"
#include "ui_SavegameWidget.h"
#include "SidebarGenerator.h"
#include "SavegameDialog.h"
#include "StandardPaths.h"
#include "SavegameData.h"
#include "SavegameCopy.h"
#include "AppEnv.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
#include <QFileInfo>
#include <QPalette>
#include <QColor>
#include <QBrush>
#include <QTimer>
#include <QDebug>
#include <QFile>
#include <QMenu>
#include <QUrl>
SavegameWidget::SavegameWidget(QWidget *parent) :
ProfileWidget(parent),
ui(new Ui::SavegameWidget)
{
ui->setupUi(this);
ui->cmdCopy->setVisible(false);
ui->cmdView->setVisible(false);
ui->cmdDelete->setVisible(false);
ui->cbSelected->setVisible(false);
qreal screenRatio = AppEnv::screenRatio();
ui->labSavegamePic->setFixedSize(48 * screenRatio, 27 * screenRatio);
QPixmap savegamePixmap(":/img/savegame.png");
if (screenRatio != 1) savegamePixmap = savegamePixmap.scaledToHeight(ui->labSavegamePic->height(), Qt::SmoothTransformation);
ui->labSavegamePic->setPixmap(savegamePixmap);
QString exportSavegameStr = tr("Export Savegame...");
Q_UNUSED(exportSavegameStr)
labelAutosaveStr = tr("AUTOSAVE - %1\n%2");
labelSaveStr = tr("SAVE %3 - %1\n%2");
ui->SavegameFrame->setMouseTracking(true);
ui->labSavegamePic->setMouseTracking(true);
ui->labSavegameStr->setMouseTracking(true);
ui->cbSelected->setMouseTracking(true);
sgdata = nullptr;
}
SavegameWidget::~SavegameWidget()
{
delete ui;
}
void SavegameWidget::setSavegameData(SavegameData *savegame, QString savegamePath)
{
// BETA CODE
QString savegameString = savegame->getSavegameStr();
QString fileName = QFileInfo(savegame->getSavegameFileName()).fileName();
renderString(savegameString, fileName);
sgdStr = savegameString;
sgdPath = savegamePath;
sgdata = savegame;
}
void SavegameWidget::renderString(const QString &savegameString, const QString &fileName)
{
bool validNumber;
QString savegameName = tr("WRONG FORMAT");
QString savegameDate = tr("WRONG FORMAT");
QStringList savegameNDL = QString(savegameString).split(" - ");
if (savegameNDL.length() >= 2)
{
savegameDate = savegameNDL.at(savegameNDL.length() - 1);
savegameName = QString(savegameString).remove(savegameString.length() - savegameDate.length() - 3, savegameDate.length() + 3);
}
int savegameNumber = QString(fileName).remove(0,5).toInt(&validNumber) + 1;
if (validNumber)
{
if (savegameNumber == 16)
{
ui->labSavegameStr->setText(labelAutosaveStr.arg(savegameDate, savegameName));
}
else
{
ui->labSavegameStr->setText(labelSaveStr.arg(savegameDate, savegameName, QString::number(savegameNumber)));
}
}
else
{
ui->labSavegameStr->setText(labelSaveStr.arg(savegameDate, savegameName, tr("UNKNOWN")));
}
}
void SavegameWidget::retranslate()
{
labelAutosaveStr = tr("AUTOSAVE - %1\n%2");
labelSaveStr = tr("SAVE %3 - %1\n%2");
QString fileName = QFileInfo(sgdata->getSavegameFileName()).fileName();
renderString(sgdStr, fileName);
}
void SavegameWidget::on_cmdCopy_clicked()
{
SavegameCopy::copySavegame(this, sgdPath);
}
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);
if (uchoice == QMessageBox::Yes)
{
if (!QFile::exists(sgdPath))
{
emit savegameDeleted();
}
else if(QFile::remove(sgdPath))
{
emit savegameDeleted();
}
else
{
QMessageBox::warning(this, tr("Delete savegame"), tr("Failed at deleting %1 from your savegames").arg("\""+sgdStr+"\""));
}
}
}
void SavegameWidget::on_cmdView_clicked()
{
SavegameDialog *savegameDialog = new SavegameDialog(this);
savegameDialog->setSavegameData(sgdata, sgdPath, true);
savegameDialog->setModal(true);
#ifdef Q_OS_ANDROID
// Android ...
savegameDialog->showMaximized();
#else
savegameDialog->show();
#endif
savegameDialog->exec();
delete savegameDialog;
}
void SavegameWidget::mousePressEvent(QMouseEvent *ev)
{
ProfileWidget::mousePressEvent(ev);
}
void SavegameWidget::mouseReleaseEvent(QMouseEvent *ev)
{
ProfileWidget::mouseReleaseEvent(ev);
if (ui->cbSelected->isVisible())
{
if (rect().contains(ev->pos()) && ev->button() == Qt::LeftButton)
{
ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
}
}
else
{
if (getContentMode() == 0 && rect().contains(ev->pos()) && ev->button() == Qt::LeftButton)
{
if (ev->modifiers().testFlag(Qt::ShiftModifier))
{
ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
}
else
{
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);
if (!ui->cbSelected->isVisible() && getContentMode() == 1 && ev->button() == Qt::LeftButton)
{
on_cmdView_clicked();
}
}
void SavegameWidget::setSelected(bool isSelected)
{
ui->cbSelected->setChecked(isSelected);
}
void SavegameWidget::savegameSelected()
{
setSelected(!ui->cbSelected->isChecked());
}
void SavegameWidget::contextMenuEvent(QContextMenuEvent *ev)
{
emit contextMenuTriggered(ev);
}
void SavegameWidget::on_cbSelected_stateChanged(int arg1)
{
if (arg1 == Qt::Checked)
{
emit widgetSelected();
}
else if (arg1 == Qt::Unchecked)
{
emit widgetDeselected();
}
}
bool SavegameWidget::isSelected()
{
return ui->cbSelected->isChecked();
}
void SavegameWidget::setSelectionMode(bool selectionMode)
{
ui->cbSelected->setVisible(selectionMode);
}
void SavegameWidget::selectAllWidgets()
{
emit allWidgetsSelected();
}
void SavegameWidget::deselectAllWidgets()
{
emit allWidgetsDeselected();
}
SavegameData* SavegameWidget::getSavegame()
{
return sgdata;
}
QString SavegameWidget::getWidgetType()
{
return "SavegameWidget";
}

View file

@ -1,82 +1,80 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 SAVEGAMEWIDGET_H
#define SAVEGAMEWIDGET_H
#include "ProfileWidget.h"
#include "SavegameData.h"
#include <QContextMenuEvent>
#include <QMouseEvent>
#include <QWidget>
#include <QColor>
namespace Ui {
class SavegameWidget;
}
class SavegameWidget : public ProfileWidget
{
Q_OBJECT
public:
SavegameWidget(QWidget *parent = 0);
void setSavegameData(SavegameData *savegame, QString savegamePath);
void setSelectionMode(bool selectionMode);
void setSelected(bool isSelected);
SavegameData* getSavegame();
QString getWidgetType();
bool isSelected();
~SavegameWidget();
private slots:
void on_cmdView_clicked();
void on_cmdCopy_clicked();
void on_cmdDelete_clicked();
void on_cbSelected_stateChanged(int arg1);
void savegameSelected();
void selectAllWidgets();
void deselectAllWidgets();
protected:
bool eventFilter(QObject *obj, QEvent *ev);
void mouseDoubleClickEvent(QMouseEvent *ev);
void mouseReleaseEvent(QMouseEvent *ev);
void mousePressEvent(QMouseEvent *ev);
void contextMenuEvent(QContextMenuEvent *ev);
private:
Ui::SavegameWidget *ui;
SavegameData *sgdata;
QColor highlightBackColor;
QColor highlightTextColor;
QString labelAutosaveStr;
QString labelSaveStr;
QString sgdPath;
QString sgdStr;
QWidget *snwgt;
signals:
void savegameDeleted();
void widgetSelected();
void widgetDeselected();
void allWidgetsSelected();
void allWidgetsDeselected();
void contextMenuTriggered(QContextMenuEvent *ev);
};
#endif // SAVEGAMEWIDGET_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 SAVEGAMEWIDGET_H
#define SAVEGAMEWIDGET_H
#include "ProfileWidget.h"
#include "SavegameData.h"
#include <QContextMenuEvent>
#include <QMouseEvent>
#include <QWidget>
#include <QColor>
namespace Ui {
class SavegameWidget;
}
class SavegameWidget : public ProfileWidget
{
Q_OBJECT
public:
SavegameWidget(QWidget *parent = 0);
void setSavegameData(SavegameData *savegame, QString savegamePath);
void setSelectionMode(bool selectionMode);
void setSelected(bool isSelected);
SavegameData* getSavegame();
QString getWidgetType();
bool isSelected();
void retranslate();
~SavegameWidget();
private slots:
void on_cmdView_clicked();
void on_cmdCopy_clicked();
void on_cmdDelete_clicked();
void on_cbSelected_stateChanged(int arg1);
void savegameSelected();
void selectAllWidgets();
void deselectAllWidgets();
protected:
void mouseDoubleClickEvent(QMouseEvent *ev);
void mouseReleaseEvent(QMouseEvent *ev);
void mousePressEvent(QMouseEvent *ev);
void contextMenuEvent(QContextMenuEvent *ev);
private:
Ui::SavegameWidget *ui;
SavegameData *sgdata;
QString labelAutosaveStr;
QString labelSaveStr;
QString sgdPath;
QString sgdStr;
void renderString(const QString &savegameString, const QString &fileName);
signals:
void savegameDeleted();
void widgetSelected();
void widgetDeselected();
void allWidgetsSelected();
void allWidgetsDeselected();
void contextMenuTriggered(QContextMenuEvent *ev);
};
#endif // SAVEGAMEWIDGET_H

View file

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

View file

@ -1,61 +1,61 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "SidebarGenerator.h"
#include "StandardPaths.h"
#include "AppEnv.h"
#include <QList>
#include <QUrl>
#include <QDir>
SidebarGenerator::SidebarGenerator()
{
}
QList<QUrl> SidebarGenerator::generateSidebarUrls(QList<QUrl> sidebarUrls)
{
QDir dir;
dir.setPath(StandardPaths::picturesLocation());
if (dir.exists())
{
sidebarUrls << QUrl::fromLocalFile(dir.absolutePath());
}
dir.setPath(StandardPaths::documentsLocation());
if (dir.exists())
{
sidebarUrls << QUrl::fromLocalFile(dir.absolutePath());
}
bool gameFolderExists;
QString gameFolder = AppEnv::getGameFolder(&gameFolderExists);
if (gameFolderExists)
{
sidebarUrls << QUrl::fromLocalFile(gameFolder);
}
dir.setPath(StandardPaths::desktopLocation());
if (dir.exists())
{
sidebarUrls << QUrl::fromLocalFile(dir.absolutePath());
}
return sidebarUrls;
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "SidebarGenerator.h"
#include "StandardPaths.h"
#include "AppEnv.h"
#include <QList>
#include <QUrl>
#include <QDir>
SidebarGenerator::SidebarGenerator()
{
}
QList<QUrl> SidebarGenerator::generateSidebarUrls(QList<QUrl> sidebarUrls)
{
QDir dir;
dir.setPath(StandardPaths::picturesLocation());
if (dir.exists())
{
sidebarUrls += QUrl::fromLocalFile(dir.absolutePath());
}
dir.setPath(StandardPaths::documentsLocation());
if (dir.exists())
{
sidebarUrls += QUrl::fromLocalFile(dir.absolutePath());
}
bool gameFolderExists;
QString gameFolder = AppEnv::getGameFolder(&gameFolderExists);
if (gameFolderExists)
{
sidebarUrls += QUrl::fromLocalFile(gameFolder);
}
dir.setPath(StandardPaths::desktopLocation());
if (dir.exists())
{
sidebarUrls += QUrl::fromLocalFile(dir.absolutePath());
}
return sidebarUrls;
}

View file

@ -1,32 +1,32 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 SIDEBARGENERATOR_H
#define SIDEBARGENERATOR_H
#include <QList>
#include <QUrl>
class SidebarGenerator
{
public:
SidebarGenerator();
static QList<QUrl> generateSidebarUrls(QList<QUrl> sidebarUrls);
};
#endif // SIDEBARGENERATOR_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 SIDEBARGENERATOR_H
#define SIDEBARGENERATOR_H
#include <QList>
#include <QUrl>
class SidebarGenerator
{
public:
SidebarGenerator();
static QList<QUrl> generateSidebarUrls(QList<QUrl> sidebarUrls);
};
#endif // SIDEBARGENERATOR_H

View file

@ -1,340 +1,340 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "SnapmaticEditor.h"
#include "ui_SnapmaticEditor.h"
#include "SnapmaticPicture.h"
#include "StringParser.h"
#include "AppEnv.h"
#include <QStringBuilder>
#include <QTextDocument>
#include <QInputDialog>
#include <QMessageBox>
#include <QDebug>
#include <QFile>
SnapmaticEditor::SnapmaticEditor(CrewDatabase *crewDB, QWidget *parent) :
QDialog(parent), crewDB(crewDB),
ui(new Ui::SnapmaticEditor)
{
ui->setupUi(this);
ui->cmdApply->setDefault(true);
if (QIcon::hasThemeIcon("dialog-apply"))
{
ui->cmdApply->setIcon(QIcon::fromTheme("dialog-apply"));
}
if (QIcon::hasThemeIcon("dialog-cancel"))
{
ui->cmdCancel->setIcon(QIcon::fromTheme("dialog-cancel"));
}
snapmaticTitle = "";
smpic = 0;
// DPI calculation
qreal screenRatio = AppEnv::screenRatio();
resize(400 * screenRatio, 360 * screenRatio);
}
SnapmaticEditor::~SnapmaticEditor()
{
delete ui;
}
void SnapmaticEditor::selfie_toggled(bool checked)
{
if (checked)
{
isSelfie = true;
}
else
{
isSelfie = false;
}
}
void SnapmaticEditor::mugshot_toggled(bool checked)
{
if (checked)
{
isMugshot = true;
ui->cbDirector->setEnabled(false);
ui->cbDirector->setChecked(false);
}
else
{
isMugshot = false;
ui->cbDirector->setEnabled(true);
}
}
void SnapmaticEditor::editor_toggled(bool checked)
{
if (checked)
{
isEditor = true;
ui->cbDirector->setEnabled(false);
ui->cbDirector->setChecked(false);
}
else
{
isEditor = false;
ui->cbDirector->setEnabled(true);
}
}
void SnapmaticEditor::on_rbSelfie_toggled(bool checked)
{
if (checked)
{
mugshot_toggled(false);
editor_toggled(false);
selfie_toggled(true);
}
}
void SnapmaticEditor::on_rbMugshot_toggled(bool checked)
{
if (checked)
{
selfie_toggled(false);
editor_toggled(false);
mugshot_toggled(true);
}
}
void SnapmaticEditor::on_rbEditor_toggled(bool checked)
{
if (checked)
{
selfie_toggled(false);
mugshot_toggled(false);
editor_toggled(true);
}
}
void SnapmaticEditor::on_rbCustom_toggled(bool checked)
{
if (checked)
{
selfie_toggled(false);
mugshot_toggled(false);
editor_toggled(false);
}
}
void SnapmaticEditor::setSnapmaticPicture(SnapmaticPicture *picture)
{
smpic = picture;
localSpJson = smpic->getSnapmaticProperties();
ui->rbCustom->setChecked(true);
crewID = localSpJson.crewID;
isSelfie = localSpJson.isSelfie;
isMugshot = localSpJson.isMug;
isEditor = localSpJson.isFromRSEditor;
ui->cbDirector->setChecked(localSpJson.isFromDirector);
ui->cbMeme->setChecked(localSpJson.isMeme);
if (isSelfie)
{
ui->rbSelfie->setChecked(true);
}
else if (isMugshot)
{
ui->rbMugshot->setChecked(true);
}
else if (isEditor)
{
ui->rbEditor->setChecked(true);
}
else
{
ui->rbCustom->setChecked(true);
}
setSnapmaticCrew(returnCrewName(crewID));
setSnapmaticTitle(picture->getPictureTitle());
}
void SnapmaticEditor::setSnapmaticTitle(const QString &title)
{
if (title.length() > 39)
{
snapmaticTitle = title.left(39);
}
else
{
snapmaticTitle = title;
}
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);
ui->labTitle->setText(titleStr);
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"))));
}
else
{
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)
{
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);
ui->labCrew->setText(crewStr);
}
QString SnapmaticEditor::returnCrewName(int crewID_)
{
return crewDB->getCrewName(crewID_);
}
void SnapmaticEditor::on_cmdCancel_clicked()
{
close();
}
void SnapmaticEditor::on_cmdApply_clicked()
{
if (ui->cbQualify->isChecked())
{
qualifyAvatar();
}
localSpJson.crewID = crewID;
localSpJson.isSelfie = isSelfie;
localSpJson.isMug = isMugshot;
localSpJson.isFromRSEditor = isEditor;
localSpJson.isFromDirector = ui->cbDirector->isChecked();
localSpJson.isMeme = ui->cbMeme->isChecked();
if (smpic)
{
QString originalFileName = smpic->getPictureFilePath();
QString adjustedFileName = originalFileName;
if (adjustedFileName.right(7) == ".hidden") // for the hidden file system
{
adjustedFileName.remove(adjustedFileName.length() - 7, 7);
}
QString backupFileName = adjustedFileName % ".bak";
if (!QFile::exists(backupFileName))
{
QFile::copy(adjustedFileName, backupFileName);
}
SnapmaticProperties fallbackProperties = smpic->getSnapmaticProperties();
QString fallbackTitle = smpic->getPictureTitle();
smpic->setSnapmaticProperties(localSpJson);
smpic->setPictureTitle(snapmaticTitle);
if (!smpic->exportPicture(originalFileName))
{
QMessageBox::warning(this, tr("Snapmatic Properties"), tr("Patching of Snapmatic Properties failed because of I/O Error"));
smpic->setSnapmaticProperties(fallbackProperties);
smpic->setPictureTitle(fallbackTitle);
}
else
{
smpic->emitUpdate();
}
}
close();
}
void SnapmaticEditor::qualifyAvatar()
{
ui->rbSelfie->setChecked(true);
ui->cbDirector->setChecked(false);
ui->cbMeme->setChecked(false);
ui->cmdApply->setDefault(true);
}
void SnapmaticEditor::on_cbQualify_toggled(bool checked)
{
if (checked)
{
ui->cbMeme->setEnabled(false);
ui->cbDirector->setEnabled(false);
ui->rbCustom->setEnabled(false);
ui->rbSelfie->setEnabled(false);
ui->rbEditor->setEnabled(false);
ui->rbMugshot->setEnabled(false);
}
else
{
ui->cbMeme->setEnabled(true);
ui->rbCustom->setEnabled(true);
ui->rbSelfie->setEnabled(true);
ui->rbEditor->setEnabled(true);
ui->rbMugshot->setEnabled(true);
if (ui->rbSelfie->isChecked() || ui->rbCustom->isChecked())
{
ui->cbDirector->setEnabled(true);
}
}
}
void SnapmaticEditor::on_labTitle_linkActivated(const QString &link)
{
if (link == "g5e://edittitle")
{
bool ok;
QString newTitle = QInputDialog::getText(this, tr("Snapmatic Title"), tr("New Snapmatic title:"), QLineEdit::Normal, snapmaticTitle, &ok, windowFlags());
if (ok && !newTitle.isEmpty())
{
setSnapmaticTitle(newTitle);
}
}
}
void SnapmaticEditor::on_labCrew_linkActivated(const QString &link)
{
if (link == "g5e://editcrew")
{
bool ok;
int indexNum = 0;
QStringList itemList;
QStringList crewList = crewDB->getCrews();
if (!crewList.contains(QLatin1String("0")))
{
crewList.append(QLatin1String("0"));
}
crewList.sort();
foreach(const QString &crew, crewList)
{
itemList.append(QString("%1 (%2)").arg(crew, returnCrewName(crew.toInt())));
}
if (crewList.contains(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());
if (ok && !newCrew.isEmpty())
{
if (newCrew.contains(" ")) newCrew = newCrew.split(" ").at(0);
if (newCrew.length() > 10) return;
foreach (const QChar &crewChar, newCrew)
{
if (!crewChar.isNumber())
{
return;
}
}
crewID = newCrew.toInt();
setSnapmaticCrew(returnCrewName(crewID));
}
}
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "SnapmaticEditor.h"
#include "ui_SnapmaticEditor.h"
#include "SnapmaticPicture.h"
#include "StringParser.h"
#include "AppEnv.h"
#include <QStringBuilder>
#include <QTextDocument>
#include <QInputDialog>
#include <QMessageBox>
#include <QDebug>
#include <QFile>
SnapmaticEditor::SnapmaticEditor(CrewDatabase *crewDB, QWidget *parent) :
QDialog(parent), crewDB(crewDB),
ui(new Ui::SnapmaticEditor)
{
ui->setupUi(this);
ui->cmdApply->setDefault(true);
if (QIcon::hasThemeIcon("dialog-apply"))
{
ui->cmdApply->setIcon(QIcon::fromTheme("dialog-apply"));
}
if (QIcon::hasThemeIcon("dialog-cancel"))
{
ui->cmdCancel->setIcon(QIcon::fromTheme("dialog-cancel"));
}
snapmaticTitle = "";
smpic = 0;
// DPI calculation
qreal screenRatio = AppEnv::screenRatio();
resize(400 * screenRatio, 360 * screenRatio);
}
SnapmaticEditor::~SnapmaticEditor()
{
delete ui;
}
void SnapmaticEditor::selfie_toggled(bool checked)
{
if (checked)
{
isSelfie = true;
}
else
{
isSelfie = false;
}
}
void SnapmaticEditor::mugshot_toggled(bool checked)
{
if (checked)
{
isMugshot = true;
ui->cbDirector->setEnabled(false);
ui->cbDirector->setChecked(false);
}
else
{
isMugshot = false;
ui->cbDirector->setEnabled(true);
}
}
void SnapmaticEditor::editor_toggled(bool checked)
{
if (checked)
{
isEditor = true;
ui->cbDirector->setEnabled(false);
ui->cbDirector->setChecked(false);
}
else
{
isEditor = false;
ui->cbDirector->setEnabled(true);
}
}
void SnapmaticEditor::on_rbSelfie_toggled(bool checked)
{
if (checked)
{
mugshot_toggled(false);
editor_toggled(false);
selfie_toggled(true);
}
}
void SnapmaticEditor::on_rbMugshot_toggled(bool checked)
{
if (checked)
{
selfie_toggled(false);
editor_toggled(false);
mugshot_toggled(true);
}
}
void SnapmaticEditor::on_rbEditor_toggled(bool checked)
{
if (checked)
{
selfie_toggled(false);
mugshot_toggled(false);
editor_toggled(true);
}
}
void SnapmaticEditor::on_rbCustom_toggled(bool checked)
{
if (checked)
{
selfie_toggled(false);
mugshot_toggled(false);
editor_toggled(false);
}
}
void SnapmaticEditor::setSnapmaticPicture(SnapmaticPicture *picture)
{
smpic = picture;
localSpJson = smpic->getSnapmaticProperties();
ui->rbCustom->setChecked(true);
crewID = localSpJson.crewID;
isSelfie = localSpJson.isSelfie;
isMugshot = localSpJson.isMug;
isEditor = localSpJson.isFromRSEditor;
ui->cbDirector->setChecked(localSpJson.isFromDirector);
ui->cbMeme->setChecked(localSpJson.isMeme);
if (isSelfie)
{
ui->rbSelfie->setChecked(true);
}
else if (isMugshot)
{
ui->rbMugshot->setChecked(true);
}
else if (isEditor)
{
ui->rbEditor->setChecked(true);
}
else
{
ui->rbCustom->setChecked(true);
}
setSnapmaticCrew(returnCrewName(crewID));
setSnapmaticTitle(picture->getPictureTitle());
}
void SnapmaticEditor::setSnapmaticTitle(const QString &title)
{
if (title.length() > 39)
{
snapmaticTitle = title.left(39);
}
else
{
snapmaticTitle = title;
}
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);
ui->labTitle->setText(titleStr);
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"))));
}
else
{
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)
{
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);
ui->labCrew->setText(crewStr);
}
QString SnapmaticEditor::returnCrewName(int crewID_)
{
return crewDB->getCrewName(crewID_);
}
void SnapmaticEditor::on_cmdCancel_clicked()
{
close();
}
void SnapmaticEditor::on_cmdApply_clicked()
{
if (ui->cbQualify->isChecked())
{
qualifyAvatar();
}
localSpJson.crewID = crewID;
localSpJson.isSelfie = isSelfie;
localSpJson.isMug = isMugshot;
localSpJson.isFromRSEditor = isEditor;
localSpJson.isFromDirector = ui->cbDirector->isChecked();
localSpJson.isMeme = ui->cbMeme->isChecked();
if (smpic)
{
QString originalFileName = smpic->getPictureFilePath();
QString adjustedFileName = originalFileName;
if (adjustedFileName.right(7) == ".hidden") // for the hidden file system
{
adjustedFileName.remove(adjustedFileName.length() - 7, 7);
}
QString backupFileName = adjustedFileName % ".bak";
if (!QFile::exists(backupFileName))
{
QFile::copy(adjustedFileName, backupFileName);
}
SnapmaticProperties fallbackProperties = smpic->getSnapmaticProperties();
QString fallbackTitle = smpic->getPictureTitle();
smpic->setSnapmaticProperties(localSpJson);
smpic->setPictureTitle(snapmaticTitle);
if (!smpic->exportPicture(originalFileName))
{
QMessageBox::warning(this, tr("Snapmatic Properties"), tr("Patching of Snapmatic Properties failed because of I/O Error"));
smpic->setSnapmaticProperties(fallbackProperties);
smpic->setPictureTitle(fallbackTitle);
}
else
{
smpic->emitUpdate();
}
}
close();
}
void SnapmaticEditor::qualifyAvatar()
{
ui->rbSelfie->setChecked(true);
ui->cbDirector->setChecked(false);
ui->cbMeme->setChecked(false);
ui->cmdApply->setDefault(true);
}
void SnapmaticEditor::on_cbQualify_toggled(bool checked)
{
if (checked)
{
ui->cbMeme->setEnabled(false);
ui->cbDirector->setEnabled(false);
ui->rbCustom->setEnabled(false);
ui->rbSelfie->setEnabled(false);
ui->rbEditor->setEnabled(false);
ui->rbMugshot->setEnabled(false);
}
else
{
ui->cbMeme->setEnabled(true);
ui->rbCustom->setEnabled(true);
ui->rbSelfie->setEnabled(true);
ui->rbEditor->setEnabled(true);
ui->rbMugshot->setEnabled(true);
if (ui->rbSelfie->isChecked() || ui->rbCustom->isChecked())
{
ui->cbDirector->setEnabled(true);
}
}
}
void SnapmaticEditor::on_labTitle_linkActivated(const QString &link)
{
if (link == "g5e://edittitle")
{
bool ok;
QString newTitle = QInputDialog::getText(this, tr("Snapmatic Title"), tr("New Snapmatic title:"), QLineEdit::Normal, snapmaticTitle, &ok, windowFlags());
if (ok && !newTitle.isEmpty())
{
setSnapmaticTitle(newTitle);
}
}
}
void SnapmaticEditor::on_labCrew_linkActivated(const QString &link)
{
if (link == "g5e://editcrew")
{
bool ok;
int indexNum = 0;
QStringList itemList;
QStringList crewList = crewDB->getCrews();
if (!crewList.contains(QLatin1String("0")))
{
crewList += QLatin1String("0");
}
crewList.sort();
foreach(const QString &crew, crewList)
{
itemList += QString("%1 (%2)").arg(crew, returnCrewName(crew.toInt()));
}
if (crewList.contains(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());
if (ok && !newCrew.isEmpty())
{
if (newCrew.contains(" ")) newCrew = newCrew.split(" ").at(0);
if (newCrew.length() > 10) return;
foreach (const QChar &crewChar, newCrew)
{
if (!crewChar.isNumber())
{
return;
}
}
crewID = newCrew.toInt();
setSnapmaticCrew(returnCrewName(crewID));
}
}
}

View file

@ -1,69 +1,69 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 SNAPMATICEDITOR_H
#define SNAPMATICEDITOR_H
#include <QDialog>
#include "CrewDatabase.h"
#include "SnapmaticPicture.h"
namespace Ui {
class SnapmaticEditor;
}
class SnapmaticEditor : public QDialog
{
Q_OBJECT
public:
explicit SnapmaticEditor(CrewDatabase *crewDB, QWidget *parent = 0);
void setSnapmaticPicture(SnapmaticPicture *picture);
void setSnapmaticTitle(const QString &title);
void setSnapmaticCrew(const QString &crew = "");
QString returnCrewName(int crewID);
~SnapmaticEditor();
private slots:
void on_rbSelfie_toggled(bool checked);
void on_rbMugshot_toggled(bool checked);
void on_rbEditor_toggled(bool checked);
void on_rbCustom_toggled(bool checked);
void on_cmdCancel_clicked();
void on_cmdApply_clicked();
void on_cbQualify_toggled(bool checked);
void on_labTitle_linkActivated(const QString &link);
void on_labCrew_linkActivated(const QString &link);
private:
CrewDatabase *crewDB;
Ui::SnapmaticEditor *ui;
SnapmaticProperties localSpJson;
SnapmaticPicture *smpic;
QString snapmaticTitle;
int crewID;
bool isSelfie;
bool isMugshot;
bool isEditor;
void selfie_toggled(bool checked);
void mugshot_toggled(bool checked);
void editor_toggled(bool checked);
void qualifyAvatar();
};
#endif // SNAPMATICEDITOR_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 SNAPMATICEDITOR_H
#define SNAPMATICEDITOR_H
#include <QDialog>
#include "CrewDatabase.h"
#include "SnapmaticPicture.h"
namespace Ui {
class SnapmaticEditor;
}
class SnapmaticEditor : public QDialog
{
Q_OBJECT
public:
explicit SnapmaticEditor(CrewDatabase *crewDB, QWidget *parent = 0);
void setSnapmaticPicture(SnapmaticPicture *picture);
void setSnapmaticTitle(const QString &title);
void setSnapmaticCrew(const QString &crew = "");
QString returnCrewName(int crewID);
~SnapmaticEditor();
private slots:
void on_rbSelfie_toggled(bool checked);
void on_rbMugshot_toggled(bool checked);
void on_rbEditor_toggled(bool checked);
void on_rbCustom_toggled(bool checked);
void on_cmdCancel_clicked();
void on_cmdApply_clicked();
void on_cbQualify_toggled(bool checked);
void on_labTitle_linkActivated(const QString &link);
void on_labCrew_linkActivated(const QString &link);
private:
CrewDatabase *crewDB;
Ui::SnapmaticEditor *ui;
SnapmaticProperties localSpJson;
SnapmaticPicture *smpic;
QString snapmaticTitle;
int crewID;
bool isSelfie;
bool isMugshot;
bool isEditor;
void selfie_toggled(bool checked);
void mugshot_toggled(bool checked);
void editor_toggled(bool checked);
void qualifyAvatar();
};
#endif // SNAPMATICEDITOR_H

View file

@ -1,248 +1,248 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SnapmaticEditor</class>
<widget class="QDialog" name="SnapmaticEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>362</height>
</rect>
</property>
<property name="windowTitle">
<string>Snapmatic Properties</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="vlEditor">
<item>
<widget class="QWidget" name="frameWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="vlFrame">
<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="QGroupBox" name="gbMode">
<property name="title">
<string>Snapmatic Type</string>
</property>
<layout class="QGridLayout" name="gdType">
<item row="2" column="1">
<widget class="QRadioButton" name="rbEditor">
<property name="text">
<string>Editor</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="rbSelfie">
<property name="text">
<string>Selfie</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QRadioButton" name="rbCustom">
<property name="text">
<string>Regular</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="rbMugshot">
<property name="text">
<string>Mugshot</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbProperties">
<property name="title">
<string>Snapmatic Properties</string>
</property>
<layout class="QGridLayout" name="gdProperties">
<item row="0" column="1">
<widget class="QCheckBox" name="cbMeme">
<property name="text">
<string>Meme</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="cbDirector">
<property name="text">
<string>Director</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbValues">
<property name="title">
<string>Snapmatic Values</string>
</property>
<layout class="QVBoxLayout" name="vlTitle">
<item>
<widget class="UiModLabel" name="labCrew">
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="text">
<string>Crew: %1 (%2)</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="UiModLabel" name="labTitle">
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="text">
<string>Title: %1 (%2)</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="UiModLabel" name="labAppropriate">
<property name="text">
<string>Appropriate: %1</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbExtras">
<property name="title">
<string>Extras</string>
</property>
<layout class="QVBoxLayout" name="vlExtras">
<item>
<widget class="QCheckBox" name="cbQualify">
<property name="text">
<string>Qualify as Avatar automatically at apply</string>
</property>
</widget>
</item>
<item>
<widget class="UiModLabel" name="labQualify">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Qualify as Avatar allows you to use this Snapmatic as a Social Club profile picture</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="vsEditor">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="hlButtons">
<item>
<spacer name="hsButtons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="cmdApply">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Apply</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="text">
<string>&amp;Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>UiModLabel</class>
<extends>QLabel</extends>
<header>UiModLabel.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SnapmaticEditor</class>
<widget class="QDialog" name="SnapmaticEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>362</height>
</rect>
</property>
<property name="windowTitle">
<string>Snapmatic Properties</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="vlEditor">
<item>
<widget class="QWidget" name="frameWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="vlFrame">
<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="QGroupBox" name="gbMode">
<property name="title">
<string>Snapmatic Type</string>
</property>
<layout class="QGridLayout" name="gdType">
<item row="2" column="1">
<widget class="QRadioButton" name="rbEditor">
<property name="text">
<string>Editor</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="rbSelfie">
<property name="text">
<string>Selfie</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QRadioButton" name="rbCustom">
<property name="text">
<string>Regular</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="rbMugshot">
<property name="text">
<string>Mugshot</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbProperties">
<property name="title">
<string>Snapmatic Properties</string>
</property>
<layout class="QGridLayout" name="gdProperties">
<item row="0" column="1">
<widget class="QCheckBox" name="cbMeme">
<property name="text">
<string>Meme</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="cbDirector">
<property name="text">
<string>Director</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbValues">
<property name="title">
<string>Snapmatic Values</string>
</property>
<layout class="QVBoxLayout" name="vlTitle">
<item>
<widget class="UiModLabel" name="labCrew">
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="text">
<string>Crew: %1 (%2)</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="UiModLabel" name="labTitle">
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="text">
<string>Title: %1 (%2)</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="UiModLabel" name="labAppropriate">
<property name="text">
<string>Appropriate: %1</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbExtras">
<property name="title">
<string>Extras</string>
</property>
<layout class="QVBoxLayout" name="vlExtras">
<item>
<widget class="QCheckBox" name="cbQualify">
<property name="text">
<string>Qualify as Avatar automatically at apply</string>
</property>
</widget>
</item>
<item>
<widget class="UiModLabel" name="labQualify">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Qualify as Avatar allows you to use this Snapmatic as a Social Club profile picture</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="vsEditor">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="hlButtons">
<item>
<spacer name="hsButtons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="cmdApply">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Apply</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="text">
<string>&amp;Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>UiModLabel</class>
<extends>QLabel</extends>
<header>UiModLabel.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</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
* Copyright (C) 2016-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 SNAPMATICPICTURE_H
#define SNAPMATICPICTURE_H
#include <QStringList>
#include <QDateTime>
#include <QObject>
#include <QString>
#include <QImage>
#include <QFile>
struct SnapmaticProperties {
struct SnapmaticLocation {
QString area;
double x;
double y;
double z;
};
int uid;
int crewID;
QStringList playersList;
uint createdTimestamp;
QDateTime createdDateTime;
bool isMeme;
bool isMug;
bool isSelfie;
bool isFromDirector;
bool isFromRSEditor;
SnapmaticLocation location;
};
class SnapmaticPicture : public QObject
{
Q_OBJECT
public:
explicit SnapmaticPicture(const QString &fileName = "", QObject *parent = 0);
~SnapmaticPicture();
void reset();
bool preloadFile();
bool readingPictureFromFile(const QString &fileName, bool writeEnabled = true, bool cacheEnabled = false, bool fastLoad = true, bool lowRamMode = false);
bool readingPicture(bool writeEnabled = true, bool cacheEnabled = false, bool fastLoad = true, bool lowRamMode = false);
bool isPicOk();
void clearCache();
QImage getImage();
QString getLastStep();
QString getPictureStr();
QString getPictureHead();
QString getPictureTitl();
QString getPictureDesc();
QString getPictureSortStr();
QString getPictureFileName();
QString getPictureFilePath();
QString getExportPictureFileName();
int getContentMaxLength();
bool setImage(const QImage &picture);
bool setPictureTitl(const QString &newTitle);
bool setPictureStream(const QByteArray &picByteArray);
void updateStrings();
void emitUpdate();
// FILE MANAGEMENT
bool exportPicture(const QString &fileName, const QString format = "PGTA");
void setPicFileName(const QString &picFileName);
void setPicFilePath(const QString &picFilePath);
bool deletePicFile();
// ALTERNATIVES
QString getPictureTitle() { return getPictureTitl(); }
QString getPictureString() { return getPictureStr(); }
QString getPictureDescription() { return getPictureDesc(); }
bool setPictureTitle(const QString &newTitle) { return setPictureTitl(newTitle); }
// JSON
bool isJsonOk();
QString getJsonStr();
SnapmaticProperties getSnapmaticProperties();
bool setSnapmaticProperties(SnapmaticProperties newSpJson);
// VISIBILITY
bool isHidden();
bool setPictureHidden();
bool setPictureVisible();
// PREDEFINED PROPERTIES
QSize getSnapmaticResolution();
// VERIFY CONTENT
static bool verifyTitle(const QString &title);
private:
QString getSnapmaticHeaderString(const QByteArray &snapmaticHeader);
QString getSnapmaticJSONString(const QByteArray &jsonBytes);
QString getSnapmaticTIDEString(const QByteArray &tideBytes);
QImage cachePicture;
QString picExportFileName;
QString picFileName;
QString picFilePath;
QString pictureHead;
QString pictureStr;
QString lastStep;
QString sortStr;
QString titlStr;
QString descStr;
bool picOk;
bool lowRamMode;
bool writeEnabled;
bool cacheEnabled;
bool isLoadedInRAM;
bool isCustomFormat;
int jpegRawContentSize;
int jpegRawContentSizeE;
// PICTURE STREAM
QByteArray rawPicContent;
// JSON
void parseJsonContent();
bool jsonOk;
QString jsonStr;
SnapmaticProperties localSpJson;
// VERIFY CONTENT
static bool verifyTitleChar(const QChar &titleChar);
signals:
void preloaded();
void updated();
void loaded();
public slots:
};
#endif // SNAPMATICPICTURE_H
/*****************************************************************************
* gta5sync-spv Grand Theft Auto Snapmatic Picture Viewer
* Copyright (C) 2016-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 SNAPMATICPICTURE_H
#define SNAPMATICPICTURE_H
#include <QStringList>
#include <QDateTime>
#include <QObject>
#include <QString>
#include <QImage>
#include <QFile>
enum class SnapmaticFormat : int { Auto_Format = 0, PGTA_Format = 1, JPEG_Format = 2, G5E_Format = 3 };
struct SnapmaticProperties {
struct SnapmaticLocation {
QString area;
double x;
double y;
double z;
};
int uid;
int crewID;
QStringList playersList;
uint createdTimestamp;
QDateTime createdDateTime;
bool isMeme;
bool isMug;
bool isSelfie;
bool isFromDirector;
bool isFromRSEditor;
SnapmaticLocation location;
};
class SnapmaticPicture : public QObject
{
Q_OBJECT
public:
explicit SnapmaticPicture(const QString &fileName = "", QObject *parent = 0);
~SnapmaticPicture();
void reset();
bool preloadFile();
bool readingPictureFromFile(const QString &fileName, bool writeEnabled = true, bool cacheEnabled = false, bool fastLoad = true, bool lowRamMode = false);
bool readingPicture(bool writeEnabled = true, bool cacheEnabled = false, bool fastLoad = true, bool lowRamMode = false);
bool isPicOk();
void clearCache();
QImage getImage(bool fastLoad = false);
QString getLastStep();
QString getPictureStr();
QString getPictureHead();
QString getPictureTitl();
QString getPictureDesc();
QString getPictureSortStr();
QString getPictureFileName();
QString getPictureFilePath();
QString getExportPictureFileName();
int getContentMaxLength();
bool setImage(const QImage &picture);
bool setPictureTitl(const QString &newTitle);
bool setPictureStream(const QByteArray &picByteArray);
void updateStrings();
void emitUpdate();
// FILE MANAGEMENT
bool exportPicture(const QString &fileName, SnapmaticFormat format = SnapmaticFormat::Auto_Format);
void setPicFileName(const QString &picFileName);
void setPicFilePath(const QString &picFilePath);
bool deletePicFile();
// ALTERNATIVES
QString getPictureTitle() { return getPictureTitl(); }
QString getPictureString() { return getPictureStr(); }
QString getPictureDescription() { return getPictureDesc(); }
bool setPictureTitle(const QString &newTitle) { return setPictureTitl(newTitle); }
// JSON
bool isJsonOk();
QString getJsonStr();
SnapmaticProperties getSnapmaticProperties();
bool setSnapmaticProperties(SnapmaticProperties newSpJson);
bool setJsonStr(const QString &jsonStr);
// VISIBILITY
bool isHidden();
bool setPictureHidden();
bool setPictureVisible();
// PREDEFINED PROPERTIES
QSize getSnapmaticResolution();
// SNAPMATIC DEFAULTS
bool isSnapmaticDefaultsEnforced();
void setSnapmaticDefaultsEnforced(bool enforced);
// VERIFY CONTENT
static bool verifyTitle(const QString &title);
private:
QString getSnapmaticHeaderString(const QByteArray &snapmaticHeader);
QString getSnapmaticJSONString(const QByteArray &jsonBytes);
QString getSnapmaticTIDEString(const QByteArray &tideBytes);
QImage cachePicture;
QString picExportFileName;
QString picFileName;
QString picFilePath;
QString pictureHead;
QString pictureStr;
QString lastStep;
QString sortStr;
QString titlStr;
QString descStr;
bool picOk;
bool lowRamMode;
bool writeEnabled;
bool cacheEnabled;
bool isLoadedInRAM;
bool isCustomFormat;
bool careSnapDefault;
int jpegRawContentSize;
int jpegRawContentSizeE;
// PICTURE STREAM
QByteArray rawPicContent;
// JSON
void parseJsonContent();
bool jsonOk;
QString jsonStr;
SnapmaticProperties localSpJson;
// VERIFY CONTENT
static bool verifyTitleChar(const QChar &titleChar);
signals:
void preloaded();
void updated();
void loaded();
public slots:
};
#endif // SNAPMATICPICTURE_H

View file

@ -1,345 +1,331 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "SnapmaticWidget.h"
#include "ui_SnapmaticWidget.h"
#include "SnapmaticPicture.h"
#include "SnapmaticEditor.h"
#include "DatabaseThread.h"
#include "PictureDialog.h"
#include "PictureExport.h"
#include "StringParser.h"
#include "AppEnv.h"
#include "config.h"
#include <QMessageBox>
#include <QPixmap>
#include <QTimer>
#include <QDebug>
#include <QMenu>
#include <QFile>
SnapmaticWidget::SnapmaticWidget(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent) :
ProfileWidget(parent), profileDB(profileDB), crewDB(crewDB), threadDB(threadDB),
ui(new Ui::SnapmaticWidget)
{
ui->setupUi(this);
ui->cmdView->setVisible(false);
ui->cmdCopy->setVisible(false);
ui->cmdExport->setVisible(false);
ui->cmdDelete->setVisible(false);
ui->cbSelected->setVisible(false);
QPalette palette;
highlightBackColor = palette.highlight().color();
highlightTextColor = palette.highlightedText().color();
palette.setCurrentColorGroup(QPalette::Disabled);
highlightHiddenColor = palette.text().color();
picPath = "";
picStr = "";
smpic = 0;
installEventFilter(this);
}
SnapmaticWidget::~SnapmaticWidget()
{
delete ui;
}
bool SnapmaticWidget::eventFilter(QObject *obj, QEvent *ev)
{
if (obj == this)
{
if (ev->type() == QEvent::Enter)
{
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;
}
else if(ev->type() == QEvent::Leave)
{
setStyleSheet("");
return true;
}
}
return false;
}
void SnapmaticWidget::setSnapmaticPicture(SnapmaticPicture *picture)
{
smpic = picture;
picPath = picture->getPictureFilePath();
picTitl = picture->getPictureTitl();
picStr = picture->getPictureStr();
QObject::connect(picture, SIGNAL(updated()), this, SLOT(snapmaticUpdated()));
qreal screenRatio = AppEnv::screenRatio();
ui->labPicture->setFixedSize(48 * screenRatio, 27 * screenRatio);
QPixmap SnapmaticPixmap = QPixmap::fromImage(picture->getImage().scaled(ui->labPicture->width(), ui->labPicture->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation), Qt::AutoColor);
ui->labPicStr->setText(picStr + "\n" + picTitl + "");
ui->labPicture->setPixmap(SnapmaticPixmap);
picture->clearCache();
adjustTextColor();
}
void SnapmaticWidget::snapmaticUpdated()
{
// Current only strings get updated
picPath = smpic->getPictureFilePath();
picTitl = smpic->getPictureTitl();
picStr = smpic->getPictureStr();
ui->labPicStr->setText(picStr + "\n" + picTitl + "");
}
void SnapmaticWidget::on_cmdView_clicked()
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("Interface");
bool navigationBar = settings.value("NavigationBar", false).toBool();
settings.endGroup();
PictureDialog *picDialog = new PictureDialog(profileDB, crewDB, this);
picDialog->setSnapmaticPicture(smpic, true);
picDialog->setModal(true);
// be ready for playerName updated
QObject::connect(threadDB, SIGNAL(playerNameUpdated()), picDialog, SLOT(playerNameUpdated()));
QObject::connect(picDialog, SIGNAL(nextPictureRequested()), this, SLOT(dialogNextPictureRequested()));
QObject::connect(picDialog, SIGNAL(previousPictureRequested()), this, SLOT(dialogPreviousPictureRequested()));
// add previous next buttons
if (navigationBar) picDialog->addPreviousNextButtons();
// show picture dialog
#ifdef Q_OS_ANDROID
// Android ...
picDialog->showMaximized();
#else
picDialog->show();
if (navigationBar) picDialog->stylizeDialog();
//picDialog->adaptNewDialogSize();
picDialog->setMinimumSize(picDialog->size());
picDialog->setMaximumSize(picDialog->size());
#endif
picDialog->exec();
delete picDialog;
}
void SnapmaticWidget::on_cmdCopy_clicked()
{
PictureExport::exportAsSnapmatic(this, smpic);
}
void SnapmaticWidget::on_cmdExport_clicked()
{
PictureExport::exportAsPicture(this, smpic);
}
void SnapmaticWidget::on_cmdDelete_clicked()
{
if (deletePicture()) emit pictureDeleted();
}
bool SnapmaticWidget::deletePicture()
{
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)
{
if (smpic->deletePicFile())
{
return true;
}
else
{
QMessageBox::warning(this, tr("Delete picture"), tr("Failed at deleting %1 from your Snapmatic pictures").arg("\""+picStr+"\""));
}
}
return false;
}
void SnapmaticWidget::mousePressEvent(QMouseEvent *ev)
{
ProfileWidget::mousePressEvent(ev);
}
void SnapmaticWidget::mouseReleaseEvent(QMouseEvent *ev)
{
ProfileWidget::mouseReleaseEvent(ev);
if (ui->cbSelected->isVisible())
{
if (rect().contains(ev->pos()) && ev->button() == Qt::LeftButton)
{
ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
}
}
else
{
if (getContentMode() == 0 && rect().contains(ev->pos()) && ev->button() == Qt::LeftButton)
{
on_cmdView_clicked();
}
}
}
void SnapmaticWidget::mouseDoubleClickEvent(QMouseEvent *ev)
{
ProfileWidget::mouseDoubleClickEvent(ev);
if (!ui->cbSelected->isVisible() && getContentMode() == 1 && ev->button() == Qt::LeftButton)
{
on_cmdView_clicked();
}
}
void SnapmaticWidget::setSelected(bool isSelected)
{
ui->cbSelected->setChecked(isSelected);
}
void SnapmaticWidget::pictureSelected()
{
setSelected(!ui->cbSelected->isChecked());
}
void SnapmaticWidget::contextMenuEvent(QContextMenuEvent *ev)
{
emit contextMenuTriggered(ev);
}
void SnapmaticWidget::dialogNextPictureRequested()
{
emit nextPictureRequested((QWidget*)sender());
}
void SnapmaticWidget::dialogPreviousPictureRequested()
{
emit previousPictureRequested((QWidget*)sender());
}
void SnapmaticWidget::on_cbSelected_stateChanged(int arg1)
{
if (arg1 == Qt::Checked)
{
emit widgetSelected();
}
else if (arg1 == Qt::Unchecked)
{
emit widgetDeselected();
}
}
void SnapmaticWidget::adjustTextColor()
{
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())));
}
else
{
ui->labPicStr->setStyleSheet("");
}
}
bool SnapmaticWidget::makePictureHidden()
{
if (smpic->setPictureHidden())
{
picPath = smpic->getPictureFilePath();
adjustTextColor();
return true;
}
return false;
}
bool SnapmaticWidget::makePictureVisible()
{
if (smpic->setPictureVisible())
{
picPath = smpic->getPictureFilePath();
adjustTextColor();
return true;
}
return false;
}
void SnapmaticWidget::makePictureHiddenSlot()
{
makePictureHidden();
}
void SnapmaticWidget::makePictureVisibleSlot()
{
makePictureVisible();
}
void SnapmaticWidget::editSnapmaticProperties()
{
SnapmaticEditor *snapmaticEditor = new SnapmaticEditor(crewDB, this);
snapmaticEditor->setWindowFlags(snapmaticEditor->windowFlags()^Qt::WindowContextHelpButtonHint);
snapmaticEditor->setSnapmaticPicture(smpic);
snapmaticEditor->setModal(true);
snapmaticEditor->exec();
delete snapmaticEditor;
}
bool SnapmaticWidget::isSelected()
{
return ui->cbSelected->isChecked();
}
bool SnapmaticWidget::isHidden()
{
if (picPath.right(7) == ".hidden")
{
return true;
}
return false;
}
void SnapmaticWidget::setSelectionMode(bool selectionMode)
{
ui->cbSelected->setVisible(selectionMode);
}
void SnapmaticWidget::selectAllWidgets()
{
emit allWidgetsSelected();
}
void SnapmaticWidget::deselectAllWidgets()
{
emit allWidgetsDeselected();
}
SnapmaticPicture* SnapmaticWidget::getPicture()
{
return smpic;
}
QString SnapmaticWidget::getPicturePath()
{
return picPath;
}
QString SnapmaticWidget::getWidgetType()
{
return "SnapmaticWidget";
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "SnapmaticWidget.h"
#include "ui_SnapmaticWidget.h"
#include "SnapmaticPicture.h"
#include "SnapmaticEditor.h"
#include "DatabaseThread.h"
#include "PictureDialog.h"
#include "PictureExport.h"
#include "StringParser.h"
#include "AppEnv.h"
#include "config.h"
#include <QStringBuilder>
#include <QMessageBox>
#include <QPixmap>
#include <QTimer>
#include <QDebug>
#include <QMenu>
#include <QFile>
SnapmaticWidget::SnapmaticWidget(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent) :
ProfileWidget(parent), profileDB(profileDB), crewDB(crewDB), threadDB(threadDB),
ui(new Ui::SnapmaticWidget)
{
ui->setupUi(this);
ui->cmdView->setVisible(false);
ui->cmdCopy->setVisible(false);
ui->cmdExport->setVisible(false);
ui->cmdDelete->setVisible(false);
ui->cbSelected->setVisible(false);
QPalette palette;
palette.setCurrentColorGroup(QPalette::Disabled);
highlightHiddenColor = palette.text().color();
ui->SnapmaticFrame->setMouseTracking(true);
ui->labPicture->setMouseTracking(true);
ui->labPicStr->setMouseTracking(true);
ui->cbSelected->setMouseTracking(true);
smpic = nullptr;
}
SnapmaticWidget::~SnapmaticWidget()
{
delete ui;
}
void SnapmaticWidget::setSnapmaticPicture(SnapmaticPicture *picture)
{
smpic = picture;
QObject::connect(picture, SIGNAL(updated()), this, SLOT(snapmaticUpdated()));
qreal screenRatio = AppEnv::screenRatio();
ui->labPicture->setFixedSize(48 * screenRatio, 27 * screenRatio);
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() % "");
ui->labPicture->setPixmap(SnapmaticPixmap);
picture->clearCache();
adjustTextColor();
}
void SnapmaticWidget::snapmaticUpdated()
{
ui->labPicStr->setText(smpic->getPictureStr() % "\n" % smpic->getPictureTitl() % "");
}
void SnapmaticWidget::retranslate()
{
smpic->updateStrings();
ui->labPicStr->setText(smpic->getPictureStr() % "\n" % smpic->getPictureTitl() % "");
}
void SnapmaticWidget::on_cmdView_clicked()
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("Interface");
bool navigationBar = settings.value("NavigationBar", false).toBool();
settings.endGroup();
PictureDialog *picDialog = new PictureDialog(profileDB, crewDB, this);
picDialog->setSnapmaticPicture(smpic, true);
picDialog->setModal(true);
// be ready for crewName and playerName updated
QObject::connect(threadDB, SIGNAL(crewNameUpdated()), picDialog, SLOT(crewNameUpdated()));
QObject::connect(threadDB, SIGNAL(playerNameUpdated()), picDialog, SLOT(playerNameUpdated()));
QObject::connect(picDialog, SIGNAL(nextPictureRequested()), this, SLOT(dialogNextPictureRequested()));
QObject::connect(picDialog, SIGNAL(previousPictureRequested()), this, SLOT(dialogPreviousPictureRequested()));
// add previous next buttons
if (navigationBar) picDialog->addPreviousNextButtons();
// show picture dialog
#ifdef Q_OS_ANDROID
// Android ...
picDialog->showMaximized();
#else
picDialog->show();
if (navigationBar) picDialog->stylizeDialog();
//picDialog->adaptNewDialogSize();
picDialog->setMinimumSize(picDialog->size());
picDialog->setMaximumSize(picDialog->size());
#endif
picDialog->exec();
delete picDialog;
}
void SnapmaticWidget::on_cmdCopy_clicked()
{
PictureExport::exportAsSnapmatic(this, smpic);
}
void SnapmaticWidget::on_cmdExport_clicked()
{
PictureExport::exportAsPicture(this, smpic);
}
void SnapmaticWidget::on_cmdDelete_clicked()
{
if (deletePicture()) emit pictureDeleted();
}
bool SnapmaticWidget::deletePicture()
{
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)
{
if (smpic->deletePicFile())
{
return true;
}
else
{
QMessageBox::warning(this, tr("Delete picture"), tr("Failed at deleting %1 from your Snapmatic pictures").arg("\""+smpic->getPictureStr()+"\""));
}
}
return false;
}
void SnapmaticWidget::mousePressEvent(QMouseEvent *ev)
{
ProfileWidget::mousePressEvent(ev);
}
void SnapmaticWidget::mouseReleaseEvent(QMouseEvent *ev)
{
ProfileWidget::mouseReleaseEvent(ev);
if (ui->cbSelected->isVisible())
{
if (rect().contains(ev->pos()) && ev->button() == Qt::LeftButton)
{
ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
}
}
else
{
if (getContentMode() == 0 && rect().contains(ev->pos()) && ev->button() == Qt::LeftButton)
{
if (ev->modifiers().testFlag(Qt::ShiftModifier))
{
ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
}
else
{
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 SnapmaticWidget::mouseDoubleClickEvent(QMouseEvent *ev)
{
ProfileWidget::mouseDoubleClickEvent(ev);
if (!ui->cbSelected->isVisible() && getContentMode() == 1 && ev->button() == Qt::LeftButton)
{
on_cmdView_clicked();
}
}
void SnapmaticWidget::setSelected(bool isSelected)
{
ui->cbSelected->setChecked(isSelected);
}
void SnapmaticWidget::pictureSelected()
{
setSelected(!ui->cbSelected->isChecked());
}
void SnapmaticWidget::contextMenuEvent(QContextMenuEvent *ev)
{
emit contextMenuTriggered(ev);
}
void SnapmaticWidget::dialogNextPictureRequested()
{
emit nextPictureRequested((QWidget*)sender());
}
void SnapmaticWidget::dialogPreviousPictureRequested()
{
emit previousPictureRequested((QWidget*)sender());
}
void SnapmaticWidget::on_cbSelected_stateChanged(int arg1)
{
if (arg1 == Qt::Checked)
{
emit widgetSelected();
}
else if (arg1 == Qt::Unchecked)
{
emit widgetDeselected();
}
}
void SnapmaticWidget::adjustTextColor()
{
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())));
}
else
{
ui->labPicStr->setStyleSheet("");
}
}
bool SnapmaticWidget::makePictureHidden()
{
if (smpic->setPictureHidden())
{
adjustTextColor();
return true;
}
return false;
}
bool SnapmaticWidget::makePictureVisible()
{
if (smpic->setPictureVisible())
{
adjustTextColor();
return true;
}
return false;
}
void SnapmaticWidget::makePictureHiddenSlot()
{
makePictureHidden();
}
void SnapmaticWidget::makePictureVisibleSlot()
{
makePictureVisible();
}
void SnapmaticWidget::editSnapmaticProperties()
{
SnapmaticEditor *snapmaticEditor = new SnapmaticEditor(crewDB, this);
snapmaticEditor->setWindowFlags(snapmaticEditor->windowFlags()^Qt::WindowContextHelpButtonHint);
snapmaticEditor->setSnapmaticPicture(smpic);
snapmaticEditor->setModal(true);
snapmaticEditor->exec();
delete snapmaticEditor;
}
bool SnapmaticWidget::isSelected()
{
return ui->cbSelected->isChecked();
}
bool SnapmaticWidget::isHidden()
{
return smpic->isHidden();
}
void SnapmaticWidget::setSelectionMode(bool selectionMode)
{
ui->cbSelected->setVisible(selectionMode);
}
void SnapmaticWidget::selectAllWidgets()
{
emit allWidgetsSelected();
}
void SnapmaticWidget::deselectAllWidgets()
{
emit allWidgetsDeselected();
}
SnapmaticPicture* SnapmaticWidget::getPicture()
{
return smpic;
}
QString SnapmaticWidget::getPicturePath()
{
return smpic->getPictureFilePath();
}
QString SnapmaticWidget::getWidgetType()
{
return "SnapmaticWidget";
}

View file

@ -1,104 +1,98 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 SNAPMATICWIDGET_H
#define SNAPMATICWIDGET_H
#include "SnapmaticPicture.h"
#include "ProfileDatabase.h"
#include "DatabaseThread.h"
#include "ProfileWidget.h"
#include "CrewDatabase.h"
#include <QContextMenuEvent>
#include <QMouseEvent>
#include <QWidget>
#include <QColor>
namespace Ui {
class SnapmaticWidget;
}
class SnapmaticWidget : public ProfileWidget
{
Q_OBJECT
public:
SnapmaticWidget(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0);
void setSnapmaticPicture(SnapmaticPicture *picture);
void setSelectionMode(bool selectionMode);
void setSelected(bool isSelected);
bool deletePicture();
bool makePictureVisible();
bool makePictureHidden();
SnapmaticPicture *getPicture();
QString getPicturePath();
QString getWidgetType();
bool isSelected();
bool isHidden();
~SnapmaticWidget();
private slots:
void on_cmdView_clicked();
void on_cmdCopy_clicked();
void on_cmdExport_clicked();
void on_cmdDelete_clicked();
void on_cbSelected_stateChanged(int arg1);
void adjustTextColor();
void pictureSelected();
void selectAllWidgets();
void deselectAllWidgets();
void dialogNextPictureRequested();
void dialogPreviousPictureRequested();
void makePictureVisibleSlot();
void makePictureHiddenSlot();
void editSnapmaticProperties();
void snapmaticUpdated();
protected:
bool eventFilter(QObject *obj, QEvent *ev);
void mouseDoubleClickEvent(QMouseEvent *ev);
void mouseReleaseEvent(QMouseEvent *ev);
void mousePressEvent(QMouseEvent *ev);
void contextMenuEvent(QContextMenuEvent *ev);
private:
ProfileDatabase *profileDB;
CrewDatabase *crewDB;
DatabaseThread *threadDB;
Ui::SnapmaticWidget *ui;
SnapmaticPicture *smpic;
QColor highlightBackColor;
QColor highlightTextColor;
QColor highlightHiddenColor;
QString picPath;
QString picTitl;
QString picStr;
QWidget *snwgt;
signals:
void pictureDeleted();
void widgetSelected();
void widgetDeselected();
void allWidgetsSelected();
void allWidgetsDeselected();
void nextPictureRequested(QWidget *dialog);
void previousPictureRequested(QWidget *dialog);
void contextMenuTriggered(QContextMenuEvent *ev);
};
#endif // SNAPMATICWIDGET_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 SNAPMATICWIDGET_H
#define SNAPMATICWIDGET_H
#include "SnapmaticPicture.h"
#include "ProfileDatabase.h"
#include "DatabaseThread.h"
#include "ProfileWidget.h"
#include "CrewDatabase.h"
#include <QContextMenuEvent>
#include <QMouseEvent>
#include <QWidget>
#include <QColor>
namespace Ui {
class SnapmaticWidget;
}
class SnapmaticWidget : public ProfileWidget
{
Q_OBJECT
public:
SnapmaticWidget(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0);
void setSnapmaticPicture(SnapmaticPicture *picture);
void setSelectionMode(bool selectionMode);
void setSelected(bool isSelected);
bool deletePicture();
bool makePictureVisible();
bool makePictureHidden();
SnapmaticPicture *getPicture();
QString getPicturePath();
QString getWidgetType();
bool isSelected();
bool isHidden();
void retranslate();
~SnapmaticWidget();
private slots:
void on_cmdView_clicked();
void on_cmdCopy_clicked();
void on_cmdExport_clicked();
void on_cmdDelete_clicked();
void on_cbSelected_stateChanged(int arg1);
void adjustTextColor();
void pictureSelected();
void selectAllWidgets();
void deselectAllWidgets();
void dialogNextPictureRequested();
void dialogPreviousPictureRequested();
void makePictureVisibleSlot();
void makePictureHiddenSlot();
void editSnapmaticProperties();
void snapmaticUpdated();
protected:
void mouseDoubleClickEvent(QMouseEvent *ev);
void mouseReleaseEvent(QMouseEvent *ev);
void mousePressEvent(QMouseEvent *ev);
void contextMenuEvent(QContextMenuEvent *ev);
private:
ProfileDatabase *profileDB;
CrewDatabase *crewDB;
DatabaseThread *threadDB;
Ui::SnapmaticWidget *ui;
SnapmaticPicture *smpic;
QColor highlightHiddenColor;
signals:
void pictureDeleted();
void widgetSelected();
void widgetDeselected();
void allWidgetsSelected();
void allWidgetsDeselected();
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"?>
<ui version="4.0">
<class>SnapmaticWidget</class>
<widget class="QWidget" name="SnapmaticWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>490</width>
<height>45</height>
</rect>
</property>
<property name="windowTitle">
<string>Snapmatic Widget</string>
</property>
<layout class="QHBoxLayout" name="hlSnapmaticContent">
<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="QFrame" name="SnapmaticFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="hlSnapmatic">
<item>
<widget class="QCheckBox" name="cbSelected">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labPicture">
<property name="minimumSize">
<size>
<width>48</width>
<height>27</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>48</width>
<height>27</height>
</size>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labPicStr">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>PHOTO - 00/00/00 00:00:00</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdView">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>View picture</string>
</property>
<property name="text">
<string>View</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdCopy">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Copy picture</string>
</property>
<property name="text">
<string>Copy</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdExport">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Export picture</string>
</property>
<property name="text">
<string>Export</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdDelete">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Delete picture</string>
</property>
<property name="text">
<string>Delete</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SnapmaticWidget</class>
<widget class="QWidget" name="SnapmaticWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>490</width>
<height>45</height>
</rect>
</property>
<property name="windowTitle">
<string>Snapmatic Widget</string>
</property>
<layout class="QHBoxLayout" name="hlSnapmaticContent">
<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="QFrame" name="SnapmaticFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="hlSnapmatic">
<item>
<widget class="QCheckBox" name="cbSelected">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labPicture">
<property name="minimumSize">
<size>
<width>48</width>
<height>27</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>48</width>
<height>27</height>
</size>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labPicStr">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>PHOTO - 00/00/00 00:00:00</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdView">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>View picture</string>
</property>
<property name="text">
<string>View</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdCopy">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Copy picture</string>
</property>
<property name="text">
<string>Copy</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdExport">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Export picture</string>
</property>
<property name="text">
<string>Export</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdDelete">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Delete picture</string>
</property>
<property name="text">
<string>Delete</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -1,128 +1,128 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "StandardPaths.h"
#if QT_VERSION >= 0x050000
#include <QStandardPaths>
#else
#include <QDesktopServices>
#endif
StandardPaths::StandardPaths()
{
}
QString StandardPaths::applicationsLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::ApplicationsLocation);
#endif
}
QString StandardPaths::cacheLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
#endif
}
QString StandardPaths::dataLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::DataLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::DataLocation);
#endif
}
QString StandardPaths::desktopLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
#endif
}
QString StandardPaths::documentsLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
#endif
}
QString StandardPaths::moviesLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::MoviesLocation);
#endif
}
QString StandardPaths::picturesLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::PicturesLocation);
#endif
}
QString StandardPaths::fontsLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::FontsLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::FontsLocation);
#endif
}
QString StandardPaths::homeLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
#endif
}
QString StandardPaths::musicLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::MusicLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
#endif
}
QString StandardPaths::tempLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::TempLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::TempLocation);
#endif
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "StandardPaths.h"
#if QT_VERSION >= 0x050000
#include <QStandardPaths>
#else
#include <QDesktopServices>
#endif
StandardPaths::StandardPaths()
{
}
QString StandardPaths::applicationsLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::ApplicationsLocation);
#endif
}
QString StandardPaths::cacheLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
#endif
}
QString StandardPaths::dataLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::DataLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::DataLocation);
#endif
}
QString StandardPaths::desktopLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
#endif
}
QString StandardPaths::documentsLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
#endif
}
QString StandardPaths::moviesLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::MoviesLocation);
#endif
}
QString StandardPaths::picturesLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::PicturesLocation);
#endif
}
QString StandardPaths::fontsLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::FontsLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::FontsLocation);
#endif
}
QString StandardPaths::homeLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
#endif
}
QString StandardPaths::musicLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::MusicLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
#endif
}
QString StandardPaths::tempLocation()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::TempLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::TempLocation);
#endif
}

View file

@ -1,41 +1,41 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 STANDARDPATHS_H
#define STANDARDPATHS_H
#include <QString>
class StandardPaths
{
public:
StandardPaths();
static QString applicationsLocation();
static QString cacheLocation();
static QString dataLocation();
static QString desktopLocation();
static QString documentsLocation();
static QString fontsLocation();
static QString homeLocation();
static QString moviesLocation();
static QString picturesLocation();
static QString musicLocation();
static QString tempLocation();
};
#endif // STANDARDPATHS_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 STANDARDPATHS_H
#define STANDARDPATHS_H
#include <QString>
class StandardPaths
{
public:
StandardPaths();
static QString applicationsLocation();
static QString cacheLocation();
static QString dataLocation();
static QString desktopLocation();
static QString documentsLocation();
static QString fontsLocation();
static QString homeLocation();
static QString moviesLocation();
static QString picturesLocation();
static QString musicLocation();
static QString tempLocation();
};
#endif // STANDARDPATHS_H

View file

@ -1,76 +1,80 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "StringParser.h"
#include "config.h"
#include <QTextDocument>
#ifndef GTA5VIEW_CMD
#include <QApplication>
#endif
#include <QTextCodec>
#include <QByteArray>
#include <QFileInfo>
#include <QString>
#include <QList>
#include <QDir>
StringParser::StringParser()
{
}
QString StringParser::parseTitleString(const QByteArray &commitBytes, int maxLength)
{
Q_UNUSED(maxLength)
QString retStr = QTextCodec::codecForName("UTF-16LE")->toUnicode(commitBytes).trimmed();
retStr.remove(QChar('\x00'));
return retStr;
}
QString StringParser::convertDrawStringForLog(const QString &inputStr)
{
QString outputStr = inputStr;
return outputStr.replace("&","&u;").replace(",","&c;");
}
QString StringParser::convertLogStringForDraw(const QString &inputStr)
{
QString outputStr = inputStr;
return outputStr.replace("&c;",",").replace("&u;","&");
}
#ifndef GTA5VIEW_CMD
QString StringParser::convertBuildedString(const QString &buildedStr)
{
QString outputStr = buildedStr;
QByteArray sharePath = GTA5SYNC_SHARE;
outputStr.replace("$SHAREDIR", QString::fromUtf8(sharePath));
outputStr.replace("$RUNDIR", QFileInfo(qApp->applicationFilePath()).absoluteDir().absolutePath());
outputStr.replace("$SEPARATOR", QDir::separator());
return outputStr;
}
#endif
QString StringParser::escapeString(const QString &toEscape)
{
#if QT_VERSION >= 0x050000
return toEscape.toHtmlEscaped();
#else
return Qt::escape(toEscape);
#endif
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "StringParser.h"
#include "config.h"
#include <QTextDocument>
#include <QLibraryInfo>
#ifndef GTA5VIEW_CMD
#include <QApplication>
#endif
#include <QTextCodec>
#include <QByteArray>
#include <QFileInfo>
#include <QString>
#include <QList>
#include <QDir>
StringParser::StringParser()
{
}
QString StringParser::parseTitleString(const QByteArray &commitBytes, int maxLength)
{
Q_UNUSED(maxLength)
QString retStr = QTextCodec::codecForName("UTF-16LE")->toUnicode(commitBytes).trimmed();
retStr.remove(QChar('\x00'));
return retStr;
}
QString StringParser::convertDrawStringForLog(const QString &inputStr)
{
QString outputStr = inputStr;
return outputStr.replace("&","&u;").replace(",","&c;");
}
QString StringParser::convertLogStringForDraw(const QString &inputStr)
{
QString outputStr = inputStr;
return outputStr.replace("&c;",",").replace("&u;","&");
}
#ifndef GTA5VIEW_CMD
QString StringParser::convertBuildedString(const QString &buildedStr)
{
QString outputStr = buildedStr;
QByteArray sharePath = GTA5SYNC_SHARE;
outputStr.replace("APPNAME:", GTA5SYNC_APPSTR);
outputStr.replace("SHAREDDIR:", QString::fromUtf8(sharePath));
outputStr.replace("RUNDIR:", QFileInfo(qApp->applicationFilePath()).absoluteDir().absolutePath());
outputStr.replace("QCONFLANG:", QLibraryInfo::location(QLibraryInfo::TranslationsPath));
outputStr.replace("QCONFPLUG:", QLibraryInfo::location(QLibraryInfo::PluginsPath));
outputStr.replace("SEPARATOR:", QDir::separator());
return outputStr;
}
#endif
QString StringParser::escapeString(const QString &toEscape)
{
#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
* Copyright (C) 2016-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 STRINGPARSER_H
#define STRINGPARSER_H
#include <QByteArray>
#include <QString>
class StringParser
{
public:
StringParser();
static QString parseTitleString(const QByteArray &commitBytes, int maxLength);
static QString convertDrawStringForLog(const QString &inputStr);
static QString convertLogStringForDraw(const QString &inputStr);
#ifndef GTA5VIEW_CMD
static QString convertBuildedString(const QString &buildedStr);
#endif
static QString escapeString(const QString &toEscape);
};
#endif // STRINGPARSER_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 STRINGPARSER_H
#define STRINGPARSER_H
#include <QByteArray>
#include <QString>
class StringParser
{
public:
StringParser();
static QString parseTitleString(const QByteArray &commitBytes, int maxLength);
static QString convertDrawStringForLog(const QString &inputStr);
static QString convertLogStringForDraw(const QString &inputStr);
#ifndef GTA5VIEW_CMD
static QString convertBuildedString(const QString &buildedStr);
#endif
static QString escapeString(const QString &toEscape);
};
#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
* Copyright (C) 2016-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 USERINTERFACE_H
#define USERINTERFACE_H
#include "SnapmaticPicture.h"
#include "ProfileInterface.h"
#include "ProfileDatabase.h"
#include "DatabaseThread.h"
#include "CrewDatabase.h"
#include "SavegameData.h"
#include <QMainWindow>
#include <QCloseEvent>
#include <QString>
#include <QMap>
namespace Ui {
class UserInterface;
}
class UserInterface : public QMainWindow
{
Q_OBJECT
public:
explicit UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0);
void setupDirEnv();
~UserInterface();
private slots:
void closeProfile();
void profileLoaded();
void changeFolder_clicked();
void profileButton_clicked();
void on_cmdReload_clicked();
void on_actionExit_triggered();
void on_actionSelect_profile_triggered();
void on_actionAbout_gta5sync_triggered();
void on_actionSelect_all_triggered();
void on_actionDeselect_all_triggered();
void on_actionExport_selected_triggered();
void on_actionDelete_selected_triggered();
void on_actionOptions_triggered();
void on_action_Import_triggered();
void on_actionOpen_File_triggered();
void on_actionSelect_GTA_Folder_triggered();
void on_action_Enable_In_game_triggered();
void on_action_Disable_In_game_triggered();
void settingsApplied(int contentMode, QString language);
protected:
void closeEvent(QCloseEvent *ev);
private:
ProfileDatabase *profileDB;
CrewDatabase *crewDB;
DatabaseThread *threadDB;
Ui::UserInterface *ui;
ProfileInterface *profileUI;
QList<QPushButton*> profileBtns;
bool profileOpen;
int contentMode;
QString language;
QString defaultWindowTitle;
QString GTAV_Folder;
QString GTAV_ProfilesFolder;
QStringList GTAV_Profiles;
void setupProfileUi();
void openProfile(QString profileName);
void openSelectProfile();
// Open File
bool openFile(QString selectedFile, bool warn = true);
void openSavegameFile(SavegameData *savegame);
void openSnapmaticFile(SnapmaticPicture *picture);
};
#endif // USERINTERFACE_H
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 USERINTERFACE_H
#define USERINTERFACE_H
#include "SnapmaticPicture.h"
#include "ProfileInterface.h"
#include "ProfileDatabase.h"
#include "DatabaseThread.h"
#include "CrewDatabase.h"
#include "SavegameData.h"
#include <QMainWindow>
#include <QMouseEvent>
#include <QCloseEvent>
#include <QString>
#include <QMap>
namespace Ui {
class UserInterface;
}
class UserInterface : public QMainWindow
{
Q_OBJECT
public:
explicit UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0);
void setupDirEnv();
~UserInterface();
private slots:
void closeProfile();
void profileLoaded();
void changeFolder_clicked();
void profileButton_clicked();
void on_cmdReload_clicked();
void on_actionExit_triggered();
void on_actionSelect_profile_triggered();
void on_actionAbout_gta5sync_triggered();
void on_actionSelect_all_triggered();
void on_actionDeselect_all_triggered();
void on_actionExport_selected_triggered();
void on_actionDelete_selected_triggered();
void on_actionOptions_triggered();
void on_action_Import_triggered();
void on_actionOpen_File_triggered();
void on_actionSelect_GTA_Folder_triggered();
void on_action_Enable_In_game_triggered();
void on_action_Disable_In_game_triggered();
void settingsApplied(int contentMode, QString language);
protected:
void closeEvent(QCloseEvent *ev);
private:
ProfileDatabase *profileDB;
CrewDatabase *crewDB;
DatabaseThread *threadDB;
Ui::UserInterface *ui;
ProfileInterface *profileUI;
QList<QPushButton*> profileBtns;
QString profileName;
bool profileOpen;
int contentMode;
QString language;
QString defaultWindowTitle;
QString GTAV_Folder;
QString GTAV_ProfilesFolder;
QStringList GTAV_Profiles;
void setupProfileUi();
void openProfile(const QString &profileName);
void openSelectProfile();
void retranslateUi();
// Open File
bool openFile(QString selectedFile, bool warn = true);
void openSavegameFile(SavegameData *savegame);
void openSnapmaticFile(SnapmaticPicture *picture);
};
#endif // USERINTERFACE_H

View file

@ -1,348 +1,354 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UserInterface</class>
<widget class="QMainWindow" name="UserInterface">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>625</width>
<height>500</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>625</width>
<height>500</height>
</size>
</property>
<property name="windowTitle">
<string>%2 - %1</string>
</property>
<widget class="QWidget" name="cwUI">
<layout class="QVBoxLayout" name="vlUI">
<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="QStackedWidget" name="swProfile">
<property name="lineWidth">
<number>0</number>
</property>
<widget class="QWidget" name="swSelection">
<layout class="QVBoxLayout" name="vlUserInterface">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<spacer name="vsUpper">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labSelectProfile">
<property name="text">
<string>Select profile</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="vlButtons"/>
</item>
<item>
<spacer name="vsFooter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="hlButtons">
<item>
<widget class="QLabel" name="labVersion">
<property name="text">
<string>%1 %2</string>
</property>
</widget>
</item>
<item>
<spacer name="hsButtons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="cmdReload">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Reload</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdClose">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Close</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>625</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="actionSelect_GTA_Folder"/>
<addaction name="actionOpen_File"/>
<addaction name="actionSelect_profile"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
<string>&amp;Help</string>
</property>
<addaction name="actionAbout_gta5sync"/>
</widget>
<widget class="QMenu" name="menuEdit">
<property name="title">
<string>&amp;Edit</string>
</property>
<addaction name="actionOptions"/>
</widget>
<widget class="QMenu" name="menuProfile">
<property name="title">
<string>&amp;Profile</string>
</property>
<widget class="QMenu" name="menuSelection_visibility">
<property name="title">
<string>&amp;Selection visibility</string>
</property>
<addaction name="action_Enable_In_game"/>
<addaction name="action_Disable_In_game"/>
</widget>
<addaction name="action_Import"/>
<addaction name="actionExport_selected"/>
<addaction name="actionDelete_selected"/>
<addaction name="separator"/>
<addaction name="menuSelection_visibility"/>
<addaction name="separator"/>
<addaction name="actionSelect_all"/>
<addaction name="actionDeselect_all"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuProfile"/>
<addaction name="menuHelp"/>
</widget>
<action name="actionAbout_gta5sync">
<property name="text">
<string>&amp;About %1</string>
</property>
<property name="shortcut">
<string>Ctrl+P</string>
</property>
</action>
<action name="actionExit">
<property name="text">
<string>&amp;Exit</string>
</property>
<property name="toolTip">
<string>Exit</string>
</property>
<property name="shortcut">
<string>Ctrl+Q</string>
</property>
</action>
<action name="actionSelect_profile">
<property name="text">
<string>Close &amp;Profile</string>
</property>
<property name="shortcut">
<string>Ctrl+End</string>
</property>
</action>
<action name="actionOptions">
<property name="text">
<string>&amp;Settings</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="actionSelect_all">
<property name="text">
<string>Select &amp;All</string>
</property>
<property name="shortcut">
<string>Ctrl+A</string>
</property>
</action>
<action name="actionDeselect_all">
<property name="text">
<string>&amp;Deselect All</string>
</property>
<property name="shortcut">
<string>Ctrl+D</string>
</property>
</action>
<action name="actionExport_selected">
<property name="text">
<string>&amp;Export selected...</string>
</property>
<property name="shortcut">
<string>Ctrl+E</string>
</property>
</action>
<action name="actionDelete_selected">
<property name="text">
<string>&amp;Remove selected</string>
</property>
<property name="shortcut">
<string>Ctrl+Del</string>
</property>
</action>
<action name="action_Import">
<property name="text">
<string>&amp;Import files...</string>
</property>
<property name="shortcut">
<string>Ctrl+I</string>
</property>
</action>
<action name="actionOpen_File">
<property name="text">
<string>&amp;Open File...</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
</property>
</action>
<action name="actionSelect_GTA_Folder">
<property name="text">
<string>Select &amp;GTA V Folder...</string>
</property>
<property name="toolTip">
<string>Select GTA V Folder...</string>
</property>
<property name="shortcut">
<string>Ctrl+G</string>
</property>
</action>
<action name="action_Enable_In_game">
<property name="text">
<string>Show In-gam&amp;e</string>
</property>
<property name="shortcut">
<string>Shift+E</string>
</property>
</action>
<action name="action_Disable_In_game">
<property name="text">
<string>Hi&amp;de In-game</string>
</property>
<property name="shortcut">
<string>Shift+D</string>
</property>
</action>
</widget>
<resources/>
<connections>
<connection>
<sender>cmdClose</sender>
<signal>clicked()</signal>
<receiver>UserInterface</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>572</x>
<y>476</y>
</hint>
<hint type="destinationlabel">
<x>312</x>
<y>249</y>
</hint>
</hints>
</connection>
</connections>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UserInterface</class>
<widget class="QMainWindow" name="UserInterface">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>625</width>
<height>500</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>625</width>
<height>500</height>
</size>
</property>
<property name="windowTitle">
<string>%2 - %1</string>
</property>
<widget class="QWidget" name="cwUI">
<layout class="QVBoxLayout" name="vlUI">
<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="QStackedWidget" name="swProfile">
<property name="lineWidth">
<number>0</number>
</property>
<widget class="QWidget" name="swSelection">
<layout class="QVBoxLayout" name="vlUserInterface">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<spacer name="vsUpper">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labSelectProfile">
<property name="text">
<string>Select profile</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="vlButtons"/>
</item>
<item>
<spacer name="vsFooter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="hlButtons">
<item>
<widget class="QLabel" name="labVersion">
<property name="text">
<string>%1 %2</string>
</property>
</widget>
</item>
<item>
<spacer name="hsButtons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="cmdReload">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Reload profile overview</string>
</property>
<property name="text">
<string>&amp;Reload</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdClose">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string extracomment="Close %1 &lt;- (gta5view/gta5sync) - %1 will be replaced automatically">Close %1</string>
</property>
<property name="text">
<string>&amp;Close</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>625</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="actionSelect_GTA_Folder"/>
<addaction name="actionOpen_File"/>
<addaction name="actionSelect_profile"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
<string>&amp;Help</string>
</property>
<addaction name="actionAbout_gta5sync"/>
</widget>
<widget class="QMenu" name="menuEdit">
<property name="title">
<string>&amp;Edit</string>
</property>
<addaction name="actionOptions"/>
</widget>
<widget class="QMenu" name="menuProfile">
<property name="title">
<string>&amp;Profile</string>
</property>
<widget class="QMenu" name="menuSelection_visibility">
<property name="title">
<string>&amp;Selection visibility</string>
</property>
<addaction name="action_Enable_In_game"/>
<addaction name="action_Disable_In_game"/>
</widget>
<addaction name="action_Import"/>
<addaction name="actionExport_selected"/>
<addaction name="actionDelete_selected"/>
<addaction name="separator"/>
<addaction name="menuSelection_visibility"/>
<addaction name="separator"/>
<addaction name="actionSelect_all"/>
<addaction name="actionDeselect_all"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuProfile"/>
<addaction name="menuHelp"/>
</widget>
<action name="actionAbout_gta5sync">
<property name="text">
<string>&amp;About %1</string>
</property>
<property name="shortcut">
<string>Ctrl+P</string>
</property>
</action>
<action name="actionExit">
<property name="text">
<string>&amp;Exit</string>
</property>
<property name="toolTip">
<string>Exit</string>
</property>
<property name="shortcut">
<string>Ctrl+Q</string>
</property>
</action>
<action name="actionSelect_profile">
<property name="text">
<string>Close &amp;Profile</string>
</property>
<property name="shortcut">
<string>Ctrl+End</string>
</property>
</action>
<action name="actionOptions">
<property name="text">
<string>&amp;Settings</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="actionSelect_all">
<property name="text">
<string>Select &amp;All</string>
</property>
<property name="shortcut">
<string>Ctrl+A</string>
</property>
</action>
<action name="actionDeselect_all">
<property name="text">
<string>&amp;Deselect All</string>
</property>
<property name="shortcut">
<string>Ctrl+D</string>
</property>
</action>
<action name="actionExport_selected">
<property name="text">
<string>&amp;Export selected...</string>
</property>
<property name="shortcut">
<string>Ctrl+E</string>
</property>
</action>
<action name="actionDelete_selected">
<property name="text">
<string>&amp;Remove selected</string>
</property>
<property name="shortcut">
<string>Ctrl+Del</string>
</property>
</action>
<action name="action_Import">
<property name="text">
<string>&amp;Import files...</string>
</property>
<property name="shortcut">
<string>Ctrl+I</string>
</property>
</action>
<action name="actionOpen_File">
<property name="text">
<string>&amp;Open File...</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
</property>
</action>
<action name="actionSelect_GTA_Folder">
<property name="text">
<string>Select &amp;GTA V Folder...</string>
</property>
<property name="toolTip">
<string>Select GTA V Folder...</string>
</property>
<property name="shortcut">
<string>Ctrl+G</string>
</property>
</action>
<action name="action_Enable_In_game">
<property name="text">
<string>Show In-gam&amp;e</string>
</property>
<property name="shortcut">
<string>Shift+E</string>
</property>
</action>
<action name="action_Disable_In_game">
<property name="text">
<string>Hi&amp;de In-game</string>
</property>
<property name="shortcut">
<string>Shift+D</string>
</property>
</action>
</widget>
<resources/>
<connections>
<connection>
<sender>cmdClose</sender>
<signal>clicked()</signal>
<receiver>UserInterface</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>572</x>
<y>476</y>
</hint>
<hint type="destinationlabel">
<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
* Copyright (C) 2016-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 CONFIG_H
#define CONFIG_H
#include <QString>
#ifndef GTA5SYNC_APPVENDOR
#define GTA5SYNC_APPVENDOR "Syping"
#endif
#ifndef GTA5SYNC_APPVENDORLINK
#define GTA5SYNC_APPVENDORLINK "https://github.com/Syping/"
#endif
#ifndef GTA5SYNC_DISABLED
#define GTA5SYNC_ENABLED
#endif
#ifndef GTA5SYNC_APPSTR
#ifdef GTA5SYNC_ENABLED
#define GTA5SYNC_APPSTR "gta5sync"
#else
#define GTA5SYNC_APPSTR "gta5view"
#endif
#endif
#ifndef GTA5SYNC_APPDES
#define GTA5SYNC_APPDES "INSERT YOUR APPLICATION DESCRIPTION HERE"
#endif
#ifndef GTA5SYNC_COPYRIGHT
#define GTA5SYNC_COPYRIGHT "2016-2017"
#endif
#ifndef GTA5SYNC_APPVER
#ifndef GTA5SYNC_DAILYB
#define GTA5SYNC_APPVER "1.4.4"
#else
#define GTA5SYNC_APPVER QString("%1").arg(GTA5SYNC_DAILYB)
#endif
#endif
#ifndef GTA5SYNC_BUILDTYPE
#define GTA5SYNC_BUILDTYPE "Custom"
#endif
#ifndef GTA5SYNC_SHARE
#define GTA5SYNC_SHARE "$RUNDIR"
#endif
#ifndef GTA5SYNC_LANG
#define GTA5SYNC_LANG "$SHAREDIR$SEPARATORlang"
#endif
#ifndef GTA5SYNC_PLUG
#define GTA5SYNC_PLUG "$RUNDIR$SEPARATORplugins"
#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
/*****************************************************************************
* gta5view Grand Theft Auto V Profile Viewer
* Copyright (C) 2016-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 CONFIG_H
#define CONFIG_H
#include <QtGlobal>
#include <QString>
#ifndef GTA5SYNC_APPVENDOR
#define GTA5SYNC_APPVENDOR "Syping"
#endif
#ifndef GTA5SYNC_APPVENDORLINK
#define GTA5SYNC_APPVENDORLINK "https://github.com/Syping/"
#endif
#ifndef GTA5SYNC_DISABLED
#define GTA5SYNC_ENABLED
#endif
#ifndef GTA5SYNC_APPSTR
#ifdef GTA5SYNC_ENABLED
#define GTA5SYNC_APPSTR "gta5sync"
#else
#define GTA5SYNC_APPSTR "gta5view"
#endif
#endif
#ifndef GTA5SYNC_APPDES
#define GTA5SYNC_APPDES "INSERT YOUR APPLICATION DESCRIPTION HERE"
#endif
#ifndef GTA5SYNC_COPYRIGHT
#define GTA5SYNC_COPYRIGHT "2016-2017"
#endif
#ifndef GTA5SYNC_APPVER
#ifndef GTA5SYNC_DAILYB
#define GTA5SYNC_APPVER "1.5.0-dev1"
#else
#define GTA5SYNC_APPVER GTA5SYNC_DAILYB
#endif
#endif
#ifdef GTA5SYNC_BUILDTYPE_REL
#ifndef GTA5SYNC_BUILDTYPE
#define GTA5SYNC_BUILDTYPE QT_TRANSLATE_NOOP("AboutDialog", "Release")
#endif
#endif
#ifdef GTA5SYNC_BUILDTYPE_RC
#ifndef GTA5SYNC_BUILDTYPE
#define GTA5SYNC_BUILDTYPE QT_TRANSLATE_NOOP("AboutDialog", "Release Candidate")
#endif
#endif
#ifdef GTA5SYNC_BUILDTYPE_DAILY
#ifndef GTA5SYNC_BUILDTYPE
#define GTA5SYNC_BUILDTYPE QT_TRANSLATE_NOOP("AboutDialog", "Daily Build")
#endif
#endif
#ifdef GTA5SYNC_BUILDTYPE_DEV
#ifndef GTA5SYNC_BUILDTYPE
#define GTA5SYNC_BUILDTYPE QT_TRANSLATE_NOOP("AboutDialog", "Developer")
#endif
#endif
#ifdef GTA5SYNC_BUILDTYPE_BETA
#ifndef GTA5SYNC_BUILDTYPE
#define GTA5SYNC_BUILDTYPE QT_TRANSLATE_NOOP("AboutDialog", "Beta")
#endif
#endif
#ifdef GTA5SYNC_BUILDTYPE_ALPHA
#ifndef GTA5SYNC_BUILDTYPE
#define GTA5SYNC_BUILDTYPE QT_TRANSLATE_NOOP("AboutDialog", "Alpha")
#endif
#endif
#ifdef GTA5SYNC_DAILYB
#ifndef GTA5SYNC_BUILDTYPE
#define GTA5SYNC_BUILDTYPE "Daily Build"
#endif
#endif
#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
#* Copyright (C) 2015-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/>.
#*****************************************************************************/
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 4): greaterThan(QT_MINOR_VERSION, 1): win32: QT += winextras
DEFINES += GTA5SYNC_DISABLED
DEPLOYMENT.display_name = gta5view
TARGET = gta5view
TEMPLATE = app
SOURCES += main.cpp \
AboutDialog.cpp \
AppEnv.cpp \
CrewDatabase.cpp \
DatabaseThread.cpp \
ExportDialog.cpp \
ExportThread.cpp \
GlobalString.cpp \
IconLoader.cpp \
ImportDialog.cpp \
OptionsDialog.cpp \
PictureDialog.cpp \
PictureExport.cpp \
PictureWidget.cpp \
ProfileDatabase.cpp \
ProfileInterface.cpp \
ProfileLoader.cpp \
ProfileWidget.cpp \
SavegameCopy.cpp \
SavegameData.cpp \
SavegameDialog.cpp \
SavegameWidget.cpp \
SidebarGenerator.cpp \
SnapmaticEditor.cpp \
SnapmaticPicture.cpp \
SnapmaticWidget.cpp \
StandardPaths.cpp \
StringParser.cpp \
UserInterface.cpp \
uimod/UiModLabel.cpp \
uimod/UiModWidget.cpp
HEADERS += \
AboutDialog.h \
AppEnv.h \
CrewDatabase.h \
DatabaseThread.h \
ExportDialog.h \
ExportThread.h \
GlobalString.h \
IconLoader.h \
ImportDialog.h \
OptionsDialog.h \
PictureDialog.h \
PictureExport.h \
PictureWidget.h \
ProfileDatabase.h \
ProfileInterface.h \
ProfileLoader.h \
ProfileWidget.h \
SavegameCopy.h \
SavegameData.h \
SavegameDialog.h \
SavegameWidget.h \
SidebarGenerator.h \
SnapmaticEditor.h \
SnapmaticPicture.h \
SnapmaticWidget.h \
StandardPaths.h \
StringParser.h \
UserInterface.h \
uimod/UiModLabel.h \
uimod/UiModWidget.h
PRECOMPILED_HEADER += config.h
FORMS += \
AboutDialog.ui \
ExportDialog.ui \
ImportDialog.ui \
OptionsDialog.ui \
PictureDialog.ui \
ProfileInterface.ui \
SavegameDialog.ui \
SavegameWidget.ui \
SnapmaticEditor.ui \
SnapmaticWidget.ui \
UserInterface.ui
TRANSLATIONS += \
res/gta5sync_de.ts \
res/gta5sync_fr.ts \
res/gta5sync_ru.ts
RESOURCES += \
res/tr_g5p.qrc \
res/app.qrc
DISTFILES += res/app.rc \
res/gta5sync.desktop \
res/gta5sync_de.ts \
res/gta5sync_fr.ts \
res/gta5sync_ru.ts \
res/gta5view.exe.manifest \
res/gta5view.png \
lang/README.txt
INCLUDEPATH += ./uimod
# WINDOWS ONLY
win32: DEFINES += GTA5SYNC_WIN
win32: RC_FILE += res/app.rc
win32: LIBS += -luser32
win32: CONFIG -= embed_manifest_exe
# MAC OS X ONLY
macx: ICON = res/5sync.icns
# QT4 ONLY STUFF
isEqual(QT_MAJOR_VERSION, 4): INCLUDEPATH += ./qjson4
isEqual(QT_MAJOR_VERSION, 4): HEADERS += qjson4/QJsonArray.h \
qjson4/QJsonDocument.h \
qjson4/QJsonObject.h \
qjson4/QJsonParseError.h \
qjson4/QJsonValue.h \
qjson4/QJsonValueRef.h \
qjson4/QJsonParser.h \
qjson4/QJsonRoot.h
isEqual(QT_MAJOR_VERSION, 4): SOURCES += qjson4/QJsonArray.cpp \
qjson4/QJsonDocument.cpp \
qjson4/QJsonObject.cpp \
qjson4/QJsonParseError.cpp \
qjson4/QJsonValue.cpp \
qjson4/QJsonValueRef.cpp \
qjson4/QJsonParser.cpp
isEqual(QT_MAJOR_VERSION, 4): RESOURCES += res/tr_qt4.qrc
# QT5 ONLY STUFF
isEqual(QT_MAJOR_VERSION, 5): RESOURCES += res/tr_qt5.qrc
# UNIX SYSTEM STUFF
unix: !macx: appfiles.path = $$(INSTALL_PATH)/share/applications
unix: !macx: appfiles.files = $$PWD/res/gta5view.desktop
unix: !macx: pixmaps.path = $$(INSTALL_PATH)/share/pixmaps
unix: !macx: pixmaps.files = $$PWD/res/gta5view.png
unix: !macx: target.path = $$(INSTALL_PATH)/bin
unix: !macx: INSTALLS += target pixmaps appfiles
#/*****************************************************************************
#* gta5view Grand Theft Auto V Profile Viewer
#* Copyright (C) 2015-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/>.
#*****************************************************************************/
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 4): greaterThan(QT_MINOR_VERSION, 1): win32: QT += winextras
DEFINES += GTA5SYNC_DISABLED
DEPLOYMENT.display_name = gta5view
TARGET = gta5view
TEMPLATE = app
DEFINES += GTA5SYNC_CSDF # Not assisting at proper usage of SnapmaticPicture class
HEADERS += config.h
PRECOMPILED_HEADER += config.h
SOURCES += main.cpp \
AboutDialog.cpp \
AppEnv.cpp \
CrewDatabase.cpp \
DatabaseThread.cpp \
ExportDialog.cpp \
ExportThread.cpp \
GlobalString.cpp \
IconLoader.cpp \
ImportDialog.cpp \
MapPreviewDialog.cpp \
OptionsDialog.cpp \
PictureDialog.cpp \
PictureExport.cpp \
PictureWidget.cpp \
ProfileDatabase.cpp \
ProfileInterface.cpp \
ProfileLoader.cpp \
ProfileWidget.cpp \
SavegameCopy.cpp \
SavegameData.cpp \
SavegameDialog.cpp \
SavegameWidget.cpp \
SidebarGenerator.cpp \
SnapmaticEditor.cpp \
SnapmaticPicture.cpp \
SnapmaticWidget.cpp \
StandardPaths.cpp \
StringParser.cpp \
TranslationClass.cpp \
UserInterface.cpp \
uimod/UiModLabel.cpp \
uimod/UiModWidget.cpp
HEADERS += \
AboutDialog.h \
AppEnv.h \
CrewDatabase.h \
DatabaseThread.h \
ExportDialog.h \
ExportThread.h \
GlobalString.h \
IconLoader.h \
ImportDialog.h \
MapPreviewDialog.h \
OptionsDialog.h \
PictureDialog.h \
PictureExport.h \
PictureWidget.h \
ProfileDatabase.h \
ProfileInterface.h \
ProfileLoader.h \
ProfileWidget.h \
SavegameCopy.h \
SavegameData.h \
SavegameDialog.h \
SavegameWidget.h \
SidebarGenerator.h \
SnapmaticEditor.h \
SnapmaticPicture.h \
SnapmaticWidget.h \
StandardPaths.h \
StringParser.h \
TranslationClass.h \
UserInterface.h \
uimod/UiModLabel.h \
uimod/UiModWidget.h
FORMS += \
AboutDialog.ui \
ExportDialog.ui \
ImportDialog.ui \
MapPreviewDialog.ui \
OptionsDialog.ui \
PictureDialog.ui \
ProfileInterface.ui \
SavegameDialog.ui \
SavegameWidget.ui \
SnapmaticEditor.ui \
SnapmaticWidget.ui \
UserInterface.ui
TRANSLATIONS += \
res/gta5sync_en_US.ts \
res/gta5sync_de.ts \
res/gta5sync_fr.ts \
res/gta5sync_ru.ts \
lang/gta5sync_no.ts
RESOURCES += \
res/tr_g5p.qrc \
res/app.qrc
DISTFILES += res/app.rc \
res/gta5view.desktop \
res/gta5sync_de.ts \
res/gta5sync_fr.ts \
res/gta5sync_ru.ts \
res/gta5view.exe.manifest \
res/gta5view.png \
lang/gta5sync_no.ts \
lang/README.txt
INCLUDEPATH += ./uimod
# WINDOWS ONLY
win32: DEFINES += GTA5SYNC_WIN
win32: RC_FILE += res/app.rc
win32: LIBS += -luser32
win32: CONFIG -= embed_manifest_exe
# MAC OS X ONLY
macx: ICON = res/5sync.icns
# QT4 ONLY STUFF
isEqual(QT_MAJOR_VERSION, 4): INCLUDEPATH += ./qjson4
isEqual(QT_MAJOR_VERSION, 4): HEADERS += qjson4/QJsonArray.h \
qjson4/QJsonDocument.h \
qjson4/QJsonObject.h \
qjson4/QJsonParseError.h \
qjson4/QJsonValue.h \
qjson4/QJsonValueRef.h \
qjson4/QJsonParser.h \
qjson4/QJsonRoot.h
isEqual(QT_MAJOR_VERSION, 4): SOURCES += qjson4/QJsonArray.cpp \
qjson4/QJsonDocument.cpp \
qjson4/QJsonObject.cpp \
qjson4/QJsonParseError.cpp \
qjson4/QJsonValue.cpp \
qjson4/QJsonValueRef.cpp \
qjson4/QJsonParser.cpp
isEqual(QT_MAJOR_VERSION, 4): RESOURCES += res/tr_qt4.qrc
# QT5 ONLY STUFF
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
* Copyright (C) 2016-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 "SnapmaticPicture.h"
#include "ProfileDatabase.h"
#include "DatabaseThread.h"
#include "SavegameDialog.h"
#include "PictureDialog.h"
#include "UserInterface.h"
#include "CrewDatabase.h"
#include "SavegameData.h"
#include "IconLoader.h"
#include "AppEnv.h"
#include "config.h"
#include <QDesktopWidget>
#include <QApplication>
#include <QStringList>
#include <QTranslator>
#include <QMessageBox>
#include <QFileInfo>
#include <QSysInfo>
#include <QRawFont>
#include <QObject>
#include <QString>
#include <QDebug>
#include <QFont>
#include <QFile>
#include <QDir>
#ifdef GTA5SYNC_WIN
#include "windows.h"
#include <iostream>
#endif
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setApplicationName(GTA5SYNC_APPSTR);
a.setApplicationVersion(GTA5SYNC_APPVER);
#ifdef GTA5SYNC_WIN
#if QT_VERSION >= 0x050400
if (QSysInfo::windowsVersion() >= 0x0080)
{
// Get Windows Font
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(ncm);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0);
LOGFONTW uiFont = ncm.lfMessageFont;
QString uiFontStr(QString::fromStdWString(std::wstring(uiFont.lfFaceName)));
#ifdef GTA5SYNC_DEBUG
QMessageBox::information(a.desktop(), QApplication::tr("Font"), QApplication::tr("Selected Font: %1").arg(uiFontStr));
#endif
// Set Application Font
QFont appFont(uiFontStr, 9);
a.setFont(appFont);
}
#endif
#endif
QString pluginsDir = AppEnv::getPluginsFolder();
if (QFileInfo(pluginsDir).exists())
{
a.addLibraryPath(pluginsDir);
}
// Loading translation settings
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("Interface");
QString language = settings.value("Language","System").toString();
settings.endGroup();
// Start external translate loading
QString langpath = AppEnv::getLangFolder();
bool trsf = false;
bool svlp = false;
QTranslator EappTranslator;
if (language == "System" || language.trimmed() == "")
{
QString languageName = QLocale::system().name();
QStringList langList = languageName.split("_");
if (langList.length() >= 1)
{
if (QFile::exists(langpath + QDir::separator() + "gta5sync_" + langList.at(0) + ".qm"))
{
EappTranslator.load(langpath + QDir::separator() + "/gta5sync_" + langList.at(0) + ".qm");
QLocale::setDefault(QLocale::system());
}
}
}
else
{
QString languageName = language;
QStringList langList = languageName.split("_");
if (langList.length() >= 1)
{
if (QFile::exists(langpath + QDir::separator() + "gta5sync_" + langList.at(0) + ".qm"))
{
if (!EappTranslator.load(langpath + QDir::separator() + "gta5sync_" + langList.at(0) + ".qm"))
{
if (langList.at(0) != "en")
{
trsf = true;
}
}
else
{
QLocale::setDefault(QLocale(langList.at(0)));
svlp = true;
}
}
else
{
if (langList.at(0) != "en")
{
trsf = true;
}
}
}
}
if (trsf)
{
QString languageName = QLocale::system().name();
QStringList langList = languageName.split("_");
if (langList.length() >= 1)
{
if (QFile::exists(langpath + QDir::separator() + "gta5sync_" + langList.at(0) + ".qm"))
{
EappTranslator.load(langpath + QDir::separator() + "gta5sync_" + langList.at(0) + ".qm");
QLocale::setDefault(QLocale(langList.at(0)));
}
}
}
a.installTranslator(&EappTranslator);
#if QT_VERSION >= 0x050000
QTranslator EqtTranslator1;
if (language == "System" || language.trimmed() == "")
{
QString languageName = QLocale::system().name();
QStringList langList = languageName.split("_");
if (langList.length() >= 1)
{
if (QFile::exists(langpath + QDir::separator() + "qtbase_" + langList.at(0) + ".qm"))
{
EqtTranslator1.load(langpath + QDir::separator() + "qtbase_" + langList.at(0) + ".qm");
}
}
}
else
{
QString languageName = language;
QStringList langList = languageName.split("_");
if (langList.length() >= 1)
{
if (QFile::exists(langpath + QDir::separator() + "qtbase_" + langList.at(0) + ".qm"))
{
EqtTranslator1.load(langpath + QDir::separator() + "qtbase_" + 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() + "qtbase_" + langList.at(0) + ".qm"))
{
EqtTranslator1.load(langpath + QDir::separator() + "qtbase_" + langList.at(0) + ".qm");
}
}
}
a.installTranslator(&EqtTranslator1);
#else
QTranslator EqtTranslator;
if (language == "System" || language.trimmed() == "")
{
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");
}
}
}
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;
}
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-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 "SnapmaticPicture.h"
#include "ProfileDatabase.h"
#include "DatabaseThread.h"
#include "SavegameDialog.h"
#include "PictureDialog.h"
#include "UserInterface.h"
#include "CrewDatabase.h"
#include "SavegameData.h"
#include "IconLoader.h"
#include "AppEnv.h"
#include "config.h"
#include <QStringBuilder>
#include <QApplication>
#include <QStringList>
#include <QTranslator>
#include <QFileInfo>
#include <QSysInfo>
#include <QObject>
#include <QString>
#include <QDebug>
#include <QFont>
#include <QFile>
#ifdef GTA5SYNC_WIN
#include "windows.h"
#include <iostream>
#endif
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setApplicationName(GTA5SYNC_APPSTR);
a.setApplicationVersion(GTA5SYNC_APPVER);
#ifdef GTA5SYNC_WIN
#if QT_VERSION >= 0x050400
if (QSysInfo::windowsVersion() >= 0x0080)
{
// Get Windows Font
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(ncm);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0);
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);
#endif
// Set Application Font
QFont appFont(uiFontStr, 9);
a.setFont(appFont);
}
#endif
#endif
QString pluginsDir = AppEnv::getPluginsFolder();
if (QFileInfo(pluginsDir).exists())
{
a.addLibraryPath(pluginsDir);
}
TCInstance->initUserLanguage();
TCInstance->loadTranslation(&a);
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(crewNameFound(int, QString)), &crewDB, SLOT(setCrewName(int, QString)));
QObject::connect(&threadDB, SIGNAL(crewNameUpdated()), &picDialog, SLOT(crewNameUpdated()));
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(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();
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
* Copyright (C) 2016 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 "QJsonArray.h"
#include "QJsonValueRef.h"
#include "QJsonValue.h"
#include <QtCore/QStringList>
#if QT_VERSION < 0x050000
//------------------------------------------------------------------------------
// Name: QJsonArray
// Desc: default constructor
//------------------------------------------------------------------------------
QJsonArray::QJsonArray() {
}
//------------------------------------------------------------------------------
// Name: QJsonArray
// Desc: copy constructor
//------------------------------------------------------------------------------
QJsonArray::QJsonArray(const QJsonArray &other) : values_(other.values_) {
}
#if __cplusplus >= 201103L
//------------------------------------------------------------------------------
// Name: QJsonArray
// Desc: Creates an array initialized from args initialization list.
//------------------------------------------------------------------------------
QJsonArray::QJsonArray(std::initializer_list<QJsonValue> args) {
for(const QJsonValue &arg : args) {
values_.append(arg);
}
}
#endif
//------------------------------------------------------------------------------
// Name: ~QJsonArray
// Desc: destructor
//------------------------------------------------------------------------------
QJsonArray::~QJsonArray() {
}
//------------------------------------------------------------------------------
// Name: operator=
// Desc: assignment operator
//------------------------------------------------------------------------------
QJsonArray &QJsonArray::operator=(const QJsonArray &other) {
QJsonArray(other).swap(*this);
return *this;
}
//------------------------------------------------------------------------------
// Name: operator+=
// Desc:
//------------------------------------------------------------------------------
QJsonArray &QJsonArray::operator+=(const QJsonValue &value) {
values_.append(value);
return *this;
}
//------------------------------------------------------------------------------
// Name: operator<<
// Desc:
//------------------------------------------------------------------------------
QJsonArray &QJsonArray::operator<<(const QJsonValue &value) {
values_.append(value);
return *this;
}
//------------------------------------------------------------------------------
// Name: operator+
// Desc:
//------------------------------------------------------------------------------
QJsonArray QJsonArray::operator+(const QJsonValue &value) const {
QJsonArray arr(*this);
arr.append(value);
return arr;
}
//------------------------------------------------------------------------------
// Name: operator!=
// Desc: returns true if the compared array IS NOT equal to this
//------------------------------------------------------------------------------
bool QJsonArray::operator!=(const QJsonArray &other) const {
return values_ != other.values_;
}
//------------------------------------------------------------------------------
// Name: operator==
// Desc: returns true if the compared array IS equal to this
//------------------------------------------------------------------------------
bool QJsonArray::operator==(const QJsonArray &other) const {
return values_ == other.values_;
}
//------------------------------------------------------------------------------
// Name: begin
// Desc: returns an iterator to the first contained element
//------------------------------------------------------------------------------
QJsonArray::const_iterator QJsonArray::begin() const {
return values_.begin();
}
//------------------------------------------------------------------------------
// Name: end
// Desc: returns an iterator to one past the last contained element
//------------------------------------------------------------------------------
QJsonArray::const_iterator QJsonArray::end() const {
return values_.end();
}
//------------------------------------------------------------------------------
// Name: begin
// Desc: returns an iterator to the first contained element
//------------------------------------------------------------------------------
QJsonArray::iterator QJsonArray::begin() {
return values_.begin();
}
//------------------------------------------------------------------------------
// Name: end
// Desc: returns an iterator to one past the last contained element
//------------------------------------------------------------------------------
QJsonArray::iterator QJsonArray::end() {
return values_.end();
}
//------------------------------------------------------------------------------
// Name: constBegin
// Desc: returns an iterator to the first contained element
//------------------------------------------------------------------------------
QJsonArray::const_iterator QJsonArray::constBegin() const {
return begin();
}
//------------------------------------------------------------------------------
// Name: constEnd
// Desc: returns an iterator to one past the last contained element
//------------------------------------------------------------------------------
QJsonArray::const_iterator QJsonArray::constEnd() const {
return end();
}
//------------------------------------------------------------------------------
// Name: first
// Desc: returns the first element by value
//------------------------------------------------------------------------------
QJsonValue QJsonArray::first() const {
Q_ASSERT(!empty());
return values_.first();
}
//------------------------------------------------------------------------------
// Name: last
// Desc: returns the last element by value
//------------------------------------------------------------------------------
QJsonValue QJsonArray::last() const {
Q_ASSERT(!empty());
return values_.last();
}
//------------------------------------------------------------------------------
// Name: operator[]
//------------------------------------------------------------------------------
QJsonValueRef QJsonArray::operator[](int i) {
return QJsonValueRef(this, i);
}
//------------------------------------------------------------------------------
// Name: operator[]
//------------------------------------------------------------------------------
QJsonValue QJsonArray::operator[](int i) const {
return values_[i];
}
//------------------------------------------------------------------------------
// Name: at
//------------------------------------------------------------------------------
QJsonValue QJsonArray::at(int i) const {
return values_.at(i);
}
//------------------------------------------------------------------------------
// Name: size
//------------------------------------------------------------------------------
int QJsonArray::size() const {
return values_.size();
}
//------------------------------------------------------------------------------
// Name: count
//------------------------------------------------------------------------------
int QJsonArray::count() const {
return size();
}
//------------------------------------------------------------------------------
// Name: empty
//------------------------------------------------------------------------------
bool QJsonArray::empty() const {
return values_.empty();
}
//------------------------------------------------------------------------------
// Name: isEmpty
//------------------------------------------------------------------------------
bool QJsonArray::isEmpty() const {
return empty();
}
//------------------------------------------------------------------------------
// Name: pop_back
//------------------------------------------------------------------------------
void QJsonArray::pop_back() {
values_.pop_back();
}
//------------------------------------------------------------------------------
// Name: pop_front
//------------------------------------------------------------------------------
void QJsonArray::pop_front() {
values_.pop_front();
}
//------------------------------------------------------------------------------
// Name: push_back
//------------------------------------------------------------------------------
void QJsonArray::push_back(const QJsonValue &value) {
values_.push_back(value);
}
//------------------------------------------------------------------------------
// Name: push_front
//------------------------------------------------------------------------------
void QJsonArray::push_front(const QJsonValue &value) {
values_.push_front(value);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonArray::append(const QJsonValue &value) {
values_.append(value);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
bool QJsonArray::contains(const QJsonValue &value) const {
return values_.contains(value);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonArray::iterator QJsonArray::erase(iterator it) {
return values_.erase(it);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonArray::insert(int i, const QJsonValue &value) {
values_.insert(i, value);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonArray::iterator QJsonArray::insert(iterator before, const QJsonValue &value) {
return values_.insert(before, value);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonArray::prepend(const QJsonValue &value) {
values_.prepend(value);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonArray::removeAt(int i) {
values_.removeAt(i);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonArray::removeFirst() {
values_.removeFirst();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonArray::removeLast() {
values_.removeLast();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonArray::replace(int i, const QJsonValue &value) {
values_.replace(i, value);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonValue QJsonArray::takeAt(int i) {
return values_.takeAt(i);
}
//------------------------------------------------------------------------------
// Name: toVariantList
//------------------------------------------------------------------------------
QVariantList QJsonArray::toVariantList() const {
QVariantList a;
Q_FOREACH(const QJsonValue &v, *this) {
a.push_back(v.toVariant());
}
return a;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonArray QJsonArray::fromStringList(const QStringList &list) {
QJsonArray a;
Q_FOREACH(const QString &s, list) {
a.push_back(QJsonValue(s));
}
return a;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonArray QJsonArray::fromVariantList(const QVariantList &list) {
QJsonArray a;
Q_FOREACH(const QVariant &v, list) {
a.push_back(QJsonValue::fromVariant(v));
}
return a;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonRoot *QJsonArray::clone() const {
return new QJsonArray(*this);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
const QJsonObject *QJsonArray::toObject() const {
return 0;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject *QJsonArray::toObject() {
return 0;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonArray *QJsonArray::toArray() {
return this;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
const QJsonArray *QJsonArray::toArray() const {
return this;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonArray::swap(QJsonArray &other) {
qSwap(values_, other.values_);
}
#endif
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 "QJsonArray.h"
#include "QJsonValueRef.h"
#include "QJsonValue.h"
#include <QtCore/QStringList>
#if QT_VERSION < 0x050000
//------------------------------------------------------------------------------
// Name: QJsonArray
// Desc: default constructor
//------------------------------------------------------------------------------
QJsonArray::QJsonArray() {
}
//------------------------------------------------------------------------------
// Name: QJsonArray
// Desc: copy constructor
//------------------------------------------------------------------------------
QJsonArray::QJsonArray(const QJsonArray &other) : values_(other.values_) {
}
#if __cplusplus >= 201103L
//------------------------------------------------------------------------------
// Name: QJsonArray
// Desc: Creates an array initialized from args initialization list.
//------------------------------------------------------------------------------
QJsonArray::QJsonArray(std::initializer_list<QJsonValue> args) {
for(const QJsonValue &arg : args) {
values_.append(arg);
}
}
#endif
//------------------------------------------------------------------------------
// Name: ~QJsonArray
// Desc: destructor
//------------------------------------------------------------------------------
QJsonArray::~QJsonArray() {
}
//------------------------------------------------------------------------------
// Name: operator=
// Desc: assignment operator
//------------------------------------------------------------------------------
QJsonArray &QJsonArray::operator=(const QJsonArray &other) {
QJsonArray(other).swap(*this);
return *this;
}
//------------------------------------------------------------------------------
// Name: operator+=
// Desc:
//------------------------------------------------------------------------------
QJsonArray &QJsonArray::operator+=(const QJsonValue &value) {
values_.append(value);
return *this;
}
//------------------------------------------------------------------------------
// Name: operator<<
// Desc:
//------------------------------------------------------------------------------
QJsonArray &QJsonArray::operator<<(const QJsonValue &value) {
values_.append(value);
return *this;
}
//------------------------------------------------------------------------------
// Name: operator+
// Desc:
//------------------------------------------------------------------------------
QJsonArray QJsonArray::operator+(const QJsonValue &value) const {
QJsonArray arr(*this);
arr.append(value);
return arr;
}
//------------------------------------------------------------------------------
// Name: operator!=
// Desc: returns true if the compared array IS NOT equal to this
//------------------------------------------------------------------------------
bool QJsonArray::operator!=(const QJsonArray &other) const {
return values_ != other.values_;
}
//------------------------------------------------------------------------------
// Name: operator==
// Desc: returns true if the compared array IS equal to this
//------------------------------------------------------------------------------
bool QJsonArray::operator==(const QJsonArray &other) const {
return values_ == other.values_;
}
//------------------------------------------------------------------------------
// Name: begin
// Desc: returns an iterator to the first contained element
//------------------------------------------------------------------------------
QJsonArray::const_iterator QJsonArray::begin() const {
return values_.begin();
}
//------------------------------------------------------------------------------
// Name: end
// Desc: returns an iterator to one past the last contained element
//------------------------------------------------------------------------------
QJsonArray::const_iterator QJsonArray::end() const {
return values_.end();
}
//------------------------------------------------------------------------------
// Name: begin
// Desc: returns an iterator to the first contained element
//------------------------------------------------------------------------------
QJsonArray::iterator QJsonArray::begin() {
return values_.begin();
}
//------------------------------------------------------------------------------
// Name: end
// Desc: returns an iterator to one past the last contained element
//------------------------------------------------------------------------------
QJsonArray::iterator QJsonArray::end() {
return values_.end();
}
//------------------------------------------------------------------------------
// Name: constBegin
// Desc: returns an iterator to the first contained element
//------------------------------------------------------------------------------
QJsonArray::const_iterator QJsonArray::constBegin() const {
return begin();
}
//------------------------------------------------------------------------------
// Name: constEnd
// Desc: returns an iterator to one past the last contained element
//------------------------------------------------------------------------------
QJsonArray::const_iterator QJsonArray::constEnd() const {
return end();
}
//------------------------------------------------------------------------------
// Name: first
// Desc: returns the first element by value
//------------------------------------------------------------------------------
QJsonValue QJsonArray::first() const {
Q_ASSERT(!empty());
return values_.first();
}
//------------------------------------------------------------------------------
// Name: last
// Desc: returns the last element by value
//------------------------------------------------------------------------------
QJsonValue QJsonArray::last() const {
Q_ASSERT(!empty());
return values_.last();
}
//------------------------------------------------------------------------------
// Name: operator[]
//------------------------------------------------------------------------------
QJsonValueRef QJsonArray::operator[](int i) {
return QJsonValueRef(this, i);
}
//------------------------------------------------------------------------------
// Name: operator[]
//------------------------------------------------------------------------------
QJsonValue QJsonArray::operator[](int i) const {
return values_[i];
}
//------------------------------------------------------------------------------
// Name: at
//------------------------------------------------------------------------------
QJsonValue QJsonArray::at(int i) const {
return values_.at(i);
}
//------------------------------------------------------------------------------
// Name: size
//------------------------------------------------------------------------------
int QJsonArray::size() const {
return values_.size();
}
//------------------------------------------------------------------------------
// Name: count
//------------------------------------------------------------------------------
int QJsonArray::count() const {
return size();
}
//------------------------------------------------------------------------------
// Name: empty
//------------------------------------------------------------------------------
bool QJsonArray::empty() const {
return values_.empty();
}
//------------------------------------------------------------------------------
// Name: isEmpty
//------------------------------------------------------------------------------
bool QJsonArray::isEmpty() const {
return empty();
}
//------------------------------------------------------------------------------
// Name: pop_back
//------------------------------------------------------------------------------
void QJsonArray::pop_back() {
values_.pop_back();
}
//------------------------------------------------------------------------------
// Name: pop_front
//------------------------------------------------------------------------------
void QJsonArray::pop_front() {
values_.pop_front();
}
//------------------------------------------------------------------------------
// Name: push_back
//------------------------------------------------------------------------------
void QJsonArray::push_back(const QJsonValue &value) {
values_.push_back(value);
}
//------------------------------------------------------------------------------
// Name: push_front
//------------------------------------------------------------------------------
void QJsonArray::push_front(const QJsonValue &value) {
values_.push_front(value);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonArray::append(const QJsonValue &value) {
values_.append(value);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
bool QJsonArray::contains(const QJsonValue &value) const {
return values_.contains(value);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonArray::iterator QJsonArray::erase(iterator it) {
return values_.erase(it);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonArray::insert(int i, const QJsonValue &value) {
values_.insert(i, value);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonArray::iterator QJsonArray::insert(iterator before, const QJsonValue &value) {
return values_.insert(before, value);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonArray::prepend(const QJsonValue &value) {
values_.prepend(value);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonArray::removeAt(int i) {
values_.removeAt(i);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonArray::removeFirst() {
values_.removeFirst();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonArray::removeLast() {
values_.removeLast();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonArray::replace(int i, const QJsonValue &value) {
values_.replace(i, value);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonValue QJsonArray::takeAt(int i) {
return values_.takeAt(i);
}
//------------------------------------------------------------------------------
// Name: toVariantList
//------------------------------------------------------------------------------
QVariantList QJsonArray::toVariantList() const {
QVariantList a;
Q_FOREACH(const QJsonValue &v, *this) {
a.push_back(v.toVariant());
}
return a;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonArray QJsonArray::fromStringList(const QStringList &list) {
QJsonArray a;
Q_FOREACH(const QString &s, list) {
a.push_back(QJsonValue(s));
}
return a;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonArray QJsonArray::fromVariantList(const QVariantList &list) {
QJsonArray a;
Q_FOREACH(const QVariant &v, list) {
a.push_back(QJsonValue::fromVariant(v));
}
return a;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonRoot *QJsonArray::clone() const {
return new QJsonArray(*this);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
const QJsonObject *QJsonArray::toObject() const {
return 0;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject *QJsonArray::toObject() {
return 0;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonArray *QJsonArray::toArray() {
return this;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
const QJsonArray *QJsonArray::toArray() const {
return this;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonArray::swap(QJsonArray &other) {
qSwap(values_, other.values_);
}
#endif

View file

@ -1,139 +1,139 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 QJSON_ARRAY_H_
#define QJSON_ARRAY_H_
#include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000
#include <QtCore/QJsonArray>
#else
#include "QJsonRoot.h"
#include <QtCore/QList>
#include <QtCore/QVariantList>
class QJsonValue;
class QJsonValueRef;
class QJsonArray : public QJsonRoot {
friend class QJsonDocument;
friend class QJsonValue;
friend class QJsonValueRef;
friend class QJsonParser;
public:
// TODO(eteran): manually implement the array, for now we use QList
// but the real thing has a custom implementation
// I guess for the purposes of less interdependancies?
// maybe so it's easier to forward declare the iterators?
typedef QList<QJsonValue>::const_iterator const_iterator;
typedef QList<QJsonValue>::iterator iterator;
typedef const_iterator ConstIterator;
typedef iterator Iterator;
typedef QList<QJsonValue>::const_pointer const_pointer;
typedef QList<QJsonValue>::const_reference const_reference;
typedef QList<QJsonValue>::difference_type difference_type;
typedef QList<QJsonValue>::pointer pointer;
typedef QList<QJsonValue>::reference reference;
typedef QList<QJsonValue>::size_type size_type;
typedef QList<QJsonValue>::value_type value_type;
public:
QJsonArray();
QJsonArray(const QJsonArray &other);
#if __cplusplus >= 201103L
QJsonArray(std::initializer_list<QJsonValue> args);
#endif
~QJsonArray();
public:
QJsonArray &operator=(const QJsonArray &other);
public:
bool operator!=(const QJsonArray &other) const;
bool operator==(const QJsonArray &other) const;
QJsonArray operator+(const QJsonValue &value) const;
QJsonArray &operator+=(const QJsonValue &value);
QJsonArray &operator<<(const QJsonValue &value);
public:
const_iterator begin() const;
const_iterator end() const;
iterator begin();
iterator end();
const_iterator constBegin() const;
const_iterator constEnd() const;
public:
QJsonValueRef operator[](int i);
QJsonValue operator[](int i) const;
QJsonValue at(int i) const;
QJsonValue first() const;
QJsonValue last() const;
public:
int size() const;
int count() const;
bool empty() const;
bool isEmpty() const;
public:
void pop_back();
void pop_front();
void push_back(const QJsonValue &value);
void push_front(const QJsonValue &value);
public:
void append(const QJsonValue &value);
bool contains(const QJsonValue &value) const;
iterator erase(iterator it);
void insert(int i, const QJsonValue &value);
iterator insert(iterator before, const QJsonValue &value);
void prepend(const QJsonValue &value);
void removeAt(int i);
void removeFirst();
void removeLast();
void replace(int i, const QJsonValue &value);
QJsonValue takeAt(int i);
public:
QVariantList toVariantList() const;
public:
static QJsonArray fromStringList(const QStringList &list);
static QJsonArray fromVariantList(const QVariantList &list);
private:
virtual QJsonRoot *clone() const;
virtual QJsonArray *toArray();
virtual QJsonObject *toObject();
virtual const QJsonArray *toArray() const;
virtual const QJsonObject *toObject() const;
private:
void swap(QJsonArray &other);
private:
QList<QJsonValue> values_;
};
#endif
#endif
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 QJSON_ARRAY_H_
#define QJSON_ARRAY_H_
#include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000
#include <QtCore/QJsonArray>
#else
#include "QJsonRoot.h"
#include <QtCore/QList>
#include <QtCore/QVariantList>
class QJsonValue;
class QJsonValueRef;
class QJsonArray : public QJsonRoot {
friend class QJsonDocument;
friend class QJsonValue;
friend class QJsonValueRef;
friend class QJsonParser;
public:
// TODO(eteran): manually implement the array, for now we use QList
// but the real thing has a custom implementation
// I guess for the purposes of less interdependancies?
// maybe so it's easier to forward declare the iterators?
typedef QList<QJsonValue>::const_iterator const_iterator;
typedef QList<QJsonValue>::iterator iterator;
typedef const_iterator ConstIterator;
typedef iterator Iterator;
typedef QList<QJsonValue>::const_pointer const_pointer;
typedef QList<QJsonValue>::const_reference const_reference;
typedef QList<QJsonValue>::difference_type difference_type;
typedef QList<QJsonValue>::pointer pointer;
typedef QList<QJsonValue>::reference reference;
typedef QList<QJsonValue>::size_type size_type;
typedef QList<QJsonValue>::value_type value_type;
public:
QJsonArray();
QJsonArray(const QJsonArray &other);
#if __cplusplus >= 201103L
QJsonArray(std::initializer_list<QJsonValue> args);
#endif
~QJsonArray();
public:
QJsonArray &operator=(const QJsonArray &other);
public:
bool operator!=(const QJsonArray &other) const;
bool operator==(const QJsonArray &other) const;
QJsonArray operator+(const QJsonValue &value) const;
QJsonArray &operator+=(const QJsonValue &value);
QJsonArray &operator<<(const QJsonValue &value);
public:
const_iterator begin() const;
const_iterator end() const;
iterator begin();
iterator end();
const_iterator constBegin() const;
const_iterator constEnd() const;
public:
QJsonValueRef operator[](int i);
QJsonValue operator[](int i) const;
QJsonValue at(int i) const;
QJsonValue first() const;
QJsonValue last() const;
public:
int size() const;
int count() const;
bool empty() const;
bool isEmpty() const;
public:
void pop_back();
void pop_front();
void push_back(const QJsonValue &value);
void push_front(const QJsonValue &value);
public:
void append(const QJsonValue &value);
bool contains(const QJsonValue &value) const;
iterator erase(iterator it);
void insert(int i, const QJsonValue &value);
iterator insert(iterator before, const QJsonValue &value);
void prepend(const QJsonValue &value);
void removeAt(int i);
void removeFirst();
void removeLast();
void replace(int i, const QJsonValue &value);
QJsonValue takeAt(int i);
public:
QVariantList toVariantList() const;
public:
static QJsonArray fromStringList(const QStringList &list);
static QJsonArray fromVariantList(const QVariantList &list);
private:
virtual QJsonRoot *clone() const;
virtual QJsonArray *toArray();
virtual QJsonObject *toObject();
virtual const QJsonArray *toArray() const;
virtual const QJsonObject *toObject() const;
private:
void swap(QJsonArray &other);
private:
QList<QJsonValue> values_;
};
#endif
#endif

View file

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

View file

@ -1,417 +1,417 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 "QJsonDocument.h"
#include "QJsonObject.h"
#include "QJsonArray.h"
#include "QJsonParser.h"
#include <QtCore/QStringList>
#include <QtCore/QByteArray>
#include <QtCore/QTextStream>
#include <QtCore/QTextCodec>
#include <QtCore/QtCore>
#if QT_VERSION < 0x050000
//------------------------------------------------------------------------------
// Name: QJsonDocument
//------------------------------------------------------------------------------
QJsonDocument::QJsonDocument() : root_(0) {
}
//------------------------------------------------------------------------------
// Name: QJsonDocument
//------------------------------------------------------------------------------
QJsonDocument::QJsonDocument(const QJsonObject &object) : root_(0) {
setObject(object);
}
//------------------------------------------------------------------------------
// Name: QJsonDocument
//------------------------------------------------------------------------------
QJsonDocument::QJsonDocument(const QJsonArray &array) : root_(0) {
setArray(array);
}
//------------------------------------------------------------------------------
// Name: QJsonDocument
//------------------------------------------------------------------------------
QJsonDocument::QJsonDocument(const QJsonDocument &other) : root_(0) {
if(other.root_) {
root_ = other.root_->clone();
}
}
//------------------------------------------------------------------------------
// Name: ~QJsonDocument
//------------------------------------------------------------------------------
QJsonDocument::~QJsonDocument() {
delete root_;
}
//------------------------------------------------------------------------------
// Name: operator=
//------------------------------------------------------------------------------
QJsonDocument &QJsonDocument::operator=(const QJsonDocument &other) {
QJsonDocument(other).swap(*this);
return *this;
}
//------------------------------------------------------------------------------
// Name: operator!=
//------------------------------------------------------------------------------
bool QJsonDocument::operator!=(const QJsonDocument &other) const {
return !(*this == other);
}
//------------------------------------------------------------------------------
// Name: operator==
//------------------------------------------------------------------------------
bool QJsonDocument::operator==(const QJsonDocument &other) const {
if(isArray() && other.isArray()) {
return array() == other.array();
}
if(isObject() && other.isObject()) {
return object() == other.object();
}
if(isEmpty() && other.isEmpty()) {
return true;
}
if(isNull() && other.isNull()) {
return true;
}
return false;
}
//------------------------------------------------------------------------------
// Name: isArray
//------------------------------------------------------------------------------
bool QJsonDocument::isArray() const {
return root_ && root_->toArray();
}
//------------------------------------------------------------------------------
// Name: isEmpty
//------------------------------------------------------------------------------
bool QJsonDocument::isEmpty() const {
// TODO(eteran): figure out the rules here that Qt5 uses
// it *looks* like they define empty as being NULL
// which is obviously different than this
return !root_;
}
//------------------------------------------------------------------------------
// Name: isNull
//------------------------------------------------------------------------------
bool QJsonDocument::isNull() const {
return !root_;
}
//------------------------------------------------------------------------------
// Name: isObject
//------------------------------------------------------------------------------
bool QJsonDocument::isObject() const {
return root_ && root_->toObject();
}
//------------------------------------------------------------------------------
// Name: setArray
//------------------------------------------------------------------------------
void QJsonDocument::setArray(const QJsonArray &array) {
setRoot(array);
}
//------------------------------------------------------------------------------
// Name: setObject
//------------------------------------------------------------------------------
void QJsonDocument::setObject(const QJsonObject &object) {
setRoot(object);
}
//------------------------------------------------------------------------------
// Name: setRoot
//------------------------------------------------------------------------------
void QJsonDocument::setRoot(const QJsonRoot &root) {
delete root_;
root_ = root.clone();
}
//------------------------------------------------------------------------------
// Name: toBinaryData
//------------------------------------------------------------------------------
QByteArray QJsonDocument::toBinaryData() const {
QByteArray r;
// TODO(eteran): implement this
return r;
}
//------------------------------------------------------------------------------
// Name: escapeString
//------------------------------------------------------------------------------
QString QJsonDocument::escapeString(const QString &s) const {
QString r;
Q_FOREACH(QChar ch, s) {
switch(ch.toLatin1()) {
case '\"': r.append("\\\""); break;
case '\\': r.append("\\\\"); break;
#if 0
case '/': r.append("\\/"); break;
#endif
case '\b': r.append("\\b"); break;
case '\f': r.append("\\f"); break;
case '\n': r.append("\\n"); break;
case '\r': r.append("\\r"); break;
case '\t': r.append("\\t"); break;
default:
r += ch;
break;
}
}
return r;
}
//------------------------------------------------------------------------------
// Name: toJson
//------------------------------------------------------------------------------
QString QJsonDocument::toJson(const QJsonValue &v, JsonFormat format) const {
QString b;
QTextStream ss(&b, QIODevice::WriteOnly | QIODevice::Text);
switch(v.type()) {
case QJsonValue::Null:
ss << "null";
break;
case QJsonValue::Bool:
ss << (v.toBool() ? "true" : "false");
break;
case QJsonValue::Double:
{
double d = v.toDouble ();
if (qIsFinite(d)) {
// +2 to format to ensure the expected precision
ss << QByteArray::number(d, 'g', 15 + 2); // ::digits10 is 15
} else {
ss << "null"; // +INF || -INF || NaN (see RFC4627#section2.4)
}
}
break;
case QJsonValue::String:
ss << '"' << escapeString(v.toString()) << '"';
break;
case QJsonValue::Array:
{
const QJsonArray a = v.toArray();
ss << "[";
if(!a.empty()) {
QJsonArray::const_iterator it = a.begin();
QJsonArray::const_iterator e = a.end();
ss << toJson(*it++, format);
for(;it != e; ++it) {
ss << ',';
ss << toJson(*it, format);
}
}
ss << "]";
}
break;
case QJsonValue::Object:
{
const QJsonObject o = v.toObject();
ss << "{";
if(!o.empty()) {
QJsonObject::const_iterator it = o.begin();
QJsonObject::const_iterator e = o.end();
ss << '"' << escapeString(it.key()) << "\": " << toJson(it.value(), format);
++it;
for(;it != e; ++it) {
ss << ',';
ss << '"' << escapeString(it.key()) << "\": " << toJson(it.value(), format);
}
}
ss << "}";
}
break;
case QJsonValue::Undefined:
Q_ASSERT(0);
break;
}
return b;
}
//------------------------------------------------------------------------------
// Name: toJson
//------------------------------------------------------------------------------
QByteArray QJsonDocument::toJson(JsonFormat format) const {
Q_UNUSED(format);
if(isArray()) {
QString s = toJson(array(), format);
return s.toUtf8();
}
if(isObject()) {
QString s = toJson(object(), format);
return s.toUtf8();
}
return QByteArray();
}
//------------------------------------------------------------------------------
// Name: toVariant
//------------------------------------------------------------------------------
QVariant QJsonDocument::toVariant() const {
if(!isEmpty()) {
if(QJsonObject *const object = root_->toObject()) {
return object->toVariantMap();
}
if(QJsonArray *const array = root_->toArray()) {
return array->toVariantList();
}
}
return QVariant();
}
//------------------------------------------------------------------------------
// Name: array
//------------------------------------------------------------------------------
QJsonArray QJsonDocument::array() const {
if(!isEmpty()) {
if(QJsonArray *const array = root_->toArray()) {
return *array;
}
}
return QJsonArray();
}
//------------------------------------------------------------------------------
// Name: object
//------------------------------------------------------------------------------
QJsonObject QJsonDocument::object() const {
if(!isEmpty()) {
if(QJsonObject *const object = root_->toObject()) {
return *object;
}
}
return QJsonObject();
}
//------------------------------------------------------------------------------
// Name: rawData
//------------------------------------------------------------------------------
const char *QJsonDocument::rawData(int *size) const {
Q_UNUSED(size);
// TODO(eteran): implement this
return 0;
}
//------------------------------------------------------------------------------
// Name: fromBinaryData
//------------------------------------------------------------------------------
QJsonDocument QJsonDocument::fromBinaryData(const QByteArray &data, DataValidation validation) {
Q_UNUSED(data);
Q_UNUSED(validation);
QJsonDocument doc;
// TODO(eteran): implement this
return doc;
}
//------------------------------------------------------------------------------
// Name: fromJson
//------------------------------------------------------------------------------
QJsonDocument QJsonDocument::fromJson(const QByteArray &json, QJsonParseError *error) {
QJsonDocument doc;
const char *const begin = json.constData();
const char *const end = begin + json.size();
QJsonParser parser(begin, end);
doc.root_ = parser.parse();
if(error) {
*error = parser.state();
}
return doc;
}
//------------------------------------------------------------------------------
// Name: fromRawData
//------------------------------------------------------------------------------
QJsonDocument QJsonDocument::fromRawData(const char *data, int size, DataValidation validation) {
// data has to be aligned to a 4 byte boundary.
Q_ASSERT(!(reinterpret_cast<quintptr>(data) % 3));
return fromBinaryData(QByteArray::fromRawData(data, size), validation);
}
//------------------------------------------------------------------------------
// Name: fromVariant
//------------------------------------------------------------------------------
QJsonDocument QJsonDocument::fromVariant(const QVariant &variant) {
QJsonDocument doc;
if (variant.type() == QVariant::Map) {
doc.setObject(QJsonObject::fromVariantMap(variant.toMap()));
} else if (variant.type() == QVariant::Hash) {
doc.setObject(QJsonObject::fromVariantHash(variant.toHash()));
} else if (variant.type() == QVariant::List) {
doc.setArray(QJsonArray::fromVariantList(variant.toList()));
} else if (variant.type() == QVariant::StringList) {
doc.setArray(QJsonArray::fromStringList(variant.toStringList()));
}
return doc;
}
//------------------------------------------------------------------------------
// Name: swap
//------------------------------------------------------------------------------
void QJsonDocument::swap(QJsonDocument &other) {
qSwap(root_, other.root_);
}
#endif
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 "QJsonDocument.h"
#include "QJsonObject.h"
#include "QJsonArray.h"
#include "QJsonParser.h"
#include <QtCore/QStringList>
#include <QtCore/QByteArray>
#include <QtCore/QTextStream>
#include <QtCore/QTextCodec>
#include <QtCore/QtCore>
#if QT_VERSION < 0x050000
//------------------------------------------------------------------------------
// Name: QJsonDocument
//------------------------------------------------------------------------------
QJsonDocument::QJsonDocument() : root_(0) {
}
//------------------------------------------------------------------------------
// Name: QJsonDocument
//------------------------------------------------------------------------------
QJsonDocument::QJsonDocument(const QJsonObject &object) : root_(0) {
setObject(object);
}
//------------------------------------------------------------------------------
// Name: QJsonDocument
//------------------------------------------------------------------------------
QJsonDocument::QJsonDocument(const QJsonArray &array) : root_(0) {
setArray(array);
}
//------------------------------------------------------------------------------
// Name: QJsonDocument
//------------------------------------------------------------------------------
QJsonDocument::QJsonDocument(const QJsonDocument &other) : root_(0) {
if(other.root_) {
root_ = other.root_->clone();
}
}
//------------------------------------------------------------------------------
// Name: ~QJsonDocument
//------------------------------------------------------------------------------
QJsonDocument::~QJsonDocument() {
delete root_;
}
//------------------------------------------------------------------------------
// Name: operator=
//------------------------------------------------------------------------------
QJsonDocument &QJsonDocument::operator=(const QJsonDocument &other) {
QJsonDocument(other).swap(*this);
return *this;
}
//------------------------------------------------------------------------------
// Name: operator!=
//------------------------------------------------------------------------------
bool QJsonDocument::operator!=(const QJsonDocument &other) const {
return !(*this == other);
}
//------------------------------------------------------------------------------
// Name: operator==
//------------------------------------------------------------------------------
bool QJsonDocument::operator==(const QJsonDocument &other) const {
if(isArray() && other.isArray()) {
return array() == other.array();
}
if(isObject() && other.isObject()) {
return object() == other.object();
}
if(isEmpty() && other.isEmpty()) {
return true;
}
if(isNull() && other.isNull()) {
return true;
}
return false;
}
//------------------------------------------------------------------------------
// Name: isArray
//------------------------------------------------------------------------------
bool QJsonDocument::isArray() const {
return root_ && root_->toArray();
}
//------------------------------------------------------------------------------
// Name: isEmpty
//------------------------------------------------------------------------------
bool QJsonDocument::isEmpty() const {
// TODO(eteran): figure out the rules here that Qt5 uses
// it *looks* like they define empty as being NULL
// which is obviously different than this
return !root_;
}
//------------------------------------------------------------------------------
// Name: isNull
//------------------------------------------------------------------------------
bool QJsonDocument::isNull() const {
return !root_;
}
//------------------------------------------------------------------------------
// Name: isObject
//------------------------------------------------------------------------------
bool QJsonDocument::isObject() const {
return root_ && root_->toObject();
}
//------------------------------------------------------------------------------
// Name: setArray
//------------------------------------------------------------------------------
void QJsonDocument::setArray(const QJsonArray &array) {
setRoot(array);
}
//------------------------------------------------------------------------------
// Name: setObject
//------------------------------------------------------------------------------
void QJsonDocument::setObject(const QJsonObject &object) {
setRoot(object);
}
//------------------------------------------------------------------------------
// Name: setRoot
//------------------------------------------------------------------------------
void QJsonDocument::setRoot(const QJsonRoot &root) {
delete root_;
root_ = root.clone();
}
//------------------------------------------------------------------------------
// Name: toBinaryData
//------------------------------------------------------------------------------
QByteArray QJsonDocument::toBinaryData() const {
QByteArray r;
// TODO(eteran): implement this
return r;
}
//------------------------------------------------------------------------------
// Name: escapeString
//------------------------------------------------------------------------------
QString QJsonDocument::escapeString(const QString &s) const {
QString r;
Q_FOREACH(QChar ch, s) {
switch(ch.toLatin1()) {
case '\"': r.append("\\\""); break;
case '\\': r.append("\\\\"); break;
#if 0
case '/': r.append("\\/"); break;
#endif
case '\b': r.append("\\b"); break;
case '\f': r.append("\\f"); break;
case '\n': r.append("\\n"); break;
case '\r': r.append("\\r"); break;
case '\t': r.append("\\t"); break;
default:
r += ch;
break;
}
}
return r;
}
//------------------------------------------------------------------------------
// Name: toJson
//------------------------------------------------------------------------------
QString QJsonDocument::toJson(const QJsonValue &v, JsonFormat format) const {
QString b;
QTextStream ss(&b, QIODevice::WriteOnly | QIODevice::Text);
switch(v.type()) {
case QJsonValue::Null:
ss << "null";
break;
case QJsonValue::Bool:
ss << (v.toBool() ? "true" : "false");
break;
case QJsonValue::Double:
{
double d = v.toDouble ();
if (qIsFinite(d)) {
// +2 to format to ensure the expected precision
ss << QByteArray::number(d, 'g', 15 + 2); // ::digits10 is 15
} else {
ss << "null"; // +INF || -INF || NaN (see RFC4627#section2.4)
}
}
break;
case QJsonValue::String:
ss << '"' << escapeString(v.toString()) << '"';
break;
case QJsonValue::Array:
{
const QJsonArray a = v.toArray();
ss << "[";
if(!a.empty()) {
QJsonArray::const_iterator it = a.begin();
QJsonArray::const_iterator e = a.end();
ss << toJson(*it++, format);
for(;it != e; ++it) {
ss << ',';
ss << toJson(*it, format);
}
}
ss << "]";
}
break;
case QJsonValue::Object:
{
const QJsonObject o = v.toObject();
ss << "{";
if(!o.empty()) {
QJsonObject::const_iterator it = o.begin();
QJsonObject::const_iterator e = o.end();
ss << '"' << escapeString(it.key()) << "\": " << toJson(it.value(), format);
++it;
for(;it != e; ++it) {
ss << ',';
ss << '"' << escapeString(it.key()) << "\": " << toJson(it.value(), format);
}
}
ss << "}";
}
break;
case QJsonValue::Undefined:
Q_ASSERT(0);
break;
}
return b;
}
//------------------------------------------------------------------------------
// Name: toJson
//------------------------------------------------------------------------------
QByteArray QJsonDocument::toJson(JsonFormat format) const {
Q_UNUSED(format);
if(isArray()) {
QString s = toJson(array(), format);
return s.toUtf8();
}
if(isObject()) {
QString s = toJson(object(), format);
return s.toUtf8();
}
return QByteArray();
}
//------------------------------------------------------------------------------
// Name: toVariant
//------------------------------------------------------------------------------
QVariant QJsonDocument::toVariant() const {
if(!isEmpty()) {
if(QJsonObject *const object = root_->toObject()) {
return object->toVariantMap();
}
if(QJsonArray *const array = root_->toArray()) {
return array->toVariantList();
}
}
return QVariant();
}
//------------------------------------------------------------------------------
// Name: array
//------------------------------------------------------------------------------
QJsonArray QJsonDocument::array() const {
if(!isEmpty()) {
if(QJsonArray *const array = root_->toArray()) {
return *array;
}
}
return QJsonArray();
}
//------------------------------------------------------------------------------
// Name: object
//------------------------------------------------------------------------------
QJsonObject QJsonDocument::object() const {
if(!isEmpty()) {
if(QJsonObject *const object = root_->toObject()) {
return *object;
}
}
return QJsonObject();
}
//------------------------------------------------------------------------------
// Name: rawData
//------------------------------------------------------------------------------
const char *QJsonDocument::rawData(int *size) const {
Q_UNUSED(size);
// TODO(eteran): implement this
return 0;
}
//------------------------------------------------------------------------------
// Name: fromBinaryData
//------------------------------------------------------------------------------
QJsonDocument QJsonDocument::fromBinaryData(const QByteArray &data, DataValidation validation) {
Q_UNUSED(data);
Q_UNUSED(validation);
QJsonDocument doc;
// TODO(eteran): implement this
return doc;
}
//------------------------------------------------------------------------------
// Name: fromJson
//------------------------------------------------------------------------------
QJsonDocument QJsonDocument::fromJson(const QByteArray &json, QJsonParseError *error) {
QJsonDocument doc;
const char *const begin = json.constData();
const char *const end = begin + json.size();
QJsonParser parser(begin, end);
doc.root_ = parser.parse();
if(error) {
*error = parser.state();
}
return doc;
}
//------------------------------------------------------------------------------
// Name: fromRawData
//------------------------------------------------------------------------------
QJsonDocument QJsonDocument::fromRawData(const char *data, int size, DataValidation validation) {
// data has to be aligned to a 4 byte boundary.
Q_ASSERT(!(reinterpret_cast<quintptr>(data) % 3));
return fromBinaryData(QByteArray::fromRawData(data, size), validation);
}
//------------------------------------------------------------------------------
// Name: fromVariant
//------------------------------------------------------------------------------
QJsonDocument QJsonDocument::fromVariant(const QVariant &variant) {
QJsonDocument doc;
if (variant.type() == QVariant::Map) {
doc.setObject(QJsonObject::fromVariantMap(variant.toMap()));
} else if (variant.type() == QVariant::Hash) {
doc.setObject(QJsonObject::fromVariantHash(variant.toHash()));
} else if (variant.type() == QVariant::List) {
doc.setArray(QJsonArray::fromVariantList(variant.toList()));
} else if (variant.type() == QVariant::StringList) {
doc.setArray(QJsonArray::fromStringList(variant.toStringList()));
}
return doc;
}
//------------------------------------------------------------------------------
// Name: swap
//------------------------------------------------------------------------------
void QJsonDocument::swap(QJsonDocument &other) {
qSwap(root_, other.root_);
}
#endif

View file

@ -1,103 +1,103 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 QJSON_DOCUMENT_H_
#define QJSON_DOCUMENT_H_
#include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000
#include <QtCore/QJsonDocument>
#else
class QVariant;
class QByteArray;
class QTextStream;
class QJsonObject;
class QJsonValue;
class QJsonArray;
class QJsonParseError;
class QJsonRoot;
class QJsonDocument {
public:
enum DataValidation {
Validate = 0,
BypassValidation = 1
};
enum JsonFormat {
Indented,
Compact
};
public:
QJsonDocument();
QJsonDocument(const QJsonObject &object);
QJsonDocument(const QJsonArray &array);
QJsonDocument(const QJsonDocument &other);
~QJsonDocument();
public:
QJsonDocument &operator=(const QJsonDocument &other);
public:
bool operator!=(const QJsonDocument &other) const;
bool operator==(const QJsonDocument &other) const;
public:
bool isArray() const;
bool isEmpty() const;
bool isNull() const;
bool isObject() const;
public:
QByteArray toBinaryData() const;
QByteArray toJson(JsonFormat format = Indented) const;
QVariant toVariant() const;
public:
QJsonArray array() const;
QJsonObject object() const;
const char *rawData(int *size) const;
public:
void setArray(const QJsonArray &array);
void setObject(const QJsonObject &object);
public:
static QJsonDocument fromBinaryData(const QByteArray &data, DataValidation validation = Validate);
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error = 0);
static QJsonDocument fromRawData(const char *data, int size, DataValidation validation = Validate);
static QJsonDocument fromVariant(const QVariant &variant);
private:
void setRoot(const QJsonRoot &root);
QString toJson(const QJsonValue &v, JsonFormat format) const;
QString escapeString(const QString &s) const;
private:
void swap(QJsonDocument &other);
private:
QJsonRoot *root_;
};
#endif
#endif
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 QJSON_DOCUMENT_H_
#define QJSON_DOCUMENT_H_
#include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000
#include <QtCore/QJsonDocument>
#else
class QVariant;
class QByteArray;
class QTextStream;
class QJsonObject;
class QJsonValue;
class QJsonArray;
class QJsonParseError;
class QJsonRoot;
class QJsonDocument {
public:
enum DataValidation {
Validate = 0,
BypassValidation = 1
};
enum JsonFormat {
Indented,
Compact
};
public:
QJsonDocument();
QJsonDocument(const QJsonObject &object);
QJsonDocument(const QJsonArray &array);
QJsonDocument(const QJsonDocument &other);
~QJsonDocument();
public:
QJsonDocument &operator=(const QJsonDocument &other);
public:
bool operator!=(const QJsonDocument &other) const;
bool operator==(const QJsonDocument &other) const;
public:
bool isArray() const;
bool isEmpty() const;
bool isNull() const;
bool isObject() const;
public:
QByteArray toBinaryData() const;
QByteArray toJson(JsonFormat format = Indented) const;
QVariant toVariant() const;
public:
QJsonArray array() const;
QJsonObject object() const;
const char *rawData(int *size) const;
public:
void setArray(const QJsonArray &array);
void setObject(const QJsonObject &object);
public:
static QJsonDocument fromBinaryData(const QByteArray &data, DataValidation validation = Validate);
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error = 0);
static QJsonDocument fromRawData(const char *data, int size, DataValidation validation = Validate);
static QJsonDocument fromVariant(const QVariant &variant);
private:
void setRoot(const QJsonRoot &root);
QString toJson(const QJsonValue &v, JsonFormat format) const;
QString escapeString(const QString &s) const;
private:
void swap(QJsonDocument &other);
private:
QJsonRoot *root_;
};
#endif
#endif

View file

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

View file

@ -1,322 +1,322 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 "QJsonObject.h"
#if QT_VERSION < 0x050000
//------------------------------------------------------------------------------
// Name: QJsonObject
//------------------------------------------------------------------------------
QJsonObject::QJsonObject() {
}
//------------------------------------------------------------------------------
// Name: QJsonObject
//------------------------------------------------------------------------------
QJsonObject::QJsonObject(const QJsonObject &other) : values_(other.values_) {
}
#if __cplusplus >= 201103L
//------------------------------------------------------------------------------
// Name: QJsonObject
//------------------------------------------------------------------------------
QJsonObject::QJsonObject(std::initializer_list<QPair<QString, QJsonValue> > args) {
for(const QPair<QString, QJsonValue> &arg : args) {
values_.insert(arg.first, arg.second);
}
}
#endif
//------------------------------------------------------------------------------
// Name: ~QJsonObject
//------------------------------------------------------------------------------
QJsonObject::~QJsonObject() {
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject &QJsonObject::operator=(const QJsonObject &other) {
QJsonObject(other).swap(*this);
return *this;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::iterator QJsonObject::begin() {
return values_.begin();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::begin() const {
return values_.begin();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::iterator QJsonObject::end() {
return values_.end();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::end() const {
return values_.end();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::constBegin() const {
return begin();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::constEnd() const {
return end();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
int QJsonObject::count() const {
return size();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
int QJsonObject::length() const {
return size();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
int QJsonObject::size() const {
return values_.size();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
bool QJsonObject::empty() const {
return values_.empty();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
bool QJsonObject::isEmpty() const {
return empty();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const {
return values_.find(key);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
bool QJsonObject::contains(const QString &key) const {
return values_.contains(key);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::iterator QJsonObject::find(const QString &key) {
return values_.find(key);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::find(const QString &key) const {
return values_.find(key);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::iterator QJsonObject::erase(iterator it) {
return values_.erase(it);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue &value) {
return values_.insert(key, value);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QStringList QJsonObject::keys() const {
return values_.keys();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonObject::remove(const QString &key) {
values_.remove(key);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonValue QJsonObject::take(const QString &key) {
return values_.take(key);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonValue QJsonObject::value(const QString &key) const {
return values_.value(key);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
bool QJsonObject::operator!=(const QJsonObject &other) const {
return values_ != other.values_;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
bool QJsonObject::operator==(const QJsonObject &other) const {
return values_ != other.values_;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonValue QJsonObject::operator[](const QString &key) const {
return values_[key];
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonValueRef QJsonObject::operator[](const QString &key) {
return QJsonValueRef(this, key);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QVariantMap QJsonObject::toVariantMap() const {
QVariantMap a;
for(const_iterator it = begin(); it != end(); ++it) {
a.insert(it.key(), it.value().toVariant());
}
return a;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QVariantHash QJsonObject::toVariantHash() const {
QVariantHash a;
for(const_iterator it = begin(); it != end(); ++it) {
a.insert(it.key(), it.value().toVariant());
}
return a;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject QJsonObject::fromVariantMap(const QVariantMap &map) {
QJsonObject o;
for(QVariantMap::const_iterator it = map.begin(); it != map.end(); ++it) {
o.insert(it.key(), QJsonValue::fromVariant(it.value()));
}
return o;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject QJsonObject::fromVariantHash(const QVariantHash &hash) {
QJsonObject o;
for(QVariantHash::const_iterator it = hash.begin(); it != hash.end(); ++it) {
o.insert(it.key(), QJsonValue::fromVariant(it.value()));
}
return o;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonRoot *QJsonObject::clone() const {
return new QJsonObject(*this);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
const QJsonObject *QJsonObject::toObject() const {
return this;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject *QJsonObject::toObject() {
return this;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonArray *QJsonObject::toArray() {
return 0;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
const QJsonArray *QJsonObject::toArray() const {
return 0;
}
//------------------------------------------------------------------------------
// Name: swap
//------------------------------------------------------------------------------
void QJsonObject::swap(QJsonObject &other) {
qSwap(values_, other.values_);
}
#endif
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 "QJsonObject.h"
#if QT_VERSION < 0x050000
//------------------------------------------------------------------------------
// Name: QJsonObject
//------------------------------------------------------------------------------
QJsonObject::QJsonObject() {
}
//------------------------------------------------------------------------------
// Name: QJsonObject
//------------------------------------------------------------------------------
QJsonObject::QJsonObject(const QJsonObject &other) : values_(other.values_) {
}
#if __cplusplus >= 201103L
//------------------------------------------------------------------------------
// Name: QJsonObject
//------------------------------------------------------------------------------
QJsonObject::QJsonObject(std::initializer_list<QPair<QString, QJsonValue> > args) {
for(const QPair<QString, QJsonValue> &arg : args) {
values_.insert(arg.first, arg.second);
}
}
#endif
//------------------------------------------------------------------------------
// Name: ~QJsonObject
//------------------------------------------------------------------------------
QJsonObject::~QJsonObject() {
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject &QJsonObject::operator=(const QJsonObject &other) {
QJsonObject(other).swap(*this);
return *this;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::iterator QJsonObject::begin() {
return values_.begin();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::begin() const {
return values_.begin();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::iterator QJsonObject::end() {
return values_.end();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::end() const {
return values_.end();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::constBegin() const {
return begin();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::constEnd() const {
return end();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
int QJsonObject::count() const {
return size();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
int QJsonObject::length() const {
return size();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
int QJsonObject::size() const {
return values_.size();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
bool QJsonObject::empty() const {
return values_.empty();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
bool QJsonObject::isEmpty() const {
return empty();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const {
return values_.find(key);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
bool QJsonObject::contains(const QString &key) const {
return values_.contains(key);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::iterator QJsonObject::find(const QString &key) {
return values_.find(key);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::const_iterator QJsonObject::find(const QString &key) const {
return values_.find(key);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::iterator QJsonObject::erase(iterator it) {
return values_.erase(it);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue &value) {
return values_.insert(key, value);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QStringList QJsonObject::keys() const {
return values_.keys();
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
void QJsonObject::remove(const QString &key) {
values_.remove(key);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonValue QJsonObject::take(const QString &key) {
return values_.take(key);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonValue QJsonObject::value(const QString &key) const {
return values_.value(key);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
bool QJsonObject::operator!=(const QJsonObject &other) const {
return values_ != other.values_;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
bool QJsonObject::operator==(const QJsonObject &other) const {
return values_ != other.values_;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonValue QJsonObject::operator[](const QString &key) const {
return values_[key];
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonValueRef QJsonObject::operator[](const QString &key) {
return QJsonValueRef(this, key);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QVariantMap QJsonObject::toVariantMap() const {
QVariantMap a;
for(const_iterator it = begin(); it != end(); ++it) {
a.insert(it.key(), it.value().toVariant());
}
return a;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QVariantHash QJsonObject::toVariantHash() const {
QVariantHash a;
for(const_iterator it = begin(); it != end(); ++it) {
a.insert(it.key(), it.value().toVariant());
}
return a;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject QJsonObject::fromVariantMap(const QVariantMap &map) {
QJsonObject o;
for(QVariantMap::const_iterator it = map.begin(); it != map.end(); ++it) {
o.insert(it.key(), QJsonValue::fromVariant(it.value()));
}
return o;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject QJsonObject::fromVariantHash(const QVariantHash &hash) {
QJsonObject o;
for(QVariantHash::const_iterator it = hash.begin(); it != hash.end(); ++it) {
o.insert(it.key(), QJsonValue::fromVariant(it.value()));
}
return o;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonRoot *QJsonObject::clone() const {
return new QJsonObject(*this);
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
const QJsonObject *QJsonObject::toObject() const {
return this;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonObject *QJsonObject::toObject() {
return this;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
QJsonArray *QJsonObject::toArray() {
return 0;
}
//------------------------------------------------------------------------------
// Name:
//------------------------------------------------------------------------------
const QJsonArray *QJsonObject::toArray() const {
return 0;
}
//------------------------------------------------------------------------------
// Name: swap
//------------------------------------------------------------------------------
void QJsonObject::swap(QJsonObject &other) {
qSwap(values_, other.values_);
}
#endif

View file

@ -1,121 +1,121 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 QJSON_OBJECT_H_
#define QJSON_OBJECT_H_
#include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000
#include <QtCore/QJsonObject>
#else
#include "QJsonRoot.h"
#include "QJsonValueRef.h"
#include "QJsonValue.h"
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QVariantMap>
#include <QtCore/QMap>
class QJsonObject : public QJsonRoot {
friend class QJsonDocument;
friend class QJsonValue;
friend class QJsonValueRef;
friend class QJsonParser;
public:
// TODO(eteran): manually implement the map, for now we use QMap
// but the real thing has a custom implementation
// I guess for the purposes of less interdependancies?
// maybe so it's easier to forward declare the iterators?
typedef QMap<QString, QJsonValue>::const_iterator const_iterator;
typedef QMap<QString, QJsonValue>::iterator iterator;
typedef const_iterator ConstIterator;
typedef iterator Iterator;
typedef QMap<QString, QJsonValue>::key_type key_type;
typedef QMap<QString, QJsonValue>::mapped_type mapped_type;
typedef QMap<QString, QJsonValue>::size_type size_type;
public:
QJsonObject();
#if __cplusplus >= 201103L
QJsonObject(std::initializer_list<QPair<QString, QJsonValue> > args);
#endif
QJsonObject(const QJsonObject &other);
~QJsonObject();
QJsonObject &operator=(const QJsonObject &other);
public:
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
const_iterator constBegin() const;
const_iterator constEnd() const;
public:
int count() const;
int length() const;
int size() const;
bool empty() const;
bool isEmpty() const;
public:
const_iterator constFind(const QString &key) const;
bool contains(const QString &key) const;
iterator find(const QString &key);
const_iterator find(const QString &key) const;
public:
iterator erase(iterator it);
iterator insert(const QString &key, const QJsonValue &value);
QStringList keys() const;
void remove(const QString &key);
QJsonValue take(const QString &key);
QJsonValue value(const QString &key) const;
bool operator!=(const QJsonObject &other) const;
bool operator==(const QJsonObject &other) const;
QJsonValue operator[](const QString &key) const;
QJsonValueRef operator[](const QString &key);
public:
QVariantMap toVariantMap() const;
QVariantHash toVariantHash() const;
public:
static QJsonObject fromVariantMap(const QVariantMap &map);
static QJsonObject fromVariantHash(const QVariantHash &hash);
private:
virtual QJsonRoot *clone() const;
virtual QJsonArray *toArray();
virtual QJsonObject *toObject();
virtual const QJsonArray *toArray() const;
virtual const QJsonObject *toObject() const;
private:
void swap(QJsonObject &other);
private:
QMap<QString, QJsonValue> values_;
};
#endif
#endif
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 QJSON_OBJECT_H_
#define QJSON_OBJECT_H_
#include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000
#include <QtCore/QJsonObject>
#else
#include "QJsonRoot.h"
#include "QJsonValueRef.h"
#include "QJsonValue.h"
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QVariantMap>
#include <QtCore/QMap>
class QJsonObject : public QJsonRoot {
friend class QJsonDocument;
friend class QJsonValue;
friend class QJsonValueRef;
friend class QJsonParser;
public:
// TODO(eteran): manually implement the map, for now we use QMap
// but the real thing has a custom implementation
// I guess for the purposes of less interdependancies?
// maybe so it's easier to forward declare the iterators?
typedef QMap<QString, QJsonValue>::const_iterator const_iterator;
typedef QMap<QString, QJsonValue>::iterator iterator;
typedef const_iterator ConstIterator;
typedef iterator Iterator;
typedef QMap<QString, QJsonValue>::key_type key_type;
typedef QMap<QString, QJsonValue>::mapped_type mapped_type;
typedef QMap<QString, QJsonValue>::size_type size_type;
public:
QJsonObject();
#if __cplusplus >= 201103L
QJsonObject(std::initializer_list<QPair<QString, QJsonValue> > args);
#endif
QJsonObject(const QJsonObject &other);
~QJsonObject();
QJsonObject &operator=(const QJsonObject &other);
public:
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
const_iterator constBegin() const;
const_iterator constEnd() const;
public:
int count() const;
int length() const;
int size() const;
bool empty() const;
bool isEmpty() const;
public:
const_iterator constFind(const QString &key) const;
bool contains(const QString &key) const;
iterator find(const QString &key);
const_iterator find(const QString &key) const;
public:
iterator erase(iterator it);
iterator insert(const QString &key, const QJsonValue &value);
QStringList keys() const;
void remove(const QString &key);
QJsonValue take(const QString &key);
QJsonValue value(const QString &key) const;
bool operator!=(const QJsonObject &other) const;
bool operator==(const QJsonObject &other) const;
QJsonValue operator[](const QString &key) const;
QJsonValueRef operator[](const QString &key);
public:
QVariantMap toVariantMap() const;
QVariantHash toVariantHash() const;
public:
static QJsonObject fromVariantMap(const QVariantMap &map);
static QJsonObject fromVariantHash(const QVariantHash &hash);
private:
virtual QJsonRoot *clone() const;
virtual QJsonArray *toArray();
virtual QJsonObject *toObject();
virtual const QJsonArray *toArray() const;
virtual const QJsonObject *toObject() const;
private:
void swap(QJsonObject &other);
private:
QMap<QString, QJsonValue> values_;
};
#endif
#endif

View file

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

View file

@ -1,64 +1,64 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 "QJsonParseError.h"
#if QT_VERSION < 0x050000
//------------------------------------------------------------------------------
// Name: errorString
// Desc: The QJsonParseError class is used to report errors during JSON parsing.
//------------------------------------------------------------------------------
QString QJsonParseError::errorString() const {
switch(error) {
case NoError:
return "No error occurred";
case UnterminatedObject:
return "unterminated object";
case MissingNameSeparator:
return "missing name separator";
case UnterminatedArray:
return "unterminated array";
case MissingValueSeparator:
return "missing value separator";
case IllegalValue:
return "illegal value";
case TerminationByNumber:
return "invalid termination by number";
case IllegalNumber:
return "illegal number";
case IllegalEscapeSequence:
return "illegal escape sequence";
case IllegalUTF8String:
return "invalid UTF8 string";
case UnterminatedString:
return "unterminated string";
case MissingObject:
return "object is missing after a comma";
case DeepNesting:
return "too deeply nested document";
case DocumentTooLarge:
return "too large document";
case GarbageAtEnd:
return "garbage at the end of the document";
}
return QString();
}
#endif
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 "QJsonParseError.h"
#if QT_VERSION < 0x050000
//------------------------------------------------------------------------------
// Name: errorString
// Desc: The QJsonParseError class is used to report errors during JSON parsing.
//------------------------------------------------------------------------------
QString QJsonParseError::errorString() const {
switch(error) {
case NoError:
return "No error occurred";
case UnterminatedObject:
return "unterminated object";
case MissingNameSeparator:
return "missing name separator";
case UnterminatedArray:
return "unterminated array";
case MissingValueSeparator:
return "missing value separator";
case IllegalValue:
return "illegal value";
case TerminationByNumber:
return "invalid termination by number";
case IllegalNumber:
return "illegal number";
case IllegalEscapeSequence:
return "illegal escape sequence";
case IllegalUTF8String:
return "invalid UTF8 string";
case UnterminatedString:
return "unterminated string";
case MissingObject:
return "object is missing after a comma";
case DeepNesting:
return "too deeply nested document";
case DocumentTooLarge:
return "too large document";
case GarbageAtEnd:
return "garbage at the end of the document";
}
return QString();
}
#endif

View file

@ -1,60 +1,60 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 QJSON_PARSE_ERROR_H_
#define QJSON_PARSE_ERROR_H_
#include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000
#include <QtCore/QJsonParseError>
#else
#include <QtCore/QString>
class QJsonParseError {
public:
enum ParseError {
NoError = 0,
UnterminatedObject = 1,
MissingNameSeparator = 2,
UnterminatedArray = 3,
MissingValueSeparator = 4,
IllegalValue = 5,
TerminationByNumber = 6,
IllegalNumber = 7,
IllegalEscapeSequence = 8,
IllegalUTF8String = 9,
UnterminatedString = 10,
MissingObject = 11,
DeepNesting = 12,
DocumentTooLarge = 13,
GarbageAtEnd = 14
};
public:
QString errorString() const;
public:
ParseError error;
int offset;
};
#endif
#endif
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 QJSON_PARSE_ERROR_H_
#define QJSON_PARSE_ERROR_H_
#include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000
#include <QtCore/QJsonParseError>
#else
#include <QtCore/QString>
class QJsonParseError {
public:
enum ParseError {
NoError = 0,
UnterminatedObject = 1,
MissingNameSeparator = 2,
UnterminatedArray = 3,
MissingValueSeparator = 4,
IllegalValue = 5,
TerminationByNumber = 6,
IllegalNumber = 7,
IllegalEscapeSequence = 8,
IllegalUTF8String = 9,
UnterminatedString = 10,
MissingObject = 11,
DeepNesting = 12,
DocumentTooLarge = 13,
GarbageAtEnd = 14
};
public:
QString errorString() const;
public:
ParseError error;
int offset;
};
#endif
#endif

View file

@ -1,455 +1,455 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 "QJsonParser.h"
#include "QJsonArray.h"
#include "QJsonObject.h"
#include "QJsonValue.h"
#if QT_VERSION < 0x050000
#include <cctype>
#include <QScopedPointer>
#include <QVector>
namespace {
unsigned int to_hex(int ch) {
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, 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, 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
};
if(static_cast<unsigned int>(ch) < 256) {
return hexval[static_cast<unsigned int>(ch)];
} else {
return 0;
}
}
}
//------------------------------------------------------------------------------
// Name: QJsonParser
//------------------------------------------------------------------------------
QJsonParser::QJsonParser(const char *begin, const char *end) : begin_(begin), end_(end), p_(begin) {
state_.error = QJsonParseError::NoError;
state_.offset = 0;
}
//------------------------------------------------------------------------------
// Name: parse
//------------------------------------------------------------------------------
QJsonRoot *QJsonParser::parse() {
if(begin_ == end_) {
return 0;
}
QJsonRoot *ret = 0;
try {
const char ch = peek();
switch(ch) {
case ArrayBegin:
ret = getArray();
break;
case ObjectBegin:
ret = getObject();
break;
default:
state_.error = QJsonParseError::IllegalValue;
state_.offset = p_ - begin_;
break;
}
} catch(const QJsonParseError &e) {
state_ = e;
}
if(ret) {
// eat up trailing white space...
while(p_ != end_ && std::isspace(*p_)) {
++p_;
}
//detect trailing garbage
if(p_ != end_) {
state_.error = QJsonParseError::GarbageAtEnd;
state_.offset = p_ - begin_;
}
}
return ret;
}
//------------------------------------------------------------------------------
// Name: peek
//------------------------------------------------------------------------------
char QJsonParser::peek() {
// first eat up some whitespace
while(p_ != end_ && std::isspace(*p_)) {
++p_;
}
return *p_;
}
//------------------------------------------------------------------------------
// Name: getValue
//------------------------------------------------------------------------------
QJsonValue QJsonParser::getValue() {
switch(peek()) {
case ObjectBegin:
{
QScopedPointer<QJsonObject> obj(getObject());
return QJsonValue(*obj);
}
case ArrayBegin:
{
QScopedPointer<QJsonArray> arr(getArray());
return QJsonValue(*arr);
}
case Quote:
return QJsonValue(getString());
case 't':
return getTrue();
case 'f':
return getFalse();
case 'n':
return getNull();
default:
return getNumber();
}
throwError(QJsonParseError::MissingObject);
return QJsonValue();
}
//------------------------------------------------------------------------------
// Name: getObject
//------------------------------------------------------------------------------
QJsonObject *QJsonParser::getObject() {
QScopedPointer<QJsonObject> obj(new QJsonObject);
char tok = peek();
if(tok != ObjectBegin) {
throwError(QJsonParseError::IllegalValue);
}
++p_;
// handle empty object
tok = peek();
if(peek() == ObjectEnd) {
++p_;
} else {
do {
QPair<QString, QJsonValue> p = getPair();
obj->values_.insert(p.first, p.second);
tok = peek();
++p_;
} while(tok == ValueSeparator);
}
if(tok != ObjectEnd) {
throwError(QJsonParseError::UnterminatedObject);
}
return obj.take();
}
//------------------------------------------------------------------------------
// Name: getArray
//------------------------------------------------------------------------------
QJsonArray *QJsonParser::getArray() {
QScopedPointer<QJsonArray> arr(new QJsonArray);
char tok = peek();
if(tok != ArrayBegin) {
throwError(QJsonParseError::IllegalValue);
}
++p_;
// handle empty object
tok = peek();
if(tok == ArrayEnd) {
++p_;
} else {
do {
arr->values_.push_back(getValue());
tok = peek();
++p_;
} while(tok == ValueSeparator);
}
if(tok != ArrayEnd) {
throwError(QJsonParseError::MissingValueSeparator);
}
return arr.take();
}
//------------------------------------------------------------------------------
// Name: getPair
//------------------------------------------------------------------------------
QPair<QString, QJsonValue> QJsonParser::getPair() {
QString key = getString();
if(peek() != NameSeparator) {
throwError(QJsonParseError::MissingNameSeparator);
}
++p_;
return qMakePair(key, getValue());
}
//------------------------------------------------------------------------------
// Name: getString
//------------------------------------------------------------------------------
QString QJsonParser::getString() {
if(peek() != Quote) {
throwError(QJsonParseError::IllegalUTF8String);
}
++p_;
QByteArray s;
while(p_ != end_ && *p_ != Quote && *p_ != '\n') {
if(*p_ == '\\') {
++p_;
if(p_ != end_) {
switch(*p_) {
case '"': s.append('"'); break;
case '\\': s.append('\\'); break;
case '/': s.append('/'); break;
case 'b': s.append('\b'); break;
case 'f': s.append('\f'); break;
case 'n': s.append('\n'); break;
case 'r': s.append('\r'); break;
case 't': s.append('\t'); break;
case 'u':
{
QString hexChar;
// convert \uXXXX escape sequences to UTF-8
char hex[4];
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[2] = *++p_;
if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[3] = *++p_;
if(!std::isxdigit(hex[0])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[1])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[2])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[3])) throwError(QJsonParseError::IllegalUTF8String);
quint16 w1 = 0;
quint16 w2 = 0;
w1 |= (to_hex(hex[0]) << 12);
w1 |= (to_hex(hex[1]) << 8);
w1 |= (to_hex(hex[2]) << 4);
w1 |= (to_hex(hex[3]));
hexChar.append(QChar(w1));
if((w1 & 0xfc00) == 0xdc00) {
throwError(QJsonParseError::IllegalUTF8String);
}
if((w1 & 0xfc00) == 0xd800) {
// part of a surrogate pair
if(p_ == end_ || *++p_ != '\\') { throwError(QJsonParseError::IllegalEscapeSequence); }
if(p_ == end_ || *++p_ != 'u') { throwError(QJsonParseError::IllegalEscapeSequence); }
// convert \uXXXX escape sequences to UTF-8
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[2] = *++p_;
if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[3] = *++p_;
if(!std::isxdigit(hex[0])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[1])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[2])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[3])) throwError(QJsonParseError::IllegalUTF8String);
w2 |= (to_hex(hex[0]) << 12);
w2 |= (to_hex(hex[1]) << 8);
w2 |= (to_hex(hex[2]) << 4);
w2 |= (to_hex(hex[3]));
hexChar.append(QChar(w2));
}
s.append(hexChar.toUtf8());
}
break;
default:
s.append('\\');
break;
}
}
} else {
s.append(*p_);
}
++p_;
}
if(*p_ != Quote || p_ == end_) {
throwError(QJsonParseError::UnterminatedString);
}
++p_;
return QString::fromUtf8(s, s.size());
}
//------------------------------------------------------------------------------
// Name: getNull
//------------------------------------------------------------------------------
QJsonValue QJsonParser::getNull() {
if(p_ == end_ || *p_++ != 'n') { 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); }
return QJsonValue();
}
//------------------------------------------------------------------------------
// Name: getTrue
//------------------------------------------------------------------------------
QJsonValue QJsonParser::getTrue() {
if(p_ == end_ || *p_++ != 't') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'r') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'u') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'e') { throwError(QJsonParseError::IllegalValue); }
return QJsonValue(true);
}
//------------------------------------------------------------------------------
// Name: getFalse
//------------------------------------------------------------------------------
QJsonValue QJsonParser::getFalse() {
if(p_ == end_ || *p_++ != 'f') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'a') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'l') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 's') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'e') { throwError(QJsonParseError::IllegalValue); }
return QJsonValue(false);
}
//------------------------------------------------------------------------------
// Name: getNumber
//------------------------------------------------------------------------------
QJsonValue QJsonParser::getNumber() {
// JSON numbers fit the regex: -?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?
const char *const first = p_;
// -?
if(p_ != end_ && *p_ == '-') {
++p_;
}
// (0|[1-9][0-9]*)
if(p_ != end_) {
if(*p_ >= '1' && *p_ <= '9') {
while(p_ != end_ && std::isdigit(*p_)) {
++p_;
}
} else if(*p_ == '0') {
++p_;
} else {
throwError(QJsonParseError::IllegalNumber);
}
}
// (\.[0-9]+)?
if(p_ != end_ && *p_ == '.') {
++p_;
if(!std::isdigit(*p_)) {
throwError(QJsonParseError::IllegalNumber);
}
while(p_ != end_ && std::isdigit(*p_)) {
++p_;
}
}
// ([eE][+-]?[0-9]+)?
if(p_ != end_ && (*p_ == 'e' || *p_ == 'E')) {
++p_;
if(p_ != end_ && (*p_ == '+' || *p_ == '-')) {
++p_;
}
if(!std::isdigit(*p_)) {
throwError(QJsonParseError::IllegalNumber);
}
while(p_ != end_ && std::isdigit(*p_)) {
++p_;
}
}
if(p_ == end_) {
throwError(QJsonParseError::TerminationByNumber);
}
return QJsonValue(QByteArray::fromRawData(first, p_ - first).toDouble());
}
//------------------------------------------------------------------------------
// Name: state
//------------------------------------------------------------------------------
QJsonParseError QJsonParser::state() const {
return state_;
}
//------------------------------------------------------------------------------
// Name: throwError
//------------------------------------------------------------------------------
void QJsonParser::throwError(QJsonParseError::ParseError e) {
QJsonParseError err;
err.error = e;
err.offset = p_ - begin_;
throw err;
}
#endif
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 "QJsonParser.h"
#include "QJsonArray.h"
#include "QJsonObject.h"
#include "QJsonValue.h"
#if QT_VERSION < 0x050000
#include <cctype>
#include <QScopedPointer>
#include <QVector>
namespace {
unsigned int to_hex(int ch) {
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, 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, 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
};
if(static_cast<unsigned int>(ch) < 256) {
return hexval[static_cast<unsigned int>(ch)];
} else {
return 0;
}
}
}
//------------------------------------------------------------------------------
// Name: QJsonParser
//------------------------------------------------------------------------------
QJsonParser::QJsonParser(const char *begin, const char *end) : begin_(begin), end_(end), p_(begin) {
state_.error = QJsonParseError::NoError;
state_.offset = 0;
}
//------------------------------------------------------------------------------
// Name: parse
//------------------------------------------------------------------------------
QJsonRoot *QJsonParser::parse() {
if(begin_ == end_) {
return 0;
}
QJsonRoot *ret = 0;
try {
const char ch = peek();
switch(ch) {
case ArrayBegin:
ret = getArray();
break;
case ObjectBegin:
ret = getObject();
break;
default:
state_.error = QJsonParseError::IllegalValue;
state_.offset = p_ - begin_;
break;
}
} catch(const QJsonParseError &e) {
state_ = e;
}
if(ret) {
// eat up trailing white space...
while(p_ != end_ && std::isspace(*p_)) {
++p_;
}
//detect trailing garbage
if(p_ != end_) {
state_.error = QJsonParseError::GarbageAtEnd;
state_.offset = p_ - begin_;
}
}
return ret;
}
//------------------------------------------------------------------------------
// Name: peek
//------------------------------------------------------------------------------
char QJsonParser::peek() {
// first eat up some whitespace
while(p_ != end_ && std::isspace(*p_)) {
++p_;
}
return *p_;
}
//------------------------------------------------------------------------------
// Name: getValue
//------------------------------------------------------------------------------
QJsonValue QJsonParser::getValue() {
switch(peek()) {
case ObjectBegin:
{
QScopedPointer<QJsonObject> obj(getObject());
return QJsonValue(*obj);
}
case ArrayBegin:
{
QScopedPointer<QJsonArray> arr(getArray());
return QJsonValue(*arr);
}
case Quote:
return QJsonValue(getString());
case 't':
return getTrue();
case 'f':
return getFalse();
case 'n':
return getNull();
default:
return getNumber();
}
throwError(QJsonParseError::MissingObject);
return QJsonValue();
}
//------------------------------------------------------------------------------
// Name: getObject
//------------------------------------------------------------------------------
QJsonObject *QJsonParser::getObject() {
QScopedPointer<QJsonObject> obj(new QJsonObject);
char tok = peek();
if(tok != ObjectBegin) {
throwError(QJsonParseError::IllegalValue);
}
++p_;
// handle empty object
tok = peek();
if(peek() == ObjectEnd) {
++p_;
} else {
do {
QPair<QString, QJsonValue> p = getPair();
obj->values_.insert(p.first, p.second);
tok = peek();
++p_;
} while(tok == ValueSeparator);
}
if(tok != ObjectEnd) {
throwError(QJsonParseError::UnterminatedObject);
}
return obj.take();
}
//------------------------------------------------------------------------------
// Name: getArray
//------------------------------------------------------------------------------
QJsonArray *QJsonParser::getArray() {
QScopedPointer<QJsonArray> arr(new QJsonArray);
char tok = peek();
if(tok != ArrayBegin) {
throwError(QJsonParseError::IllegalValue);
}
++p_;
// handle empty object
tok = peek();
if(tok == ArrayEnd) {
++p_;
} else {
do {
arr->values_.push_back(getValue());
tok = peek();
++p_;
} while(tok == ValueSeparator);
}
if(tok != ArrayEnd) {
throwError(QJsonParseError::MissingValueSeparator);
}
return arr.take();
}
//------------------------------------------------------------------------------
// Name: getPair
//------------------------------------------------------------------------------
QPair<QString, QJsonValue> QJsonParser::getPair() {
QString key = getString();
if(peek() != NameSeparator) {
throwError(QJsonParseError::MissingNameSeparator);
}
++p_;
return qMakePair(key, getValue());
}
//------------------------------------------------------------------------------
// Name: getString
//------------------------------------------------------------------------------
QString QJsonParser::getString() {
if(peek() != Quote) {
throwError(QJsonParseError::IllegalUTF8String);
}
++p_;
QByteArray s;
while(p_ != end_ && *p_ != Quote && *p_ != '\n') {
if(*p_ == '\\') {
++p_;
if(p_ != end_) {
switch(*p_) {
case '"': s.append('"'); break;
case '\\': s.append('\\'); break;
case '/': s.append('/'); break;
case 'b': s.append('\b'); break;
case 'f': s.append('\f'); break;
case 'n': s.append('\n'); break;
case 'r': s.append('\r'); break;
case 't': s.append('\t'); break;
case 'u':
{
QString hexChar;
// convert \uXXXX escape sequences to UTF-8
char hex[4];
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[2] = *++p_;
if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[3] = *++p_;
if(!std::isxdigit(hex[0])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[1])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[2])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[3])) throwError(QJsonParseError::IllegalUTF8String);
quint16 w1 = 0;
quint16 w2 = 0;
w1 |= (to_hex(hex[0]) << 12);
w1 |= (to_hex(hex[1]) << 8);
w1 |= (to_hex(hex[2]) << 4);
w1 |= (to_hex(hex[3]));
hexChar.append(QChar(w1));
if((w1 & 0xfc00) == 0xdc00) {
throwError(QJsonParseError::IllegalUTF8String);
}
if((w1 & 0xfc00) == 0xd800) {
// part of a surrogate pair
if(p_ == end_ || *++p_ != '\\') { throwError(QJsonParseError::IllegalEscapeSequence); }
if(p_ == end_ || *++p_ != 'u') { throwError(QJsonParseError::IllegalEscapeSequence); }
// convert \uXXXX escape sequences to UTF-8
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[2] = *++p_;
if(p_ == end_) { throwError(QJsonParseError::IllegalEscapeSequence); } hex[3] = *++p_;
if(!std::isxdigit(hex[0])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[1])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[2])) throwError(QJsonParseError::IllegalUTF8String);
if(!std::isxdigit(hex[3])) throwError(QJsonParseError::IllegalUTF8String);
w2 |= (to_hex(hex[0]) << 12);
w2 |= (to_hex(hex[1]) << 8);
w2 |= (to_hex(hex[2]) << 4);
w2 |= (to_hex(hex[3]));
hexChar.append(QChar(w2));
}
s.append(hexChar.toUtf8());
}
break;
default:
s.append('\\');
break;
}
}
} else {
s.append(*p_);
}
++p_;
}
if(*p_ != Quote || p_ == end_) {
throwError(QJsonParseError::UnterminatedString);
}
++p_;
return QString::fromUtf8(s, s.size());
}
//------------------------------------------------------------------------------
// Name: getNull
//------------------------------------------------------------------------------
QJsonValue QJsonParser::getNull() {
if(p_ == end_ || *p_++ != 'n') { 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); }
return QJsonValue();
}
//------------------------------------------------------------------------------
// Name: getTrue
//------------------------------------------------------------------------------
QJsonValue QJsonParser::getTrue() {
if(p_ == end_ || *p_++ != 't') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'r') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'u') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'e') { throwError(QJsonParseError::IllegalValue); }
return QJsonValue(true);
}
//------------------------------------------------------------------------------
// Name: getFalse
//------------------------------------------------------------------------------
QJsonValue QJsonParser::getFalse() {
if(p_ == end_ || *p_++ != 'f') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'a') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'l') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 's') { throwError(QJsonParseError::IllegalValue); }
if(p_ == end_ || *p_++ != 'e') { throwError(QJsonParseError::IllegalValue); }
return QJsonValue(false);
}
//------------------------------------------------------------------------------
// Name: getNumber
//------------------------------------------------------------------------------
QJsonValue QJsonParser::getNumber() {
// JSON numbers fit the regex: -?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?
const char *const first = p_;
// -?
if(p_ != end_ && *p_ == '-') {
++p_;
}
// (0|[1-9][0-9]*)
if(p_ != end_) {
if(*p_ >= '1' && *p_ <= '9') {
while(p_ != end_ && std::isdigit(*p_)) {
++p_;
}
} else if(*p_ == '0') {
++p_;
} else {
throwError(QJsonParseError::IllegalNumber);
}
}
// (\.[0-9]+)?
if(p_ != end_ && *p_ == '.') {
++p_;
if(!std::isdigit(*p_)) {
throwError(QJsonParseError::IllegalNumber);
}
while(p_ != end_ && std::isdigit(*p_)) {
++p_;
}
}
// ([eE][+-]?[0-9]+)?
if(p_ != end_ && (*p_ == 'e' || *p_ == 'E')) {
++p_;
if(p_ != end_ && (*p_ == '+' || *p_ == '-')) {
++p_;
}
if(!std::isdigit(*p_)) {
throwError(QJsonParseError::IllegalNumber);
}
while(p_ != end_ && std::isdigit(*p_)) {
++p_;
}
}
if(p_ == end_) {
throwError(QJsonParseError::TerminationByNumber);
}
return QJsonValue(QByteArray::fromRawData(first, p_ - first).toDouble());
}
//------------------------------------------------------------------------------
// Name: state
//------------------------------------------------------------------------------
QJsonParseError QJsonParser::state() const {
return state_;
}
//------------------------------------------------------------------------------
// Name: throwError
//------------------------------------------------------------------------------
void QJsonParser::throwError(QJsonParseError::ParseError e) {
QJsonParseError err;
err.error = e;
err.offset = p_ - begin_;
throw err;
}
#endif

View file

@ -1,81 +1,81 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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/>.
*****************************************************************************/
// NOTE: this is not part of the "public" Qt API, so using this class directly
// is not recomended
#ifndef QJSON_PARSER_H_
#define QJSON_PARSER_H_
#include <QtCore/QtGlobal>
#if QT_VERSION < 0x050000
#include "QJsonParseError.h"
#include <QPair>
class QJsonRoot;
class QJsonObject;
class QJsonArray;
class QJsonValue;
class QJsonParser {
friend class QJsonDocument;
public:
QJsonParser(const char *begin, const char *end);
public:
QJsonRoot *parse();
public:
QJsonParseError state() const;
private:
static const char ArrayBegin = '[';
static const char ArrayEnd = ']';
static const char NameSeparator = ':';
static const char ValueSeparator = ',';
static const char ObjectBegin = '{';
static const char ObjectEnd = '}';
static const char Quote = '"';
private:
char peek();
QJsonObject *getObject();
QJsonArray *getArray();
QJsonValue getValue();
QString getString();
QJsonValue getTrue();
QJsonValue getFalse();
QJsonValue getNull();
QJsonValue getNumber();
QPair<QString, QJsonValue> getPair();
private:
void throwError(QJsonParseError::ParseError e);
private:
QJsonParseError state_;
const char *const begin_;
const char *const end_;
const char * p_;
};
#endif
#endif
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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/>.
*****************************************************************************/
// NOTE: this is not part of the "public" Qt API, so using this class directly
// is not recomended
#ifndef QJSON_PARSER_H_
#define QJSON_PARSER_H_
#include <QtCore/QtGlobal>
#if QT_VERSION < 0x050000
#include "QJsonParseError.h"
#include <QPair>
class QJsonRoot;
class QJsonObject;
class QJsonArray;
class QJsonValue;
class QJsonParser {
friend class QJsonDocument;
public:
QJsonParser(const char *begin, const char *end);
public:
QJsonRoot *parse();
public:
QJsonParseError state() const;
private:
static const char ArrayBegin = '[';
static const char ArrayEnd = ']';
static const char NameSeparator = ':';
static const char ValueSeparator = ',';
static const char ObjectBegin = '{';
static const char ObjectEnd = '}';
static const char Quote = '"';
private:
char peek();
QJsonObject *getObject();
QJsonArray *getArray();
QJsonValue getValue();
QString getString();
QJsonValue getTrue();
QJsonValue getFalse();
QJsonValue getNull();
QJsonValue getNumber();
QPair<QString, QJsonValue> getPair();
private:
void throwError(QJsonParseError::ParseError e);
private:
QJsonParseError state_;
const char *const begin_;
const char *const end_;
const char * p_;
};
#endif
#endif

View file

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

View file

@ -1,45 +1,45 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 QJSON_ROOT_H_
#define QJSON_ROOT_H_
#include <QtCore/QtGlobal>
#if QT_VERSION < 0x050000
class QJsonObject;
class QJsonArray;
class QJsonRoot {
public:
virtual ~QJsonRoot() {};
public:
virtual QJsonRoot *clone() const = 0;
public:
virtual QJsonArray *toArray() = 0;
virtual QJsonObject *toObject() = 0;
virtual const QJsonArray *toArray() const = 0;
virtual const QJsonObject *toObject() const = 0;
};
#endif
#endif
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 QJSON_ROOT_H_
#define QJSON_ROOT_H_
#include <QtCore/QtGlobal>
#if QT_VERSION < 0x050000
class QJsonObject;
class QJsonArray;
class QJsonRoot {
public:
virtual ~QJsonRoot() {};
public:
virtual QJsonRoot *clone() const = 0;
public:
virtual QJsonArray *toArray() = 0;
virtual QJsonObject *toObject() = 0;
virtual const QJsonArray *toArray() const = 0;
virtual const QJsonObject *toObject() const = 0;
};
#endif
#endif

View file

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

View file

@ -1,391 +1,391 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 "QJsonValue.h"
#include "QJsonArray.h"
#include "QJsonObject.h"
#if QT_VERSION < 0x050000
#include <QtCore/QtAlgorithms>
#include <QtCore/qmath.h>
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(Type type) : type_(type) {
}
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(bool b) : type_(Bool) {
value_.b = b;
}
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(double n) : type_(Double) {
value_.n = n;
}
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(const QString &s) : type_(String) {
value_.s = new QString(s);
}
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(QLatin1String s) : type_(String) {
value_.s = new QString(s);
}
#ifndef QT_NO_CAST_FROM_ASCII
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(const char *s) : type_(String) {
value_.s = new QString(QString::fromUtf8(s));
}
#endif
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(const QJsonArray &a) : type_(Array) {
value_.r = a.clone();
}
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(const QJsonObject &o) : type_(Object) {
value_.r = o.clone();
}
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(int n) : type_(Double) {
value_.n = n;
}
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(qint64 n) : type_(Double) {
value_.n = n;
}
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(const QJsonValue &other) : type_(other.type_) {
switch(other.type_) {
case Bool:
value_.b = other.value_.b;
break;
case Double:
value_.n = other.value_.n;
break;
case String:
value_.s = new QString(*other.value_.s);
break;
case Array:
case Object:
value_.r = other.value_.r->clone();
break;
case Undefined:
case Null:
value_ = other.value_;
break;
}
}
//------------------------------------------------------------------------------
// Name: ~QJsonValue
//------------------------------------------------------------------------------
QJsonValue::~QJsonValue() {
switch(type_) {
case Null:
case Bool:
case Double:
case Undefined:
break;
case String:
delete value_.s;
break;
case Object:
case Array:
delete value_.r;
break;
}
}
//------------------------------------------------------------------------------
// Name: operator=
//------------------------------------------------------------------------------
QJsonValue &QJsonValue::operator=(const QJsonValue &other) {
QJsonValue(other).swap(*this);
return *this;
}
//------------------------------------------------------------------------------
// Name: operator!=
//------------------------------------------------------------------------------
bool QJsonValue::operator!=(const QJsonValue &other) const {
return !(*this == other);
}
//------------------------------------------------------------------------------
// Name: operator==
//------------------------------------------------------------------------------
bool QJsonValue::operator==(const QJsonValue &other) const {
if(type_ == other.type_) {
switch(type_) {
case Null:
return true;
case Bool:
return value_.b == other.value_.b;
case Double:
return value_.n == other.value_.n;
case Undefined:
return true;
case String:
return *value_.s == *other.value_.s;
case Array:
return *(value_.r->toArray()) == *(other.value_.r->toArray());
case Object:
return *(value_.r->toObject()) == *(other.value_.r->toObject());
}
}
return false;
}
//------------------------------------------------------------------------------
// Name: isArray
//------------------------------------------------------------------------------
bool QJsonValue::isArray() const {
return type_ == Array;
}
//------------------------------------------------------------------------------
// Name: isBool
//------------------------------------------------------------------------------
bool QJsonValue::isBool() const {
return type_ == Bool;
}
//------------------------------------------------------------------------------
// Name: isDouble
//------------------------------------------------------------------------------
bool QJsonValue::isDouble() const {
return type_ == Double;
}
//------------------------------------------------------------------------------
// Name: isNull
//------------------------------------------------------------------------------
bool QJsonValue::isNull() const {
return type_ == Null;
}
//------------------------------------------------------------------------------
// Name: isObject
//------------------------------------------------------------------------------
bool QJsonValue::isObject() const {
return type_ == Object;
}
//------------------------------------------------------------------------------
// Name: isString
//------------------------------------------------------------------------------
bool QJsonValue::isString() const {
return type_ == String;
}
//------------------------------------------------------------------------------
// Name: isUndefined
//------------------------------------------------------------------------------
bool QJsonValue::isUndefined() const {
return type_ == Undefined;
}
//------------------------------------------------------------------------------
// Name: type
//------------------------------------------------------------------------------
QJsonValue::Type QJsonValue::type() const {
return type_;
}
//------------------------------------------------------------------------------
// Name: toArray
//------------------------------------------------------------------------------
QJsonArray QJsonValue::toArray(const QJsonArray &defaultValue) const {
if(isArray()) {
return *(value_.r->toArray());
}
return defaultValue;
}
//------------------------------------------------------------------------------
// Name: toArray
//------------------------------------------------------------------------------
QJsonArray QJsonValue::toArray() const {
return toArray(QJsonArray());
}
//------------------------------------------------------------------------------
// Name: toBool
//------------------------------------------------------------------------------
bool QJsonValue::toBool(bool defaultValue) const {
if(isBool()) {
return value_.b;
}
return defaultValue;
}
//------------------------------------------------------------------------------
// Name: toDouble
//------------------------------------------------------------------------------
double QJsonValue::toDouble(double defaultValue) const {
if(isDouble()) {
return value_.n;
}
return defaultValue;
}
//------------------------------------------------------------------------------
// Name: toInt
//------------------------------------------------------------------------------
int QJsonValue::toInt(int defaultValue) const {
if(isDouble() && qFloor(value_.n) == value_.n) {
return value_.n;
}
return defaultValue;
}
//------------------------------------------------------------------------------
// Name: toObject
//------------------------------------------------------------------------------
QJsonObject QJsonValue::toObject(const QJsonObject &defaultValue) const {
if(isObject()) {
return *(value_.r->toObject());
}
return defaultValue;
}
//------------------------------------------------------------------------------
// Name: toObject
//------------------------------------------------------------------------------
QJsonObject QJsonValue::toObject() const {
return toObject(QJsonObject());
}
//------------------------------------------------------------------------------
// Name: toString
//------------------------------------------------------------------------------
QString QJsonValue::toString(const QString &defaultValue) const {
if(isString()) {
return *value_.s;
}
return defaultValue;
}
//------------------------------------------------------------------------------
// Name: toVariant
//------------------------------------------------------------------------------
QVariant QJsonValue::toVariant() const {
switch(type_) {
case Null:
return QVariant();
case Bool:
return QVariant::fromValue(value_.b);
case Double:
return QVariant::fromValue(value_.n);
case String:
return QVariant::fromValue(*value_.s);
case Array:
return value_.r->toArray()->toVariantList();
case Object:
return value_.r->toObject()->toVariantMap();
case Undefined:
return QVariant();
}
return QVariant();
}
//------------------------------------------------------------------------------
// Name: fromVariant
//------------------------------------------------------------------------------
QJsonValue QJsonValue::fromVariant(const QVariant &variant) {
if(variant.isNull()) {
return QJsonValue(Null);
}
switch(variant.type()) {
case QVariant::Bool:
return QJsonValue(variant.toBool());
case QVariant::Int:
return QJsonValue(variant.toInt());
case QVariant::Double:
case QVariant::LongLong:
case QVariant::ULongLong:
case QVariant::UInt:
return QJsonValue(variant.toDouble());
case QVariant::String:
return QJsonValue(variant.toString());
case QVariant::List:
return QJsonArray::fromVariantList(variant.toList());
case QVariant::StringList:
return QJsonArray::fromStringList(variant.toStringList());
case QVariant::Map:
return QJsonObject::fromVariantMap(variant.toMap());
default:
const QString s = variant.toString();
if(!s.isEmpty()) {
return QJsonValue(s);
}
break;
}
return QJsonValue(Null);
}
//------------------------------------------------------------------------------
// Name: swap
//------------------------------------------------------------------------------
void QJsonValue::swap(QJsonValue &other) {
qSwap(type_, other.type_);
qSwap(value_, other.value_);
}
#endif
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 "QJsonValue.h"
#include "QJsonArray.h"
#include "QJsonObject.h"
#if QT_VERSION < 0x050000
#include <QtCore/QtAlgorithms>
#include <QtCore/qmath.h>
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(Type type) : type_(type) {
}
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(bool b) : type_(Bool) {
value_.b = b;
}
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(double n) : type_(Double) {
value_.n = n;
}
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(const QString &s) : type_(String) {
value_.s = new QString(s);
}
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(QLatin1String s) : type_(String) {
value_.s = new QString(s);
}
#ifndef QT_NO_CAST_FROM_ASCII
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(const char *s) : type_(String) {
value_.s = new QString(QString::fromUtf8(s));
}
#endif
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(const QJsonArray &a) : type_(Array) {
value_.r = a.clone();
}
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(const QJsonObject &o) : type_(Object) {
value_.r = o.clone();
}
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(int n) : type_(Double) {
value_.n = n;
}
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(qint64 n) : type_(Double) {
value_.n = n;
}
//------------------------------------------------------------------------------
// Name: QJsonValue
//------------------------------------------------------------------------------
QJsonValue::QJsonValue(const QJsonValue &other) : type_(other.type_) {
switch(other.type_) {
case Bool:
value_.b = other.value_.b;
break;
case Double:
value_.n = other.value_.n;
break;
case String:
value_.s = new QString(*other.value_.s);
break;
case Array:
case Object:
value_.r = other.value_.r->clone();
break;
case Undefined:
case Null:
value_ = other.value_;
break;
}
}
//------------------------------------------------------------------------------
// Name: ~QJsonValue
//------------------------------------------------------------------------------
QJsonValue::~QJsonValue() {
switch(type_) {
case Null:
case Bool:
case Double:
case Undefined:
break;
case String:
delete value_.s;
break;
case Object:
case Array:
delete value_.r;
break;
}
}
//------------------------------------------------------------------------------
// Name: operator=
//------------------------------------------------------------------------------
QJsonValue &QJsonValue::operator=(const QJsonValue &other) {
QJsonValue(other).swap(*this);
return *this;
}
//------------------------------------------------------------------------------
// Name: operator!=
//------------------------------------------------------------------------------
bool QJsonValue::operator!=(const QJsonValue &other) const {
return !(*this == other);
}
//------------------------------------------------------------------------------
// Name: operator==
//------------------------------------------------------------------------------
bool QJsonValue::operator==(const QJsonValue &other) const {
if(type_ == other.type_) {
switch(type_) {
case Null:
return true;
case Bool:
return value_.b == other.value_.b;
case Double:
return value_.n == other.value_.n;
case Undefined:
return true;
case String:
return *value_.s == *other.value_.s;
case Array:
return *(value_.r->toArray()) == *(other.value_.r->toArray());
case Object:
return *(value_.r->toObject()) == *(other.value_.r->toObject());
}
}
return false;
}
//------------------------------------------------------------------------------
// Name: isArray
//------------------------------------------------------------------------------
bool QJsonValue::isArray() const {
return type_ == Array;
}
//------------------------------------------------------------------------------
// Name: isBool
//------------------------------------------------------------------------------
bool QJsonValue::isBool() const {
return type_ == Bool;
}
//------------------------------------------------------------------------------
// Name: isDouble
//------------------------------------------------------------------------------
bool QJsonValue::isDouble() const {
return type_ == Double;
}
//------------------------------------------------------------------------------
// Name: isNull
//------------------------------------------------------------------------------
bool QJsonValue::isNull() const {
return type_ == Null;
}
//------------------------------------------------------------------------------
// Name: isObject
//------------------------------------------------------------------------------
bool QJsonValue::isObject() const {
return type_ == Object;
}
//------------------------------------------------------------------------------
// Name: isString
//------------------------------------------------------------------------------
bool QJsonValue::isString() const {
return type_ == String;
}
//------------------------------------------------------------------------------
// Name: isUndefined
//------------------------------------------------------------------------------
bool QJsonValue::isUndefined() const {
return type_ == Undefined;
}
//------------------------------------------------------------------------------
// Name: type
//------------------------------------------------------------------------------
QJsonValue::Type QJsonValue::type() const {
return type_;
}
//------------------------------------------------------------------------------
// Name: toArray
//------------------------------------------------------------------------------
QJsonArray QJsonValue::toArray(const QJsonArray &defaultValue) const {
if(isArray()) {
return *(value_.r->toArray());
}
return defaultValue;
}
//------------------------------------------------------------------------------
// Name: toArray
//------------------------------------------------------------------------------
QJsonArray QJsonValue::toArray() const {
return toArray(QJsonArray());
}
//------------------------------------------------------------------------------
// Name: toBool
//------------------------------------------------------------------------------
bool QJsonValue::toBool(bool defaultValue) const {
if(isBool()) {
return value_.b;
}
return defaultValue;
}
//------------------------------------------------------------------------------
// Name: toDouble
//------------------------------------------------------------------------------
double QJsonValue::toDouble(double defaultValue) const {
if(isDouble()) {
return value_.n;
}
return defaultValue;
}
//------------------------------------------------------------------------------
// Name: toInt
//------------------------------------------------------------------------------
int QJsonValue::toInt(int defaultValue) const {
if(isDouble() && qFloor(value_.n) == value_.n) {
return value_.n;
}
return defaultValue;
}
//------------------------------------------------------------------------------
// Name: toObject
//------------------------------------------------------------------------------
QJsonObject QJsonValue::toObject(const QJsonObject &defaultValue) const {
if(isObject()) {
return *(value_.r->toObject());
}
return defaultValue;
}
//------------------------------------------------------------------------------
// Name: toObject
//------------------------------------------------------------------------------
QJsonObject QJsonValue::toObject() const {
return toObject(QJsonObject());
}
//------------------------------------------------------------------------------
// Name: toString
//------------------------------------------------------------------------------
QString QJsonValue::toString(const QString &defaultValue) const {
if(isString()) {
return *value_.s;
}
return defaultValue;
}
//------------------------------------------------------------------------------
// Name: toVariant
//------------------------------------------------------------------------------
QVariant QJsonValue::toVariant() const {
switch(type_) {
case Null:
return QVariant();
case Bool:
return QVariant::fromValue(value_.b);
case Double:
return QVariant::fromValue(value_.n);
case String:
return QVariant::fromValue(*value_.s);
case Array:
return value_.r->toArray()->toVariantList();
case Object:
return value_.r->toObject()->toVariantMap();
case Undefined:
return QVariant();
}
return QVariant();
}
//------------------------------------------------------------------------------
// Name: fromVariant
//------------------------------------------------------------------------------
QJsonValue QJsonValue::fromVariant(const QVariant &variant) {
if(variant.isNull()) {
return QJsonValue(Null);
}
switch(variant.type()) {
case QVariant::Bool:
return QJsonValue(variant.toBool());
case QVariant::Int:
return QJsonValue(variant.toInt());
case QVariant::Double:
case QVariant::LongLong:
case QVariant::ULongLong:
case QVariant::UInt:
return QJsonValue(variant.toDouble());
case QVariant::String:
return QJsonValue(variant.toString());
case QVariant::List:
return QJsonArray::fromVariantList(variant.toList());
case QVariant::StringList:
return QJsonArray::fromStringList(variant.toStringList());
case QVariant::Map:
return QJsonObject::fromVariantMap(variant.toMap());
default:
const QString s = variant.toString();
if(!s.isEmpty()) {
return QJsonValue(s);
}
break;
}
return QJsonValue(Null);
}
//------------------------------------------------------------------------------
// Name: swap
//------------------------------------------------------------------------------
void QJsonValue::swap(QJsonValue &other) {
qSwap(type_, other.type_);
qSwap(value_, other.value_);
}
#endif

View file

@ -1,120 +1,120 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 QJSON_VALUE_H_
#define QJSON_VALUE_H_
#include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000
#include <QtCore/QJsonValue>
#else
class QString;
#include <QtCore/QVariant>
class QJsonRoot;
class QJsonArray;
class QJsonObject;
class QJsonValue {
public:
enum Type {
Null = 0x0,
Bool = 0x1,
Double = 0x2,
String = 0x3,
Array = 0x4,
Object = 0x5,
Undefined = 0x80
};
public:
QJsonValue(Type type = Null);
QJsonValue(bool b);
QJsonValue(double n);
QJsonValue(int n);
QJsonValue(qint64 n);
QJsonValue(const QString &s);
QJsonValue(QLatin1String s);
#ifndef QT_NO_CAST_FROM_ASCII
QJsonValue(const char *s);
#endif
QJsonValue(const QJsonArray &a);
QJsonValue(const QJsonObject &o);
QJsonValue(const QJsonValue &other);
~QJsonValue();
private:
// to protect against incorrect usage due to passing a const char *
QJsonValue(const void *);
public:
QJsonValue &operator=(const QJsonValue &other);
public:
bool operator!=(const QJsonValue &other) const;
bool operator==(const QJsonValue &other) const;
public:
bool isArray() const;
bool isBool() const;
bool isDouble() const;
bool isNull() const;
bool isObject() const;
bool isString() const;
bool isUndefined() const;
public:
QJsonArray toArray(const QJsonArray &defaultValue) const;
QJsonArray toArray() const;
bool toBool(bool defaultValue = false) const;
double toDouble(double defaultValue = 0) const;
int toInt(int defaultValue = 0) const;
QJsonObject toObject(const QJsonObject &defaultValue) const;
QJsonObject toObject() const;
QString toString(const QString &defaultValue = QString()) const;
QVariant toVariant() const;
public:
Type type() const;
public:
static QJsonValue fromVariant(const QVariant &variant);
private:
void swap(QJsonValue &other);
private:
Type type_;
union ValueType {
bool b;
double n;
QString *s;
QJsonRoot *r; // OJsonObject or QJsonArray
};
ValueType value_;
};
#endif
#endif
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 QJSON_VALUE_H_
#define QJSON_VALUE_H_
#include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000
#include <QtCore/QJsonValue>
#else
class QString;
#include <QtCore/QVariant>
class QJsonRoot;
class QJsonArray;
class QJsonObject;
class QJsonValue {
public:
enum Type {
Null = 0x0,
Bool = 0x1,
Double = 0x2,
String = 0x3,
Array = 0x4,
Object = 0x5,
Undefined = 0x80
};
public:
QJsonValue(Type type = Null);
QJsonValue(bool b);
QJsonValue(double n);
QJsonValue(int n);
QJsonValue(qint64 n);
QJsonValue(const QString &s);
QJsonValue(QLatin1String s);
#ifndef QT_NO_CAST_FROM_ASCII
QJsonValue(const char *s);
#endif
QJsonValue(const QJsonArray &a);
QJsonValue(const QJsonObject &o);
QJsonValue(const QJsonValue &other);
~QJsonValue();
private:
// to protect against incorrect usage due to passing a const char *
QJsonValue(const void *);
public:
QJsonValue &operator=(const QJsonValue &other);
public:
bool operator!=(const QJsonValue &other) const;
bool operator==(const QJsonValue &other) const;
public:
bool isArray() const;
bool isBool() const;
bool isDouble() const;
bool isNull() const;
bool isObject() const;
bool isString() const;
bool isUndefined() const;
public:
QJsonArray toArray(const QJsonArray &defaultValue) const;
QJsonArray toArray() const;
bool toBool(bool defaultValue = false) const;
double toDouble(double defaultValue = 0) const;
int toInt(int defaultValue = 0) const;
QJsonObject toObject(const QJsonObject &defaultValue) const;
QJsonObject toObject() const;
QString toString(const QString &defaultValue = QString()) const;
QVariant toVariant() const;
public:
Type type() const;
public:
static QJsonValue fromVariant(const QVariant &variant);
private:
void swap(QJsonValue &other);
private:
Type type_;
union ValueType {
bool b;
double n;
QString *s;
QJsonRoot *r; // OJsonObject or QJsonArray
};
ValueType value_;
};
#endif
#endif

View file

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

View file

@ -1,228 +1,228 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 "QJsonValueRef.h"
#if QT_VERSION < 0x050000
#include "QJsonArray.h"
#include "QJsonObject.h"
//------------------------------------------------------------------------------
// Name:
// Desc:
//------------------------------------------------------------------------------
QJsonValueRef::QJsonValueRef(QJsonArray *array, int idx) : p_(array), index_(idx) {
}
//------------------------------------------------------------------------------
// Name:
// Desc:
//------------------------------------------------------------------------------
QJsonValueRef::QJsonValueRef(QJsonObject *object, const QString &key) : p_(object), index_(0), key_(key) {
}
//------------------------------------------------------------------------------
// Name:
// Desc:
//------------------------------------------------------------------------------
QJsonValueRef::operator QJsonValue() const {
return toValue();
}
//------------------------------------------------------------------------------
// Name:
// Desc:
//------------------------------------------------------------------------------
QJsonValueRef &QJsonValueRef::operator=(const QJsonValue &val) {
if(QJsonObject *const o = p_->toObject()) {
o->values_[key_] = val;
} else if(QJsonArray *const a = p_->toArray()) {
a->values_[index_] = val;
}
return *this;
}
//------------------------------------------------------------------------------
// Name:
// Desc:
//------------------------------------------------------------------------------
QJsonValueRef &QJsonValueRef::operator=(const QJsonValueRef &ref) {
if(QJsonObject *const o = p_->toObject()) {
o->values_[key_] = ref;
} else if(QJsonArray *const a = p_->toArray()) {
a->values_[index_] = ref;
}
return *this;
}
//------------------------------------------------------------------------------
// Name: type
// Desc:
//------------------------------------------------------------------------------
QJsonValue::Type QJsonValueRef::type() const {
return toValue().type();
}
//------------------------------------------------------------------------------
// Name: isNull
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::isNull() const {
return toValue().isNull();
}
//------------------------------------------------------------------------------
// Name: isBool
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::isBool() const {
return toValue().isBool();
}
//------------------------------------------------------------------------------
// Name: isDouble
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::isDouble() const {
return toValue().isDouble();
}
//------------------------------------------------------------------------------
// Name: isString
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::isString() const {
return toValue().isString();
}
//------------------------------------------------------------------------------
// Name: isArray
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::isArray() const {
return toValue().isArray();
}
//------------------------------------------------------------------------------
// Name: isObject
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::isObject() const {
return toValue().isObject();
}
//------------------------------------------------------------------------------
// Name: isUndefined
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::isUndefined() const {
return toValue().isUndefined();
}
//------------------------------------------------------------------------------
// Name: toBool
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::toBool() const {
return toValue().toBool();
}
//------------------------------------------------------------------------------
// Name: toDouble
// Desc:
//------------------------------------------------------------------------------
double QJsonValueRef::toDouble() const {
return toValue().toDouble();
}
//------------------------------------------------------------------------------
// Name: toInt
// Desc:
//------------------------------------------------------------------------------
int QJsonValueRef::toInt(int defaultValue) const {
return toValue().toInt(defaultValue);
}
//------------------------------------------------------------------------------
// Name: toString
// Desc:
//------------------------------------------------------------------------------
QString QJsonValueRef::toString() const {
return toValue().toString();
}
//------------------------------------------------------------------------------
// Name: toArray
// Desc:
//------------------------------------------------------------------------------
QJsonArray QJsonValueRef::toArray() const {
return toValue().toArray();
}
//------------------------------------------------------------------------------
// Name: toObject
// Desc:
//------------------------------------------------------------------------------
QJsonObject QJsonValueRef::toObject() const {
return toValue().toObject();
}
//------------------------------------------------------------------------------
// Name: operator==
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::operator==(const QJsonValue &other) const {
return toValue() == other;
}
//------------------------------------------------------------------------------
// Name: operator!=
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::operator!=(const QJsonValue &other) const {
return toValue() != other;
}
//------------------------------------------------------------------------------
// Name: toValue
// Desc:
//------------------------------------------------------------------------------
QJsonValue QJsonValueRef::toValue() const {
if(QJsonObject *const o = p_->toObject()) {
return o->values_[key_];
} else if(QJsonArray *const a = p_->toArray()) {
return a->values_[index_];
}
return QJsonValue();
}
//------------------------------------------------------------------------------
// Name: swap
// Desc:
//------------------------------------------------------------------------------
void QJsonValueRef::swap(QJsonValueRef &other) {
qSwap(p_, other.p_);
qSwap(key_, other.key_);
qSwap(index_, other.index_);
}
#endif
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 "QJsonValueRef.h"
#if QT_VERSION < 0x050000
#include "QJsonArray.h"
#include "QJsonObject.h"
//------------------------------------------------------------------------------
// Name:
// Desc:
//------------------------------------------------------------------------------
QJsonValueRef::QJsonValueRef(QJsonArray *array, int idx) : p_(array), index_(idx) {
}
//------------------------------------------------------------------------------
// Name:
// Desc:
//------------------------------------------------------------------------------
QJsonValueRef::QJsonValueRef(QJsonObject *object, const QString &key) : p_(object), index_(0), key_(key) {
}
//------------------------------------------------------------------------------
// Name:
// Desc:
//------------------------------------------------------------------------------
QJsonValueRef::operator QJsonValue() const {
return toValue();
}
//------------------------------------------------------------------------------
// Name:
// Desc:
//------------------------------------------------------------------------------
QJsonValueRef &QJsonValueRef::operator=(const QJsonValue &val) {
if(QJsonObject *const o = p_->toObject()) {
o->values_[key_] = val;
} else if(QJsonArray *const a = p_->toArray()) {
a->values_[index_] = val;
}
return *this;
}
//------------------------------------------------------------------------------
// Name:
// Desc:
//------------------------------------------------------------------------------
QJsonValueRef &QJsonValueRef::operator=(const QJsonValueRef &ref) {
if(QJsonObject *const o = p_->toObject()) {
o->values_[key_] = ref;
} else if(QJsonArray *const a = p_->toArray()) {
a->values_[index_] = ref;
}
return *this;
}
//------------------------------------------------------------------------------
// Name: type
// Desc:
//------------------------------------------------------------------------------
QJsonValue::Type QJsonValueRef::type() const {
return toValue().type();
}
//------------------------------------------------------------------------------
// Name: isNull
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::isNull() const {
return toValue().isNull();
}
//------------------------------------------------------------------------------
// Name: isBool
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::isBool() const {
return toValue().isBool();
}
//------------------------------------------------------------------------------
// Name: isDouble
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::isDouble() const {
return toValue().isDouble();
}
//------------------------------------------------------------------------------
// Name: isString
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::isString() const {
return toValue().isString();
}
//------------------------------------------------------------------------------
// Name: isArray
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::isArray() const {
return toValue().isArray();
}
//------------------------------------------------------------------------------
// Name: isObject
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::isObject() const {
return toValue().isObject();
}
//------------------------------------------------------------------------------
// Name: isUndefined
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::isUndefined() const {
return toValue().isUndefined();
}
//------------------------------------------------------------------------------
// Name: toBool
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::toBool() const {
return toValue().toBool();
}
//------------------------------------------------------------------------------
// Name: toDouble
// Desc:
//------------------------------------------------------------------------------
double QJsonValueRef::toDouble() const {
return toValue().toDouble();
}
//------------------------------------------------------------------------------
// Name: toInt
// Desc:
//------------------------------------------------------------------------------
int QJsonValueRef::toInt(int defaultValue) const {
return toValue().toInt(defaultValue);
}
//------------------------------------------------------------------------------
// Name: toString
// Desc:
//------------------------------------------------------------------------------
QString QJsonValueRef::toString() const {
return toValue().toString();
}
//------------------------------------------------------------------------------
// Name: toArray
// Desc:
//------------------------------------------------------------------------------
QJsonArray QJsonValueRef::toArray() const {
return toValue().toArray();
}
//------------------------------------------------------------------------------
// Name: toObject
// Desc:
//------------------------------------------------------------------------------
QJsonObject QJsonValueRef::toObject() const {
return toValue().toObject();
}
//------------------------------------------------------------------------------
// Name: operator==
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::operator==(const QJsonValue &other) const {
return toValue() == other;
}
//------------------------------------------------------------------------------
// Name: operator!=
// Desc:
//------------------------------------------------------------------------------
bool QJsonValueRef::operator!=(const QJsonValue &other) const {
return toValue() != other;
}
//------------------------------------------------------------------------------
// Name: toValue
// Desc:
//------------------------------------------------------------------------------
QJsonValue QJsonValueRef::toValue() const {
if(QJsonObject *const o = p_->toObject()) {
return o->values_[key_];
} else if(QJsonArray *const a = p_->toArray()) {
return a->values_[index_];
}
return QJsonValue();
}
//------------------------------------------------------------------------------
// Name: swap
// Desc:
//------------------------------------------------------------------------------
void QJsonValueRef::swap(QJsonValueRef &other) {
qSwap(p_, other.p_);
qSwap(key_, other.key_);
qSwap(index_, other.index_);
}
#endif

View file

@ -1,79 +1,79 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 QJSON_VALUEREF_H_
#define QJSON_VALUEREF_H_
#include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000
#include <QtCore/QJsonValueRef>
#else
#include "QJsonValue.h"
class QJsonRoot;
class QJsonValueRef {
public:
QJsonValueRef(QJsonArray *array, int idx);
// slight variant from official APIs implementation
QJsonValueRef(QJsonObject *object, const QString &key);
public:
operator QJsonValue() const;
public:
QJsonValueRef &operator=(const QJsonValue &val);
QJsonValueRef &operator=(const QJsonValueRef &val);
public:
QJsonValue::Type type() const;
bool isNull() const;
bool isBool() const;
bool isDouble() const;
bool isString() const;
bool isArray() const;
bool isObject() const;
bool isUndefined() const;
public:
bool toBool() const;
double toDouble() const;
QString toString() const;
QJsonArray toArray() const;
QJsonObject toObject() const;
int toInt(int defaultValue = 0) const;
public:
bool operator==(const QJsonValue &other) const;
bool operator!=(const QJsonValue &other) const;
private:
QJsonValue toValue() const;
void swap(QJsonValueRef &other);
private:
QJsonRoot *p_;
int index_;
QString key_;
};
#endif
#endif
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 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 QJSON_VALUEREF_H_
#define QJSON_VALUEREF_H_
#include <QtCore/QtGlobal>
#if QT_VERSION >= 0x050000
#include <QtCore/QJsonValueRef>
#else
#include "QJsonValue.h"
class QJsonRoot;
class QJsonValueRef {
public:
QJsonValueRef(QJsonArray *array, int idx);
// slight variant from official APIs implementation
QJsonValueRef(QJsonObject *object, const QString &key);
public:
operator QJsonValue() const;
public:
QJsonValueRef &operator=(const QJsonValue &val);
QJsonValueRef &operator=(const QJsonValueRef &val);
public:
QJsonValue::Type type() const;
bool isNull() const;
bool isBool() const;
bool isDouble() const;
bool isString() const;
bool isArray() const;
bool isObject() const;
bool isUndefined() const;
public:
bool toBool() const;
double toDouble() const;
QString toString() const;
QJsonArray toArray() const;
QJsonObject toObject() const;
int toInt(int defaultValue = 0) const;
public:
bool operator==(const QJsonValue &other) const;
bool operator!=(const QJsonValue &other) const;
private:
QJsonValue toValue() const;
void swap(QJsonValueRef &other);
private:
QJsonRoot *p_;
int index_;
QString key_;
};
#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