added openFile function
This commit is contained in:
parent
c4b42beae4
commit
61ff2d7026
5 changed files with 162 additions and 17 deletions
|
@ -415,7 +415,7 @@ bool ProfileInterface::importFile(QString selectedFile, bool warn)
|
||||||
SnapmaticPicture *picture = new SnapmaticPicture(selectedFile);
|
SnapmaticPicture *picture = new SnapmaticPicture(selectedFile);
|
||||||
if (picture->readingPicture())
|
if (picture->readingPicture())
|
||||||
{
|
{
|
||||||
bool success = importSnapmaticPicture(picture, selectedFile, warn);;
|
bool success = importSnapmaticPicture(picture, selectedFile, warn);
|
||||||
if (!success) delete picture;
|
if (!success) delete picture;
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
@ -450,7 +450,7 @@ bool ProfileInterface::importFile(QString selectedFile, bool warn)
|
||||||
SavegameData *savegame = new SavegameData(selectedFile);
|
SavegameData *savegame = new SavegameData(selectedFile);
|
||||||
if (picture->readingPicture())
|
if (picture->readingPicture())
|
||||||
{
|
{
|
||||||
bool success = importSnapmaticPicture(picture, selectedFile, warn);;
|
bool success = importSnapmaticPicture(picture, selectedFile, warn);
|
||||||
delete savegame;
|
delete savegame;
|
||||||
if (!success) delete picture;
|
if (!success) delete picture;
|
||||||
return success;
|
return success;
|
||||||
|
|
|
@ -16,27 +16,23 @@
|
||||||
<layout class="QVBoxLayout" name="vlSavegameDialog">
|
<layout class="QVBoxLayout" name="vlSavegameDialog">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="labSavegameText">
|
<widget class="QLabel" name="labSavegameText">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string><span style=" font-weight:600;">Savegame</span><br><br>%1</string>
|
<string><span style=" font-weight:600;">Savegame</span><br><br>%1</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
|
</property>
|
||||||
<property name="wordWrap">
|
<property name="wordWrap">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="hlButtons">
|
<layout class="QHBoxLayout" name="hlButtons">
|
||||||
<item>
|
<item>
|
||||||
|
@ -55,7 +51,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="cmdCopy">
|
<widget class="QPushButton" name="cmdCopy">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Cop&y</string>
|
<string>&Export</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -87,7 +87,7 @@
|
||||||
<string>Copy savegame</string>
|
<string>Copy savegame</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Copy</string>
|
<string>Export</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="autoDefault">
|
<property name="autoDefault">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
|
|
@ -19,8 +19,13 @@
|
||||||
#include "UserInterface.h"
|
#include "UserInterface.h"
|
||||||
#include "ui_UserInterface.h"
|
#include "ui_UserInterface.h"
|
||||||
#include "ProfileInterface.h"
|
#include "ProfileInterface.h"
|
||||||
|
#include "SnapmaticPicture.h"
|
||||||
|
#include "SidebarGenerator.h"
|
||||||
|
#include "SavegameDialog.h"
|
||||||
#include "StandardPaths.h"
|
#include "StandardPaths.h"
|
||||||
#include "OptionsDialog.h"
|
#include "OptionsDialog.h"
|
||||||
|
#include "PictureDialog.h"
|
||||||
|
#include "SavegameData.h"
|
||||||
#include "AboutDialog.h"
|
#include "AboutDialog.h"
|
||||||
#include "IconLoader.h"
|
#include "IconLoader.h"
|
||||||
#include "AppEnv.h"
|
#include "AppEnv.h"
|
||||||
|
@ -260,3 +265,139 @@ void UserInterface::on_action_Import_triggered()
|
||||||
{
|
{
|
||||||
profileUI->importFiles();
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -19,10 +19,12 @@
|
||||||
#ifndef USERINTERFACE_H
|
#ifndef USERINTERFACE_H
|
||||||
#define USERINTERFACE_H
|
#define USERINTERFACE_H
|
||||||
|
|
||||||
|
#include "SnapmaticPicture.h"
|
||||||
#include "ProfileInterface.h"
|
#include "ProfileInterface.h"
|
||||||
#include "ProfileDatabase.h"
|
#include "ProfileDatabase.h"
|
||||||
#include "DatabaseThread.h"
|
#include "DatabaseThread.h"
|
||||||
#include "CrewDatabase.h"
|
#include "CrewDatabase.h"
|
||||||
|
#include "SavegameData.h"
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
@ -54,6 +56,7 @@ private slots:
|
||||||
void on_actionDelete_selected_triggered();
|
void on_actionDelete_selected_triggered();
|
||||||
void on_actionOptions_triggered();
|
void on_actionOptions_triggered();
|
||||||
void on_action_Import_triggered();
|
void on_action_Import_triggered();
|
||||||
|
void on_actionOpen_File_triggered();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ProfileDatabase *profileDB;
|
ProfileDatabase *profileDB;
|
||||||
|
@ -69,6 +72,11 @@ private:
|
||||||
void setupProfileUi(QStringList GTAV_Profiles);
|
void setupProfileUi(QStringList GTAV_Profiles);
|
||||||
void openProfile(QString profileName);
|
void openProfile(QString profileName);
|
||||||
void openSelectProfile();
|
void openSelectProfile();
|
||||||
|
|
||||||
|
// Open File
|
||||||
|
bool openFile(QString selectedFile, bool warn = true);
|
||||||
|
void openSavegameFile(SavegameData *savegame);
|
||||||
|
void openSnapmaticFile(SnapmaticPicture *picture);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // USERINTERFACE_H
|
#endif // USERINTERFACE_H
|
||||||
|
|
Loading…
Reference in a new issue