From e7c0d4f01a381d31caa7870035e7239cbcf1c25d Mon Sep 17 00:00:00 2001 From: Rafael Date: Tue, 29 Mar 2016 01:13:34 +0200 Subject: [PATCH] import function added, german translation updated --- ProfileInterface.cpp | 175 ++++++++++++++++++++++++++++++++++++++++++- ProfileInterface.h | 6 ++ ProfileInterface.ui | 14 +++- gta5sync_de.qm | Bin 7254 -> 8807 bytes gta5sync_de.ts | 84 +++++++++++++++++++-- 5 files changed, 269 insertions(+), 10 deletions(-) diff --git a/ProfileInterface.cpp b/ProfileInterface.cpp index c7e8ed2..a3f7ff7 100755 --- a/ProfileInterface.cpp +++ b/ProfileInterface.cpp @@ -21,14 +21,18 @@ #include "SnapmaticWidget.h" #include "DatabaseThread.h" #include "SavegameWidget.h" +#include "StandardPaths.h" #include "ProfileLoader.h" #include +#include +#include #include #include #include #include #include #include +#include #include 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 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; + } +} diff --git a/ProfileInterface.h b/ProfileInterface.h index 7464692..5d09a30 100755 --- a/ProfileInterface.h +++ b/ProfileInterface.h @@ -26,6 +26,7 @@ #include "ProfileLoader.h" #include "SavegameData.h" #include "CrewDatabase.h" +#include #include #include @@ -50,6 +51,7 @@ private slots: void on_savegameDeleted(); void on_pictureDeleted(); void on_profileLoaded(); + void on_cmdImport_clicked(); private: ProfileDatabase *profileDB; @@ -61,10 +63,14 @@ private: QList savegames; QList pictures; QList widgets; + QSpacerItem *saSpacerItem; QString profileFolder; QString profileName; QString loadingStr; + bool importSnapmaticPicture(SnapmaticPicture *picture, QString picPath); + bool importSavegameData(SavegameData *savegame, QString sgdPath); + signals: void profileClosed(); }; diff --git a/ProfileInterface.ui b/ProfileInterface.ui index 4081f9a..5ad5a70 100755 --- a/ProfileInterface.ui +++ b/ProfileInterface.ui @@ -105,8 +105,8 @@ 0 0 - 398 - 251 + 98 + 28 @@ -173,6 +173,16 @@ + + + + Import copy + + + true + + + diff --git a/gta5sync_de.qm b/gta5sync_de.qm index 05a11a5b0765be3c1ef8a1bd77cea71c4df40d60..1388ce6c5e1d9c94f90a2a334b9d9f02ae4dd1e6 100755 GIT binary patch delta 1745 zcmb7EYfKzf7(F{X%QDL@yX>;;!m`Vy4V4yS+C~V*7f=e_7FrDWiiu%aW?|BOWp<#c zKU@SCFfB1+^V`|b;O0CfbO=}v{XhN*@nf~yboe0IKp_$Bl zcfNb)+;hHrzPVWceRKA{>0bZm3vUjesVx7v`@o0uO@L4haeOyWJPPq#6%cv~;*aZr ziU2G#p8>%t++V*LD0~iE>xKbrF{0USME5}>1`i3Zy6Agc7v5^W0ocA0_IrLJya{2f zdjnve6UMUoz&$TaMy}F^v%>NBYXKjG6Q8aIyhnx8d!2w)60VFF1Ld>ApTl0jVmGt1 za|8?{2A?oDj>~{pBX;=T2K}RS6cHs2@8x!b(c#4XHiz_*>^WFUXaw^ zH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sync_de.ts +++ b/gta5sync_de.ts @@ -1,6 +1,6 @@ - + AboutDialog @@ -8,7 +8,7 @@ About gta5sync Über gta5sync - + <span style=" font-weight:600;">gta5sync</span><br/><br/>A project for viewing and sync Grand Theft Auto 5 Snapmatic Pictures and Savegames<br/><br/>Project version: %1<br/>Compiled with Qt %2<br/>Running with Qt %3<br/><br/>Copyright © <a href="https://github.com/Syping/">Syping</a> 2016<br/>gta5sync is licensed under <a href="https://www.gnu.org/licenses/gpl-3.0.html#content">GNU GPLv3</a> @@ -92,7 +92,7 @@ JPEG picture (*.jpg);;Portable Network Graphics (*.png) - JPEG Bild (*.jpg);;Portable Network Graphics (*.png) + JPEG Bild (*.jpg);;Portable Network Graphics (*.png) @@ -109,7 +109,7 @@ Failed to save the picture - Beim Speichern des Bildes ist ein Fehler aufgetreten + Beim Speichern des Bildes ist ein Fehler aufgetreten @@ -130,6 +130,20 @@ Loading %1 files of %2 files Lade Datei %1 von %2 Dateien + + + + + + + + + + + + Import copy + Kopie importieren + Content of Profile %1 Inhalt vom Profil %1 @@ -139,15 +153,71 @@ Ansehen - + Close Profile Profil schließen - + Loading... Lade... + + + All profile files (SGTA* PGTA*) + Alle Profildateien (SGTA* PGTA*) + + + + Savegames files (SGTA*) + Spielstanddateien (SGTA*) + + + + Snapmatic pictures (PGTA*) + Snapmatic Bilder (PGTA*) + + + + All files (**) + Alle Dateien (**) + + + + Failed to read Snapmatic picture + Fehler beim Lesen vom Snapmatic Bild + + + + Failed to read Savegame file + Fehler beim Lesen von Spielstanddatei + + + + + No valid file is selected + Keine gültige Datei wurde ausgewählt + + + + Failed to import copy of Snapmatic picture because the file not begin with PGTA + Fehlgeschlagenen beim Import vom Snapmatic Bild weil die Datei nicht mit PGTA begint + + + + Failed to import copy of Snapmatic picture because the copy failed + Fehlgeschlagenen beim Import vom Snapmatic Bild weil kopieren fehlgeschlagen ist + + + + Failed to import copy of Savegame file because the copy failed + Fehlgeschlagenen beim Import vom Spielstand weil kopieren fehlgeschlagen ist + + + + Failed to import copy of Savegame file because no free Savegame slot left + Fehlgeschlagenen beim Import vom Spielstand weil kein Spielstandslot mehr übrig ist + SavegameDialog @@ -247,7 +317,7 @@ Failed to copy the savegame - Beim Kopieren vom Spielstand ist ein Fehler aufgetreten + Beim Kopieren vom Spielstand ist ein Fehler aufgetreten