2016-03-29 11:22:41 +02:00
/*****************************************************************************
2018-05-24 22:32:00 +02:00
* gta5view Grand Theft Auto V Profile Viewer
2022-08-21 21:39:19 +02:00
* Copyright ( C ) 2016 - 2022 Syping
2016-03-29 11:22:41 +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 "ProfileInterface.h"
# include "ui_ProfileInterface.h"
2017-12-17 13:03:43 +01:00
# include "PlayerListDialog.h"
2016-03-29 15:14:49 +02:00
# include "SidebarGenerator.h"
2016-03-29 11:22:41 +02:00
# include "SnapmaticWidget.h"
# include "DatabaseThread.h"
# include "SavegameWidget.h"
2016-04-12 20:56:58 +02:00
# include "PictureDialog.h"
2016-03-29 11:22:41 +02:00
# include "StandardPaths.h"
# include "ProfileLoader.h"
2016-04-03 12:27:40 +02:00
# include "ExportThread.h"
2017-02-11 04:21:55 +01:00
# include "ImportDialog.h"
2018-06-17 09:27:10 +02:00
# include "UiModLabel.h"
2018-06-15 04:43:13 +02:00
# include "pcg_basic.h"
2017-05-01 05:05:55 +02:00
# include "AppEnv.h"
2016-04-14 01:27:29 +02:00
# include "config.h"
2018-06-17 09:27:10 +02:00
# include <QNetworkAccessManager>
2016-04-03 12:27:40 +02:00
# include <QProgressDialog>
2018-06-17 09:27:10 +02:00
# include <QNetworkRequest>
2017-09-05 03:36:01 +02:00
# include <QStringBuilder>
2018-06-17 09:27:10 +02:00
# include <QNetworkReply>
2017-09-17 23:27:49 +02:00
# include <QImageReader>
2016-04-03 12:27:40 +02:00
# include <QProgressBar>
2016-04-03 10:17:01 +02:00
# include <QInputDialog>
2016-04-03 12:27:40 +02:00
# include <QPushButton>
2016-03-29 11:22:41 +02:00
# include <QSpacerItem>
# include <QMessageBox>
2017-10-09 08:35:48 +02:00
# include <QMouseEvent>
2016-03-29 11:22:41 +02:00
# include <QFileDialog>
2018-06-17 09:27:10 +02:00
# include <QVBoxLayout>
2016-04-03 12:27:40 +02:00
# include <QEventLoop>
2016-04-03 01:43:04 +02:00
# include <QScrollBar>
2018-06-17 09:27:10 +02:00
# include <QClipboard>
2016-03-29 11:22:41 +02:00
# include <QFileInfo>
2017-02-11 04:21:55 +01:00
# include <QPainter>
2017-03-01 15:19:40 +01:00
# include <QAction>
2016-03-29 11:22:41 +02:00
# include <QDebug>
# include <QColor>
2016-04-03 01:43:04 +02:00
# include <QTimer>
2018-05-30 07:49:33 +02:00
# include <QStyle>
2016-03-29 11:22:41 +02:00
# include <QFile>
# include <QUrl>
# include <QDir>
2020-11-05 18:32:20 +01:00
# include <cstdint>
2018-06-14 11:36:01 +02:00
# include <random>
2018-06-17 10:52:50 +02:00
# include <ctime>
2018-06-14 11:36:01 +02:00
2018-07-28 04:55:55 +02:00
# ifdef GTA5SYNC_TELEMETRY
# include "TelemetryClass.h"
# include <QJsonDocument>
# include <QJsonObject>
# endif
2017-11-22 14:59:40 +01:00
# define importTimeFormat "HHmmss"
# define findRetryLimit 500
2016-03-29 11:22:41 +02:00
ProfileInterface : : ProfileInterface ( ProfileDatabase * profileDB , CrewDatabase * crewDB , DatabaseThread * threadDB , QWidget * parent ) :
QWidget ( parent ) , profileDB ( profileDB ) , crewDB ( crewDB ) , threadDB ( threadDB ) ,
ui ( new Ui : : ProfileInterface )
{
ui - > setupUi ( this ) ;
ui - > cmdImport - > setEnabled ( false ) ;
ui - > cmdCloseProfile - > setEnabled ( false ) ;
loadingStr = ui - > labProfileLoading - > text ( ) ;
2016-10-27 08:12:59 +02:00
enabledPicStr = tr ( " Enabled pictures: %1 of %2 " ) ;
2016-04-03 01:18:48 +02:00
selectedWidgts = 0 ;
2016-03-29 11:22:41 +02:00
profileFolder = " " ;
2017-10-09 08:35:48 +02:00
contextMenuOpened = false ;
isProfileLoaded = false ;
previousWidget = nullptr ;
profileLoader = nullptr ;
saSpacerItem = nullptr ;
updatePalette ( ) ;
2021-05-27 05:42:05 +02:00
QString appVersion = QApplication : : applicationVersion ( ) ;
const char * literalBuildType = GTA5SYNC_BUILDTYPE ;
2018-07-13 12:07:13 +02:00
# ifdef GTA5SYNC_COMMIT
2021-05-27 05:42:05 +02:00
if ( ( strcmp ( literalBuildType , REL_BUILDTYPE ) ! = 0 ) & & ! appVersion . contains ( " - " ) )
appVersion = appVersion % " - " % GTA5SYNC_COMMIT ;
2018-07-13 12:07:13 +02:00
# endif
ui - > labVersion - > setText ( QString ( " %1 %2 " ) . arg ( GTA5SYNC_APPSTR , appVersion ) ) ;
2018-06-29 08:52:43 +02:00
ui - > saProfileContent - > setFilesDropEnabled ( true ) ;
ui - > saProfileContent - > setImageDropEnabled ( true ) ;
2017-02-11 04:21:55 +01:00
2018-01-11 08:41:00 +01:00
// Set Icon for Close Button
2021-03-27 08:23:05 +01:00
if ( QIcon : : hasThemeIcon ( " dialog-close " ) ) {
2017-02-11 04:21:55 +01:00
ui - > cmdCloseProfile - > setIcon ( QIcon : : fromTheme ( " dialog-close " ) ) ;
}
2021-03-27 08:23:05 +01:00
else if ( QIcon : : hasThemeIcon ( " gtk-close " ) ) {
2018-01-11 08:41:00 +01:00
ui - > cmdCloseProfile - > setIcon ( QIcon : : fromTheme ( " gtk-close " ) ) ;
}
// Set Icon for Import Button
2021-03-27 08:23:05 +01:00
if ( QIcon : : hasThemeIcon ( " document-import " ) ) {
2018-01-11 08:41:00 +01:00
ui - > cmdImport - > setIcon ( QIcon : : fromTheme ( " document-import " ) ) ;
}
2021-03-27 08:23:05 +01:00
else if ( QIcon : : hasThemeIcon ( " document-open " ) ) {
2018-01-24 16:26:54 +01:00
ui - > cmdImport - > setIcon ( QIcon : : fromTheme ( " document-open " ) ) ;
}
2017-05-01 05:05:55 +02:00
// DPI calculation
qreal screenRatio = AppEnv : : screenRatio ( ) ;
2017-07-28 19:53:07 +02:00
# ifndef Q_OS_MAC
2017-05-01 05:05:55 +02:00
ui - > hlButtons - > setSpacing ( 6 * screenRatio ) ;
ui - > hlButtons - > setContentsMargins ( 9 * screenRatio , 9 * screenRatio , 9 * screenRatio , 9 * screenRatio ) ;
2022-08-21 21:39:19 +02:00
# else
# if QT_VERSION >= 0x060000
if ( QApplication : : style ( ) - > objectName ( ) = = " macos " ) {
2017-07-28 19:53:07 +02:00
# else
2021-03-27 08:23:05 +01:00
if ( QApplication : : style ( ) - > objectName ( ) = = " macintosh " ) {
2022-08-21 21:39:19 +02:00
# endif
2017-12-12 04:45:46 +01:00
ui - > hlButtons - > setSpacing ( 6 * screenRatio ) ;
ui - > hlButtons - > setContentsMargins ( 9 * screenRatio , 15 * screenRatio , 15 * screenRatio , 17 * screenRatio ) ;
}
2021-03-27 08:23:05 +01:00
else {
2017-12-12 04:45:46 +01:00
ui - > hlButtons - > setSpacing ( 6 * screenRatio ) ;
ui - > hlButtons - > setContentsMargins ( 9 * screenRatio , 9 * screenRatio , 9 * screenRatio , 9 * screenRatio ) ;
}
2017-07-28 19:53:07 +02:00
# endif
2017-10-09 08:35:48 +02:00
2018-06-16 05:28:56 +02:00
// Seed RNG
pcg32_srandom_r ( & rng , time ( NULL ) , ( intptr_t ) & rng ) ;
2021-05-23 07:20:20 +02:00
# if QT_VERSION >= 0x050000
2021-05-23 07:12:56 +02:00
// Register Metatypes
qRegisterMetaType < QVector < QString > > ( ) ;
2021-05-23 07:20:20 +02:00
# endif
2021-05-23 07:12:56 +02:00
2017-10-09 08:35:48 +02:00
setMouseTracking ( true ) ;
installEventFilter ( this ) ;
2016-03-29 11:22:41 +02:00
}
ProfileInterface : : ~ ProfileInterface ( )
{
2021-03-27 08:23:05 +01:00
for ( const QString & widgetStr : qAsConst ( widgets ) ) {
ProfileWidget * widget = widgets . key ( widgetStr , nullptr ) ;
if ( widget ! = nullptr ) {
widget - > removeEventFilter ( this ) ;
widget - > disconnect ( ) ;
delete widget ;
}
2016-04-03 03:56:24 +02:00
}
2017-11-12 15:58:59 +01:00
widgets . clear ( ) ;
2021-03-27 08:23:05 +01:00
for ( SavegameData * savegame : qAsConst ( savegames ) ) {
2016-03-29 11:22:41 +02:00
delete savegame ;
}
2017-11-12 15:58:59 +01:00
savegames . clear ( ) ;
2021-03-27 08:23:05 +01:00
for ( SnapmaticPicture * picture : qAsConst ( pictures ) ) {
2016-03-29 11:22:41 +02:00
delete picture ;
}
2017-11-12 15:58:59 +01:00
pictures . clear ( ) ;
2016-04-03 12:27:40 +02:00
2017-11-12 15:58:59 +01:00
delete profileLoader ;
2016-03-29 11:22:41 +02:00
delete ui ;
}
void ProfileInterface : : setProfileFolder ( QString folder , QString profile )
{
profileFolder = folder ;
profileName = profile ;
}
void ProfileInterface : : setupProfileInterface ( )
{
2017-11-22 20:23:36 +01:00
fixedPictures . clear ( ) ;
2016-03-29 11:22:41 +02:00
ui - > labProfileLoading - > setText ( tr ( " Loading... " ) ) ;
profileLoader = new ProfileLoader ( profileFolder , crewDB ) ;
2021-05-23 07:20:20 +02:00
# if QT_VERSION >= 0x050000
2021-05-23 07:12:56 +02:00
QObject : : connect ( profileLoader , SIGNAL ( directoryScanned ( QVector < QString > , QVector < QString > ) ) , this , SLOT ( directoryScanned ( QVector < QString > , QVector < QString > ) ) ) ;
2021-05-23 07:20:20 +02:00
# endif
2017-02-11 04:21:55 +01:00
QObject : : connect ( profileLoader , SIGNAL ( savegameLoaded ( SavegameData * , QString ) ) , this , SLOT ( savegameLoaded_event ( SavegameData * , QString ) ) ) ;
QObject : : connect ( profileLoader , SIGNAL ( pictureLoaded ( SnapmaticPicture * ) ) , this , SLOT ( pictureLoaded_event ( SnapmaticPicture * ) ) ) ;
2017-11-22 20:23:36 +01:00
QObject : : connect ( profileLoader , SIGNAL ( pictureFixed ( SnapmaticPicture * ) ) , this , SLOT ( pictureFixed_event ( SnapmaticPicture * ) ) ) ;
2016-04-03 06:12:12 +02:00
QObject : : connect ( profileLoader , SIGNAL ( loadingProgress ( int , int ) ) , this , SLOT ( loadingProgress ( int , int ) ) ) ;
2016-04-03 08:39:31 +02:00
QObject : : connect ( profileLoader , SIGNAL ( finished ( ) ) , this , SLOT ( profileLoaded_p ( ) ) ) ;
2016-03-29 11:22:41 +02:00
profileLoader - > start ( ) ;
}
2017-02-11 04:21:55 +01:00
void ProfileInterface : : savegameLoaded_event ( SavegameData * savegame , QString savegamePath )
2016-04-06 06:38:43 +02:00
{
2017-02-11 04:21:55 +01:00
savegameLoaded ( savegame , savegamePath , false ) ;
2016-04-06 06:38:43 +02:00
}
2017-02-11 04:21:55 +01:00
void ProfileInterface : : savegameLoaded ( SavegameData * savegame , QString savegamePath , bool inserted )
2016-03-29 11:22:41 +02:00
{
2016-10-27 10:35:20 +02:00
SavegameWidget * sgdWidget = new SavegameWidget ( this ) ;
2016-03-29 11:22:41 +02:00
sgdWidget - > setSavegameData ( savegame , savegamePath ) ;
2016-04-14 06:33:15 +02:00
sgdWidget - > setContentMode ( contentMode ) ;
2017-10-09 08:35:48 +02:00
sgdWidget - > setMouseTracking ( true ) ;
sgdWidget - > installEventFilter ( this ) ;
2017-09-05 03:36:01 +02:00
widgets [ sgdWidget ] = " SGD " % QFileInfo ( savegamePath ) . fileName ( ) ;
savegames + = savegame ;
2020-11-23 03:13:07 +01:00
if ( selectedWidgts ! = 0 | | contentMode = = 2 )
sgdWidget - > setSelectionMode ( true ) ;
2017-02-11 04:21:55 +01:00
QObject : : connect ( sgdWidget , SIGNAL ( savegameDeleted ( ) ) , this , SLOT ( savegameDeleted_event ( ) ) ) ;
2016-04-03 06:12:12 +02:00
QObject : : connect ( sgdWidget , SIGNAL ( widgetSelected ( ) ) , this , SLOT ( profileWidgetSelected ( ) ) ) ;
QObject : : connect ( sgdWidget , SIGNAL ( widgetDeselected ( ) ) , this , SLOT ( profileWidgetDeselected ( ) ) ) ;
2016-04-03 09:23:14 +02:00
QObject : : connect ( sgdWidget , SIGNAL ( allWidgetsSelected ( ) ) , this , SLOT ( selectAllWidgets ( ) ) ) ;
QObject : : connect ( sgdWidget , SIGNAL ( allWidgetsDeselected ( ) ) , this , SLOT ( deselectAllWidgets ( ) ) ) ;
2017-02-13 04:12:47 +01:00
QObject : : connect ( sgdWidget , SIGNAL ( contextMenuTriggered ( QContextMenuEvent * ) ) , this , SLOT ( contextMenuTriggeredSGD ( QContextMenuEvent * ) ) ) ;
2020-11-23 03:13:07 +01:00
if ( inserted )
insertSavegameIPI ( sgdWidget ) ;
2016-03-29 11:22:41 +02:00
}
2017-02-11 04:21:55 +01:00
void ProfileInterface : : pictureLoaded_event ( SnapmaticPicture * picture )
2016-04-06 06:38:43 +02:00
{
2017-02-11 04:21:55 +01:00
pictureLoaded ( picture , false ) ;
2016-04-06 06:38:43 +02:00
}
2017-11-22 20:23:36 +01:00
void ProfileInterface : : pictureFixed_event ( SnapmaticPicture * picture )
{
QString fixedPicture = picture - > getPictureStr ( ) % " ( " % picture - > getPictureTitl ( ) % " ) " ;
fixedPictures < < fixedPicture ;
}
2017-02-11 04:21:55 +01:00
void ProfileInterface : : pictureLoaded ( SnapmaticPicture * picture , bool inserted )
2016-03-29 11:22:41 +02:00
{
2017-12-17 13:03:43 +01:00
SnapmaticWidget * picWidget = new SnapmaticWidget ( profileDB , crewDB , threadDB , profileName , this ) ;
2017-02-11 04:21:55 +01:00
picWidget - > setSnapmaticPicture ( picture ) ;
2016-04-14 06:33:15 +02:00
picWidget - > setContentMode ( contentMode ) ;
2017-10-09 08:35:48 +02:00
picWidget - > setMouseTracking ( true ) ;
picWidget - > installEventFilter ( this ) ;
2017-09-05 03:36:01 +02:00
widgets [ picWidget ] = " PIC " % picture - > getPictureSortStr ( ) ;
pictures + = picture ;
2020-11-23 03:13:07 +01:00
if ( selectedWidgts ! = 0 | | contentMode = = 2 )
picWidget - > setSelectionMode ( true ) ;
2017-02-11 04:21:55 +01:00
QObject : : connect ( picWidget , SIGNAL ( pictureDeleted ( ) ) , this , SLOT ( pictureDeleted_event ( ) ) ) ;
2016-04-03 06:12:12 +02:00
QObject : : connect ( picWidget , SIGNAL ( widgetSelected ( ) ) , this , SLOT ( profileWidgetSelected ( ) ) ) ;
QObject : : connect ( picWidget , SIGNAL ( widgetDeselected ( ) ) , this , SLOT ( profileWidgetDeselected ( ) ) ) ;
2016-04-03 09:23:14 +02:00
QObject : : connect ( picWidget , SIGNAL ( allWidgetsSelected ( ) ) , this , SLOT ( selectAllWidgets ( ) ) ) ;
QObject : : connect ( picWidget , SIGNAL ( allWidgetsDeselected ( ) ) , this , SLOT ( deselectAllWidgets ( ) ) ) ;
2016-04-12 20:56:58 +02:00
QObject : : connect ( picWidget , SIGNAL ( nextPictureRequested ( QWidget * ) ) , this , SLOT ( dialogNextPictureRequested ( QWidget * ) ) ) ;
QObject : : connect ( picWidget , SIGNAL ( previousPictureRequested ( QWidget * ) ) , this , SLOT ( dialogPreviousPictureRequested ( QWidget * ) ) ) ;
2017-02-13 04:12:47 +01:00
QObject : : connect ( picWidget , SIGNAL ( contextMenuTriggered ( QContextMenuEvent * ) ) , this , SLOT ( contextMenuTriggeredPIC ( QContextMenuEvent * ) ) ) ;
2020-11-23 03:13:07 +01:00
if ( inserted )
insertSnapmaticIPI ( picWidget ) ;
2016-03-29 11:22:41 +02:00
}
2016-04-03 06:12:12 +02:00
void ProfileInterface : : loadingProgress ( int value , int maximum )
2016-03-29 11:22:41 +02:00
{
ui - > pbPictureLoading - > setMaximum ( maximum ) ;
ui - > pbPictureLoading - > setValue ( value ) ;
ui - > labProfileLoading - > setText ( loadingStr . arg ( QString : : number ( value ) , QString : : number ( maximum ) ) ) ;
}
2021-05-23 07:20:20 +02:00
# if QT_VERSION >= 0x050000
2021-05-23 07:12:56 +02:00
void ProfileInterface : : directoryChanged ( const QString & path )
{
2021-05-23 07:20:20 +02:00
Q_UNUSED ( path )
2021-05-27 02:28:41 +02:00
2021-05-23 07:12:56 +02:00
QDir dir ( profileFolder ) ;
QVector < QString > t_savegameFiles ;
QVector < QString > t_snapmaticPics ;
QVector < QString > n_savegameFiles ;
QVector < QString > n_snapmaticPics ;
2021-05-27 02:28:41 +02:00
2021-05-23 07:12:56 +02:00
const QStringList files = dir . entryList ( QDir : : Files ) ;
for ( const QString & fileName : files ) {
if ( fileName . startsWith ( " SGTA5 " ) & & ! fileName . endsWith ( " .bak " ) ) {
t_savegameFiles < < fileName ;
if ( ! savegameFiles . contains ( fileName ) ) {
n_savegameFiles < < fileName ;
}
}
if ( fileName . startsWith ( " PGTA5 " ) & & ! fileName . endsWith ( " .bak " ) ) {
t_snapmaticPics < < fileName ;
2023-03-27 15:07:12 +02:00
if ( fileName . endsWith ( " .hidden " ) ) {
const QString originalFileName = fileName . left ( fileName . length ( ) - 7 ) ;
if ( ! snapmaticPics . contains ( fileName ) & & ! snapmaticPics . contains ( originalFileName ) ) {
n_snapmaticPics < < fileName ;
}
}
else {
if ( ! snapmaticPics . contains ( fileName ) & & ! snapmaticPics . contains ( fileName % " .hidden " ) ) {
n_snapmaticPics < < fileName ;
}
2021-05-23 07:12:56 +02:00
}
}
}
savegameFiles = t_savegameFiles ;
snapmaticPics = t_snapmaticPics ;
if ( ! n_savegameFiles . isEmpty ( ) | | ! n_snapmaticPics . isEmpty ( ) ) {
2021-05-27 02:28:41 +02:00
QTimer : : singleShot ( 1000 , this , [ = ] ( ) {
for ( const QString & fileName : qAsConst ( n_savegameFiles ) ) {
const QString filePath = profileFolder % " / " % fileName ;
SavegameData * savegame = new SavegameData ( filePath ) ;
if ( savegame - > readingSavegame ( ) )
savegameLoaded ( savegame , filePath , true ) ;
else
delete savegame ;
}
for ( const QString & fileName : qAsConst ( n_snapmaticPics ) ) {
const QString filePath = profileFolder % " / " % fileName ;
SnapmaticPicture * picture = new SnapmaticPicture ( filePath ) ;
if ( picture - > readingPicture ( true ) )
pictureLoaded ( picture , true ) ;
else
delete picture ;
}
} ) ;
2021-05-23 07:12:56 +02:00
}
}
void ProfileInterface : : directoryScanned ( QVector < QString > savegameFiles_s , QVector < QString > snapmaticPics_s )
{
savegameFiles = savegameFiles_s ;
snapmaticPics = snapmaticPics_s ;
fileSystemWatcher . addPath ( profileFolder ) ;
2021-05-27 02:28:41 +02:00
QObject : : connect ( & fileSystemWatcher , & QFileSystemWatcher : : directoryChanged , this , & ProfileInterface : : directoryChanged ) ;
2021-05-23 07:12:56 +02:00
}
2021-05-23 07:20:20 +02:00
# endif
2021-05-23 07:12:56 +02:00
2016-04-06 06:38:43 +02:00
void ProfileInterface : : insertSnapmaticIPI ( QWidget * widget )
{
2017-10-09 08:35:48 +02:00
ProfileWidget * proWidget = qobject_cast < ProfileWidget * > ( widget ) ;
2021-03-27 08:23:05 +01:00
const QString widgetKey = widgets . value ( proWidget , QString ( ) ) ;
if ( ! widgetKey . isNull ( ) ) {
2016-04-06 06:38:43 +02:00
QStringList widgetsKeyList = widgets . values ( ) ;
QStringList pictureKeyList = widgetsKeyList . filter ( " PIC " , Qt : : CaseSensitive ) ;
2016-04-06 07:00:50 +02:00
# if QT_VERSION >= 0x050600
2020-08-25 17:29:41 +02:00
std : : sort ( pictureKeyList . rbegin ( ) , pictureKeyList . rend ( ) ) ;
2016-04-06 06:48:42 +02:00
# else
qSort ( pictureKeyList . begin ( ) , pictureKeyList . end ( ) , qGreater < QString > ( ) ) ;
# endif
2020-09-28 05:33:04 +02:00
int picIndex = pictureKeyList . indexOf ( widgetKey ) ;
2016-04-06 06:38:43 +02:00
ui - > vlSnapmatic - > insertWidget ( picIndex , proWidget ) ;
2016-04-06 17:38:31 +02:00
2020-09-28 05:33:04 +02:00
QApplication : : processEvents ( ) ;
2016-04-06 17:38:31 +02:00
ui - > saProfile - > ensureWidgetVisible ( proWidget , 0 , 0 ) ;
2016-04-06 06:38:43 +02:00
}
}
void ProfileInterface : : insertSavegameIPI ( QWidget * widget )
2016-03-29 11:22:41 +02:00
{
2017-10-09 08:35:48 +02:00
ProfileWidget * proWidget = qobject_cast < ProfileWidget * > ( widget ) ;
2021-03-27 08:23:05 +01:00
const QString widgetKey = widgets . value ( proWidget , QString ( ) ) ;
if ( ! widgetKey . isNull ( ) ) {
2016-04-06 06:38:43 +02:00
QStringList widgetsKeyList = widgets . values ( ) ;
QStringList savegameKeyList = widgetsKeyList . filter ( " SGD " , Qt : : CaseSensitive ) ;
2020-10-11 17:46:45 +02:00
# if QT_VERSION >= 0x050600
2020-08-25 17:29:41 +02:00
std : : sort ( savegameKeyList . begin ( ) , savegameKeyList . end ( ) ) ;
# else
2016-04-06 06:38:43 +02:00
qSort ( savegameKeyList . begin ( ) , savegameKeyList . end ( ) ) ;
2020-08-25 17:29:41 +02:00
# endif
2020-09-28 05:33:04 +02:00
int sgdIndex = savegameKeyList . indexOf ( widgetKey ) ;
2016-04-06 06:38:43 +02:00
ui - > vlSavegame - > insertWidget ( sgdIndex , proWidget ) ;
2016-04-06 17:38:31 +02:00
2020-09-28 05:33:04 +02:00
QApplication : : processEvents ( ) ;
2016-04-06 17:38:31 +02:00
ui - > saProfile - > ensureWidgetVisible ( proWidget , 0 , 0 ) ;
2016-04-06 06:38:43 +02:00
}
}
2016-04-12 20:56:58 +02:00
void ProfileInterface : : dialogNextPictureRequested ( QWidget * dialog )
{
2017-10-09 08:35:48 +02:00
PictureDialog * picDialog = qobject_cast < PictureDialog * > ( dialog ) ;
ProfileWidget * proWidget = qobject_cast < ProfileWidget * > ( sender ( ) ) ;
2021-03-27 08:23:05 +01:00
const QString widgetKey = widgets . value ( proWidget , QString ( ) ) ;
if ( ! widgetKey . isNull ( ) ) {
2016-04-12 20:56:58 +02:00
QStringList widgetsKeyList = widgets . values ( ) ;
QStringList pictureKeyList = widgetsKeyList . filter ( " PIC " , Qt : : CaseSensitive ) ;
# if QT_VERSION >= 0x050600
2020-08-25 17:29:41 +02:00
std : : sort ( pictureKeyList . rbegin ( ) , pictureKeyList . rend ( ) ) ;
2016-04-12 20:56:58 +02:00
# else
qSort ( pictureKeyList . begin ( ) , pictureKeyList . end ( ) , qGreater < QString > ( ) ) ;
# endif
int picIndex ;
2021-03-27 08:23:05 +01:00
if ( picDialog - > isIndexed ( ) ) {
2016-04-12 20:56:58 +02:00
picIndex = picDialog - > getIndex ( ) ;
}
2021-03-27 08:23:05 +01:00
else {
2020-09-28 05:33:04 +02:00
picIndex = pictureKeyList . indexOf ( widgetKey ) ;
2016-04-12 20:56:58 +02:00
}
picIndex + + ;
2021-03-27 08:23:05 +01:00
if ( pictureKeyList . length ( ) > picIndex ) {
const QString newWidgetKey = pictureKeyList . at ( picIndex ) ;
SnapmaticWidget * picWidget = static_cast < SnapmaticWidget * > ( widgets . key ( newWidgetKey ) ) ;
2016-04-12 20:56:58 +02:00
picDialog - > setSnapmaticPicture ( picWidget - > getPicture ( ) , picIndex ) ;
}
}
}
void ProfileInterface : : dialogPreviousPictureRequested ( QWidget * dialog )
{
2017-10-09 08:35:48 +02:00
PictureDialog * picDialog = qobject_cast < PictureDialog * > ( dialog ) ;
ProfileWidget * proWidget = qobject_cast < ProfileWidget * > ( sender ( ) ) ;
2021-03-27 08:23:05 +01:00
const QString widgetKey = widgets . value ( proWidget , QString ( ) ) ;
if ( ! widgetKey . isNull ( ) ) {
2016-04-12 20:56:58 +02:00
QStringList widgetsKeyList = widgets . values ( ) ;
QStringList pictureKeyList = widgetsKeyList . filter ( " PIC " , Qt : : CaseSensitive ) ;
# if QT_VERSION >= 0x050600
2020-08-25 17:29:41 +02:00
std : : sort ( pictureKeyList . rbegin ( ) , pictureKeyList . rend ( ) ) ;
2016-04-12 20:56:58 +02:00
# else
qSort ( pictureKeyList . begin ( ) , pictureKeyList . end ( ) , qGreater < QString > ( ) ) ;
# endif
int picIndex ;
2021-03-27 08:23:05 +01:00
if ( picDialog - > isIndexed ( ) ) {
2016-04-12 20:56:58 +02:00
picIndex = picDialog - > getIndex ( ) ;
}
2021-03-27 08:23:05 +01:00
else {
2020-09-28 05:33:04 +02:00
picIndex = pictureKeyList . indexOf ( widgetKey ) ;
2016-04-12 20:56:58 +02:00
}
2021-03-27 08:23:05 +01:00
if ( picIndex > 0 ) {
2016-04-12 20:56:58 +02:00
picIndex - - ;
2021-03-27 08:23:05 +01:00
const QString newWidgetKey = pictureKeyList . at ( picIndex ) ;
SnapmaticWidget * picWidget = static_cast < SnapmaticWidget * > ( widgets . key ( newWidgetKey ) ) ;
2016-04-12 20:56:58 +02:00
picDialog - > setSnapmaticPicture ( picWidget - > getPicture ( ) , picIndex ) ;
}
}
}
2016-04-06 06:38:43 +02:00
void ProfileInterface : : sortingProfileInterface ( )
{
ui - > vlSavegame - > setEnabled ( false ) ;
ui - > vlSnapmatic - > setEnabled ( false ) ;
2016-04-06 05:34:26 +02:00
QStringList widgetsKeyList = widgets . values ( ) ;
2020-08-25 17:29:41 +02:00
2020-10-11 17:46:45 +02:00
# if QT_VERSION >= 0x050600
2020-08-25 17:29:41 +02:00
std : : sort ( widgetsKeyList . begin ( ) , widgetsKeyList . end ( ) ) ;
# else
2016-04-06 05:34:26 +02:00
qSort ( widgetsKeyList . begin ( ) , widgetsKeyList . end ( ) ) ;
2020-08-25 17:29:41 +02:00
# endif
2016-04-06 06:38:43 +02:00
2021-03-27 08:23:05 +01:00
for ( const QString & widgetKey : qAsConst ( widgetsKeyList ) ) {
2016-04-06 05:34:26 +02:00
ProfileWidget * widget = widgets . key ( widgetKey ) ;
2021-03-27 08:23:05 +01:00
if ( widget - > getWidgetType ( ) = = " SnapmaticWidget " ) {
2016-04-06 05:34:26 +02:00
ui - > vlSnapmatic - > insertWidget ( 0 , widget ) ;
}
2021-03-27 08:23:05 +01:00
else if ( widget - > getWidgetType ( ) = = " SavegameWidget " ) {
2016-04-06 05:34:26 +02:00
ui - > vlSavegame - > addWidget ( widget ) ;
}
}
2016-04-06 06:38:43 +02:00
ui - > vlSavegame - > setEnabled ( true ) ;
ui - > vlSnapmatic - > setEnabled ( true ) ;
2016-04-06 17:29:08 +02:00
2020-09-28 05:33:04 +02:00
QApplication : : processEvents ( ) ;
2016-04-06 06:38:43 +02:00
}
void ProfileInterface : : profileLoaded_p ( )
{
sortingProfileInterface ( ) ;
2016-03-29 11:22:41 +02:00
saSpacerItem = new QSpacerItem ( 0 , 0 , QSizePolicy : : Minimum , QSizePolicy : : Expanding ) ;
ui - > saProfileContent - > layout ( ) - > addItem ( saSpacerItem ) ;
ui - > swProfile - > setCurrentWidget ( ui - > pageProfile ) ;
ui - > cmdCloseProfile - > setEnabled ( true ) ;
ui - > cmdImport - > setEnabled ( true ) ;
2017-10-09 08:35:48 +02:00
isProfileLoaded = true ;
2016-04-03 08:39:31 +02:00
emit profileLoaded ( ) ;
2017-11-22 20:23:36 +01:00
2021-03-27 08:23:05 +01:00
if ( ! fixedPictures . isEmpty ( ) ) {
2017-11-22 20:23:36 +01:00
int fixedInt = 0 ;
QString fixedStr ;
2021-03-27 08:23:05 +01:00
for ( const QString & fixedPicture : qAsConst ( fixedPictures ) ) {
2017-11-22 20:23:36 +01:00
if ( fixedInt ! = 0 ) { fixedStr + = " <br> " ; }
fixedStr + = fixedPicture ;
fixedInt + + ;
}
QMessageBox : : information ( this , tr ( " Snapmatic Loader " ) , tr ( " <h4>Following Snapmatic Pictures got repaired</h4>%1 " ) . arg ( fixedStr ) ) ;
}
2016-03-29 11:22:41 +02:00
}
2017-02-11 04:21:55 +01:00
void ProfileInterface : : savegameDeleted_event ( )
2016-03-29 11:22:41 +02:00
{
2017-10-09 08:35:48 +02:00
savegameDeleted ( qobject_cast < SavegameWidget * > ( sender ( ) ) , true ) ;
2016-04-03 12:54:55 +02:00
}
2017-03-01 15:19:40 +01:00
void ProfileInterface : : savegameDeleted ( SavegameWidget * sgdWidget , bool isRemoteEmited )
2016-04-03 12:54:55 +02:00
{
2016-04-03 03:56:24 +02:00
SavegameData * savegame = sgdWidget - > getSavegame ( ) ;
2021-03-27 08:23:05 +01:00
if ( sgdWidget - > isSelected ( ) )
sgdWidget - > setSelected ( false ) ;
2016-04-13 00:41:06 +02:00
widgets . remove ( sgdWidget ) ;
2017-03-01 15:19:40 +01:00
2017-10-12 22:42:15 +02:00
sgdWidget - > disconnect ( ) ;
2017-10-09 08:35:48 +02:00
sgdWidget - > removeEventFilter ( this ) ;
2021-03-27 08:23:05 +01:00
if ( sgdWidget = = previousWidget ) {
2017-10-09 08:35:48 +02:00
previousWidget = nullptr ;
}
2017-03-01 15:19:40 +01:00
// Deleting when the widget did send a event cause a crash
2017-10-12 22:42:15 +02:00
isRemoteEmited ? sgdWidget - > deleteLater ( ) : delete sgdWidget ;
2017-03-01 15:19:40 +01:00
2016-04-03 03:56:24 +02:00
savegames . removeAll ( savegame ) ;
delete savegame ;
2016-03-29 11:22:41 +02:00
}
2017-02-11 04:21:55 +01:00
void ProfileInterface : : pictureDeleted_event ( )
2016-03-29 11:22:41 +02:00
{
2017-10-09 08:35:48 +02:00
pictureDeleted ( qobject_cast < SnapmaticWidget * > ( sender ( ) ) , true ) ;
2016-04-03 12:54:55 +02:00
}
2017-03-01 15:19:40 +01:00
void ProfileInterface : : pictureDeleted ( SnapmaticWidget * picWidget , bool isRemoteEmited )
2016-04-03 12:54:55 +02:00
{
2016-04-03 03:56:24 +02:00
SnapmaticPicture * picture = picWidget - > getPicture ( ) ;
2021-03-27 08:23:05 +01:00
if ( picWidget - > isSelected ( ) )
picWidget - > setSelected ( false ) ;
2016-04-13 00:41:06 +02:00
widgets . remove ( picWidget ) ;
2017-03-01 15:19:40 +01:00
2017-10-12 22:42:15 +02:00
picWidget - > disconnect ( ) ;
2017-10-09 08:35:48 +02:00
picWidget - > removeEventFilter ( this ) ;
2021-03-27 08:23:05 +01:00
if ( picWidget = = previousWidget ) {
2017-10-09 08:35:48 +02:00
previousWidget = nullptr ;
}
2017-03-01 15:19:40 +01:00
// Deleting when the widget did send a event cause a crash
2017-10-12 22:42:15 +02:00
isRemoteEmited ? picWidget - > deleteLater ( ) : delete picWidget ;
2017-03-01 15:19:40 +01:00
2016-04-03 03:56:24 +02:00
pictures . removeAll ( picture ) ;
delete picture ;
2016-03-29 11:22:41 +02:00
}
void ProfileInterface : : on_cmdCloseProfile_clicked ( )
{
emit profileClosed ( ) ;
}
void ProfileInterface : : on_cmdImport_clicked ( )
{
2016-04-14 01:27:29 +02:00
QSettings settings ( GTA5SYNC_APPVENDOR , GTA5SYNC_APPSTR ) ;
2016-03-29 11:22:41 +02:00
settings . beginGroup ( " FileDialogs " ) ;
2017-10-12 22:21:45 +02:00
bool dontUseNativeDialog = settings . value ( " DontUseNativeDialog " , false ) . toBool ( ) ;
2016-04-24 13:34:03 +02:00
settings . beginGroup ( " ImportCopy " ) ;
2016-03-29 11:22:41 +02:00
2017-03-01 15:19:40 +01:00
fileDialogPreOpen : //Work?
2016-03-29 11:22:41 +02:00
QFileDialog fileDialog ( this ) ;
2016-04-13 00:11:20 +02:00
fileDialog . setFileMode ( QFileDialog : : ExistingFiles ) ;
2016-03-29 11:22:41 +02:00
fileDialog . setViewMode ( QFileDialog : : Detail ) ;
fileDialog . setAcceptMode ( QFileDialog : : AcceptOpen ) ;
2017-10-12 22:21:45 +02:00
fileDialog . setOption ( QFileDialog : : DontUseNativeDialog , dontUseNativeDialog ) ;
2023-01-27 20:09:43 +01:00
fileDialog . setWindowFlag ( Qt : : WindowContextHelpButtonHint , false ) ;
2016-04-08 16:55:28 +02:00
fileDialog . setWindowTitle ( tr ( " Import... " ) ) ;
2018-07-27 04:26:10 +02:00
fileDialog . setLabelText ( QFileDialog : : Accept , tr ( " Import... " ) ) ;
2016-03-29 11:22:41 +02:00
2017-10-09 08:35:48 +02:00
// Getting readable Image formats
QString imageFormatsStr = " " ;
2021-03-27 08:23:05 +01:00
for ( const QByteArray & imageFormat : QImageReader : : supportedImageFormats ( ) ) {
2017-10-09 08:35:48 +02:00
imageFormatsStr + = QString ( " *. " ) % QString : : fromUtf8 ( imageFormat ) . toLower ( ) % " " ;
}
QString importableFormatsStr = QString ( " *.g5e SGTA* PGTA* " ) ;
2021-03-27 08:23:05 +01:00
if ( ! imageFormatsStr . trimmed ( ) . isEmpty ( ) ) {
2017-10-09 08:35:48 +02:00
importableFormatsStr = QString ( " *.g5e%1SGTA* PGTA* " ) . arg ( imageFormatsStr ) ;
}
2016-03-29 11:22:41 +02:00
QStringList filters ;
2017-10-09 08:35:48 +02:00
filters < < tr ( " Importable files (%1) " ) . arg ( importableFormatsStr ) ;
2017-01-27 04:33:27 +01:00
filters < < tr ( " GTA V Export (*.g5e) " ) ;
2016-03-29 11:22:41 +02:00
filters < < tr ( " Savegames files (SGTA*) " ) ;
filters < < tr ( " Snapmatic pictures (PGTA*) " ) ;
2017-10-09 08:35:48 +02:00
filters < < tr ( " All image files (%1) " ) . arg ( imageFormatsStr . trimmed ( ) ) ;
2016-03-29 11:22:41 +02:00
filters < < tr ( " All files (**) " ) ;
fileDialog . setNameFilters ( filters ) ;
2016-03-29 15:14:49 +02:00
QList < QUrl > sidebarUrls = SidebarGenerator : : generateSidebarUrls ( fileDialog . sidebarUrls ( ) ) ;
2016-03-29 11:22:41 +02:00
fileDialog . setSidebarUrls ( sidebarUrls ) ;
2017-09-05 03:36:01 +02:00
fileDialog . setDirectory ( settings . value ( profileName % " +Directory " , StandardPaths : : documentsLocation ( ) ) . toString ( ) ) ;
fileDialog . restoreGeometry ( settings . value ( profileName % " +Geometry " , " " ) . toByteArray ( ) ) ;
2016-03-29 11:22:41 +02:00
2021-03-27 08:23:05 +01:00
if ( fileDialog . exec ( ) ) {
2016-03-29 11:22:41 +02:00
QStringList selectedFiles = fileDialog . selectedFiles ( ) ;
2021-03-27 08:23:05 +01:00
if ( selectedFiles . length ( ) = = 1 ) {
2016-03-29 11:22:41 +02:00
QString selectedFile = selectedFiles . at ( 0 ) ;
2017-11-22 14:59:40 +01:00
QDateTime importDateTime = QDateTime : : currentDateTime ( ) ;
2018-06-14 11:36:01 +02:00
if ( ! importFile ( selectedFile , importDateTime , true ) ) goto fileDialogPreOpen ; //Work?
2016-04-13 00:11:20 +02:00
}
2021-03-27 08:23:05 +01:00
else if ( selectedFiles . length ( ) > 1 ) {
2017-07-28 19:53:07 +02:00
importFilesProgress ( selectedFiles ) ;
2016-03-29 11:22:41 +02:00
}
2021-03-27 08:23:05 +01:00
else {
2018-07-27 04:26:10 +02:00
QMessageBox : : warning ( this , tr ( " Import... " ) , tr ( " No valid file is selected " ) ) ;
2017-03-01 15:19:40 +01:00
goto fileDialogPreOpen ; //Work?
2016-03-29 11:22:41 +02:00
}
}
2017-09-05 03:36:01 +02:00
settings . setValue ( profileName % " +Geometry " , fileDialog . saveGeometry ( ) ) ;
settings . setValue ( profileName % " +Directory " , fileDialog . directory ( ) . absolutePath ( ) ) ;
2016-04-24 13:34:03 +02:00
settings . endGroup ( ) ;
2016-03-29 11:22:41 +02:00
settings . endGroup ( ) ;
}
2018-06-29 08:20:01 +02:00
bool ProfileInterface : : importFilesProgress ( QStringList selectedFiles )
2017-07-28 19:53:07 +02:00
{
int maximumId = selectedFiles . length ( ) ;
2017-12-17 13:03:43 +01:00
int overallId = 0 ;
2017-07-28 19:53:07 +02:00
QString errorStr ;
2017-12-17 13:03:43 +01:00
QStringList failed ;
2017-07-28 19:53:07 +02:00
// Progress dialog
QProgressDialog pbDialog ( this ) ;
2023-01-27 20:09:43 +01:00
pbDialog . setWindowFlag ( Qt : : WindowContextHelpButtonHint , false ) ;
pbDialog . setWindowFlag ( Qt : : WindowCloseButtonHint , false ) ;
2017-07-28 19:53:07 +02:00
pbDialog . setWindowTitle ( tr ( " Import... " ) ) ;
2017-12-17 13:03:43 +01:00
pbDialog . setLabelText ( tr ( " Import file %1 of %2 files " ) . arg ( QString : : number ( 1 ) , QString : : number ( maximumId ) ) ) ;
2017-07-28 19:53:07 +02:00
pbDialog . setRange ( 1 , maximumId ) ;
pbDialog . setValue ( 1 ) ;
pbDialog . setModal ( true ) ;
QList < QPushButton * > pbBtn = pbDialog . findChildren < QPushButton * > ( ) ;
pbBtn . at ( 0 ) - > setDisabled ( true ) ;
QList < QProgressBar * > pbBar = pbDialog . findChildren < QProgressBar * > ( ) ;
pbBar . at ( 0 ) - > setTextVisible ( false ) ;
2017-12-17 13:03:43 +01:00
pbDialog . setAutoClose ( false ) ;
2017-07-28 19:53:07 +02:00
pbDialog . show ( ) ;
2017-12-12 04:45:46 +01:00
// THREADING HERE PLEASE
2017-11-22 14:59:40 +01:00
QDateTime importDateTime = QDateTime : : currentDateTime ( ) ;
2021-03-27 08:23:05 +01:00
for ( const QString & selectedFile : selectedFiles ) {
2017-12-17 13:03:43 +01:00
overallId + + ;
2017-07-28 19:53:07 +02:00
pbDialog . setValue ( overallId ) ;
pbDialog . setLabelText ( tr ( " Import file %1 of %2 files " ) . arg ( QString : : number ( overallId ) , QString : : number ( maximumId ) ) ) ;
2017-11-22 14:59:40 +01:00
importDateTime = QDateTime : : currentDateTime ( ) ;
2021-03-27 08:23:05 +01:00
if ( ! importFile ( selectedFile , importDateTime , false ) ) {
2017-12-17 13:03:43 +01:00
failed < < QFileInfo ( selectedFile ) . fileName ( ) ;
2017-07-28 19:53:07 +02:00
}
}
2017-12-12 04:45:46 +01:00
2017-07-28 19:53:07 +02:00
pbDialog . close ( ) ;
2021-03-27 08:23:05 +01:00
for ( const QString & curErrorStr : qAsConst ( failed ) ) {
2017-09-05 03:36:01 +02:00
errorStr + = " , " % curErrorStr ;
2017-07-28 19:53:07 +02:00
}
2021-03-27 08:23:05 +01:00
if ( errorStr ! = " " ) {
2017-07-28 19:53:07 +02:00
errorStr . remove ( 0 , 2 ) ;
2018-07-27 04:26:10 +02:00
QMessageBox : : warning ( this , tr ( " Import... " ) , tr ( " Import failed with... \n \n %1 " ) . arg ( errorStr ) ) ;
2018-06-29 08:20:01 +02:00
return false ;
2017-07-28 19:53:07 +02:00
}
2018-06-29 08:20:01 +02:00
return true ;
2017-07-28 19:53:07 +02:00
}
2018-06-14 11:36:01 +02:00
bool ProfileInterface : : importFile ( QString selectedFile , QDateTime importDateTime , bool notMultiple )
2016-04-13 00:11:20 +02:00
{
QString selectedFileName = QFileInfo ( selectedFile ) . fileName ( ) ;
2021-03-27 08:23:05 +01:00
if ( QFile : : exists ( selectedFile ) ) {
if ( ( selectedFileName . left ( 4 ) = = " PGTA " & & ! selectedFileName . contains ( ' . ' ) ) | | selectedFileName . right ( 4 ) = = " .g5e " ) {
2016-04-13 00:11:20 +02:00
SnapmaticPicture * picture = new SnapmaticPicture ( selectedFile ) ;
2021-03-27 08:23:05 +01:00
if ( picture - > readingPicture ( true ) ) {
2017-02-11 04:21:55 +01:00
bool success = importSnapmaticPicture ( picture , notMultiple ) ;
2021-03-27 08:23:05 +01:00
if ( ! success )
delete picture ;
2018-07-28 04:55:55 +02:00
# ifdef GTA5SYNC_TELEMETRY
2021-03-27 08:23:05 +01:00
if ( success & & notMultiple ) {
2018-07-28 04:55:55 +02:00
QSettings telemetrySettings ( GTA5SYNC_APPVENDOR , GTA5SYNC_APPSTR ) ;
telemetrySettings . beginGroup ( " Telemetry " ) ;
bool pushUsageData = telemetrySettings . value ( " PushUsageData " , false ) . toBool ( ) ;
telemetrySettings . endGroup ( ) ;
2021-03-27 08:23:05 +01:00
if ( pushUsageData & & Telemetry - > canPush ( ) ) {
2018-07-28 04:55:55 +02:00
QJsonDocument jsonDocument ;
QJsonObject jsonObject ;
jsonObject [ " Type " ] = " ImportSuccess " ;
2023-02-27 14:17:50 +01:00
jsonObject [ " ImportSize " ] = QString : : number ( picture - > getPictureSize ( ) ) ;
2021-01-27 14:35:42 +01:00
# if QT_VERSION >= 0x060000
jsonObject [ " ImportTime " ] = QString : : number ( QDateTime : : currentDateTimeUtc ( ) . toSecsSinceEpoch ( ) ) ;
# else
2018-07-28 04:55:55 +02:00
jsonObject [ " ImportTime " ] = QString : : number ( QDateTime : : currentDateTimeUtc ( ) . toTime_t ( ) ) ;
2021-01-27 14:35:42 +01:00
# endif
2018-07-28 04:55:55 +02:00
jsonObject [ " ImportType " ] = " Snapmatic " ;
jsonDocument . setObject ( jsonObject ) ;
Telemetry - > push ( TelemetryCategory : : PersonalData , jsonDocument ) ;
}
}
# endif
2016-04-13 00:32:14 +02:00
return success ;
2016-04-13 00:11:20 +02:00
}
2021-03-27 08:23:05 +01:00
else {
if ( notMultiple )
QMessageBox : : warning ( this , tr ( " Import... " ) , tr ( " Failed to read Snapmatic picture " ) ) ;
2016-04-13 00:11:20 +02:00
delete picture ;
return false ;
}
}
2021-03-27 08:23:05 +01:00
else if ( selectedFileName . left ( 4 ) = = " SGTA " ) {
2016-04-13 00:11:20 +02:00
SavegameData * savegame = new SavegameData ( selectedFile ) ;
2021-03-27 08:23:05 +01:00
if ( savegame - > readingSavegame ( ) ) {
2017-02-11 04:21:55 +01:00
bool success = importSavegameData ( savegame , selectedFile , notMultiple ) ;
2021-03-27 08:23:05 +01:00
if ( ! success )
delete savegame ;
2018-07-28 04:55:55 +02:00
# ifdef GTA5SYNC_TELEMETRY
2021-03-27 08:23:05 +01:00
if ( success & & notMultiple ) {
2018-07-28 04:55:55 +02:00
QSettings telemetrySettings ( GTA5SYNC_APPVENDOR , GTA5SYNC_APPSTR ) ;
telemetrySettings . beginGroup ( " Telemetry " ) ;
bool pushUsageData = telemetrySettings . value ( " PushUsageData " , false ) . toBool ( ) ;
telemetrySettings . endGroup ( ) ;
2021-03-27 08:23:05 +01:00
if ( pushUsageData & & Telemetry - > canPush ( ) ) {
2018-07-28 04:55:55 +02:00
QJsonDocument jsonDocument ;
QJsonObject jsonObject ;
jsonObject [ " Type " ] = " ImportSuccess " ;
2021-01-27 14:35:42 +01:00
# if QT_VERSION >= 0x060000
jsonObject [ " ImportTime " ] = QString : : number ( QDateTime : : currentDateTimeUtc ( ) . toSecsSinceEpoch ( ) ) ;
# else
2018-07-28 04:55:55 +02:00
jsonObject [ " ImportTime " ] = QString : : number ( QDateTime : : currentDateTimeUtc ( ) . toTime_t ( ) ) ;
2021-01-27 14:35:42 +01:00
# endif
2018-07-28 04:55:55 +02:00
jsonObject [ " ImportType " ] = " Savegame " ;
jsonDocument . setObject ( jsonObject ) ;
Telemetry - > push ( TelemetryCategory : : PersonalData , jsonDocument ) ;
}
}
# endif
2016-04-13 00:32:14 +02:00
return success ;
2016-04-13 00:11:20 +02:00
}
2021-03-27 08:23:05 +01:00
else {
2018-07-27 04:26:10 +02:00
if ( notMultiple ) QMessageBox : : warning ( this , tr ( " Import... " ) , tr ( " Failed to read Savegame file " ) ) ;
2016-04-13 00:11:20 +02:00
delete savegame ;
return false ;
}
}
2021-03-27 08:23:05 +01:00
else if ( isSupportedImageFile ( selectedFileName ) ) {
2017-02-11 04:21:55 +01:00
SnapmaticPicture * picture = new SnapmaticPicture ( " :/template/template.g5e " ) ;
2021-03-27 08:23:05 +01:00
if ( picture - > readingPicture ( false ) ) {
if ( ! notMultiple ) {
2017-09-17 23:27:49 +02:00
QFile snapmaticFile ( selectedFile ) ;
2021-03-27 08:23:05 +01:00
if ( ! snapmaticFile . open ( QFile : : ReadOnly ) ) {
2017-09-17 23:27:49 +02:00
delete picture ;
return false ;
}
2017-02-11 04:21:55 +01:00
QImage snapmaticImage ;
2017-09-17 23:27:49 +02:00
QImageReader snapmaticImageReader ;
snapmaticImageReader . setDecideFormatFromContent ( true ) ;
snapmaticImageReader . setDevice ( & snapmaticFile ) ;
2021-03-27 08:23:05 +01:00
if ( ! snapmaticImageReader . read ( & snapmaticImage ) ) {
2017-02-11 04:21:55 +01:00
delete picture ;
return false ;
}
2017-09-17 23:27:49 +02:00
QString customImageTitle ;
QPixmap snapmaticPixmap ( 960 , 536 ) ;
snapmaticPixmap . fill ( Qt : : black ) ;
QPainter snapmaticPainter ( & snapmaticPixmap ) ;
2021-03-27 08:23:05 +01:00
if ( snapmaticImage . height ( ) = = snapmaticImage . width ( ) ) {
2017-02-11 04:21:55 +01:00
// Avatar mode
int diffWidth = 0 ;
int diffHeight = 0 ;
snapmaticImage = snapmaticImage . scaled ( 470 , 470 , Qt : : KeepAspectRatio , Qt : : SmoothTransformation ) ;
2021-03-27 08:23:05 +01:00
if ( snapmaticImage . width ( ) > snapmaticImage . height ( ) ) {
2017-02-11 04:21:55 +01:00
diffHeight = 470 - snapmaticImage . height ( ) ;
diffHeight = diffHeight / 2 ;
}
2021-03-27 08:23:05 +01:00
else if ( snapmaticImage . width ( ) < snapmaticImage . height ( ) ) {
2017-02-11 04:21:55 +01:00
diffWidth = 470 - snapmaticImage . width ( ) ;
diffWidth = diffWidth / 2 ;
}
snapmaticPainter . drawImage ( 145 + diffWidth , 66 + diffHeight , snapmaticImage ) ;
2017-11-22 14:59:40 +01:00
customImageTitle = ImportDialog : : tr ( " Custom Avatar " , " Custom Avatar Description in SC, don't use Special Character! " ) ;
2017-02-11 04:21:55 +01:00
}
2021-03-27 08:23:05 +01:00
else {
2017-02-11 04:21:55 +01:00
// Picture mode
int diffWidth = 0 ;
int diffHeight = 0 ;
snapmaticImage = snapmaticImage . scaled ( 960 , 536 , Qt : : KeepAspectRatio , Qt : : SmoothTransformation ) ;
2021-03-27 08:23:05 +01:00
if ( snapmaticImage . width ( ) ! = 960 ) {
2017-02-11 04:21:55 +01:00
diffWidth = 960 - snapmaticImage . width ( ) ;
diffWidth = diffWidth / 2 ;
}
2021-03-27 08:23:05 +01:00
else if ( snapmaticImage . height ( ) ! = 536 ) {
2017-02-11 04:21:55 +01:00
diffHeight = 536 - snapmaticImage . height ( ) ;
diffHeight = diffHeight / 2 ;
}
snapmaticPainter . drawImage ( 0 + diffWidth , 0 + diffHeight , snapmaticImage ) ;
2017-11-22 14:59:40 +01:00
customImageTitle = ImportDialog : : tr ( " Custom Picture " , " Custom Picture Description in SC, don't use Special Character! " ) ;
2017-02-11 04:21:55 +01:00
}
snapmaticPainter . end ( ) ;
2021-03-27 08:23:05 +01:00
if ( ! picture - > setImage ( snapmaticPixmap . toImage ( ) ) ) {
2017-02-11 04:21:55 +01:00
delete picture ;
return false ;
}
SnapmaticProperties spJson = picture - > getSnapmaticProperties ( ) ;
2018-06-14 11:36:01 +02:00
spJson . uid = getRandomUid ( ) ;
2017-10-12 22:21:45 +02:00
bool fExists = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) ) ;
2018-06-14 11:36:01 +02:00
bool fExistsBackup = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) % " .bak " ) ;
2017-10-12 22:21:45 +02:00
bool fExistsHidden = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) % " .hidden " ) ;
2017-08-31 03:13:31 +02:00
int cEnough = 0 ;
2021-03-27 08:23:05 +01:00
while ( ( fExists | | fExistsBackup | | fExistsHidden ) & & cEnough < findRetryLimit ) {
2018-06-14 11:36:01 +02:00
spJson . uid = getRandomUid ( ) ;
2017-10-12 22:21:45 +02:00
fExists = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) ) ;
2018-06-14 11:36:01 +02:00
fExistsBackup = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) % " .bak " ) ;
2017-10-12 22:21:45 +02:00
fExistsHidden = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) % " .hidden " ) ;
2017-08-31 03:13:31 +02:00
cEnough + + ;
}
2017-11-22 14:59:40 +01:00
spJson . createdDateTime = importDateTime ;
2020-09-28 05:33:04 +02:00
# if QT_VERSION >= 0x060000
2020-11-05 18:32:20 +01:00
quint64 timestamp = spJson . createdDateTime . toSecsSinceEpoch ( ) ;
if ( timestamp > UINT32_MAX ) {
timestamp = UINT32_MAX ;
}
spJson . createdTimestamp = ( quint32 ) timestamp ;
2020-09-28 05:33:04 +02:00
# else
2017-02-11 04:21:55 +01:00
spJson . createdTimestamp = spJson . createdDateTime . toTime_t ( ) ;
2020-09-28 05:33:04 +02:00
# endif
2017-02-11 04:21:55 +01:00
picture - > setSnapmaticProperties ( spJson ) ;
2021-05-23 07:12:56 +02:00
const QString picFileName = QString ( " PGTA5%1 " ) . arg ( QString : : number ( spJson . uid ) ) ;
picture - > setPicFileName ( picFileName ) ;
2017-02-11 04:21:55 +01:00
picture - > setPictureTitle ( customImageTitle ) ;
picture - > updateStrings ( ) ;
bool success = importSnapmaticPicture ( picture , notMultiple ) ;
2021-03-27 08:23:05 +01:00
if ( ! success )
delete picture ;
2017-02-11 04:21:55 +01:00
return success ;
}
2021-03-27 08:23:05 +01:00
else {
2017-02-11 04:21:55 +01:00
bool success = false ;
2017-09-17 23:27:49 +02:00
QFile snapmaticFile ( selectedFile ) ;
2021-03-27 08:23:05 +01:00
if ( ! snapmaticFile . open ( QFile : : ReadOnly ) ) {
2018-07-27 04:26:10 +02:00
QMessageBox : : warning ( this , tr ( " Import... " ) , tr ( " Can't import %1 because file can't be open " ) . arg ( " \" " + selectedFileName + " \" " ) ) ;
2017-09-17 23:27:49 +02:00
delete picture ;
return false ;
}
2018-06-17 09:27:10 +02:00
QImage * snapmaticImage = new QImage ( ) ;
2017-09-17 23:27:49 +02:00
QImageReader snapmaticImageReader ;
snapmaticImageReader . setDecideFormatFromContent ( true ) ;
snapmaticImageReader . setDevice ( & snapmaticFile ) ;
2021-03-27 08:23:05 +01:00
if ( ! snapmaticImageReader . read ( snapmaticImage ) ) {
2018-07-27 04:26:10 +02:00
QMessageBox : : warning ( this , tr ( " Import... " ) , tr ( " Can't import %1 because file can't be parsed properly " ) . arg ( " \" " + selectedFileName + " \" " ) ) ;
2018-06-17 09:27:10 +02:00
delete snapmaticImage ;
2017-02-11 04:21:55 +01:00
delete picture ;
return false ;
}
2018-07-17 16:41:38 +02:00
ImportDialog * importDialog = new ImportDialog ( profileName , this ) ;
2018-06-17 09:27:10 +02:00
importDialog - > setImage ( snapmaticImage ) ;
2017-02-11 04:21:55 +01:00
importDialog - > setModal ( true ) ;
importDialog - > show ( ) ;
importDialog - > exec ( ) ;
2021-03-27 08:23:05 +01:00
if ( importDialog - > isImportAgreed ( ) ) {
if ( picture - > setImage ( importDialog - > image ( ) , importDialog - > isUnlimitedBuffer ( ) ) ) {
2017-02-11 04:21:55 +01:00
SnapmaticProperties spJson = picture - > getSnapmaticProperties ( ) ;
2018-06-14 11:36:01 +02:00
spJson . uid = getRandomUid ( ) ;
2017-10-12 22:21:45 +02:00
bool fExists = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) ) ;
2018-06-14 11:36:01 +02:00
bool fExistsBackup = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) % " .bak " ) ;
2017-10-12 22:21:45 +02:00
bool fExistsHidden = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) % " .hidden " ) ;
2017-08-31 03:13:31 +02:00
int cEnough = 0 ;
2021-03-27 08:23:05 +01:00
while ( ( fExists | | fExistsBackup | | fExistsHidden ) & & cEnough < findRetryLimit ) {
2018-06-14 11:36:01 +02:00
spJson . uid = getRandomUid ( ) ;
2017-10-12 22:21:45 +02:00
fExists = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) ) ;
2018-06-14 11:36:01 +02:00
fExistsBackup = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) % " .bak " ) ;
2017-10-12 22:21:45 +02:00
fExistsHidden = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) % " .hidden " ) ;
2017-08-31 03:13:31 +02:00
cEnough + + ;
}
2017-11-22 14:59:40 +01:00
spJson . createdDateTime = importDateTime ;
2020-09-28 05:33:04 +02:00
# if QT_VERSION >= 0x060000
2020-11-05 18:32:20 +01:00
quint64 timestamp = spJson . createdDateTime . toSecsSinceEpoch ( ) ;
if ( timestamp > UINT32_MAX ) {
timestamp = UINT32_MAX ;
}
spJson . createdTimestamp = ( quint32 ) timestamp ;
2020-09-28 05:33:04 +02:00
# else
2017-02-11 04:21:55 +01:00
spJson . createdTimestamp = spJson . createdDateTime . toTime_t ( ) ;
2020-09-28 05:33:04 +02:00
# endif
2017-02-11 04:21:55 +01:00
picture - > setSnapmaticProperties ( spJson ) ;
2021-05-23 07:12:56 +02:00
const QString picFileName = QString ( " PGTA5%1 " ) . arg ( QString : : number ( spJson . uid ) ) ;
picture - > setPicFileName ( picFileName ) ;
2017-02-11 04:21:55 +01:00
picture - > setPictureTitle ( importDialog - > getImageTitle ( ) ) ;
picture - > updateStrings ( ) ;
success = importSnapmaticPicture ( picture , notMultiple ) ;
2018-07-28 04:55:55 +02:00
# ifdef GTA5SYNC_TELEMETRY
2021-03-27 08:23:05 +01:00
if ( success ) {
2018-07-28 04:55:55 +02:00
QSettings telemetrySettings ( GTA5SYNC_APPVENDOR , GTA5SYNC_APPSTR ) ;
telemetrySettings . beginGroup ( " Telemetry " ) ;
bool pushUsageData = telemetrySettings . value ( " PushUsageData " , false ) . toBool ( ) ;
telemetrySettings . endGroup ( ) ;
2021-03-27 08:23:05 +01:00
if ( pushUsageData & & Telemetry - > canPush ( ) ) {
2018-07-28 04:55:55 +02:00
QJsonDocument jsonDocument ;
QJsonObject jsonObject ;
jsonObject [ " Type " ] = " ImportSuccess " ;
jsonObject [ " ExtraFlag " ] = " Dialog " ;
2023-02-27 14:17:50 +01:00
jsonObject [ " ImportSize " ] = QString : : number ( picture - > getPictureSize ( ) ) ;
2021-01-27 14:35:42 +01:00
# if QT_VERSION >= 0x060000
jsonObject [ " ImportTime " ] = QString : : number ( QDateTime : : currentDateTimeUtc ( ) . toSecsSinceEpoch ( ) ) ;
# else
2018-07-28 04:55:55 +02:00
jsonObject [ " ImportTime " ] = QString : : number ( QDateTime : : currentDateTimeUtc ( ) . toTime_t ( ) ) ;
2021-01-27 14:35:42 +01:00
# endif
2018-07-28 04:55:55 +02:00
jsonObject [ " ImportType " ] = " Image " ;
jsonDocument . setObject ( jsonObject ) ;
Telemetry - > push ( TelemetryCategory : : PersonalData , jsonDocument ) ;
}
}
# endif
2017-02-11 04:21:55 +01:00
}
}
2021-03-27 08:23:05 +01:00
else {
2017-02-11 04:21:55 +01:00
delete picture ;
success = true ;
}
delete importDialog ;
2021-03-27 08:23:05 +01:00
if ( ! success )
delete picture ;
2017-02-11 04:21:55 +01:00
return success ;
}
}
2021-03-27 08:23:05 +01:00
else {
2017-02-11 04:21:55 +01:00
delete picture ;
return false ;
}
}
2021-03-27 08:23:05 +01:00
else {
2016-04-13 00:11:20 +02:00
SnapmaticPicture * picture = new SnapmaticPicture ( selectedFile ) ;
SavegameData * savegame = new SavegameData ( selectedFile ) ;
2021-03-27 08:23:05 +01:00
if ( picture - > readingPicture ( ) ) {
2017-02-11 04:21:55 +01:00
bool success = importSnapmaticPicture ( picture , notMultiple ) ;
2016-04-13 00:11:20 +02:00
delete savegame ;
2021-03-27 08:23:05 +01:00
if ( ! success )
delete picture ;
2018-07-28 04:55:55 +02:00
# ifdef GTA5SYNC_TELEMETRY
2021-03-27 08:23:05 +01:00
if ( success & & notMultiple ) {
2018-07-28 04:55:55 +02:00
QSettings telemetrySettings ( GTA5SYNC_APPVENDOR , GTA5SYNC_APPSTR ) ;
telemetrySettings . beginGroup ( " Telemetry " ) ;
bool pushUsageData = telemetrySettings . value ( " PushUsageData " , false ) . toBool ( ) ;
telemetrySettings . endGroup ( ) ;
2021-03-27 08:23:05 +01:00
if ( pushUsageData & & Telemetry - > canPush ( ) ) {
2018-07-28 04:55:55 +02:00
QJsonDocument jsonDocument ;
QJsonObject jsonObject ;
jsonObject [ " Type " ] = " ImportSuccess " ;
2023-02-27 14:17:50 +01:00
jsonObject [ " ImportSize " ] = QString : : number ( picture - > getPictureSize ( ) ) ;
2021-01-27 14:35:42 +01:00
# if QT_VERSION >= 0x060000
jsonObject [ " ImportTime " ] = QString : : number ( QDateTime : : currentDateTimeUtc ( ) . toSecsSinceEpoch ( ) ) ;
# else
2018-07-28 04:55:55 +02:00
jsonObject [ " ImportTime " ] = QString : : number ( QDateTime : : currentDateTimeUtc ( ) . toTime_t ( ) ) ;
2021-01-27 14:35:42 +01:00
# endif
2018-07-28 04:55:55 +02:00
jsonObject [ " ImportType " ] = " Snapmatic " ;
jsonDocument . setObject ( jsonObject ) ;
Telemetry - > push ( TelemetryCategory : : PersonalData , jsonDocument ) ;
}
}
# endif
2016-04-13 00:32:14 +02:00
return success ;
2016-04-13 00:11:20 +02:00
}
2021-03-27 08:23:05 +01:00
else if ( savegame - > readingSavegame ( ) ) {
2017-02-11 04:21:55 +01:00
bool success = importSavegameData ( savegame , selectedFile , notMultiple ) ;
2016-04-13 00:11:20 +02:00
delete picture ;
2021-03-27 08:23:05 +01:00
if ( ! success )
delete savegame ;
2018-07-28 04:55:55 +02:00
# ifdef GTA5SYNC_TELEMETRY
2021-03-27 08:23:05 +01:00
if ( success & & notMultiple ) {
2018-07-28 04:55:55 +02:00
QSettings telemetrySettings ( GTA5SYNC_APPVENDOR , GTA5SYNC_APPSTR ) ;
telemetrySettings . beginGroup ( " Telemetry " ) ;
bool pushUsageData = telemetrySettings . value ( " PushUsageData " , false ) . toBool ( ) ;
telemetrySettings . endGroup ( ) ;
2021-03-27 08:23:05 +01:00
if ( pushUsageData & & Telemetry - > canPush ( ) ) {
2018-07-28 04:55:55 +02:00
QJsonDocument jsonDocument ;
QJsonObject jsonObject ;
jsonObject [ " Type " ] = " ImportSuccess " ;
2021-01-27 14:35:42 +01:00
# if QT_VERSION >= 0x060000
jsonObject [ " ImportTime " ] = QString : : number ( QDateTime : : currentDateTimeUtc ( ) . toSecsSinceEpoch ( ) ) ;
# else
2018-07-28 04:55:55 +02:00
jsonObject [ " ImportTime " ] = QString : : number ( QDateTime : : currentDateTimeUtc ( ) . toTime_t ( ) ) ;
2021-01-27 14:35:42 +01:00
# endif
2018-07-28 04:55:55 +02:00
jsonObject [ " ImportType " ] = " Savegame " ;
jsonDocument . setObject ( jsonObject ) ;
Telemetry - > push ( TelemetryCategory : : PersonalData , jsonDocument ) ;
}
}
# endif
2016-04-13 00:32:14 +02:00
return success ;
2016-04-13 00:11:20 +02:00
}
2021-03-27 08:23:05 +01:00
else {
2017-10-09 08:35:48 +02:00
# ifdef GTA5SYNC_DEBUG
qDebug ( ) < < " ImportError SnapmaticPicture " < < picture - > getLastStep ( ) ;
qDebug ( ) < < " ImportError SavegameData " < < savegame - > getLastStep ( ) ;
# endif
2016-04-13 00:11:20 +02:00
delete picture ;
2017-10-09 08:35:48 +02:00
delete savegame ;
2018-07-27 04:26:10 +02:00
if ( notMultiple ) QMessageBox : : warning ( this , tr ( " Import... " ) , tr ( " Can't import %1 because file format can't be detected " ) . arg ( " \" " + selectedFileName + " \" " ) ) ;
2016-04-13 00:11:20 +02:00
return false ;
}
}
}
2021-03-27 08:23:05 +01:00
if ( notMultiple )
QMessageBox : : warning ( this , tr ( " Import... " ) , tr ( " No valid file is selected " ) ) ;
2016-04-13 00:11:20 +02:00
return false ;
}
2018-06-29 08:20:01 +02:00
bool ProfileInterface : : importUrls ( const QMimeData * mimeData )
{
QStringList pathList ;
2021-03-27 08:23:05 +01:00
for ( const QUrl & currentUrl : mimeData - > urls ( ) ) {
2018-06-29 08:20:01 +02:00
if ( currentUrl . isLocalFile ( ) )
pathList + = currentUrl . toLocalFile ( ) ;
}
2021-03-27 08:23:05 +01:00
if ( pathList . length ( ) = = 1 ) {
2018-06-29 08:20:01 +02:00
QString selectedFile = pathList . at ( 0 ) ;
return importFile ( selectedFile , QDateTime : : currentDateTime ( ) , true ) ;
}
2021-03-27 08:23:05 +01:00
else if ( pathList . length ( ) > 1 ) {
2018-06-29 08:20:01 +02:00
return importFilesProgress ( pathList ) ;
}
return false ;
}
2018-06-29 09:57:06 +02:00
bool ProfileInterface : : importRemote ( QUrl remoteUrl )
{
bool retValue = false ;
QDialog urlPasteDialog ( this ) ;
urlPasteDialog . setObjectName ( QStringLiteral ( " UrlPasteDialog " ) ) ;
2023-01-27 20:09:43 +01:00
urlPasteDialog . setWindowFlag ( Qt : : WindowContextHelpButtonHint , false ) ;
urlPasteDialog . setWindowFlag ( Qt : : WindowCloseButtonHint , false ) ;
2018-06-29 09:57:06 +02:00
urlPasteDialog . setWindowTitle ( tr ( " Import... " ) ) ;
urlPasteDialog . setModal ( true ) ;
QVBoxLayout urlPasteLayout ( & urlPasteDialog ) ;
urlPasteLayout . setObjectName ( QStringLiteral ( " UrlPasteLayout " ) ) ;
urlPasteDialog . setLayout ( & urlPasteLayout ) ;
UiModLabel urlPasteLabel ( & urlPasteDialog ) ;
urlPasteLabel . setObjectName ( QStringLiteral ( " UrlPasteLabel " ) ) ;
urlPasteLabel . setText ( tr ( " Prepare Content for Import... " ) ) ;
urlPasteLayout . addWidget ( & urlPasteLabel ) ;
urlPasteDialog . setFixedSize ( urlPasteDialog . sizeHint ( ) ) ;
urlPasteDialog . show ( ) ;
QNetworkAccessManager * netManager = new QNetworkAccessManager ( ) ;
QNetworkRequest netRequest ( remoteUrl ) ;
netRequest . setRawHeader ( " User-Agent " , AppEnv : : getUserAgent ( ) ) ;
netRequest . setRawHeader ( " Accept " , " text/html " ) ;
netRequest . setRawHeader ( " Accept-Charset " , " utf-8 " ) ;
netRequest . setRawHeader ( " Accept-Language " , " en-US,en;q=0.9 " ) ;
netRequest . setRawHeader ( " Connection " , " keep-alive " ) ;
QNetworkReply * netReply = netManager - > get ( netRequest ) ;
QEventLoop * downloadLoop = new QEventLoop ( ) ;
QObject : : connect ( netReply , SIGNAL ( finished ( ) ) , downloadLoop , SLOT ( quit ( ) ) ) ;
QTimer : : singleShot ( 30000 , downloadLoop , SLOT ( quit ( ) ) ) ;
downloadLoop - > exec ( ) ;
downloadLoop - > disconnect ( ) ;
delete downloadLoop ;
urlPasteDialog . close ( ) ;
2021-03-27 08:23:05 +01:00
if ( netReply - > isFinished ( ) ) {
2018-06-29 09:57:06 +02:00
QImage * snapmaticImage = new QImage ( ) ;
QImageReader snapmaticImageReader ;
snapmaticImageReader . setDecideFormatFromContent ( true ) ;
snapmaticImageReader . setDevice ( netReply ) ;
2021-03-27 08:23:05 +01:00
if ( snapmaticImageReader . read ( snapmaticImage ) ) {
2018-06-29 09:57:06 +02:00
retValue = importImage ( snapmaticImage , QDateTime : : currentDateTime ( ) ) ;
}
2021-03-27 08:23:05 +01:00
else {
2018-06-29 09:57:06 +02:00
delete snapmaticImage ;
}
}
2021-03-27 08:23:05 +01:00
else {
2018-06-29 09:57:06 +02:00
netReply - > abort ( ) ;
}
delete netReply ;
delete netManager ;
return retValue ;
}
2018-06-17 09:27:10 +02:00
bool ProfileInterface : : importImage ( QImage * snapmaticImage , QDateTime importDateTime )
{
SnapmaticPicture * picture = new SnapmaticPicture ( " :/template/template.g5e " ) ;
2021-03-27 08:23:05 +01:00
if ( picture - > readingPicture ( false ) ) {
2018-06-17 09:27:10 +02:00
bool success = false ;
2018-07-17 16:41:38 +02:00
ImportDialog * importDialog = new ImportDialog ( profileName , this ) ;
2018-06-17 09:27:10 +02:00
importDialog - > setImage ( snapmaticImage ) ;
importDialog - > setModal ( true ) ;
importDialog - > show ( ) ;
importDialog - > exec ( ) ;
2021-03-27 08:23:05 +01:00
if ( importDialog - > isImportAgreed ( ) ) {
if ( picture - > setImage ( importDialog - > image ( ) , importDialog - > isUnlimitedBuffer ( ) ) ) {
2018-06-17 09:27:10 +02:00
SnapmaticProperties spJson = picture - > getSnapmaticProperties ( ) ;
spJson . uid = getRandomUid ( ) ;
bool fExists = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) ) ;
bool fExistsBackup = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) % " .bak " ) ;
bool fExistsHidden = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) % " .hidden " ) ;
int cEnough = 0 ;
2021-03-27 08:23:05 +01:00
while ( ( fExists | | fExistsBackup | | fExistsHidden ) & & cEnough < findRetryLimit ) {
2018-06-17 09:27:10 +02:00
spJson . uid = getRandomUid ( ) ;
fExists = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) ) ;
fExistsBackup = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) % " .bak " ) ;
fExistsHidden = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( spJson . uid ) % " .hidden " ) ;
cEnough + + ;
}
spJson . createdDateTime = importDateTime ;
2020-09-28 05:33:04 +02:00
# if QT_VERSION >= 0x060000
2020-11-05 18:32:20 +01:00
quint64 timestamp = spJson . createdDateTime . toSecsSinceEpoch ( ) ;
if ( timestamp > UINT32_MAX ) {
timestamp = UINT32_MAX ;
}
spJson . createdTimestamp = ( quint32 ) timestamp ;
2020-09-28 05:33:04 +02:00
# else
2018-06-17 09:27:10 +02:00
spJson . createdTimestamp = spJson . createdDateTime . toTime_t ( ) ;
2020-09-28 05:33:04 +02:00
# endif
2018-06-17 09:27:10 +02:00
picture - > setSnapmaticProperties ( spJson ) ;
2021-05-23 07:12:56 +02:00
const QString picFileName = QString ( " PGTA5%1 " ) . arg ( QString : : number ( spJson . uid ) ) ;
picture - > setPicFileName ( picFileName ) ;
2018-06-17 09:27:10 +02:00
picture - > setPictureTitle ( importDialog - > getImageTitle ( ) ) ;
picture - > updateStrings ( ) ;
success = importSnapmaticPicture ( picture , true ) ;
}
}
2021-03-27 08:23:05 +01:00
else {
2018-06-17 09:27:10 +02:00
delete picture ;
success = true ;
}
delete importDialog ;
2021-03-27 08:23:05 +01:00
if ( ! success )
delete picture ;
2018-06-17 09:27:10 +02:00
return success ;
}
2021-03-27 08:23:05 +01:00
else {
2018-06-17 09:27:10 +02:00
delete picture ;
return false ;
}
}
2017-02-11 04:21:55 +01:00
bool ProfileInterface : : importSnapmaticPicture ( SnapmaticPicture * picture , bool warn )
2016-03-29 11:22:41 +02:00
{
2017-02-11 04:21:55 +01:00
QString picFileName = picture - > getPictureFileName ( ) ;
2017-10-12 22:21:45 +02:00
QString adjustedFileName = picture - > getOriginalPictureFileName ( ) ;
2021-03-27 08:23:05 +01:00
if ( ! picFileName . startsWith ( " PGTA5 " ) ) {
if ( warn )
QMessageBox : : warning ( this , tr ( " Import... " ) , tr ( " Failed to import the Snapmatic picture, file not begin with PGTA or end with .g5e " ) ) ;
2016-03-29 11:22:41 +02:00
return false ;
}
2021-03-27 08:23:05 +01:00
else if ( QFile : : exists ( profileFolder % " / " % adjustedFileName ) | | QFile : : exists ( profileFolder % " / " % adjustedFileName % " .hidden " ) ) {
2018-07-27 04:26:10 +02:00
SnapmaticProperties snapmaticProperties = picture - > getSnapmaticProperties ( ) ;
2021-03-27 08:23:05 +01:00
if ( warn ) {
2018-07-27 04:26:10 +02:00
int uchoice = QMessageBox : : question ( this , tr ( " Import... " ) , tr ( " A Snapmatic picture already exists with the uid %1, you want assign your import a new uid and timestamp? " ) . arg ( QString : : number ( snapmaticProperties . uid ) ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) ;
2021-03-27 08:23:05 +01:00
if ( uchoice = = QMessageBox : : Yes ) {
2018-07-27 04:26:10 +02:00
// Update Snapmatic uid
snapmaticProperties . uid = getRandomUid ( ) ;
snapmaticProperties . createdDateTime = QDateTime : : currentDateTime ( ) ;
2020-09-28 05:33:04 +02:00
# if QT_VERSION >= 0x060000
2020-11-05 18:32:20 +01:00
quint64 timestamp = snapmaticProperties . createdDateTime . toSecsSinceEpoch ( ) ;
if ( timestamp > UINT32_MAX ) {
timestamp = UINT32_MAX ;
}
snapmaticProperties . createdTimestamp = ( quint32 ) timestamp ;
2020-09-28 05:33:04 +02:00
# else
2018-07-27 04:26:10 +02:00
snapmaticProperties . createdTimestamp = snapmaticProperties . createdDateTime . toTime_t ( ) ;
2020-09-28 05:33:04 +02:00
# endif
2018-07-27 04:26:10 +02:00
bool fExists = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( snapmaticProperties . uid ) ) ;
bool fExistsBackup = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( snapmaticProperties . uid ) % " .bak " ) ;
bool fExistsHidden = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( snapmaticProperties . uid ) % " .hidden " ) ;
int cEnough = 0 ;
2021-03-27 08:23:05 +01:00
while ( ( fExists | | fExistsBackup | | fExistsHidden ) & & cEnough < findRetryLimit ) {
2018-07-27 04:26:10 +02:00
snapmaticProperties . uid = getRandomUid ( ) ;
fExists = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( snapmaticProperties . uid ) ) ;
fExistsBackup = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( snapmaticProperties . uid ) % " .bak " ) ;
fExistsHidden = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( snapmaticProperties . uid ) % " .hidden " ) ;
cEnough + + ;
}
2021-03-27 08:23:05 +01:00
if ( fExists | | fExistsBackup | | fExistsHidden ) {
2018-07-27 04:26:10 +02:00
// That should never happen
return false ;
}
2021-03-27 08:23:05 +01:00
if ( ! picture - > setSnapmaticProperties ( snapmaticProperties ) ) {
2018-07-27 04:26:10 +02:00
// That should never happen
return false ;
}
picture - > updateStrings ( ) ;
picFileName = picture - > getPictureFileName ( ) ;
adjustedFileName = picture - > getOriginalPictureFileName ( ) ;
}
2021-03-27 08:23:05 +01:00
else {
2018-07-27 04:26:10 +02:00
return false ;
}
}
2021-03-27 08:23:05 +01:00
else {
2018-07-27 04:26:10 +02:00
// Update Snapmatic uid
snapmaticProperties . uid = getRandomUid ( ) ;
snapmaticProperties . createdDateTime = QDateTime : : currentDateTime ( ) ;
2020-09-28 05:33:04 +02:00
# if QT_VERSION >= 0x060000
2020-11-05 18:32:20 +01:00
quint64 timestamp = snapmaticProperties . createdDateTime . toSecsSinceEpoch ( ) ;
if ( timestamp > UINT32_MAX ) {
timestamp = UINT32_MAX ;
}
snapmaticProperties . createdTimestamp = ( quint32 ) timestamp ;
2020-09-28 05:33:04 +02:00
# else
2018-07-27 04:26:10 +02:00
snapmaticProperties . createdTimestamp = snapmaticProperties . createdDateTime . toTime_t ( ) ;
2020-09-28 05:33:04 +02:00
# endif
2018-07-27 04:26:10 +02:00
bool fExists = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( snapmaticProperties . uid ) ) ;
bool fExistsBackup = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( snapmaticProperties . uid ) % " .bak " ) ;
bool fExistsHidden = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( snapmaticProperties . uid ) % " .hidden " ) ;
int cEnough = 0 ;
2021-03-27 08:23:05 +01:00
while ( ( fExists | | fExistsBackup | | fExistsHidden ) & & cEnough < findRetryLimit ) {
2018-07-27 04:26:10 +02:00
snapmaticProperties . uid = getRandomUid ( ) ;
fExists = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( snapmaticProperties . uid ) ) ;
fExistsBackup = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( snapmaticProperties . uid ) % " .bak " ) ;
fExistsHidden = QFile : : exists ( profileFolder % " /PGTA5 " % QString : : number ( snapmaticProperties . uid ) % " .hidden " ) ;
cEnough + + ;
}
2021-03-27 08:23:05 +01:00
if ( fExists | | fExistsBackup | | fExistsHidden ) {
2018-07-27 04:26:10 +02:00
// That should never happen
return false ;
}
2021-03-27 08:23:05 +01:00
if ( ! picture - > setSnapmaticProperties ( snapmaticProperties ) ) {
2018-07-27 04:26:10 +02:00
// That should never happen
return false ;
}
picture - > updateStrings ( ) ;
picFileName = picture - > getPictureFileName ( ) ;
adjustedFileName = picture - > getOriginalPictureFileName ( ) ;
}
2016-10-27 07:19:51 +02:00
}
2023-02-27 14:17:50 +01:00
if ( picture - > exportPicture ( profileFolder % " / " % adjustedFileName , SnapmaticFormat : : PGTA5_Format ) ) {
picture - > setSnapmaticFormat ( SnapmaticFormat : : PGTA5_Format ) ;
2017-10-12 22:21:45 +02:00
picture - > setPicFilePath ( profileFolder % " / " % adjustedFileName ) ;
2021-05-23 07:12:56 +02:00
snapmaticPics < < picture - > getPictureFileName ( ) ;
2017-02-11 04:21:55 +01:00
pictureLoaded ( picture , true ) ;
2016-03-29 11:22:41 +02:00
return true ;
}
2021-03-27 08:23:05 +01:00
else {
if ( warn )
QMessageBox : : warning ( this , tr ( " Import... " ) , tr ( " Failed to import the Snapmatic picture, can't copy the file into profile " ) ) ;
2016-03-29 11:22:41 +02:00
return false ;
}
}
2016-04-13 00:11:20 +02:00
bool ProfileInterface : : importSavegameData ( SavegameData * savegame , QString sgdPath , bool warn )
2016-03-29 11:22:41 +02:00
{
QString sgdFileName ;
bool foundFree = 0 ;
int currentSgd = 0 ;
2021-03-27 08:23:05 +01:00
while ( currentSgd < 15 & & ! foundFree ) {
2016-03-29 11:22:41 +02:00
QString sgdNumber = QString : : number ( currentSgd ) ;
2021-03-27 08:23:05 +01:00
if ( sgdNumber . length ( ) = = 1 ) {
2016-03-29 11:22:41 +02:00
sgdNumber . insert ( 0 , " 0 " ) ;
}
2017-09-05 03:36:01 +02:00
sgdFileName = " SGTA500 " % sgdNumber ;
2016-03-29 11:22:41 +02:00
2021-03-27 08:23:05 +01:00
if ( ! QFile : : exists ( profileFolder % " / " % sgdFileName ) ) {
2016-03-29 11:22:41 +02:00
foundFree = true ;
}
currentSgd + + ;
}
2021-03-27 08:23:05 +01:00
if ( foundFree ) {
2021-05-23 07:12:56 +02:00
const QString newSgdPath = profileFolder % " / " % sgdFileName ;
if ( QFile : : copy ( sgdPath , newSgdPath ) ) {
savegame - > setSavegameFileName ( newSgdPath ) ;
2021-05-23 07:20:20 +02:00
# if QT_VERSION >= 0x050000
2021-05-23 07:12:56 +02:00
savegameFiles < < newSgdPath ;
2021-05-23 07:20:20 +02:00
# endif
2021-05-23 07:12:56 +02:00
savegameLoaded ( savegame , newSgdPath , true ) ;
2016-03-29 11:22:41 +02:00
return true ;
}
2021-03-27 08:23:05 +01:00
else {
if ( warn )
QMessageBox : : warning ( this , tr ( " Import... " ) , tr ( " Failed to import the Savegame, can't copy the file into profile " ) ) ;
2016-03-29 11:22:41 +02:00
return false ;
}
}
2021-03-27 08:23:05 +01:00
else {
if ( warn )
QMessageBox : : warning ( this , tr ( " Import... " ) , tr ( " Failed to import the Savegame, no Savegame slot is left " ) ) ;
2016-03-29 11:22:41 +02:00
return false ;
}
}
2016-04-03 01:18:48 +02:00
2016-04-03 06:12:12 +02:00
void ProfileInterface : : profileWidgetSelected ( )
2016-04-03 01:18:48 +02:00
{
2021-03-27 08:23:05 +01:00
if ( selectedWidgts = = 0 ) {
for ( const QString & widgetStr : qAsConst ( widgets ) ) {
ProfileWidget * widget = widgets . key ( widgetStr , nullptr ) ;
if ( widget ! = nullptr )
widget - > setSelectionMode ( true ) ;
2016-04-03 01:18:48 +02:00
}
}
selectedWidgts + + ;
}
2016-04-03 06:12:12 +02:00
void ProfileInterface : : profileWidgetDeselected ( )
2016-04-03 01:18:48 +02:00
{
2021-03-27 08:23:05 +01:00
if ( selectedWidgts = = 1 ) {
2016-04-03 01:43:04 +02:00
int scrollBarValue = ui - > saProfile - > verticalScrollBar ( ) - > value ( ) ;
2021-03-27 08:23:05 +01:00
for ( const QString & widgetStr : qAsConst ( widgets ) ) {
ProfileWidget * widget = widgets . key ( widgetStr , nullptr ) ;
2023-02-27 14:17:50 +01:00
if ( widget ! = nullptr & & contentMode ! = 2 )
2016-04-14 06:33:15 +02:00
widget - > setSelectionMode ( false ) ;
2016-04-03 01:18:48 +02:00
}
2016-04-03 01:43:04 +02:00
ui - > saProfile - > verticalScrollBar ( ) - > setValue ( scrollBarValue ) ;
2016-04-03 01:18:48 +02:00
}
selectedWidgts - - ;
}
2016-04-03 08:39:31 +02:00
void ProfileInterface : : selectAllWidgets ( )
{
2021-03-27 08:23:05 +01:00
for ( const QString & widgetStr : qAsConst ( widgets ) ) {
ProfileWidget * widget = widgets . key ( widgetStr , nullptr ) ;
if ( widget ! = nullptr )
widget - > setSelected ( true ) ;
2016-04-03 08:39:31 +02:00
}
}
void ProfileInterface : : deselectAllWidgets ( )
{
2021-03-27 08:23:05 +01:00
for ( const QString & widgetStr : qAsConst ( widgets ) ) {
ProfileWidget * widget = widgets . key ( widgetStr , nullptr ) ;
if ( widget ! = nullptr )
widget - > setSelected ( false ) ;
2016-04-03 08:39:31 +02:00
}
}
2016-04-03 10:17:01 +02:00
void ProfileInterface : : exportSelected ( )
{
2021-03-27 08:23:05 +01:00
if ( selectedWidgts ! = 0 ) {
2016-04-08 19:46:27 +02:00
int exportCount = 0 ;
int exportPictures = 0 ;
int exportSavegames = 0 ;
bool pictureCopyEnabled = false ;
bool pictureExportEnabled = false ;
2016-04-24 13:34:03 +02:00
QSettings settings ( GTA5SYNC_APPVENDOR , GTA5SYNC_APPSTR ) ;
settings . beginGroup ( " FileDialogs " ) ;
2017-10-12 22:21:45 +02:00
//bool dontUseNativeDialog = settings.value("DontUseNativeDialog", false).toBool();
2016-04-24 13:34:03 +02:00
settings . beginGroup ( " ExportDirectory " ) ;
2017-12-17 13:03:43 +01:00
QString exportDirectory = QFileDialog : : getExistingDirectory ( this , tr ( " Export selected... " ) , settings . value ( profileName , profileFolder ) . toString ( ) ) ;
2021-03-27 08:23:05 +01:00
if ( exportDirectory ! = " " ) {
2016-04-24 13:34:03 +02:00
settings . setValue ( profileName , exportDirectory ) ;
2021-03-27 08:23:05 +01:00
for ( const QString & widgetStr : qAsConst ( widgets ) ) {
ProfileWidget * widget = widgets . key ( widgetStr , nullptr ) ;
if ( widget ! = nullptr ) {
if ( widget - > isSelected ( ) ) {
if ( widget - > getWidgetType ( ) = = " SnapmaticWidget " ) {
exportPictures + + ;
}
else if ( widget - > getWidgetType ( ) = = " SavegameWidget " ) {
exportSavegames + + ;
}
2016-04-08 19:46:27 +02:00
}
2016-04-03 10:17:01 +02:00
}
2016-04-03 12:27:40 +02:00
}
2016-04-03 10:17:01 +02:00
2021-03-27 08:23:05 +01:00
if ( exportPictures ! = 0 ) {
2016-04-08 19:46:27 +02:00
QInputDialog inputDialog ;
QStringList inputDialogItems ;
inputDialogItems < < tr ( " JPG pictures and GTA Snapmatic " ) ;
inputDialogItems < < tr ( " JPG pictures only " ) ;
inputDialogItems < < tr ( " GTA Snapmatic only " ) ;
2016-04-11 19:40:49 +02:00
QString ExportPreSpan ;
QString ExportPostSpan ;
2020-09-26 16:12:55 +02:00
# ifdef Q_OS_WIN
2020-11-25 00:36:12 +01:00
ExportPreSpan = " <span style= \" color:#003399;font-size:12pt \" > " ;
2016-04-11 19:40:49 +02:00
ExportPostSpan = " </span> " ;
# else
2020-11-25 00:36:12 +01:00
ExportPreSpan = " <span style= \" font-weight:bold \" > " ;
2016-04-11 19:40:49 +02:00
ExportPostSpan = " </span> " ;
# endif
2016-04-08 19:46:27 +02:00
bool itemSelected = false ;
2017-12-17 13:03:43 +01:00
QString selectedItem = inputDialog . getItem ( this , tr ( " Export selected... " ) , tr ( " %1Export Snapmatic pictures%2<br><br>JPG pictures make it possible to open the picture with a Image Viewer<br>GTA Snapmatic make it possible to import the picture into the game<br><br>Export as: " ) . arg ( ExportPreSpan , ExportPostSpan ) , inputDialogItems , 0 , false , & itemSelected , inputDialog . windowFlags ( ) ^ Qt : : WindowContextHelpButtonHint ) ;
2021-03-27 08:23:05 +01:00
if ( itemSelected ) {
if ( selectedItem = = tr ( " JPG pictures and GTA Snapmatic " ) ) {
2016-04-08 19:46:27 +02:00
pictureExportEnabled = true ;
pictureCopyEnabled = true ;
}
2021-03-27 08:23:05 +01:00
else if ( selectedItem = = tr ( " JPG pictures only " ) ) {
2016-04-08 19:46:27 +02:00
pictureExportEnabled = true ;
}
2021-03-27 08:23:05 +01:00
else if ( selectedItem = = tr ( " GTA Snapmatic only " ) ) {
2016-04-08 19:46:27 +02:00
pictureCopyEnabled = true ;
}
2021-03-27 08:23:05 +01:00
else {
2016-04-08 19:46:27 +02:00
pictureExportEnabled = true ;
pictureCopyEnabled = true ;
}
2016-04-03 10:17:01 +02:00
}
2021-03-27 08:23:05 +01:00
else {
2017-10-09 08:35:48 +02:00
// Don't export anymore when any Cancel button got clicked
settings . endGroup ( ) ;
settings . endGroup ( ) ;
return ;
2016-04-03 10:17:01 +02:00
}
}
2016-04-08 19:46:27 +02:00
// Counting the exports together
exportCount = exportCount + exportSavegames ;
2021-03-27 08:23:05 +01:00
if ( pictureExportEnabled & & pictureCopyEnabled ) {
2016-04-08 19:46:27 +02:00
int exportPictures2 = exportPictures * 2 ;
exportCount = exportCount + exportPictures2 ;
}
2021-03-27 08:23:05 +01:00
else {
2016-04-08 19:46:27 +02:00
exportCount = exportCount + exportPictures ;
2016-04-03 12:27:40 +02:00
}
2016-04-08 19:46:27 +02:00
QProgressDialog pbDialog ( this ) ;
2023-01-27 20:09:43 +01:00
pbDialog . setWindowFlag ( Qt : : WindowContextHelpButtonHint , false ) ;
pbDialog . setWindowFlag ( Qt : : WindowCloseButtonHint , false ) ;
2016-04-08 19:46:27 +02:00
pbDialog . setWindowTitle ( tr ( " Export selected... " ) ) ;
2017-10-09 08:35:48 +02:00
pbDialog . setLabelText ( tr ( " Initialising export... " ) ) ;
2016-04-08 19:46:27 +02:00
pbDialog . setRange ( 0 , exportCount ) ;
2016-04-05 04:08:14 +02:00
2016-04-08 19:46:27 +02:00
QList < QPushButton * > pbBtn = pbDialog . findChildren < QPushButton * > ( ) ;
pbBtn . at ( 0 ) - > setDisabled ( true ) ;
2016-04-03 12:27:40 +02:00
2016-04-08 19:46:27 +02:00
QList < QProgressBar * > pbBar = pbDialog . findChildren < QProgressBar * > ( ) ;
pbBar . at ( 0 ) - > setTextVisible ( false ) ;
2016-04-03 12:27:40 +02:00
2016-04-08 19:46:27 +02:00
ExportThread * exportThread = new ExportThread ( widgets , exportDirectory , pictureCopyEnabled , pictureExportEnabled , exportCount ) ;
QObject : : connect ( exportThread , SIGNAL ( exportStringUpdate ( QString ) ) , & pbDialog , SLOT ( setLabelText ( QString ) ) ) ;
QObject : : connect ( exportThread , SIGNAL ( exportProgressUpdate ( int ) ) , & pbDialog , SLOT ( setValue ( int ) ) ) ;
QObject : : connect ( exportThread , SIGNAL ( exportFinished ( ) ) , & pbDialog , SLOT ( close ( ) ) ) ;
exportThread - > start ( ) ;
2016-04-03 12:27:40 +02:00
2017-12-17 13:03:43 +01:00
pbDialog . setAutoClose ( false ) ;
2016-04-08 19:46:27 +02:00
pbDialog . exec ( ) ;
QStringList getFailedSavegames = exportThread - > getFailedSavegames ( ) ;
QStringList getFailedCopyPictures = exportThread - > getFailedCopyPictures ( ) ;
QStringList getFailedExportPictures = exportThread - > getFailedExportPictures ( ) ;
2016-04-03 12:27:40 +02:00
2016-04-08 19:46:27 +02:00
QString errorStr ;
QStringList errorList ;
errorList < < getFailedExportPictures ;
errorList < < getFailedCopyPictures ;
errorList < < getFailedSavegames ;
2016-04-03 12:27:40 +02:00
2021-03-27 08:23:05 +01:00
for ( const QString & curErrorStr : qAsConst ( errorList ) ) {
2017-09-05 03:36:01 +02:00
errorStr + = " , " % curErrorStr ;
2016-04-08 19:46:27 +02:00
}
2021-03-27 08:23:05 +01:00
if ( errorStr ! = " " ) {
2016-04-08 19:46:27 +02:00
errorStr . remove ( 0 , 2 ) ;
2018-01-16 00:13:08 +01:00
QMessageBox : : warning ( this , tr ( " Export selected... " ) , tr ( " Export failed with... \n \n %1 " ) . arg ( errorStr ) ) ;
2016-04-08 19:46:27 +02:00
}
2016-04-03 12:27:40 +02:00
2021-03-27 08:23:05 +01:00
if ( exportThread - > isFinished ( ) ) {
2016-04-08 19:46:27 +02:00
delete exportThread ;
}
2021-03-27 08:23:05 +01:00
else {
2016-04-08 19:46:27 +02:00
QEventLoop threadFinishLoop ;
QObject : : connect ( exportThread , SIGNAL ( finished ( ) ) , & threadFinishLoop , SLOT ( quit ( ) ) ) ;
threadFinishLoop . exec ( ) ;
delete exportThread ;
}
2016-04-03 10:17:01 +02:00
}
2016-04-24 13:34:03 +02:00
settings . endGroup ( ) ;
settings . endGroup ( ) ;
2016-04-03 10:17:01 +02:00
}
2021-03-27 08:23:05 +01:00
else {
2018-01-16 00:13:08 +01:00
QMessageBox : : information ( this , tr ( " Export selected... " ) , tr ( " No Snapmatic pictures or Savegames files are selected " ) ) ;
2016-04-08 19:46:27 +02:00
}
2016-04-03 10:17:01 +02:00
}
2020-11-23 03:47:17 +01:00
void ProfileInterface : : deleteSelectedL ( bool isRemoteEmited )
2016-04-03 10:17:01 +02:00
{
2021-03-27 08:23:05 +01:00
if ( selectedWidgts ! = 0 ) {
if ( QMessageBox : : Yes = = QMessageBox : : warning ( this , tr ( " Remove selected " ) , tr ( " You really want remove the selected Snapmatic picutres and Savegame files? " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) ) {
for ( const QString & widgetStr : qAsConst ( widgets ) ) {
ProfileWidget * widget = widgets . key ( widgetStr , nullptr ) ;
if ( widget ! = nullptr ) {
if ( widget - > isSelected ( ) ) {
if ( widget - > getWidgetType ( ) = = " SnapmaticWidget " ) {
SnapmaticWidget * picWidget = qobject_cast < SnapmaticWidget * > ( widget ) ;
if ( picWidget - > getPicture ( ) - > deletePictureFile ( ) ) {
pictureDeleted ( picWidget , isRemoteEmited ) ;
}
2016-04-08 19:46:27 +02:00
}
2021-03-27 08:23:05 +01:00
else if ( widget - > getWidgetType ( ) = = " SavegameWidget " ) {
SavegameWidget * sgdWidget = qobject_cast < SavegameWidget * > ( widget ) ;
SavegameData * savegame = sgdWidget - > getSavegame ( ) ;
QString fileName = savegame - > getSavegameFileName ( ) ;
if ( ! QFile : : exists ( fileName ) | | QFile : : remove ( fileName ) ) {
savegameDeleted ( sgdWidget , isRemoteEmited ) ;
}
2016-04-08 19:46:27 +02:00
}
2016-04-03 12:54:55 +02:00
}
}
}
2021-03-27 08:23:05 +01:00
if ( selectedWidgts ! = 0 ) {
2018-01-17 00:59:40 +01:00
QMessageBox : : warning ( this , tr ( " Remove selected " ) , tr ( " Failed to remove all selected Snapmatic pictures and/or Savegame files " ) ) ;
2016-04-08 19:46:27 +02:00
}
2016-04-03 12:54:55 +02:00
}
2016-04-08 19:46:27 +02:00
}
2021-03-27 08:23:05 +01:00
else {
2016-04-08 19:46:27 +02:00
QMessageBox : : information ( this , tr ( " Remove selected " ) , tr ( " No Snapmatic pictures or Savegames files are selected " ) ) ;
2016-04-03 12:54:55 +02:00
}
2016-04-03 10:17:01 +02:00
}
2016-04-13 00:47:07 +02:00
2020-11-23 03:47:17 +01:00
void ProfileInterface : : deleteSelected ( )
{
deleteSelectedL ( false ) ;
}
void ProfileInterface : : deleteSelectedR ( )
{
deleteSelectedL ( true ) ;
}
2020-11-23 03:13:07 +01:00
void ProfileInterface : : massToolQualify ( )
{
massTool ( MassTool : : Qualify ) ;
}
void ProfileInterface : : massToolPlayers ( )
{
massTool ( MassTool : : Players ) ;
}
void ProfileInterface : : massToolCrew ( )
{
massTool ( MassTool : : Crew ) ;
}
void ProfileInterface : : massToolTitle ( )
{
massTool ( MassTool : : Title ) ;
}
2016-04-13 00:47:07 +02:00
void ProfileInterface : : importFiles ( )
{
on_cmdImport_clicked ( ) ;
}
2016-04-14 06:33:15 +02:00
2017-10-12 22:21:45 +02:00
void ProfileInterface : : settingsApplied ( int _contentMode , bool languageChanged )
2016-04-14 06:33:15 +02:00
{
2021-03-27 08:23:05 +01:00
if ( languageChanged )
retranslateUi ( ) ;
2016-04-14 06:33:15 +02:00
contentMode = _contentMode ;
2021-03-27 08:23:05 +01:00
if ( contentMode = = 2 ) {
for ( const QString & widgetStr : qAsConst ( widgets ) ) {
ProfileWidget * widget = widgets . key ( widgetStr , nullptr ) ;
if ( widget ! = nullptr ) {
widget - > setSelectionMode ( true ) ;
widget - > setContentMode ( contentMode ) ;
if ( languageChanged )
widget - > retranslate ( ) ;
}
2016-04-14 06:33:15 +02:00
}
}
2021-03-27 08:23:05 +01:00
else {
for ( const QString & widgetStr : qAsConst ( widgets ) ) {
ProfileWidget * widget = widgets . key ( widgetStr , nullptr ) ;
if ( widget ! = nullptr ) {
if ( selectedWidgts = = 0 ) {
widget - > setSelectionMode ( false ) ;
}
widget - > setContentMode ( contentMode ) ;
if ( languageChanged )
widget - > retranslate ( ) ;
2016-04-14 06:33:15 +02:00
}
}
}
2017-12-12 04:45:46 +01:00
# ifdef Q_OS_MAC
// DPI calculation
qreal screenRatio = AppEnv : : screenRatio ( ) ;
2022-08-21 21:39:19 +02:00
# if QT_VERSION >= 0x060000
if ( QApplication : : style ( ) - > objectName ( ) = = " macos " ) {
# else
2021-03-27 08:23:05 +01:00
if ( QApplication : : style ( ) - > objectName ( ) = = " macintosh " ) {
2022-08-21 21:39:19 +02:00
# endif
2017-12-12 04:45:46 +01:00
ui - > hlButtons - > setSpacing ( 6 * screenRatio ) ;
ui - > hlButtons - > setContentsMargins ( 9 * screenRatio , 15 * screenRatio , 15 * screenRatio , 17 * screenRatio ) ;
}
2021-03-27 08:23:05 +01:00
else {
2017-12-12 04:45:46 +01:00
ui - > hlButtons - > setSpacing ( 6 * screenRatio ) ;
ui - > hlButtons - > setContentsMargins ( 9 * screenRatio , 9 * screenRatio , 9 * screenRatio , 9 * screenRatio ) ;
}
# endif
2016-04-14 06:33:15 +02:00
}
2016-10-27 10:35:20 +02:00
2016-10-27 11:24:26 +02:00
void ProfileInterface : : enableSelected ( )
{
2018-01-16 00:13:08 +01:00
QList < SnapmaticWidget * > snapmaticWidgets ;
2021-03-27 08:23:05 +01:00
for ( const QString & widgetStr : qAsConst ( widgets ) ) {
ProfileWidget * widget = widgets . key ( widgetStr , nullptr ) ;
if ( widget ! = nullptr ) {
if ( widget - > isSelected ( ) ) {
if ( widget - > getWidgetType ( ) = = " SnapmaticWidget " ) {
SnapmaticWidget * snapmaticWidget = qobject_cast < SnapmaticWidget * > ( widget ) ;
snapmaticWidgets + = snapmaticWidget ;
}
2016-10-27 11:24:26 +02:00
}
}
}
2021-03-27 08:23:05 +01:00
if ( snapmaticWidgets . isEmpty ( ) ) {
2018-01-16 00:13:08 +01:00
QMessageBox : : information ( this , QApplication : : translate ( " UserInterface " , " Show In-game " ) , QApplication : : translate ( " ProfileInterface " , " No Snapmatic pictures are selected " ) ) ;
return ;
}
QStringList fails ;
2021-03-27 08:23:05 +01:00
for ( SnapmaticWidget * widget : qAsConst ( snapmaticWidgets ) ) {
2018-01-16 00:13:08 +01:00
SnapmaticPicture * picture = widget - > getPicture ( ) ;
2021-03-27 08:23:05 +01:00
if ( ! widget - > makePictureVisible ( ) ) {
2018-01-16 00:13:08 +01:00
fails < < QString ( " %1 [%2] " ) . arg ( picture - > getPictureTitle ( ) , picture - > getPictureString ( ) ) ;
}
}
2021-03-27 08:23:05 +01:00
if ( ! fails . isEmpty ( ) ) {
2018-01-16 00:13:08 +01:00
QMessageBox : : warning ( this , QApplication : : translate ( " UserInterface " , " Show In-game " ) , QApplication : : translate ( " ProfileInterface " , " %1 failed with... \n \n %2 " , " Action failed with... " ) . arg ( QApplication : : translate ( " UserInterface " , " Show In-game " ) , fails . join ( " , " ) ) ) ;
}
2016-10-27 11:24:26 +02:00
}
void ProfileInterface : : disableSelected ( )
{
2018-01-16 00:13:08 +01:00
QList < SnapmaticWidget * > snapmaticWidgets ;
2021-03-27 08:23:05 +01:00
for ( const QString & widgetStr : qAsConst ( widgets ) ) {
ProfileWidget * widget = widgets . key ( widgetStr , nullptr ) ;
if ( widget ! = nullptr ) {
if ( widget - > isSelected ( ) ) {
if ( widget - > getWidgetType ( ) = = " SnapmaticWidget " ) {
SnapmaticWidget * snapmaticWidget = qobject_cast < SnapmaticWidget * > ( widget ) ;
snapmaticWidgets + = snapmaticWidget ;
}
2016-10-27 11:24:26 +02:00
}
}
}
2021-03-27 08:23:05 +01:00
if ( snapmaticWidgets . isEmpty ( ) ) {
2018-01-16 00:13:08 +01:00
QMessageBox : : information ( this , QApplication : : translate ( " UserInterface " , " Hide In-game " ) , QApplication : : translate ( " ProfileInterface " , " No Snapmatic pictures are selected " ) ) ;
return ;
}
QStringList fails ;
2021-03-27 08:23:05 +01:00
for ( SnapmaticWidget * widget : qAsConst ( snapmaticWidgets ) ) {
2018-01-16 00:13:08 +01:00
SnapmaticPicture * picture = widget - > getPicture ( ) ;
2021-03-27 08:23:05 +01:00
if ( ! widget - > makePictureHidden ( ) ) {
2018-01-16 00:13:08 +01:00
fails < < QString ( " %1 [%2] " ) . arg ( picture - > getPictureTitle ( ) , picture - > getPictureString ( ) ) ;
}
}
2021-03-27 08:23:05 +01:00
if ( ! fails . isEmpty ( ) ) {
2018-01-16 00:13:08 +01:00
QMessageBox : : warning ( this , QApplication : : translate ( " UserInterface " , " Hide In-game " ) , QApplication : : translate ( " ProfileInterface " , " %1 failed with... \n \n %2 " , " Action failed with... " ) . arg ( QApplication : : translate ( " UserInterface " , " Hide In-game " ) , fails . join ( " , " ) ) ) ;
}
2016-10-27 11:24:26 +02:00
}
2016-10-27 10:35:20 +02:00
int ProfileInterface : : selectedWidgets ( )
{
return selectedWidgts ;
}
2017-02-13 04:12:47 +01:00
void ProfileInterface : : contextMenuTriggeredPIC ( QContextMenuEvent * ev )
{
2017-10-09 08:35:48 +02:00
SnapmaticWidget * picWidget = qobject_cast < SnapmaticWidget * > ( sender ( ) ) ;
2020-11-23 03:13:07 +01:00
if ( picWidget ! = previousWidget ) {
if ( previousWidget ! = nullptr ) {
2023-02-09 20:42:05 +01:00
previousWidget - > setStyleSheet ( QString ( ) ) ;
2017-10-09 08:35:48 +02:00
}
2018-12-01 17:47:28 +01:00
picWidget - > setStyleSheet ( QString ( " QFrame#SnapmaticFrame{background-color:palette(highlight)}QLabel#labPicStr{color:palette(highlighted-text)} " ) ) ;
2017-10-09 08:35:48 +02:00
previousWidget = picWidget ;
}
2017-02-13 04:12:47 +01:00
QMenu contextMenu ( picWidget ) ;
2020-11-23 03:13:07 +01:00
const int selectedCount = selectedWidgets ( ) ;
2020-12-16 13:02:11 +01:00
if ( contentMode < 20 | | selectedCount = = 0 ) {
2020-11-23 03:13:07 +01:00
QMenu editMenu ( SnapmaticWidget : : tr ( " Edi&t " ) , picWidget ) ;
if ( picWidget - > isHidden ( ) ) {
2023-02-09 20:42:05 +01:00
editMenu . addAction ( SnapmaticWidget : : tr ( " Show &In-game " ) , picWidget , & SnapmaticWidget : : makePictureVisibleSlot ) ;
2020-11-23 03:13:07 +01:00
}
else {
2023-02-09 20:42:05 +01:00
editMenu . addAction ( SnapmaticWidget : : tr ( " Hide &In-game " ) , picWidget , & SnapmaticWidget : : makePictureHiddenSlot ) ;
2020-11-23 03:13:07 +01:00
}
2023-02-09 20:42:05 +01:00
editMenu . addAction ( PictureDialog : : tr ( " &Edit Properties... " ) , picWidget , & SnapmaticWidget : : editSnapmaticProperties ) ;
editMenu . addAction ( PictureDialog : : tr ( " &Overwrite Image... " ) , picWidget , & SnapmaticWidget : : editSnapmaticImage ) ;
2020-11-23 03:13:07 +01:00
editMenu . addSeparator ( ) ;
2023-02-09 20:42:05 +01:00
editMenu . addAction ( PictureDialog : : tr ( " Open &Map Viewer... " ) , picWidget , & SnapmaticWidget : : openMapViewer ) ;
editMenu . addAction ( PictureDialog : : tr ( " Open &JSON Editor... " ) , picWidget , & SnapmaticWidget : : editSnapmaticRawJson ) ;
2020-11-23 03:13:07 +01:00
QMenu exportMenu ( SnapmaticWidget : : tr ( " &Export " ) , this ) ;
2023-02-09 20:42:05 +01:00
exportMenu . addAction ( PictureDialog : : tr ( " Export as &Picture... " ) , picWidget , & SnapmaticWidget : : on_cmdExport_clicked ) ;
exportMenu . addAction ( PictureDialog : : tr ( " Export as &Snapmatic... " ) , picWidget , & SnapmaticWidget : : on_cmdCopy_clicked ) ;
contextMenu . addAction ( SnapmaticWidget : : tr ( " &View " ) , picWidget , & SnapmaticWidget : : on_cmdView_clicked ) ;
2020-11-23 03:13:07 +01:00
contextMenu . addMenu ( & editMenu ) ;
contextMenu . addMenu ( & exportMenu ) ;
2023-02-09 20:42:05 +01:00
contextMenu . addAction ( SnapmaticWidget : : tr ( " &Remove " ) , picWidget , & SnapmaticWidget : : on_cmdDelete_clicked ) ;
2020-11-23 03:13:07 +01:00
contextMenu . addSeparator ( ) ;
if ( ! picWidget - > isSelected ( ) )
2023-02-09 20:42:05 +01:00
contextMenu . addAction ( SnapmaticWidget : : tr ( " &Select " ) , picWidget , & SnapmaticWidget : : pictureSelected ) ;
2020-11-23 03:13:07 +01:00
else {
2023-02-09 20:42:05 +01:00
contextMenu . addAction ( SnapmaticWidget : : tr ( " &Deselect " ) , picWidget , & SnapmaticWidget : : pictureSelected ) ;
2020-11-23 03:13:07 +01:00
}
if ( selectedCount ! = widgets . count ( ) ) {
2023-02-09 20:42:05 +01:00
QAction * action = contextMenu . addAction ( SnapmaticWidget : : tr ( " Select &All " ) , picWidget , & SnapmaticWidget : : selectAllWidgets ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Ctrl+A " ) ) ;
2020-11-23 03:13:07 +01:00
}
if ( selectedCount ! = 0 ) {
2023-02-09 20:42:05 +01:00
QAction * action = contextMenu . addAction ( SnapmaticWidget : : tr ( " &Deselect All " ) , picWidget , & SnapmaticWidget : : deselectAllWidgets ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Ctrl+D " ) ) ;
2020-11-23 03:13:07 +01:00
}
contextMenuOpened = true ;
contextMenu . exec ( ev - > globalPos ( ) ) ;
contextMenuOpened = false ;
2023-02-09 20:42:05 +01:00
QTimer : : singleShot ( 0 , this , & ProfileInterface : : hoverProfileWidgetCheck ) ;
2020-11-23 03:13:07 +01:00
}
else {
QMenu editMenu ( SnapmaticWidget : : tr ( " Edi&t " ) , picWidget ) ;
2023-02-09 20:42:05 +01:00
QAction * action = editMenu . addAction ( QApplication : : translate ( " UserInterface " , " &Qualify as Avatar " ) , this , & ProfileInterface : : massToolQualify ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Shift+Q " ) ) ;
action = editMenu . addAction ( QApplication : : translate ( " UserInterface " , " Change &Players... " ) , this , & ProfileInterface : : massToolPlayers ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Shift+P " ) ) ;
action = editMenu . addAction ( QApplication : : translate ( " UserInterface " , " Change &Crew... " ) , this , & ProfileInterface : : massToolCrew ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Shift+C " ) ) ;
action = editMenu . addAction ( QApplication : : translate ( " UserInterface " , " Change &Title... " ) , this , & ProfileInterface : : massToolTitle ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Shift+T " ) ) ;
2020-11-23 03:13:07 +01:00
editMenu . addSeparator ( ) ;
2023-02-09 20:42:05 +01:00
action = editMenu . addAction ( SnapmaticWidget : : tr ( " Show &In-game " ) , this , & ProfileInterface : : enableSelected ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Shift+E " ) ) ;
action = editMenu . addAction ( SnapmaticWidget : : tr ( " Hide &In-game " ) , this , & ProfileInterface : : disableSelected ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Shift+D " ) ) ;
2020-11-23 03:13:07 +01:00
contextMenu . addMenu ( & editMenu ) ;
2023-02-09 20:42:05 +01:00
action = contextMenu . addAction ( SavegameWidget : : tr ( " &Export " ) , this , & ProfileInterface : : exportSelected ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Ctrl+E " ) ) ;
action = contextMenu . addAction ( SavegameWidget : : tr ( " &Remove " ) , this , & ProfileInterface : : deleteSelectedR ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Ctrl+Del " ) ) ;
2020-11-23 03:13:07 +01:00
contextMenu . addSeparator ( ) ;
2021-03-27 08:23:05 +01:00
if ( ! picWidget - > isSelected ( ) ) {
2023-02-09 20:42:05 +01:00
contextMenu . addAction ( SnapmaticWidget : : tr ( " &Select " ) , picWidget , & SnapmaticWidget : : pictureSelected ) ;
2021-03-27 08:23:05 +01:00
}
2020-11-23 03:13:07 +01:00
else {
2023-02-09 20:42:05 +01:00
contextMenu . addAction ( SnapmaticWidget : : tr ( " &Deselect " ) , picWidget , & SnapmaticWidget : : pictureSelected ) ;
2020-11-23 03:13:07 +01:00
}
if ( selectedCount ! = widgets . count ( ) ) {
2023-02-09 20:42:05 +01:00
action = contextMenu . addAction ( SnapmaticWidget : : tr ( " Select &All " ) , picWidget , & SnapmaticWidget : : selectAllWidgets ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Ctrl+A " ) ) ;
2020-11-23 03:13:07 +01:00
}
if ( selectedCount ! = 0 ) {
2023-02-09 20:42:05 +01:00
action = contextMenu . addAction ( SnapmaticWidget : : tr ( " &Deselect All " ) , picWidget , & SnapmaticWidget : : deselectAllWidgets ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Ctrl+D " ) ) ;
2020-11-23 03:13:07 +01:00
}
contextMenuOpened = true ;
contextMenu . exec ( ev - > globalPos ( ) ) ;
contextMenuOpened = false ;
2023-02-09 20:42:05 +01:00
QTimer : : singleShot ( 0 , this , & ProfileInterface : : hoverProfileWidgetCheck ) ;
2017-02-13 04:12:47 +01:00
}
}
void ProfileInterface : : contextMenuTriggeredSGD ( QContextMenuEvent * ev )
{
2017-10-09 08:35:48 +02:00
SavegameWidget * sgdWidget = qobject_cast < SavegameWidget * > ( sender ( ) ) ;
2020-11-23 03:13:07 +01:00
if ( sgdWidget ! = previousWidget ) {
if ( previousWidget ! = nullptr ) {
2017-10-09 08:35:48 +02:00
previousWidget - > setStyleSheet ( QLatin1String ( " " ) ) ;
}
2018-12-01 17:47:28 +01:00
sgdWidget - > setStyleSheet ( QString ( " QFrame#SavegameFrame{background-color:palette(highlight)}QLabel#labSavegameStr{color:palette(highlighted-text)} " ) ) ;
2017-10-09 08:35:48 +02:00
previousWidget = sgdWidget ;
}
2017-02-13 04:12:47 +01:00
QMenu contextMenu ( sgdWidget ) ;
2020-11-23 03:13:07 +01:00
const int selectedCount = selectedWidgets ( ) ;
2020-12-16 13:02:11 +01:00
if ( contentMode < 20 | | selectedCount = = 0 ) {
2023-02-09 20:42:05 +01:00
contextMenu . addAction ( SavegameWidget : : tr ( " &View " ) , sgdWidget , & SavegameWidget : : on_cmdView_clicked ) ;
contextMenu . addAction ( SavegameWidget : : tr ( " &Export " ) , sgdWidget , & SavegameWidget : : on_cmdCopy_clicked ) ;
contextMenu . addAction ( SavegameWidget : : tr ( " &Remove " ) , sgdWidget , & SavegameWidget : : on_cmdDelete_clicked ) ;
2020-11-23 03:13:07 +01:00
contextMenu . addSeparator ( ) ;
if ( ! sgdWidget - > isSelected ( ) ) {
2023-02-09 20:42:05 +01:00
contextMenu . addAction ( SavegameWidget : : tr ( " &Select " ) , sgdWidget , & SavegameWidget : : savegameSelected ) ;
2020-11-23 03:13:07 +01:00
}
else {
2023-02-09 20:42:05 +01:00
contextMenu . addAction ( SavegameWidget : : tr ( " &Deselect " ) , sgdWidget , & SavegameWidget : : savegameSelected ) ;
2020-11-23 03:13:07 +01:00
}
if ( selectedCount ! = widgets . count ( ) ) {
2023-02-09 20:42:05 +01:00
QAction * action = contextMenu . addAction ( SavegameWidget : : tr ( " Select &All " ) , sgdWidget , & SavegameWidget : : selectAllWidgets ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Ctrl+A " ) ) ;
2020-11-23 03:13:07 +01:00
}
if ( selectedCount ! = 0 ) {
2023-02-09 20:42:05 +01:00
QAction * action = contextMenu . addAction ( SavegameWidget : : tr ( " &Deselect All " ) , sgdWidget , & SavegameWidget : : deselectAllWidgets ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Ctrl+D " ) ) ;
2020-11-23 03:13:07 +01:00
}
contextMenuOpened = true ;
contextMenu . exec ( ev - > globalPos ( ) ) ;
contextMenuOpened = false ;
2023-02-09 20:42:05 +01:00
QTimer : : singleShot ( 0 , this , & ProfileInterface : : hoverProfileWidgetCheck ) ;
2020-11-23 03:13:07 +01:00
}
else {
QMenu editMenu ( SnapmaticWidget : : tr ( " Edi&t " ) , sgdWidget ) ;
2023-02-09 20:42:05 +01:00
QAction * action = editMenu . addAction ( QApplication : : translate ( " UserInterface " , " &Qualify as Avatar " ) , this , & ProfileInterface : : massToolQualify ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Shift+Q " ) ) ;
action = editMenu . addAction ( QApplication : : translate ( " UserInterface " , " Change &Players... " ) , this , & ProfileInterface : : massToolPlayers ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Shift+P " ) ) ;
action = editMenu . addAction ( QApplication : : translate ( " UserInterface " , " Change &Crew... " ) , this , & ProfileInterface : : massToolCrew ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Shift+C " ) ) ;
action = editMenu . addAction ( QApplication : : translate ( " UserInterface " , " Change &Title... " ) , this , & ProfileInterface : : massToolTitle ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Shift+T " ) ) ;
2020-11-23 03:13:07 +01:00
editMenu . addSeparator ( ) ;
2023-02-09 20:42:05 +01:00
action = editMenu . addAction ( SnapmaticWidget : : tr ( " Show &In-game " ) , this , & ProfileInterface : : enableSelected ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Shift+E " ) ) ;
action = editMenu . addAction ( SnapmaticWidget : : tr ( " Hide &In-game " ) , this , & ProfileInterface : : disableSelected ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Shift+D " ) ) ;
2020-11-23 03:13:07 +01:00
contextMenu . addMenu ( & editMenu ) ;
2023-02-09 20:42:05 +01:00
action = contextMenu . addAction ( SavegameWidget : : tr ( " &Export " ) , this , & ProfileInterface : : exportSelected ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Ctrl+E " ) ) ;
action = contextMenu . addAction ( SavegameWidget : : tr ( " &Remove " ) , this , & ProfileInterface : : deleteSelectedR ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Ctrl+Del " ) ) ;
2020-11-23 03:13:07 +01:00
contextMenu . addSeparator ( ) ;
if ( ! sgdWidget - > isSelected ( ) )
2023-02-09 20:42:05 +01:00
contextMenu . addAction ( SavegameWidget : : tr ( " &Select " ) , sgdWidget , & SavegameWidget : : savegameSelected ) ;
2020-11-23 03:13:07 +01:00
else {
2023-02-09 20:42:05 +01:00
contextMenu . addAction ( SavegameWidget : : tr ( " &Deselect " ) , sgdWidget , & SavegameWidget : : savegameSelected ) ;
2020-11-23 03:13:07 +01:00
}
if ( selectedCount ! = widgets . count ( ) ) {
2023-02-09 20:42:05 +01:00
action = contextMenu . addAction ( SavegameWidget : : tr ( " Select &All " ) , sgdWidget , & SavegameWidget : : selectAllWidgets ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Ctrl+A " ) ) ;
2020-11-23 03:13:07 +01:00
}
if ( selectedCount ! = 0 ) {
2023-02-09 20:42:05 +01:00
action = contextMenu . addAction ( SavegameWidget : : tr ( " &Deselect All " ) , sgdWidget , & SavegameWidget : : deselectAllWidgets ) ;
action - > setShortcut ( QKeySequence : : fromString ( " Ctrl+D " ) ) ;
2020-11-23 03:13:07 +01:00
}
contextMenuOpened = true ;
contextMenu . exec ( ev - > globalPos ( ) ) ;
contextMenuOpened = false ;
2023-02-09 20:42:05 +01:00
QTimer : : singleShot ( 0 , this , & ProfileInterface : : hoverProfileWidgetCheck ) ;
2017-07-28 19:53:07 +02:00
}
}
void ProfileInterface : : on_saProfileContent_dropped ( const QMimeData * mimeData )
{
2021-03-27 08:23:05 +01:00
if ( ! mimeData )
return ;
if ( mimeData - > hasImage ( ) ) {
2018-06-29 08:52:43 +02:00
QImage * snapmaticImage = new QImage ( qvariant_cast < QImage > ( mimeData - > imageData ( ) ) ) ;
importImage ( snapmaticImage , QDateTime : : currentDateTime ( ) ) ;
}
2021-03-27 08:23:05 +01:00
else if ( mimeData - > hasUrls ( ) ) {
2018-06-29 08:52:43 +02:00
importUrls ( mimeData ) ;
}
2017-02-13 04:12:47 +01:00
}
2017-10-09 08:35:48 +02:00
void ProfileInterface : : retranslateUi ( )
{
ui - > retranslateUi ( this ) ;
2021-06-17 06:14:35 +02:00
QString appVersion = QApplication : : applicationVersion ( ) ;
const char * literalBuildType = GTA5SYNC_BUILDTYPE ;
2018-07-13 12:07:13 +02:00
# ifdef GTA5SYNC_COMMIT
2021-06-17 06:14:35 +02:00
if ( ( strcmp ( literalBuildType , REL_BUILDTYPE ) ! = 0 ) & & ! appVersion . contains ( " - " ) )
2021-03-27 08:23:05 +01:00
appVersion = appVersion % " - " % GTA5SYNC_COMMIT ;
2018-07-13 12:07:13 +02:00
# endif
ui - > labVersion - > setText ( QString ( " %1 %2 " ) . arg ( GTA5SYNC_APPSTR , appVersion ) ) ;
2017-10-09 08:35:48 +02:00
}
bool ProfileInterface : : eventFilter ( QObject * watched , QEvent * event )
{
2021-03-27 08:23:05 +01:00
if ( event - > type ( ) = = QEvent : : KeyPress ) {
if ( isProfileLoaded ) {
2018-06-17 09:27:10 +02:00
QKeyEvent * keyEvent = dynamic_cast < QKeyEvent * > ( event ) ;
2021-03-27 08:23:05 +01:00
switch ( keyEvent - > key ( ) ) {
2018-06-17 09:27:10 +02:00
case Qt : : Key_V :
2021-03-27 08:23:05 +01:00
if ( QApplication : : keyboardModifiers ( ) . testFlag ( Qt : : ControlModifier ) & & ! QApplication : : keyboardModifiers ( ) . testFlag ( Qt : : ShiftModifier ) ) {
2018-06-29 08:02:28 +02:00
const QMimeData * clipboardData = QApplication : : clipboard ( ) - > mimeData ( ) ;
2021-03-27 08:23:05 +01:00
if ( clipboardData - > hasImage ( ) ) {
2018-06-29 08:02:28 +02:00
QImage * snapmaticImage = new QImage ( qvariant_cast < QImage > ( clipboardData - > imageData ( ) ) ) ;
2018-06-17 09:27:10 +02:00
importImage ( snapmaticImage , QDateTime : : currentDateTime ( ) ) ;
}
2021-03-27 08:23:05 +01:00
else if ( clipboardData - > hasUrls ( ) ) {
if ( clipboardData - > urls ( ) . length ( ) > = 2 ) {
2018-06-29 08:20:01 +02:00
importUrls ( clipboardData ) ;
2018-06-29 08:02:28 +02:00
}
2021-03-27 08:23:05 +01:00
else if ( clipboardData - > urls ( ) . length ( ) = = 1 ) {
2018-06-29 08:02:28 +02:00
QUrl clipboardUrl = clipboardData - > urls ( ) . at ( 0 ) ;
2021-03-27 08:23:05 +01:00
if ( clipboardUrl . isLocalFile ( ) ) {
2018-06-29 08:02:28 +02:00
importFile ( clipboardUrl . toLocalFile ( ) , QDateTime : : currentDateTime ( ) , true ) ;
}
2021-03-27 08:23:05 +01:00
else {
2018-06-29 09:57:06 +02:00
importRemote ( clipboardUrl ) ;
}
}
}
2021-03-27 08:23:05 +01:00
else if ( clipboardData - > hasText ( ) ) {
2018-06-29 09:57:06 +02:00
QUrl clipboardUrl = QUrl : : fromUserInput ( clipboardData - > text ( ) ) ;
2021-03-27 08:23:05 +01:00
if ( clipboardUrl . isValid ( ) ) {
if ( clipboardUrl . isLocalFile ( ) ) {
2018-06-29 09:57:06 +02:00
importFile ( clipboardUrl . toLocalFile ( ) , QDateTime : : currentDateTime ( ) , true ) ;
}
2021-03-27 08:23:05 +01:00
else {
2018-06-29 09:57:06 +02:00
importRemote ( clipboardUrl ) ;
2018-06-17 09:27:10 +02:00
}
}
}
}
}
}
}
2021-03-27 08:23:05 +01:00
else if ( event - > type ( ) = = QEvent : : MouseMove ) {
if ( ( watched - > objectName ( ) = = " SavegameWidget " | | watched - > objectName ( ) = = " SnapmaticWidget " ) & & isProfileLoaded ) {
2017-10-09 08:35:48 +02:00
ProfileWidget * pWidget = qobject_cast < ProfileWidget * > ( watched ) ;
2021-03-27 08:23:05 +01:00
if ( pWidget - > underMouse ( ) ) {
2017-10-09 08:35:48 +02:00
bool styleSheetChanged = false ;
2021-03-27 08:23:05 +01:00
if ( pWidget - > getWidgetType ( ) = = " SnapmaticWidget " ) {
if ( pWidget ! = previousWidget ) {
2018-12-01 17:47:28 +01:00
pWidget - > setStyleSheet ( QString ( " QFrame#SnapmaticFrame{background-color:palette(highlight)}QLabel#labPicStr{color:palette(highlighted-text)} " ) ) ;
2017-10-09 08:35:48 +02:00
styleSheetChanged = true ;
}
}
2021-03-27 08:23:05 +01:00
else if ( pWidget - > getWidgetType ( ) = = " SavegameWidget " ) {
if ( pWidget ! = previousWidget ) {
2018-12-01 17:47:28 +01:00
pWidget - > setStyleSheet ( QString ( " QFrame#SavegameFrame{background-color:palette(highlight)}QLabel#labSavegameStr{color:palette(highlighted-text)} " ) ) ;
2017-10-09 08:35:48 +02:00
styleSheetChanged = true ;
}
}
2021-03-27 08:23:05 +01:00
if ( styleSheetChanged ) {
if ( previousWidget ! = nullptr ) {
2017-10-09 08:35:48 +02:00
previousWidget - > setStyleSheet ( QLatin1String ( " " ) ) ;
}
previousWidget = pWidget ;
}
}
return true ;
}
}
2021-03-27 08:23:05 +01:00
else if ( event - > type ( ) = = QEvent : : MouseButtonPress | | event - > type ( ) = = QEvent : : MouseButtonRelease ) {
if ( ( watched - > objectName ( ) = = " SavegameWidget " | | watched - > objectName ( ) = = " SnapmaticWidget " ) & & isProfileLoaded ) {
2017-10-09 08:35:48 +02:00
ProfileWidget * pWidget = nullptr ;
2021-03-27 08:23:05 +01:00
for ( auto it = widgets . constBegin ( ) ; it ! = widgets . constEnd ( ) ; it + + ) {
2020-08-24 17:44:32 +02:00
ProfileWidget * widget = it . key ( ) ;
2017-10-09 08:35:48 +02:00
QPoint mousePos = widget - > mapFromGlobal ( QCursor : : pos ( ) ) ;
2021-03-27 08:23:05 +01:00
if ( widget - > rect ( ) . contains ( mousePos ) ) {
2017-10-09 08:35:48 +02:00
pWidget = widget ;
break ;
}
}
2021-03-27 08:23:05 +01:00
if ( pWidget ! = nullptr ) {
2017-10-09 08:35:48 +02:00
bool styleSheetChanged = false ;
2021-03-27 08:23:05 +01:00
if ( pWidget - > getWidgetType ( ) = = " SnapmaticWidget " ) {
if ( pWidget ! = previousWidget ) {
2018-12-01 17:47:28 +01:00
pWidget - > setStyleSheet ( QString ( " QFrame#SnapmaticFrame{background-color:palette(highlight)}QLabel#labPicStr{color:palette(highlighted-text)} " ) ) ;
2017-10-09 08:35:48 +02:00
styleSheetChanged = true ;
}
}
2021-03-27 08:23:05 +01:00
else if ( pWidget - > getWidgetType ( ) = = " SavegameWidget " ) {
if ( pWidget ! = previousWidget ) {
2018-12-01 17:47:28 +01:00
pWidget - > setStyleSheet ( QString ( " QFrame#SavegameFrame{background-color:palette(highlight)}QLabel#labSavegameStr{color:palette(highlighted-text)} " ) ) ;
2017-10-09 08:35:48 +02:00
styleSheetChanged = true ;
}
}
2021-03-27 08:23:05 +01:00
if ( styleSheetChanged ) {
if ( previousWidget ! = nullptr ) {
2017-10-09 08:35:48 +02:00
previousWidget - > setStyleSheet ( QLatin1String ( " " ) ) ;
}
previousWidget = pWidget ;
}
}
}
}
2021-03-27 08:23:05 +01:00
else if ( event - > type ( ) = = QEvent : : WindowDeactivate & & isProfileLoaded ) {
if ( previousWidget ! = nullptr & & watched = = previousWidget ) {
2017-10-09 08:35:48 +02:00
previousWidget - > setStyleSheet ( QLatin1String ( " " ) ) ;
previousWidget = nullptr ;
}
}
2021-03-27 08:23:05 +01:00
else if ( event - > type ( ) = = QEvent : : Leave & & isProfileLoaded & & ! contextMenuOpened ) {
if ( watched - > objectName ( ) = = " SavegameWidget " | | watched - > objectName ( ) = = " SnapmaticWidget " ) {
2017-10-09 08:35:48 +02:00
ProfileWidget * pWidget = qobject_cast < ProfileWidget * > ( watched ) ;
QPoint mousePos = pWidget - > mapFromGlobal ( QCursor : : pos ( ) ) ;
2021-03-27 08:23:05 +01:00
if ( ! pWidget - > geometry ( ) . contains ( mousePos ) ) {
if ( previousWidget ! = nullptr ) {
2017-10-09 08:35:48 +02:00
previousWidget - > setStyleSheet ( QLatin1String ( " " ) ) ;
previousWidget = nullptr ;
}
}
}
2021-03-27 08:23:05 +01:00
else if ( watched - > objectName ( ) = = " ProfileInterface " ) {
if ( previousWidget ! = nullptr ) {
2018-08-17 16:35:14 +02:00
previousWidget - > setStyleSheet ( QLatin1String ( " " ) ) ;
previousWidget = nullptr ;
}
}
2017-10-09 08:35:48 +02:00
}
return false ;
}
void ProfileInterface : : hoverProfileWidgetCheck ( )
{
ProfileWidget * pWidget = nullptr ;
2021-03-27 08:23:05 +01:00
for ( auto it = widgets . constBegin ( ) ; it ! = widgets . constEnd ( ) ; it + + ) {
2020-08-24 17:23:10 +02:00
ProfileWidget * widget = it . key ( ) ;
2021-03-27 08:23:05 +01:00
if ( widget - > underMouse ( ) ) {
2017-10-09 08:35:48 +02:00
pWidget = widget ;
break ;
}
}
2021-03-27 08:23:05 +01:00
if ( pWidget ! = nullptr ) {
2017-10-09 08:35:48 +02:00
bool styleSheetChanged = false ;
2021-03-27 08:23:05 +01:00
if ( pWidget - > getWidgetType ( ) = = " SnapmaticWidget " ) {
if ( pWidget ! = previousWidget ) {
2018-12-01 17:47:28 +01:00
pWidget - > setStyleSheet ( QString ( " QFrame#SnapmaticFrame{background-color:palette(highlight)}QLabel#labPicStr{color:palette(highlighted-text)} " ) ) ;
2017-10-09 08:35:48 +02:00
styleSheetChanged = true ;
}
}
2021-03-27 08:23:05 +01:00
else if ( pWidget - > getWidgetType ( ) = = " SavegameWidget " ) {
if ( pWidget ! = previousWidget ) {
2018-12-01 17:47:28 +01:00
pWidget - > setStyleSheet ( QString ( " QFrame#SavegameFrame{background-color:palette(highlight)}QLabel#labSavegameStr{color:palette(highlighted-text)} " ) ) ;
2017-10-09 08:35:48 +02:00
styleSheetChanged = true ;
}
}
2021-03-27 08:23:05 +01:00
if ( styleSheetChanged ) {
if ( previousWidget ! = nullptr ) {
2017-10-09 08:35:48 +02:00
previousWidget - > setStyleSheet ( QLatin1String ( " " ) ) ;
}
previousWidget = pWidget ;
}
}
2021-03-27 08:23:05 +01:00
else {
if ( previousWidget ! = nullptr ) {
2017-10-09 08:35:48 +02:00
previousWidget - > setStyleSheet ( QLatin1String ( " " ) ) ;
previousWidget = nullptr ;
}
}
}
void ProfileInterface : : updatePalette ( )
{
2018-12-01 17:47:28 +01:00
ui - > saProfile - > setStyleSheet ( QString ( " QWidget#saProfileContent{background-color:palette(base)} " ) ) ;
2021-03-27 08:23:05 +01:00
if ( previousWidget ! = nullptr ) {
if ( previousWidget - > getWidgetType ( ) = = " SnapmaticWidget " ) {
2018-12-01 17:47:28 +01:00
previousWidget - > setStyleSheet ( QString ( " QFrame#SnapmaticFrame{background-color:palette(highlight)}QLabel#labPicStr{color:palette(highlighted-text)} " ) ) ;
2017-10-09 08:35:48 +02:00
}
2021-03-27 08:23:05 +01:00
else if ( previousWidget - > getWidgetType ( ) = = " SavegameWidget " ) {
2018-12-01 17:47:28 +01:00
previousWidget - > setStyleSheet ( QString ( " QFrame#SnapmaticFrame{background-color:palette(highlight)}QLabel#labPicStr{color:palette(highlighted-text)} " ) ) ;
2017-10-09 08:35:48 +02:00
}
}
}
bool ProfileInterface : : isSupportedImageFile ( QString selectedFileName )
{
2021-03-27 08:23:05 +01:00
for ( const QByteArray & imageFormat : QImageReader : : supportedImageFormats ( ) ) {
2017-10-09 08:35:48 +02:00
QString imageFormatStr = QString ( " . " ) % QString : : fromUtf8 ( imageFormat ) . toLower ( ) ;
2021-03-27 08:23:05 +01:00
if ( selectedFileName . length ( ) > = imageFormatStr . length ( ) & & selectedFileName . toLower ( ) . right ( imageFormatStr . length ( ) ) = = imageFormatStr ) {
2017-10-09 08:35:48 +02:00
return true ;
}
}
return false ;
}
2017-12-17 13:03:43 +01:00
void ProfileInterface : : massTool ( MassTool tool )
{
2021-03-27 08:23:05 +01:00
switch ( tool ) {
case MassTool : : Qualify : {
2017-12-17 13:03:43 +01:00
QList < SnapmaticWidget * > snapmaticWidgets ;
2021-03-27 08:23:05 +01:00
for ( const QString & widgetStr : qAsConst ( widgets ) ) {
ProfileWidget * widget = widgets . key ( widgetStr , nullptr ) ;
if ( widget ! = nullptr ) {
if ( widget - > isSelected ( ) ) {
if ( widget - > getWidgetType ( ) = = " SnapmaticWidget " ) {
SnapmaticWidget * snapmaticWidget = qobject_cast < SnapmaticWidget * > ( widget ) ;
snapmaticWidgets + = snapmaticWidget ;
}
2017-12-17 13:03:43 +01:00
}
}
}
2021-03-27 08:23:05 +01:00
if ( snapmaticWidgets . isEmpty ( ) ) {
2018-01-16 00:13:08 +01:00
QMessageBox : : information ( this , tr ( " Qualify as Avatar " ) , tr ( " No Snapmatic pictures are selected " ) ) ;
2017-12-17 13:03:43 +01:00
return ;
}
// Prepare Progress
int maximumId = snapmaticWidgets . length ( ) ;
int overallId = 0 ;
QProgressDialog pbDialog ( this ) ;
2023-01-27 20:09:43 +01:00
pbDialog . setWindowFlag ( Qt : : WindowContextHelpButtonHint , false ) ;
pbDialog . setWindowFlag ( Qt : : WindowCloseButtonHint , false ) ;
2017-12-17 13:03:43 +01:00
pbDialog . setWindowTitle ( tr ( " Patch selected... " ) ) ;
pbDialog . setLabelText ( tr ( " Patch file %1 of %2 files " ) . arg ( QString : : number ( 1 ) , QString : : number ( maximumId ) ) ) ;
pbDialog . setRange ( 1 , maximumId ) ;
pbDialog . setValue ( 1 ) ;
pbDialog . setModal ( true ) ;
QList < QPushButton * > pbBtn = pbDialog . findChildren < QPushButton * > ( ) ;
pbBtn . at ( 0 ) - > setDisabled ( true ) ;
QList < QProgressBar * > pbBar = pbDialog . findChildren < QProgressBar * > ( ) ;
pbBar . at ( 0 ) - > setTextVisible ( false ) ;
pbDialog . setAutoClose ( false ) ;
pbDialog . show ( ) ;
// Begin Progress
QStringList fails ;
2021-03-27 08:23:05 +01:00
for ( SnapmaticWidget * snapmaticWidget : qAsConst ( snapmaticWidgets ) ) {
2017-12-17 13:03:43 +01:00
// Update Progress
overallId + + ;
pbDialog . setValue ( overallId ) ;
pbDialog . setLabelText ( tr ( " Patch file %1 of %2 files " ) . arg ( QString : : number ( overallId ) , QString : : number ( maximumId ) ) ) ;
SnapmaticPicture * picture = snapmaticWidget - > getPicture ( ) ;
SnapmaticProperties snapmaticProperties = picture - > getSnapmaticProperties ( ) ;
snapmaticProperties . isSelfie = true ;
snapmaticProperties . isMug = false ;
snapmaticProperties . isFromRSEditor = false ;
snapmaticProperties . isFromDirector = false ;
snapmaticProperties . isMeme = false ;
QString currentFilePath = picture - > getPictureFilePath ( ) ;
QString originalFilePath = picture - > getOriginalPictureFilePath ( ) ;
QString backupFileName = originalFilePath % " .bak " ;
2021-03-27 08:23:05 +01:00
if ( ! QFile : : exists ( backupFileName ) ) {
2017-12-17 13:03:43 +01:00
QFile : : copy ( currentFilePath , backupFileName ) ;
}
SnapmaticProperties fallbackProperties = picture - > getSnapmaticProperties ( ) ;
picture - > setSnapmaticProperties ( snapmaticProperties ) ;
2021-03-27 08:23:05 +01:00
if ( ! picture - > exportPicture ( currentFilePath ) ) {
2017-12-17 13:03:43 +01:00
picture - > setSnapmaticProperties ( fallbackProperties ) ;
fails < < QString ( " %1 [%2] " ) . arg ( picture - > getPictureTitle ( ) , picture - > getPictureString ( ) ) ;
}
2021-03-27 08:23:05 +01:00
else {
2017-12-17 13:03:43 +01:00
picture - > emitUpdate ( ) ;
2020-09-28 05:33:04 +02:00
QApplication : : processEvents ( ) ;
2017-12-17 13:03:43 +01:00
}
}
pbDialog . close ( ) ;
2021-03-27 08:23:05 +01:00
if ( ! fails . isEmpty ( ) ) {
2018-01-16 00:13:08 +01:00
QMessageBox : : warning ( this , tr ( " Qualify as Avatar " ) , tr ( " %1 failed with... \n \n %2 " , " Action failed with... " ) . arg ( tr ( " Qualify " , " %1 failed with... " ) , fails . join ( " , " ) ) ) ;
2017-12-17 13:03:43 +01:00
}
}
break ;
2021-03-27 08:23:05 +01:00
case MassTool : : Players : {
2017-12-17 13:03:43 +01:00
QList < SnapmaticWidget * > snapmaticWidgets ;
2021-03-27 08:23:05 +01:00
for ( const QString & widgetStr : qAsConst ( widgets ) ) {
ProfileWidget * widget = widgets . key ( widgetStr , nullptr ) ;
if ( widget ! = nullptr ) {
if ( widget - > isSelected ( ) ) {
if ( widget - > getWidgetType ( ) = = " SnapmaticWidget " ) {
SnapmaticWidget * snapmaticWidget = qobject_cast < SnapmaticWidget * > ( widget ) ;
snapmaticWidgets + = snapmaticWidget ;
}
2017-12-17 13:03:43 +01:00
}
}
}
2021-03-27 08:23:05 +01:00
if ( snapmaticWidgets . isEmpty ( ) ) {
2018-01-16 00:13:08 +01:00
QMessageBox : : information ( this , tr ( " Change Players... " ) , tr ( " No Snapmatic pictures are selected " ) ) ;
2017-12-17 13:03:43 +01:00
return ;
}
2018-06-17 22:02:41 +02:00
QStringList players ;
2021-03-27 08:23:05 +01:00
if ( snapmaticWidgets . length ( ) = = 1 ) {
2018-06-17 22:02:41 +02:00
players = snapmaticWidgets . at ( 0 ) - > getPicture ( ) - > getSnapmaticProperties ( ) . playersList ;
}
PlayerListDialog * playerListDialog = new PlayerListDialog ( players , profileDB , this ) ;
2017-12-17 13:03:43 +01:00
playerListDialog - > setModal ( true ) ;
playerListDialog - > show ( ) ;
playerListDialog - > exec ( ) ;
if ( ! playerListDialog - > isListUpdated ( ) )
return ;
2018-06-17 22:02:41 +02:00
players = playerListDialog - > getPlayerList ( ) ;
2017-12-17 13:03:43 +01:00
delete playerListDialog ;
// Prepare Progress
int maximumId = snapmaticWidgets . length ( ) ;
int overallId = 0 ;
QProgressDialog pbDialog ( this ) ;
2023-01-27 20:09:43 +01:00
pbDialog . setWindowFlag ( Qt : : WindowContextHelpButtonHint , false ) ;
pbDialog . setWindowFlag ( Qt : : WindowCloseButtonHint , false ) ;
2017-12-17 13:03:43 +01:00
pbDialog . setWindowTitle ( tr ( " Patch selected... " ) ) ;
pbDialog . setLabelText ( tr ( " Patch file %1 of %2 files " ) . arg ( QString : : number ( 1 ) , QString : : number ( maximumId ) ) ) ;
pbDialog . setRange ( 1 , maximumId ) ;
pbDialog . setValue ( 1 ) ;
pbDialog . setModal ( true ) ;
QList < QPushButton * > pbBtn = pbDialog . findChildren < QPushButton * > ( ) ;
pbBtn . at ( 0 ) - > setDisabled ( true ) ;
QList < QProgressBar * > pbBar = pbDialog . findChildren < QProgressBar * > ( ) ;
pbBar . at ( 0 ) - > setTextVisible ( false ) ;
pbDialog . setAutoClose ( false ) ;
pbDialog . show ( ) ;
// Begin Progress
QStringList fails ;
2021-03-27 08:23:05 +01:00
for ( SnapmaticWidget * snapmaticWidget : qAsConst ( snapmaticWidgets ) ) {
2017-12-17 13:03:43 +01:00
// Update Progress
overallId + + ;
pbDialog . setValue ( overallId ) ;
pbDialog . setLabelText ( tr ( " Patch file %1 of %2 files " ) . arg ( QString : : number ( overallId ) , QString : : number ( maximumId ) ) ) ;
SnapmaticPicture * picture = snapmaticWidget - > getPicture ( ) ;
SnapmaticProperties snapmaticProperties = picture - > getSnapmaticProperties ( ) ;
snapmaticProperties . playersList = players ;
QString currentFilePath = picture - > getPictureFilePath ( ) ;
QString originalFilePath = picture - > getOriginalPictureFilePath ( ) ;
QString backupFileName = originalFilePath % " .bak " ;
2021-03-27 08:23:05 +01:00
if ( ! QFile : : exists ( backupFileName ) ) {
2017-12-17 13:03:43 +01:00
QFile : : copy ( currentFilePath , backupFileName ) ;
}
SnapmaticProperties fallbackProperties = picture - > getSnapmaticProperties ( ) ;
picture - > setSnapmaticProperties ( snapmaticProperties ) ;
2021-03-27 08:23:05 +01:00
if ( ! picture - > exportPicture ( currentFilePath ) ) {
2017-12-17 13:03:43 +01:00
picture - > setSnapmaticProperties ( fallbackProperties ) ;
fails < < QString ( " %1 [%2] " ) . arg ( picture - > getPictureTitle ( ) , picture - > getPictureString ( ) ) ;
}
2021-03-27 08:23:05 +01:00
else {
2017-12-17 13:03:43 +01:00
picture - > emitUpdate ( ) ;
2020-09-28 05:33:04 +02:00
QApplication : : processEvents ( ) ;
2017-12-17 13:03:43 +01:00
}
}
pbDialog . close ( ) ;
2021-03-27 08:23:05 +01:00
if ( ! fails . isEmpty ( ) ) {
2018-01-16 00:13:08 +01:00
QMessageBox : : warning ( this , tr ( " Change Players... " ) , tr ( " %1 failed with... \n \n %2 " , " Action failed with... " ) . arg ( tr ( " Change Players " , " %1 failed with... " ) , fails . join ( " , " ) ) ) ;
2017-12-17 13:03:43 +01:00
}
}
break ;
2021-03-27 08:23:05 +01:00
case MassTool : : Crew : {
2017-12-17 13:03:43 +01:00
QList < SnapmaticWidget * > snapmaticWidgets ;
2021-03-27 08:23:05 +01:00
for ( const QString & widgetStr : qAsConst ( widgets ) ) {
ProfileWidget * widget = widgets . key ( widgetStr , nullptr ) ;
if ( widget ! = nullptr ) {
if ( widget - > isSelected ( ) ) {
if ( widget - > getWidgetType ( ) = = " SnapmaticWidget " ) {
SnapmaticWidget * snapmaticWidget = qobject_cast < SnapmaticWidget * > ( widget ) ;
snapmaticWidgets + = snapmaticWidget ;
}
2017-12-17 13:03:43 +01:00
}
}
}
2021-03-27 08:23:05 +01:00
if ( snapmaticWidgets . isEmpty ( ) ) {
2018-01-16 00:13:08 +01:00
QMessageBox : : information ( this , tr ( " Change Crew... " ) , tr ( " No Snapmatic pictures are selected " ) ) ;
2017-12-17 13:03:43 +01:00
return ;
}
int crewID = 0 ;
2021-03-27 08:23:05 +01:00
if ( snapmaticWidgets . length ( ) = = 1 ) {
2018-06-17 22:02:41 +02:00
crewID = snapmaticWidgets . at ( 0 ) - > getPicture ( ) - > getSnapmaticProperties ( ) . crewID ;
}
2017-12-17 13:03:43 +01:00
{
preSelectionCrewID :
bool ok ;
2018-06-17 22:02:41 +02:00
int indexNum = 0 ;
2017-12-17 13:03:43 +01:00
QStringList itemList ;
QStringList crewList = crewDB - > getCrews ( ) ;
2021-03-27 08:23:05 +01:00
if ( ! crewList . contains ( QLatin1String ( " 0 " ) ) ) {
2017-12-17 13:03:43 +01:00
crewList + = QLatin1String ( " 0 " ) ;
}
crewList . sort ( ) ;
2021-04-25 13:24:05 +02:00
for ( QString crew : qAsConst ( crewList ) ) {
2017-12-17 13:03:43 +01:00
itemList + = QString ( " %1 (%2) " ) . arg ( crew , crewDB - > getCrewName ( crew . toInt ( ) ) ) ;
}
2021-03-27 08:23:05 +01:00
if ( crewList . contains ( QString : : number ( crewID ) ) ) {
2020-09-28 05:33:04 +02:00
indexNum = crewList . indexOf ( QString : : number ( crewID ) ) ;
2018-06-17 22:02:41 +02:00
}
QString newCrew = QInputDialog : : getItem ( this , QApplication : : translate ( " SnapmaticEditor " , " Snapmatic Crew " ) , QApplication : : translate ( " SnapmaticEditor " , " New Snapmatic crew: " ) , itemList , indexNum , true , & ok , windowFlags ( ) ^ Qt : : Dialog ^ Qt : : WindowMinMaxButtonsHint ) ;
2021-03-27 08:23:05 +01:00
if ( ok & & ! newCrew . isEmpty ( ) ) {
2017-12-17 13:03:43 +01:00
if ( newCrew . contains ( " " ) ) newCrew = newCrew . split ( " " ) . at ( 0 ) ;
if ( newCrew . length ( ) > 10 ) return ;
2021-05-23 07:12:56 +02:00
for ( const QChar & crewChar : qAsConst ( newCrew ) ) {
2021-03-27 08:23:05 +01:00
if ( ! crewChar . isNumber ( ) ) {
2018-01-16 00:13:08 +01:00
QMessageBox : : warning ( this , tr ( " Change Crew... " ) , tr ( " Failed to enter a valid Snapmatic Crew ID " ) ) ;
2017-12-17 13:03:43 +01:00
goto preSelectionCrewID ;
}
}
2021-03-27 08:23:05 +01:00
if ( ! crewList . contains ( newCrew ) ) {
2018-08-25 03:11:37 +02:00
crewDB - > addCrew ( crewID ) ;
}
2017-12-17 13:03:43 +01:00
crewID = newCrew . toInt ( ) ;
}
2021-03-27 08:23:05 +01:00
else {
2017-12-17 13:03:43 +01:00
return ;
}
}
// Prepare Progress
int maximumId = snapmaticWidgets . length ( ) ;
int overallId = 0 ;
QProgressDialog pbDialog ( this ) ;
2023-01-27 20:09:43 +01:00
pbDialog . setWindowFlag ( Qt : : WindowContextHelpButtonHint , false ) ;
pbDialog . setWindowFlag ( Qt : : WindowCloseButtonHint , false ) ;
2017-12-17 13:03:43 +01:00
pbDialog . setWindowTitle ( tr ( " Patch selected... " ) ) ;
pbDialog . setLabelText ( tr ( " Patch file %1 of %2 files " ) . arg ( QString : : number ( 1 ) , QString : : number ( maximumId ) ) ) ;
pbDialog . setRange ( 1 , maximumId ) ;
pbDialog . setValue ( 1 ) ;
pbDialog . setModal ( true ) ;
QList < QPushButton * > pbBtn = pbDialog . findChildren < QPushButton * > ( ) ;
pbBtn . at ( 0 ) - > setDisabled ( true ) ;
QList < QProgressBar * > pbBar = pbDialog . findChildren < QProgressBar * > ( ) ;
pbBar . at ( 0 ) - > setTextVisible ( false ) ;
pbDialog . setAutoClose ( false ) ;
pbDialog . show ( ) ;
// Begin Progress
QStringList fails ;
2021-03-27 08:23:05 +01:00
for ( SnapmaticWidget * snapmaticWidget : qAsConst ( snapmaticWidgets ) ) {
2017-12-17 13:03:43 +01:00
// Update Progress
overallId + + ;
pbDialog . setValue ( overallId ) ;
pbDialog . setLabelText ( tr ( " Patch file %1 of %2 files " ) . arg ( QString : : number ( overallId ) , QString : : number ( maximumId ) ) ) ;
SnapmaticPicture * picture = snapmaticWidget - > getPicture ( ) ;
SnapmaticProperties snapmaticProperties = picture - > getSnapmaticProperties ( ) ;
snapmaticProperties . crewID = crewID ;
QString currentFilePath = picture - > getPictureFilePath ( ) ;
QString originalFilePath = picture - > getOriginalPictureFilePath ( ) ;
QString backupFileName = originalFilePath % " .bak " ;
2021-03-27 08:23:05 +01:00
if ( ! QFile : : exists ( backupFileName ) ) {
2017-12-17 13:03:43 +01:00
QFile : : copy ( currentFilePath , backupFileName ) ;
}
SnapmaticProperties fallbackProperties = picture - > getSnapmaticProperties ( ) ;
picture - > setSnapmaticProperties ( snapmaticProperties ) ;
2021-03-27 08:23:05 +01:00
if ( ! picture - > exportPicture ( currentFilePath ) ) {
2017-12-17 13:03:43 +01:00
picture - > setSnapmaticProperties ( fallbackProperties ) ;
fails < < QString ( " %1 [%2] " ) . arg ( picture - > getPictureTitle ( ) , picture - > getPictureString ( ) ) ;
}
2021-03-27 08:23:05 +01:00
else {
2017-12-17 13:03:43 +01:00
picture - > emitUpdate ( ) ;
2020-09-28 05:33:04 +02:00
QApplication : : processEvents ( ) ;
2017-12-17 13:03:43 +01:00
}
}
pbDialog . close ( ) ;
2021-03-27 08:23:05 +01:00
if ( ! fails . isEmpty ( ) ) {
2018-01-16 00:13:08 +01:00
QMessageBox : : warning ( this , tr ( " Change Crew... " ) , tr ( " %1 failed with... \n \n %2 " , " Action failed with... " ) . arg ( tr ( " Change Crew " , " %1 failed with... " ) , fails . join ( " , " ) ) ) ;
2017-12-17 13:03:43 +01:00
}
}
break ;
2021-03-27 08:23:05 +01:00
case MassTool : : Title : {
2017-12-17 13:03:43 +01:00
QList < SnapmaticWidget * > snapmaticWidgets ;
2021-03-27 08:23:05 +01:00
for ( const QString & widgetStr : qAsConst ( widgets ) ) {
ProfileWidget * widget = widgets . key ( widgetStr , nullptr ) ;
if ( widget ! = nullptr ) {
if ( widget - > isSelected ( ) ) {
if ( widget - > getWidgetType ( ) = = " SnapmaticWidget " ) {
SnapmaticWidget * snapmaticWidget = qobject_cast < SnapmaticWidget * > ( widget ) ;
snapmaticWidgets + = snapmaticWidget ;
}
2017-12-17 13:03:43 +01:00
}
}
}
2021-03-27 08:23:05 +01:00
if ( snapmaticWidgets . isEmpty ( ) ) {
2018-01-16 00:13:08 +01:00
QMessageBox : : information ( this , tr ( " Change Title... " ) , tr ( " No Snapmatic pictures are selected " ) ) ;
2017-12-17 13:03:43 +01:00
return ;
}
QString snapmaticTitle ;
2021-03-27 08:23:05 +01:00
if ( snapmaticWidgets . length ( ) = = 1 ) {
2018-06-17 22:02:41 +02:00
snapmaticTitle = snapmaticWidgets . at ( 0 ) - > getPicture ( ) - > getPictureTitle ( ) ;
}
2017-12-17 13:03:43 +01:00
{
preSelectionTitle :
bool ok ;
QString newTitle = QInputDialog : : getText ( this , QApplication : : translate ( " SnapmaticEditor " , " Snapmatic Title " ) , QApplication : : translate ( " SnapmaticEditor " , " New Snapmatic title: " ) , QLineEdit : : Normal , snapmaticTitle , & ok , windowFlags ( ) ^ Qt : : Dialog ^ Qt : : WindowMinMaxButtonsHint ) ;
2021-03-27 08:23:05 +01:00
if ( ok & & ! newTitle . isEmpty ( ) ) {
if ( ! SnapmaticPicture : : verifyTitle ( newTitle ) ) {
2018-01-16 00:13:08 +01:00
QMessageBox : : warning ( this , tr ( " Change Title... " ) , tr ( " Failed to enter a valid Snapmatic title " ) ) ;
2017-12-17 13:03:43 +01:00
goto preSelectionTitle ;
}
snapmaticTitle = newTitle ;
}
2021-03-27 08:23:05 +01:00
else {
2017-12-17 13:03:43 +01:00
return ;
}
}
// Prepare Progress
int maximumId = snapmaticWidgets . length ( ) ;
int overallId = 0 ;
QProgressDialog pbDialog ( this ) ;
2023-01-27 20:09:43 +01:00
pbDialog . setWindowFlag ( Qt : : WindowContextHelpButtonHint , false ) ;
pbDialog . setWindowFlag ( Qt : : WindowCloseButtonHint , false ) ;
2017-12-17 13:03:43 +01:00
pbDialog . setWindowTitle ( tr ( " Patch selected... " ) ) ;
pbDialog . setLabelText ( tr ( " Patch file %1 of %2 files " ) . arg ( QString : : number ( overallId ) , QString : : number ( maximumId ) ) ) ;
pbDialog . setRange ( 1 , maximumId ) ;
pbDialog . setValue ( 1 ) ;
pbDialog . setModal ( true ) ;
QList < QPushButton * > pbBtn = pbDialog . findChildren < QPushButton * > ( ) ;
pbBtn . at ( 0 ) - > setDisabled ( true ) ;
QList < QProgressBar * > pbBar = pbDialog . findChildren < QProgressBar * > ( ) ;
pbBar . at ( 0 ) - > setTextVisible ( false ) ;
pbDialog . setAutoClose ( false ) ;
pbDialog . show ( ) ;
// Begin Progress
QStringList fails ;
2021-03-27 08:23:05 +01:00
for ( SnapmaticWidget * snapmaticWidget : qAsConst ( snapmaticWidgets ) ) {
2017-12-17 13:03:43 +01:00
// Update Progress
overallId + + ;
pbDialog . setValue ( overallId ) ;
pbDialog . setLabelText ( tr ( " Patch file %1 of %2 files " ) . arg ( QString : : number ( overallId ) , QString : : number ( maximumId ) ) ) ;
SnapmaticPicture * picture = snapmaticWidget - > getPicture ( ) ;
QString currentFilePath = picture - > getPictureFilePath ( ) ;
QString originalFilePath = picture - > getOriginalPictureFilePath ( ) ;
QString backupFileName = originalFilePath % " .bak " ;
2021-03-27 08:23:05 +01:00
if ( ! QFile : : exists ( backupFileName ) ) {
2017-12-17 13:03:43 +01:00
QFile : : copy ( currentFilePath , backupFileName ) ;
}
QString fallbackTitle = picture - > getPictureTitle ( ) ;
picture - > setPictureTitle ( snapmaticTitle ) ;
2021-03-27 08:23:05 +01:00
if ( ! picture - > exportPicture ( currentFilePath ) ) {
2017-12-17 13:03:43 +01:00
picture - > setPictureTitle ( fallbackTitle ) ;
fails < < QString ( " %1 [%2] " ) . arg ( picture - > getPictureTitle ( ) , picture - > getPictureString ( ) ) ;
}
2021-03-27 08:23:05 +01:00
else {
2017-12-17 13:03:43 +01:00
picture - > emitUpdate ( ) ;
2020-09-28 05:33:04 +02:00
QApplication : : processEvents ( ) ;
2017-12-17 13:03:43 +01:00
}
}
pbDialog . close ( ) ;
2021-03-27 08:23:05 +01:00
if ( ! fails . isEmpty ( ) ) {
2018-01-16 00:13:08 +01:00
QMessageBox : : warning ( this , tr ( " Change Title... " ) , tr ( " %1 failed with... \n \n %2 " , " Action failed with... " ) . arg ( tr ( " Change Title " , " %1 failed with... " ) , fails . join ( " , " ) ) ) ;
2017-12-17 13:03:43 +01:00
}
}
break ;
}
}
2018-06-14 11:36:01 +02:00
int ProfileInterface : : getRandomUid ( )
{
2018-06-15 04:43:13 +02:00
int random_int = pcg32_boundedrand_r ( & rng , 2147483647 ) ;
return random_int ;
2018-06-14 11:36:01 +02:00
}