2016-04-04 23:54:17 +02:00
/*****************************************************************************
* 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 "OptionsDialog.h"
# include "ui_OptionsDialog.h"
2016-07-26 08:00:56 +02:00
# include "StandardPaths.h"
# include "UserInterface.h"
2016-04-14 01:27:29 +02:00
# include "AppEnv.h"
# include "config.h"
2016-04-26 14:59:14 +02:00
# include <QDesktopWidget>
# include <QApplication>
2016-07-26 08:00:56 +02:00
# include <QFileDialog>
2016-04-14 01:27:29 +02:00
# include <QMessageBox>
# include <QStringList>
# include <QLocale>
# include <QString>
# include <QDebug>
# include <QList>
# include <QDir>
2016-04-04 23:54:17 +02:00
2016-04-14 01:27:29 +02:00
OptionsDialog : : OptionsDialog ( ProfileDatabase * profileDB , QWidget * parent ) :
QDialog ( parent ) , profileDB ( profileDB ) ,
2016-04-04 23:54:17 +02:00
ui ( new Ui : : OptionsDialog )
{
ui - > setupUi ( this ) ;
2016-04-14 01:59:41 +02:00
ui - > tabWidget - > setCurrentIndex ( 0 ) ;
2016-04-26 15:10:52 +02:00
ui - > labPicCustomRes - > setVisible ( false ) ;
2016-04-26 14:59:14 +02:00
QRect desktopResolution = QApplication : : desktop ( ) - > screenGeometry ( ) ;
int desktopSizeWidth = desktopResolution . width ( ) ;
int desktopSizeHeight = desktopResolution . height ( ) ;
2016-04-28 00:21:25 +02:00
aspectRatio = Qt : : KeepAspectRatio ;
2016-04-26 14:59:14 +02:00
defExportSize = QSize ( 960 , 536 ) ;
cusExportSize = defExportSize ;
defaultQuality = 100 ;
customQuality = 100 ;
2016-04-14 06:33:15 +02:00
contentMode = 0 ;
settings = new QSettings ( GTA5SYNC_APPVENDOR , GTA5SYNC_APPSTR ) ;
2016-04-26 14:59:14 +02:00
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 ( ) ) ) ) ;
2016-04-14 01:27:29 +02:00
setupTreeWidget ( ) ;
setupLanguageBox ( ) ;
2016-04-14 06:33:15 +02:00
setupRadioButtons ( ) ;
setupDefaultProfile ( ) ;
2016-04-26 14:59:14 +02:00
setupPictureSettings ( ) ;
2016-07-26 08:00:56 +02:00
setupCustomGTAFolder ( ) ;
2016-04-04 23:54:17 +02:00
}
OptionsDialog : : ~ OptionsDialog ( )
{
2016-04-14 06:33:15 +02:00
delete settings ;
2016-04-14 01:27:29 +02:00
foreach ( QTreeWidgetItem * playerItem , playerItems )
{
delete playerItem ;
}
2016-04-04 23:54:17 +02:00
delete ui ;
}
2016-04-14 01:27:29 +02:00
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 ( )
{
2016-04-14 06:33:15 +02:00
settings - > beginGroup ( " Interface " ) ;
currentLanguage = settings - > value ( " Language " , " System " ) . toString ( ) ;
settings - > endGroup ( ) ;
2016-04-14 01:27:29 +02:00
2016-04-19 05:46:10 +02:00
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 " ,
2016-04-26 14:59:14 +02:00
" System like PC System " ) , QLocale : : languageToString ( QLocale ( langList . at ( 0 ) ) . language ( ) ) ) ;
2016-04-19 05:46:10 +02:00
ui - > cbLanguage - > addItem ( cbSysStr , " System " ) ;
}
2016-04-14 01:27:29 +02:00
QString cbEngStr = " English (English) [en] " ;
ui - > cbLanguage - > addItem ( QIcon : : fromTheme ( " flag-us " ) , cbEngStr , " en " ) ;
if ( currentLanguage = = " en " )
{
2016-04-18 07:44:21 +02:00
# if QT_VERSION >= 0x050000
2016-04-14 01:27:29 +02:00
ui - > cbLanguage - > setCurrentText ( cbEngStr ) ;
2016-04-18 07:44:21 +02:00
# else
int indexOfEnglish = ui - > cbLanguage - > findText ( cbEngStr ) ;
ui - > cbLanguage - > setCurrentIndex ( indexOfEnglish ) ;
# endif
2016-04-14 01:27:29 +02:00
}
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 )
{
2016-04-18 07:44:21 +02:00
# if QT_VERSION >= 0x050000
2016-04-14 01:27:29 +02:00
ui - > cbLanguage - > setCurrentText ( cbLangStr ) ;
2016-04-18 07:44:21 +02:00
# else
int indexOfLang = ui - > cbLanguage - > findText ( cbLangStr ) ;
ui - > cbLanguage - > setCurrentIndex ( indexOfLang ) ;
# endif
2016-04-14 01:27:29 +02:00
}
}
}
2016-04-14 06:33:15 +02:00
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 ) ;
}
}
}
2016-04-14 01:27:29 +02:00
void OptionsDialog : : on_cmdOK_clicked ( )
{
applySettings ( ) ;
close ( ) ;
}
void OptionsDialog : : applySettings ( )
{
2016-04-14 06:33:15 +02:00
settings - > beginGroup ( " Interface " ) ;
2016-04-18 07:44:21 +02:00
# if QT_VERSION >= 0x050000
2016-04-14 06:33:15 +02:00
settings - > setValue ( " Language " , ui - > cbLanguage - > currentData ( ) ) ;
2016-04-18 07:44:21 +02:00
# else
settings - > setValue ( " Language " , ui - > cbLanguage - > itemData ( ui - > cbLanguage - > currentIndex ( ) ) ) ;
# endif
2016-04-14 06:33:15 +02:00
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 ) ;
2016-04-18 07:44:21 +02:00
# if QT_VERSION >= 0x050000
2016-04-14 06:33:15 +02:00
settings - > setValue ( " Default " , ui - > cbProfiles - > currentData ( ) ) ;
2016-04-18 07:44:21 +02:00
# else
settings - > setValue ( " Default " , ui - > cbProfiles - > itemData ( ui - > cbProfiles - > currentIndex ( ) ) ) ;
# endif
2016-04-14 06:33:15 +02:00
settings - > endGroup ( ) ;
2016-04-26 14:59:14 +02:00
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 ) ;
2016-04-28 00:21:25 +02:00
settings - > setValue ( " AspectRatio " , aspectRatio ) ;
2016-04-26 14:59:14 +02:00
settings - > endGroup ( ) ;
2016-07-26 08:22:10 +02:00
bool forceCustomFolder = ui - > cbForceCustomFolder - > isChecked ( ) ;
2016-07-26 08:00:56 +02:00
settings - > beginGroup ( " dir " ) ;
settings - > setValue ( " dir " , ui - > txtFolder - > text ( ) ) ;
2016-07-26 08:22:10 +02:00
settings - > setValue ( " force " , forceCustomFolder ) ;
2016-07-26 08:00:56 +02:00
settings - > endGroup ( ) ;
2016-04-18 07:44:21 +02:00
# if QT_VERSION >= 0x050000
2016-04-14 06:33:15 +02:00
emit settingsApplied ( newContentMode , ui - > cbLanguage - > currentData ( ) . toString ( ) ) ;
2016-04-18 07:44:21 +02:00
# 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
2016-07-26 08:22:10 +02:00
2016-09-20 08:49:46 +02:00
if ( ( forceCustomFolder & & ui - > txtFolder - > text ( ) ! = currentCFolder ) | | ( forceCustomFolder ! = currentFFolder & & forceCustomFolder ) )
2016-07-26 08:22:10 +02:00
{
QMessageBox : : information ( this , tr ( " %1 " , " %1 " ) . arg ( GTA5SYNC_APPSTR ) , tr ( " The new Custom Folder will initialize after you restart %1. " ) . arg ( GTA5SYNC_APPSTR ) ) ;
}
2016-04-18 07:44:21 +02:00
if ( languageChanged )
2016-04-14 01:27:29 +02:00
{
QMessageBox : : information ( this , tr ( " %1 " , " %1 " ) . arg ( GTA5SYNC_APPSTR ) , tr ( " The language change will take effect after you restart %1. " ) . arg ( GTA5SYNC_APPSTR ) ) ;
}
}
2016-04-14 06:33:15 +02:00
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 )
{
2016-04-18 07:44:21 +02:00
# if QT_VERSION >= 0x050000
2016-04-14 06:33:15 +02:00
ui - > cbProfiles - > setCurrentText ( tr ( " Profile: %1 " ) . arg ( profile ) ) ;
2016-04-18 07:44:21 +02:00
# else
int indexOfProfile = ui - > cbProfiles - > findText ( tr ( " Profile: %1 " ) . arg ( profile ) ) ;
ui - > cbProfiles - > setCurrentIndex ( indexOfProfile ) ;
# endif
2016-04-14 06:33:15 +02:00
}
}
}
2016-04-26 14:59:14 +02:00
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 ( ) ;
2016-04-26 23:12:17 +02:00
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 ) ;
}
2016-04-26 14:59:14 +02:00
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 ) ;
}
2016-04-28 00:21:25 +02:00
aspectRatio = ( Qt : : AspectRatioMode ) settings - > value ( " AspectRatio " , Qt : : KeepAspectRatio ) . toInt ( ) ;
if ( aspectRatio = = Qt : : IgnoreAspectRatio )
{
ui - > cbIgnoreAspectRatio - > setChecked ( true ) ;
}
2016-04-26 14:59:14 +02:00
settings - > endGroup ( ) ;
}
2016-04-28 00:21:25 +02:00
void OptionsDialog : : on_cbIgnoreAspectRatio_toggled ( bool checked )
{
if ( checked )
{
aspectRatio = Qt : : IgnoreAspectRatio ;
}
else
{
aspectRatio = Qt : : KeepAspectRatio ;
}
}
2016-07-26 08:00:56 +02:00
void OptionsDialog : : setupCustomGTAFolder ( )
{
bool ok ;
QString defaultGameFolder = AppEnv : : getGameFolder ( & ok ) ;
settings - > beginGroup ( " dir " ) ;
2016-07-26 08:22:10 +02:00
currentCFolder = settings - > value ( " dir " , " " ) . toString ( ) ;
currentFFolder = settings - > value ( " force " , false ) . toBool ( ) ;
if ( currentCFolder = = " " & & ok )
2016-07-26 08:00:56 +02:00
{
2016-07-26 08:22:10 +02:00
currentCFolder = defaultGameFolder ;
2016-07-26 08:00:56 +02:00
}
2016-07-26 08:22:10 +02:00
ui - > txtFolder - > setText ( currentCFolder ) ;
ui - > cbForceCustomFolder - > setChecked ( currentFFolder ) ;
2016-07-26 08:00:56 +02:00
settings - > endGroup ( ) ;
}
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 ) ;
}
}