added logs

This commit is contained in:
2019-11-12 17:43:43 +01:00
parent b6a9f56069
commit a120d57b89
6 changed files with 237 additions and 22 deletions
+20
View File
@@ -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);
}
+24
View File
@@ -0,0 +1,24 @@
#ifndef CLOGWINDOW_H
#define CLOGWINDOW_H
#include <QDialog>
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
+67
View File
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>cLogWindow</class>
<widget class="QDialog" name="cLogWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>500</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QTextEdit" name="m_lpLog"/>
</item>
<item row="1" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>cLogWindow</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>cLogWindow</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
+121 -22
View File
@@ -10,6 +10,8 @@
#include "cexportdialog.h"
#include "cfiledialog.h"
#include "clogwindow.h"
#include <QSettings>
#include <QFileInfo>
@@ -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(" <tr>\n <td class='time'>" + now.toString("yyyy-mm-dd hh:MM:ss") + "</td>\n <td>" + text + "</td>\n </tr>\n");
}
void cMainWindow::doExport()
{
EXPORTSETTINGS exportSettings;
OVERWRITE overwrite = OVERWRITE_ASK;
m_exportLog = "<!DOCTYPE html>\n";
m_exportLog.append("<html>\n");
m_exportLog.append("<head>\n");
m_exportLog.append("<style>\n");
m_exportLog.append("body { background-color: white; color: black; }\n");
m_exportLog.append("h1 { color: black; }\n");
m_exportLog.append("p { color: black; }\n");
m_exportLog.append(".time { color: darkgrey; }");
m_exportLog.append(".title { color: darkblue; font-style: bold; }");
m_exportLog.append(".option { color: darkmagenta; font-style: italic; }");
m_exportLog.append(".optionok { color: green; font-style: italic; }");
m_exportLog.append(".optionnok { color: red; font-style: italic; }");
m_exportLog.append("td { color: black; }\n");
m_exportLog.append("</style>\n");
m_exportLog.append("</head>\n");
m_exportLog.append("<body>\n");
addToExportLog(m_exportLog, "<span class='title'>Start Export</span>");
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, "<b>done.</b>");
m_exportLog.append("</body>\n");
m_exportLog.append("</html>\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, "<b>Settings:</b>");
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: <span class='option'>DIRECTORY_METHOD_TAG</span>");
addToExportLog(m_exportLog, " - used TAG: <span class='option'>" + exportSettings.directoryTag + "</span>");
}
else if(tmp == "newDirectory")
{
exportSettings.directoryMethod = DIRECTORY_METHOD_NEW;
addToExportLog(m_exportLog, "Directory Name Method: <span class='option'>DIRECTORY_METHOD_NEW</span>");
addToExportLog(m_exportLog, " - used Directory: <span class='option'>" + exportSettings.directory + "</span>");
}
else
exportSettings.fileMethod = FILE_METHOD_KEEP;
{
exportSettings.directoryMethod = DIRECTORY_METHOD_KEEP;
addToExportLog(m_exportLog, "Directory Name Method: <span class='option'>DIRECTORY_METHOD_KEEP</span>");
}
addToExportLog(m_exportLog, QString("Keep old Structure: <span class='option'>%1</span>").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: <span class='option'>FILE_METHOD_RENAME</span>");
if(exportSettings.fileAdd == FILE_ADD_TAG)
addToExportLog(m_exportLog, " - used TAG: <span class='option'>" + exportSettings.fileTag + "</span>");
else
addToExportLog(m_exportLog, " - add <span class='option'>'_converted'</span>");
}
else
{
exportSettings.fileMethod = FILE_METHOD_KEEP;
addToExportLog(m_exportLog, "File Name Method: <span class='option'>FILE_METHOD_KEEP</span>");
}
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: <span class='option'>FILE_OVERWRITE_OVERWRITE</span>");
}
else if(tmp == "rename")
{
exportSettings.fileOverwrite = FILE_OVERWRITE_RENAME;
addToExportLog(m_exportLog, "Existing File Overwrite Mode: <span class='option'>FILE_OVERWRITE_RENAME</span>");
}
else
{
exportSettings.fileOverwrite = FILE_OVERWRITE_ASK;
addToExportLog(m_exportLog, "Existing File Overwrite Mode: <span class='option'>FILE_OVERWRITE_ASK</span>");
}
exportSettings.fileFormat = settings.value("export/fileFormat").toString();
exportSettings.quality = settings.value("export/quality", QVariant::fromValue(50)).toInt();
addToExportLog(m_exportLog, "File Format: <span class='option'>" + exportSettings.fileFormat + "</span>");
addToExportLog(m_exportLog, "Default Output Quality: <span class='option'>" + QString::number(exportSettings.quality) + "</span>");
}
OVERWRITE cMainWindow::exportFile(const EXPORTSETTINGS& exportSettings, cEXIF* lpExif, OVERWRITE overwrite)
{
addToExportLog(m_exportLog, "Loading file: <span class='option'>" + lpExif->fileName() + "</span>");
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: <span class='option'>" + destFile + "</span>");
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: <span class='optionok'>overwrite all</span>");
}
else if(ret == QMessageBox::NoAll)
{
overwrite = OVERWRITE_NONE;
addToExportLog(m_exportLog, "New Option: <span class='optionnok'>overwrite none</span>");
addToExportLog(m_exportLog, "<span class='optionnok'>aborting, destination file exists</span>");
return(overwrite);
}
else if(ret == QMessageBox::No)
{
addToExportLog(m_exportLog, "<span class='optionnok'>aborting, destination file exists</span>");
return(overwrite);
}
else
addToExportLog(m_exportLog, "<span class='optionok'>file exists, overwrite</span>");
}
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, "<span class='optionnok'>aborting, file cannot be renamed</span>");
return(overwrite);
}
addToExportLog(m_exportLog, "renaming to <span class='optionok'>" + destFile + "</span>");
break;
case FILE_OVERWRITE_OVERWRITE:
break;
}
}
else if(overwrite == OVERWRITE_NONE)
{
addToExportLog(m_exportLog, "<span class='optionnok'>aborting, destination file exists</span>");
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: <span class='optionok'>successful</span>");
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: <span class='option'>" + destFile + "</span>");
writer.setQuality(exportSettings.quality);
if(writer.write(image))
addToExportLog(m_exportLog, "Writing file: <span class='optionok'>successful</span>");
else
addToExportLog(m_exportLog, "Writing file: <span class='optionnok'>error: " + writer.errorString() + "</span>");
}
}
+2
View File
@@ -135,6 +135,8 @@ private:
bool m_working; /*!< TODO: describe */
QString m_exportLog; /*!< TODO: describe */
/*!
\brief
+3
View File
@@ -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.