gta5view/ProfileInterface.cpp

1943 lines
77 KiB
C++
Raw Normal View History

2016-03-29 11:22:41 +02:00
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
2018-01-11 08:41:00 +01:00
* Copyright (C) 2016-2018 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"
#include "AppEnv.h"
#include "config.h"
2016-04-03 12:27:40 +02:00
#include <QProgressDialog>
#include <QStringBuilder>
#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>
2016-04-03 12:27:40 +02:00
#include <QEventLoop>
2016-04-03 01:43:04 +02:00
#include <QScrollBar>
2016-03-29 11:22:41 +02:00
#include <QFileInfo>
#include <QPalette>
2017-02-11 04:21:55 +01:00
#include <QPainter>
2016-03-29 11:22:41 +02:00
#include <QRegExp>
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>
2016-03-29 11:22:41 +02:00
#include <QFile>
#include <QUrl>
#include <QDir>
#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();
ui->labVersion->setText(QString("%1 %2").arg(GTA5SYNC_APPSTR, GTA5SYNC_APPVER));
ui->saProfileContent->setFilesMode(true);
2017-02-11 04:21:55 +01:00
2018-01-11 08:41:00 +01:00
// Set Icon for Close Button
2017-02-11 04:21:55 +01:00
if (QIcon::hasThemeIcon("dialog-close"))
{
ui->cmdCloseProfile->setIcon(QIcon::fromTheme("dialog-close"));
}
2018-01-11 08:41:00 +01:00
else if (QIcon::hasThemeIcon("gtk-close"))
{
ui->cmdCloseProfile->setIcon(QIcon::fromTheme("gtk-close"));
}
// Set Icon for Import Button
if (QIcon::hasThemeIcon("document-import"))
{
ui->cmdImport->setIcon(QIcon::fromTheme("document-import"));
}
// 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
2017-12-12 04:45:46 +01:00
if (QApplication::style()->objectName() == "macintosh")
{
ui->hlButtons->setSpacing(6 * screenRatio);
ui->hlButtons->setContentsMargins(9 * screenRatio, 15 * screenRatio, 15 * screenRatio, 17 * screenRatio);
}
else
{
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
setMouseTracking(true);
installEventFilter(this);
2016-03-29 11:22:41 +02:00
}
ProfileInterface::~ProfileInterface()
{
for (ProfileWidget *widget : widgets.keys())
{
2017-10-09 08:35:48 +02:00
widget->removeEventFilter(this);
widget->disconnect();
delete widget;
}
widgets.clear();
for (SavegameData *savegame : savegames)
2016-03-29 11:22:41 +02:00
{
delete savegame;
}
savegames.clear();
for (SnapmaticPicture *picture : 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);
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;
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*)));
2016-04-06 06:38:43 +02: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;
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*)));
2016-04-06 06:38:43 +02: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)));
}
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);
2016-04-06 06:38:43 +02:00
if (widgets.contains(proWidget))
{
QString widgetKey = widgets[proWidget];
QStringList widgetsKeyList = widgets.values();
QStringList pictureKeyList = widgetsKeyList.filter("PIC", Qt::CaseSensitive);
#if QT_VERSION >= 0x050600
2016-04-06 06:38:43 +02:00
qSort(pictureKeyList.rbegin(), pictureKeyList.rend());
2016-04-06 06:48:42 +02:00
#else
qSort(pictureKeyList.begin(), pictureKeyList.end(), qGreater<QString>());
#endif
2016-04-06 06:38:43 +02:00
int picIndex = pictureKeyList.indexOf(QRegExp(widgetKey));
ui->vlSnapmatic->insertWidget(picIndex, proWidget);
2016-04-06 17:38:31 +02:00
qApp->processEvents();
ui->saProfile->ensureWidgetVisible(proWidget, 0, 0);
2016-04-06 06:38:43 +02:00
}
}
void ProfileInterface::insertSavegameIPI(QWidget *widget)
2016-03-29 11:22:41 +02:00
{
2017-10-09 08:35:48 +02:00
ProfileWidget *proWidget = qobject_cast<ProfileWidget*>(widget);
2016-04-06 06:38:43 +02:00
if (widgets.contains(proWidget))
{
QString widgetKey = widgets[proWidget];
QStringList widgetsKeyList = widgets.values();
QStringList savegameKeyList = widgetsKeyList.filter("SGD", Qt::CaseSensitive);
qSort(savegameKeyList.begin(), savegameKeyList.end());
int sgdIndex = savegameKeyList.indexOf(QRegExp(widgetKey));
ui->vlSavegame->insertWidget(sgdIndex, proWidget);
2016-04-06 17:38:31 +02:00
qApp->processEvents();
ui->saProfile->ensureWidgetVisible(proWidget, 0, 0);
2016-04-06 06:38:43 +02:00
}
}
void ProfileInterface::dialogNextPictureRequested(QWidget *dialog)
{
2017-10-09 08:35:48 +02:00
PictureDialog *picDialog = qobject_cast<PictureDialog*>(dialog);
ProfileWidget *proWidget = qobject_cast<ProfileWidget*>(sender());
if (widgets.contains(proWidget))
{
QString widgetKey = widgets[proWidget];
QStringList widgetsKeyList = widgets.values();
QStringList pictureKeyList = widgetsKeyList.filter("PIC", Qt::CaseSensitive);
#if QT_VERSION >= 0x050600
qSort(pictureKeyList.rbegin(), pictureKeyList.rend());
#else
qSort(pictureKeyList.begin(), pictureKeyList.end(), qGreater<QString>());
#endif
int picIndex;
if (picDialog->isIndexed())
{
picIndex = picDialog->getIndex();
}
else
{
picIndex = pictureKeyList.indexOf(QRegExp(widgetKey));
}
picIndex++;
if (pictureKeyList.length() > picIndex)
{
QString newWidgetKey = pictureKeyList.at(picIndex);
SnapmaticWidget *picWidget = (SnapmaticWidget*)widgets.key(newWidgetKey);
2017-01-27 04:33:27 +01:00
//picDialog->setMaximumHeight(QWIDGETSIZE_MAX);
picDialog->setSnapmaticPicture(picWidget->getPicture(), picIndex);
2017-01-27 04:33:27 +01:00
//picDialog->setMaximumHeight(picDialog->height());
}
}
}
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());
if (widgets.contains(proWidget))
{
QString widgetKey = widgets[proWidget];
QStringList widgetsKeyList = widgets.values();
QStringList pictureKeyList = widgetsKeyList.filter("PIC", Qt::CaseSensitive);
#if QT_VERSION >= 0x050600
qSort(pictureKeyList.rbegin(), pictureKeyList.rend());
#else
qSort(pictureKeyList.begin(), pictureKeyList.end(), qGreater<QString>());
#endif
int picIndex;
if (picDialog->isIndexed())
{
picIndex = picDialog->getIndex();
}
else
{
picIndex = pictureKeyList.indexOf(QRegExp(widgetKey));
}
if (picIndex > 0)
{
picIndex--;
QString newWidgetKey = pictureKeyList.at(picIndex );
SnapmaticWidget *picWidget = (SnapmaticWidget*)widgets.key(newWidgetKey);
2017-01-27 04:33:27 +01:00
//picDialog->setMaximumHeight(QWIDGETSIZE_MAX);
picDialog->setSnapmaticPicture(picWidget->getPicture(), picIndex);
2017-01-27 04:33:27 +01:00
//picDialog->setMaximumHeight(picDialog->height());
}
}
}
2016-04-06 06:38:43 +02:00
void ProfileInterface::sortingProfileInterface()
{
ui->vlSavegame->setEnabled(false);
ui->vlSnapmatic->setEnabled(false);
QStringList widgetsKeyList = widgets.values();
qSort(widgetsKeyList.begin(), widgetsKeyList.end());
2016-04-06 06:38:43 +02:00
2017-10-21 05:59:10 +02:00
for (QString widgetKey : widgetsKeyList)
{
ProfileWidget *widget = widgets.key(widgetKey);
if (widget->getWidgetType() == "SnapmaticWidget")
{
ui->vlSnapmatic->insertWidget(0, widget);
}
else if (widget->getWidgetType() == "SavegameWidget")
{
ui->vlSavegame->addWidget(widget);
}
}
2016-04-06 06:38:43 +02:00
ui->vlSavegame->setEnabled(true);
ui->vlSnapmatic->setEnabled(true);
2016-04-06 17:29:08 +02:00
qApp->processEvents();
2016-04-06 06:38:43 +02:00
}
void ProfileInterface::profileLoaded_p()
{
sortingProfileInterface();
2016-03-29 11:22:41 +02:00
saSpacerItem = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
ui->saProfileContent->layout()->addItem(saSpacerItem);
ui->swProfile->setCurrentWidget(ui->pageProfile);
ui->cmdCloseProfile->setEnabled(true);
ui->cmdImport->setEnabled(true);
2017-10-09 08:35:48 +02:00
isProfileLoaded = true;
emit profileLoaded();
if (!fixedPictures.isEmpty())
{
int fixedInt = 0;
QString fixedStr;
for (QString fixedPicture : 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();
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);
if (sgdWidget == previousWidget)
{
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();
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);
if (picWidget == previousWidget)
{
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..."));
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 = " ";
2017-10-21 05:59:10 +02:00
for (QByteArray imageFormat : QImageReader::supportedImageFormats())
2017-10-09 08:35:48 +02:00
{
imageFormatsStr += QString("*.") % QString::fromUtf8(imageFormat).toLower() % " ";
}
QString importableFormatsStr = QString("*.g5e SGTA* PGTA*");
if (!imageFormatsStr.trimmed().isEmpty())
{
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
if (fileDialog.exec())
{
QStringList selectedFiles = fileDialog.selectedFiles();
if (selectedFiles.length() == 1)
{
QString selectedFile = selectedFiles.at(0);
QDateTime importDateTime = QDateTime::currentDateTime();
int currentTime = importDateTime.toString(importTimeFormat).toInt();
if (!importFile(selectedFile, importDateTime, &currentTime, true)) goto fileDialogPreOpen; //Work?
2016-04-13 00:11:20 +02:00
}
else if (selectedFiles.length() > 1)
{
importFilesProgress(selectedFiles);
2016-03-29 11:22:41 +02:00
}
else
{
2016-04-08 19:46:27 +02:00
QMessageBox::warning(this, tr("Import"), tr("No valid file is selected"));
2017-03-01 15:19:40 +01:00
goto fileDialogPreOpen; //Work?
2016-03-29 11:22:41 +02:00
}
}
settings.setValue(profileName % "+Geometry", fileDialog.saveGeometry());
settings.setValue(profileName % "+Directory", fileDialog.directory().absolutePath());
2016-04-24 13:34:03 +02:00
settings.endGroup();
2016-03-29 11:22:41 +02:00
settings.endGroup();
}
void ProfileInterface::importFilesProgress(QStringList selectedFiles)
{
int maximumId = selectedFiles.length();
2017-12-17 13:03:43 +01:00
int overallId = 0;
QString errorStr;
2017-12-17 13:03:43 +01:00
QStringList failed;
// Progress dialog
QProgressDialog pbDialog(this);
pbDialog.setWindowFlags(pbDialog.windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint);
pbDialog.setWindowTitle(tr("Import..."));
2017-12-17 13:03:43 +01:00
pbDialog.setLabelText(tr("Import file %1 of %2 files").arg(QString::number(1), QString::number(maximumId)));
pbDialog.setRange(1, maximumId);
pbDialog.setValue(1);
pbDialog.setModal(true);
QList<QPushButton*> pbBtn = pbDialog.findChildren<QPushButton*>();
pbBtn.at(0)->setDisabled(true);
QList<QProgressBar*> pbBar = pbDialog.findChildren<QProgressBar*>();
pbBar.at(0)->setTextVisible(false);
2017-12-17 13:03:43 +01:00
pbDialog.setAutoClose(false);
pbDialog.show();
2017-12-12 04:45:46 +01:00
// THREADING HERE PLEASE
QDateTime importDateTime = QDateTime::currentDateTime();
int currentTime = importDateTime.time().toString(importTimeFormat).toInt();
2017-10-21 05:59:10 +02:00
for (QString selectedFile : selectedFiles)
{
2017-12-17 13:03:43 +01:00
overallId++;
pbDialog.setValue(overallId);
pbDialog.setLabelText(tr("Import file %1 of %2 files").arg(QString::number(overallId), QString::number(maximumId)));
importDateTime = QDateTime::currentDateTime();
if (!importFile(selectedFile, importDateTime, &currentTime, false))
{
2017-12-17 13:03:43 +01:00
failed << QFileInfo(selectedFile).fileName();
}
}
2017-12-12 04:45:46 +01:00
pbDialog.close();
2017-12-17 13:03:43 +01:00
for (QString curErrorStr : failed)
{
errorStr += ", " % curErrorStr;
}
if (errorStr != "")
{
errorStr.remove(0, 2);
QMessageBox::warning(this, tr("Import"), tr("Import failed with...\n\n%1").arg(errorStr));
}
}
bool ProfileInterface::importFile(QString selectedFile, QDateTime importDateTime, int *currentTime, bool notMultiple)
2016-04-13 00:11:20 +02:00
{
QString selectedFileName = QFileInfo(selectedFile).fileName();
if (QFile::exists(selectedFile))
{
2017-01-27 04:33:27 +01:00
if (selectedFileName.left(4) == "PGTA" || selectedFileName.right(4) == ".g5e")
2016-04-13 00:11:20 +02:00
{
SnapmaticPicture *picture = new SnapmaticPicture(selectedFile);
2017-06-05 18:16:17 +02:00
if (picture->readingPicture(true, true, true))
2016-04-13 00:11:20 +02:00
{
2017-02-11 04:21:55 +01:00
bool success = importSnapmaticPicture(picture, notMultiple);
2016-04-13 00:32:14 +02:00
if (!success) delete picture;
return success;
2016-04-13 00:11:20 +02:00
}
else
{
2017-02-11 04:21:55 +01:00
if (notMultiple) QMessageBox::warning(this, tr("Import"), tr("Failed to read Snapmatic picture"));
2016-04-13 00:11:20 +02:00
delete picture;
return false;
}
}
else if (selectedFileName.left(4) == "SGTA")
{
SavegameData *savegame = new SavegameData(selectedFile);
if (savegame->readingSavegame())
{
2017-02-11 04:21:55 +01:00
bool success = importSavegameData(savegame, selectedFile, notMultiple);
2016-04-13 00:32:14 +02:00
if (!success) delete savegame;
return success;
2016-04-13 00:11:20 +02:00
}
else
{
2017-02-11 04:21:55 +01:00
if (notMultiple) QMessageBox::warning(this, tr("Import"), tr("Failed to read Savegame file"));
2016-04-13 00:11:20 +02:00
delete savegame;
return false;
}
}
2017-10-09 08:35:48 +02:00
else if(isSupportedImageFile(selectedFileName))
2017-02-11 04:21:55 +01:00
{
SnapmaticPicture *picture = new SnapmaticPicture(":/template/template.g5e");
2017-06-05 18:16:17 +02:00
if (picture->readingPicture(true, false, true, false))
2017-02-11 04:21:55 +01:00
{
if (!notMultiple)
{
QFile snapmaticFile(selectedFile);
if (!snapmaticFile.open(QFile::ReadOnly))
{
delete picture;
return false;
}
2017-02-11 04:21:55 +01:00
QImage snapmaticImage;
QImageReader snapmaticImageReader;
snapmaticImageReader.setDecideFormatFromContent(true);
snapmaticImageReader.setDevice(&snapmaticFile);
if (!snapmaticImageReader.read(&snapmaticImage))
2017-02-11 04:21:55 +01:00
{
delete picture;
return false;
}
QString customImageTitle;
QPixmap snapmaticPixmap(960, 536);
snapmaticPixmap.fill(Qt::black);
QPainter snapmaticPainter(&snapmaticPixmap);
2017-02-11 04:21:55 +01:00
if (snapmaticImage.height() == snapmaticImage.width())
{
// Avatar mode
int diffWidth = 0;
int diffHeight = 0;
snapmaticImage = snapmaticImage.scaled(470, 470, Qt::KeepAspectRatio, Qt::SmoothTransformation);
if (snapmaticImage.width() > snapmaticImage.height())
{
diffHeight = 470 - snapmaticImage.height();
diffHeight = diffHeight / 2;
}
else if (snapmaticImage.width() < snapmaticImage.height())
{
diffWidth = 470 - snapmaticImage.width();
diffWidth = diffWidth / 2;
}
snapmaticPainter.drawImage(145 + diffWidth, 66 + diffHeight, snapmaticImage);
customImageTitle = ImportDialog::tr("Custom Avatar", "Custom Avatar Description in SC, don't use Special Character!");
2017-02-11 04:21:55 +01:00
}
else
{
// Picture mode
int diffWidth = 0;
int diffHeight = 0;
snapmaticImage = snapmaticImage.scaled(960, 536, Qt::KeepAspectRatio, Qt::SmoothTransformation);
if (snapmaticImage.width() != 960)
{
diffWidth = 960 - snapmaticImage.width();
diffWidth = diffWidth / 2;
}
else if (snapmaticImage.height() != 536)
{
diffHeight = 536 - snapmaticImage.height();
diffHeight = diffHeight / 2;
}
snapmaticPainter.drawImage(0 + diffWidth, 0 + diffHeight, snapmaticImage);
customImageTitle = ImportDialog::tr("Custom Picture", "Custom Picture Description in SC, don't use Special Character!");
2017-02-11 04:21:55 +01:00
}
snapmaticPainter.end();
if (!picture->setImage(snapmaticPixmap.toImage()))
{
delete picture;
return false;
}
SnapmaticProperties spJson = picture->getSnapmaticProperties();
spJson.uid = QString(QString::number(*currentTime) %
QString::number(importDateTime.date().dayOfYear())).toInt();
2017-10-12 22:21:45 +02:00
bool fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid));
bool fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden");
int cEnough = 0;
while ((fExists || fExistsHidden) && cEnough < findRetryLimit)
{
*currentTime = *currentTime - 1;
spJson.uid = QString(QString::number(*currentTime) %
QString::number(importDateTime.date().dayOfYear())).toInt();
2017-10-12 22:21:45 +02:00
fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid));
fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden");
cEnough++;
}
spJson.createdDateTime = importDateTime;
2017-02-11 04:21:55 +01:00
spJson.createdTimestamp = spJson.createdDateTime.toTime_t();
picture->setSnapmaticProperties(spJson);
picture->setPicFileName(QString("PGTA5%1").arg(QString::number(spJson.uid)));
picture->setPictureTitle(customImageTitle);
picture->updateStrings();
bool success = importSnapmaticPicture(picture, notMultiple);
if (!success) delete picture;
return success;
}
else
{
bool success = false;
QFile snapmaticFile(selectedFile);
if (!snapmaticFile.open(QFile::ReadOnly))
{
2017-12-17 13:03:43 +01:00
QMessageBox::warning(this, tr("Import"), tr("Can't import %1 because file can't be open").arg("\""+selectedFileName+"\""));
delete picture;
return false;
}
QImage *importImage = new QImage();
QImageReader snapmaticImageReader;
snapmaticImageReader.setDecideFormatFromContent(true);
snapmaticImageReader.setDevice(&snapmaticFile);
if (!snapmaticImageReader.read(importImage))
2017-02-11 04:21:55 +01:00
{
2017-10-09 08:35:48 +02:00
QMessageBox::warning(this, tr("Import"), tr("Can't import %1 because file can't be parsed properly").arg("\""+selectedFileName+"\""));
2017-12-17 13:03:43 +01:00
delete importImage;
2017-02-11 04:21:55 +01:00
delete picture;
return false;
}
ImportDialog *importDialog = new ImportDialog(this);
importDialog->setImage(importImage);
2017-02-11 04:21:55 +01:00
importDialog->setModal(true);
importDialog->show();
importDialog->exec();
2017-10-09 08:35:48 +02:00
if (importDialog->isImportAgreed())
2017-02-11 04:21:55 +01:00
{
if (picture->setImage(importDialog->image()))
{
SnapmaticProperties spJson = picture->getSnapmaticProperties();
spJson.uid = QString(QString::number(*currentTime) %
QString::number(importDateTime.date().dayOfYear())).toInt();
2017-10-12 22:21:45 +02:00
bool fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid));
bool fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden");
int cEnough = 0;
while ((fExists || fExistsHidden) && cEnough < findRetryLimit)
{
*currentTime = *currentTime - 1;
spJson.uid = QString(QString::number(*currentTime) %
QString::number(importDateTime.date().dayOfYear())).toInt();
2017-10-12 22:21:45 +02:00
fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid));
fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden");
cEnough++;
}
spJson.createdDateTime = importDateTime;
2017-02-11 04:21:55 +01:00
spJson.createdTimestamp = spJson.createdDateTime.toTime_t();
picture->setSnapmaticProperties(spJson);
picture->setPicFileName(QString("PGTA5%1").arg(QString::number(spJson.uid)));
picture->setPictureTitle(importDialog->getImageTitle());
picture->updateStrings();
success = importSnapmaticPicture(picture, notMultiple);
}
}
else
{
delete picture;
success = true;
}
delete importDialog;
if (!success) delete picture;
return success;
}
}
else
{
delete picture;
return false;
}
}
2016-04-13 00:11:20 +02:00
else
{
SnapmaticPicture *picture = new SnapmaticPicture(selectedFile);
SavegameData *savegame = new SavegameData(selectedFile);
if (picture->readingPicture())
{
2017-02-11 04:21:55 +01:00
bool success = importSnapmaticPicture(picture, notMultiple);
2016-04-13 00:11:20 +02:00
delete savegame;
2016-04-13 00:32:14 +02:00
if (!success) delete picture;
return success;
2016-04-13 00:11:20 +02:00
}
else if (savegame->readingSavegame())
{
2017-02-11 04:21:55 +01:00
bool success = importSavegameData(savegame, selectedFile, notMultiple);
2016-04-13 00:11:20 +02:00
delete picture;
2016-04-13 00:32:14 +02:00
if (!success) delete savegame;
return success;
2016-04-13 00:11:20 +02:00
}
else
{
2017-10-09 08:35:48 +02:00
#ifdef GTA5SYNC_DEBUG
qDebug() << "ImportError SnapmaticPicture" << picture->getLastStep();
qDebug() << "ImportError SavegameData" << savegame->getLastStep();
#endif
2016-04-13 00:11:20 +02:00
delete picture;
2017-10-09 08:35:48 +02:00
delete savegame;
if (notMultiple) QMessageBox::warning(this, tr("Import"), tr("Can't import %1 because file format can't be detected").arg("\""+selectedFileName+"\""));
2016-04-13 00:11:20 +02:00
return false;
}
}
}
2017-02-11 04:21:55 +01:00
if (notMultiple) QMessageBox::warning(this, tr("Import"), tr("No valid file is selected"));
2016-04-13 00:11:20 +02:00
return false;
}
2017-02-11 04:21:55 +01:00
bool ProfileInterface::importSnapmaticPicture(SnapmaticPicture *picture, bool warn)
2016-03-29 11:22:41 +02:00
{
2017-02-11 04:21:55 +01:00
QString picFileName = picture->getPictureFileName();
qDebug() << picFileName;
2017-10-12 22:21:45 +02:00
QString adjustedFileName = picture->getOriginalPictureFileName();
2017-02-11 04:21:55 +01:00
if (picFileName.left(4) != "PGTA")
2016-03-29 11:22:41 +02:00
{
2017-01-27 04:33:27 +01:00
if (warn) QMessageBox::warning(this, tr("Import"), tr("Failed to import the Snapmatic picture, file not begin with PGTA or end with .g5e"));
2016-03-29 11:22:41 +02:00
return false;
}
2017-10-12 22:21:45 +02:00
else if (QFile::exists(profileFolder % "/" % adjustedFileName) || QFile::exists(profileFolder % "/" % adjustedFileName % ".hidden"))
{
if (warn) QMessageBox::warning(this, tr("Import"), tr("Failed to import the Snapmatic picture, the picture is already in the game"));
return false;
}
2017-10-12 22:21:45 +02:00
else if (picture->exportPicture(profileFolder % "/" % adjustedFileName, SnapmaticFormat::PGTA_Format))
2016-03-29 11:22:41 +02:00
{
picture->setSnapmaticFormat(SnapmaticFormat::PGTA_Format);
2017-10-12 22:21:45 +02:00
picture->setPicFilePath(profileFolder % "/" % adjustedFileName);
2017-02-11 04:21:55 +01:00
pictureLoaded(picture, true);
2016-03-29 11:22:41 +02:00
return true;
}
else
{
2016-04-13 00:11:20 +02:00
if (warn) QMessageBox::warning(this, tr("Import"), tr("Failed to import the Snapmatic picture, can't copy the file into profile"));
2016-03-29 11:22:41 +02:00
return false;
}
}
2016-04-13 00:11:20 +02:00
bool ProfileInterface::importSavegameData(SavegameData *savegame, QString sgdPath, bool warn)
2016-03-29 11:22:41 +02:00
{
QString sgdFileName;
bool foundFree = 0;
int currentSgd = 0;
while (currentSgd < 15 && !foundFree)
{
QString sgdNumber = QString::number(currentSgd);
if (sgdNumber.length() == 1)
{
sgdNumber.insert(0, "0");
}
sgdFileName = "SGTA500" % sgdNumber;
2016-03-29 11:22:41 +02:00
2017-10-12 22:21:45 +02:00
if (!QFile::exists(profileFolder % "/" % sgdFileName))
2016-03-29 11:22:41 +02:00
{
foundFree = true;
}
currentSgd++;
}
if (foundFree)
{
2017-10-12 22:21:45 +02:00
if (QFile::copy(sgdPath, profileFolder % "/" % sgdFileName))
2016-03-29 11:22:41 +02:00
{
2017-10-12 22:21:45 +02:00
savegame->setSavegameFileName(profileFolder % "/" % sgdFileName);
savegameLoaded(savegame, profileFolder % "/" % sgdFileName, true);
2016-03-29 11:22:41 +02:00
return true;
}
else
{
2016-04-13 00:11:20 +02:00
if (warn) QMessageBox::warning(this, tr("Import"), tr("Failed to import the Savegame, can't copy the file into profile"));
2016-03-29 11:22:41 +02:00
return false;
}
}
else
{
2016-04-13 00:11:20 +02:00
if (warn) QMessageBox::warning(this, tr("Import"), tr("Failed to import the Savegame, no Savegame slot is left"));
2016-03-29 11:22:41 +02:00
return false;
}
}
2016-04-03 01:18:48 +02:00
void ProfileInterface::profileWidgetSelected()
2016-04-03 01:18:48 +02:00
{
if (selectedWidgts == 0)
{
for (ProfileWidget *widget : widgets.keys())
2016-04-03 01:18:48 +02:00
{
widget->setSelectionMode(true);
}
}
selectedWidgts++;
}
void ProfileInterface::profileWidgetDeselected()
2016-04-03 01:18:48 +02:00
{
if (selectedWidgts == 1)
{
2016-04-03 01:43:04 +02:00
int scrollBarValue = ui->saProfile->verticalScrollBar()->value();
for (ProfileWidget *widget : widgets.keys())
2016-04-03 01:18:48 +02:00
{
if (contentMode != 2)
{
widget->setSelectionMode(false);
}
2016-04-03 01:18:48 +02:00
}
2016-04-03 01:43:04 +02:00
ui->saProfile->verticalScrollBar()->setValue(scrollBarValue);
2016-04-03 01:18:48 +02:00
}
selectedWidgts--;
}
void ProfileInterface::selectAllWidgets()
{
for (ProfileWidget *widget : widgets.keys())
{
widget->setSelected(true);
}
}
void ProfileInterface::deselectAllWidgets()
{
for (ProfileWidget *widget : widgets.keys())
{
widget->setSelected(false);
}
}
2016-04-03 10:17:01 +02:00
void ProfileInterface::exportSelected()
{
2016-04-08 19:46:27 +02:00
if (selectedWidgts != 0)
2016-04-03 10:17:01 +02:00
{
2016-04-08 19:46:27 +02:00
int exportCount = 0;
int exportPictures = 0;
int exportSavegames = 0;
bool pictureCopyEnabled = false;
bool pictureExportEnabled = false;
2016-04-24 13:34:03 +02:00
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("FileDialogs");
2017-10-12 22:21:45 +02:00
//bool dontUseNativeDialog = settings.value("DontUseNativeDialog", false).toBool();
2016-04-24 13:34:03 +02:00
settings.beginGroup("ExportDirectory");
2017-12-17 13:03:43 +01:00
QString exportDirectory = QFileDialog::getExistingDirectory(this, tr("Export selected..."), settings.value(profileName, profileFolder).toString());
2016-04-08 19:46:27 +02:00
if (exportDirectory != "")
2016-04-03 10:17:01 +02:00
{
2016-04-24 13:34:03 +02:00
settings.setValue(profileName, exportDirectory);
for (ProfileWidget *widget : widgets.keys())
2016-04-03 10:17:01 +02:00
{
2016-04-08 19:46:27 +02:00
if (widget->isSelected())
2016-04-03 10:17:01 +02:00
{
2016-04-08 19:46:27 +02:00
if (widget->getWidgetType() == "SnapmaticWidget")
{
exportPictures++;
}
else if (widget->getWidgetType() == "SavegameWidget")
{
exportSavegames++;
}
2016-04-03 10:17:01 +02:00
}
2016-04-03 12:27:40 +02:00
}
2016-04-03 10:17:01 +02:00
2016-04-08 19:46:27 +02:00
if (exportPictures != 0)
2016-04-03 12:27:40 +02:00
{
2016-04-08 19:46:27 +02:00
QInputDialog inputDialog;
QStringList inputDialogItems;
inputDialogItems << tr("JPG pictures and GTA Snapmatic");
inputDialogItems << tr("JPG pictures only");
inputDialogItems << tr("GTA Snapmatic only");
QString ExportPreSpan;
QString ExportPostSpan;
#ifdef GTA5SYNC_WIN
ExportPreSpan = "<span style=\"color: #003399; font-size: 12pt\">";
ExportPostSpan = "</span>";
#else
ExportPreSpan = "<span style=\"font-weight: bold\">";
ExportPostSpan = "</span>";
#endif
2016-04-08 19:46:27 +02:00
bool itemSelected = false;
2017-12-17 13:03:43 +01:00
QString selectedItem = inputDialog.getItem(this, tr("Export selected..."), tr("%1Export Snapmatic pictures%2<br><br>JPG pictures make it possible to open the picture with a Image Viewer<br>GTA Snapmatic make it possible to import the picture into the game<br><br>Export as:").arg(ExportPreSpan, ExportPostSpan), inputDialogItems, 0, false, &itemSelected, inputDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
2016-04-08 19:46:27 +02:00
if (itemSelected)
2016-04-03 10:17:01 +02:00
{
2016-04-08 19:46:27 +02:00
if (selectedItem == tr("JPG pictures and GTA Snapmatic"))
{
pictureExportEnabled = true;
pictureCopyEnabled = true;
}
else if (selectedItem == tr("JPG pictures only"))
{
pictureExportEnabled = true;
}
else if (selectedItem == tr("GTA Snapmatic only"))
{
pictureCopyEnabled = true;
}
else
{
pictureExportEnabled = true;
pictureCopyEnabled = true;
}
2016-04-03 10:17:01 +02:00
}
2016-04-08 19:46:27 +02:00
else
2016-04-03 10:17:01 +02:00
{
2017-10-09 08:35:48 +02:00
// Don't export anymore when any Cancel button got clicked
settings.endGroup();
settings.endGroup();
return;
2016-04-03 10:17:01 +02:00
}
}
2016-04-08 19:46:27 +02:00
// Counting the exports together
exportCount = exportCount + exportSavegames;
if (pictureExportEnabled && pictureCopyEnabled)
{
int exportPictures2 = exportPictures * 2;
exportCount = exportCount + exportPictures2;
}
2016-04-03 12:27:40 +02:00
else
{
2016-04-08 19:46:27 +02:00
exportCount = exportCount + exportPictures;
2016-04-03 12:27:40 +02:00
}
2016-04-08 19:46:27 +02:00
QProgressDialog pbDialog(this);
pbDialog.setWindowFlags(pbDialog.windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint);
pbDialog.setWindowTitle(tr("Export selected..."));
2017-10-09 08:35:48 +02:00
pbDialog.setLabelText(tr("Initialising export..."));
2016-04-08 19:46:27 +02:00
pbDialog.setRange(0, exportCount);
2016-04-05 04:08:14 +02:00
2016-04-08 19:46:27 +02:00
QList<QPushButton*> pbBtn = pbDialog.findChildren<QPushButton*>();
pbBtn.at(0)->setDisabled(true);
2016-04-03 12:27:40 +02:00
2016-04-08 19:46:27 +02:00
QList<QProgressBar*> pbBar = pbDialog.findChildren<QProgressBar*>();
pbBar.at(0)->setTextVisible(false);
2016-04-03 12:27:40 +02:00
2016-04-08 19:46:27 +02:00
ExportThread *exportThread = new ExportThread(widgets, exportDirectory, pictureCopyEnabled, pictureExportEnabled, exportCount);
QObject::connect(exportThread, SIGNAL(exportStringUpdate(QString)), &pbDialog, SLOT(setLabelText(QString)));
QObject::connect(exportThread, SIGNAL(exportProgressUpdate(int)), &pbDialog, SLOT(setValue(int)));
QObject::connect(exportThread, SIGNAL(exportFinished()), &pbDialog, SLOT(close()));
exportThread->start();
2016-04-03 12:27:40 +02:00
2017-12-17 13:03:43 +01:00
pbDialog.setAutoClose(false);
2016-04-08 19:46:27 +02:00
pbDialog.exec();
QStringList getFailedSavegames = exportThread->getFailedSavegames();
QStringList getFailedCopyPictures = exportThread->getFailedCopyPictures();
QStringList getFailedExportPictures = exportThread->getFailedExportPictures();
2016-04-03 12:27:40 +02:00
2016-04-08 19:46:27 +02:00
QString errorStr;
QStringList errorList;
errorList << getFailedExportPictures;
errorList << getFailedCopyPictures;
errorList << getFailedSavegames;
2016-04-03 12:27:40 +02:00
2017-10-21 05:59:10 +02:00
for (QString curErrorStr : errorList)
2016-04-08 19:46:27 +02:00
{
errorStr += ", " % curErrorStr;
2016-04-08 19:46:27 +02:00
}
if (errorStr != "")
{
errorStr.remove(0, 2);
QMessageBox::warning(this, tr("Export selected..."), tr("Export failed with...\n\n%1").arg(errorStr));
2016-04-08 19:46:27 +02:00
}
2016-04-03 12:27:40 +02:00
2016-04-08 19:46:27 +02:00
if (exportThread->isFinished())
{
delete exportThread;
}
else
{
QEventLoop threadFinishLoop;
QObject::connect(exportThread, SIGNAL(finished()), &threadFinishLoop, SLOT(quit()));
threadFinishLoop.exec();
delete exportThread;
}
2016-04-03 10:17:01 +02:00
}
2016-04-24 13:34:03 +02:00
settings.endGroup();
settings.endGroup();
2016-04-03 10:17:01 +02:00
}
2016-04-08 19:46:27 +02:00
else
{
QMessageBox::information(this, tr("Export selected..."), tr("No Snapmatic pictures or Savegames files are selected"));
2016-04-08 19:46:27 +02:00
}
2016-04-03 10:17:01 +02:00
}
void ProfileInterface::deleteSelected()
{
2016-04-08 19:46:27 +02:00
if (selectedWidgts != 0)
{
2016-04-08 19:46:27 +02:00
if (QMessageBox::Yes == QMessageBox::warning(this, tr("Remove selected"), tr("You really want remove the selected Snapmatic picutres and Savegame files?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No))
{
for (ProfileWidget *widget : widgets.keys())
{
2016-04-08 19:46:27 +02:00
if (widget->isSelected())
{
2016-04-08 19:46:27 +02:00
if (widget->getWidgetType() == "SnapmaticWidget")
{
2017-10-09 08:35:48 +02:00
SnapmaticWidget *picWidget = qobject_cast<SnapmaticWidget*>(widget);
2017-03-01 15:19:40 +01:00
if (picWidget->getPicture()->deletePicFile())
2016-04-08 19:46:27 +02:00
{
2017-02-11 04:21:55 +01:00
pictureDeleted(picWidget);
2016-04-08 19:46:27 +02:00
}
}
2016-04-08 19:46:27 +02:00
else if (widget->getWidgetType() == "SavegameWidget")
{
2017-10-09 08:35:48 +02:00
SavegameWidget *sgdWidget = qobject_cast<SavegameWidget*>(widget);
2016-04-08 19:46:27 +02:00
SavegameData *savegame = sgdWidget->getSavegame();
QString fileName = savegame->getSavegameFileName();
if (!QFile::exists(fileName) || QFile::remove(fileName))
{
2017-02-11 04:21:55 +01:00
savegameDeleted(sgdWidget);
2016-04-08 19:46:27 +02:00
}
}
}
}
2016-04-08 19:46:27 +02:00
if (selectedWidgts != 0)
{
2018-01-17 00:59:40 +01:00
QMessageBox::warning(this, tr("Remove selected"), tr("Failed to remove all selected Snapmatic pictures and/or Savegame files"));
2016-04-08 19:46:27 +02:00
}
}
2016-04-08 19:46:27 +02:00
}
else
{
QMessageBox::information(this, tr("Remove selected"), tr("No Snapmatic pictures or Savegames files are selected"));
}
2016-04-03 10:17:01 +02:00
}
2016-04-13 00:47:07 +02:00
void ProfileInterface::importFiles()
{
on_cmdImport_clicked();
}
2017-10-12 22:21:45 +02:00
void ProfileInterface::settingsApplied(int _contentMode, bool languageChanged)
{
2017-10-12 22:21:45 +02:00
if (languageChanged) retranslateUi();
contentMode = _contentMode;
if (contentMode == 2)
{
for (ProfileWidget *widget : widgets.keys())
{
widget->setSelectionMode(true);
widget->setContentMode(contentMode);
2017-10-12 22:21:45 +02:00
if (languageChanged) widget->retranslate();
}
}
else
{
for (ProfileWidget *widget : widgets.keys())
{
if (selectedWidgts == 0)
{
widget->setSelectionMode(false);
}
widget->setContentMode(contentMode);
2017-10-12 22:21:45 +02:00
if (languageChanged) widget->retranslate();
}
}
2017-12-12 04:45:46 +01:00
#ifdef Q_OS_MAC
// DPI calculation
qreal screenRatio = AppEnv::screenRatio();
if (QApplication::style()->objectName() == "macintosh")
{
ui->hlButtons->setSpacing(6 * screenRatio);
ui->hlButtons->setContentsMargins(9 * screenRatio, 15 * screenRatio, 15 * screenRatio, 17 * screenRatio);
}
else
{
ui->hlButtons->setSpacing(6 * screenRatio);
ui->hlButtons->setContentsMargins(9 * screenRatio, 9 * screenRatio, 9 * screenRatio, 9 * screenRatio);
}
#endif
}
void ProfileInterface::enableSelected()
{
QList<SnapmaticWidget*> snapmaticWidgets;
for (ProfileWidget *widget : widgets.keys())
{
if (widget->isSelected())
{
if (widget->getWidgetType() == "SnapmaticWidget")
{
2017-10-09 08:35:48 +02:00
SnapmaticWidget *snapmaticWidget = qobject_cast<SnapmaticWidget*>(widget);
snapmaticWidgets += snapmaticWidget;
}
}
}
if (snapmaticWidgets.isEmpty())
{
QMessageBox::information(this, QApplication::translate("UserInterface", "Show In-game"), QApplication::translate("ProfileInterface", "No Snapmatic pictures are selected"));
return;
}
QStringList fails;
for (SnapmaticWidget *widget : snapmaticWidgets)
{
SnapmaticPicture *picture = widget->getPicture();
if (!widget->makePictureVisible())
{
fails << QString("%1 [%2]").arg(picture->getPictureTitle(), picture->getPictureString());
}
}
if (!fails.isEmpty())
{
QMessageBox::warning(this, QApplication::translate("UserInterface", "Show In-game"), QApplication::translate("ProfileInterface", "%1 failed with...\n\n%2", "Action failed with...").arg(QApplication::translate("UserInterface", "Show In-game"), fails.join(", ")));
}
}
void ProfileInterface::disableSelected()
{
QList<SnapmaticWidget*> snapmaticWidgets;
for (ProfileWidget *widget : widgets.keys())
{
if (widget->isSelected())
{
if (widget->getWidgetType() == "SnapmaticWidget")
{
2017-10-09 08:35:48 +02:00
SnapmaticWidget *snapmaticWidget = qobject_cast<SnapmaticWidget*>(widget);
snapmaticWidgets += snapmaticWidget;
}
}
}
if (snapmaticWidgets.isEmpty())
{
QMessageBox::information(this, QApplication::translate("UserInterface", "Hide In-game"), QApplication::translate("ProfileInterface", "No Snapmatic pictures are selected"));
return;
}
QStringList fails;
for (SnapmaticWidget *widget : snapmaticWidgets)
{
SnapmaticPicture *picture = widget->getPicture();
if (!widget->makePictureHidden())
{
fails << QString("%1 [%2]").arg(picture->getPictureTitle(), picture->getPictureString());
}
}
if (!fails.isEmpty())
{
QMessageBox::warning(this, QApplication::translate("UserInterface", "Hide In-game"), QApplication::translate("ProfileInterface", "%1 failed with...\n\n%2", "Action failed with...").arg(QApplication::translate("UserInterface", "Hide In-game"), fails.join(", ")));
}
}
int ProfileInterface::selectedWidgets()
{
return selectedWidgts;
}
2017-02-13 04:12:47 +01:00
void ProfileInterface::contextMenuTriggeredPIC(QContextMenuEvent *ev)
{
2017-10-09 08:35:48 +02:00
SnapmaticWidget *picWidget = qobject_cast<SnapmaticWidget*>(sender());
if (picWidget != previousWidget)
{
if (previousWidget != nullptr)
{
previousWidget->setStyleSheet(QLatin1String(""));
}
picWidget->setStyleSheet(QString("QFrame#SnapmaticFrame{background-color: rgb(%1, %2, %3)}QLabel#labPicStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
previousWidget = picWidget;
}
2017-02-13 04:12:47 +01:00
QMenu contextMenu(picWidget);
QMenu editMenu(SnapmaticWidget::tr("Edi&t"), picWidget);
2017-02-25 06:30:37 +01:00
if (picWidget->isHidden())
2017-02-13 04:12:47 +01:00
{
editMenu.addAction(SnapmaticWidget::tr("Show &In-game"), picWidget, SLOT(makePictureVisibleSlot()));
}
else
{
editMenu.addAction(SnapmaticWidget::tr("Hide &In-game"), picWidget, SLOT(makePictureHiddenSlot()));
}
2017-10-12 22:21:45 +02:00
editMenu.addAction(PictureDialog::tr("&Edit Properties..."), picWidget, SLOT(editSnapmaticProperties()));
2017-12-17 13:03:43 +01:00
editMenu.addAction(PictureDialog::tr("&Overwrite Image..."), picWidget, SLOT(editSnapmaticImage()));
editMenu.addSeparator();
editMenu.addAction(PictureDialog::tr("Open &Map Viewer..."), picWidget, SLOT(openMapViewer()));
editMenu.addAction(PictureDialog::tr("Open &JSON Editor..."), picWidget, SLOT(editSnapmaticRawJson()));
2017-02-13 04:12:47 +01:00
QMenu exportMenu(SnapmaticWidget::tr("&Export"), this);
2017-10-12 22:21:45 +02:00
exportMenu.addAction(PictureDialog::tr("Export as &Picture..."), picWidget, SLOT(on_cmdExport_clicked()));
exportMenu.addAction(PictureDialog::tr("Export as &Snapmatic..."), picWidget, SLOT(on_cmdCopy_clicked()));
2017-02-13 04:12:47 +01:00
contextMenu.addAction(SnapmaticWidget::tr("&View"), picWidget, SLOT(on_cmdView_clicked()));
contextMenu.addMenu(&editMenu);
contextMenu.addMenu(&exportMenu);
contextMenu.addAction(SnapmaticWidget::tr("&Remove"), picWidget, SLOT(on_cmdDelete_clicked()));
contextMenu.addSeparator();
if (!picWidget->isSelected()) { contextMenu.addAction(SnapmaticWidget::tr("&Select"), picWidget, SLOT(pictureSelected())); }
if (picWidget->isSelected()) { contextMenu.addAction(SnapmaticWidget::tr("&Deselect"), picWidget, SLOT(pictureSelected())); }
if (selectedWidgets() != widgets.count())
2017-02-13 04:12:47 +01:00
{
contextMenu.addAction(SnapmaticWidget::tr("Select &All"), picWidget, SLOT(selectAllWidgets()), QKeySequence::fromString("Ctrl+A"));
}
if (selectedWidgets() != 0)
2017-02-13 04:12:47 +01:00
{
contextMenu.addAction(SnapmaticWidget::tr("&Deselect All"), picWidget, SLOT(deselectAllWidgets()), QKeySequence::fromString("Ctrl+D"));
2017-02-13 04:12:47 +01:00
}
2017-10-09 08:35:48 +02:00
contextMenuOpened = true;
2017-02-13 04:12:47 +01:00
contextMenu.exec(ev->globalPos());
2017-10-09 08:35:48 +02:00
contextMenuOpened = false;
hoverProfileWidgetCheck();
2017-02-13 04:12:47 +01:00
}
void ProfileInterface::contextMenuTriggeredSGD(QContextMenuEvent *ev)
{
2017-10-09 08:35:48 +02:00
SavegameWidget *sgdWidget = qobject_cast<SavegameWidget*>(sender());
if (sgdWidget != previousWidget)
{
if (previousWidget != nullptr)
{
previousWidget->setStyleSheet(QLatin1String(""));
}
sgdWidget->setStyleSheet(QString("QFrame#SavegameFrame{background-color: rgb(%1, %2, %3)}QLabel#labSavegameStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
previousWidget = sgdWidget;
}
2017-02-13 04:12:47 +01:00
QMenu contextMenu(sgdWidget);
contextMenu.addAction(SavegameWidget::tr("&View"), sgdWidget, SLOT(on_cmdView_clicked()));
contextMenu.addAction(SavegameWidget::tr("&Export"), sgdWidget, SLOT(on_cmdCopy_clicked()));
contextMenu.addAction(SavegameWidget::tr("&Remove"), sgdWidget, SLOT(on_cmdDelete_clicked()));
contextMenu.addSeparator();
if (!sgdWidget->isSelected()) { contextMenu.addAction(SavegameWidget::tr("&Select"), sgdWidget, SLOT(savegameSelected())); }
if (sgdWidget->isSelected()) { contextMenu.addAction(SavegameWidget::tr("&Deselect"), sgdWidget, SLOT(savegameSelected())); }
if (selectedWidgets() != widgets.count())
2017-02-13 04:12:47 +01:00
{
contextMenu.addAction(SavegameWidget::tr("Select &All"), sgdWidget, SLOT(selectAllWidgets()), QKeySequence::fromString("Ctrl+A"));
}
if (selectedWidgets() != 0)
{
contextMenu.addAction(SavegameWidget::tr("&Deselect All"), sgdWidget, SLOT(deselectAllWidgets()), QKeySequence::fromString("Ctrl+D"));
}
2017-10-09 08:35:48 +02:00
contextMenuOpened = true;
contextMenu.exec(ev->globalPos());
2017-10-09 08:35:48 +02:00
contextMenuOpened = false;
hoverProfileWidgetCheck();
}
void ProfileInterface::on_saProfileContent_dropped(const QMimeData *mimeData)
{
if (!mimeData) return;
QStringList pathList;
2017-10-21 05:59:10 +02:00
for (QUrl currentUrl : mimeData->urls())
{
if (currentUrl.isLocalFile())
2017-02-13 04:12:47 +01:00
{
pathList += currentUrl.toLocalFile();
2017-02-13 04:12:47 +01:00
}
}
if (pathList.length() == 1)
2017-02-13 04:12:47 +01:00
{
QString selectedFile = pathList.at(0);
QDateTime importDateTime = QDateTime::currentDateTime();
int currentTime = importDateTime.toString(importTimeFormat).toInt();
importFile(selectedFile, QDateTime::currentDateTime(), &currentTime, true);
}
else if (pathList.length() > 1)
{
importFilesProgress(pathList);
2017-02-13 04:12:47 +01:00
}
}
2017-10-09 08:35:48 +02:00
void ProfileInterface::retranslateUi()
{
ui->retranslateUi(this);
ui->labVersion->setText(QString("%1 %2").arg(GTA5SYNC_APPSTR, GTA5SYNC_APPVER));
}
bool ProfileInterface::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::MouseMove)
{
if ((watched->objectName() == "SavegameWidget" || watched->objectName() == "SnapmaticWidget") && isProfileLoaded)
{
ProfileWidget *pWidget = qobject_cast<ProfileWidget*>(watched);
if (pWidget->underMouse())
{
bool styleSheetChanged = false;
if (pWidget->getWidgetType() == "SnapmaticWidget")
{
if (pWidget != previousWidget)
{
pWidget->setStyleSheet(QString("QFrame#SnapmaticFrame{background-color: rgb(%1, %2, %3)}QLabel#labPicStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
styleSheetChanged = true;
}
}
else if (pWidget->getWidgetType() == "SavegameWidget")
{
if (pWidget != previousWidget)
{
pWidget->setStyleSheet(QString("QFrame#SavegameFrame{background-color: rgb(%1, %2, %3)}QLabel#labSavegameStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
styleSheetChanged = true;
}
}
if (styleSheetChanged)
{
if (previousWidget != nullptr)
{
previousWidget->setStyleSheet(QLatin1String(""));
}
previousWidget = pWidget;
}
}
return true;
}
}
else if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::WindowActivate)
{
if ((watched->objectName() == "SavegameWidget" || watched->objectName() == "SnapmaticWidget") && isProfileLoaded)
{
ProfileWidget *pWidget = nullptr;
for (ProfileWidget *widget : widgets.keys())
2017-10-09 08:35:48 +02:00
{
QPoint mousePos = widget->mapFromGlobal(QCursor::pos());
if (widget->rect().contains(mousePos))
{
pWidget = widget;
break;
}
}
if (pWidget != nullptr)
{
bool styleSheetChanged = false;
if (pWidget->getWidgetType() == "SnapmaticWidget")
{
if (pWidget != previousWidget)
{
pWidget->setStyleSheet(QString("QFrame#SnapmaticFrame{background-color: rgb(%1, %2, %3)}QLabel#labPicStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
styleSheetChanged = true;
}
}
else if (pWidget->getWidgetType() == "SavegameWidget")
{
if (pWidget != previousWidget)
{
pWidget->setStyleSheet(QString("QFrame#SavegameFrame{background-color: rgb(%1, %2, %3)}QLabel#labSavegameStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
styleSheetChanged = true;
}
}
if (styleSheetChanged)
{
if (previousWidget != nullptr)
{
previousWidget->setStyleSheet(QLatin1String(""));
}
previousWidget = pWidget;
}
}
}
}
else if (event->type() == QEvent::WindowDeactivate && isProfileLoaded)
{
if (previousWidget != nullptr)
{
previousWidget->setStyleSheet(QLatin1String(""));
previousWidget = nullptr;
}
}
else if (event->type() == QEvent::Leave && isProfileLoaded && !contextMenuOpened)
{
if (watched->objectName() == "SavegameWidget" || watched->objectName() == "SnapmaticWidget")
{
ProfileWidget *pWidget = qobject_cast<ProfileWidget*>(watched);
QPoint mousePos = pWidget->mapFromGlobal(QCursor::pos());
if (!pWidget->geometry().contains(mousePos))
{
if (previousWidget != nullptr)
{
previousWidget->setStyleSheet(QLatin1String(""));
previousWidget = nullptr;
}
}
}
}
return false;
}
void ProfileInterface::hoverProfileWidgetCheck()
{
ProfileWidget *pWidget = nullptr;
for (ProfileWidget *widget : widgets.keys())
2017-10-09 08:35:48 +02:00
{
if (widget->underMouse())
{
pWidget = widget;
break;
}
}
if (pWidget != nullptr)
{
bool styleSheetChanged = false;
if (pWidget->getWidgetType() == "SnapmaticWidget")
{
if (pWidget != previousWidget)
{
pWidget->setStyleSheet(QString("QFrame#SnapmaticFrame{background-color: rgb(%1, %2, %3)}QLabel#labPicStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
styleSheetChanged = true;
}
}
else if (pWidget->getWidgetType() == "SavegameWidget")
{
if (pWidget != previousWidget)
{
pWidget->setStyleSheet(QString("QFrame#SavegameFrame{background-color: rgb(%1, %2, %3)}QLabel#labSavegameStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
styleSheetChanged = true;
}
}
if (styleSheetChanged)
{
if (previousWidget != nullptr)
{
previousWidget->setStyleSheet(QLatin1String(""));
}
previousWidget = pWidget;
}
}
else
{
if (previousWidget != nullptr)
{
previousWidget->setStyleSheet(QLatin1String(""));
previousWidget = nullptr;
}
}
}
void ProfileInterface::updatePalette()
{
QPalette palette;
QColor baseColor = palette.base().color();
highlightBackColor = palette.highlight().color();
highlightTextColor = palette.highlightedText().color();
ui->saProfile->setStyleSheet(QString("QWidget#saProfileContent{background-color: rgb(%1, %2, %3)}").arg(QString::number(baseColor.red()), QString::number(baseColor.green()), QString::number(baseColor.blue())));
if (previousWidget != nullptr)
{
if (previousWidget->getWidgetType() == "SnapmaticWidget")
{
previousWidget->setStyleSheet(QString("QFrame#SnapmaticFrame{background-color: rgb(%1, %2, %3)}QLabel#labPicStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
}
else if (previousWidget->getWidgetType() == "SavegameWidget")
{
previousWidget->setStyleSheet(QString("QFrame#SavegameFrame{background-color: rgb(%1, %2, %3)}QLabel#labSavegameStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
}
}
}
bool ProfileInterface::isSupportedImageFile(QString selectedFileName)
{
2017-10-21 05:59:10 +02:00
for (QByteArray imageFormat : QImageReader::supportedImageFormats())
2017-10-09 08:35:48 +02:00
{
QString imageFormatStr = QString(".") % QString::fromUtf8(imageFormat).toLower();
if (selectedFileName.length() >= imageFormatStr.length() && selectedFileName.toLower().right(imageFormatStr.length()) == imageFormatStr)
{
return true;
}
}
return false;
}
2017-12-17 13:03:43 +01:00
void ProfileInterface::massTool(MassTool tool)
{
switch(tool)
{
case MassTool::Qualify:
{
QList<SnapmaticWidget*> snapmaticWidgets;
for (ProfileWidget *widget : widgets.keys())
{
if (widget->isSelected())
{
if (widget->getWidgetType() == "SnapmaticWidget")
{
SnapmaticWidget *snapmaticWidget = qobject_cast<SnapmaticWidget*>(widget);
snapmaticWidgets += snapmaticWidget;
}
}
}
if (snapmaticWidgets.isEmpty())
{
QMessageBox::information(this, tr("Qualify as Avatar"), tr("No Snapmatic pictures are selected"));
2017-12-17 13:03:43 +01:00
return;
}
// Prepare Progress
int maximumId = snapmaticWidgets.length();
int overallId = 0;
QProgressDialog pbDialog(this);
pbDialog.setWindowFlags(pbDialog.windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint);
pbDialog.setWindowTitle(tr("Patch selected..."));
pbDialog.setLabelText(tr("Patch file %1 of %2 files").arg(QString::number(1), QString::number(maximumId)));
pbDialog.setRange(1, maximumId);
pbDialog.setValue(1);
pbDialog.setModal(true);
QList<QPushButton*> pbBtn = pbDialog.findChildren<QPushButton*>();
pbBtn.at(0)->setDisabled(true);
QList<QProgressBar*> pbBar = pbDialog.findChildren<QProgressBar*>();
pbBar.at(0)->setTextVisible(false);
pbDialog.setAutoClose(false);
pbDialog.show();
// Begin Progress
QStringList fails;
for (SnapmaticWidget *snapmaticWidget : snapmaticWidgets)
{
// Update Progress
overallId++;
pbDialog.setValue(overallId);
pbDialog.setLabelText(tr("Patch file %1 of %2 files").arg(QString::number(overallId), QString::number(maximumId)));
SnapmaticPicture *picture = snapmaticWidget->getPicture();
SnapmaticProperties snapmaticProperties = picture->getSnapmaticProperties();
snapmaticProperties.isSelfie = true;
snapmaticProperties.isMug = false;
snapmaticProperties.isFromRSEditor = false;
snapmaticProperties.isFromDirector = false;
snapmaticProperties.isMeme = false;
QString currentFilePath = picture->getPictureFilePath();
QString originalFilePath = picture->getOriginalPictureFilePath();
QString backupFileName = originalFilePath % ".bak";
if (!QFile::exists(backupFileName))
{
QFile::copy(currentFilePath, backupFileName);
}
SnapmaticProperties fallbackProperties = picture->getSnapmaticProperties();
picture->setSnapmaticProperties(snapmaticProperties);
if (!picture->exportPicture(currentFilePath))
{
picture->setSnapmaticProperties(fallbackProperties);
fails << QString("%1 [%2]").arg(picture->getPictureTitle(), picture->getPictureString());
}
else
{
picture->emitUpdate();
qApp->processEvents();
}
}
pbDialog.close();
if (!fails.isEmpty())
{
QMessageBox::warning(this, tr("Qualify as Avatar"), tr("%1 failed with...\n\n%2", "Action failed with...").arg(tr("Qualify", "%1 failed with..."), fails.join(", ")));
2017-12-17 13:03:43 +01:00
}
}
break;
case MassTool::Players:
{
QList<SnapmaticWidget*> snapmaticWidgets;
for (ProfileWidget *widget : widgets.keys())
{
if (widget->isSelected())
{
if (widget->getWidgetType() == "SnapmaticWidget")
{
SnapmaticWidget *snapmaticWidget = qobject_cast<SnapmaticWidget*>(widget);
snapmaticWidgets += snapmaticWidget;
}
}
}
if (snapmaticWidgets.isEmpty())
{
QMessageBox::information(this, tr("Change Players..."), tr("No Snapmatic pictures are selected"));
2017-12-17 13:03:43 +01:00
return;
}
PlayerListDialog *playerListDialog = new PlayerListDialog(QStringList(), profileDB, this);
playerListDialog->setModal(true);
playerListDialog->show();
playerListDialog->exec();
if (!playerListDialog->isListUpdated())
{
return;
}
QStringList players = playerListDialog->getPlayerList();
delete playerListDialog;
// Prepare Progress
int maximumId = snapmaticWidgets.length();
int overallId = 0;
QProgressDialog pbDialog(this);
pbDialog.setWindowFlags(pbDialog.windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint);
pbDialog.setWindowTitle(tr("Patch selected..."));
pbDialog.setLabelText(tr("Patch file %1 of %2 files").arg(QString::number(1), QString::number(maximumId)));
pbDialog.setRange(1, maximumId);
pbDialog.setValue(1);
pbDialog.setModal(true);
QList<QPushButton*> pbBtn = pbDialog.findChildren<QPushButton*>();
pbBtn.at(0)->setDisabled(true);
QList<QProgressBar*> pbBar = pbDialog.findChildren<QProgressBar*>();
pbBar.at(0)->setTextVisible(false);
pbDialog.setAutoClose(false);
pbDialog.show();
// Begin Progress
QStringList fails;
for (SnapmaticWidget *snapmaticWidget : snapmaticWidgets)
{
// Update Progress
overallId++;
pbDialog.setValue(overallId);
pbDialog.setLabelText(tr("Patch file %1 of %2 files").arg(QString::number(overallId), QString::number(maximumId)));
SnapmaticPicture *picture = snapmaticWidget->getPicture();
SnapmaticProperties snapmaticProperties = picture->getSnapmaticProperties();
snapmaticProperties.playersList = players;
QString currentFilePath = picture->getPictureFilePath();
QString originalFilePath = picture->getOriginalPictureFilePath();
QString backupFileName = originalFilePath % ".bak";
if (!QFile::exists(backupFileName))
{
QFile::copy(currentFilePath, backupFileName);
}
SnapmaticProperties fallbackProperties = picture->getSnapmaticProperties();
picture->setSnapmaticProperties(snapmaticProperties);
if (!picture->exportPicture(currentFilePath))
{
picture->setSnapmaticProperties(fallbackProperties);
fails << QString("%1 [%2]").arg(picture->getPictureTitle(), picture->getPictureString());
}
else
{
picture->emitUpdate();
qApp->processEvents();
}
}
pbDialog.close();
if (!fails.isEmpty())
{
QMessageBox::warning(this, tr("Change Players..."), tr("%1 failed with...\n\n%2", "Action failed with...").arg(tr("Change Players", "%1 failed with..."), fails.join(", ")));
2017-12-17 13:03:43 +01:00
}
}
break;
case MassTool::Crew:
{
QList<SnapmaticWidget*> snapmaticWidgets;
for (ProfileWidget *widget : widgets.keys())
{
if (widget->isSelected())
{
if (widget->getWidgetType() == "SnapmaticWidget")
{
SnapmaticWidget *snapmaticWidget = qobject_cast<SnapmaticWidget*>(widget);
snapmaticWidgets += snapmaticWidget;
}
}
}
if (snapmaticWidgets.isEmpty())
{
QMessageBox::information(this, tr("Change Crew..."), tr("No Snapmatic pictures are selected"));
2017-12-17 13:03:43 +01:00
return;
}
int crewID = 0;
{
preSelectionCrewID:
bool ok;
QStringList itemList;
QStringList crewList = crewDB->getCrews();
if (!crewList.contains(QLatin1String("0")))
{
crewList += QLatin1String("0");
}
crewList.sort();
for (QString crew : crewList)
{
itemList += QString("%1 (%2)").arg(crew, crewDB->getCrewName(crew.toInt()));
}
QString newCrew = QInputDialog::getItem(this, QApplication::translate("SnapmaticEditor", "Snapmatic Crew"), QApplication::translate("SnapmaticEditor", "New Snapmatic crew:"), itemList, 0, true, &ok, windowFlags()^Qt::Dialog^Qt::WindowMinMaxButtonsHint);
if (ok && !newCrew.isEmpty())
{
if (newCrew.contains(" ")) newCrew = newCrew.split(" ").at(0);
if (newCrew.length() > 10) return;
for (QChar crewChar : newCrew)
{
if (!crewChar.isNumber())
{
QMessageBox::warning(this, tr("Change Crew..."), tr("Failed to enter a valid Snapmatic Crew ID"));
2017-12-17 13:03:43 +01:00
goto preSelectionCrewID;
}
}
crewID = newCrew.toInt();
}
else
{
return;
}
}
// Prepare Progress
int maximumId = snapmaticWidgets.length();
int overallId = 0;
QProgressDialog pbDialog(this);
pbDialog.setWindowFlags(pbDialog.windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint);
pbDialog.setWindowTitle(tr("Patch selected..."));
pbDialog.setLabelText(tr("Patch file %1 of %2 files").arg(QString::number(1), QString::number(maximumId)));
pbDialog.setRange(1, maximumId);
pbDialog.setValue(1);
pbDialog.setModal(true);
QList<QPushButton*> pbBtn = pbDialog.findChildren<QPushButton*>();
pbBtn.at(0)->setDisabled(true);
QList<QProgressBar*> pbBar = pbDialog.findChildren<QProgressBar*>();
pbBar.at(0)->setTextVisible(false);
pbDialog.setAutoClose(false);
pbDialog.show();
// Begin Progress
QStringList fails;
for (SnapmaticWidget *snapmaticWidget : snapmaticWidgets)
{
// Update Progress
overallId++;
pbDialog.setValue(overallId);
pbDialog.setLabelText(tr("Patch file %1 of %2 files").arg(QString::number(overallId), QString::number(maximumId)));
SnapmaticPicture *picture = snapmaticWidget->getPicture();
SnapmaticProperties snapmaticProperties = picture->getSnapmaticProperties();
snapmaticProperties.crewID = crewID;
QString currentFilePath = picture->getPictureFilePath();
QString originalFilePath = picture->getOriginalPictureFilePath();
QString backupFileName = originalFilePath % ".bak";
if (!QFile::exists(backupFileName))
{
QFile::copy(currentFilePath, backupFileName);
}
SnapmaticProperties fallbackProperties = picture->getSnapmaticProperties();
picture->setSnapmaticProperties(snapmaticProperties);
if (!picture->exportPicture(currentFilePath))
{
picture->setSnapmaticProperties(fallbackProperties);
fails << QString("%1 [%2]").arg(picture->getPictureTitle(), picture->getPictureString());
}
else
{
picture->emitUpdate();
qApp->processEvents();
}
}
pbDialog.close();
if (!fails.isEmpty())
{
QMessageBox::warning(this, tr("Change Crew..."), tr("%1 failed with...\n\n%2", "Action failed with...").arg(tr("Change Crew", "%1 failed with..."), fails.join(", ")));
2017-12-17 13:03:43 +01:00
}
}
break;
case MassTool::Title:
{
QList<SnapmaticWidget*> snapmaticWidgets;
for (ProfileWidget *widget : widgets.keys())
{
if (widget->isSelected())
{
if (widget->getWidgetType() == "SnapmaticWidget")
{
SnapmaticWidget *snapmaticWidget = qobject_cast<SnapmaticWidget*>(widget);
snapmaticWidgets += snapmaticWidget;
}
}
}
if (snapmaticWidgets.isEmpty())
{
QMessageBox::information(this, tr("Change Title..."), tr("No Snapmatic pictures are selected"));
2017-12-17 13:03:43 +01:00
return;
}
QString snapmaticTitle;
{
preSelectionTitle:
bool ok;
QString newTitle = QInputDialog::getText(this, QApplication::translate("SnapmaticEditor", "Snapmatic Title"), QApplication::translate("SnapmaticEditor", "New Snapmatic title:"), QLineEdit::Normal, snapmaticTitle, &ok, windowFlags()^Qt::Dialog^Qt::WindowMinMaxButtonsHint);
if (ok && !newTitle.isEmpty())
{
if (!SnapmaticPicture::verifyTitle(newTitle))
{
QMessageBox::warning(this, tr("Change Title..."), tr("Failed to enter a valid Snapmatic title"));
2017-12-17 13:03:43 +01:00
goto preSelectionTitle;
}
snapmaticTitle = newTitle;
}
else
{
return;
}
}
// Prepare Progress
int maximumId = snapmaticWidgets.length();
int overallId = 0;
QProgressDialog pbDialog(this);
pbDialog.setWindowFlags(pbDialog.windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint);
pbDialog.setWindowTitle(tr("Patch selected..."));
pbDialog.setLabelText(tr("Patch file %1 of %2 files").arg(QString::number(overallId), QString::number(maximumId)));
pbDialog.setRange(1, maximumId);
pbDialog.setValue(1);
pbDialog.setModal(true);
QList<QPushButton*> pbBtn = pbDialog.findChildren<QPushButton*>();
pbBtn.at(0)->setDisabled(true);
QList<QProgressBar*> pbBar = pbDialog.findChildren<QProgressBar*>();
pbBar.at(0)->setTextVisible(false);
pbDialog.setAutoClose(false);
pbDialog.show();
// Begin Progress
QStringList fails;
for (SnapmaticWidget *snapmaticWidget : snapmaticWidgets)
{
// Update Progress
overallId++;
pbDialog.setValue(overallId);
pbDialog.setLabelText(tr("Patch file %1 of %2 files").arg(QString::number(overallId), QString::number(maximumId)));
SnapmaticPicture *picture = snapmaticWidget->getPicture();
QString currentFilePath = picture->getPictureFilePath();
QString originalFilePath = picture->getOriginalPictureFilePath();
QString backupFileName = originalFilePath % ".bak";
if (!QFile::exists(backupFileName))
{
QFile::copy(currentFilePath, backupFileName);
}
QString fallbackTitle = picture->getPictureTitle();
picture->setPictureTitle(snapmaticTitle);
if (!picture->exportPicture(currentFilePath))
{
picture->setPictureTitle(fallbackTitle);
fails << QString("%1 [%2]").arg(picture->getPictureTitle(), picture->getPictureString());
}
else
{
picture->emitUpdate();
qApp->processEvents();
}
}
pbDialog.close();
if (!fails.isEmpty())
{
QMessageBox::warning(this, tr("Change Title..."), tr("%1 failed with...\n\n%2", "Action failed with...").arg(tr("Change Title", "%1 failed with..."), fails.join(", ")));
2017-12-17 13:03:43 +01:00
}
}
break;
}
}