2017-10-09 08:35:48 +02:00
/*****************************************************************************
2018-05-24 22:32:00 +02:00
* gta5view Grand Theft Auto V Profile Viewer
2021-01-27 14:35:42 +01:00
* Copyright ( C ) 2016 - 2021 Syping
2017-10-09 08:35:48 +02:00
*
* 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"
2021-04-02 19:51:05 +02:00
# include "wrapper.h"
2017-10-09 08:35:48 +02:00
# include "AppEnv.h"
# include "config.h"
# include <QStringBuilder>
2018-01-16 00:13:08 +01:00
# include <QJsonDocument>
2017-11-22 14:59:40 +01:00
# include <QStyleFactory>
2017-10-09 08:35:48 +02:00
# include <QApplication>
2018-01-16 00:13:08 +01:00
# include <QJsonObject>
2017-10-09 08:35:48 +02:00
# include <QFileDialog>
2020-11-17 10:46:37 +01:00
# include <QFontDialog>
2017-10-09 08:35:48 +02:00
# include <QMessageBox>
# include <QStringList>
2018-01-16 00:13:08 +01:00
# include <QClipboard>
2017-10-09 08:35:48 +02:00
# include <QLocale>
# include <QString>
2018-01-16 00:13:08 +01:00
# include <QTimer>
2017-10-09 08:35:48 +02:00
# include <QDebug>
# include <QList>
# include <QDir>
2020-04-24 05:36:11 +02:00
# if QT_VERSION >= 0x050000
# include <QScreen>
# else
# include <QDesktopWidget>
# endif
2018-01-16 00:13:08 +01:00
# ifdef GTA5SYNC_TELEMETRY
# include "TelemetryClass.h"
# endif
2017-10-09 08:35:48 +02:00
OptionsDialog : : OptionsDialog ( ProfileDatabase * profileDB , QWidget * parent ) :
QDialog ( parent ) , profileDB ( profileDB ) ,
ui ( new Ui : : OptionsDialog )
{
// Set Window Flags
2021-02-15 23:12:44 +01:00
# if QT_VERSION >= 0x050900
setWindowFlag ( Qt : : WindowContextHelpButtonHint , false ) ;
# else
2017-10-09 08:35:48 +02:00
setWindowFlags ( windowFlags ( ) ^ Qt : : WindowContextHelpButtonHint ) ;
2021-02-15 23:12:44 +01:00
# endif
2017-10-09 08:35:48 +02:00
// Setup User Interface
ui - > setupUi ( this ) ;
ui - > tabWidget - > setCurrentIndex ( 0 ) ;
ui - > labPicCustomRes - > setVisible ( false ) ;
2018-06-07 17:07:30 +02:00
ui - > cmdCancel - > setDefault ( true ) ;
2018-01-16 00:13:08 +01:00
ui - > cmdCancel - > setFocus ( ) ;
2017-10-09 08:35:48 +02:00
2020-04-24 05:36:11 +02:00
# if QT_VERSION >= 0x050000
qreal screenRatioPR = AppEnv : : screenRatioPR ( ) ;
QRect desktopResolution = QApplication : : primaryScreen ( ) - > geometry ( ) ;
int desktopSizeWidth = qRound ( ( double ) desktopResolution . width ( ) * screenRatioPR ) ;
int desktopSizeHeight = qRound ( ( double ) desktopResolution . height ( ) * screenRatioPR ) ;
# else
2017-12-12 04:45:46 +01:00
QRect desktopResolution = QApplication : : desktop ( ) - > screenGeometry ( this ) ;
2017-10-09 08:35:48 +02:00
int desktopSizeWidth = desktopResolution . width ( ) ;
int desktopSizeHeight = desktopResolution . height ( ) ;
2020-04-24 05:36:11 +02:00
# endif
2017-10-09 08:35:48 +02:00
aspectRatio = Qt : : KeepAspectRatio ;
2020-11-25 00:36:12 +01:00
defExportSize = SnapmaticPicture : : getSnapmaticResolution ( ) ;
2017-10-09 08:35:48 +02:00
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 ( ) ) ) ) ;
2018-01-11 08:41:00 +01:00
// Set Icon for OK Button
2021-04-02 19:51:05 +02:00
if ( QIcon : : hasThemeIcon ( " dialog-ok " ) ) {
2017-10-09 08:35:48 +02:00
ui - > cmdOK - > setIcon ( QIcon : : fromTheme ( " dialog-ok " ) ) ;
}
2021-04-02 19:51:05 +02:00
else if ( QIcon : : hasThemeIcon ( " gtk-ok " ) ) {
2018-01-11 08:41:00 +01:00
ui - > cmdOK - > setIcon ( QIcon : : fromTheme ( " gtk-ok " ) ) ;
}
// Set Icon for Cancel Button
2021-04-02 19:51:05 +02:00
if ( QIcon : : hasThemeIcon ( " dialog-cancel " ) ) {
2017-10-09 08:35:48 +02:00
ui - > cmdCancel - > setIcon ( QIcon : : fromTheme ( " dialog-cancel " ) ) ;
}
2021-04-02 19:51:05 +02:00
else if ( QIcon : : hasThemeIcon ( " gtk-cancel " ) ) {
2018-01-11 08:41:00 +01:00
ui - > cmdCancel - > setIcon ( QIcon : : fromTheme ( " gtk-cancel " ) ) ;
}
2017-10-09 08:35:48 +02:00
setupTreeWidget ( ) ;
setupLanguageBox ( ) ;
setupRadioButtons ( ) ;
setupDefaultProfile ( ) ;
setupPictureSettings ( ) ;
setupCustomGTAFolder ( ) ;
2017-11-22 14:59:40 +01:00
setupInterfaceSettings ( ) ;
2018-01-16 00:13:08 +01:00
setupStatisticsSettings ( ) ;
2017-10-09 08:35:48 +02:00
setupSnapmaticPictureViewer ( ) ;
2018-07-28 04:55:55 +02:00
setupWindowsGameSettings ( ) ;
2017-10-09 08:35:48 +02:00
2017-12-17 13:03:43 +01:00
# ifndef Q_QS_ANDROID
2017-11-22 14:59:40 +01:00
// DPI calculation
qreal screenRatio = AppEnv : : screenRatio ( ) ;
resize ( 435 * screenRatio , 405 * screenRatio ) ;
2017-12-17 13:03:43 +01:00
# endif
2017-11-22 14:59:40 +01:00
2020-11-23 03:47:17 +01:00
ui - > rbModern - > setText ( ui - > rbModern - > text ( ) . arg ( GTA5SYNC_APPSTR ) ) ;
ui - > rbClassic - > setText ( ui - > rbClassic - > text ( ) . arg ( GTA5SYNC_APPSTR ) ) ;
2018-07-28 04:55:55 +02:00
setWindowTitle ( windowTitle ( ) . arg ( GTA5SYNC_APPSTR ) ) ;
2017-10-09 08:35:48 +02:00
}
OptionsDialog : : ~ OptionsDialog ( )
{
delete settings ;
2017-10-21 05:59:10 +02:00
qDeleteAll ( playerItems . begin ( ) , playerItems . end ( ) ) ;
playerItems . clear ( ) ;
2017-10-09 08:35:48 +02:00
delete ui ;
}
void OptionsDialog : : setupTreeWidget ( )
{
2020-08-25 14:07:42 +02:00
const QStringList players = profileDB - > getPlayers ( ) ;
if ( players . length ( ) ! = 0 ) {
2021-04-02 19:51:05 +02:00
for ( auto it = players . constBegin ( ) ; it ! = players . constEnd ( ) ; it + + ) {
2020-08-25 14:07:42 +02:00
bool ok ;
int playerID = it - > toInt ( & ok ) ;
2021-04-02 19:51:05 +02:00
if ( ok ) {
const QString playerName = profileDB - > getPlayerName ( playerID ) ;
2020-08-25 14:07:42 +02:00
QStringList playerTreeViewList ;
playerTreeViewList + = * it ;
playerTreeViewList + = playerName ;
QTreeWidgetItem * playerItem = new QTreeWidgetItem ( playerTreeViewList ) ;
ui - > twPlayers - > addTopLevelItem ( playerItem ) ;
playerItems + = playerItem ;
}
2017-10-09 08:35:48 +02:00
}
2020-08-25 14:07:42 +02:00
ui - > twPlayers - > sortItems ( 1 , Qt : : AscendingOrder ) ;
}
else {
ui - > tabWidget - > removeTab ( ui - > tabWidget - > indexOf ( ui - > tabPlayers ) ) ;
2017-10-09 08:35:48 +02:00
}
}
void OptionsDialog : : setupLanguageBox ( )
{
settings - > beginGroup ( " Interface " ) ;
2017-10-21 05:59:10 +02:00
currentLanguage = settings - > value ( " Language " , " System " ) . toString ( ) ;
2017-11-12 15:58:59 +01:00
currentAreaLanguage = settings - > value ( " AreaLanguage " , " Auto " ) . toString ( ) ;
2017-10-09 08:35:48 +02:00
settings - > endGroup ( ) ;
2021-04-02 19:51:05 +02:00
const QString cbSysStr = tr ( " %1 (Language priority) " , " First language a person can talk with a different person/application. \" Native \" or \" Not Native \" . " ) . arg ( tr ( " System " ,
2018-07-28 04:55:55 +02:00
" System in context of System default " ) ) ;
2020-09-26 16:12:55 +02:00
# ifdef Q_OS_WIN
2018-07-28 04:55:55 +02:00
QString cbAutoStr ;
2021-04-02 19:51:05 +02:00
if ( AppEnv : : getGameLanguage ( AppEnv : : getGameVersion ( ) ) ! = GameLanguage : : Undefined ) {
2018-07-28 04:55:55 +02:00
cbAutoStr = tr ( " %1 (Game language) " , " Next closest language compared to the Game settings " ) . arg ( tr ( " Auto " , " Automatic language choice. " ) ) ;
}
2021-04-02 19:51:05 +02:00
else {
2018-07-28 04:55:55 +02:00
cbAutoStr = tr ( " %1 (Closest to Interface) " , " Next closest language compared to the Interface " ) . arg ( tr ( " Auto " , " Automatic language choice. " ) ) ;
}
# else
2021-04-02 19:51:05 +02:00
const QString cbAutoStr = tr ( " %1 (Closest to Interface) " , " Next closest language compared to the Interface " ) . arg ( tr ( " Auto " , " Automatic language choice. " ) ) ;
2018-07-28 04:55:55 +02:00
# endif
2017-10-09 08:35:48 +02:00
ui - > cbLanguage - > addItem ( cbSysStr , " System " ) ;
2017-11-12 15:58:59 +01:00
ui - > cbAreaLanguage - > addItem ( cbAutoStr , " Auto " ) ;
2017-10-09 08:35:48 +02:00
QStringList availableLanguages ;
availableLanguages < < QString ( " en_GB " ) ;
# ifndef GTA5SYNC_QCONF
2017-11-12 15:58:59 +01:00
availableLanguages < < TranslationClass : : listTranslations ( AppEnv : : getExLangFolder ( ) ) ;
2017-10-09 08:35:48 +02:00
# endif
2017-11-12 15:58:59 +01:00
availableLanguages < < TranslationClass : : listTranslations ( AppEnv : : getInLangFolder ( ) ) ;
2017-10-09 08:35:48 +02:00
availableLanguages . removeDuplicates ( ) ;
availableLanguages . sort ( ) ;
2021-04-02 19:51:05 +02:00
for ( const QString & lang : qAsConst ( availableLanguages ) ) {
2017-10-09 08:35:48 +02:00
QLocale langLocale ( lang ) ;
2021-04-02 19:51:05 +02:00
const QString cbLangStr = langLocale . nativeLanguageName ( ) % " ( " % langLocale . nativeCountryName ( ) % " ) [ " % lang % " ] " ;
const QString langIconPath = AppEnv : : getImagesFolder ( ) % " /flag- " % TranslationClass : : getCountryCode ( langLocale ) % " .png " ;
2017-10-09 08:35:48 +02:00
2021-04-02 19:51:05 +02:00
if ( QFile : : exists ( langIconPath ) ) {
ui - > cbLanguage - > addItem ( QIcon ( langIconPath ) , cbLangStr , lang ) ;
}
else {
ui - > cbLanguage - > addItem ( cbLangStr , lang ) ;
}
if ( currentLanguage = = lang ) {
2017-10-09 08:35:48 +02:00
# if QT_VERSION >= 0x050000
ui - > cbLanguage - > setCurrentText ( cbLangStr ) ;
# else
int indexOfLang = ui - > cbLanguage - > findText ( cbLangStr ) ;
ui - > cbLanguage - > setCurrentIndex ( indexOfLang ) ;
# endif
}
}
2017-11-12 15:58:59 +01:00
QString aCurrentLanguage = QString ( " en_GB " ) ;
2021-04-02 19:51:05 +02:00
if ( Translator - > isLanguageLoaded ( ) )
aCurrentLanguage = Translator - > getCurrentLanguage ( ) ;
2017-11-12 15:58:59 +01:00
QLocale currentLocale = QLocale ( aCurrentLanguage ) ;
ui - > labCurrentLanguage - > setText ( tr ( " Current: %1 " ) . arg ( currentLocale . nativeLanguageName ( ) % " ( " % currentLocale . nativeCountryName ( ) % " ) [ " % aCurrentLanguage % " ] " ) ) ;
availableLanguages . clear ( ) ;
availableLanguages < < TranslationClass : : listAreaTranslations ( ) ;
availableLanguages . removeDuplicates ( ) ;
availableLanguages . sort ( ) ;
2021-04-02 19:51:05 +02:00
for ( const QString & lang : qAsConst ( availableLanguages ) ) {
2017-11-12 15:58:59 +01:00
// correcting Language Location if possible
QString aLang = lang ;
2021-03-26 14:58:54 +01:00
if ( QFile : : exists ( " :/global/global. " % lang % " .loc " ) ) {
2017-11-12 15:58:59 +01:00
QFile locFile ( " :/global/global. " % lang % " .loc " ) ;
2021-03-26 14:58:54 +01:00
if ( locFile . open ( QFile : : ReadOnly ) ) {
2017-11-12 15:58:59 +01:00
aLang = QString : : fromUtf8 ( locFile . readLine ( ) ) . trimmed ( ) ;
locFile . close ( ) ;
}
}
QLocale langLocale ( aLang ) ;
2021-04-02 19:51:05 +02:00
const QString cbLangStr = langLocale . nativeLanguageName ( ) % " ( " % langLocale . nativeCountryName ( ) % " ) [ " % aLang % " ] " ;
ui - > cbAreaLanguage - > addItem ( cbLangStr , lang ) ;
2021-03-26 14:58:54 +01:00
if ( currentAreaLanguage = = lang ) {
2017-11-12 15:58:59 +01:00
# if QT_VERSION >= 0x050000
ui - > cbAreaLanguage - > setCurrentText ( cbLangStr ) ;
# else
int indexOfLang = ui - > cbAreaLanguage - > findText ( cbLangStr ) ;
ui - > cbAreaLanguage - > setCurrentIndex ( indexOfLang ) ;
# endif
}
}
2018-01-16 00:13:08 +01:00
QString aCurrentAreaLanguage = Translator - > getCurrentAreaLanguage ( ) ;
2021-03-26 14:58:54 +01:00
if ( QFile : : exists ( " :/global/global. " % aCurrentAreaLanguage % " .loc " ) ) {
2018-02-05 10:33:22 +01:00
qDebug ( ) < < " locFile found " ;
QFile locFile ( " :/global/global. " % aCurrentAreaLanguage % " .loc " ) ;
2021-04-02 19:51:05 +02:00
if ( locFile . open ( QFile : : ReadOnly ) ) {
2017-11-12 15:58:59 +01:00
aCurrentAreaLanguage = QString : : fromUtf8 ( locFile . readLine ( ) ) . trimmed ( ) ;
locFile . close ( ) ;
}
}
currentLocale = QLocale ( aCurrentAreaLanguage ) ;
ui - > labCurrentAreaLanguage - > setText ( tr ( " Current: %1 " ) . arg ( currentLocale . nativeLanguageName ( ) % " ( " % currentLocale . nativeCountryName ( ) % " ) [ " % aCurrentAreaLanguage % " ] " ) ) ;
2017-10-09 08:35:48 +02:00
}
void OptionsDialog : : setupRadioButtons ( )
{
bool contentModeOk ;
settings - > beginGroup ( " Profile " ) ;
contentMode = settings - > value ( " ContentMode " , 0 ) . toInt ( & contentModeOk ) ;
settings - > endGroup ( ) ;
2021-03-26 14:58:54 +01:00
if ( contentModeOk ) {
switch ( contentMode ) {
2017-10-12 22:21:45 +02:00
case 0 :
2020-11-23 03:47:17 +01:00
case 20 :
ui - > rbModern - > setChecked ( true ) ;
2017-10-12 22:21:45 +02:00
break ;
case 1 :
case 2 :
2020-11-23 03:47:17 +01:00
case 21 :
ui - > rbModern - > setChecked ( true ) ;
ui - > cbDoubleclick - > setChecked ( true ) ;
2017-10-12 22:21:45 +02:00
break ;
2020-11-23 03:47:17 +01:00
case 10 :
ui - > rbClassic - > setChecked ( true ) ;
2020-11-25 00:36:12 +01:00
# if QT_VERSION >= 0x050800
Q_FALLTHROUGH ( ) ;
# endif
2020-11-23 03:47:17 +01:00
case 11 :
ui - > cbDoubleclick - > setChecked ( true ) ;
2017-10-09 08:35:48 +02:00
}
}
}
2017-11-22 14:59:40 +01:00
void OptionsDialog : : setupInterfaceSettings ( )
{
settings - > beginGroup ( " Startup " ) ;
2020-11-17 04:43:04 +01:00
const QString currentStyle = QApplication : : style ( ) - > objectName ( ) ;
const QString appStyle = settings - > value ( " AppStyle " , currentStyle ) . toString ( ) ;
2017-11-22 14:59:40 +01:00
bool customStyle = settings - > value ( " CustomStyle " , false ) . toBool ( ) ;
const QStringList availableStyles = QStyleFactory : : keys ( ) ;
ui - > cbStyleList - > addItems ( availableStyles ) ;
2020-11-17 04:43:04 +01:00
if ( availableStyles . contains ( appStyle , Qt : : CaseInsensitive ) ) {
2017-11-22 14:59:40 +01:00
// use 'for' for select to be sure it's case insensitive
int currentIndex = 0 ;
2020-11-17 04:43:04 +01:00
for ( const QString & currentStyleFF : availableStyles ) {
if ( currentStyleFF . toLower ( ) = = appStyle . toLower ( ) ) {
2017-11-22 14:59:40 +01:00
ui - > cbStyleList - > setCurrentIndex ( currentIndex ) ;
}
currentIndex + + ;
}
}
2021-03-26 14:58:54 +01:00
else {
2020-11-17 04:43:04 +01:00
if ( availableStyles . contains ( currentStyle , Qt : : CaseInsensitive ) ) {
2017-11-22 14:59:40 +01:00
int currentIndex = 0 ;
2020-11-17 04:43:04 +01:00
for ( const QString & currentStyleFF : availableStyles ) {
if ( currentStyleFF . toLower ( ) = = currentStyle . toLower ( ) ) {
2017-11-22 14:59:40 +01:00
ui - > cbStyleList - > setCurrentIndex ( currentIndex ) ;
}
currentIndex + + ;
}
}
}
2020-11-17 04:43:04 +01:00
ui - > cbDefaultStyle - > setChecked ( ! customStyle ) ;
ui - > cbStyleList - > setEnabled ( customStyle ) ;
const QFont currentFont = QApplication : : font ( ) ;
const QFont appFont = qvariant_cast < QFont > ( settings - > value ( " AppFont " , currentFont ) ) ;
bool customFont = settings - > value ( " CustomFont " , false ) . toBool ( ) ;
ui - > cbDefaultFont - > setChecked ( ! customFont ) ;
ui - > cbFont - > setEnabled ( customFont ) ;
ui - > cbFont - > setCurrentFont ( appFont ) ;
2017-11-22 14:59:40 +01:00
settings - > endGroup ( ) ;
}
2017-10-09 08:35:48 +02:00
void OptionsDialog : : on_cmdOK_clicked ( )
{
applySettings ( ) ;
close ( ) ;
}
void OptionsDialog : : applySettings ( )
{
settings - > beginGroup ( " Interface " ) ;
# if QT_VERSION >= 0x050000
settings - > setValue ( " Language " , ui - > cbLanguage - > currentData ( ) ) ;
2017-11-12 15:58:59 +01:00
settings - > setValue ( " AreaLanguage " , ui - > cbAreaLanguage - > currentData ( ) ) ;
2017-10-09 08:35:48 +02:00
# else
settings - > setValue ( " Language " , ui - > cbLanguage - > itemData ( ui - > cbLanguage - > currentIndex ( ) ) ) ;
2017-11-12 15:58:59 +01:00
settings - > setValue ( " AreaLanguage " , ui - > cbAreaLanguage - > itemData ( ui - > cbAreaLanguage - > currentIndex ( ) ) ) ;
2017-10-09 08:35:48 +02:00
# endif
2020-09-26 16:12:55 +02:00
# ifdef Q_OS_WIN
2017-10-09 08:35:48 +02:00
# if QT_VERSION >= 0x050200
settings - > setValue ( " NavigationBar " , ui - > cbSnapmaticNavigationBar - > isChecked ( ) ) ;
# endif
2020-08-24 16:35:52 +02:00
# else
settings - > setValue ( " NavigationBar " , ui - > cbSnapmaticNavigationBar - > isChecked ( ) ) ;
2017-10-09 08:35:48 +02:00
# endif
settings - > endGroup ( ) ;
settings - > beginGroup ( " Profile " ) ;
2020-11-23 03:47:17 +01:00
int newContentMode = 20 ;
2021-03-26 14:58:54 +01:00
if ( ui - > rbModern - > isChecked ( ) ) {
2020-11-23 03:47:17 +01:00
newContentMode = 20 ;
2017-10-09 08:35:48 +02:00
}
2021-03-26 14:58:54 +01:00
else if ( ui - > rbClassic - > isChecked ( ) ) {
2020-11-23 03:47:17 +01:00
newContentMode = 10 ;
2017-10-09 08:35:48 +02:00
}
2021-03-26 14:58:54 +01:00
if ( ui - > cbDoubleclick - > isChecked ( ) ) {
2020-11-23 03:47:17 +01:00
newContentMode + + ;
2017-10-09 08:35:48 +02:00
}
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 " ) ;
2021-03-26 14:58:54 +01:00
if ( ui - > cbPicCustomQuality - > isChecked ( ) ) {
2017-10-09 08:35:48 +02:00
settings - > setValue ( " CustomQuality " , ui - > hsPicQuality - > value ( ) ) ;
}
settings - > setValue ( " CustomQualityEnabled " , ui - > cbPicCustomQuality - > isChecked ( ) ) ;
QString sizeMode = " Default " ;
2021-03-26 14:58:54 +01:00
if ( ui - > rbPicDesktopRes - > isChecked ( ) ) {
2017-10-09 08:35:48 +02:00
sizeMode = " Desktop " ;
}
2021-03-26 14:58:54 +01:00
else if ( ui - > rbPicCustomRes - > isChecked ( ) ) {
2017-10-09 08:35:48 +02:00
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 ( ) ;
2017-11-22 14:59:40 +01:00
bool defaultStyle = ui - > cbDefaultStyle - > isChecked ( ) ;
settings - > beginGroup ( " Startup " ) ;
2020-11-17 04:43:04 +01:00
if ( ! defaultStyle ) {
2017-11-22 14:59:40 +01:00
QString newStyle = ui - > cbStyleList - > currentText ( ) ;
settings - > setValue ( " CustomStyle " , true ) ;
settings - > setValue ( " AppStyle " , newStyle ) ;
2017-12-12 04:45:46 +01:00
QApplication : : setStyle ( QStyleFactory : : create ( newStyle ) ) ;
2017-11-22 14:59:40 +01:00
}
2020-11-17 04:43:04 +01:00
else {
2017-11-22 14:59:40 +01:00
settings - > setValue ( " CustomStyle " , false ) ;
}
2020-11-17 04:43:04 +01:00
bool defaultFont = ui - > cbDefaultFont - > isChecked ( ) ;
if ( ! defaultFont ) {
QFont newFont = ui - > cbFont - > currentFont ( ) ;
settings - > setValue ( " CustomFont " , true ) ;
settings - > setValue ( " AppFont " , newFont ) ;
QApplication : : setFont ( newFont ) ;
}
else {
settings - > setValue ( " CustomFont " , false ) ;
}
2017-11-22 14:59:40 +01:00
settings - > endGroup ( ) ;
2018-01-16 00:13:08 +01:00
# ifdef GTA5SYNC_TELEMETRY
settings - > beginGroup ( " Telemetry " ) ;
settings - > setValue ( " PushAppConf " , ui - > cbAppConfigStats - > isChecked ( ) ) ;
2018-06-07 17:07:30 +02:00
settings - > setValue ( " PushUsageData " , ui - > cbUsageData - > isChecked ( ) ) ;
2018-01-16 00:13:08 +01:00
if ( ! Telemetry - > isStateForced ( ) ) { settings - > setValue ( " IsEnabled " , ui - > cbParticipateStats - > isChecked ( ) ) ; }
settings - > endGroup ( ) ;
Telemetry - > refresh ( ) ;
Telemetry - > work ( ) ;
2021-03-26 14:58:54 +01:00
if ( ui - > cbUsageData - > isChecked ( ) & & Telemetry - > canPush ( ) ) {
2018-07-28 04:55:55 +02:00
QJsonDocument jsonDocument ;
QJsonObject jsonObject ;
jsonObject [ " Type " ] = " SettingsUpdated " ;
2021-01-27 14:35:42 +01:00
# if QT_VERSION >= 0x060000
jsonObject [ " UpdateTime " ] = QString : : number ( QDateTime : : currentDateTimeUtc ( ) . toSecsSinceEpoch ( ) ) ;
# else
2018-07-28 04:55:55 +02:00
jsonObject [ " UpdateTime " ] = QString : : number ( QDateTime : : currentDateTimeUtc ( ) . toTime_t ( ) ) ;
2021-01-27 14:35:42 +01:00
# endif
2018-07-28 04:55:55 +02:00
jsonDocument . setObject ( jsonObject ) ;
Telemetry - > push ( TelemetryCategory : : PersonalData , jsonDocument ) ;
}
2018-01-16 00:13:08 +01:00
# endif
2017-10-09 08:35:48 +02:00
# if QT_VERSION >= 0x050000
bool languageChanged = ui - > cbLanguage - > currentData ( ) . toString ( ) ! = currentLanguage ;
2017-11-12 15:58:59 +01:00
bool languageAreaChanged = ui - > cbAreaLanguage - > currentData ( ) . toString ( ) ! = currentAreaLanguage ;
2017-10-09 08:35:48 +02:00
# else
bool languageChanged = ui - > cbLanguage - > itemData ( ui - > cbLanguage - > currentIndex ( ) ) . toString ( ) ! = currentLanguage ;
2017-11-12 15:58:59 +01:00
bool languageAreaChanged = ui - > cbAreaLanguage - > itemData ( ui - > cbLanguage - > currentIndex ( ) ) . toString ( ) ! = currentAreaLanguage ;
2017-10-09 08:35:48 +02:00
# endif
2021-03-26 14:58:54 +01:00
if ( languageChanged ) {
2018-01-16 00:13:08 +01:00
Translator - > unloadTranslation ( qApp ) ;
Translator - > initUserLanguage ( ) ;
Translator - > loadTranslation ( qApp ) ;
2017-10-09 08:35:48 +02:00
}
2021-03-26 14:58:54 +01:00
else if ( languageAreaChanged ) {
2018-01-16 00:13:08 +01:00
Translator - > initUserLanguage ( ) ;
2017-11-12 15:58:59 +01:00
}
2017-10-09 08:35:48 +02:00
2018-07-28 04:55:55 +02:00
settings - > sync ( ) ;
2017-10-12 22:21:45 +02:00
emit settingsApplied ( newContentMode , languageChanged ) ;
2017-10-09 08:35:48 +02:00
2021-03-26 14:58:54 +01:00
if ( ( forceCustomFolder & & ui - > txtFolder - > text ( ) ! = currentCFolder ) | | ( forceCustomFolder ! = currentFFolder & & forceCustomFolder ) ) {
2017-10-09 08:35:48 +02:00
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 , " " ) ;
}
2017-10-21 05:59:10 +02:00
void OptionsDialog : : commitProfiles ( const QStringList & profiles )
2017-10-09 08:35:48 +02:00
{
2021-04-02 19:51:05 +02:00
for ( const QString & profile : profiles ) {
2017-10-09 08:35:48 +02:00
ui - > cbProfiles - > addItem ( tr ( " Profile: %1 " ) . arg ( profile ) , profile ) ;
2021-03-26 14:58:54 +01:00
if ( defaultProfile = = profile ) {
2017-10-09 08:35:48 +02:00
# 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 ( ) ;
2021-03-26 14:58:54 +01:00
if ( customQuality < 1 | | customQuality > 100 ) {
2017-10-09 08:35:48 +02:00
customQuality = 100 ;
}
ui - > hsPicQuality - > setValue ( customQuality ) ;
ui - > cbPicCustomQuality - > setChecked ( settings - > value ( " CustomQualityEnabled " , false ) . toBool ( ) ) ;
// Size Settings
cusExportSize = settings - > value ( " CustomSize " , defExportSize ) . toSize ( ) ;
2021-03-26 14:58:54 +01:00
if ( cusExportSize . width ( ) > 3840 ) {
2017-10-09 08:35:48 +02:00
cusExportSize . setWidth ( 3840 ) ;
}
2021-03-26 14:58:54 +01:00
else if ( cusExportSize . height ( ) > 2160 ) {
2017-10-09 08:35:48 +02:00
cusExportSize . setHeight ( 2160 ) ;
}
2021-03-26 14:58:54 +01:00
if ( cusExportSize . width ( ) < 1 ) {
2017-10-09 08:35:48 +02:00
cusExportSize . setWidth ( 1 ) ;
}
2021-03-26 14:58:54 +01:00
else if ( cusExportSize . height ( ) < 1 ) {
2017-10-09 08:35:48 +02:00
cusExportSize . setHeight ( 1 ) ;
}
ui - > sbPicExportWidth - > setValue ( cusExportSize . width ( ) ) ;
ui - > sbPicExportHeight - > setValue ( cusExportSize . height ( ) ) ;
QString sizeMode = settings - > value ( " ExportSizeMode " , " Default " ) . toString ( ) ;
2021-03-26 14:58:54 +01:00
if ( sizeMode = = " Desktop " ) {
2017-10-09 08:35:48 +02:00
ui - > rbPicDesktopRes - > setChecked ( true ) ;
}
2021-03-26 14:58:54 +01:00
else if ( sizeMode = = " Custom " ) {
2017-10-09 08:35:48 +02:00
ui - > rbPicCustomRes - > setChecked ( true ) ;
}
2021-03-26 14:58:54 +01:00
else {
2017-10-09 08:35:48 +02:00
ui - > rbPicDefaultRes - > setChecked ( true ) ;
}
aspectRatio = ( Qt : : AspectRatioMode ) settings - > value ( " AspectRatio " , Qt : : KeepAspectRatio ) . toInt ( ) ;
2021-03-26 14:58:54 +01:00
if ( aspectRatio = = Qt : : IgnoreAspectRatio ) {
2017-10-09 08:35:48 +02:00
ui - > cbIgnoreAspectRatio - > setChecked ( true ) ;
}
settings - > endGroup ( ) ;
}
2018-01-16 00:13:08 +01:00
void OptionsDialog : : setupStatisticsSettings ( )
{
# ifdef GTA5SYNC_TELEMETRY
ui - > cbParticipateStats - > setText ( tr ( " Participate in %1 User Statistics " ) . arg ( GTA5SYNC_APPSTR ) ) ;
ui - > labUserStats - > setText ( QString ( " <a href= \" %2 \" >%1</a> " ) . arg ( tr ( " View %1 User Statistics Online " ) . arg ( GTA5SYNC_APPSTR ) , TelemetryClass : : getWebURL ( ) . toString ( ) ) ) ;
settings - > beginGroup ( " Telemetry " ) ;
ui - > cbParticipateStats - > setChecked ( Telemetry - > isEnabled ( ) ) ;
ui - > cbAppConfigStats - > setChecked ( settings - > value ( " PushAppConf " , false ) . toBool ( ) ) ;
2018-06-07 17:07:30 +02:00
ui - > cbUsageData - > setChecked ( settings - > value ( " PushUsageData " , false ) . toBool ( ) ) ;
2018-01-16 00:13:08 +01:00
settings - > endGroup ( ) ;
2021-03-26 14:58:54 +01:00
if ( Telemetry - > isStateForced ( ) ) {
2018-01-16 00:13:08 +01:00
ui - > cbParticipateStats - > setEnabled ( false ) ;
}
2021-03-26 14:58:54 +01:00
if ( Telemetry - > isRegistered ( ) ) {
2018-01-16 00:13:08 +01:00
ui - > labParticipationID - > setText ( tr ( " Participation ID: %1 " ) . arg ( Telemetry - > getRegisteredID ( ) ) ) ;
}
2021-03-26 14:58:54 +01:00
else {
2018-01-16 00:13:08 +01:00
ui - > labParticipationID - > setText ( tr ( " Participation ID: %1 " ) . arg ( tr ( " Not registered " ) ) ) ;
ui - > cmdCopyStatsID - > setVisible ( false ) ;
}
# else
ui - > tabWidget - > removeTab ( ui - > tabWidget - > indexOf ( ui - > tabStats ) ) ;
# endif
}
2018-07-28 04:55:55 +02:00
void OptionsDialog : : setupWindowsGameSettings ( )
{
# ifdef GTA5SYNC_GAME
GameVersion gameVersion = AppEnv : : getGameVersion ( ) ;
2020-09-26 16:12:55 +02:00
# ifdef Q_OS_WIN
2021-03-26 14:58:54 +01:00
if ( gameVersion ! = GameVersion : : NoVersion ) {
if ( gameVersion = = GameVersion : : SocialClubVersion ) {
2018-07-28 04:55:55 +02:00
ui - > gbSteam - > setDisabled ( true ) ;
ui - > labSocialClubFound - > setText ( tr ( " Found: %1 " ) . arg ( QString ( " <span style= \" color: green \" >%1</span> " ) . arg ( tr ( " Yes " ) ) ) ) ;
ui - > labSteamFound - > setText ( tr ( " Found: %1 " ) . arg ( QString ( " <span style= \" color: red \" >%1</span> " ) . arg ( tr ( " No " ) ) ) ) ;
2021-03-26 14:58:54 +01:00
if ( AppEnv : : getGameLanguage ( GameVersion : : SocialClubVersion ) ! = GameLanguage : : Undefined ) {
2018-07-28 04:55:55 +02:00
ui - > labSocialClubLanguage - > setText ( tr ( " Language: %1 " ) . arg ( QLocale ( AppEnv : : gameLanguageToString ( AppEnv : : getGameLanguage ( GameVersion : : SocialClubVersion ) ) ) . nativeLanguageName ( ) ) ) ;
}
2021-03-26 14:58:54 +01:00
else {
2018-07-28 04:55:55 +02:00
ui - > labSocialClubLanguage - > setText ( tr ( " Language: %1 " ) . arg ( tr ( " OS defined " ) ) ) ;
}
ui - > labSteamLanguage - > setVisible ( false ) ;
}
2021-03-26 14:58:54 +01:00
else if ( gameVersion = = GameVersion : : SteamVersion ) {
2018-07-28 04:55:55 +02:00
ui - > gbSocialClub - > setDisabled ( true ) ;
ui - > labSocialClubFound - > setText ( tr ( " Found: %1 " ) . arg ( QString ( " <span style= \" color: red \" >%1</span> " ) . arg ( tr ( " No " ) ) ) ) ;
ui - > labSteamFound - > setText ( tr ( " Found: %1 " ) . arg ( QString ( " <span style= \" color: green \" >%1</span> " ) . arg ( tr ( " Yes " ) ) ) ) ;
ui - > labSocialClubLanguage - > setVisible ( false ) ;
2021-03-26 14:58:54 +01:00
if ( AppEnv : : getGameLanguage ( GameVersion : : SteamVersion ) ! = GameLanguage : : Undefined ) {
2018-07-28 04:55:55 +02:00
ui - > labSteamLanguage - > setText ( tr ( " Language: %1 " ) . arg ( QLocale ( AppEnv : : gameLanguageToString ( AppEnv : : getGameLanguage ( GameVersion : : SteamVersion ) ) ) . nativeLanguageName ( ) ) ) ;
}
2021-03-26 14:58:54 +01:00
else {
2018-07-28 04:55:55 +02:00
ui - > labSteamLanguage - > setText ( tr ( " Language: %1 " ) . arg ( tr ( " Steam defined " ) ) ) ;
}
}
2021-03-26 14:58:54 +01:00
else {
2018-07-28 04:55:55 +02:00
ui - > labSocialClubFound - > setText ( tr ( " Found: %1 " ) . arg ( QString ( " <span style= \" color: green \" >%1</span> " ) . arg ( tr ( " Yes " ) ) ) ) ;
ui - > labSteamFound - > setText ( tr ( " Found: %1 " ) . arg ( QString ( " <span style= \" color: green \" >%1</span> " ) . arg ( tr ( " Yes " ) ) ) ) ;
2021-03-26 14:58:54 +01:00
if ( AppEnv : : getGameLanguage ( GameVersion : : SocialClubVersion ) ! = GameLanguage : : Undefined ) {
2018-07-28 04:55:55 +02:00
ui - > labSocialClubLanguage - > setText ( tr ( " Language: %1 " ) . arg ( QLocale ( AppEnv : : gameLanguageToString ( AppEnv : : getGameLanguage ( GameVersion : : SocialClubVersion ) ) ) . nativeLanguageName ( ) ) ) ;
}
2021-03-26 14:58:54 +01:00
else {
2018-07-28 04:55:55 +02:00
ui - > labSocialClubLanguage - > setText ( tr ( " Language: %1 " ) . arg ( tr ( " OS defined " ) ) ) ;
}
2021-03-26 14:58:54 +01:00
if ( AppEnv : : getGameLanguage ( GameVersion : : SteamVersion ) ! = GameLanguage : : Undefined ) {
2018-07-28 04:55:55 +02:00
ui - > labSteamLanguage - > setText ( tr ( " Language: %1 " ) . arg ( QLocale ( AppEnv : : gameLanguageToString ( AppEnv : : getGameLanguage ( GameVersion : : SteamVersion ) ) ) . nativeLanguageName ( ) ) ) ;
}
2021-03-26 14:58:54 +01:00
else {
2018-07-28 04:55:55 +02:00
ui - > labSteamLanguage - > setText ( tr ( " Language: %1 " ) . arg ( tr ( " Steam defined " ) ) ) ;
}
}
}
2021-03-26 14:58:54 +01:00
else {
2018-07-28 04:55:55 +02:00
ui - > tabWidget - > removeTab ( ui - > tabWidget - > indexOf ( ui - > tabGame ) ) ;
}
# else
ui - > tabWidget - > removeTab ( ui - > tabWidget - > indexOf ( ui - > tabGame ) ) ;
# endif
# else
ui - > tabWidget - > removeTab ( ui - > tabWidget - > indexOf ( ui - > tabGame ) ) ;
# endif
}
2017-10-09 08:35:48 +02:00
void OptionsDialog : : on_cbIgnoreAspectRatio_toggled ( bool checked )
{
2021-03-26 14:58:54 +01:00
if ( checked ) {
2017-10-09 08:35:48 +02:00
aspectRatio = Qt : : IgnoreAspectRatio ;
}
2021-03-26 14:58:54 +01:00
else {
2017-10-09 08:35:48 +02:00
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 ( ) ;
2021-03-26 14:58:54 +01:00
if ( currentCFolder = = " " & & ok ) {
2017-10-09 08:35:48 +02:00
currentCFolder = defaultGameFolder ;
}
ui - > txtFolder - > setText ( currentCFolder ) ;
ui - > cbForceCustomFolder - > setChecked ( currentFFolder ) ;
settings - > endGroup ( ) ;
}
void OptionsDialog : : setupSnapmaticPictureViewer ( )
{
2020-09-26 16:12:55 +02:00
# ifdef Q_OS_WIN
2017-10-09 08:35:48 +02:00
# if QT_VERSION >= 0x050200
settings - > beginGroup ( " Interface " ) ;
2019-07-24 18:57:00 +02:00
ui - > cbSnapmaticNavigationBar - > setChecked ( settings - > value ( " NavigationBar " , true ) . toBool ( ) ) ;
2017-10-09 08:35:48 +02:00
settings - > endGroup ( ) ;
# else
ui - > cbSnapmaticNavigationBar - > setVisible ( false ) ;
ui - > gbSnapmaticPictureViewer - > setVisible ( false ) ;
# endif
# else
2020-08-24 16:35:52 +02:00
settings - > beginGroup ( " Interface " ) ;
ui - > cbSnapmaticNavigationBar - > setChecked ( settings - > value ( " NavigationBar " , true ) . toBool ( ) ) ;
settings - > endGroup ( ) ;
2017-10-09 08:35:48 +02:00
# endif
}
void OptionsDialog : : on_cmdExploreFolder_clicked ( )
{
2021-04-02 19:51:05 +02:00
const QString GTAV_Folder = QFileDialog : : getExistingDirectory ( this , UserInterface : : tr ( " Select GTA V Folder... " ) , StandardPaths : : documentsLocation ( ) , QFileDialog : : ShowDirsOnly ) ;
if ( QDir ( GTAV_Folder ) . exists ( ) ) {
2017-10-09 08:35:48 +02:00
ui - > txtFolder - > setText ( GTAV_Folder ) ;
}
}
2017-11-22 14:59:40 +01:00
void OptionsDialog : : on_cbDefaultStyle_toggled ( bool checked )
{
ui - > cbStyleList - > setDisabled ( checked ) ;
2020-11-17 10:46:37 +01:00
ui - > labStyle - > setDisabled ( checked ) ;
2017-11-22 14:59:40 +01:00
}
2018-01-16 00:13:08 +01:00
2020-11-17 04:43:04 +01:00
void OptionsDialog : : on_cbDefaultFont_toggled ( bool checked )
{
ui - > cbFont - > setDisabled ( checked ) ;
2020-11-17 10:46:37 +01:00
ui - > cmdFont - > setDisabled ( checked ) ;
ui - > labFont - > setDisabled ( checked ) ;
2020-11-17 04:43:04 +01:00
}
2018-01-16 00:13:08 +01:00
void OptionsDialog : : on_cmdCopyStatsID_clicked ( )
{
2018-01-16 00:15:43 +01:00
# ifdef GTA5SYNC_TELEMETRY
2018-01-16 00:13:08 +01:00
QApplication : : clipboard ( ) - > setText ( Telemetry - > getRegisteredID ( ) ) ;
2018-01-16 00:15:43 +01:00
# endif
2018-01-16 00:13:08 +01:00
}
2020-11-17 10:46:37 +01:00
void OptionsDialog : : on_cbFont_currentFontChanged ( const QFont & font )
{
ui - > cbFont - > setFont ( font ) ;
}
void OptionsDialog : : on_cmdFont_clicked ( )
{
bool ok ;
const QFont font = QFontDialog : : getFont ( & ok , ui - > cbFont - > currentFont ( ) , this ) ;
if ( ok ) {
ui - > cbFont - > setCurrentFont ( font ) ;
ui - > cbFont - > setFont ( font ) ;
}
}