import function added, german translation updated
This commit is contained in:
parent
e8c3d82db2
commit
e7c0d4f01a
5 changed files with 269 additions and 10 deletions
|
@ -21,14 +21,18 @@
|
|||
#include "SnapmaticWidget.h"
|
||||
#include "DatabaseThread.h"
|
||||
#include "SavegameWidget.h"
|
||||
#include "StandardPaths.h"
|
||||
#include "ProfileLoader.h"
|
||||
#include <QSpacerItem>
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QPalette>
|
||||
#include <QRegExp>
|
||||
#include <QDebug>
|
||||
#include <QColor>
|
||||
#include <QFile>
|
||||
#include <QUrl>
|
||||
#include <QDir>
|
||||
|
||||
ProfileInterface::ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent) :
|
||||
|
@ -36,10 +40,12 @@ ProfileInterface::ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *cre
|
|||
ui(new Ui::ProfileInterface)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->cmdImport->setEnabled(false);
|
||||
ui->cmdCloseProfile->setEnabled(false);
|
||||
loadingStr = ui->labProfileLoading->text();
|
||||
profileFolder = "";
|
||||
profileLoader = 0;
|
||||
saSpacerItem = 0;
|
||||
|
||||
QPalette palette;
|
||||
QColor baseColor = palette.base().color();
|
||||
|
@ -116,10 +122,11 @@ void ProfileInterface::on_loadingProgress(int value, int maximum)
|
|||
|
||||
void ProfileInterface::on_profileLoaded()
|
||||
{
|
||||
QSpacerItem *saSpacerItem = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
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);
|
||||
}
|
||||
|
||||
void ProfileInterface::on_savegameDeleted()
|
||||
|
@ -142,3 +149,169 @@ void ProfileInterface::on_cmdCloseProfile_clicked()
|
|||
{
|
||||
emit profileClosed();
|
||||
}
|
||||
|
||||
void ProfileInterface::on_cmdImport_clicked()
|
||||
{
|
||||
QSettings settings("Syping", "gta5sync");
|
||||
settings.beginGroup("FileDialogs");
|
||||
|
||||
QFileDialog fileDialog(this);
|
||||
fileDialog.setFileMode(QFileDialog::AnyFile);
|
||||
fileDialog.setViewMode(QFileDialog::Detail);
|
||||
fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
|
||||
fileDialog.setOption(QFileDialog::DontUseNativeDialog, true);
|
||||
fileDialog.setWindowTitle(tr("Import copy"));
|
||||
fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
|
||||
|
||||
QStringList filters;
|
||||
filters << tr("All profile files (SGTA* PGTA*)");
|
||||
filters << tr("Savegames files (SGTA*)");
|
||||
filters << tr("Snapmatic pictures (PGTA*)");
|
||||
filters << tr("All files (**)");
|
||||
fileDialog.setNameFilters(filters);
|
||||
|
||||
QList<QUrl> sidebarUrls = fileDialog.sidebarUrls();
|
||||
QDir dir;
|
||||
|
||||
// Get Documents + Desktop Location
|
||||
QString documentsLocation = StandardPaths::documentsLocation();
|
||||
QString desktopLocation = StandardPaths::desktopLocation();
|
||||
|
||||
// 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);
|
||||
fileDialog.restoreState(settings.value("ImportCopy","").toByteArray());
|
||||
|
||||
fileDialogPreOpen:
|
||||
if (fileDialog.exec())
|
||||
{
|
||||
QStringList selectedFiles = fileDialog.selectedFiles();
|
||||
if (selectedFiles.length() == 1)
|
||||
{
|
||||
QString selectedFile = selectedFiles.at(0);
|
||||
QFileInfo selectedFileInfo(selectedFile);
|
||||
QString selectedFileName = selectedFileInfo.fileName();
|
||||
if (QFile::exists(selectedFile))
|
||||
{
|
||||
if (selectedFileName.left(4) == "PGTA")
|
||||
{
|
||||
SnapmaticPicture *picture = new SnapmaticPicture(selectedFile);
|
||||
if (picture->readingPicture())
|
||||
{
|
||||
importSnapmaticPicture(picture, selectedFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, tr("Import copy"), tr("Failed to read Snapmatic picture"));
|
||||
goto fileDialogPreOpen;
|
||||
}
|
||||
}
|
||||
else if (selectedFileName.left(4) == "SGTA")
|
||||
{
|
||||
SavegameData *savegame = new SavegameData(selectedFile);
|
||||
if (savegame->readingSavegame())
|
||||
{
|
||||
importSavegameData(savegame, selectedFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, tr("Import copy"), tr("Failed to read Savegame file"));
|
||||
goto fileDialogPreOpen;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, tr("Import copy"), tr("No valid file is selected"));
|
||||
goto fileDialogPreOpen;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, tr("Import copy"), tr("No valid file is selected"));
|
||||
goto fileDialogPreOpen;
|
||||
}
|
||||
}
|
||||
|
||||
settings.setValue("ImportCopy", fileDialog.saveState());
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
bool ProfileInterface::importSnapmaticPicture(SnapmaticPicture *picture, QString picPath)
|
||||
{
|
||||
QFileInfo picFileInfo(picPath);
|
||||
QString picFileName = picFileInfo.fileName();
|
||||
if (picFileName.left(4) != "PGTA")
|
||||
{
|
||||
QMessageBox::warning(this, tr("Import copy"), tr("Failed to import copy of Snapmatic picture because the file not begin with PGTA"));
|
||||
return false;
|
||||
}
|
||||
else if (QFile::copy(picPath, profileFolder + "/" + picFileName))
|
||||
{
|
||||
on_pictureLoaded(picture, profileFolder + "/" + picFileName);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, tr("Import copy"), tr("Failed to import copy of Snapmatic picture because the copy failed"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ProfileInterface::importSavegameData(SavegameData *savegame, QString sgdPath)
|
||||
{
|
||||
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 = "SGTA00" + sgdNumber;
|
||||
|
||||
if (!QFile::exists(profileFolder + "/" + sgdFileName))
|
||||
{
|
||||
foundFree = true;
|
||||
}
|
||||
currentSgd++;
|
||||
}
|
||||
|
||||
if (foundFree)
|
||||
{
|
||||
if (QFile::copy(sgdPath, profileFolder + "/" + sgdFileName))
|
||||
{
|
||||
on_savegameLoaded(savegame, profileFolder + "/" + sgdFileName);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, tr("Import copy"), tr("Failed to import copy of Savegame file because the copy failed"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, tr("Import copy"), tr("Failed to import copy of Savegame file because no free Savegame slot left"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue