Browse Source

code cleanup, remove first start prompt

1.10.x
Syping 9 months ago
parent
commit
929d341826
  1. 237
      AppEnv.cpp
  2. 4
      AppEnv.h
  3. 84
      DatabaseThread.cpp
  4. 15
      GlobalString.cpp
  5. 284
      TranslationClass.cpp
  6. 69
      main.cpp
  7. 16
      res/gta5sync.ts
  8. BIN
      res/gta5sync_de.qm
  9. 11
      res/gta5sync_de.ts
  10. 16
      res/gta5sync_en_US.ts
  11. BIN
      res/gta5sync_fr.qm
  12. 11
      res/gta5sync_fr.ts
  13. BIN
      res/gta5sync_ko.qm
  14. 11
      res/gta5sync_ko.ts
  15. BIN
      res/gta5sync_ru.qm
  16. 11
      res/gta5sync_ru.ts
  17. BIN
      res/gta5sync_uk.qm
  18. 11
      res/gta5sync_uk.ts
  19. BIN
      res/gta5sync_zh_TW.qm
  20. 11
      res/gta5sync_zh_TW.ts

237
AppEnv.cpp

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5view Grand Theft Auto V Profile Viewer
* Copyright (C) 2016-2020 Syping
* Copyright (C) 2016-2021 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
@ -33,12 +33,8 @@
#include <QDesktopWidget>
#endif
#include <iostream>
using namespace std;
AppEnv::AppEnv()
{
}
// Build Stuff
@ -59,12 +55,11 @@ QString AppEnv::getGameFolder(bool *ok)
{
QDir dir;
QString GTAV_FOLDER = QString::fromUtf8(qgetenv("GTAV_FOLDER"));
if (GTAV_FOLDER != "")
{
if (GTAV_FOLDER != "") {
dir.setPath(GTAV_FOLDER);
if (dir.exists())
{
if (ok != NULL) *ok = true;
if (dir.exists()) {
if (ok != NULL)
*ok = true;
qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8());
return dir.absolutePath();
}
@ -79,46 +74,44 @@ QString AppEnv::getGameFolder(bool *ok)
GTAV_returnFolder = settings.value("dir", GTAV_defaultFolder).toString();
settings.endGroup();
if (forceDir)
{
if (forceDir) {
dir.setPath(GTAV_returnFolder);
if (dir.exists())
{
if (ok != 0) *ok = true;
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;
if (dir.exists()) {
if (ok != 0)
*ok = true;
qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8());
return dir.absolutePath();
}
if (!forceDir)
{
if (!forceDir) {
dir.setPath(GTAV_returnFolder);
if (dir.exists())
{
if (ok != 0) *ok = true;
if (dir.exists()) {
if (ok != 0)
*ok = true;
qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8());
return dir.absolutePath();
}
}
if (ok != 0) *ok = false;
return "";
if (ok != 0)
*ok = false;
return QString();
}
bool AppEnv::setGameFolder(QString gameFolder)
{
QDir dir;
dir.setPath(gameFolder);
if (dir.exists())
{
if (dir.exists()) {
qputenv("GTAV_FOLDER", dir.absolutePath().toUtf8());
return true;
}
@ -160,24 +153,19 @@ QByteArray AppEnv::getUserAgent()
#ifdef Q_OS_WIN
QString kernelVersion = QSysInfo::kernelVersion();
const QStringList &kernelVersionList = kernelVersion.split(".");
if (kernelVersionList.length() > 2)
{
if (kernelVersionList.length() > 2) {
kernelVersion = kernelVersionList.at(0) % "." % kernelVersionList.at(1);
}
QString runArch = QSysInfo::buildCpuArchitecture();
if (runArch == "x86_64")
{
if (runArch == "x86_64") {
runArch = "Win64; x64";
}
else if (runArch == "i686")
{
else if (runArch == "i686") {
const QString &curArch = QSysInfo::currentCpuArchitecture();
if (curArch == "x86_64")
{
if (curArch == "x86_64") {
runArch = "WOW64";
}
else if (curArch == "i686")
{
else if (curArch == "i686") {
runArch = "Win32; x86";
}
}
@ -190,11 +178,6 @@ QByteArray AppEnv::getUserAgent()
#endif
}
// 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));
@ -223,8 +206,7 @@ GameVersion AppEnv::getGameVersion()
QString installFolderSc = registrySettingsSc.value("InstallFolder", "").toString();
QDir installFolderScDir(installFolderSc);
bool scVersionInstalled = false;
if (!installFolderSc.isEmpty() && installFolderScDir.exists())
{
if (!installFolderSc.isEmpty() && installFolderScDir.exists()) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "gameVersionFoundSocialClubVersion";
#endif
@ -233,34 +215,28 @@ GameVersion AppEnv::getGameVersion()
QSettings registrySettingsSteam(QString("HKEY_LOCAL_MACHINE\\SOFTWARE%1\\Rockstar Games\\GTAV").arg(argumentValue), QSettings::NativeFormat);
QString installFolderSteam = registrySettingsSteam.value("installfoldersteam", "").toString();
if (installFolderSteam.right(5) == "\\GTAV")
{
if (installFolderSteam.right(5) == "\\GTAV") {
installFolderSteam = installFolderSteam.remove(installFolderSteam.length() - 5, 5);
}
QDir installFolderSteamDir(installFolderSteam);
bool steamVersionInstalled = false;
if (!installFolderSteam.isEmpty() && installFolderSteamDir.exists())
{
if (!installFolderSteam.isEmpty() && installFolderSteamDir.exists()) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "gameVersionFoundSteamVersion";
#endif
steamVersionInstalled = true;
}
if (scVersionInstalled && steamVersionInstalled)
{
if (scVersionInstalled && steamVersionInstalled) {
return GameVersion::BothVersions;
}
else if (scVersionInstalled)
{
else if (scVersionInstalled) {
return GameVersion::SocialClubVersion;
}
else if (steamVersionInstalled)
{
else if (steamVersionInstalled) {
return GameVersion::SteamVersion;
}
else
{
else {
return GameVersion::NoVersion;
}
#else
@ -270,8 +246,7 @@ GameVersion AppEnv::getGameVersion()
GameLanguage AppEnv::getGameLanguage(GameVersion gameVersion)
{
if (gameVersion == GameVersion::SocialClubVersion)
{
if (gameVersion == GameVersion::SocialClubVersion) {
#ifdef Q_OS_WIN
QString argumentValue;
#ifdef _WIN64
@ -284,8 +259,7 @@ GameLanguage AppEnv::getGameLanguage(GameVersion gameVersion)
return GameLanguage::Undefined;
#endif
}
else if (gameVersion == GameVersion::SteamVersion)
{
else if (gameVersion == GameVersion::SteamVersion) {
#ifdef Q_OS_WIN
QString argumentValue;
#ifdef _WIN64
@ -298,128 +272,81 @@ GameLanguage AppEnv::getGameLanguage(GameVersion gameVersion)
return GameLanguage::Undefined;
#endif
}
else
{
return GameLanguage::Undefined;
}
return GameLanguage::Undefined;
}
GameLanguage AppEnv::gameLanguageFromString(QString gameLanguage)
{
if (gameLanguage == "en-US")
{
if (gameLanguage == "en-US") {
return GameLanguage::English;
}
else if (gameLanguage == "fr-FR")
{
else if (gameLanguage == "fr-FR") {
return GameLanguage::French;
}
else if (gameLanguage == "it-IT")
{
else if (gameLanguage == "it-IT") {
return GameLanguage::Italian;
}
else if (gameLanguage == "de-DE")
{
else if (gameLanguage == "de-DE") {
return GameLanguage::German;
}
else if (gameLanguage == "es-ES")
{
else if (gameLanguage == "es-ES") {
return GameLanguage::Spanish;
}
else if (gameLanguage == "es-MX")
{
else if (gameLanguage == "es-MX") {
return GameLanguage::Mexican;
}
else if (gameLanguage == "pt-BR")
{
else if (gameLanguage == "pt-BR") {
return GameLanguage::Brasilian;
}
else if (gameLanguage == "ru-RU")
{
else if (gameLanguage == "ru-RU") {
return GameLanguage::Russian;
}
else if (gameLanguage == "pl-PL")
{
else if (gameLanguage == "pl-PL") {
return GameLanguage::Polish;
}
else if (gameLanguage == "ja-JP")
{
else if (gameLanguage == "ja-JP") {
return GameLanguage::Japanese;
}
else if (gameLanguage == "zh-CHS")
{
else if (gameLanguage == "zh-CHS") {
return GameLanguage::SChinese;
}
else if (gameLanguage == "zh-CHT")
{
else if (gameLanguage == "zh-CHT") {
return GameLanguage::TChinese;
}
else if (gameLanguage == "ko-KR")
{
return GameLanguage::Koreana;
}
else
{
return GameLanguage::Undefined;
else if (gameLanguage == "ko-KR") {
return GameLanguage::Korean;
}
return GameLanguage::Undefined;
}
QString AppEnv::gameLanguageToString(GameLanguage gameLanguage)
{
if (gameLanguage == GameLanguage::English)
{
switch (gameLanguage) {
case GameLanguage::English:
return "en-US";
}
else if (gameLanguage == GameLanguage::French)
{
case GameLanguage::French:
return "fr-FR";
}
else if (gameLanguage == GameLanguage::Italian)
{
case GameLanguage::Italian:
return "it-IT";
}
else if (gameLanguage == GameLanguage::German)
{
case GameLanguage::German:
return "de-DE";
}
else if (gameLanguage == GameLanguage::Spanish)
{
case GameLanguage::Spanish:
return "es-ES";
}
else if (gameLanguage == GameLanguage::Mexican)
{
case GameLanguage::Mexican:
return "es-MX";
}
else if (gameLanguage == GameLanguage::Brasilian)
{
case GameLanguage::Brasilian:
return "pt-BR";
}
else if (gameLanguage == GameLanguage::Russian)
{
return "ru-RU";
}
else if (gameLanguage == GameLanguage::Polish)
{
case GameLanguage::Polish:
return "pl-PL";
}
else if (gameLanguage == GameLanguage::Japanese)
{
case GameLanguage::Japanese:
return "ja-JP";
}
else if (gameLanguage == GameLanguage::SChinese)
{
case GameLanguage::SChinese:
return "zh-CHS";
}
else if (gameLanguage == GameLanguage::TChinese)
{
case GameLanguage::TChinese:
return "zh-CHT";
}
else if (gameLanguage == GameLanguage::Koreana)
{
case GameLanguage::Korean:
return "ko-KR";
}
else
{
default:
return "Undefinied";
}
}
@ -428,67 +355,55 @@ bool AppEnv::setGameLanguage(GameVersion gameVersion, GameLanguage gameLanguage)
{
bool socialClubVersion = false;
bool steamVersion = false;
if (gameVersion == GameVersion::SocialClubVersion)
{
if (gameVersion == GameVersion::SocialClubVersion) {
socialClubVersion = true;
}
else if (gameVersion == GameVersion::SteamVersion)
{
else if (gameVersion == GameVersion::SteamVersion) {
steamVersion = true;
}
else if (gameVersion == GameVersion::BothVersions)
{
else if (gameVersion == GameVersion::BothVersions) {
socialClubVersion = true;
steamVersion = true;
}
else
{
else {
return false;
}
if (socialClubVersion)
{
if (socialClubVersion) {
#ifdef Q_OS_WIN
QString argumentValue;
#ifdef _WIN64
argumentValue = "\\WOW6432Node";
#endif
QSettings registrySettingsSc(QString("HKEY_LOCAL_MACHINE\\SOFTWARE%1\\Rockstar Games\\Grand Theft Auto V").arg(argumentValue), QSettings::NativeFormat);
if (gameLanguage != GameLanguage::Undefined)
{
if (gameLanguage != GameLanguage::Undefined) {
registrySettingsSc.setValue("Language", gameLanguageToString(gameLanguage));
}
else
{
else {
registrySettingsSc.remove("Language");
}
registrySettingsSc.sync();
if (registrySettingsSc.status() != QSettings::NoError)
{
if (registrySettingsSc.status() != QSettings::NoError) {
return false;
}
#else
Q_UNUSED(gameLanguage)
#endif
}
if (steamVersion)
{
if (steamVersion) {
#ifdef Q_OS_WIN
QString argumentValue;
#ifdef _WIN64
argumentValue = "\\WOW6432Node";
#endif
QSettings registrySettingsSteam(QString("HKEY_LOCAL_MACHINE\\SOFTWARE%1\\Rockstar Games\\Grand Theft Auto V Steam").arg(argumentValue), QSettings::NativeFormat);
if (gameLanguage != GameLanguage::Undefined)
{
if (gameLanguage != GameLanguage::Undefined) {
registrySettingsSteam.setValue("Language", gameLanguageToString(gameLanguage));
}
else
{
else {
registrySettingsSteam.remove("Language");
}
registrySettingsSteam.sync();
if (registrySettingsSteam.status() != QSettings::NoError)
{
if (registrySettingsSteam.status() != QSettings::NoError) {
return false;
}
#else

4
AppEnv.h

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5view Grand Theft Auto V Profile Viewer
* Copyright (C) 2016-2018 Syping
* Copyright (C) 2016-2021 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
@ -23,7 +23,7 @@
#include <QUrl>
enum class GameVersion : int { NoVersion = 0, SocialClubVersion = 1, SteamVersion = 2, BothVersions = 3 };
enum class GameLanguage : int { Undefined = 0, English = 1, French = 2, Italian = 3, German = 4, Spanish = 5, Mexican = 6, Brasilian = 7, Russian = 8, Polish = 9, Japanese = 10, SChinese = 11, TChinese = 12, Koreana = 13 };
enum class GameLanguage : int { Undefined = 0, English = 1, French = 2, Italian = 3, German = 4, Spanish = 5, Mexican = 6, Brasilian = 7, Russian = 8, Polish = 9, Japanese = 10, SChinese = 11, TChinese = 12, Korean = 13 };
class AppEnv
{

84
DatabaseThread.cpp

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5view Grand Theft Auto V Profile Viewer
* Copyright (C) 2016-2020 Syping
* Copyright (C) 2016-2021 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
@ -46,8 +46,7 @@ void DatabaseThread::run()
QObject::connect(this, SIGNAL(threadTerminated()), &threadLoop, SLOT(quit()));
while (threadRunning)
{
while (threadRunning) {
QTimer::singleShot(300000, &threadLoop, SLOT(quit()));
threadLoop.exec();
}
@ -55,10 +54,8 @@ void DatabaseThread::run()
void DatabaseThread::scanCrewReference(const QStringList &crewList, const int &requestDelay)
{
for (QString crewID : crewList)
{
if (threadRunning && crewID != QLatin1String("0"))
{
for (const QString &crewID : crewList) {
if (threadRunning && crewID != QLatin1String("0")) {
QNetworkAccessManager *netManager = new QNetworkAccessManager();
QNetworkRequest netRequest(AppEnv::getCrewFetchingUrl(crewID));
#if QT_VERSION >= 0x050600
@ -76,40 +73,36 @@ void DatabaseThread::scanCrewReference(const QStringList &crewList, const int &r
QEventLoop *downloadLoop = new QEventLoop();
QObject::connect(netReply, SIGNAL(finished()), downloadLoop, SLOT(quit()));
if (!continueLastCrew) { QObject::connect(this, SIGNAL(threadTerminated()), downloadLoop, SLOT(quit())); }
if (!continueLastCrew)
QObject::connect(this, SIGNAL(threadTerminated()), downloadLoop, SLOT(quit()));
QTimer::singleShot(30000, downloadLoop, SLOT(quit()));
downloadLoop->exec();
downloadLoop->disconnect();
delete downloadLoop;
if (netReply->isFinished())
{
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)
{
if (crewHtmlSplit1.length() >= 2) {
QStringList crewHtmlSplit2 = QString(crewHtmlSplit1.at(1)).split("</title>");
if (crewHtmlSplit2.length() >= 1)
{
if (crewHtmlSplit2.length() >= 1) {
crewName = crewHtmlSplit2.at(0);
}
}
if (!crewName.isEmpty())
{
if (!crewName.isEmpty()) {
emit crewNameFound(crewID.toInt(), crewName);
}
}
else
{
else {
netReply->abort();
}
if (threadRunning)
{
if (threadRunning) {
QEventLoop *waitingLoop = new QEventLoop();
QTimer::singleShot(requestDelay, waitingLoop, SLOT(quit()));
if (!continueLastCrew) { QObject::connect(this, SIGNAL(threadTerminated()), waitingLoop, SLOT(quit())); }
if (!continueLastCrew)
QObject::connect(this, SIGNAL(threadTerminated()), waitingLoop, SLOT(quit()));
waitingLoop->exec();
waitingLoop->disconnect();
delete waitingLoop;
@ -123,17 +116,14 @@ void DatabaseThread::scanCrewReference(const QStringList &crewList, const int &r
void DatabaseThread::scanCrewMembersList(const QStringList &crewList, const int &maxPages, const int &requestDelay)
{
for (QString crewID : crewList)
{
if (threadRunning && crewID != QLatin1String("0"))
{
for (const QString &crewID : crewList) {
if (threadRunning && crewID != QLatin1String("0")) {
int currentFail = 0;
int currentPage = 0;
int foundPlayers = 0;
int totalPlayers = 1000;
while(foundPlayers < totalPlayers && currentPage < maxPages && (continueLastCrew ? true : threadRunning))
{
while(foundPlayers < totalPlayers && currentPage < maxPages && (continueLastCrew ? true : threadRunning)) {
QNetworkAccessManager *netManager = new QNetworkAccessManager();
QNetworkRequest netRequest(AppEnv::getPlayerFetchingUrl(crewID, currentPage));
#if QT_VERSION >= 0x050600
@ -151,14 +141,14 @@ void DatabaseThread::scanCrewMembersList(const QStringList &crewList, const int
QEventLoop *downloadLoop = new QEventLoop();
QObject::connect(netReply, SIGNAL(finished()), downloadLoop, SLOT(quit()));
if (!continueLastCrew) { QObject::connect(this, SIGNAL(threadTerminated()), downloadLoop, SLOT(quit())); }
if (!continueLastCrew)
QObject::connect(this, SIGNAL(threadTerminated()), downloadLoop, SLOT(quit()));
QTimer::singleShot(30000, downloadLoop, SLOT(quit()));
downloadLoop->exec();
downloadLoop->disconnect();
delete downloadLoop;
if (netReply->isFinished())
{
if (netReply->isFinished()) {
QByteArray crewJson = netReply->readAll();
QJsonDocument crewDocument = QJsonDocument::fromJson(crewJson);
QJsonObject crewObject = crewDocument.object();
@ -166,32 +156,25 @@ void DatabaseThread::scanCrewMembersList(const QStringList &crewList, const int
if (crewMap.contains("Total")) { totalPlayers = crewMap["Total"].toInt(); }
if (crewMap.contains("Members"))
{
if (crewMap.contains("Members")) {
const QList<QVariant> memberList = crewMap["Members"].toList();
for (QVariant memberVariant : memberList)
{
for (const QVariant &memberVariant : memberList) {
QMap<QString, QVariant> memberMap = memberVariant.toMap();
if (memberMap.contains("RockstarId") && memberMap.contains("Name"))
{
if (memberMap.contains("RockstarId") && memberMap.contains("Name")) {
int RockstarId = memberMap["RockstarId"].toInt();
QString memberName = memberMap["Name"].toString();
if (!memberName.isEmpty() && RockstarId != 0)
{
if (!memberName.isEmpty() && RockstarId != 0) {
foundPlayers++;
emit playerNameFound(RockstarId, memberName);
}
}
}
}
currentPage++;
}
else
{
else {
currentFail++;
if (currentFail == maxLoadFails)
{
if (currentFail == maxLoadFails) {
currentFail = 0;
currentPage++;
}
@ -200,8 +183,7 @@ void DatabaseThread::scanCrewMembersList(const QStringList &crewList, const int
delete netReply;
delete netManager;
if (foundPlayers < totalPlayers && currentPage < maxPages && (continueLastCrew ? true : threadRunning))
{
if (foundPlayers < totalPlayers && currentPage < maxPages && (continueLastCrew ? true : threadRunning)) {
QEventLoop *waitingLoop = new QEventLoop();
QTimer::singleShot(requestDelay, waitingLoop, SLOT(quit()));
if (!continueLastCrew) { QObject::connect(this, SIGNAL(threadTerminated()), waitingLoop, SLOT(quit())); }
@ -216,10 +198,8 @@ void DatabaseThread::scanCrewMembersList(const QStringList &crewList, const int
void DatabaseThread::deleteCompatibleCrews(QStringList *crewList)
{
for (QString crewNID : *crewList)
{
if (crewDB->isCompatibleCrew(crewNID))
{
for (const QString &crewNID : *crewList) {
if (crewDB->isCompatibleCrew(crewNID)) {
crewList->removeAll(crewNID);
}
}
@ -228,10 +208,8 @@ void DatabaseThread::deleteCompatibleCrews(QStringList *crewList)
QStringList DatabaseThread::deleteCompatibleCrews(const QStringList &crewList)
{
QStringList crewListR = crewList;
for (QString crewNID : crewListR)
{
if (crewDB->isCompatibleCrew(crewNID))
{
for (const QString &crewNID : crewListR) {
if (crewDB->isCompatibleCrew(crewNID)) {
crewListR.removeAll(crewNID);
}
}

15
GlobalString.cpp

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5view Grand Theft Auto V Profile Viewer
* Copyright (C) 2016-2020 Syping
* Copyright (C) 2016-2021 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
@ -28,7 +28,6 @@
GlobalString::GlobalString()
{
}
QMap<QString, QString> GlobalString::getGlobalMap()
@ -39,8 +38,7 @@ QMap<QString, QString> GlobalString::getGlobalMap()
globalFile.setIniCodec("UTF-8");
#endif
globalFile.beginGroup("Global");
for (const QString &globalStr : globalFile.childKeys())
{
for (const QString &globalStr : globalFile.childKeys()) {
globalMap[globalStr] = globalFile.value(globalStr, globalStr).toString();
}
globalFile.endGroup();
@ -56,9 +54,9 @@ QString GlobalString::getString(QString valueStr, bool *ok)
#endif
globalFile.beginGroup("Global");
QStringList globalStrList = globalFile.childKeys();
if (globalStrList.contains(valueStr))
{
if (ok != nullptr) *ok = true;
if (globalStrList.contains(valueStr)) {
if (ok != nullptr)
*ok = true;
globalString = globalFile.value(valueStr, valueStr).toString();
}
globalFile.endGroup();
@ -69,8 +67,7 @@ QString GlobalString::getLanguageFile()
{
QString language = getLanguage();
QString languageFile = ":/global/global." % language % ".ini";
if (!QFileInfo(languageFile).exists())
{
if (!QFileInfo::exists(languageFile)) {
languageFile = ":/global/global.en.ini";
}
return languageFile;

284
TranslationClass.cpp

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5view Grand Theft Auto V Profile Viewer
* Copyright (C) 2017 Syping
* Copyright (C) 2017-2021 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
@ -48,19 +48,20 @@ void TranslationClass::initUserLanguage()
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")
{
if (isLangLoaded) {
unloadTranslation(app);
}
else {
currentLangIndex = 0;
}
const QString exLangPath = AppEnv::getExLangFolder();
const QString inLangPath = AppEnv::getInLangFolder();
if (userLanguage == "en" || userLanguage == "en_GB") {
currentLanguage = "en_GB";
if (loadQtTranslation_p(exLangPath, &exQtTranslator))
{
if (loadQtTranslation_p(exLangPath, &exQtTranslator)) {
app->installTranslator(&exQtTranslator);
}
else if (loadQtTranslation_p(inLangPath, &inQtTranslator))
{
else if (loadQtTranslation_p(inLangPath, &inQtTranslator)) {
app->installTranslator(&inQtTranslator);
}
#if QT_VERSION >= 0x060000
@ -77,33 +78,28 @@ void TranslationClass::loadTranslation(QApplication *app)
bool externalEnglishMode = false;
bool loadInternalLang = false;
bool trLoadSuccess = false;
if (isUserLanguageSystem_p())
{
if (isUserLanguageSystem_p()) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadExSystemLanguage";
#endif
trLoadSuccess = loadSystemTranslation_p(exLangPath, &exAppTranslator);
}
else
{
else {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadExUserLanguage";
#endif
trLoadSuccess = loadUserTranslation_p(exLangPath, &exAppTranslator);
if (!trLoadSuccess)
{
if (!trLoadSuccess) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadInUserLanguage";
#endif
trLoadSuccess = loadUserTranslation_p(inLangPath, &inAppTranslator);
if (!trLoadSuccess)
{
if (!trLoadSuccess) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadUserLanguageFailed";
#endif
}
else
{
else {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadUserLanguageSuccess";
#endif
@ -111,18 +107,16 @@ void TranslationClass::loadTranslation(QApplication *app)
isLangLoaded = true;
}
}
else
{
else {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadUserLanguageSuccess";
#endif
isLangLoaded = true;
}
}
if (trLoadSuccess)
{
if (currentLangIndex != 0 || isEnglishMode) // Don't install the language until we know we not have a better language for the user
{
if (trLoadSuccess) {
// Don't install the language until we know we not have a better language for the user
if (currentLangIndex != 0 || isEnglishMode) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "externalLanguageReady" << currentLanguage;
#endif
@ -130,25 +124,20 @@ void TranslationClass::loadTranslation(QApplication *app)
externalLanguageStr = currentLanguage;
externalLanguageReady = true;
}
else
{
else {
#ifdef GTA5SYNC_DEBUG
qDebug() << "installTranslation";
#endif
if (loadInternalLang)
{
if (loadInternalLang) {
app->installTranslator(&inAppTranslator);
}
else
{
else {
app->installTranslator(&exAppTranslator);
}
if (loadQtTranslation_p(exLangPath, &exQtTranslator))
{
if (loadQtTranslation_p(exLangPath, &exQtTranslator)) {
app->installTranslator(&exQtTranslator);
}
else if (loadQtTranslation_p(inLangPath, &inQtTranslator))
{
else if (loadQtTranslation_p(inLangPath, &inQtTranslator)) {
app->installTranslator(&inQtTranslator);
}
#if QT_VERSION >= 0x060000
@ -159,8 +148,7 @@ void TranslationClass::loadTranslation(QApplication *app)
isLangLoaded = true;
}
}
if (externalLanguageReady)
{
if (externalLanguageReady) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadInSystemLanguage";
#endif
@ -170,18 +158,15 @@ void TranslationClass::loadTranslation(QApplication *app)
qDebug() << "externalLangIndex" << externalLangIndex << "internalLangIndex" << currentLangIndex;
qDebug() << "externalEnglishMode" << externalEnglishMode << "internalEnglishMode" << isEnglishMode;
#endif
if ((trLoadSuccess && externalLangIndex > currentLangIndex) || (trLoadSuccess && externalEnglishMode && !isEnglishMode))
{
if ((trLoadSuccess && externalLangIndex > currentLangIndex) || (trLoadSuccess && externalEnglishMode && !isEnglishMode)) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "installInternalTranslation";
#endif
app->installTranslator(&inAppTranslator);
if (loadQtTranslation_p(exLangPath, &exQtTranslator))
{
if (loadQtTranslation_p(exLangPath, &exQtTranslator)) {
app->installTranslator(&exQtTranslator);
}
else if (loadQtTranslation_p(inLangPath, &inQtTranslator))
{
else if (loadQtTranslation_p(inLangPath, &inQtTranslator)) {
app->installTranslator(&inQtTranslator);
}
#if QT_VERSION >= 0x060000
@ -191,20 +176,17 @@ void TranslationClass::loadTranslation(QApplication *app)
#endif
isLangLoaded = true;
}
else
{
else {
#ifdef GTA5SYNC_DEBUG
qDebug() << "installExternalTranslation";
#endif
isEnglishMode = externalEnglishMode;
currentLanguage = externalLanguageStr;
app->installTranslator(&exAppTranslator);
if (loadQtTranslation_p(exLangPath, &exQtTranslator))
{
if (loadQtTranslation_p(exLangPath, &exQtTranslator)) {
app->installTranslator(&exQtTranslator);
}
else if (loadQtTranslation_p(inLangPath, &inQtTranslator))
{
else if (loadQtTranslation_p(inLangPath, &inQtTranslator)) {
app->installTranslator(&inQtTranslator);
}
#if QT_VERSION >= 0x060000
@ -215,24 +197,20 @@ void TranslationClass::loadTranslation(QApplication *app)
isLangLoaded = true;
}
}
else if (!isLangLoaded)
{
else if (!isLangLoaded) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadInSystemLanguage";
#endif
trLoadSuccess = loadSystemTranslation_p(inLangPath, &inAppTranslator);
if (trLoadSuccess)
{
if (trLoadSuccess) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "installInternalTranslation";
#endif
app->installTranslator(&inAppTranslator);
if (loadQtTranslation_p(exLangPath, &exQtTranslator))
{
if (loadQtTranslation_p(exLangPath, &exQtTranslator)) {
app->installTranslator(&exQtTranslator);
}
else if (loadQtTranslation_p(inLangPath, &inQtTranslator))
{
else if (loadQtTranslation_p(inLangPath, &inQtTranslator)) {
app->installTranslator(&inQtTranslator);
}
#if QT_VERSION >= 0x060000
@ -242,18 +220,15 @@ void TranslationClass::loadTranslation(QApplication *app)
#endif
isLangLoaded = true;
}
else if (!trLoadSuccess)
{
else if (!trLoadSuccess) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "fallbackToDefaultApplicationLanguage";
#endif
currentLanguage = "en_GB";
if (loadQtTranslation_p(exLangPath, &exQtTranslator))
{
if (loadQtTranslation_p(exLangPath, &exQtTranslator)) {
app->installTranslator(&exQtTranslator);
}
else if (loadQtTranslation_p(inLangPath, &inQtTranslator))
{
else if (loadQtTranslation_p(inLangPath, &inQtTranslator)) {
app->installTranslator(&inQtTranslator);
}
#if QT_VERSION >= 0x060000
@ -266,30 +241,24 @@ void TranslationClass::loadTranslation(QApplication *app)
}
#else // New qconf loading method
bool trLoadSuccess;
if (isUserLanguageSystem_p())
{
if (isUserLanguageSystem_p()) {
trLoadSuccess = loadSystemTranslation_p(inLangPath, &inAppTranslator);
}
else
{
else {
trLoadSuccess = loadUserTranslation_p(inLangPath, &inAppTranslator);
}
if (!trLoadSuccess && !isUserLanguageSystem_p())
{
if (!trLoadSuccess && !isUserLanguageSystem_p()) {
trLoadSuccess = loadSystemTranslation_p(inLangPath, &inAppTranslator);
}
if (trLoadSuccess)
{
if (trLoadSuccess) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "installTranslation" << currentLanguage;
#endif
app->installTranslator(&inAppTranslator);
if (loadQtTranslation_p(exLangPath, &exQtTranslator))
{
if (loadQtTranslation_p(exLangPath, &exQtTranslator)) {
app->installTranslator(&exQtTranslator);
}
else if (loadQtTranslation_p(inLangPath, &inQtTranslator))
{
else if (loadQtTranslation_p(inLangPath, &inQtTranslator)) {
app->installTranslator(&inQtTranslator);
}
#if QT_VERSION >= 0x060000
@ -332,21 +301,17 @@ bool TranslationClass::loadSystemTranslation_p(const QString &langPath, QTransla
qDebug() << "loadSystemTranslation_p";
#endif
int currentLangCounter = 0;
for (QString languageName : QLocale::system().uiLanguages())
{
for (const QString &languageName : QLocale::system().uiLanguages()) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguage" << languageName;
#endif
QStringList langList = QString(languageName).replace("-","_").split("_");
if (langList.length() == 2)
{
const QStringList langList = QString(languageName).replace("-","_").split("_");
if (langList.length() == 2) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFile" << QString(langPath % "/gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm");
#endif
if (QFile::exists(langPath % "/gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm"))
{
if (appTranslator->load(langPath % "/gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm"))
{
if (QFile::exists(langPath % "/gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm")) {
if (appTranslator->load(langPath % "/gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm")) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFileSuccess" << QString(langPath % "/gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm");
#endif
@ -359,10 +324,8 @@ bool TranslationClass::loadSystemTranslation_p(const QString &langPath, QTransla
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFile" << QString(langPath % "/gta5sync_" % langList.at(0) % ".qm");
#endif
if (QFile::exists(langPath % "/gta5sync_" % langList.at(0) % ".qm"))
{
if (appTranslator->load(langPath % "/gta5sync_" % langList.at(0) % ".qm"))
{
if (QFile::exists(langPath % "/gta5sync_" % langList.at(0) % ".qm")) {
if (appTranslator->load(langPath % "/gta5sync_" % langList.at(0) % ".qm")) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFileSuccess" << QString(langPath % "/gta5sync_" % langList.at(0) % ".qm");
#endif
@ -371,8 +334,7 @@ bool TranslationClass::loadSystemTranslation_p(const QString &langPath, QTransla
currentLangIndex = currentLangCounter;
return true;
}
else if (langList.at(0) == "en")
{
else if (langList.at(0) == "en") {
#ifdef GTA5SYNC_DEBUG
qDebug() << "languageEnglishMode index" << currentLangCounter;
#endif
@ -382,8 +344,7 @@ bool TranslationClass::loadSystemTranslation_p(const QString &langPath, QTransla
return true;
}
}
else if (langList.at(0) == "en")
{
else if (langList.at(0) == "en") {
#ifdef GTA5SYNC_DEBUG
qDebug() << "languageEnglishMode index" << currentLangCounter;
#endif
@ -393,15 +354,12 @@ bool TranslationClass::loadSystemTranslation_p(const QString &langPath, QTransla
return true;
}
}
else if (langList.length() == 1)
{
else if (langList.length() == 1) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFile" << QString(langPath % "/gta5sync_" % langList.at(0) % ".qm");
#endif
if (QFile::exists(langPath % "/gta5sync_" % langList.at(0) % ".qm"))
{
if (appTranslator->load(langPath % "/gta5sync_" % langList.at(0) % ".qm"))
{
if (QFile::exists(langPath % "/gta5sync_" % langList.at(0) % ".qm")) {
if (appTranslator->load(langPath % "/gta5sync_" % langList.at(0) % ".qm")) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFileSuccess" << QString(langPath % "/gta5sync_" % langList.at(0) % ".qm");
#endif
@ -425,17 +383,14 @@ bool TranslationClass::loadUserTranslation_p(const QString &langPath, QTranslato
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadUserTranslation_p";
#endif
QString languageName = userLanguage;
QStringList langList = QString(languageName).replace("-","_").split("_");
if (langList.length() == 2)
{
const QString languageName = userLanguage;
const QStringList langList = QString(languageName).replace("-","_").split("_");
if (langList.length() == 2) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFile" << QString(langPath % "/gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm");
#endif
if (QFile::exists(langPath % "/gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm"))
{
if (appTranslator->load(langPath % "/gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm"))
{
if (QFile::exists(langPath % "/gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm")) {
if (appTranslator->load(langPath % "/gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm")) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFileSuccess" << QString(langPath % "/gta5sync_" % langList.at(0) % "_" % langList.at(1) % ".qm");
#endif
@ -446,10 +401,8 @@ bool TranslationClass::loadUserTranslation_p(const QString &langPath, QTranslato
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFile" << QString(langPath % "/gta5sync_" % langList.at(0) % ".qm");
#endif
if (QFile::exists(langPath % "/gta5sync_" % langList.at(0) % ".qm"))
{
if (appTranslator->load(langPath % "/gta5sync_" % langList.at(0) % ".qm"))
{
if (QFile::exists(langPath % "/gta5sync_" % langList.at(0) % ".qm")) {
if (appTranslator->load(langPath % "/gta5sync_" % langList.at(0) % ".qm")) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFileSuccess" << QString(langPath % "/gta5sync_" % langList.at(0) % ".qm");
#endif
@ -458,15 +411,12 @@ bool TranslationClass::loadUserTranslation_p(const QString &langPath, QTranslato
}
}
}
else if (langList.length() == 1)
{
else if (langList.length() == 1) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFile" << QString(langPath % "/gta5sync_" % langList.at(0) % ".qm");
#endif
if (QFile::exists(langPath % "/gta5sync_" % langList.at(0) % ".qm"))
{
if (appTranslator->load(langPath % "/gta5sync_" % langList.at(0) % ".qm"))
{
if (QFile::exists(langPath % "/gta5sync_" % langList.at(0) % ".qm")) {
if (appTranslator->load(langPath % "/gta5sync_" % langList.at(0) % ".qm")) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadLanguageFileSuccess" << QString(langPath % "/gta5sync_" % langList.at(0) % ".qm");
#endif
@ -483,17 +433,14 @@ bool TranslationClass::loadQtTranslation_p(const QString &langPath, QTranslator
#ifdef GTA5SYNC_DEBUG
qDebug() << "loadQtTranslation_p" << currentLanguage;
#endif
QString languageName = currentLanguage;
QStringList langList = QString(languageName).replace("-","_").split("_");
if (langList.length() == 2)
{
const QString languageName = currentLanguage;
const 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"))
{
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
@ -503,10 +450,8 @@ bool TranslationClass::loadQtTranslation_p(const QString &langPath, QTranslator
#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"))
{
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
@ -514,15 +459,12 @@ bool TranslationClass::loadQtTranslation_p(const QString &langPath, QTranslator
}
}
}
else if (langList.length() == 1)
{
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"))
{
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
@ -541,49 +483,44 @@ bool TranslationClass::isUserLanguageSystem_p()
QString TranslationClass::getCurrentAreaLanguage()
{
const QStringList areaTranslations = listAreaTranslations();
if (userAreaLanguage == "Auto" || userAreaLanguage.trimmed().isEmpty())
{
GameLanguage gameLanguage = AppEnv::getGameLanguage(AppEnv::getGameVersion());
if (gameLanguage == GameLanguage::Undefined)
{
if (userAreaLanguage == "Auto" || userAreaLanguage.trimmed().isEmpty()) {
const GameLanguage gameLanguage = AppEnv::getGameLanguage(AppEnv::getGameVersion());
if (gameLanguage == GameLanguage::Undefined) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "autoAreaLanguageModeInterface";
#endif
QString langCode = QString(currentLanguage).replace("-", "_");
if (areaTranslations.contains(langCode))
{
if (areaTranslations.contains(langCode)) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "autoAreaLanguageSelected" << langCode;
#endif
return langCode;
}
else if (langCode.contains("_"))
{
else if (langCode.contains("_")) {
langCode = langCode.split("_").at(0);
if (!areaTranslations.contains(langCode)) goto outputDefaultLanguage;
if (!areaTranslations.contains(langCode))
goto outputDefaultLanguage;
#ifdef GTA5SYNC_DEBUG
qDebug() << "autoAreaLanguageSelected" << langCode;
#endif
return langCode;
}
}
else
{
else {
#ifdef GTA5SYNC_DEBUG
qDebug() << "autoAreaLanguageModeGame";
#endif
QString langCode = AppEnv::gameLanguageToString(gameLanguage).replace("-", "_");
if (areaTranslations.contains(langCode))
{
if (areaTranslations.contains(langCode)) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "autoAreaLanguageSelected" << langCode;
#endif
return langCode;
}
else if (langCode.contains("_"))
{
else if (langCode.contains("_")) {
langCode = langCode.split("_").at(0);
if (!areaTranslations.contains(langCode)) goto outputDefaultLanguage;
if (!areaTranslations.contains(langCode))
goto outputDefaultLanguage;
#ifdef GTA5SYNC_DEBUG
qDebug() << "autoAreaLanguageSelected" << langCode;
#endif
@ -591,17 +528,16 @@ QString TranslationClass::getCurrentAreaLanguage()
}
}
}
else if (areaTranslations.contains(userAreaLanguage))
{
else if (areaTranslations.contains(userAreaLanguage)) {
#ifdef GTA5SYNC_DEBUG
qDebug() << "userAreaLanguageSelected" << userAreaLanguage;
#endif
return userAreaLanguage;
}
else if (userAreaLanguage.contains("_"))
{
QString langCode = QString(userAreaLanguage).replace("-", "_").split("_").at(0);
if (!areaTranslations.contains(langCode)) goto outputDefaultLanguage;
else if (userAreaLanguage.contains("_")) {
const QString langCode = QString(userAreaLanguage).replace("-", "_").split("_").at(0);
if (!areaTranslations.contains(langCode))
goto outputDefaultLanguage;
#ifdef GTA5SYNC_DEBUG
qDebug() << "userAreaLanguageSelected" << langCode;
#endif
@ -626,8 +562,7 @@ bool TranslationClass::isLanguageLoaded()
void TranslationClass::unloadTranslation(QApplication *app)
{
if (isLangLoaded)
{
if (isLangLoaded) {
#ifndef GTA5SYNC_QCONF
app->removeTranslator(&exAppTranslator);
app->removeTranslator(&exQtTranslator);
@ -650,30 +585,21 @@ void TranslationClass::unloadTranslation(QApplication *app)
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();
const QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, country);
if (!locales.isEmpty()) {
const QStringList localeStrList = locales.at(0).name().split("_");
if (localeStrList.length() >= 2) {
return localeStrList.at(1).toLower();
}
}
return QString();
}
QString TranslationClass::getCountryCode(QLocale locale)
{
QStringList localeStrList = locale.name().split("_");
if (localeStrList.length() >= 2)
{
if (localeStrList.length() >= 2) {
return localeStrList.at(1).toLower();
}
else
{
return QString();
}
return QString();
}

69
main.cpp

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5view Grand Theft Auto V Profile Viewer
* Copyright (C) 2016-2019 Syping
* Copyright (C) 2016-2021 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
@ -94,7 +94,6 @@ int main(int argc, char *argv[])
settings.sync();
#endif
bool isFirstStart = settings.value("IsFirstStart", true).toBool();
bool customStyle = settings.value("CustomStyle", false).toBool();
if (customStyle) {
const QString appStyle = settings.value("AppStyle", "Default").toString();
@ -130,28 +129,10 @@ int main(int argc, char *argv[])
Telemetry->work();
#endif
if (!applicationArgs.contains("--skip-firststart"))