mass export added

This commit is contained in:
Rafael 2016-04-03 12:27:40 +02:00
parent 68868b1f6c
commit 8a9efc5ed9
5 changed files with 261 additions and 64 deletions

110
ExportThread.cpp Executable file
View file

@ -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 <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "SnapmaticPicture.h"
#include "PictureExport.h"
#include "ProfileWidget.h"
#include "ExportThread.h"
#include "SavegameData.h"
#include <QFileInfo>
#include <QFile>
ExportThread::ExportThread(QMap<ProfileWidget*,QString> 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;
}

55
ExportThread.h Executable file
View file

@ -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 <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef EXPORTTHREAD_H
#define EXPORTTHREAD_H
#include "SnapmaticWidget.h"
#include "SavegameWidget.h"
#include "ProfileWidget.h"
#include <QThread>
#include <QMap>
class ExportThread : public QThread
{
Q_OBJECT
public:
explicit ExportThread(QMap<ProfileWidget*,QString> profileMap, QString exportDirectory, bool pictureCopyEnabled, bool pictureExportEnabled, QObject *parent = 0);
QStringList getFailedSavegames();
QStringList getFailedCopyPictures();
QStringList getFailedExportPictures();
protected:
void run();
private:
QMap <ProfileWidget*, QString> 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

View file

@ -25,10 +25,15 @@
#include "PictureExport.h"
#include "StandardPaths.h"
#include "ProfileLoader.h"
#include "ExportThread.h"
#include <QProgressDialog>
#include <QProgressBar>
#include <QInputDialog>
#include <QPushButton>
#include <QSpacerItem>
#include <QMessageBox>
#include <QFileDialog>
#include <QEventLoop>
#include <QScrollBar>
#include <QFileInfo>
#include <QPalette>
@ -80,6 +85,7 @@ ProfileInterface::~ProfileInterface()
}
profileLoader->deleteLater();
delete profileLoader;
delete ui;
}
@ -389,23 +395,27 @@ 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 (widget->isSelected())
{
if (widgets[widget] == "SnapmaticWidget")
{
SnapmaticWidget *picWidget = (SnapmaticWidget*)widget;
SnapmaticPicture *picture = picWidget->getPicture();
if (!modeSet)
haveToExportPics = true;
}
exportCount++;
}
}
if (haveToExportPics)
{
QInputDialog inputDialog;
QStringList inputDialogItems;
@ -436,41 +446,59 @@ void ProfileInterface::exportSelected()
pictureExportEnabled = true;
pictureCopyEnabled = true;
}
modeSet = true;
}
if (pictureExportEnabled)
{
QString exportFileName = PictureExport::getPictureFileName(picture);
if (!picture->getPicture().save(exportDirectory + "/" + exportFileName, "JPEG", 100))
{
failedExportPictures.append(exportFileName);
}
}
if (pictureCopyEnabled)
{
QString originalFileName = picture->getPictureFileName();
QFileInfo originalFileInfo(originalFileName);
QString exportFileName = originalFileInfo.fileName();
if (QFile::copy(originalFileName, exportDirectory + "/" + exportFileName))
{
failedCopyPictures.append(exportFileName);
}
}
}
else if (widgets[widget] == "SavegameWidget")
{
SavegameWidget *sgdWidget = (SavegameWidget*)widget;
SavegameData *savegame = sgdWidget->getSavegame();
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);
QString originalFileName = savegame->getSavegameFileName();
QFileInfo originalFileInfo(originalFileName);
QString exportFileName = originalFileInfo.fileName();
if (QFile::copy(originalFileName, exportDirectory + "/" + exportFileName))
QList<QPushButton*> pbBtn = pbDialog.findChildren<QPushButton*>();
pbBtn.at(0)->setDisabled(true);
QList<QProgressBar*> pbBar = pbDialog.findChildren<QProgressBar*>();
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)
{
failedSavegames.append(exportFileName);
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;
}
}
}

View file

@ -25,8 +25,10 @@
#include "DatabaseThread.h"
#include "ProfileLoader.h"
#include "ProfileWidget.h"
#include "ExportThread.h"
#include "SavegameData.h"
#include "CrewDatabase.h"
#include <QProgressDialog>
#include <QSpacerItem>
#include <QWidget>
#include <QList>

View file

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