added openFile function

This commit is contained in:
Rafael 2016-04-14 04:18:22 +02:00
parent c4b42beae4
commit 61ff2d7026
5 changed files with 162 additions and 17 deletions

View File

@ -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;

View File

@ -16,27 +16,23 @@
<layout class="QVBoxLayout" name="vlSavegameDialog">
<item>
<widget class="QLabel" name="labSavegameText">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;span style=&quot; font-weight:600;&quot;&gt;Savegame&lt;/span&gt;&lt;br&gt;&lt;br&gt;%1</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="vsSavegameDialog">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>3</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="hlButtons">
<item>
@ -55,7 +51,7 @@
<item>
<widget class="QPushButton" name="cmdCopy">
<property name="text">
<string>Cop&amp;y</string>
<string>&amp;Export</string>
</property>
</widget>
</item>

View File

@ -87,7 +87,7 @@
<string>Copy savegame</string>
</property>
<property name="text">
<string>Copy</string>
<string>Export</string>
</property>
<property name="autoDefault">
<bool>true</bool>

View File

@ -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<QUrl> 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;
}

View File

@ -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 <QMainWindow>
#include <QString>
#include <QMap>
@ -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