From 61ff2d7026c8b629a21ce14c5a4fb688c003f27a Mon Sep 17 00:00:00 2001 From: Rafael Date: Thu, 14 Apr 2016 04:18:22 +0200 Subject: [PATCH] added openFile function --- ProfileInterface.cpp | 4 +- SavegameDialog.ui | 24 +++----- SavegameWidget.ui | 2 +- UserInterface.cpp | 141 +++++++++++++++++++++++++++++++++++++++++++ UserInterface.h | 8 +++ 5 files changed, 162 insertions(+), 17 deletions(-) diff --git a/ProfileInterface.cpp b/ProfileInterface.cpp index 8324213..cf8d7b0 100755 --- a/ProfileInterface.cpp +++ b/ProfileInterface.cpp @@ -415,7 +415,7 @@ bool ProfileInterface::importFile(QString selectedFile, bool warn) SnapmaticPicture *picture = new SnapmaticPicture(selectedFile); if (picture->readingPicture()) { - bool success = importSnapmaticPicture(picture, selectedFile, warn);; + bool success = importSnapmaticPicture(picture, selectedFile, warn); if (!success) delete picture; return success; } @@ -450,7 +450,7 @@ bool ProfileInterface::importFile(QString selectedFile, bool warn) SavegameData *savegame = new SavegameData(selectedFile); if (picture->readingPicture()) { - bool success = importSnapmaticPicture(picture, selectedFile, warn);; + bool success = importSnapmaticPicture(picture, selectedFile, warn); delete savegame; if (!success) delete picture; return success; diff --git a/SavegameDialog.ui b/SavegameDialog.ui index f9c05a8..9dbbe30 100755 --- a/SavegameDialog.ui +++ b/SavegameDialog.ui @@ -16,27 +16,23 @@ + + + 0 + 0 + + <span style=" font-weight:600;">Savegame</span><br><br>%1 + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + true - - - - Qt::Vertical - - - - 0 - 3 - - - - @@ -55,7 +51,7 @@ - Cop&y + &Export diff --git a/SavegameWidget.ui b/SavegameWidget.ui index 0901718..39d5f62 100755 --- a/SavegameWidget.ui +++ b/SavegameWidget.ui @@ -87,7 +87,7 @@ Copy savegame - Copy + Export true diff --git a/UserInterface.cpp b/UserInterface.cpp index cb9f919..bd99cd0 100755 --- a/UserInterface.cpp +++ b/UserInterface.cpp @@ -19,8 +19,13 @@ #include "UserInterface.h" #include "ui_UserInterface.h" #include "ProfileInterface.h" +#include "SnapmaticPicture.h" +#include "SidebarGenerator.h" +#include "SavegameDialog.h" #include "StandardPaths.h" #include "OptionsDialog.h" +#include "PictureDialog.h" +#include "SavegameData.h" #include "AboutDialog.h" #include "IconLoader.h" #include "AppEnv.h" @@ -260,3 +265,139 @@ void UserInterface::on_action_Import_triggered() { profileUI->importFiles(); } + +void UserInterface::on_actionOpen_File_triggered() +{ + QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); + settings.beginGroup("FileDialogs"); + +fileDialogPreOpen: + QFileDialog fileDialog(this); + fileDialog.setFileMode(QFileDialog::ExistingFiles); + fileDialog.setViewMode(QFileDialog::Detail); + fileDialog.setAcceptMode(QFileDialog::AcceptOpen); + fileDialog.setOption(QFileDialog::DontUseNativeDialog, false); + fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint); + fileDialog.setWindowTitle(tr("Open File...")); + + QStringList filters; + filters << ProfileInterface::tr("All profile files (SGTA* PGTA*)"); + filters << ProfileInterface::tr("Savegames files (SGTA*)"); + filters << ProfileInterface::tr("Snapmatic pictures (PGTA*)"); + filters << ProfileInterface::tr("All files (**)"); + fileDialog.setNameFilters(filters); + + QList sidebarUrls = SidebarGenerator::generateSidebarUrls(fileDialog.sidebarUrls()); + + fileDialog.setSidebarUrls(sidebarUrls); + fileDialog.restoreState(settings.value("OpenFile","").toByteArray()); + + if (fileDialog.exec()) + { + QStringList selectedFiles = fileDialog.selectedFiles(); + if (selectedFiles.length() == 1) + { + QString selectedFile = selectedFiles.at(0); + if (!openFile(selectedFile, true)) goto fileDialogPreOpen; + } + } + settings.endGroup(); +} + +bool UserInterface::openFile(QString selectedFile, bool warn) +{ + QString selectedFileName = QFileInfo(selectedFile).fileName(); + if (QFile::exists(selectedFile)) + { + if (selectedFileName.left(4) == "PGTA") + { + SnapmaticPicture *picture = new SnapmaticPicture(selectedFile); + if (picture->readingPicture()) + { + openSnapmaticFile(picture); + delete picture; + return true; + } + else + { + if (warn) QMessageBox::warning(this, tr("Import"), ProfileInterface::tr("Failed to read Snapmatic picture")); + delete picture; + return false; + } + } + else if (selectedFileName.left(4) == "SGTA") + { + SavegameData *savegame = new SavegameData(selectedFile); + if (savegame->readingSavegame()) + { + openSavegameFile(savegame); + delete savegame; + return true; + } + else + { + if (warn) QMessageBox::warning(this, tr("Open File"), ProfileInterface::tr("Failed to read Savegame file")); + delete savegame; + return false; + } + } + else + { + SnapmaticPicture *picture = new SnapmaticPicture(selectedFile); + SavegameData *savegame = new SavegameData(selectedFile); + if (picture->readingPicture()) + { + delete savegame; + openSnapmaticFile(picture); + delete picture; + return true; + } + else if (savegame->readingSavegame()) + { + delete picture; + openSavegameFile(savegame); + delete savegame; + return true; + } + else + { + delete savegame; + delete picture; + if (warn) QMessageBox::warning(this, tr("Open File"), tr("Can't open %1 because of not valid file format").arg("\""+selectedFileName+"\"")); + return false; + } + } + } + if (warn) QMessageBox::warning(this, tr("Open File"), ProfileInterface::tr("No valid file is selected")); + return false; +} + +void UserInterface::openSnapmaticFile(SnapmaticPicture *picture) +{ + PictureDialog *picDialog = new PictureDialog(profileDB, this); + picDialog->setWindowFlags(picDialog->windowFlags()^Qt::WindowContextHelpButtonHint); + picDialog->setSnapmaticPicture(picture, true); + + int crewID = picture->getCrewNumber(); + if (crewID != 0) { crewDB->addCrew(crewID); } + + QObject::connect(threadDB, SIGNAL(playerNameFound(int, QString)), profileDB, SLOT(setPlayerName(int, QString))); + QObject::connect(threadDB, SIGNAL(playerNameUpdated()), picDialog, SLOT(playerNameUpdated())); + + picDialog->setModal(true); + picDialog->show(); + picDialog->exec(); + delete picDialog; +} + +void UserInterface::openSavegameFile(SavegameData *savegame) +{ + SavegameDialog *sgdDialog = new SavegameDialog(this); + sgdDialog->setWindowFlags(sgdDialog->windowFlags()^Qt::WindowContextHelpButtonHint); + sgdDialog->setSavegameData(savegame, savegame->getSavegameFileName(), true); + + sgdDialog->setModal(true); + sgdDialog->show(); + sgdDialog->exec(); + delete sgdDialog; +} diff --git a/UserInterface.h b/UserInterface.h index b0aed0a..b908bb0 100755 --- a/UserInterface.h +++ b/UserInterface.h @@ -19,10 +19,12 @@ #ifndef USERINTERFACE_H #define USERINTERFACE_H +#include "SnapmaticPicture.h" #include "ProfileInterface.h" #include "ProfileDatabase.h" #include "DatabaseThread.h" #include "CrewDatabase.h" +#include "SavegameData.h" #include #include #include @@ -54,6 +56,7 @@ private slots: void on_actionDelete_selected_triggered(); void on_actionOptions_triggered(); void on_action_Import_triggered(); + void on_actionOpen_File_triggered(); private: ProfileDatabase *profileDB; @@ -69,6 +72,11 @@ private: void setupProfileUi(QStringList GTAV_Profiles); void openProfile(QString profileName); void openSelectProfile(); + + // Open File + bool openFile(QString selectedFile, bool warn = true); + void openSavegameFile(SavegameData *savegame); + void openSnapmaticFile(SnapmaticPicture *picture); }; #endif // USERINTERFACE_H