diff --git a/clogwindow.cpp b/clogwindow.cpp new file mode 100644 index 0000000..a53889c --- /dev/null +++ b/clogwindow.cpp @@ -0,0 +1,20 @@ +#include "clogwindow.h" +#include "ui_clogwindow.h" + + +cLogWindow::cLogWindow(QWidget *parent) : + QDialog(parent), + ui(new Ui::cLogWindow) +{ + ui->setupUi(this); +} + +cLogWindow::~cLogWindow() +{ + delete ui; +} + +void cLogWindow::setText(const QString& text) +{ + ui->m_lpLog->setHtml(text); +} diff --git a/clogwindow.h b/clogwindow.h new file mode 100644 index 0000000..13eaf4f --- /dev/null +++ b/clogwindow.h @@ -0,0 +1,24 @@ +#ifndef CLOGWINDOW_H +#define CLOGWINDOW_H + +#include + +namespace Ui { +class cLogWindow; +} + +class cLogWindow : public QDialog +{ + Q_OBJECT + +public: + explicit cLogWindow(QWidget *parent = nullptr); + ~cLogWindow(); + + void setText(const QString& text); + +private: + Ui::cLogWindow* ui; +}; + +#endif // CLOGWINDOW_H diff --git a/clogwindow.ui b/clogwindow.ui new file mode 100644 index 0000000..4da5a45 --- /dev/null +++ b/clogwindow.ui @@ -0,0 +1,67 @@ + + + cLogWindow + + + + 0 + 0 + 800 + 500 + + + + Dialog + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + cLogWindow + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + cLogWindow + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 75c9d38..d69fc77 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -10,6 +10,8 @@ #include "cexportdialog.h" #include "cfiledialog.h" +#include "clogwindow.h" + #include #include @@ -418,11 +420,37 @@ void cMainWindow::onThumbnailSize(int size) ui->m_lpFileList->setIconSize(QSize(size, size)); } +void addToExportLog(QString& exportLog, const QString& text) +{ + QDateTime now = QDateTime::currentDateTime(); + + exportLog.append(" \n " + now.toString("yyyy-mm-dd hh:MM:ss") + "\n " + text + "\n \n"); +} + void cMainWindow::doExport() { EXPORTSETTINGS exportSettings; OVERWRITE overwrite = OVERWRITE_ASK; + m_exportLog = "\n"; + m_exportLog.append("\n"); + m_exportLog.append("\n"); + m_exportLog.append("\n"); + m_exportLog.append("\n"); + m_exportLog.append("\n"); + + addToExportLog(m_exportLog, "Start Export"); + getExportSettings(exportSettings); m_lpProgressBar->setRange(0, m_lpFileListModel->rowCount()); @@ -447,6 +475,15 @@ void cMainWindow::doExport() m_lpProgressBar->setVisible(false); ui->m_lpStatusBar->showMessage(tr("export done."), 3000); + + addToExportLog(m_exportLog, "done."); + m_exportLog.append("\n"); + m_exportLog.append("\n"); + + cLogWindow logWindow; + + logWindow.setText(m_exportLog); + logWindow.exec(); } void cMainWindow::getExportSettings(EXPORTSETTINGS& exportSettings) @@ -456,24 +493,31 @@ void cMainWindow::getExportSettings(EXPORTSETTINGS& exportSettings) 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; + addToExportLog(m_exportLog, "Settings:"); 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; + if(tmp == "newDirectoryTag") + { + exportSettings.directoryMethod = DIRECTORY_METHOD_TAG; + addToExportLog(m_exportLog, "Directory Name Method: DIRECTORY_METHOD_TAG"); + addToExportLog(m_exportLog, " - used TAG: " + exportSettings.directoryTag + ""); + } + else if(tmp == "newDirectory") + { + exportSettings.directoryMethod = DIRECTORY_METHOD_NEW; + addToExportLog(m_exportLog, "Directory Name Method: DIRECTORY_METHOD_NEW"); + addToExportLog(m_exportLog, " - used Directory: " + exportSettings.directory + ""); + } else - exportSettings.fileMethod = FILE_METHOD_KEEP; + { + exportSettings.directoryMethod = DIRECTORY_METHOD_KEEP; + addToExportLog(m_exportLog, "Directory Name Method: DIRECTORY_METHOD_KEEP"); + } + + addToExportLog(m_exportLog, QString("Keep old Structure: %1").arg(exportSettings.keepStructure ? "yes" : "no")); tmp = settings.value("export/filenamePlus", QVariant::fromValue(QString("converted"))).toString(); @@ -485,21 +529,54 @@ void cMainWindow::getExportSettings(EXPORTSETTINGS& exportSettings) exportSettings.fileTag = settings.value("export/fileTag", QVariant::fromValue(QString(""))).toString(); + tmp = settings.value("export/fileMethod", QVariant::fromValue(QString("keepFilename"))).toString(); + + if(tmp == "newFilename") + { + exportSettings.fileMethod = FILE_METHOD_RENAME; + addToExportLog(m_exportLog, "File Name Method: FILE_METHOD_RENAME"); + + if(exportSettings.fileAdd == FILE_ADD_TAG) + addToExportLog(m_exportLog, " - used TAG: " + exportSettings.fileTag + ""); + else + addToExportLog(m_exportLog, " - add '_converted'"); + } + else + { + exportSettings.fileMethod = FILE_METHOD_KEEP; + addToExportLog(m_exportLog, "File Name Method: FILE_METHOD_KEEP"); + } + + tmp = settings.value("export/overwrite", QVariant::fromValue(QString("ask"))).toString(); if(tmp == "overwrite") + { exportSettings.fileOverwrite = FILE_OVERWRITE_OVERWRITE; + addToExportLog(m_exportLog, "Existing File Overwrite Mode: FILE_OVERWRITE_OVERWRITE"); + } else if(tmp == "rename") + { exportSettings.fileOverwrite = FILE_OVERWRITE_RENAME; + addToExportLog(m_exportLog, "Existing File Overwrite Mode: FILE_OVERWRITE_RENAME"); + } else + { exportSettings.fileOverwrite = FILE_OVERWRITE_ASK; + addToExportLog(m_exportLog, "Existing File Overwrite Mode: FILE_OVERWRITE_ASK"); + } exportSettings.fileFormat = settings.value("export/fileFormat").toString(); exportSettings.quality = settings.value("export/quality", QVariant::fromValue(50)).toInt(); + + addToExportLog(m_exportLog, "File Format: " + exportSettings.fileFormat + ""); + addToExportLog(m_exportLog, "Default Output Quality: " + QString::number(exportSettings.quality) + ""); } OVERWRITE cMainWindow::exportFile(const EXPORTSETTINGS& exportSettings, cEXIF* lpExif, OVERWRITE overwrite) { + addToExportLog(m_exportLog, "Loading file: " + lpExif->fileName() + ""); + QString destPath; QString destFile; QFileInfo fileInfo(lpExif->fileName()); @@ -544,6 +621,8 @@ OVERWRITE cMainWindow::exportFile(const EXPORTSETTINGS& exportSettings, cEXIF* l destFile.prepend(destPath + "/"); QFileInfo destInfo(destFile); + addToExportLog(m_exportLog, "Destination: " + destFile + ""); + if(destInfo.exists() && overwrite != OVERWRITE_ALL) { switch(exportSettings.fileOverwrite) @@ -552,14 +631,24 @@ OVERWRITE cMainWindow::exportFile(const EXPORTSETTINGS& exportSettings, cEXIF* l { 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 | QMessageBox::NoAll); if(ret == QMessageBox::YesAll) + { overwrite = OVERWRITE_ALL; + addToExportLog(m_exportLog, "New Option: overwrite all"); + } else if(ret == QMessageBox::NoAll) { overwrite = OVERWRITE_NONE; + addToExportLog(m_exportLog, "New Option: overwrite none"); + addToExportLog(m_exportLog, "aborting, destination file exists"); return(overwrite); } else if(ret == QMessageBox::No) + { + addToExportLog(m_exportLog, "aborting, destination file exists"); return(overwrite); + } + else + addToExportLog(m_exportLog, "file exists, overwrite"); } break; case FILE_OVERWRITE_RENAME: @@ -567,15 +656,20 @@ OVERWRITE cMainWindow::exportFile(const EXPORTSETTINGS& exportSettings, cEXIF* l if(destFile.isEmpty()) { QMessageBox::information(this, tr("File Export"), QString("%1 cannot be renamed.").arg(lpExif->fileName())); + addToExportLog(m_exportLog, "aborting, file cannot be renamed"); return(overwrite); } + addToExportLog(m_exportLog, "renaming to " + destFile + ""); break; case FILE_OVERWRITE_OVERWRITE: break; } } else if(overwrite == OVERWRITE_NONE) + { + addToExportLog(m_exportLog, "aborting, destination file exists"); return(overwrite); + } ui->m_lpStatusBar->showMessage(QString(tr("loading %1...")).arg(lpExif->fileName())); qApp->processEvents(); @@ -605,20 +699,25 @@ OVERWRITE cMainWindow::exportFile(const EXPORTSETTINGS& exportSettings, cEXIF* l image = image.transformed(rotation); } + addToExportLog(m_exportLog, "Loading file: successful"); + 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; + + if(dir.mkpath(info.absolutePath())) { - ui->m_lpStatusBar->showMessage(QString(tr("converting to %1...")).arg(destFile)); - qApp->processEvents(); + QImageWriter writer(destFile); - QDir dir; - QFileInfo info(destFile); - - if(dir.mkpath(info.absolutePath())) - image.save(destFile, nullptr, exportSettings.quality); + addToExportLog(m_exportLog, "Writing file: " + destFile + ""); + writer.setQuality(exportSettings.quality); + if(writer.write(image)) + addToExportLog(m_exportLog, "Writing file: successful"); + else + addToExportLog(m_exportLog, "Writing file: error: " + writer.errorString() + ""); } } diff --git a/cmainwindow.h b/cmainwindow.h index 24c2c93..a9cb5de 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -135,6 +135,8 @@ private: bool m_working; /*!< TODO: describe */ + QString m_exportLog; /*!< TODO: describe */ + /*! \brief diff --git a/pictureConvert.pro b/pictureConvert.pro index c4bc8a2..b1b3b81 100644 --- a/pictureConvert.pro +++ b/pictureConvert.pro @@ -48,6 +48,7 @@ SOURCES += \ cexportdialog.cpp \ cfiledialog.cpp \ cimage.cpp \ + clogwindow.cpp \ common.cpp \ csplashscreen.cpp \ ctreeview.cpp \ @@ -59,6 +60,7 @@ HEADERS += \ cexportdialog.h \ cfiledialog.h \ cimage.h \ + clogwindow.h \ csplashscreen.h \ cmainwindow.h \ common.h \ @@ -66,6 +68,7 @@ HEADERS += \ FORMS += \ cexportdialog.ui \ + clogwindow.ui \ cmainwindow.ui # Default rules for deployment.