From 2b021749ce4dc3ec8e160a5800e323f7a45047db Mon Sep 17 00:00:00 2001 From: Chris MacLeod Date: Sat, 5 Aug 2023 04:39:01 -0400 Subject: Batch export logs (#2485) * Implement most basic functional batch export For the future: * The loop still needs to be made asynchronous so the process doesn't hang. * Ideally, there should be some sort of progress window. * There is redundant code that should be reduced. * Make batch export asynchronous Reminder: The comment about overwrite protection no longer applies Todo: Progress dialog * Avoid possible dangling pointer, improve type safety and const correctness in the process In reality, the log exporting code has no reason to be in the GUI class to begin with. `exportLog` makes sense as a Qt slot, but `createLog` should be a member function of the `LogFile` class and operate on `this` rather than a `LogFile` argument. A future commit should amend this, but for now I will avoid changing anything unnecessary until a working progress dialog is in place and I have tested the finished feature thoroughly. * Add progress dialog * Make LogViewWindow::createLog a member function of LogFile * Reduce memory usage by sharing `LogFile`s with the GUI thread * Correct progress dialog modality * Collect log files directly instead of reiterating through view items later Also adds a little documentation * Fix batch export for paths with reserved characters * avoid sigsegv * fix tags removal before nickname in html export * Fix directory selection and output path for icons in html export --------- Co-authored-by: ctrlaltca --- src/modules/logview/libkvilogview.cpp | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'src/modules/logview/libkvilogview.cpp') diff --git a/src/modules/logview/libkvilogview.cpp b/src/modules/logview/libkvilogview.cpp index d4255726e..61056f370 100644 --- a/src/modules/logview/libkvilogview.cpp +++ b/src/modules/logview/libkvilogview.cpp @@ -32,6 +32,12 @@ #include "KviIconManager.h" #include "KviLocale.h" #include "KviApplication.h" +#include "KviOptions.h" +#include "KviFileUtils.h" +#include "KviFileDialog.h" + +#include +#include static QRect g_rectLogViewGeometry; LogViewWindow * g_pLogViewWindow = nullptr; @@ -107,12 +113,31 @@ static bool logview_module_ctrl(KviModule *, const char * pcOperation, void * pP if(!pData) return false; - LogFile log{pData->szName}; - int iId = LogFile::PlainText; + LogFile log { pData->szName }; + LogFile::ExportType exportType = LogFile::PlainText; if(pData->szType == QLatin1String("html")) - iId = LogFile::HTML; + exportType = LogFile::HTML; + + QString szDate = log.date().toString("yyyy.MM.dd"); + QString szLog = KVI_OPTION_STRING(KviOption_stringLogsExportPath).trimmed(); + if(!szLog.isEmpty()) + szLog += KVI_PATH_SEPARATOR_CHAR; + szLog += QString("%1_%2.%3_%4").arg(log.typeString(), log.name(), log.network(), szDate); + KviFileUtils::adjustFilePath(szLog); + + // Getting output file path from the user, with overwrite confirmation + if(!KviFileDialog::askForSaveFileName( + szLog, + __tr2qs_ctx("Export Log - KVIrc", "log"), + szLog, + QString(), + false, + true, + true, + g_pLogViewWindow)) + return false; - g_pLogViewWindow->createLog(&log, iId, &(pData->szFile)); + log.createLog(exportType, szLog, &(pData->szFile)); return true; } -- cgit v1.3.1-10-gc9f91