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 05a11a5..1388ce6 100755 Binary files a/gta5sync_de.qm and b/gta5sync_de.qm differ diff --git a/gta5sync_de.ts b/gta5sync_de.ts index a3e8480..59bc191 100755 --- a/gta5sync_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