2016-03-29 11:22:41 +02:00
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright ( C ) 2016 Syping
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "ProfileInterface.h"
# include "ui_ProfileInterface.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-03 10:17:01 +02:00
# include "PictureExport.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"
# include <QProgressDialog>
# 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>
# include <QFileDialog>
2016-04-03 12:27:40 +02:00
# include <QEventLoop>
2016-04-03 01:43:04 +02:00
# include <QScrollBar>
2016-03-29 11:22:41 +02:00
# include <QFileInfo>
# include <QPalette>
# include <QRegExp>
# include <QDebug>
# include <QColor>
2016-04-03 01:43:04 +02:00
# include <QTimer>
2016-03-29 11:22:41 +02:00
# include <QFile>
# include <QUrl>
# include <QDir>
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-04-03 01:18:48 +02:00
selectedWidgts = 0 ;
2016-03-29 11:22:41 +02:00
profileFolder = " " ;
profileLoader = 0 ;
saSpacerItem = 0 ;
QPalette palette ;
QColor baseColor = palette . base ( ) . color ( ) ;
2016-04-03 05:28:00 +02:00
ui - > saProfile - > setStyleSheet ( QString ( " QWidget#saProfileContent{background-color: rgb(%1, %2, %3)} " ) . arg ( QString : : number ( baseColor . red ( ) ) , QString : : number ( baseColor . green ( ) ) , QString : : number ( baseColor . blue ( ) ) ) ) ;
2016-03-29 11:22:41 +02:00
}
ProfileInterface : : ~ ProfileInterface ( )
{
2016-04-03 03:56:24 +02:00
foreach ( ProfileWidget * widget , widgets . keys ( ) )
{
widgets . remove ( widget ) ;
widget - > deleteLater ( ) ;
delete widget ;
}
2016-03-29 11:22:41 +02:00
foreach ( SavegameData * savegame , savegames )
{
2016-04-03 03:56:24 +02:00
savegames . removeAll ( savegame ) ;
2016-03-29 11:22:41 +02:00
savegame - > deleteLater ( ) ;
delete savegame ;
}
foreach ( SnapmaticPicture * picture , pictures )
{
pictures . removeAll ( picture ) ;
picture - > deleteLater ( ) ;
delete picture ;
}
profileLoader - > deleteLater ( ) ;
delete profileLoader ;
2016-04-03 12:27:40 +02:00
2016-03-29 11:22:41 +02:00
delete ui ;
}
void ProfileInterface : : setProfileFolder ( QString folder , QString profile )
{
profileFolder = folder ;
profileName = profile ;
}
void ProfileInterface : : setupProfileInterface ( )
{
ui - > labProfileLoading - > setText ( tr ( " Loading... " ) ) ;
profileLoader = new ProfileLoader ( profileFolder , crewDB ) ;
2016-04-03 06:12:12 +02:00
QObject : : connect ( profileLoader , SIGNAL ( savegameLoaded ( SavegameData * , QString ) ) , this , SLOT ( savegameLoaded ( SavegameData * , QString ) ) ) ;
QObject : : connect ( profileLoader , SIGNAL ( pictureLoaded ( SnapmaticPicture * , QString ) ) , this , SLOT ( pictureLoaded ( SnapmaticPicture * , QString ) ) ) ;
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 ( ) ;
}
2016-04-03 06:12:12 +02:00
void ProfileInterface : : savegameLoaded ( SavegameData * savegame , QString savegamePath )
2016-04-06 06:38:43 +02:00
{
savegameLoaded_f ( savegame , savegamePath , false ) ;
}
void ProfileInterface : : savegameLoaded_f ( SavegameData * savegame , QString savegamePath , bool inserted )
2016-03-29 11:22:41 +02:00
{
SavegameWidget * sgdWidget = new SavegameWidget ( ) ;
sgdWidget - > setSavegameData ( savegame , savegamePath ) ;
2016-04-06 05:34:26 +02:00
widgets [ sgdWidget ] = " SGD " + QFileInfo ( savegamePath ) . fileName ( ) ;
2016-03-29 11:22:41 +02:00
savegames . append ( savegame ) ;
2016-04-03 03:56:24 +02:00
if ( selectedWidgts ! = 0 ) { sgdWidget - > setSelectionMode ( true ) ; }
2016-04-03 06:12:12 +02:00
QObject : : connect ( sgdWidget , SIGNAL ( savegameDeleted ( ) ) , this , SLOT ( savegameDeleted ( ) ) ) ;
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 ( ) ) ) ;
2016-04-06 06:38:43 +02:00
if ( inserted ) { insertSavegameIPI ( sgdWidget ) ; }
2016-03-29 11:22:41 +02:00
}
2016-04-03 06:12:12 +02:00
void ProfileInterface : : pictureLoaded ( SnapmaticPicture * picture , QString picturePath )
2016-04-06 06:38:43 +02:00
{
pictureLoaded_f ( picture , picturePath , false ) ;
}
void ProfileInterface : : pictureLoaded_f ( SnapmaticPicture * picture , QString picturePath , bool inserted )
2016-03-29 11:22:41 +02:00
{
SnapmaticWidget * picWidget = new SnapmaticWidget ( profileDB , threadDB ) ;
picWidget - > setSnapmaticPicture ( picture , picturePath ) ;
2016-04-06 05:34:26 +02:00
widgets [ picWidget ] = " PIC " + picture - > getPictureSortStr ( ) ;
2016-03-29 11:22:41 +02:00
pictures . append ( picture ) ;
2016-04-03 03:56:24 +02:00
if ( selectedWidgts ! = 0 ) { picWidget - > setSelectionMode ( true ) ; }
2016-04-03 06:12:12 +02:00
QObject : : connect ( picWidget , SIGNAL ( pictureDeleted ( ) ) , this , SLOT ( pictureDeleted ( ) ) ) ;
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-06 06:38:43 +02: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 ) ) ) ;
}
2016-04-06 06:38:43 +02:00
void ProfileInterface : : insertSnapmaticIPI ( QWidget * widget )
{
ProfileWidget * proWidget = ( ProfileWidget * ) widget ;
if ( widgets . contains ( proWidget ) )
{
QString widgetKey = widgets [ proWidget ] ;
QStringList widgetsKeyList = widgets . values ( ) ;
QStringList pictureKeyList = widgetsKeyList . filter ( " PIC " , Qt : : CaseSensitive ) ;
2016-04-06 07:00:50 +02:00
# if QT_VERSION >= 0x050600
2016-04-06 06:38:43 +02:00
qSort ( pictureKeyList . rbegin ( ) , pictureKeyList . rend ( ) ) ;
2016-04-06 06:48:42 +02:00
# else
qSort ( pictureKeyList . begin ( ) , pictureKeyList . end ( ) , qGreater < QString > ( ) ) ;
# endif
2016-04-06 06:38:43 +02:00
int picIndex = pictureKeyList . indexOf ( QRegExp ( widgetKey ) ) ;
ui - > vlSnapmatic - > insertWidget ( picIndex , proWidget ) ;
2016-04-06 17:38:31 +02:00
qApp - > processEvents ( ) ;
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
{
2016-04-06 06:38:43 +02:00
ProfileWidget * proWidget = ( ProfileWidget * ) widget ;
if ( widgets . contains ( proWidget ) )
{
QString widgetKey = widgets [ proWidget ] ;
QStringList widgetsKeyList = widgets . values ( ) ;
QStringList savegameKeyList = widgetsKeyList . filter ( " SGD " , Qt : : CaseSensitive ) ;
qSort ( savegameKeyList . begin ( ) , savegameKeyList . end ( ) ) ;
int sgdIndex = savegameKeyList . indexOf ( QRegExp ( widgetKey ) ) ;
ui - > vlSavegame - > insertWidget ( sgdIndex , proWidget ) ;
2016-04-06 17:38:31 +02:00
qApp - > processEvents ( ) ;
ui - > saProfile - > ensureWidgetVisible ( proWidget , 0 , 0 ) ;
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 ( ) ;
qSort ( widgetsKeyList . begin ( ) , widgetsKeyList . end ( ) ) ;
2016-04-06 06:38:43 +02:00
2016-04-06 05:34:26 +02:00
foreach ( QString widgetKey , widgetsKeyList )
{
ProfileWidget * widget = widgets . key ( widgetKey ) ;
if ( widget - > getWidgetType ( ) = = " SnapmaticWidget " )
{
ui - > vlSnapmatic - > insertWidget ( 0 , widget ) ;
}
else if ( widget - > getWidgetType ( ) = = " SavegameWidget " )
{
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
qApp - > 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 ) ;
2016-04-03 08:39:31 +02:00
emit profileLoaded ( ) ;
2016-03-29 11:22:41 +02:00
}
2016-04-03 06:12:12 +02:00
void ProfileInterface : : savegameDeleted ( )
2016-03-29 11:22:41 +02:00
{
2016-04-03 12:54:55 +02:00
savegameDeleted_f ( ( SavegameWidget * ) sender ( ) ) ;
}
void ProfileInterface : : savegameDeleted_f ( QWidget * sgdWidget_ )
{
SavegameWidget * sgdWidget = ( SavegameWidget * ) sgdWidget_ ;
2016-04-03 03:56:24 +02:00
SavegameData * savegame = sgdWidget - > getSavegame ( ) ;
2016-04-03 08:39:31 +02:00
if ( sgdWidget - > isSelected ( ) ) { sgdWidget - > setSelected ( false ) ; }
2016-04-03 03:56:24 +02:00
sgdWidget - > close ( ) ;
savegames . removeAll ( savegame ) ;
delete savegame ;
2016-03-29 11:22:41 +02:00
}
2016-04-03 06:12:12 +02:00
void ProfileInterface : : pictureDeleted ( )
2016-03-29 11:22:41 +02:00
{
2016-04-03 12:54:55 +02:00
pictureDeleted_f ( ( SnapmaticWidget * ) sender ( ) ) ;
}
void ProfileInterface : : pictureDeleted_f ( QWidget * picWidget_ )
{
SnapmaticWidget * picWidget = ( SnapmaticWidget * ) picWidget_ ;
2016-04-03 03:56:24 +02:00
SnapmaticPicture * picture = picWidget - > getPicture ( ) ;
2016-04-03 08:39:31 +02:00
if ( picWidget - > isSelected ( ) ) { picWidget - > setSelected ( false ) ; }
2016-04-03 03:56:24 +02:00
picWidget - > close ( ) ;
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 ( )
{
QSettings settings ( " Syping " , " gta5sync " ) ;
settings . beginGroup ( " FileDialogs " ) ;
fileDialogPreOpen :
QFileDialog fileDialog ( this ) ;
fileDialog . setFileMode ( QFileDialog : : AnyFile ) ;
fileDialog . setViewMode ( QFileDialog : : Detail ) ;
fileDialog . setAcceptMode ( QFileDialog : : AcceptOpen ) ;
fileDialog . setOption ( QFileDialog : : DontUseNativeDialog , true ) ;
fileDialog . setWindowFlags ( fileDialog . windowFlags ( ) ^ Qt : : WindowContextHelpButtonHint ) ;
2016-04-08 16:55:28 +02:00
fileDialog . setWindowTitle ( tr ( " Import... " ) ) ;
fileDialog . setLabelText ( QFileDialog : : Accept , tr ( " Import " ) ) ;
2016-03-29 11:22:41 +02:00
QStringList filters ;
filters < < tr ( " All profile files (SGTA* PGTA*) " ) ;
filters < < tr ( " Savegames files (SGTA*) " ) ;
filters < < tr ( " Snapmatic pictures (PGTA*) " ) ;
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 ) ;
fileDialog . restoreState ( settings . value ( " ImportCopy " , " " ) . toByteArray ( ) ) ;
if ( fileDialog . exec ( ) )
{
QStringList selectedFiles = fileDialog . selectedFiles ( ) ;
if ( selectedFiles . length ( ) = = 1 )
{
QString selectedFile = selectedFiles . at ( 0 ) ;
QFileInfo selectedFileInfo ( selectedFile ) ;
QString selectedFileName = selectedFileInfo . fileName ( ) ;
if ( QFile : : exists ( selectedFile ) )
{
if ( selectedFileName . left ( 4 ) = = " PGTA " )
{
SnapmaticPicture * picture = new SnapmaticPicture ( selectedFile ) ;
if ( picture - > readingPicture ( ) )
{
importSnapmaticPicture ( picture , selectedFile ) ;
}
else
{
2016-04-08 19:46:27 +02:00
QMessageBox : : warning ( this , tr ( " Import " ) , tr ( " Failed to read Snapmatic picture " ) ) ;
2016-03-29 11:22:41 +02:00
picture - > deleteLater ( ) ;
delete picture ;
goto fileDialogPreOpen ;
}
}
else if ( selectedFileName . left ( 4 ) = = " SGTA " )
{
SavegameData * savegame = new SavegameData ( selectedFile ) ;
if ( savegame - > readingSavegame ( ) )
{
importSavegameData ( savegame , selectedFile ) ;
}
else
{
2016-04-08 19:46:27 +02:00
QMessageBox : : warning ( this , tr ( " Import " ) , tr ( " Failed to read Savegame file " ) ) ;
2016-03-29 11:22:41 +02:00
savegame - > deleteLater ( ) ;
delete savegame ;
goto fileDialogPreOpen ;
}
}
else
{
SnapmaticPicture * picture = new SnapmaticPicture ( selectedFile ) ;
SavegameData * savegame = new SavegameData ( selectedFile ) ;
if ( picture - > readingPicture ( ) )
{
importSnapmaticPicture ( picture , selectedFile ) ;
savegame - > deleteLater ( ) ;
delete savegame ;
}
else if ( savegame - > readingSavegame ( ) )
{
importSavegameData ( savegame , selectedFile ) ;
picture - > deleteLater ( ) ;
delete picture ;
}
else
{
savegame - > deleteLater ( ) ;
picture - > deleteLater ( ) ;
delete savegame ;
delete picture ;
2016-04-08 19:46:27 +02:00
QMessageBox : : warning ( this , tr ( " Import " ) , tr ( " Can't import %1 because of not valid file format " ) . arg ( " \" " + selectedFileName + " \" " ) ) ;
2016-03-29 11:22:41 +02:00
goto fileDialogPreOpen ;
}
}
}
else
{
2016-04-08 19:46:27 +02:00
QMessageBox : : warning ( this , tr ( " Import " ) , tr ( " No valid file is selected " ) ) ;
2016-03-29 11:22:41 +02:00
goto fileDialogPreOpen ;
}
}
else
{
2016-04-08 19:46:27 +02:00
QMessageBox : : warning ( this , tr ( " Import " ) , tr ( " No valid file is selected " ) ) ;
2016-03-29 11:22:41 +02:00
goto fileDialogPreOpen ;
}
}
settings . setValue ( " ImportCopy " , fileDialog . saveState ( ) ) ;
settings . endGroup ( ) ;
}
bool ProfileInterface : : importSnapmaticPicture ( SnapmaticPicture * picture , QString picPath )
{
QFileInfo picFileInfo ( picPath ) ;
QString picFileName = picFileInfo . fileName ( ) ;
if ( picFileName . left ( 4 ) ! = " PGTA " )
{
2016-04-08 19:46:27 +02:00
QMessageBox : : warning ( this , tr ( " Import " ) , tr ( " Failed to import the Snapmatic picture, file not begin with PGTA " ) ) ;
2016-03-29 11:22:41 +02:00
return false ;
}
2016-04-10 22:31:11 +02:00
else if ( QFile : : copy ( picPath , profileFolder + QDir : : separator ( ) + picFileName ) )
2016-03-29 11:22:41 +02:00
{
2016-04-10 22:31:11 +02:00
pictureLoaded_f ( picture , profileFolder + QDir : : separator ( ) + picFileName , true ) ;
2016-03-29 11:22:41 +02:00
return true ;
}
else
{
2016-04-08 19:46:27 +02:00
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 ;
}
}
bool ProfileInterface : : importSavegameData ( SavegameData * savegame , QString sgdPath )
{
QString sgdFileName ;
bool foundFree = 0 ;
int currentSgd = 0 ;
while ( currentSgd < 15 & & ! foundFree )
{
QString sgdNumber = QString : : number ( currentSgd ) ;
if ( sgdNumber . length ( ) = = 1 )
{
sgdNumber . insert ( 0 , " 0 " ) ;
}
sgdFileName = " SGTA500 " + sgdNumber ;
2016-04-10 22:31:11 +02:00
if ( ! QFile : : exists ( profileFolder + QDir : : separator ( ) + sgdFileName ) )
2016-03-29 11:22:41 +02:00
{
foundFree = true ;
}
currentSgd + + ;
}
if ( foundFree )
{
2016-04-10 22:31:11 +02:00
if ( QFile : : copy ( sgdPath , profileFolder + QDir : : separator ( ) + sgdFileName ) )
2016-03-29 11:22:41 +02:00
{
2016-04-10 22:31:11 +02:00
savegameLoaded_f ( savegame , profileFolder + QDir : : separator ( ) + sgdFileName , true ) ;
2016-03-29 11:22:41 +02:00
return true ;
}
else
{
2016-04-08 19:46:27 +02:00
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 ;
}
}
else
{
2016-04-08 19:46:27 +02:00
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
{
if ( selectedWidgts = = 0 )
{
foreach ( ProfileWidget * widget , widgets . keys ( ) )
{
widget - > setSelectionMode ( true ) ;
}
}
selectedWidgts + + ;
}
2016-04-03 06:12:12 +02:00
void ProfileInterface : : profileWidgetDeselected ( )
2016-04-03 01:18:48 +02:00
{
if ( selectedWidgts = = 1 )
{
2016-04-03 01:43:04 +02:00
int scrollBarValue = ui - > saProfile - > verticalScrollBar ( ) - > value ( ) ;
2016-04-03 01:18:48 +02:00
foreach ( ProfileWidget * widget , widgets . keys ( ) )
{
widget - > setSelectionMode ( false ) ;
}
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 ( )
{
foreach ( ProfileWidget * widget , widgets . keys ( ) )
{
widget - > setSelected ( true ) ;
}
}
void ProfileInterface : : deselectAllWidgets ( )
{
foreach ( ProfileWidget * widget , widgets . keys ( ) )
{
widget - > setSelected ( false ) ;
}
}
2016-04-03 10:17:01 +02:00
void ProfileInterface : : exportSelected ( )
{
2016-04-08 19:46:27 +02:00
if ( selectedWidgts ! = 0 )
2016-04-03 10:17:01 +02:00
{
2016-04-08 19:46:27 +02:00
int exportCount = 0 ;
int exportPictures = 0 ;
int exportSavegames = 0 ;
bool pictureCopyEnabled = false ;
bool pictureExportEnabled = false ;
QString exportDirectory = QFileDialog : : getExistingDirectory ( this , tr ( " Export selected " ) , profileFolder ) ;
if ( exportDirectory ! = " " )
2016-04-03 10:17:01 +02:00
{
2016-04-08 19:46:27 +02:00
foreach ( ProfileWidget * widget , widgets . keys ( ) )
2016-04-03 10:17:01 +02:00
{
2016-04-08 19:46:27 +02:00
if ( widget - > isSelected ( ) )
2016-04-03 10:17:01 +02:00
{
2016-04-08 19:46:27 +02:00
if ( widget - > getWidgetType ( ) = = " SnapmaticWidget " )
{
exportPictures + + ;
}
else if ( widget - > getWidgetType ( ) = = " SavegameWidget " )
{
exportSavegames + + ;
}
2016-04-03 10:17:01 +02:00
}
2016-04-03 12:27:40 +02:00
}
2016-04-03 10:17:01 +02:00
2016-04-08 19:46:27 +02:00
if ( exportPictures ! = 0 )
2016-04-03 12:27:40 +02:00
{
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 ;
# ifdef GTA5SYNC_WIN
ExportPreSpan = " <span style= \" color: #003399; font-size: 12pt \" > " ;
ExportPostSpan = " </span> " ;
# else
ExportPreSpan = " <span style= \" font-weight: bold \" > " ;
ExportPostSpan = " </span> " ;
# endif
2016-04-08 19:46:27 +02:00
bool itemSelected = false ;
2016-04-11 19:40:49 +02: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 ) ;
2016-04-08 19:46:27 +02:00
if ( itemSelected )
2016-04-03 10:17:01 +02:00
{
2016-04-08 19:46:27 +02:00
if ( selectedItem = = tr ( " JPG pictures and GTA Snapmatic " ) )
{
pictureExportEnabled = true ;
pictureCopyEnabled = true ;
}
else if ( selectedItem = = tr ( " JPG pictures only " ) )
{
pictureExportEnabled = true ;
}
else if ( selectedItem = = tr ( " GTA Snapmatic only " ) )
{
pictureCopyEnabled = true ;
}
else
{
pictureExportEnabled = true ;
pictureCopyEnabled = true ;
}
2016-04-03 10:17:01 +02:00
}
2016-04-08 19:46:27 +02:00
else
2016-04-03 10:17:01 +02:00
{
2016-04-03 12:27:40 +02:00
pictureExportEnabled = true ;
pictureCopyEnabled = true ;
2016-04-03 10:17:01 +02:00
}
}
2016-04-08 19:46:27 +02:00
// Counting the exports together
exportCount = exportCount + exportSavegames ;
if ( pictureExportEnabled & & pictureCopyEnabled )
{
int exportPictures2 = exportPictures * 2 ;
exportCount = exportCount + exportPictures2 ;
}
2016-04-03 12:27:40 +02: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 ) ;
pbDialog . setWindowFlags ( pbDialog . windowFlags ( ) ^ Qt : : WindowContextHelpButtonHint ^ Qt : : WindowCloseButtonHint ) ;
pbDialog . setWindowTitle ( tr ( " Export selected... " ) ) ;
pbDialog . setLabelText ( tr ( " Initializing export... " ) ) ;
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
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
2016-04-08 19:46:27 +02:00
foreach ( const QString & curErrorStr , errorList )
{
errorStr . append ( " , " + curErrorStr ) ;
}
if ( errorStr ! = " " )
{
errorStr . remove ( 0 , 2 ) ;
QMessageBox : : warning ( this , tr ( " Export selected " ) , tr ( " Export failed with... \n \n %1 " ) . arg ( errorStr ) ) ;
}
2016-04-03 12:27:40 +02:00
2016-04-08 19:46:27 +02:00
if ( exportThread - > isFinished ( ) )
{
exportThread - > deleteLater ( ) ;
delete exportThread ;
}
else
{
QEventLoop threadFinishLoop ;
QObject : : connect ( exportThread , SIGNAL ( finished ( ) ) , & threadFinishLoop , SLOT ( quit ( ) ) ) ;
threadFinishLoop . exec ( ) ;
exportThread - > deleteLater ( ) ;
delete exportThread ;
}
2016-04-03 10:17:01 +02:00
}
}
2016-04-08 19:46:27 +02:00
else
{
QMessageBox : : information ( this , tr ( " Export selected " ) , tr ( " No Snapmatic pictures or Savegames files are selected " ) ) ;
}
2016-04-03 10:17:01 +02:00
}
void ProfileInterface : : deleteSelected ( )
{
2016-04-08 19:46:27 +02:00
if ( selectedWidgts ! = 0 )
2016-04-03 12:54:55 +02:00
{
2016-04-08 19:46:27 +02:00
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 ) )
2016-04-03 12:54:55 +02:00
{
2016-04-08 19:46:27 +02:00
foreach ( ProfileWidget * widget , widgets . keys ( ) )
2016-04-03 12:54:55 +02:00
{
2016-04-08 19:46:27 +02:00
if ( widget - > isSelected ( ) )
2016-04-03 12:54:55 +02:00
{
2016-04-08 19:46:27 +02:00
if ( widget - > getWidgetType ( ) = = " SnapmaticWidget " )
2016-04-03 12:54:55 +02:00
{
2016-04-08 19:46:27 +02:00
SnapmaticWidget * picWidget = ( SnapmaticWidget * ) widget ;
SnapmaticPicture * picture = picWidget - > getPicture ( ) ;
QString fileName = picture - > getPictureFileName ( ) ;
if ( ! QFile : : exists ( fileName ) | | QFile : : remove ( fileName ) )
{
pictureDeleted_f ( picWidget ) ;
}
2016-04-03 12:54:55 +02:00
}
2016-04-08 19:46:27 +02:00
else if ( widget - > getWidgetType ( ) = = " SavegameWidget " )
2016-04-03 12:54:55 +02:00
{
2016-04-08 19:46:27 +02:00
SavegameWidget * sgdWidget = ( SavegameWidget * ) widget ;
SavegameData * savegame = sgdWidget - > getSavegame ( ) ;
QString fileName = savegame - > getSavegameFileName ( ) ;
if ( ! QFile : : exists ( fileName ) | | QFile : : remove ( fileName ) )
{
savegameDeleted_f ( sgdWidget ) ;
}
2016-04-03 12:54:55 +02:00
}
}
}
2016-04-08 19:46:27 +02:00
if ( selectedWidgts ! = 0 )
{
QMessageBox : : warning ( this , tr ( " Remove selected " ) , tr ( " Failed at remove the complete selected Snapmatic pictures and/or Savegame files " ) ) ;
}
2016-04-03 12:54:55 +02:00
}
2016-04-08 19:46:27 +02:00
}
else
{
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
}