import function added, german translation updated

This commit is contained in:
Rafael 2016-03-29 01:13:34 +02:00
parent e8c3d82db2
commit e7c0d4f01a
5 changed files with 269 additions and 10 deletions

View File

@ -21,14 +21,18 @@
#include "SnapmaticWidget.h" #include "SnapmaticWidget.h"
#include "DatabaseThread.h" #include "DatabaseThread.h"
#include "SavegameWidget.h" #include "SavegameWidget.h"
#include "StandardPaths.h"
#include "ProfileLoader.h" #include "ProfileLoader.h"
#include <QSpacerItem> #include <QSpacerItem>
#include <QMessageBox>
#include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
#include <QPalette> #include <QPalette>
#include <QRegExp> #include <QRegExp>
#include <QDebug> #include <QDebug>
#include <QColor> #include <QColor>
#include <QFile> #include <QFile>
#include <QUrl>
#include <QDir> #include <QDir>
ProfileInterface::ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent) : 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(new Ui::ProfileInterface)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->cmdImport->setEnabled(false);
ui->cmdCloseProfile->setEnabled(false); ui->cmdCloseProfile->setEnabled(false);
loadingStr = ui->labProfileLoading->text(); loadingStr = ui->labProfileLoading->text();
profileFolder = ""; profileFolder = "";
profileLoader = 0; profileLoader = 0;
saSpacerItem = 0;
QPalette palette; QPalette palette;
QColor baseColor = palette.base().color(); QColor baseColor = palette.base().color();
@ -116,10 +122,11 @@ void ProfileInterface::on_loadingProgress(int value, int maximum)
void ProfileInterface::on_profileLoaded() 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->saProfileContent->layout()->addItem(saSpacerItem);
ui->swProfile->setCurrentWidget(ui->pageProfile); ui->swProfile->setCurrentWidget(ui->pageProfile);
ui->cmdCloseProfile->setEnabled(true); ui->cmdCloseProfile->setEnabled(true);
ui->cmdImport->setEnabled(true);
} }
void ProfileInterface::on_savegameDeleted() void ProfileInterface::on_savegameDeleted()
@ -142,3 +149,169 @@ void ProfileInterface::on_cmdCloseProfile_clicked()
{ {
emit profileClosed(); 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<QUrl> 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;
}
}

View File

@ -26,6 +26,7 @@
#include "ProfileLoader.h" #include "ProfileLoader.h"
#include "SavegameData.h" #include "SavegameData.h"
#include "CrewDatabase.h" #include "CrewDatabase.h"
#include <QSpacerItem>
#include <QWidget> #include <QWidget>
#include <QList> #include <QList>
@ -50,6 +51,7 @@ private slots:
void on_savegameDeleted(); void on_savegameDeleted();
void on_pictureDeleted(); void on_pictureDeleted();
void on_profileLoaded(); void on_profileLoaded();
void on_cmdImport_clicked();
private: private:
ProfileDatabase *profileDB; ProfileDatabase *profileDB;
@ -61,10 +63,14 @@ private:
QList<SavegameData*> savegames; QList<SavegameData*> savegames;
QList<SnapmaticPicture*> pictures; QList<SnapmaticPicture*> pictures;
QList<QWidget*> widgets; QList<QWidget*> widgets;
QSpacerItem *saSpacerItem;
QString profileFolder; QString profileFolder;
QString profileName; QString profileName;
QString loadingStr; QString loadingStr;
bool importSnapmaticPicture(SnapmaticPicture *picture, QString picPath);
bool importSavegameData(SavegameData *savegame, QString sgdPath);
signals: signals:
void profileClosed(); void profileClosed();
}; };

View File

@ -105,8 +105,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>398</width> <width>98</width>
<height>251</height> <height>28</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="vlProfile"> <layout class="QVBoxLayout" name="vlProfile">
@ -173,6 +173,16 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QPushButton" name="cmdImport">
<property name="text">
<string>Import copy</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="cmdCloseProfile"> <widget class="QPushButton" name="cmdCloseProfile">
<property name="text"> <property name="text">

Binary file not shown.

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS> <!DOCTYPE TS>
<TS version="2.1" language="de_DE"> <TS version="2.0" language="de_DE">
<context> <context>
<name>AboutDialog</name> <name>AboutDialog</name>
<message> <message>
@ -8,7 +8,7 @@
<source>About gta5sync</source> <source>About gta5sync</source>
<translation>Über gta5sync</translation> <translation>Über gta5sync</translation>
</message> </message>
<message> <message utf8="true">
<location filename="AboutDialog.ui" line="59"/> <location filename="AboutDialog.ui" line="59"/>
<source>&lt;span style=&quot; font-weight:600;&quot;&gt;gta5sync&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;A project for viewing and sync Grand Theft Auto 5 Snapmatic Pictures and Savegames&lt;br/&gt;&lt;br/&gt;Project version: %1&lt;br/&gt;Compiled with Qt %2&lt;br/&gt;Running with Qt %3&lt;br/&gt;&lt;br/&gt;Copyright © &lt;a href=&quot;https://github.com/Syping/&quot;&gt;Syping&lt;/a&gt; 2016&lt;br/&gt;gta5sync is licensed under &lt;a href=&quot;https://www.gnu.org/licenses/gpl-3.0.html#content&quot;&gt;GNU GPLv3&lt;/a&gt;</source> <source>&lt;span style=&quot; font-weight:600;&quot;&gt;gta5sync&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;A project for viewing and sync Grand Theft Auto 5 Snapmatic Pictures and Savegames&lt;br/&gt;&lt;br/&gt;Project version: %1&lt;br/&gt;Compiled with Qt %2&lt;br/&gt;Running with Qt %3&lt;br/&gt;&lt;br/&gt;Copyright © &lt;a href=&quot;https://github.com/Syping/&quot;&gt;Syping&lt;/a&gt; 2016&lt;br/&gt;gta5sync is licensed under &lt;a href=&quot;https://www.gnu.org/licenses/gpl-3.0.html#content&quot;&gt;GNU GPLv3&lt;/a&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -92,7 +92,7 @@
</message> </message>
<message> <message>
<source>JPEG picture (*.jpg);;Portable Network Graphics (*.png)</source> <source>JPEG picture (*.jpg);;Portable Network Graphics (*.png)</source>
<translation type="vanished">JPEG Bild (*.jpg);;Portable Network Graphics (*.png)</translation> <translation type="obsolete">JPEG Bild (*.jpg);;Portable Network Graphics (*.png)</translation>
</message> </message>
<message> <message>
<location filename="PictureDialog.cpp" line="159"/> <location filename="PictureDialog.cpp" line="159"/>
@ -109,7 +109,7 @@
</message> </message>
<message> <message>
<source>Failed to save the picture</source> <source>Failed to save the picture</source>
<translation type="vanished">Beim Speichern des Bildes ist ein Fehler aufgetreten</translation> <translation type="obsolete">Beim Speichern des Bildes ist ein Fehler aufgetreten</translation>
</message> </message>
<message> <message>
<location filename="PictureDialog.cpp" line="258"/> <location filename="PictureDialog.cpp" line="258"/>
@ -130,6 +130,20 @@
<oldsource>Loading %1 files of %2 files</oldsource> <oldsource>Loading %1 files of %2 files</oldsource>
<translation>Lade Datei %1 von %2 Dateien</translation> <translation>Lade Datei %1 von %2 Dateien</translation>
</message> </message>
<message>
<location filename="ProfileInterface.ui" line="179"/>
<location filename="ProfileInterface.cpp" line="163"/>
<location filename="ProfileInterface.cpp" line="221"/>
<location filename="ProfileInterface.cpp" line="234"/>
<location filename="ProfileInterface.cpp" line="241"/>
<location filename="ProfileInterface.cpp" line="247"/>
<location filename="ProfileInterface.cpp" line="262"/>
<location filename="ProfileInterface.cpp" line="272"/>
<location filename="ProfileInterface.cpp" line="308"/>
<location filename="ProfileInterface.cpp" line="314"/>
<source>Import copy</source>
<translation>Kopie importieren</translation>
</message>
<message> <message>
<source>Content of Profile %1</source> <source>Content of Profile %1</source>
<translation type="obsolete">Inhalt vom Profil %1</translation> <translation type="obsolete">Inhalt vom Profil %1</translation>
@ -139,15 +153,71 @@
<translation type="obsolete">Ansehen</translation> <translation type="obsolete">Ansehen</translation>
</message> </message>
<message> <message>
<location filename="ProfileInterface.ui" line="179"/> <location filename="ProfileInterface.ui" line="189"/>
<source>Close Profile</source> <source>Close Profile</source>
<translation>Profil schließen</translation> <translation>Profil schließen</translation>
</message> </message>
<message> <message>
<location filename="ProfileInterface.cpp" line="81"/> <location filename="ProfileInterface.cpp" line="87"/>
<source>Loading...</source> <source>Loading...</source>
<translation>Lade...</translation> <translation>Lade...</translation>
</message> </message>
<message>
<location filename="ProfileInterface.cpp" line="167"/>
<source>All profile files (SGTA* PGTA*)</source>
<translation>Alle Profildateien (SGTA* PGTA*)</translation>
</message>
<message>
<location filename="ProfileInterface.cpp" line="168"/>
<source>Savegames files (SGTA*)</source>
<translation>Spielstanddateien (SGTA*)</translation>
</message>
<message>
<location filename="ProfileInterface.cpp" line="169"/>
<source>Snapmatic pictures (PGTA*)</source>
<translation>Snapmatic Bilder (PGTA*)</translation>
</message>
<message>
<location filename="ProfileInterface.cpp" line="170"/>
<source>All files (**)</source>
<translation>Alle Dateien (**)</translation>
</message>
<message>
<location filename="ProfileInterface.cpp" line="221"/>
<source>Failed to read Snapmatic picture</source>
<translation>Fehler beim Lesen vom Snapmatic Bild</translation>
</message>
<message>
<location filename="ProfileInterface.cpp" line="234"/>
<source>Failed to read Savegame file</source>
<translation>Fehler beim Lesen von Spielstanddatei</translation>
</message>
<message>
<location filename="ProfileInterface.cpp" line="241"/>
<location filename="ProfileInterface.cpp" line="247"/>
<source>No valid file is selected</source>
<translation>Keine gültige Datei wurde ausgewählt</translation>
</message>
<message>
<location filename="ProfileInterface.cpp" line="262"/>
<source>Failed to import copy of Snapmatic picture because the file not begin with PGTA</source>
<translation>Fehlgeschlagenen beim Import vom Snapmatic Bild weil die Datei nicht mit PGTA begint </translation>
</message>
<message>
<location filename="ProfileInterface.cpp" line="272"/>
<source>Failed to import copy of Snapmatic picture because the copy failed</source>
<translation>Fehlgeschlagenen beim Import vom Snapmatic Bild weil kopieren fehlgeschlagen ist</translation>
</message>
<message>
<location filename="ProfileInterface.cpp" line="308"/>
<source>Failed to import copy of Savegame file because the copy failed</source>
<translation>Fehlgeschlagenen beim Import vom Spielstand weil kopieren fehlgeschlagen ist</translation>
</message>
<message>
<location filename="ProfileInterface.cpp" line="314"/>
<source>Failed to import copy of Savegame file because no free Savegame slot left</source>
<translation>Fehlgeschlagenen beim Import vom Spielstand weil kein Spielstandslot mehr übrig ist</translation>
</message>
</context> </context>
<context> <context>
<name>SavegameDialog</name> <name>SavegameDialog</name>
@ -247,7 +317,7 @@
</message> </message>
<message> <message>
<source>Failed to copy the savegame</source> <source>Failed to copy the savegame</source>
<translation type="vanished">Beim Kopieren vom Spielstand ist ein Fehler aufgetreten</translation> <translation type="obsolete">Beim Kopieren vom Spielstand ist ein Fehler aufgetreten</translation>
</message> </message>
<message> <message>
<location filename="SavegameWidget.cpp" line="155"/> <location filename="SavegameWidget.cpp" line="155"/>