diff --git a/ExportThread.cpp b/ExportThread.cpp
new file mode 100755
index 0000000..05d77e2
--- /dev/null
+++ b/ExportThread.cpp
@@ -0,0 +1,110 @@
+/*****************************************************************************
+* gta5sync GRAND THEFT AUTO V SYNC
+* Copyright (C) 2016 Syping
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*****************************************************************************/
+
+#include "SnapmaticPicture.h"
+#include "PictureExport.h"
+#include "ProfileWidget.h"
+#include "ExportThread.h"
+#include "SavegameData.h"
+#include
+#include
+
+ExportThread::ExportThread(QMap profileMap, QString exportDirectory, bool pictureCopyEnabled, bool pictureExportEnabled, QObject *parent) : QThread(parent),
+ exportDirectory(exportDirectory), profileMap(profileMap), pictureCopyEnabled(pictureCopyEnabled), pictureExportEnabled(pictureExportEnabled)
+{
+
+}
+
+void ExportThread::run()
+{
+ int intExportProgress = 0;
+ foreach(ProfileWidget *widget, profileMap.keys())
+ {
+ if (widget->isSelected())
+ {
+ if (profileMap[widget] == "SnapmaticWidget")
+ {
+ SnapmaticWidget *picWidget = (SnapmaticWidget*)widget;
+ SnapmaticPicture *picture = picWidget->getPicture();
+
+ if (pictureExportEnabled)
+ {
+ QString exportFileName = PictureExport::getPictureFileName(picture);
+
+ intExportProgress++;
+ emit exportStringUpdate(ProfileInterface::tr("Current export job: %1").arg(exportFileName));
+ emit exportProgressUpdate(intExportProgress);
+
+ if (!picture->getPicture().save(exportDirectory + "/" + exportFileName, "JPEG", 100))
+ {
+ failedExportPictures.append(exportFileName);
+ }
+ }
+ if (pictureCopyEnabled)
+ {
+ QString originalFileName = picture->getPictureFileName();
+ QFileInfo originalFileInfo(originalFileName);
+ QString exportFileName = originalFileInfo.fileName();
+
+ intExportProgress++;
+ emit exportStringUpdate(ProfileInterface::tr("Current export job: %1").arg(exportFileName));
+ emit exportProgressUpdate(intExportProgress);
+
+ if (!QFile::copy(originalFileName, exportDirectory + "/" + exportFileName))
+ {
+ failedCopyPictures.append(exportFileName);
+ }
+ }
+ }
+ else if (profileMap[widget] == "SavegameWidget")
+ {
+ SavegameWidget *sgdWidget = (SavegameWidget*)widget;
+ SavegameData *savegame = sgdWidget->getSavegame();
+
+ QString originalFileName = savegame->getSavegameFileName();
+ QFileInfo originalFileInfo(originalFileName);
+ QString exportFileName = originalFileInfo.fileName();
+
+ intExportProgress++;
+ emit exportStringUpdate(ProfileInterface::tr("Current export job: %1").arg(exportFileName));
+ emit exportProgressUpdate(intExportProgress);
+
+ if (!QFile::copy(originalFileName, exportDirectory + "/" + exportFileName))
+ {
+ failedSavegames.append(exportFileName);
+ }
+ }
+ }
+ }
+ emit exportFinished();
+}
+
+QStringList ExportThread::getFailedCopyPictures()
+{
+ return failedCopyPictures;
+}
+
+QStringList ExportThread::getFailedExportPictures()
+{
+ return failedExportPictures;
+}
+
+QStringList ExportThread::getFailedSavegames()
+{
+ return failedSavegames;
+}
diff --git a/ExportThread.h b/ExportThread.h
new file mode 100755
index 0000000..a0a727b
--- /dev/null
+++ b/ExportThread.h
@@ -0,0 +1,55 @@
+/*****************************************************************************
+* gta5sync GRAND THEFT AUTO V SYNC
+* Copyright (C) 2016 Syping
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*****************************************************************************/
+
+#ifndef EXPORTTHREAD_H
+#define EXPORTTHREAD_H
+
+#include "SnapmaticWidget.h"
+#include "SavegameWidget.h"
+#include "ProfileWidget.h"
+#include
+#include
+
+class ExportThread : public QThread
+{
+ Q_OBJECT
+public:
+ explicit ExportThread(QMap profileMap, QString exportDirectory, bool pictureCopyEnabled, bool pictureExportEnabled, QObject *parent = 0);
+ QStringList getFailedSavegames();
+ QStringList getFailedCopyPictures();
+ QStringList getFailedExportPictures();
+
+protected:
+ void run();
+
+private:
+ QMap profileMap;
+ QStringList failedSavegames;
+ QStringList failedCopyPictures;
+ QStringList failedExportPictures;
+ QString exportDirectory;
+ bool pictureCopyEnabled;
+ bool pictureExportEnabled;
+
+signals:
+ void exportStringUpdate(QString currentFileName);
+ void exportProgressUpdate(int currentProgressValue);
+ void exportFinished();
+};
+
+#endif // EXPORTTHREAD_H
diff --git a/ProfileInterface.cpp b/ProfileInterface.cpp
index 91ffdec..daf2eb4 100755
--- a/ProfileInterface.cpp
+++ b/ProfileInterface.cpp
@@ -25,10 +25,15 @@
#include "PictureExport.h"
#include "StandardPaths.h"
#include "ProfileLoader.h"
+#include "ExportThread.h"
+#include
+#include
#include
+#include
#include
#include
#include
+#include
#include
#include
#include
@@ -80,6 +85,7 @@ ProfileInterface::~ProfileInterface()
}
profileLoader->deleteLater();
delete profileLoader;
+
delete ui;
}
@@ -389,89 +395,111 @@ void ProfileInterface::deselectAllWidgets()
void ProfileInterface::exportSelected()
{
- bool modeSet = false;
+ int exportCount = 0;
+ bool haveToExportPics = false;
bool pictureCopyEnabled = false;
bool pictureExportEnabled = false;
- QStringList failedSavegames;
- QStringList failedCopyPictures;
- QStringList failedExportPictures;
QString exportDirectory = QFileDialog::getExistingDirectory(this, tr("Export selected"), profileFolder);
if (exportDirectory != "")
{
- foreach(ProfileWidget *widget, widgets.keys())
+ foreach (ProfileWidget *widget, widgets.keys())
{
- if (widgets[widget] == "SnapmaticWidget")
+ if (widget->isSelected())
{
- SnapmaticWidget *picWidget = (SnapmaticWidget*)widget;
- SnapmaticPicture *picture = picWidget->getPicture();
- if (!modeSet)
+ if (widgets[widget] == "SnapmaticWidget")
{
- QInputDialog inputDialog;
- QStringList inputDialogItems;
- inputDialogItems << tr("Export and Copy pictures");
- inputDialogItems << tr("Export pictures");
- inputDialogItems << tr("Copy pictures");
-
- bool itemSelected = false;
- QString selectedItem = inputDialog.getItem(this, tr("Export selected"), tr("How should we deal with the Snapmatic pictures?"), inputDialogItems, 0, false, &itemSelected, inputDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
- if (itemSelected)
- {
- if (selectedItem == tr("Export and Copy pictures"))
- {
- pictureExportEnabled = true;
- pictureCopyEnabled = true;
- }
- else if (selectedItem == tr("Export pictures"))
- {
- pictureExportEnabled = true;
- }
- else if (selectedItem == tr("Copy pictures"))
- {
- pictureCopyEnabled = true;
- }
- }
- else
- {
- pictureExportEnabled = true;
- pictureCopyEnabled = true;
- }
- modeSet = true;
+ haveToExportPics = true;
}
+ exportCount++;
+ }
+ }
- if (pictureExportEnabled)
+ if (haveToExportPics)
+ {
+ QInputDialog inputDialog;
+ QStringList inputDialogItems;
+ inputDialogItems << tr("Export and Copy pictures");
+ inputDialogItems << tr("Export pictures");
+ inputDialogItems << tr("Copy pictures");
+
+ bool itemSelected = false;
+ QString selectedItem = inputDialog.getItem(this, tr("Export selected"), tr("How should we deal with the Snapmatic pictures?"), inputDialogItems, 0, false, &itemSelected, inputDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
+ if (itemSelected)
+ {
+ if (selectedItem == tr("Export and Copy pictures"))
{
- QString exportFileName = PictureExport::getPictureFileName(picture);
- if (!picture->getPicture().save(exportDirectory + "/" + exportFileName, "JPEG", 100))
- {
- failedExportPictures.append(exportFileName);
- }
+ pictureExportEnabled = true;
+ pictureCopyEnabled = true;
}
- if (pictureCopyEnabled)
+ else if (selectedItem == tr("Export pictures"))
{
- QString originalFileName = picture->getPictureFileName();
- QFileInfo originalFileInfo(originalFileName);
- QString exportFileName = originalFileInfo.fileName();
- if (QFile::copy(originalFileName, exportDirectory + "/" + exportFileName))
- {
- failedCopyPictures.append(exportFileName);
- }
+ pictureExportEnabled = true;
+ }
+ else if (selectedItem == tr("Copy pictures"))
+ {
+ pictureCopyEnabled = true;
}
}
- else if (widgets[widget] == "SavegameWidget")
+ else
{
- SavegameWidget *sgdWidget = (SavegameWidget*)widget;
- SavegameData *savegame = sgdWidget->getSavegame();
-
- QString originalFileName = savegame->getSavegameFileName();
- QFileInfo originalFileInfo(originalFileName);
- QString exportFileName = originalFileInfo.fileName();
- if (QFile::copy(originalFileName, exportDirectory + "/" + exportFileName))
- {
- failedSavegames.append(exportFileName);
- }
+ pictureExportEnabled = true;
+ pictureCopyEnabled = true;
}
}
+
+ QProgressDialog pbDialog(this);
+ pbDialog.setWindowFlags(pbDialog.windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint);
+ pbDialog.setWindowTitle(tr("Export selected..."));
+ pbDialog.setLabelText(tr("Current export job: %1").arg(tr("Initializing...")));
+ pbDialog.setRange(0, exportCount);
+
+ QList pbBtn = pbDialog.findChildren();
+ pbBtn.at(0)->setDisabled(true);
+
+ QList pbBar = pbDialog.findChildren();
+ pbBar.at(0)->setTextVisible(false);
+
+ ExportThread *exportThread = new ExportThread(widgets, exportDirectory, pictureCopyEnabled, pictureExportEnabled);
+ QObject::connect(exportThread, SIGNAL(exportStringUpdate(QString)), &pbDialog, SLOT(setLabelText(QString)));
+ QObject::connect(exportThread, SIGNAL(exportProgressUpdate(int)), &pbDialog, SLOT(setValue(int)));
+ QObject::connect(exportThread, SIGNAL(exportFinished()), &pbDialog, SLOT(close()));
+ exportThread->start();
+
+ pbDialog.exec();
+ QStringList getFailedSavegames = exportThread->getFailedSavegames();
+ QStringList getFailedCopyPictures = exportThread->getFailedCopyPictures();
+ QStringList getFailedExportPictures = exportThread->getFailedExportPictures();
+
+ QString errorStr;
+ QStringList errorList;
+ errorList << getFailedExportPictures;
+ errorList << getFailedCopyPictures;
+ errorList << getFailedSavegames;
+
+ foreach (const QString &curErrorStr, errorList)
+ {
+ errorStr.append(", " + curErrorStr);
+ }
+ if (errorStr != "")
+ {
+ errorStr.remove(0, 2);
+ QMessageBox::warning(this, tr("Export selected"), tr("Export failed with...\n\n%1").arg(errorStr));
+ }
+
+ if (exportThread->isFinished())
+ {
+ exportThread->deleteLater();
+ delete exportThread;
+ }
+ else
+ {
+ QEventLoop threadFinishLoop;
+ QObject::connect(exportThread, SIGNAL(finished()), &threadFinishLoop, SLOT(quit()));
+ threadFinishLoop.exec();
+ exportThread->deleteLater();
+ delete exportThread;
+ }
}
}
diff --git a/ProfileInterface.h b/ProfileInterface.h
index f3847fa..868c916 100755
--- a/ProfileInterface.h
+++ b/ProfileInterface.h
@@ -25,8 +25,10 @@
#include "DatabaseThread.h"
#include "ProfileLoader.h"
#include "ProfileWidget.h"
+#include "ExportThread.h"
#include "SavegameData.h"
#include "CrewDatabase.h"
+#include
#include
#include
#include
diff --git a/gta5sync.pro b/gta5sync.pro
index 5786dbc..4a03a45 100755
--- a/gta5sync.pro
+++ b/gta5sync.pro
@@ -27,6 +27,7 @@ SOURCES += main.cpp \
AboutDialog.cpp \
CrewDatabase.cpp \
DatabaseThread.cpp \
+ ExportThread.cpp \
IconLoader.cpp \
PictureCopy.cpp \
PictureDialog.cpp \
@@ -51,6 +52,7 @@ HEADERS += \
AboutDialog.h \
CrewDatabase.h \
DatabaseThread.h \
+ ExportThread.h \
IconLoader.h \
PictureCopy.h \
PictureDialog.h \