From 0f86abad9fdbd5cff3981693ddc7551de6b0bfc2 Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Mon, 11 Nov 2019 15:56:45 +0100 Subject: [PATCH] initial commit --- cexportdialog.cpp | 278 ++++++++++++++++++++++++++++++++++++++++- cexportdialog.h | 34 ++++- cexportdialog.ui | 302 ++++++++++++++++++++++++++++++++++----------- cmainwindow.cpp | 298 ++++++++++++++++++++++++++++++++++---------- cmainwindow.h | 65 ++++++++-- common.cpp | 55 +++++++++ common.h | 14 +++ pictureConvert.pro | 1 + 8 files changed, 889 insertions(+), 158 deletions(-) create mode 100644 common.cpp diff --git a/cexportdialog.cpp b/cexportdialog.cpp index 18be38b..53b2b78 100644 --- a/cexportdialog.cpp +++ b/cexportdialog.cpp @@ -1,14 +1,16 @@ #include "cexportdialog.h" #include "ui_cexportdialog.h" +#include +#include -cExportDialog::cExportDialog(QWidget *parent) : + +cExportDialog::cExportDialog(const QList& imageFormats, QWidget *parent) : QDialog(parent), ui(new Ui::cExportDialog) { - ui->setupUi(this); - - connect(ui->m_lpQuality, &QSlider::valueChanged, this, &cExportDialog::onQualityChanged); + initUI(imageFormats); + createActions(); } cExportDialog::~cExportDialog() @@ -16,7 +18,275 @@ cExportDialog::~cExportDialog() delete ui; } +void cExportDialog::accept() +{ + saveSettings(); + QDialog::accept(); +} + +void cExportDialog::reject() +{ + saveSettings(); + QDialog::reject(); +} + +void cExportDialog::saveSettings() +{ + QSettings settings; + settings.setValue("export/width", QVariant::fromValue(size().width())); + settings.setValue("export/height", QVariant::fromValue(size().height())); + settings.setValue("export/x", QVariant::fromValue(x())); + settings.setValue("export/y", QVariant::fromValue(y())); + + + if(ui->m_lpNewDirectoryTag->isChecked()) + settings.setValue("export/directoryMethod", QVariant::fromValue(QString("newDirectoryTag"))); + else if(ui->m_lpNewDirectory->isChecked()) + settings.setValue("export/directoryMethod", QVariant::fromValue(QString("newDirectory"))); + else + settings.setValue("export/directoryMethod", QVariant::fromValue(QString("keepDirectory"))); + + settings.setValue("export/destinationPath", QVariant::fromValue(ui->m_lpDestinationPath->text())); + settings.setValue("export/keepStructure", QVariant::fromValue(ui->m_lpKeepStructure->isChecked())); + settings.setValue("export/destinationPathTag", QVariant::fromValue(ui->m_lpDestinationPathTag->text())); + + + if(ui->m_lpNewFilename->isChecked()) + settings.setValue("export/fileMethod", QVariant::fromValue(QString("newFilename"))); + else + settings.setValue("export/fileMethod", QVariant::fromValue(QString("keepFilename"))); + + if(ui->m_lpFilenameTag->isChecked()) + settings.setValue("export/filenamePlus", QVariant::fromValue(QString("TAG"))); + else + settings.setValue("export/filenamePlus", QVariant::fromValue(QString("converted"))); + + settings.setValue("export/fileTag", QVariant::fromValue(ui->m_lpFileTag->text())); + + if(ui->m_lpFileOverwrite->isChecked()) + settings.setValue("export/overwrite", QVariant::fromValue(QString("overwrite"))); + else if(ui->m_lpFileRename->isChecked()) + settings.setValue("export/overwrite", QVariant::fromValue(QString("rename"))); + else + settings.setValue("export/overwrite", QVariant::fromValue(QString("ask"))); + + settings.setValue("export/fileFormat", QVariant::fromValue(ui->m_lpFileFormat->currentText())); + settings.setValue("export/quality", QVariant::fromValue(ui->m_lpQuality->value())); +} + +void cExportDialog::initUI(const QList& imageFormats) +{ + QSettings settings; + + ui->setupUi(this); + + qint32 iX = settings.value("export/x", QVariant::fromValue(-1)).toInt(); + qint32 iY = settings.value("export/y", QVariant::fromValue(-1)).toInt(); + qint32 iWidth = settings.value("export/width", QVariant::fromValue(-1)).toInt(); + qint32 iHeight = settings.value("export/height", QVariant::fromValue(-1)).toInt(); + + if(iWidth != -1 && iHeight != -1) + resize(iWidth, iHeight); + if(iX != -1 && iY != -1) + move(iX, iY); + + QString directoryMethod = settings.value("export/directoryMethod", QVariant::fromValue(QString("keepDirectory"))).toString(); + + if(directoryMethod == "newDirectoryTag") + { + ui->m_lpKeepDirectory->setChecked(false); + ui->m_lpNewDirectory->setChecked(false); + ui->m_lpNewDirectoryTag->setChecked(true); + + ui->m_lpDestinationPath->setEnabled(false); + ui->m_lpDestinationPathBrowse->setEnabled(false); + } + else if(directoryMethod == "newDirectory") + { + ui->m_lpKeepDirectory->setChecked(false); + ui->m_lpNewDirectory->setChecked(true); + ui->m_lpNewDirectoryTag->setChecked(false); + + ui->m_lpDestinationPathTag->setEnabled(false); + } + else + { + ui->m_lpKeepDirectory->setChecked(true); + ui->m_lpNewDirectory->setChecked(false); + ui->m_lpNewDirectoryTag->setChecked(false); + + ui->m_lpDestinationPath->setEnabled(false); + ui->m_lpDestinationPathBrowse->setEnabled(false); + ui->m_lpDestinationPathTag->setEnabled(false); + + ui->m_lpKeepStructure->setEnabled(false); + } + + ui->m_lpDestinationPath->setText(settings.value("export/destinationPath", QVariant::fromValue(QString(""))).toString()); + ui->m_lpKeepStructure->setChecked(settings.value("export/keepStructure", QVariant::fromValue(false)).toBool()); + ui->m_lpDestinationPathTag->setText(settings.value("export/destinationPathTag", QVariant::fromValue(QString(""))).toString()); + + QString fileMethod = settings.value("export/fileMethod", QVariant::fromValue(QString("keepFilename"))).toString(); + + if(fileMethod == "newFilename") + { + ui->m_lpKeepFilename->setChecked(false); + ui->m_lpNewFilename->setChecked(true); + + ui->m_lpFilenamePlusConverted->setEnabled(true); + ui->m_lpFilenameTag->setEnabled(true); + ui->m_lpFileTag->setEnabled(true); + } + else + { + ui->m_lpKeepFilename->setChecked(true); + ui->m_lpNewFilename->setChecked(false); + + ui->m_lpFilenamePlusConverted->setEnabled(false); + ui->m_lpFilenameTag->setEnabled(false); + ui->m_lpFileTag->setEnabled(false); + } + + QString filenamePlus = settings.value("export/filenamePlus", QVariant::fromValue(QString("converted"))).toString(); + + if(filenamePlus == "TAG") + { + ui->m_lpFilenamePlusConverted->setChecked(false); + ui->m_lpFilenameTag->setChecked(true); + } + else + { + ui->m_lpFilenamePlusConverted->setChecked(true); + ui->m_lpFilenameTag->setChecked(false); + + ui->m_lpFileTag->setEnabled(false); + } + + ui->m_lpFileTag->setText(settings.value("export/fileTag", QVariant::fromValue(QString(""))).toString()); + + QString fileOverwrite = settings.value("export/overwrite", QVariant::fromValue(QString("ask"))).toString(); + + if(fileOverwrite == "overwrite") + { + ui->m_lpFileAsk->setChecked(false); + ui->m_lpFileRename->setChecked(false); + ui->m_lpFileOverwrite->setChecked(true); + } + else if(fileOverwrite == "rename") + { + ui->m_lpFileAsk->setChecked(false); + ui->m_lpFileRename->setChecked(true); + ui->m_lpFileOverwrite->setChecked(false); + } + else + { + ui->m_lpFileAsk->setChecked(true); + ui->m_lpFileRename->setChecked(false); + ui->m_lpFileOverwrite->setChecked(false); + } + + for(int x = 0;x < imageFormats.count();x++) + { + IMAGEFORMAT i = imageFormats[x]; + + if(i.write) + ui->m_lpFileFormat->addItem(i.description + " (" + i.extension + ")"); + } + ui->m_lpFileFormat->setCurrentText(settings.value("export/fileFormat").toString()); + ui->m_lpQuality->setValue(settings.value("export/quality", QVariant::fromValue(50)).toInt()); + ui->m_lpQualityValue->setText(QString::number(ui->m_lpQuality->value())); + + ui->m_lpPathTagHelp->setText("" + "" + "" + "" + "" + "" + "" + "" + "" + "
%ooriginal directory
%yyear of picture taken
%mmonth of picture taken
%dday of picture taken
%Hhour of picture taken
%Mminute of picture taken
%Ssecond of picture taken
%ttype of created picture
"); + ui->m_lpFileTagHelp->setText("" + "" + "" + "" + "" + "" + "" + "" + "" + "
%ooriginal filename (without extension)
%yyear of picture taken
%mmonth of picture taken
%dday of picture taken
%Hhour of picture taken
%Mminute of picture taken
%Ssecond of picture taken
%ttype of created picture
"); +} + +void cExportDialog::createActions() +{ + QSettings settings; + + connect(ui->m_lpQuality, &QSlider::valueChanged, this, &cExportDialog::onQualityChanged); + + connect(ui->m_lpDirectoryMethod, QOverload::of(&QButtonGroup::buttonClicked), this, &cExportDialog::onDirectoryMethodChanged); + connect(ui->m_lpFilenameMethod, QOverload::of(&QButtonGroup::buttonClicked), this, &cExportDialog::onFileMethodChanged); + connect(ui->m_lpFilenameAdd, QOverload::of(&QButtonGroup::buttonClicked), this, &cExportDialog::onFileNamePlusChanged); + connect(ui->m_lpFileOverwriteMethod, QOverload::of(&QButtonGroup::buttonClicked), this, &cExportDialog::onFileOverwriteMethodChanged); +} + void cExportDialog::onQualityChanged(int value) { ui->m_lpQualityValue->setNum(value); } + +void cExportDialog::onDirectoryMethodChanged(int /*id*/) +{ + if(ui->m_lpNewDirectoryTag->isChecked()) + { + ui->m_lpDestinationPath->setEnabled(false); + ui->m_lpDestinationPathBrowse->setEnabled(false); + ui->m_lpKeepStructure->setEnabled(false); + ui->m_lpDestinationPathTag->setEnabled(true); + } + else if(ui->m_lpNewDirectory->isChecked()) + { + ui->m_lpDestinationPath->setEnabled(true); + ui->m_lpDestinationPathBrowse->setEnabled(true); + ui->m_lpKeepStructure->setEnabled(true); + ui->m_lpDestinationPathTag->setEnabled(false); + } + else + { + ui->m_lpDestinationPath->setEnabled(false); + ui->m_lpDestinationPathBrowse->setEnabled(false); + ui->m_lpKeepStructure->setEnabled(false); + ui->m_lpDestinationPathTag->setEnabled(false); + } +} + +void cExportDialog::onFileMethodChanged(int /*id*/) +{ + if(ui->m_lpNewFilename->isChecked()) + { + ui->m_lpFilenamePlusConverted->setEnabled(true); + ui->m_lpFilenameTag->setEnabled(true); + ui->m_lpFilenamePlusConverted->setEnabled(true); + ui->m_lpFilenameTag->setEnabled(true); + onFileNamePlusChanged(0); + } + else + { + ui->m_lpFilenamePlusConverted->setEnabled(false); + ui->m_lpFilenameTag->setEnabled(false); + ui->m_lpFileTag->setEnabled(false); + } +} + +void cExportDialog::onFileNamePlusChanged(int /*id*/) +{ + if(ui->m_lpNewFilename->isChecked() && ui->m_lpFilenameTag->isChecked()) + ui->m_lpFileTag->setEnabled(true); + else + ui->m_lpFileTag->setEnabled(false); +} + +void cExportDialog::onFileOverwriteMethodChanged(int /*id*/) +{ + //NOTHING +} diff --git a/cexportdialog.h b/cexportdialog.h index b1714f5..eb0efa7 100644 --- a/cexportdialog.h +++ b/cexportdialog.h @@ -1,8 +1,25 @@ #ifndef CEXPORTDIALOG_H #define CEXPORTDIALOG_H + #include +#include "common.h" + + +/* + * altes Verzeichnis + * neues Verzeichnis, alte Struktur + * neues Verzeichnis + * + * alter Name (umbenennen, wenn gleich) + * alter Name + _converted + * alter Name + tag + * tag + * + * überschreiben / fragen / umbenennen +*/ + namespace Ui { class cExportDialog; } @@ -12,14 +29,29 @@ class cExportDialog : public QDialog Q_OBJECT public: - explicit cExportDialog(QWidget *parent = nullptr); + explicit cExportDialog(const QList& imageFormats, QWidget *parent = nullptr); ~cExportDialog(); private: Ui::cExportDialog *ui; + void accept(); + void reject(); + + void saveSettings(); + + void initUI(const QList& imageFormats); + void createActions(); + private slots: void onQualityChanged(int value); + + void onDirectoryMethodChanged(int id); + void onFileMethodChanged(int id); + void onFileNamePlusChanged(int id); + void onFileOverwriteMethodChanged(int id); + +protected: }; #endif // CEXPORTDIALOG_H diff --git a/cexportdialog.ui b/cexportdialog.ui index 5e2df33..8d76c09 100644 --- a/cexportdialog.ui +++ b/cexportdialog.ui @@ -6,96 +6,248 @@ 0 0 - 400 - 135 + 554 + 466 Dialog - + - - - - - quality: + + + + + Destination Path + + + + + + + ... + + + + + + + keep structure + + + + + + + keep directory + + + m_lpDirectoryMethod + + + + + + + + + + TAG + + + m_lpDirectoryMethod + + + + + + + new directory + + + m_lpDirectoryMethod + + + + + + + + + + + + + + + + - - - - file format: - - - m_lpFileFormat + + + + Filename + + + + + + + overwrite existing file + + + m_lpFileOverwriteMethod + + + + + + + TAG: + + + m_lpFilenameAdd + + + + + + + old filename + _converted + + + m_lpFilenameAdd + + + + + + + keep filename + + + m_lpFilenameMethod + + + + + + + + + + auto rename existing file + + + m_lpFileOverwriteMethod + + + + + + + ask before overwrite existing file + + + m_lpFileOverwriteMethod + + + + + + + + + + + + + + rename + + + m_lpFilenameMethod + + + + + + - - - - - - - destination path: - - - m_lpDestinationPath + + + + File Format + + + + + + + + + Qt::Horizontal + + + QSlider::TicksBelow + + + + + + + 0 + + + m_lpQuality + + + + + + + + + file format: + + + m_lpFileFormat + + + + + + + + + + quality: + + + + + + - - - - - - Qt::Horizontal - - - QSlider::TicksBelow - - - - - - - 0 - - - m_lpQuality - - - - - - - - - - - - - - ... - - - - + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - @@ -133,4 +285,10 @@ + + + + + + diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 5842002..8ee1628 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -2,7 +2,6 @@ #include "ui_cmainwindow.h" #include "cimage.h" -#include "cexif.h" #include "cexportdialog.h" #include "cfiledialog.h" @@ -27,6 +26,7 @@ cMainWindow::cMainWindow(cSplashScreen* lpSplashScreen, QWidget *parent) : QMainWindow(parent), ui(new Ui::cMainWindow), m_lpSplashScreen(lpSplashScreen), + m_lpProgressBar(nullptr), m_working(false) { initUI(); @@ -91,6 +91,10 @@ void cMainWindow::initUI() if(iX != -1 && iY != -1) move(iX, iY); } + + m_lpProgressBar = new QProgressBar(this); + m_lpProgressBar->setVisible(false); + ui->m_lpStatusBar->addPermanentWidget(m_lpProgressBar); } void cMainWindow::createActions() @@ -189,58 +193,6 @@ void cMainWindow::addImageFormat(const char* shortName, const char* description, m_imageFormats.append(i); } -QString cMainWindow::generateReadList() -{ - QString all("all supported files ("); - QString readList; - - for(int z = 0;z < m_imageFormats.count();z++) - { - IMAGEFORMAT i = m_imageFormats[z]; - - if(i.read) - { - all.append(i.extension); - all.append(" "); - - readList.append(";;"); - readList.append(i.description); - readList.append(" ("); - readList.append(i.extension); - readList.append(")"); - } - } - - readList.prepend(all); - return(readList); -} - -QString cMainWindow::generateWriteList() -{ - QString all("all supported files ("); - QString writeList; - - for(int z = 0;z < m_imageFormats.count();z++) - { - IMAGEFORMAT i = m_imageFormats[z]; - - if(i.write) - { - all.append(i.extension); - all.append(" "); - - writeList.append(";;"); - writeList.append(i.description); - writeList.append(" ("); - writeList.append(i.extension); - writeList.append(")"); - } - } - - writeList.prepend(all); - return(writeList); -} - void cMainWindow::onAddFile() { QSettings settings; @@ -253,7 +205,7 @@ void cMainWindow::onAddFile() fileDialog.setDirectory(path); fileDialog.setFileMode(QFileDialog::ExistingFiles); fileDialog.setViewMode(QFileDialog::Detail); - fileDialog.setNameFilter(generateReadList()); + fileDialog.setNameFilter(generateReadList(m_imageFormats)); if(!fileDialog.exec()) return; @@ -300,12 +252,15 @@ void cMainWindow::onAddFolder() settings.setValue("import/recursive", QVariant::fromValue(checked)); m_working = true; + ui->m_lpStatusBar->showMessage(tr("importing...")); + qApp->processEvents(); addPath(path, checked); for(int i = 0;i < m_lpFileListModel->columnCount();i++) ui->m_lpFileList->resizeColumnToContents(i); + ui->m_lpStatusBar->showMessage(tr("done."), 3000); m_working = false; } @@ -324,6 +279,8 @@ void cMainWindow::onClearList() void cMainWindow::onAddEntrys(const QStringList& fileList) { m_working = true; + ui->m_lpStatusBar->showMessage(tr("importing...")); + qApp->processEvents(); for(int i = 0;i < fileList.count();i++) { @@ -345,11 +302,15 @@ void cMainWindow::onAddEntrys(const QStringList& fileList) for(int i = 0;i < m_lpFileListModel->columnCount();i++) ui->m_lpFileList->resizeColumnToContents(i); + ui->m_lpStatusBar->showMessage(tr("done."), 3000); m_working = false; } void cMainWindow::addPath(const QString& path, bool recursive) { + ui->m_lpStatusBar->showMessage(QString(tr("importing %1...")).arg(path)); + qApp->processEvents(); + QDir dir(path); QStringList dirList = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); QStringList fileList = dir.entryList(QDir::Files); @@ -366,6 +327,9 @@ void cMainWindow::addPath(const QString& path, bool recursive) void cMainWindow::addFile(const QString& file) { + ui->m_lpStatusBar->showMessage(QString(tr("importing %1...")).arg(file)); + qApp->processEvents(); + if(isInList(file)) return; @@ -415,9 +379,29 @@ bool cMainWindow::isInList(const QString& file) void cMainWindow::onConvert() { - cExportDialog* lpExportDialog = new cExportDialog(this); - lpExportDialog->exec(); - delete lpExportDialog; + cExportDialog exportDialog(m_imageFormats, this); + if(exportDialog.exec() == QDialog::Rejected) + return; + + doExport(); +} + +void cMainWindow::onThumbnailSize(int size) +{ + ui->m_lpThumbnailSizeValue->setText(QString::number(size)); + ui->m_lpFileList->setIconSize(QSize(size, size)); +} + +void cMainWindow::doExport() +{ + EXPORTSETTINGS exportSettings; + bool overwriteAll = false; + + getExportSettings(exportSettings); + + m_lpProgressBar->setRange(0, m_lpFileListModel->rowCount()); + m_lpProgressBar->setValue(0); + m_lpProgressBar->setVisible(true); for(int i = 0;i < m_lpFileListModel->rowCount();i++) { @@ -429,20 +413,198 @@ void cMainWindow::onConvert() if(!lpExif) continue; - cImage image(lpExif->fileName()); - if(image.isNull()) - continue; + overwriteAll = exportFile(exportSettings, lpExif, overwriteAll); - QString newFile = lpExif->fileName(); - newFile = newFile.left(newFile.lastIndexOf(".")); - newFile.append("_converted.jpg"); - - image.save(newFile); + m_lpProgressBar->setValue(i); + qApp->processEvents(); } + + m_lpProgressBar->setVisible(false); + ui->m_lpStatusBar->showMessage(tr("export done."), 3000); } -void cMainWindow::onThumbnailSize(int size) +void cMainWindow::getExportSettings(EXPORTSETTINGS& exportSettings) { - ui->m_lpThumbnailSizeValue->setText(QString::number(size)); - ui->m_lpFileList->setIconSize(QSize(size, size)); + QSettings settings; + QString tmp; + + tmp = settings.value("export/directoryMethod", QVariant::fromValue(QString("keepDirectory"))).toString(); + + if(tmp == "newDirectoryTag") + exportSettings.directoryMethod = DIRECTORY_METHOD_TAG; + else if(tmp == "newDirectory") + exportSettings.directoryMethod = DIRECTORY_METHOD_NEW; + else + exportSettings.directoryMethod = DIRECTORY_METHOD_KEEP; + + exportSettings.directory = settings.value("export/destinationPath", QVariant::fromValue(QString(""))).toString(); + exportSettings.keepStructure = settings.value("export/keepStructure", QVariant::fromValue(false)).toBool(); + exportSettings.directoryTag = settings.value("export/destinationPathTag", QVariant::fromValue(QString(""))).toString(); + + + tmp = settings.value("export/fileMethod", QVariant::fromValue(QString("keepFilename"))).toString(); + + if(tmp == "newFilename") + exportSettings.fileMethod = FILE_METHOD_RENAME; + else + exportSettings.fileMethod = FILE_METHOD_KEEP; + + + tmp = settings.value("export/filenamePlus", QVariant::fromValue(QString("converted"))).toString(); + + if(tmp == "TAG") + exportSettings.fileAdd = FILE_ADD_TAG; + else + exportSettings.fileAdd = FILE_ADD_CONVERTED; + + exportSettings.fileTag = settings.value("export/fileTag", QVariant::fromValue(QString(""))).toString(); + + tmp = settings.value("export/overwrite", QVariant::fromValue(QString("ask"))).toString(); + + if(tmp == "overwrite") + exportSettings.fileOverwrite = FILE_OVERWRITE_OVERWRITE; + else if(tmp == "rename") + exportSettings.fileOverwrite = FILE_OVERWRITE_RENAME; + else + exportSettings.fileOverwrite = FILE_OVERWRITE_ASK; + + exportSettings.fileFormat = settings.value("export/fileFormat").toString(); + exportSettings.quality = settings.value("export/quality", QVariant::fromValue(50)).toInt(); +} + +bool cMainWindow::exportFile(const EXPORTSETTINGS& exportSettings, cEXIF* lpExif, bool overwriteAll) +{ + QString destPath; + QString destFile; + QFileInfo fileInfo(lpExif->fileName()); + QString extension = exportSettings.fileFormat; + + extension = extension.mid(extension.lastIndexOf(".")+1); + extension = extension.left(extension.length()-1); + + switch(exportSettings.directoryMethod) + { + case DIRECTORY_METHOD_NEW: + destPath = exportSettings.directory; + if(exportSettings.keepStructure) + destPath.append("/" + fileInfo.absolutePath().replace(":", "")); + break; + case DIRECTORY_METHOD_KEEP: + destPath = fileInfo.absolutePath(); + break; + case DIRECTORY_METHOD_TAG: + destPath = replaceTags(exportSettings.directoryTag, lpExif, extension); + break; + } + + switch(exportSettings.fileMethod) + { + case FILE_METHOD_KEEP: + destFile = fileInfo.baseName() + "." + extension; + break; + case FILE_METHOD_RENAME: + switch(exportSettings.fileAdd) + { + case FILE_ADD_CONVERTED: + destFile = fileInfo.baseName() + "_converted" + "." + extension; + break; + case FILE_ADD_TAG: + destFile = replaceTags(fileInfo.baseName(), lpExif, extension, false) + "." + extension; + break; + } + break; + } + + destFile.prepend(destPath + "/"); + QFileInfo destInfo(destFile); + + if(destInfo.exists() && !overwriteAll) + { + switch(exportSettings.fileOverwrite) + { + case FILE_OVERWRITE_ASK: + { + QMessageBox::StandardButton ret = QMessageBox::question(this, tr("File Exists"), QString(tr("File %1 exists. Do you want to overwrite?")).arg(destFile), QMessageBox::Yes | QMessageBox::No | QMessageBox::YesAll); + if(ret == QMessageBox::YesAll) + overwriteAll = true; + else if(ret == QMessageBox::No) + return(overwriteAll); + } + break; + case FILE_OVERWRITE_RENAME: + destFile = findFreeFileName(destFile); + if(destFile.isEmpty()) + { + QMessageBox::information(this, tr("File Export"), QString("%1 cannot be renamed.").arg(lpExif->fileName())); + return(overwriteAll); + } + break; + case FILE_OVERWRITE_OVERWRITE: + break; + } + } + + ui->m_lpStatusBar->showMessage(QString(tr("loading %1...")).arg(lpExif->fileName())); + qApp->processEvents(); + + cImage image(lpExif->fileName()); + if(!image.isNull()) + { + QFileInfo info(destFile); + + if(info.exists()) + qDebug() << "MACHMA NED!!!"; + else + { + ui->m_lpStatusBar->showMessage(QString(tr("converting to %1...")).arg(destFile)); + qApp->processEvents(); + + QDir dir; + QFileInfo info(destFile); + + if(dir.mkpath(info.absolutePath())) + image.save(destFile); + } + } + + return(overwriteAll); +} + +QString cMainWindow::replaceTags(const QString& path, cEXIF* lpExif, const QString& extension, bool directory) +{ + QString dest = path; + QFileInfo fileInfo(lpExif->fileName()); + + if(directory) + dest = dest.replace("%o", fileInfo.absolutePath()); + else + dest = dest.replace("%o", fileInfo.fileName()); + + dest = dest.replace("%y", lpExif->dateTime().toString("yyyy")); + dest = dest.replace("%m", lpExif->dateTime().toString("MM")); + dest = dest.replace("%d", lpExif->dateTime().toString("dd")); + dest = dest.replace("%H", lpExif->dateTime().toString("hh")); + dest = dest.replace("%M", lpExif->dateTime().toString("mm")); + dest = dest.replace("%S", lpExif->dateTime().toString("ss")); + dest = dest.replace("%t", extension); + + dest = dest.replace("\\", "/"); + + return(dest); +} + +QString cMainWindow::findFreeFileName(const QString& fileName) +{ + QFileInfo fileInfo(fileName); + QString newName; + int number = 1; + + for(;;) + { + newName = fileInfo.absolutePath() + "/" + fileInfo.baseName() + QString::number(number) + "." + fileInfo.suffix(); + + if(!QFileInfo::exists(newName)) + return(newName); + } +// return(""); } diff --git a/cmainwindow.h b/cmainwindow.h index 47a8a9b..7428978 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -3,6 +3,8 @@ #include "csplashscreen.h" +#include "common.h" +#include "cexif.h" #include #include @@ -10,20 +12,53 @@ #include #include +#include + QT_BEGIN_NAMESPACE namespace Ui { class cMainWindow; } QT_END_NAMESPACE -typedef struct tagIMAGEFORMAT +enum DIRECTORY_METHOD { - QString shortName; - QString description; - QString extension; - bool read; - bool write; -} IMAGEFORMAT; + DIRECTORY_METHOD_KEEP = 1, + DIRECTORY_METHOD_NEW = 2, + DIRECTORY_METHOD_TAG = 3, +}; + +enum FILE_METHOD +{ + FILE_METHOD_KEEP = 1, + FILE_METHOD_RENAME = 2, +}; + +enum FILE_OVERWRITE +{ + FILE_OVERWRITE_ASK = 1, + FILE_OVERWRITE_RENAME = 2, + FILE_OVERWRITE_OVERWRITE = 3, +}; + +enum FILE_ADD +{ + FILE_ADD_CONVERTED = 1, + FILE_ADD_TAG = 2, +}; + +typedef struct tagEXPORTSETTINGS +{ + DIRECTORY_METHOD directoryMethod; + QString directory; + bool keepStructure; + QString directoryTag; + FILE_METHOD fileMethod; + FILE_ADD fileAdd; + QString fileTag; + FILE_OVERWRITE fileOverwrite; + QString fileFormat; + int quality; +} EXPORTSETTINGS; class cMainWindow : public QMainWindow @@ -38,6 +73,7 @@ private: Ui::cMainWindow* ui; cSplashScreen* m_lpSplashScreen; /*!< TODO: describe */ QStandardItemModel* m_lpFileListModel; + QProgressBar* m_lpProgressBar; /*!< TODO: describe */ QMimeDatabase m_mimeDB; QList m_imageFormats; @@ -54,6 +90,15 @@ private: bool isInList(const QString& file); + void doExport(); + void getExportSettings(EXPORTSETTINGS& exportSettings); + bool exportFile(const EXPORTSETTINGS& exportSettings, cEXIF* lpExif, bool overwriteAll); + QString replaceTags(const QString& path, cEXIF* lpExif, const QString& extension = QString(""), bool directory = true); + QString findFreeFileName(const QString& fileName); + + void setImageFormats(); + void addImageFormat(const char* shortName, const char* description, const char* extension, QList& readList, QList& writeList); + private slots: void onAddFile(); void onAddFolder(); @@ -66,11 +111,5 @@ private slots: protected: void closeEvent(QCloseEvent* event); - - void setImageFormats(); - void addImageFormat(const char* shortName, const char* description, const char* extension, QList& readList, QList& writeList); - - QString generateReadList(); - QString generateWriteList(); }; #endif // CMAINWINDOW_H diff --git a/common.cpp b/common.cpp new file mode 100644 index 0000000..1d018f6 --- /dev/null +++ b/common.cpp @@ -0,0 +1,55 @@ +#include "common.h" + + +QString generateReadList(const QList& imageFormats) +{ + QString all("all supported files ("); + QString readList; + + for(int z = 0;z < imageFormats.count();z++) + { + IMAGEFORMAT i = imageFormats[z]; + + if(i.read) + { + all.append(i.extension); + all.append(" "); + + readList.append(";;"); + readList.append(i.description); + readList.append(" ("); + readList.append(i.extension); + readList.append(")"); + } + } + + readList.prepend(all); + return(readList); +} + +QString generateWriteList(const QList& imageFormats) +{ + QString all("all supported files ("); + QString writeList; + + for(int z = 0;z < imageFormats.count();z++) + { + IMAGEFORMAT i = imageFormats[z]; + + if(i.write) + { + all.append(i.extension); + all.append(" "); + + writeList.append(";;"); + writeList.append(i.description); + writeList.append(" ("); + writeList.append(i.extension); + writeList.append(")"); + } + } + + writeList.prepend(all); + return(writeList); +} + diff --git a/common.h b/common.h index f42e6c5..256ac4a 100644 --- a/common.h +++ b/common.h @@ -18,4 +18,18 @@ #endif +typedef struct tagIMAGEFORMAT +{ + QString shortName; + QString description; + QString extension; + bool read; + bool write; +} IMAGEFORMAT; + + +QString generateReadList(const QList& imageFormats); +QString generateWriteList(const QList& imageFormats); + + #endif // COMMON_H diff --git a/pictureConvert.pro b/pictureConvert.pro index aa6dc49..2eb3232 100644 --- a/pictureConvert.pro +++ b/pictureConvert.pro @@ -48,6 +48,7 @@ SOURCES += \ cexportdialog.cpp \ cfiledialog.cpp \ cimage.cpp \ + common.cpp \ csplashscreen.cpp \ ctreeview.cpp \ main.cpp \