2017-10-09 08:35:48 +02:00
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
2018-01-11 08:41:00 +01:00
* Copyright ( C ) 2016 - 2018 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 "TranslationClass.h"
# include "SnapmaticPicture.h"
# include "ProfileDatabase.h"
# include "DatabaseThread.h"
# include "SavegameDialog.h"
2017-11-22 14:59:40 +01:00
# include "OptionsDialog.h"
2017-10-09 08:35:48 +02:00
# include "PictureDialog.h"
# include "UserInterface.h"
# include "CrewDatabase.h"
# include "SavegameData.h"
2018-01-16 00:13:08 +01:00
# include "UiModWidget.h"
# include "UiModLabel.h"
2017-10-09 08:35:48 +02:00
# include "IconLoader.h"
# include "AppEnv.h"
# include "config.h"
2017-11-22 14:59:40 +01:00
# include <QDesktopWidget>
2017-10-09 08:35:48 +02:00
# include <QStringBuilder>
2018-01-16 00:13:08 +01:00
# include <QSignalMapper>
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 <QPushButton>
# include <QSpacerItem>
# include <QVBoxLayout>
# include <QHBoxLayout>
2017-11-22 14:59:40 +01:00
# include <QMessageBox>
2017-10-09 08:35:48 +02:00
# include <QStringList>
# include <QTranslator>
2018-01-16 00:13:08 +01:00
# include <QCheckBox>
2017-10-09 08:35:48 +02:00
# include <QFileInfo>
# include <QSysInfo>
2018-01-16 00:13:08 +01:00
# include <QLayout>
2017-10-09 08:35:48 +02:00
# include <QObject>
# include <QString>
# include <QDebug>
# include <QFont>
# include <QFile>
# ifdef GTA5SYNC_WIN
# include "windows.h"
# include <iostream>
# endif
2018-01-11 08:41:00 +01:00
# ifdef GTA5SYNC_TELEMETRY
# include "TelemetryClass.h"
# endif
2017-10-09 08:35:48 +02:00
int main ( int argc , char * argv [ ] )
{
QApplication a ( argc , argv ) ;
a . setApplicationName ( GTA5SYNC_APPSTR ) ;
a . setApplicationVersion ( GTA5SYNC_APPVER ) ;
2017-10-21 05:59:10 +02:00
a . setQuitOnLastWindowClosed ( false ) ;
2017-10-09 08:35:48 +02:00
2017-11-22 14:59:40 +01:00
QSettings settings ( GTA5SYNC_APPVENDOR , GTA5SYNC_APPSTR ) ;
settings . beginGroup ( " Startup " ) ;
bool isFirstStart = settings . value ( " IsFirstStart " , true ) . toBool ( ) ;
bool customStyle = settings . value ( " CustomStyle " , false ) . toBool ( ) ;
QString appStyle = settings . value ( " AppStyle " , " Default " ) . toString ( ) ;
if ( customStyle )
{
if ( QStyleFactory : : keys ( ) . contains ( appStyle , Qt : : CaseInsensitive ) )
{
a . setStyle ( QStyleFactory : : create ( appStyle ) ) ;
}
}
2017-10-09 08:35:48 +02:00
# ifdef GTA5SYNC_WIN
# if QT_VERSION >= 0x050400
2017-11-22 14:59:40 +01:00
bool alwaysUseMessageFont = settings . value ( " AlwaysUseMessageFont " , false ) . toBool ( ) ;
if ( QSysInfo : : windowsVersion ( ) > = 0x0080 | | alwaysUseMessageFont )
2017-10-09 08:35:48 +02:00
{
// Get Windows Font
NONCLIENTMETRICS ncm ;
ncm . cbSize = sizeof ( ncm ) ;
SystemParametersInfo ( SPI_GETNONCLIENTMETRICS , ncm . cbSize , & ncm , 0 ) ;
LOGFONTW uiFont = ncm . lfMessageFont ;
QString uiFontStr ( QString : : fromStdWString ( std : : wstring ( uiFont . lfFaceName ) ) ) ;
# ifdef GTA5SYNC_DEBUG
qDebug ( ) < < QApplication : : tr ( " Font " ) < < QApplication : : tr ( " Selected Font: %1 " ) . arg ( uiFontStr ) ;
# endif
// Set Application Font
QFont appFont ( uiFontStr , 9 ) ;
a . setFont ( appFont ) ;
}
# endif
# endif
2018-01-11 08:41:00 +01:00
QStringList applicationArgs = a . arguments ( ) ;
QString selectedAction ;
QString arg1 ;
applicationArgs . removeAt ( 0 ) ;
2018-01-16 00:13:08 +01:00
Translator - > initUserLanguage ( ) ;
Translator - > loadTranslation ( & a ) ;
# ifdef GTA5SYNC_TELEMETRY
if ( ! applicationArgs . contains ( " --disable-telemetry " ) )
{
if ( ! applicationArgs . contains ( " --skip-telemetryinit " ) )
{
Telemetry - > init ( ) ;
Telemetry - > work ( ) ;
}
}
else
{
Telemetry - > setDisabled ( true ) ;
}
# endif
2017-10-09 08:35:48 +02:00
2018-01-11 08:41:00 +01:00
if ( ! applicationArgs . contains ( " --skip-firststart " ) )
2017-11-22 14:59:40 +01:00
{
2018-01-11 08:41:00 +01:00
if ( isFirstStart )
2017-11-22 14:59:40 +01:00
{
2018-01-11 08:41:00 +01:00
QMessageBox : : StandardButton button = QMessageBox : : information ( a . desktop ( ) , QString ( " %1 %2 " ) . arg ( GTA5SYNC_APPSTR , GTA5SYNC_APPVER ) , QApplication : : tr ( " <h4>Welcome to %1!</h4>You want to configure %1 before you start using it? " ) . arg ( GTA5SYNC_APPSTR ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) ;
if ( button = = QMessageBox : : Yes )
{
ProfileDatabase profileDB ;
OptionsDialog optionsDialog ( & profileDB ) ;
optionsDialog . setWindowIcon ( IconLoader : : loadingAppIcon ( ) ) ;
optionsDialog . show ( ) ;
optionsDialog . exec ( ) ;
}
settings . setValue ( " IsFirstStart " , false ) ;
2017-11-22 14:59:40 +01:00
}
}
2018-01-11 08:41:00 +01:00
# ifdef GTA5SYNC_TELEMETRY
2018-01-16 00:13:08 +01:00
bool telemetryWindowLaunched = settings . value ( " TelemetryWindowLaunched " , false ) . toBool ( ) ;
if ( ! telemetryWindowLaunched & & ! Telemetry - > isEnabled ( ) & & ! Telemetry - > isStateForced ( ) )
2018-01-11 08:41:00 +01:00
{
2018-01-16 00:13:08 +01:00
QDialog telemetryDialog ;
telemetryDialog . setObjectName ( QStringLiteral ( " TelemetryDialog " ) ) ;
telemetryDialog . setWindowTitle ( QString ( " %1 %2 " ) . arg ( GTA5SYNC_APPSTR , GTA5SYNC_APPVER ) ) ;
telemetryDialog . setWindowFlags ( telemetryDialog . windowFlags ( ) ^ Qt : : WindowContextHelpButtonHint ^ Qt : : WindowCloseButtonHint ) ;
telemetryDialog . setWindowIcon ( IconLoader : : loadingAppIcon ( ) ) ;
QVBoxLayout telemetryLayout ;
telemetryLayout . setObjectName ( QStringLiteral ( " TelemetryLayout " ) ) ;
telemetryDialog . setLayout ( & telemetryLayout ) ;
UiModLabel telemetryLabel ( & telemetryDialog ) ;
telemetryLabel . setObjectName ( QStringLiteral ( " TelemetryLabel " ) ) ;
telemetryLabel . setText ( QString ( " <h4>%2</h4>%1 " ) . arg ( QApplication : : translate ( " TelemetryDialog " , " You want help %1 to improve in the future by collection of data? " ) . arg ( GTA5SYNC_APPSTR ) , QApplication : : translate ( " TelemetryDialog " , " %1 User Statistics " ) . arg ( GTA5SYNC_APPSTR ) ) ) ;
telemetryLayout . addWidget ( & telemetryLabel ) ;
QCheckBox telemetryCheckBox ( & telemetryDialog ) ;
telemetryCheckBox . setObjectName ( QStringLiteral ( " TelemetryCheckBox " ) ) ;
telemetryCheckBox . setText ( QApplication : : translate ( " TelemetryDialog " , " Yes, I would like to take part. " ) ) ;
telemetryCheckBox . setChecked ( true ) ;
telemetryLayout . addWidget ( & telemetryCheckBox ) ;
QHBoxLayout telemetryButtonLayout ;
telemetryButtonLayout . setObjectName ( QStringLiteral ( " TelemetryButtonLayout " ) ) ;
telemetryLayout . addLayout ( & telemetryButtonLayout ) ;
QSpacerItem telemetryButtonSpacer ( 0 , 0 , QSizePolicy : : Expanding , QSizePolicy : : Minimum ) ;
telemetryButtonLayout . addSpacerItem ( & telemetryButtonSpacer ) ;
QPushButton telemetryButton ( & telemetryDialog ) ;
telemetryButton . setObjectName ( QStringLiteral ( " TelemetryButton " ) ) ;
telemetryButton . setText ( QApplication : : translate ( " TelemetryDialog " , " &OK " ) ) ;
telemetryButtonLayout . addWidget ( & telemetryButton ) ;
QObject : : connect ( & telemetryButton , SIGNAL ( clicked ( bool ) ) , & telemetryDialog , SLOT ( close ( ) ) ) ;
telemetryDialog . setFixedSize ( telemetryDialog . sizeHint ( ) ) ;
telemetryDialog . exec ( ) ;
if ( telemetryCheckBox . isChecked ( ) )
2018-01-11 08:41:00 +01:00
{
2018-01-16 00:13:08 +01:00
QSettings telemetrySettings ( GTA5SYNC_APPVENDOR , GTA5SYNC_APPSTR ) ;
telemetrySettings . beginGroup ( " Telemetry " ) ;
telemetrySettings . setValue ( " IsEnabled " , true ) ;
telemetrySettings . endGroup ( ) ;
2018-01-11 08:41:00 +01:00
Telemetry - > init ( ) ;
2018-01-16 00:13:08 +01:00
Telemetry - > work ( ) ;
2018-01-11 08:41:00 +01:00
}
2018-01-16 00:13:08 +01:00
settings . setValue ( " TelemetryWindowLaunched " , true ) ;
2018-01-11 08:41:00 +01:00
}
# endif
2017-10-09 08:35:48 +02:00
2018-01-16 00:13:08 +01:00
settings . endGroup ( ) ;
2017-10-21 05:59:10 +02:00
for ( QString currentArg : applicationArgs )
2017-10-09 08:35:48 +02:00
{
QString reworkedArg ;
if ( currentArg . left ( 9 ) = = " -showpic= " & & selectedAction = = " " )
{
reworkedArg = currentArg . remove ( 0 , 9 ) ;
arg1 = reworkedArg ;
selectedAction = " showpic " ;
}
else if ( currentArg . left ( 9 ) = = " -showsgd= " & & selectedAction = = " " )
{
reworkedArg = currentArg . remove ( 0 , 9 ) ;
arg1 = reworkedArg ;
selectedAction = " showsgd " ;
}
else if ( selectedAction = = " " )
{
QFile argumentFile ( currentArg ) ;
QFileInfo argumentFileInfo ( argumentFile ) ;
if ( argumentFile . exists ( ) )
{
QString argumentFileName = argumentFileInfo . fileName ( ) ;
QString argumentFileType = argumentFileName . left ( 4 ) ;
QString argumentFileExt = argumentFileName . right ( 4 ) ;
if ( argumentFileType = = " PGTA " | | argumentFileExt = = " .g5e " )
{
arg1 = currentArg ;
selectedAction = " showpic " ;
}
else if ( argumentFileType = = " SGTA " )
{
arg1 = currentArg ;
selectedAction = " showsgd " ;
}
else if ( argumentFileType = = " MISR " )
{
arg1 = currentArg ;
selectedAction = " showsgd " ;
}
}
}
}
if ( selectedAction = = " showpic " )
{
CrewDatabase crewDB ;
ProfileDatabase profileDB ;
DatabaseThread threadDB ( & crewDB ) ;
PictureDialog picDialog ( true , & profileDB , & crewDB ) ;
SnapmaticPicture picture ;
bool readOk = picture . readingPictureFromFile ( arg1 ) ;
picDialog . setWindowIcon ( IconLoader : : loadingAppIcon ( ) ) ;
picDialog . setSnapmaticPicture ( & picture , readOk ) ;
2017-12-17 13:03:43 +01:00
# ifndef Q_OS_LINUX
picDialog . setWindowFlags ( picDialog . windowFlags ( ) ^ Qt : : Dialog ^ Qt : : Window ) ;
# endif
2017-10-09 08:35:48 +02:00
int crewID = picture . getSnapmaticProperties ( ) . crewID ;
if ( crewID ! = 0 ) { crewDB . addCrew ( crewID ) ; }
if ( ! readOk ) { return 1 ; }
QObject : : connect ( & threadDB , SIGNAL ( crewNameFound ( int , QString ) ) , & crewDB , SLOT ( setCrewName ( int , QString ) ) ) ;
QObject : : connect ( & threadDB , SIGNAL ( crewNameUpdated ( ) ) , & picDialog , SLOT ( crewNameUpdated ( ) ) ) ;
QObject : : connect ( & threadDB , SIGNAL ( playerNameFound ( int , QString ) ) , & profileDB , SLOT ( setPlayerName ( int , QString ) ) ) ;
QObject : : connect ( & threadDB , SIGNAL ( playerNameUpdated ( ) ) , & picDialog , SLOT ( playerNameUpdated ( ) ) ) ;
2017-11-12 15:58:59 +01:00
QObject : : connect ( & threadDB , SIGNAL ( finished ( ) ) , & a , SLOT ( quit ( ) ) ) ;
QObject : : connect ( & picDialog , SIGNAL ( endDatabaseThread ( ) ) , & threadDB , SLOT ( terminateThread ( ) ) ) ;
2017-10-09 08:35:48 +02:00
threadDB . start ( ) ;
picDialog . show ( ) ;
2017-11-12 15:58:59 +01:00
return a . exec ( ) ;
2017-10-09 08:35:48 +02:00
}
else if ( selectedAction = = " showsgd " )
{
SavegameDialog savegameDialog ;
SavegameData savegame ;
bool readOk = savegame . readingSavegameFromFile ( arg1 ) ;
savegameDialog . setWindowIcon ( IconLoader : : loadingAppIcon ( ) ) ;
savegameDialog . setSavegameData ( & savegame , arg1 , readOk ) ;
2017-12-17 13:03:43 +01:00
savegameDialog . setWindowFlags ( savegameDialog . windowFlags ( ) ^ Qt : : Dialog ^ Qt : : Window ) ;
2017-10-09 08:35:48 +02:00
if ( ! readOk ) { return 1 ; }
2017-11-12 15:58:59 +01:00
a . setQuitOnLastWindowClosed ( true ) ;
2017-10-09 08:35:48 +02:00
savegameDialog . show ( ) ;
return a . exec ( ) ;
}
CrewDatabase crewDB ;
ProfileDatabase profileDB ;
DatabaseThread threadDB ( & crewDB ) ;
QObject : : connect ( & threadDB , SIGNAL ( crewNameFound ( int , QString ) ) , & crewDB , SLOT ( setCrewName ( int , QString ) ) ) ;
QObject : : connect ( & threadDB , SIGNAL ( playerNameFound ( int , QString ) ) , & profileDB , SLOT ( setPlayerName ( int , QString ) ) ) ;
2017-10-21 05:59:10 +02:00
QObject : : connect ( & threadDB , SIGNAL ( finished ( ) ) , & a , SLOT ( quit ( ) ) ) ;
2017-10-09 08:35:48 +02:00
threadDB . start ( ) ;
UserInterface uiWindow ( & profileDB , & crewDB , & threadDB ) ;
uiWindow . setWindowIcon ( IconLoader : : loadingAppIcon ( ) ) ;
uiWindow . setupDirEnv ( ) ;
# ifdef Q_OS_ANDROID
uiWindow . showMaximized ( ) ;
# else
uiWindow . show ( ) ;
# endif
2017-11-12 15:58:59 +01:00
return a . exec ( ) ;
2017-10-09 08:35:48 +02:00
}