gta5view/ProfileInterface.cpp

2399 lines
104 KiB
C++
Raw Permalink Normal View History

2016-03-29 11:22:41 +02:00
/*****************************************************************************
* gta5view Grand Theft Auto V Profile Viewer
* 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"
#include "SidebarGenerator.h"
2016-03-29 11:22:41 +02:00
#include "SnapmaticWidget.h"
#include "DatabaseThread.h"
#include "SavegameWidget.h"
#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"
#include "pcg_basic.h"
2021-03-27 08:23:05 +01:00
#include "wrapper.h"
#include "AppEnv.h"
#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>
#include <QStringBuilder>
2018-06-17 09:27:10 +02:00
#include <QNetworkReply>
#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>
#include <random>
2018-06-17 10:52:50 +02:00
#include <ctime>
#ifdef GTA5SYNC_TELEMETRY
#include "TelemetryClass.h"
#include <QJsonDocument>
#include <QJsonObject>
#endif
#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;
#ifdef GTA5SYNC_COMMIT
2021-05-27 05:42:05 +02:00
if ((strcmp(literalBuildType, REL_BUILDTYPE) != 0) && !appVersion.contains("-"))
appVersion = appVersion % "-" % GTA5SYNC_COMMIT;
#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"));
}
// DPI calculation
qreal screenRatio = AppEnv::screenRatio();
#ifndef Q_OS_MAC
ui->hlButtons->setSpacing(6 * screenRatio);
ui->hlButtons->setContentsMargins(9 * screenRatio, 9 * screenRatio, 9 * screenRatio, 9 * screenRatio);
#else
#if QT_VERSION >= 0x060000
if (QApplication::style()->objectName() == "macos") {
#else
2021-03-27 08:23:05 +01:00
if (QApplication::style()->objectName() == "macintosh") {
#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
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
// Register Metatypes
qRegisterMetaType<QVector<QString>>();
2021-05-23 07:20:20 +02:00
#endif
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;
}
}
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;
}
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;
}
pictures.clear();
2016-04-03 12:27:40 +02: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()
{
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
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*)));
QObject::connect(profileLoader, SIGNAL(pictureFixed(SnapmaticPicture*)), this, SLOT(pictureFixed_event(SnapmaticPicture*)));
QObject::connect(profileLoader, SIGNAL(loadingProgress(int,int)), this, SLOT(loadingProgress(int,int)));
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
{
SavegameWidget *sgdWidget = new SavegameWidget(this);
2016-03-29 11:22:41 +02:00
sgdWidget->setSavegameData(savegame, savegamePath);
sgdWidget->setContentMode(contentMode);
2017-10-09 08:35:48 +02:00
sgdWidget->setMouseTracking(true);
sgdWidget->installEventFilter(this);
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()));
QObject::connect(sgdWidget, SIGNAL(widgetSelected()), this, SLOT(profileWidgetSelected()));
QObject::connect(sgdWidget, SIGNAL(widgetDeselected()), this, SLOT(profileWidgetDeselected()));
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
}
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);
picWidget->setContentMode(contentMode);
2017-10-09 08:35:48 +02:00
picWidget->setMouseTracking(true);
picWidget->installEventFilter(this);
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()));
QObject::connect(picWidget, SIGNAL(widgetSelected()), this, SLOT(profileWidgetSelected()));
QObject::connect(picWidget, SIGNAL(widgetDeselected()), this, SLOT(profileWidgetDeselected()));
QObject::connect(picWidget, SIGNAL(allWidgetsSelected()), this, SLOT(selectAllWidgets()));
QObject::connect(picWidget, SIGNAL(allWidgetsDeselected()), this, SLOT(deselectAllWidgets()));
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
}
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
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
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
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;
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;
}
}
}
}
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;
}
});
}
}
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:20:20 +02:00
#endif
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);
#if QT_VERSION >= 0x050600
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
std::sort(savegameKeyList.begin(), savegameKeyList.end());
#else
2016-04-06 06:38:43 +02:00
qSort(savegameKeyList.begin(), savegameKeyList.end());
#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
}
}
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()) {
QStringList widgetsKeyList = widgets.values();
QStringList pictureKeyList = widgetsKeyList.filter("PIC", Qt::CaseSensitive);
#if QT_VERSION >= 0x050600
std::sort(pictureKeyList.rbegin(), pictureKeyList.rend());
#else
qSort(pictureKeyList.begin(), pictureKeyList.end(), qGreater<QString>());
#endif
int picIndex;
2021-03-27 08:23:05 +01:00
if (picDialog->isIndexed()) {
picIndex = picDialog->getIndex();
}
2021-03-27 08:23:05 +01:00
else {
2020-09-28 05:33:04 +02:00
picIndex = pictureKeyList.indexOf(widgetKey);
}
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));
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()) {
QStringList widgetsKeyList = widgets.values();
QStringList pictureKeyList = widgetsKeyList.filter("PIC", Qt::CaseSensitive);
#if QT_VERSION >= 0x050600
std::sort(pictureKeyList.rbegin(), pictureKeyList.rend());
#else
qSort(pictureKeyList.begin(), pictureKeyList.end(), qGreater<QString>());
#endif
int picIndex;
2021-03-27 08:23:05 +01:00
if (picDialog->isIndexed()) {
picIndex = picDialog->getIndex();
}
2021-03-27 08:23:05 +01:00
else {
2020-09-28 05:33:04 +02:00
picIndex = pictureKeyList.indexOf(widgetKey);
}
2021-03-27 08:23:05 +01:00
if (picIndex > 0) {
picIndex--;
2021-03-27 08:23:05 +01:00
const QString newWidgetKey = pictureKeyList.at(picIndex);
SnapmaticWidget *picWidget = static_cast<SnapmaticWidget*>(widgets.key(newWidgetKey));
picDialog->setSnapmaticPicture(picWidget->getPicture(), picIndex);
}
}
}
2016-04-06 06:38:43 +02:00
void ProfileInterface::sortingProfileInterface()
{
ui->vlSavegame->setEnabled(false);
ui->vlSnapmatic->setEnabled(false);
QStringList widgetsKeyList = widgets.values();
2020-10-11 17:46:45 +02:00
#if QT_VERSION >= 0x050600
std::sort(widgetsKeyList.begin(), widgetsKeyList.end());
#else
qSort(widgetsKeyList.begin(), widgetsKeyList.end());
#endif
2016-04-06 06:38:43 +02:00
2021-03-27 08:23:05 +01:00
for (const QString &widgetKey : qAsConst(widgetsKeyList)) {
ProfileWidget *widget = widgets.key(widgetKey);
2021-03-27 08:23:05 +01:00
if (widget->getWidgetType() == "SnapmaticWidget") {
ui->vlSnapmatic->insertWidget(0, widget);
}
2021-03-27 08:23:05 +01:00
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
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;
emit profileLoaded();
2021-03-27 08:23:05 +01:00
if (!fixedPictures.isEmpty()) {
int fixedInt = 0;
QString fixedStr;
2021-03-27 08:23:05 +01:00
for (const QString &fixedPicture : qAsConst(fixedPictures)) {
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);
}
2017-03-01 15:19:40 +01:00
void ProfileInterface::savegameDeleted(SavegameWidget *sgdWidget, bool isRemoteEmited)
{
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
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);
}
2017-03-01 15:19:40 +01:00
void ProfileInterface::pictureDeleted(SnapmaticWidget *picWidget, bool isRemoteEmited)
{
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
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(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);
QList<QUrl> sidebarUrls = SidebarGenerator::generateSidebarUrls(fileDialog.sidebarUrls());
2016-03-29 11:22:41 +02:00
fileDialog.setSidebarUrls(sidebarUrls);
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);
QDateTime importDateTime = QDateTime::currentDateTime();
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) {
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?