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-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"
|
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"
|
2021-03-27 08:23:05 +01:00
|
|
|
#include "wrapper.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-15 07:10:50 +01: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);
|
2016-03-29 11:22:41 +02:00
|
|
|
fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
|
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?
|
|