mass export added
This commit is contained in:
parent
68868b1f6c
commit
8a9efc5ed9
5 changed files with 261 additions and 64 deletions
110
ExportThread.cpp
Executable file
110
ExportThread.cpp
Executable 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
55
ExportThread.h
Executable 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
|
|
@ -25,10 +25,15 @@
|
||||||
#include "PictureExport.h"
|
#include "PictureExport.h"
|
||||||
#include "StandardPaths.h"
|
#include "StandardPaths.h"
|
||||||
#include "ProfileLoader.h"
|
#include "ProfileLoader.h"
|
||||||
|
#include "ExportThread.h"
|
||||||
|
#include <QProgressDialog>
|
||||||
|
#include <QProgressBar>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
#include <QPushButton>
|
||||||
#include <QSpacerItem>
|
#include <QSpacerItem>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QEventLoop>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
|
@ -80,6 +85,7 @@ ProfileInterface::~ProfileInterface()
|
||||||
}
|
}
|
||||||
profileLoader->deleteLater();
|
profileLoader->deleteLater();
|
||||||
delete profileLoader;
|
delete profileLoader;
|
||||||
|
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,23 +395,27 @@ void ProfileInterface::deselectAllWidgets()
|
||||||
|
|
||||||
void ProfileInterface::exportSelected()
|
void ProfileInterface::exportSelected()
|
||||||
{
|
{
|
||||||
bool modeSet = false;
|
int exportCount = 0;
|
||||||
|
bool haveToExportPics = false;
|
||||||
bool pictureCopyEnabled = false;
|
bool pictureCopyEnabled = false;
|
||||||
bool pictureExportEnabled = false;
|
bool pictureExportEnabled = false;
|
||||||
|
|
||||||
QStringList failedSavegames;
|
|
||||||
QStringList failedCopyPictures;
|
|
||||||
QStringList failedExportPictures;
|
|
||||||
QString exportDirectory = QFileDialog::getExistingDirectory(this, tr("Export selected"), profileFolder);
|
QString exportDirectory = QFileDialog::getExistingDirectory(this, tr("Export selected"), profileFolder);
|
||||||
if (exportDirectory != "")
|
if (exportDirectory != "")
|
||||||
{
|
{
|
||||||
foreach (ProfileWidget *widget, widgets.keys())
|
foreach (ProfileWidget *widget, widgets.keys())
|
||||||
|
{
|
||||||
|
if (widget->isSelected())
|
||||||
{
|
{
|
||||||
if (widgets[widget] == "SnapmaticWidget")
|
if (widgets[widget] == "SnapmaticWidget")
|
||||||
{
|
{
|
||||||
SnapmaticWidget *picWidget = (SnapmaticWidget*)widget;
|
haveToExportPics = true;
|
||||||
SnapmaticPicture *picture = picWidget->getPicture();
|
}
|
||||||
if (!modeSet)
|
exportCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (haveToExportPics)
|
||||||
{
|
{
|
||||||
QInputDialog inputDialog;
|
QInputDialog inputDialog;
|
||||||
QStringList inputDialogItems;
|
QStringList inputDialogItems;
|
||||||
|
@ -436,41 +446,59 @@ void ProfileInterface::exportSelected()
|
||||||
pictureExportEnabled = true;
|
pictureExportEnabled = true;
|
||||||
pictureCopyEnabled = true;
|
pictureCopyEnabled = true;
|
||||||
}
|
}
|
||||||
modeSet = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pictureExportEnabled)
|
QProgressDialog pbDialog(this);
|
||||||
{
|
pbDialog.setWindowFlags(pbDialog.windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint);
|
||||||
QString exportFileName = PictureExport::getPictureFileName(picture);
|
pbDialog.setWindowTitle(tr("Export selected..."));
|
||||||
if (!picture->getPicture().save(exportDirectory + "/" + exportFileName, "JPEG", 100))
|
pbDialog.setLabelText(tr("Current export job: %1").arg(tr("Initializing...")));
|
||||||
{
|
pbDialog.setRange(0, exportCount);
|
||||||
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();
|
|
||||||
|
|
||||||
QString originalFileName = savegame->getSavegameFileName();
|
QList<QPushButton*> pbBtn = pbDialog.findChildren<QPushButton*>();
|
||||||
QFileInfo originalFileInfo(originalFileName);
|
pbBtn.at(0)->setDisabled(true);
|
||||||
QString exportFileName = originalFileInfo.fileName();
|
|
||||||
if (QFile::copy(originalFileName, exportDirectory + "/" + exportFileName))
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,10 @@
|
||||||
#include "DatabaseThread.h"
|
#include "DatabaseThread.h"
|
||||||
#include "ProfileLoader.h"
|
#include "ProfileLoader.h"
|
||||||
#include "ProfileWidget.h"
|
#include "ProfileWidget.h"
|
||||||
|
#include "ExportThread.h"
|
||||||
#include "SavegameData.h"
|
#include "SavegameData.h"
|
||||||
#include "CrewDatabase.h"
|
#include "CrewDatabase.h"
|
||||||
|
#include <QProgressDialog>
|
||||||
#include <QSpacerItem>
|
#include <QSpacerItem>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
|
@ -27,6 +27,7 @@ SOURCES += main.cpp \
|
||||||
AboutDialog.cpp \
|
AboutDialog.cpp \
|
||||||
CrewDatabase.cpp \
|
CrewDatabase.cpp \
|
||||||
DatabaseThread.cpp \
|
DatabaseThread.cpp \
|
||||||
|
ExportThread.cpp \
|
||||||
IconLoader.cpp \
|
IconLoader.cpp \
|
||||||
PictureCopy.cpp \
|
PictureCopy.cpp \
|
||||||
PictureDialog.cpp \
|
PictureDialog.cpp \
|
||||||
|
@ -51,6 +52,7 @@ HEADERS += \
|
||||||
AboutDialog.h \
|
AboutDialog.h \
|
||||||
CrewDatabase.h \
|
CrewDatabase.h \
|
||||||
DatabaseThread.h \
|
DatabaseThread.h \
|
||||||
|
ExportThread.h \
|
||||||
IconLoader.h \
|
IconLoader.h \
|
||||||
PictureCopy.h \
|
PictureCopy.h \
|
||||||
PictureDialog.h \
|
PictureDialog.h \
|
||||||
|
|
Loading…
Reference in a new issue