2016-03-21 07:54:14 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* gta5sync GRAND THEFT AUTO V SYNC
|
2016-03-27 09:52:23 +02:00
|
|
|
* Copyright (C) 2016 Syping
|
2016-03-21 07:54:14 +01: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/>.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2016-03-20 21:57:18 +01:00
|
|
|
#include "PictureDialog.h"
|
2016-03-22 05:20:42 +01:00
|
|
|
#include "ProfileDatabase.h"
|
2016-03-20 21:57:18 +01:00
|
|
|
#include "ui_PictureDialog.h"
|
|
|
|
|
2016-03-21 20:44:07 +01:00
|
|
|
#include <QJsonDocument>
|
2016-03-22 05:20:42 +01:00
|
|
|
#include <QFileDialog>
|
2016-03-21 22:14:32 +01:00
|
|
|
#include <QMessageBox>
|
2016-03-21 20:44:07 +01:00
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QVariantMap>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QDebug>
|
2016-03-23 03:33:46 +01:00
|
|
|
#include <QList>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QDir>
|
|
|
|
|
|
|
|
#if QT5_MODE
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#else
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#endif
|
2016-03-21 20:44:07 +01:00
|
|
|
|
2016-03-22 05:20:42 +01:00
|
|
|
PictureDialog::PictureDialog(ProfileDatabase *profileDB, QWidget *parent) :
|
|
|
|
QDialog(parent), profileDB(profileDB),
|
2016-03-20 21:57:18 +01:00
|
|
|
ui(new Ui::PictureDialog)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2016-03-21 22:06:17 +01:00
|
|
|
windowTitleStr = this->windowTitle();
|
2016-03-21 20:44:07 +01:00
|
|
|
jsonDrawString = ui->labJSON->text();
|
2016-03-22 05:20:42 +01:00
|
|
|
ui->cmdExport->setEnabled(0);
|
2016-03-22 05:59:17 +01:00
|
|
|
plyrsList = QStringList();
|
|
|
|
crewID = "";
|
|
|
|
locX = "";
|
|
|
|
locY = "";
|
|
|
|
locZ = "";
|
2016-03-20 21:57:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PictureDialog::~PictureDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2016-03-21 03:10:28 +01:00
|
|
|
|
2016-03-21 22:14:32 +01:00
|
|
|
void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, bool readOk)
|
2016-03-21 20:44:07 +01:00
|
|
|
{
|
2016-03-21 22:40:03 +01:00
|
|
|
// Showing error if reading error
|
|
|
|
if (!readOk)
|
|
|
|
{
|
2016-03-23 02:08:16 +01:00
|
|
|
QMessageBox::warning(this, tr("Snapmatic Picture Viewer"), tr("Failed at %1").arg(picture->getLastStep()));
|
|
|
|
return;
|
2016-03-21 22:40:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (picture->isPicOk())
|
|
|
|
{
|
2016-03-27 09:52:23 +02:00
|
|
|
ui->labPicture->setPixmap(QPixmap::fromImage(picture->getPicture(), Qt::AutoColor));
|
2016-03-22 05:20:42 +01:00
|
|
|
ui->cmdExport->setEnabled(true);
|
2016-03-21 22:40:03 +01:00
|
|
|
}
|
|
|
|
if (picture->isJsonOk())
|
2016-03-21 22:14:32 +01:00
|
|
|
{
|
2016-03-22 05:59:17 +01:00
|
|
|
locX = QString::number(picture->getLocationX());
|
|
|
|
locY = QString::number(picture->getLocationY());
|
|
|
|
locZ = QString::number(picture->getLocationZ());
|
|
|
|
crewID = QString::number(picture->getCrewNumber());
|
|
|
|
plyrsList = picture->getPlayers();
|
2016-03-21 22:14:32 +01:00
|
|
|
|
|
|
|
QString plyrsStr;
|
2016-03-21 22:40:03 +01:00
|
|
|
if (plyrsList.length() >= 1)
|
|
|
|
{
|
|
|
|
foreach (const QString &player, plyrsList)
|
|
|
|
{
|
2016-03-23 06:29:49 +01:00
|
|
|
QString playerName = profileDB->getPlayerName(player.toInt());
|
|
|
|
plyrsStr.append(", <a href=\"http://socialclub.rockstargames.com/member/");
|
|
|
|
plyrsStr.append(playerName);
|
|
|
|
plyrsStr.append("/");
|
|
|
|
plyrsStr.append(player);
|
|
|
|
plyrsStr.append("\">");
|
|
|
|
plyrsStr.append(playerName);
|
|
|
|
plyrsStr.append("</a>");
|
2016-03-21 22:40:03 +01:00
|
|
|
}
|
|
|
|
plyrsStr.remove(0,2);
|
|
|
|
}
|
|
|
|
else
|
2016-03-21 22:14:32 +01:00
|
|
|
{
|
2016-03-21 22:40:03 +01:00
|
|
|
plyrsStr = tr("No player");
|
2016-03-21 22:14:32 +01:00
|
|
|
}
|
2016-03-21 22:40:03 +01:00
|
|
|
|
|
|
|
if (crewID == "") { crewID = tr("No crew"); }
|
2016-03-21 20:44:07 +01:00
|
|
|
|
2016-03-21 22:14:32 +01:00
|
|
|
this->setWindowTitle(windowTitleStr.arg(picture->getPictureStr()));
|
|
|
|
ui->labJSON->setText(jsonDrawString.arg(locX, locY, locZ, plyrsStr, crewID));
|
|
|
|
}
|
|
|
|
else
|
2016-03-21 20:44:07 +01:00
|
|
|
{
|
2016-03-21 22:40:03 +01:00
|
|
|
ui->labJSON->setText(jsonDrawString.arg("0.0", "0.0", "0.0", tr("No player"), tr("No crew")));
|
2016-03-21 22:14:32 +01:00
|
|
|
QMessageBox::warning(this,tr("Snapmatic Picture Viewer"),tr("Failed at %1").arg(picture->getLastStep()));
|
2016-03-21 20:44:07 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-21 21:54:46 +01:00
|
|
|
|
2016-03-22 05:59:17 +01:00
|
|
|
void PictureDialog::on_playerNameUpdated()
|
|
|
|
{
|
|
|
|
if (plyrsList.count() >= 1)
|
|
|
|
{
|
|
|
|
QString plyrsStr;
|
|
|
|
foreach (const QString &player, plyrsList)
|
|
|
|
{
|
2016-03-23 06:29:49 +01:00
|
|
|
QString playerName = profileDB->getPlayerName(player.toInt());
|
|
|
|
plyrsStr.append(", <a href=\"http://socialclub.rockstargames.com/member/");
|
|
|
|
if (playerName != player)
|
|
|
|
{
|
|
|
|
plyrsStr.append(playerName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
plyrsStr.append("id");
|
|
|
|
}
|
|
|
|
plyrsStr.append("/");
|
|
|
|
plyrsStr.append(player);
|
|
|
|
plyrsStr.append("\">");
|
|
|
|
plyrsStr.append(playerName);
|
|
|
|
plyrsStr.append("</a>");
|
2016-03-22 05:59:17 +01:00
|
|
|
}
|
|
|
|
plyrsStr.remove(0,2);
|
|
|
|
ui->labJSON->setText(jsonDrawString.arg(locX, locY, locZ, plyrsStr, crewID));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-21 21:54:46 +01:00
|
|
|
void PictureDialog::on_cmdClose_clicked()
|
|
|
|
{
|
|
|
|
this->close();
|
|
|
|
}
|
2016-03-22 05:20:42 +01:00
|
|
|
|
|
|
|
void PictureDialog::on_cmdExport_clicked()
|
|
|
|
{
|
2016-03-23 03:33:46 +01:00
|
|
|
QFileDialog fileDialog(this);
|
|
|
|
fileDialog.setFileMode(QFileDialog::AnyFile);
|
|
|
|
fileDialog.setViewMode(QFileDialog::Detail);
|
|
|
|
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
|
|
|
|
fileDialog.setDefaultSuffix("suffix");
|
|
|
|
fileDialog.setNameFilter(tr("JPEG picture (*.jpg);;Portable Network Graphics (*.png)"));
|
|
|
|
fileDialog.setWindowTitle(tr("Export picture"));
|
|
|
|
fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
|
|
|
|
|
|
|
|
QList<QUrl> sidebarUrls = fileDialog.sidebarUrls();
|
|
|
|
QDir dir;
|
|
|
|
|
|
|
|
// Get Documents + Desktop Location
|
|
|
|
#ifdef QT5_MODE
|
|
|
|
QString documentsLocation = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
|
|
|
|
QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
|
|
|
#else
|
|
|
|
QString documentsLocation = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
|
|
|
|
QString desktopLocation = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Add Desktop Location to Sidebar
|
|
|
|
dir.setPath(desktopLocation);
|
|
|
|
if (dir.exists())
|
|
|
|
{
|
|
|
|
sidebarUrls.append(QUrl::fromLocalFile(dir.absolutePath()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add Documents + GTA V Location to Sidebar
|
|
|
|
dir.setPath(documentsLocation);
|
|
|
|
if (dir.exists())
|
|
|
|
{
|
|
|
|
sidebarUrls.append(QUrl::fromLocalFile(dir.absolutePath()));
|
|
|
|
if (dir.cd("Rockstar Games/GTA V"))
|
|
|
|
{
|
|
|
|
sidebarUrls.append(QUrl::fromLocalFile(dir.absolutePath()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fileDialog.setSidebarUrls(sidebarUrls);
|
2016-03-22 05:20:42 +01:00
|
|
|
|
2016-03-23 03:33:46 +01:00
|
|
|
fileDialogPreSave:
|
|
|
|
if (fileDialog.exec())
|
|
|
|
{
|
|
|
|
QStringList selectedFiles = fileDialog.selectedFiles();
|
|
|
|
if (selectedFiles.length() == 1)
|
|
|
|
{
|
|
|
|
QString saveFileFormat;
|
|
|
|
QString selectedFile = selectedFiles.at(0);
|
2016-03-23 06:29:49 +01:00
|
|
|
|
2016-03-23 03:33:46 +01:00
|
|
|
if (selectedFile.right(4) == ".jpg")
|
|
|
|
{
|
|
|
|
saveFileFormat = "JPEG";
|
|
|
|
}
|
|
|
|
else if (selectedFile.right(4) == ".jpeg")
|
|
|
|
{
|
|
|
|
saveFileFormat = "JPEG";
|
|
|
|
}
|
|
|
|
else if (selectedFile.right(4) == ".png")
|
|
|
|
{
|
|
|
|
saveFileFormat = "PNG";
|
|
|
|
}
|
|
|
|
else if (selectedFile.right(7) == ".suffix")
|
|
|
|
{
|
|
|
|
if (fileDialog.selectedNameFilter() == "JPEG picture (*.jpg)")
|
|
|
|
{
|
|
|
|
selectedFile.replace(".suffix", ".jpg");
|
|
|
|
}
|
|
|
|
else if (fileDialog.selectedNameFilter() == "Portable Network Graphics (*.png)")
|
|
|
|
{
|
|
|
|
selectedFile.replace(".suffix", ".png");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
selectedFile.replace(".suffix", ".jpg");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSaved = ui->labPicture->pixmap()->save(selectedFile, saveFileFormat.toStdString().c_str(), 100);
|
|
|
|
|
|
|
|
if (!isSaved)
|
|
|
|
{
|
|
|
|
QMessageBox::warning(this, tr("Snapmatic Picture Exporter"), tr("Failed to save the picture"));
|
|
|
|
goto fileDialogPreSave;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QMessageBox::warning(this, tr("Snapmatic Picture Exporter"), tr("No valid file is selected"));
|
|
|
|
goto fileDialogPreSave;
|
|
|
|
}
|
|
|
|
}
|
2016-03-22 05:20:42 +01:00
|
|
|
}
|