more RDR 2-awareness, some code rework

This commit is contained in:
Syping 2023-10-06 15:37:48 +02:00
parent e7721404b6
commit 259e785165
10 changed files with 185 additions and 210 deletions

View file

@ -36,7 +36,7 @@
#include <QDesktopWidget>
#endif
ExportThread::ExportThread(QMap<ProfileWidget*,QString> profileMap, QString exportDirectory, bool pictureCopyEnabled, bool pictureExportEnabled, int exportCount, QObject *parent) : QThread(parent),
ExportThread::ExportThread(QHash<ProfileWidget*,QString> profileMap, QString exportDirectory, bool pictureCopyEnabled, bool pictureExportEnabled, int exportCount, QObject *parent) : QThread(parent),
profileMap(profileMap), exportDirectory(exportDirectory), pictureCopyEnabled(pictureCopyEnabled), pictureExportEnabled(pictureExportEnabled), exportCount(exportCount)
{
}
@ -59,9 +59,12 @@ void ExportThread::run()
emit exportStringUpdate(ProfileInterface::tr("Export file %1 of %2 files").arg(QString::number(intExportProgress), QString::number(exportCount)));
emit exportProgressUpdate(intExportProgress);
bool isSaved = false;
QSaveFile exportFile(exportDirectory % "/" % exportFileName);
exportFile.write(picture->getPictureStream());
bool isSaved = exportFile.commit();
if (exportFile.open(QIODevice::WriteOnly)) {
exportFile.write(picture->getPictureStream());
isSaved = exportFile.commit();
}
if (!isSaved)
failedExportPictures += exportFileName;

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5view Grand Theft Auto V Profile Viewer
* Copyright (C) 2016-2017 Syping
* Copyright (C) 2016-2023 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
@ -29,7 +29,7 @@ class ExportThread : public QThread
{
Q_OBJECT
public:
explicit ExportThread(QMap<ProfileWidget*,QString> profileMap, QString exportDirectory, bool pictureCopyEnabled, bool pictureExportEnabled, int exportCount, QObject *parent = 0);
explicit ExportThread(QHash<ProfileWidget*,QString> profileMap, QString exportDirectory, bool pictureCopyEnabled, bool pictureExportEnabled, int exportCount, QObject *parent = 0);
QStringList getFailedSavegames();
QStringList getFailedCopyPictures();
QStringList getFailedExportPictures();
@ -38,7 +38,7 @@ protected:
void run();
private:
QMap <ProfileWidget*, QString> profileMap;
QHash<ProfileWidget*,QString> profileMap;
QString exportDirectory;
bool pictureCopyEnabled;
bool pictureExportEnabled;

View file

@ -169,12 +169,13 @@ void PictureDialog::setupPictureDialog()
// Manage menu
manageMenu = new QMenu(this);
manageMenu->addAction(tr("Export as &Picture..."), this, &PictureDialog::exportSnapmaticPicture);
manageMenu->addAction(tr("Export as &Snapmatic..."), this, &PictureDialog::copySnapmaticPicture);
exportPhotoAction = manageMenu->addAction(tr("Export as &RAGE Photo..."), this, &PictureDialog::copySnapmaticPicture);
manageMenu->addSeparator();
manageMenu->addAction(tr("&Edit Properties..."), this, &PictureDialog::editSnapmaticProperties);
manageMenu->addAction(tr("&Overwrite Image..."), this, &PictureDialog::editSnapmaticImage);
manageMenu->addSeparator();
QAction *openViewerAction = manageMenu->addAction(tr("Open &Map Viewer..."), this, &PictureDialog::openPreviewMap);
openViewerAction = manageMenu->addAction(tr("Open &Map Viewer..."), this, &PictureDialog::openPreviewMap);
openViewerAction->setEnabled(false);
openViewerAction->setShortcut(Qt::Key_M);
manageMenu->addAction(tr("Open &JSON Editor..."), this, &PictureDialog::editSnapmaticRawJson);
ui->cmdManage->setMenu(manageMenu);
@ -490,6 +491,17 @@ void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, bool readOk,
snapmaticPicture = picture->getImage();
renderPicture();
ui->cmdManage->setEnabled(true);
if (smpic->getSnapmaticFormat() == SnapmaticFormat::PGTA5_Format)
exportPhotoAction->setText(tr("Export as &GTA V Snapmatic..."));
else if (smpic->getSnapmaticFormat() == SnapmaticFormat::G5E_Format)
exportPhotoAction->setText(tr("Export as &GTA V Snapmatic..."));
else if (smpic->getSnapmaticFormat() == SnapmaticFormat::PRDR3_Format)
exportPhotoAction->setText(tr("Export as &RDR 2 Photo..."));
else
exportPhotoAction->setText(tr("Export as &RAGE Photo..."));
}
else {
exportPhotoAction->setText(tr("Export as &RAGE Photo..."));
}
if (picture->isJsonOk()) {
crewStr = crewDB->getCrewName(crewID);
@ -498,10 +510,17 @@ void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, bool readOk,
else
picAreaStr = picArea;
ui->labJSON->setText(jsonDrawString.arg(locX, locY, locZ, generatePlayersString(), generateCrewString(), picTitl, picAreaStr, created));
if (smpic->getSnapmaticFormat() == SnapmaticFormat::PGTA5_Format)
openViewerAction->setEnabled(true);
else if (smpic->getSnapmaticFormat() == SnapmaticFormat::G5E_Format)
openViewerAction->setEnabled(true);
else
openViewerAction->setEnabled(false);
QTimer::singleShot(0, this, &PictureDialog::adaptDialogSize);
}
else {
ui->labJSON->setText(jsonDrawString.arg("0", "0", "0", tr("No Players"), tr("No Crew"), tr("Unknown Location")));
openViewerAction->setEnabled(false);
QTimer::singleShot(0, this, &PictureDialog::adaptDialogSize);
}
QObject::connect(smpic, &SnapmaticPicture::updated, this, &PictureDialog::updated);
@ -642,29 +661,28 @@ void PictureDialog::on_labPicture_mouseDoubleClicked(Qt::MouseButton button)
#else
QRect desktopRect = QApplication::desktop()->screenGeometry(this);
#endif
PictureWidget *pictureWidget = new PictureWidget(this); // Work!
pictureWidget->setObjectName("PictureWidget");
pictureWidget->setWindowFlag(Qt::FramelessWindowHint, true);
pictureWidget->setWindowFlag(Qt::MaximizeUsingFullscreenGeometryHint, true);
pictureWidget->setWindowTitle(windowTitle());
pictureWidget->setStyleSheet("QLabel#pictureLabel{background-color:black;}");
pictureWidget->setImage(smpic->getImage(), desktopRect);
pictureWidget->setModal(true);
PictureWidget pictureWidget(this);
pictureWidget.setObjectName("PictureWidget");
pictureWidget.setWindowFlag(Qt::FramelessWindowHint, true);
pictureWidget.setWindowFlag(Qt::MaximizeUsingFullscreenGeometryHint, true);
pictureWidget.setWindowTitle(windowTitle());
pictureWidget.setStyleSheet("QLabel#pictureLabel{background-color:black;}");
pictureWidget.setImage(smpic->getImage(), desktopRect);
pictureWidget.setModal(true);
fullscreenWidget = pictureWidget;
QObject::connect(this, &PictureDialog::newPictureCommited, pictureWidget, QOverload<QImage>::of(&PictureWidget::setImage));
QObject::connect(pictureWidget, &PictureWidget::nextPictureRequested, this, &PictureDialog::dialogNextPictureRequested);
QObject::connect(pictureWidget, &PictureWidget::previousPictureRequested, this, &PictureDialog::dialogPreviousPictureRequested);
fullscreenWidget = &pictureWidget;
QObject::connect(this, &PictureDialog::newPictureCommited, &pictureWidget, QOverload<QImage>::of(&PictureWidget::setImage));
QObject::connect(&pictureWidget, &PictureWidget::nextPictureRequested, this, &PictureDialog::dialogNextPictureRequested);
QObject::connect(&pictureWidget, &PictureWidget::previousPictureRequested, this, &PictureDialog::dialogPreviousPictureRequested);
pictureWidget->move(desktopRect.x(), desktopRect.y());
pictureWidget->resize(desktopRect.width(), desktopRect.height());
pictureWidget->showFullScreen();
pictureWidget->setFocus();
pictureWidget->raise();
pictureWidget->exec();
pictureWidget.move(desktopRect.x(), desktopRect.y());
pictureWidget.resize(desktopRect.width(), desktopRect.height());
pictureWidget.showFullScreen();
pictureWidget.setFocus();
pictureWidget.raise();
pictureWidget.exec();
fullscreenWidget = nullptr; // Work!
delete pictureWidget; // Work!
fullscreenWidget = nullptr;
}
}
@ -861,7 +879,7 @@ void PictureDialog::updated()
void PictureDialog::customSignal(QString signal)
{
SnapmaticPicture *picture = smpic; // used by macro
if (signal == "PictureUpdated") {
if (signal == QStringLiteral("PictureUpdated")) {
snapmaticPicture = picture->getImage();
renderPicture();
}

View file

@ -124,6 +124,8 @@ private:
int avatarLocX;
int avatarLocY;
int avatarSize;
QAction *exportPhotoAction;
QAction *openViewerAction;
QMenu *manageMenu;
#ifdef Q_OS_WIN
#if QT_VERSION >= 0x050000

View file

@ -925,20 +925,20 @@ bool ProfileInterface::importRemote(QUrl remoteUrl)
urlPasteDialog.setFixedSize(urlPasteDialog.sizeHint());
urlPasteDialog.show();
QNetworkAccessManager *netManager = new QNetworkAccessManager();
QNetworkAccessManager netManager;
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;
QNetworkReply *netReply = netManager.get(netRequest);
netReply->setParent(&netManager);
QEventLoop downloadLoop;
QObject::connect(netReply, &QNetworkReply::finished, &downloadLoop, &QEventLoop::quit);
QTimer::singleShot(30000, &downloadLoop, &QEventLoop::quit);
downloadLoop.exec();
downloadLoop.disconnect();
urlPasteDialog.close();
@ -957,8 +957,6 @@ bool ProfileInterface::importRemote(QUrl remoteUrl)
else {
netReply->abort();
}
delete netReply;
delete netManager;
return retValue;
}
@ -966,14 +964,14 @@ bool ProfileInterface::importImage(QImage *snapmaticImage, QDateTime importDateT
{
SnapmaticPicture *picture = new SnapmaticPicture();
picture->initialise(photoFormat);
ImportDialog *importDialog = new ImportDialog(profileName, this);
importDialog->setImage(snapmaticImage);
importDialog->setModal(true);
importDialog->show();
importDialog->exec();
ImportDialog importDialog(profileName, this);
importDialog.setImage(snapmaticImage);
importDialog.setModal(true);
importDialog.show();
importDialog.exec();
bool success = false;
if (importDialog->isImportAgreed()) {
if (picture->setImage(importDialog->image(), importDialog->isUnlimitedBuffer())) {
if (importDialog.isImportAgreed()) {
if (picture->setImage(importDialog.image(), importDialog.isUnlimitedBuffer())) {
QString fileFormat;
switch (photoFormat) {
case RagePhoto::PhotoFormat::GTA5:
@ -1011,7 +1009,7 @@ bool ProfileInterface::importImage(QImage *snapmaticImage, QDateTime importDateT
#endif
picture->setSnapmaticProperties(spJson);
picture->setPicFileName(fileFormat.arg(QString::number(spJson.uid)));
picture->setPictureTitle(importDialog->getImageTitle());
picture->setPictureTitle(importDialog.getImageTitle());
success = importSnapmaticPicture(picture, true);
}
}
@ -1019,7 +1017,6 @@ bool ProfileInterface::importImage(QImage *snapmaticImage, QDateTime importDateT
delete picture;
success = true;
}
delete importDialog;
if (!success)
delete picture;
return success;
@ -1214,10 +1211,13 @@ void ProfileInterface::exportSelected()
if (exportPictures != 0) {
QInputDialog inputDialog;
inputDialog.setWindowFlag(Qt::WindowContextHelpButtonHint, false);
inputDialog.setWindowFlag(Qt::WindowMinMaxButtonsHint, false);
QStringList inputDialogItems;
inputDialogItems << tr("JPG pictures and GTA Snapmatic");
inputDialogItems << tr("JPG pictures only");
inputDialogItems << tr("GTA Snapmatic only");
inputDialogItems << tr("JPEG pictures, GTA V Snapmatic and RDR 2 Photo");
inputDialogItems << tr("JPEG pictures");
inputDialogItems << tr("GTA V Snapmatic and RDR 2 Photo");
QString ExportPreSpan;
QString ExportPostSpan;
@ -1230,16 +1230,16 @@ void ProfileInterface::exportSelected()
#endif
bool itemSelected = false;
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);
QString selectedItem = inputDialog.getItem(this, tr("Export selected..."), tr("%1Export GTA V Snapmatic and RDR 2 Photo%2<br><br>JPEG pictures can be open by your operating system and various software, but will lose metadata saved from the game<br>GTA V Snapmatic and RDR 2 Photo keeps all metadata, but the software compatibility is limited<br><br>Export as:").arg(ExportPreSpan, ExportPostSpan), inputDialogItems, 0, false, &itemSelected, inputDialog.windowFlags());
if (itemSelected) {
if (selectedItem == tr("JPG pictures and GTA Snapmatic")) {
if (selectedItem == tr("JPEG pictures, GTA V Snapmatic and RDR 2 Photo")) {
pictureExportEnabled = true;
pictureCopyEnabled = true;
}
else if (selectedItem == tr("JPG pictures only")) {
else if (selectedItem == tr("JPEG pictures")) {
pictureExportEnabled = true;
}
else if (selectedItem == tr("GTA Snapmatic only")) {
else if (selectedItem == tr("GTA V Snapmatic and RDR 2 Photo")) {
pictureCopyEnabled = true;
}
else {
@ -1278,17 +1278,17 @@ void ProfileInterface::exportSelected()
QList<QProgressBar*> pbBar = pbDialog.findChildren<QProgressBar*>();
pbBar.at(0)->setTextVisible(false);
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();
ExportThread exportThread(widgets, exportDirectory, pictureCopyEnabled, pictureExportEnabled, exportCount);
QObject::connect(&exportThread, &ExportThread::exportStringUpdate, &pbDialog, &QProgressDialog::setLabelText);
QObject::connect(&exportThread, &ExportThread::exportProgressUpdate, &pbDialog, &QProgressDialog::setValue);
QObject::connect(&exportThread, &ExportThread::exportFinished, &pbDialog, &QProgressDialog::close);
exportThread.start();
pbDialog.setAutoClose(false);
pbDialog.exec();
QStringList getFailedSavegames = exportThread->getFailedSavegames();
QStringList getFailedCopyPictures = exportThread->getFailedCopyPictures();
QStringList getFailedExportPictures = exportThread->getFailedExportPictures();
QStringList getFailedSavegames = exportThread.getFailedSavegames();
QStringList getFailedCopyPictures = exportThread.getFailedCopyPictures();
QStringList getFailedExportPictures = exportThread.getFailedExportPictures();
QString errorStr;
QStringList errorList;
@ -1299,33 +1299,29 @@ void ProfileInterface::exportSelected()
for (const QString &curErrorStr : qAsConst(errorList)) {
errorStr += ", " % curErrorStr;
}
if (errorStr != "") {
if (!errorStr.isEmpty()) {
errorStr.remove(0, 2);
QMessageBox::warning(this, tr("Export selected..."), tr("Export failed with...\n\n%1").arg(errorStr));
}
if (exportThread->isFinished()) {
delete exportThread;
}
else {
if (!exportThread.isFinished()) {
QEventLoop threadFinishLoop;
QObject::connect(exportThread, SIGNAL(finished()), &threadFinishLoop, SLOT(quit()));
QObject::connect(&exportThread, &ExportThread::finished, &threadFinishLoop, &QEventLoop::quit);
threadFinishLoop.exec();
delete exportThread;
}
}
settings.endGroup();
settings.endGroup();
}
else {
QMessageBox::information(this, tr("Export selected..."), tr("No Snapmatic pictures or Savegames files are selected"));
QMessageBox::information(this, tr("Export selected..."), tr("No Snapmatic, Photo or Savegame files are selected"));
}
}
void ProfileInterface::deleteSelectedL(bool isRemoteEmited)
{
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)) {
if (QMessageBox::Yes == QMessageBox::warning(this, tr("Remove selected"), tr("You really want remove the selected Snapmatic, Photo and Savegame files?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No)) {
for (const QString &widgetStr : qAsConst(widgets)) {
ProfileWidget *widget = widgets.key(widgetStr, nullptr);
if (widget != nullptr) {
@ -1348,12 +1344,12 @@ void ProfileInterface::deleteSelectedL(bool isRemoteEmited)
}
}
if (selectedWidgts != 0) {
QMessageBox::warning(this, tr("Remove selected"), tr("Failed to remove all selected Snapmatic pictures and/or Savegame files"));
QMessageBox::warning(this, tr("Remove selected"), tr("Failed to remove all selected Snapmatic, Photo and/or Savegame files"));
}
}
}
else {
QMessageBox::information(this, tr("Remove selected"), tr("No Snapmatic pictures or Savegames files are selected"));
QMessageBox::information(this, tr("Remove selected"), tr("No Snapmatic, Photo or Savegame files are selected"));
}
}
@ -1454,7 +1450,7 @@ void ProfileInterface::enableSelected()
}
}
if (snapmaticWidgets.isEmpty()) {
QMessageBox::information(this, QApplication::translate("UserInterface", "Show In-game"), QApplication::translate("ProfileInterface", "No Snapmatic pictures are selected"));
QMessageBox::information(this, QApplication::translate("UserInterface", "Show In-game"), QApplication::translate("ProfileInterface", "No Snapmatic or Photos are selected"));
return;
}
QStringList fails;
@ -1484,7 +1480,7 @@ void ProfileInterface::disableSelected()
}
}
if (snapmaticWidgets.isEmpty()) {
QMessageBox::information(this, QApplication::translate("UserInterface", "Hide In-game"), QApplication::translate("ProfileInterface", "No Snapmatic pictures are selected"));
QMessageBox::information(this, QApplication::translate("UserInterface", "Hide In-game"), QApplication::translate("ProfileInterface", "No Snapmatic or Photos are selected"));
return;
}
QStringList fails;
@ -1527,11 +1523,18 @@ void ProfileInterface::contextMenuTriggeredPIC(QContextMenuEvent *ev)
editMenu.addAction(PictureDialog::tr("&Edit Properties..."), picWidget, &SnapmaticWidget::editSnapmaticProperties);
editMenu.addAction(PictureDialog::tr("&Overwrite Image..."), picWidget, &SnapmaticWidget::editSnapmaticImage);
editMenu.addSeparator();
editMenu.addAction(PictureDialog::tr("Open &Map Viewer..."), picWidget, &SnapmaticWidget::openMapViewer);
QAction *openViewerAction = editMenu.addAction(PictureDialog::tr("Open &Map Viewer..."), picWidget, &SnapmaticWidget::openMapViewer);
if (photoFormat != RagePhoto::PhotoFormat::GTA5)
openViewerAction->setEnabled(false);
editMenu.addAction(PictureDialog::tr("Open &JSON Editor..."), picWidget, &SnapmaticWidget::editSnapmaticRawJson);
QMenu exportMenu(SnapmaticWidget::tr("&Export"), this);
exportMenu.addAction(PictureDialog::tr("Export as &Picture..."), picWidget, &SnapmaticWidget::on_cmdExport_clicked);
exportMenu.addAction(PictureDialog::tr("Export as &Snapmatic..."), picWidget, &SnapmaticWidget::on_cmdCopy_clicked);
if (photoFormat == RagePhoto::PhotoFormat::GTA5)
exportMenu.addAction(PictureDialog::tr("Export as &GTA V Snapmatic..."), picWidget, &SnapmaticWidget::on_cmdCopy_clicked);
else if (photoFormat == RagePhoto::PhotoFormat::RDR2)
exportMenu.addAction(PictureDialog::tr("Export as &RDR 2 Photo..."), picWidget, &SnapmaticWidget::on_cmdCopy_clicked);
else
exportMenu.addAction(PictureDialog::tr("Export as &RAGE Photo..."), picWidget, &SnapmaticWidget::on_cmdCopy_clicked);
contextMenu.addAction(SnapmaticWidget::tr("&View"), picWidget, &SnapmaticWidget::on_cmdView_clicked);
contextMenu.addMenu(&editMenu);
contextMenu.addMenu(&exportMenu);

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5view Grand Theft Auto V Profile Viewer
* Copyright (C) 2016-2021 Syping
* Copyright (C) 2016-2023 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
@ -106,7 +106,7 @@ private:
ProfileWidget *previousWidget;
QList<SavegameData*> savegames;
QList<SnapmaticPicture*> pictures;
QMap<ProfileWidget*,QString> widgets;
QHash<ProfileWidget*,QString> widgets;
QFileSystemWatcher fileSystemWatcher;
QVector<QString> savegameFiles;
QVector<QString> snapmaticPics;

View file

@ -96,27 +96,19 @@ void SavegameWidget::renderString(const QString &savegameString, const QString &
QString savegameName = tr("WRONG FORMAT");
QString savegameDate = tr("WRONG FORMAT");
QStringList savegameNDL = QString(savegameString).split(" - ");
if (savegameNDL.length() >= 2)
{
if (savegameNDL.length() >= 2) {
savegameDate = savegameNDL.at(savegameNDL.length() - 1);
savegameName = QString(savegameString).remove(savegameString.length() - savegameDate.length() - 3, savegameDate.length() + 3);
}
int savegameNumber = QString(fileName).remove(0,5).toInt(&validNumber) + 1;
if (validNumber)
{
int savegameNumber = QString(fileName).remove(0, 5).toInt(&validNumber) + 1;
if (validNumber) {
if (savegameNumber == 16)
{
ui->labSavegameStr->setText(labelAutosaveStr.arg(savegameDate, savegameName));
}
else
{
ui->labSavegameStr->setText(labelSaveStr.arg(savegameDate, savegameName, QString::number(savegameNumber)));
}
}
else
{
ui->labSavegameStr->setText(labelSaveStr.arg(savegameDate, savegameName, tr("UNKNOWN")));
}
}
void SavegameWidget::retranslate()
@ -136,18 +128,15 @@ void SavegameWidget::on_cmdCopy_clicked()
void SavegameWidget::on_cmdDelete_clicked()
{
int uchoice = QMessageBox::question(this, tr("Delete Savegame"), tr("Are you sure to delete %1 from your savegames?").arg("\""+sgdStr+"\""), QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
if (uchoice == QMessageBox::Yes)
{
if (!QFile::exists(sgdPath))
{
if (uchoice == QMessageBox::Yes) {
if (!QFile::exists(sgdPath)) {
emit savegameDeleted();
#ifdef GTA5SYNC_TELEMETRY
QSettings telemetrySettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
telemetrySettings.beginGroup("Telemetry");
bool pushUsageData = telemetrySettings.value("PushUsageData", false).toBool();
telemetrySettings.endGroup();
if (pushUsageData && Telemetry->canPush())
{
if (pushUsageData && Telemetry->canPush()) {
QJsonDocument jsonDocument;
QJsonObject jsonObject;
jsonObject["Type"] = "DeleteSuccess";
@ -162,15 +151,13 @@ void SavegameWidget::on_cmdDelete_clicked()
}
#endif
}
else if (QFile::remove(sgdPath))
{
else if (QFile::remove(sgdPath)) {
#ifdef GTA5SYNC_TELEMETRY
QSettings telemetrySettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
telemetrySettings.beginGroup("Telemetry");
bool pushUsageData = telemetrySettings.value("PushUsageData", false).toBool();
telemetrySettings.endGroup();
if (pushUsageData && Telemetry->canPush())
{
if (pushUsageData && Telemetry->canPush()) {
QJsonDocument jsonDocument;
QJsonObject jsonObject;
jsonObject["Type"] = "DeleteSuccess";
@ -187,25 +174,17 @@ void SavegameWidget::on_cmdDelete_clicked()
emit savegameDeleted();
}
else
{
QMessageBox::warning(this, tr("Delete Savegame"), tr("Failed at deleting %1 from your savegames").arg("\""+sgdStr+"\""));
}
}
}
void SavegameWidget::on_cmdView_clicked()
{
SavegameDialog *savegameDialog = new SavegameDialog(this);
savegameDialog->setSavegameData(sgdata, sgdPath, true);
savegameDialog->setModal(true);
#ifdef Q_OS_ANDROID
// Android ...
savegameDialog->showMaximized();
#else
savegameDialog->show();
#endif
savegameDialog->exec();
delete savegameDialog;
SavegameDialog savegameDialog(this);
savegameDialog.setSavegameData(sgdata, sgdPath, true);
savegameDialog.setModal(true);
savegameDialog.show();
savegameDialog.exec();
}
void SavegameWidget::mousePressEvent(QMouseEvent *ev)
@ -216,31 +195,20 @@ void SavegameWidget::mousePressEvent(QMouseEvent *ev)
void SavegameWidget::mouseReleaseEvent(QMouseEvent *ev)
{
ProfileWidget::mouseReleaseEvent(ev);
if (ui->cbSelected->isVisible())
{
if (ui->cbSelected->isVisible()) {
if (rect().contains(ev->pos()) && ev->button() == Qt::LeftButton)
{
ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
}
}
else
{
else {
const int contentMode = getContentMode();
if ((contentMode == 0 || contentMode == 10 || contentMode == 20) && rect().contains(ev->pos()) && ev->button() == Qt::LeftButton)
{
if ((contentMode == 0 || contentMode == 10 || contentMode == 20) && rect().contains(ev->pos()) && ev->button() == Qt::LeftButton) {
if (ev->modifiers().testFlag(Qt::ShiftModifier))
{
ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
}
else
{
on_cmdView_clicked();
}
}
else if (!ui->cbSelected->isVisible() && (contentMode == 1 || contentMode == 11 || contentMode == 21) && ev->button() == Qt::LeftButton && ev->modifiers().testFlag(Qt::ShiftModifier))
{
ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
}
}
}
@ -250,9 +218,7 @@ void SavegameWidget::mouseDoubleClickEvent(QMouseEvent *ev)
const int contentMode = getContentMode();
if (!ui->cbSelected->isVisible() && (contentMode == 1 || contentMode == 11 || contentMode == 21) && ev->button() == Qt::LeftButton)
{
on_cmdView_clicked();
}
}
void SavegameWidget::setSelected(bool isSelected)
@ -273,13 +239,9 @@ void SavegameWidget::contextMenuEvent(QContextMenuEvent *ev)
void SavegameWidget::on_cbSelected_stateChanged(int arg1)
{
if (arg1 == Qt::Checked)
{
emit widgetSelected();
}
else if (arg1 == Qt::Unchecked)
{
emit widgetDeselected();
}
}
bool SavegameWidget::isSelected()
@ -309,5 +271,5 @@ SavegameData* SavegameWidget::getSavegame()
QString SavegameWidget::getWidgetType()
{
return "SavegameWidget";
return QStringLiteral("SavegameWidget");
}

View file

@ -73,8 +73,8 @@ SnapmaticWidget::~SnapmaticWidget()
void SnapmaticWidget::setSnapmaticPicture(SnapmaticPicture *picture)
{
smpic = picture;
QObject::connect(picture, SIGNAL(updated()), this, SLOT(snapmaticUpdated()));
QObject::connect(picture, SIGNAL(customSignal(QString)), this, SLOT(customSignal(QString)));
QObject::connect(picture, &SnapmaticPicture::updated, this, &SnapmaticWidget::snapmaticUpdated);
QObject::connect(picture, &SnapmaticPicture::customSignal, this, &SnapmaticWidget::customSignal);
const qreal screenRatio = AppEnv::screenRatio();
const qreal screenRatioPR = AppEnv::screenRatioPR();
@ -116,7 +116,7 @@ void SnapmaticWidget::snapmaticUpdated()
void SnapmaticWidget::customSignal(QString signal)
{
if (signal == "PictureUpdated") {
if (signal == QStringLiteral("PictureUpdated")) {
QPixmap SnapmaticPixmap = QPixmap::fromImage(smpic->getImage().scaled(ui->labPicture->width(), ui->labPicture->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation), Qt::AutoColor);
ui->labPicture->setPixmap(SnapmaticPixmap);
}
@ -135,33 +135,28 @@ void SnapmaticWidget::on_cmdView_clicked()
bool navigationBar = settings.value("NavigationBar", true).toBool();
settings.endGroup();
PictureDialog *picDialog = new PictureDialog(profileDB, crewDB, profileName, this);
picDialog->setSnapmaticPicture(smpic, true);
picDialog->setModal(true);
PictureDialog picDialog(profileDB, crewDB, profileName, this);
picDialog.setSnapmaticPicture(smpic, true);
picDialog.setModal(true);
// be ready for crewName and playerName updated
QObject::connect(threadDB, SIGNAL(crewNameUpdated()), picDialog, SLOT(crewNameUpdated()));
QObject::connect(threadDB, SIGNAL(playerNameUpdated()), picDialog, SLOT(playerNameUpdated()));
QObject::connect(picDialog, SIGNAL(nextPictureRequested()), this, SLOT(dialogNextPictureRequested()));
QObject::connect(picDialog, SIGNAL(previousPictureRequested()), this, SLOT(dialogPreviousPictureRequested()));
QObject::connect(threadDB, &DatabaseThread::crewNameUpdated, &picDialog, &PictureDialog::crewNameUpdated);
QObject::connect(threadDB, &DatabaseThread::playerNameUpdated, &picDialog, &PictureDialog::playerNameUpdated);
QObject::connect(&picDialog, &PictureDialog::nextPictureRequested, this, &SnapmaticWidget::dialogNextPictureRequested);
QObject::connect(&picDialog, &PictureDialog::previousPictureRequested, this, &SnapmaticWidget::dialogPreviousPictureRequested);
// add previous next buttons
if (navigationBar)
picDialog->addPreviousNextButtons();
picDialog.addPreviousNextButtons();
// show picture dialog
#ifdef Q_OS_ANDROID
// Android ...
picDialog->showMaximized();
#else
picDialog->show();
if (navigationBar) picDialog->styliseDialog();
//picDialog->adaptNewDialogSize();
picDialog->setMinimumSize(picDialog->size());
picDialog->setMaximumSize(picDialog->size());
#endif
picDialog->exec();
delete picDialog;
picDialog.show();
if (navigationBar)
picDialog.styliseDialog();
picDialog.setMinimumSize(picDialog.size());
picDialog.setMaximumSize(picDialog.size());
picDialog.exec();
}
void SnapmaticWidget::on_cmdCopy_clicked()
@ -270,32 +265,28 @@ void SnapmaticWidget::contextMenuEvent(QContextMenuEvent *ev)
void SnapmaticWidget::dialogNextPictureRequested()
{
emit nextPictureRequested((QWidget*)sender());
emit nextPictureRequested(static_cast<QWidget*>(sender()));
}
void SnapmaticWidget::dialogPreviousPictureRequested()
{
emit previousPictureRequested((QWidget*)sender());
emit previousPictureRequested(static_cast<QWidget*>(sender()));
}
void SnapmaticWidget::on_cbSelected_stateChanged(int arg1)
{
if (arg1 == Qt::Checked) {
if (arg1 == Qt::Checked)
emit widgetSelected();
}
else if (arg1 == Qt::Unchecked) {
else if (arg1 == Qt::Unchecked)
emit widgetDeselected();
}
}
void SnapmaticWidget::adjustTextColor()
{
if (isHidden()) {
if (isHidden())
ui->labPicStr->setStyleSheet(QString("QLabel{color: rgb(%1, %2, %3);}").arg(QString::number(highlightHiddenColor.red()), QString::number(highlightHiddenColor.green()), QString::number(highlightHiddenColor.blue())));
}
else {
ui->labPicStr->setStyleSheet("");
}
else
ui->labPicStr->setStyleSheet(QString());
}
bool SnapmaticWidget::makePictureHidden()
@ -330,35 +321,33 @@ void SnapmaticWidget::makePictureVisibleSlot()
void SnapmaticWidget::editSnapmaticProperties()
{
SnapmaticEditor *snapmaticEditor = new SnapmaticEditor(crewDB, profileDB, this);
snapmaticEditor->setSnapmaticPicture(smpic);
snapmaticEditor->setModal(true);
snapmaticEditor->show();
snapmaticEditor->exec();
delete snapmaticEditor;
SnapmaticEditor snapmaticEditor(crewDB, profileDB, this);
snapmaticEditor.setSnapmaticPicture(smpic);
snapmaticEditor.setModal(true);
snapmaticEditor.show();
snapmaticEditor.exec();
}
void SnapmaticWidget::editSnapmaticRawJson()
{
JsonEditorDialog *jsonEditor = new JsonEditorDialog(smpic, this);
jsonEditor->setModal(true);
jsonEditor->show();
jsonEditor->exec();
delete jsonEditor;
JsonEditorDialog jsonEditor(smpic, this);
jsonEditor.setModal(true);
jsonEditor.show();
jsonEditor.exec();
}
void SnapmaticWidget::editSnapmaticImage()
{
QImage *currentImage = new QImage(smpic->getImage());
ImportDialog *importDialog = new ImportDialog(profileName, this);
importDialog->setImage(currentImage);
importDialog->enableOverwriteMode();
importDialog->setModal(true);
importDialog->exec();
if (importDialog->isImportAgreed()) {
ImportDialog importDialog(profileName, this);
importDialog.setImage(currentImage);
importDialog.enableOverwriteMode();
importDialog.setModal(true);
importDialog.exec();
if (importDialog.isImportAgreed()) {
const QSize previousSize = smpic->getPictureResolution();
const QByteArray previousPicture = smpic->getPictureStream();
bool success = smpic->setImage(importDialog->image(), importDialog->isUnlimitedBuffer());
bool success = smpic->setImage(importDialog.image(), importDialog.isUnlimitedBuffer());
if (success) {
QString currentFilePath = smpic->getPictureFilePath();
QString originalFilePath = smpic->getOriginalPictureFilePath();
@ -398,22 +387,21 @@ void SnapmaticWidget::editSnapmaticImage()
return;
}
}
delete importDialog;
}
void SnapmaticWidget::openMapViewer()
{
SnapmaticPicture *picture = smpic;
SnapmaticProperties currentProperties = picture->getSnapmaticProperties();
MapLocationDialog *mapLocDialog = new MapLocationDialog(currentProperties.location.x, currentProperties.location.y, this);
mapLocDialog->setCayoPerico(currentProperties.location.isCayoPerico);
mapLocDialog->setModal(true);
mapLocDialog->show();
mapLocDialog->exec();
if (mapLocDialog->propUpdated()) {
MapLocationDialog mapLocDialog(currentProperties.location.x, currentProperties.location.y, this);
mapLocDialog.setCayoPerico(currentProperties.location.isCayoPerico);
mapLocDialog.setModal(true);
mapLocDialog.show();
mapLocDialog.exec();
if (mapLocDialog.propUpdated()) {
// Update Snapmatic Properties
currentProperties.location.x = mapLocDialog->getXpos();
currentProperties.location.y = mapLocDialog->getYpos();
currentProperties.location.x = mapLocDialog.getXpos();
currentProperties.location.y = mapLocDialog.getYpos();
currentProperties.location.z = 0;
// Update Snapmatic Picture
@ -452,7 +440,6 @@ void SnapmaticWidget::openMapViewer()
}
#endif
}
delete mapLocDialog;
}
bool SnapmaticWidget::isSelected()
@ -492,5 +479,5 @@ QString SnapmaticWidget::getPicturePath()
QString SnapmaticWidget::getWidgetType()
{
return "SnapmaticWidget";
return QStringLiteral("SnapmaticWidget");
}

View file

@ -83,8 +83,8 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D
setWindowTitle(defaultWindowTitle.arg(tr("Select Profile")));
QString appVersion = QApplication::applicationVersion();
const char* literalBuildType = GTA5SYNC_BUILDTYPE;
#ifdef GTA5SYNC_COMMIT
const char* literalBuildType = GTA5SYNC_BUILDTYPE;
if ((strcmp(literalBuildType, REL_BUILDTYPE) != 0) && !appVersion.contains("-"))
appVersion = appVersion % "-" % GTA5SYNC_COMMIT;
#endif
@ -129,7 +129,7 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D
// Set Icon for Exit Menu Item
if (QIcon::hasThemeIcon("application-exit")) {
#ifndef Q_OS_MACOS // Setting icon for exit/quit lead to a crash in Mac OS X
#ifndef Q_OS_MACOS // Setting icon for exit/quit lead to a crash in macOS
ui->actionExit->setIcon(QIcon::fromTheme("application-exit"));
#endif
}
@ -846,8 +846,8 @@ void UserInterface::retranslateUi()
ui->actionAbout_gta5sync->setText(tr("&About %1").arg(GTA5SYNC_APPSTR));
#endif
QString appVersion = QApplication::applicationVersion();
const char* literalBuildType = GTA5SYNC_BUILDTYPE;
#ifdef GTA5SYNC_COMMIT
const char* literalBuildType = GTA5SYNC_BUILDTYPE;
if ((strcmp(literalBuildType, REL_BUILDTYPE) != 0) && !appVersion.contains("-"))
appVersion = appVersion % "-" % GTA5SYNC_COMMIT;
#endif

View file

@ -228,12 +228,12 @@ int main(int argc, char *argv[])
if (!readOk)
return 1;
QObject::connect(&threadDB, SIGNAL(crewNameFound(int, QString)), &crewDB, SLOT(setCrewName(int, QString)));
QObject::connect(&threadDB, SIGNAL(crewNameUpdated()), &picDialog, SLOT(crewNameUpdated()));
QObject::connect(&threadDB, SIGNAL(playerNameFound(int, QString)), &profileDB, SLOT(setPlayerName(int, QString)));
QObject::connect(&threadDB, SIGNAL(playerNameUpdated()), &picDialog, SLOT(playerNameUpdated()));
QObject::connect(&threadDB, SIGNAL(finished()), &a, SLOT(quit()));
QObject::connect(&picDialog, SIGNAL(endDatabaseThread()), &threadDB, SLOT(terminateThread()));
QObject::connect(&threadDB, &DatabaseThread::crewNameFound, &crewDB, &CrewDatabase::setCrewName);
QObject::connect(&threadDB, &DatabaseThread::crewNameUpdated, &picDialog, &PictureDialog::crewNameUpdated);
QObject::connect(&threadDB, &DatabaseThread::playerNameFound, &profileDB, &ProfileDatabase::setPlayerName);
QObject::connect(&threadDB, &DatabaseThread::playerNameUpdated, &picDialog, &PictureDialog::playerNameUpdated);
QObject::connect(&threadDB, &DatabaseThread::finished, &a, &QApplication::quit);
QObject::connect(&picDialog, &PictureDialog::endDatabaseThread, &threadDB, &DatabaseThread::terminateThread);
threadDB.start();
picDialog.show();
@ -261,9 +261,9 @@ int main(int argc, char *argv[])
ProfileDatabase profileDB;
DatabaseThread threadDB(&crewDB);
QObject::connect(&threadDB, SIGNAL(crewNameFound(int,QString)), &crewDB, SLOT(setCrewName(int, QString)));
QObject::connect(&threadDB, SIGNAL(playerNameFound(int, QString)), &profileDB, SLOT(setPlayerName(int, QString)));
QObject::connect(&threadDB, SIGNAL(finished()), &a, SLOT(quit()));
QObject::connect(&threadDB, &DatabaseThread::crewNameFound, &crewDB, &CrewDatabase::setCrewName);
QObject::connect(&threadDB, &DatabaseThread::playerNameFound, &profileDB, &ProfileDatabase::setPlayerName);
QObject::connect(&threadDB, &DatabaseThread::finished, &a, &QApplication::quit);
threadDB.start();
#ifdef GTA5SYNC_MOTD