[pim/trojita] src/Gui: Refactor ProtocolLogWidget to use smartpointer
Espen Sandøy Hustad <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 936aeacd12c544ff65b49a3a6a214f62eb2856f3 by Espen Sandøy Hustad.
Committed on 03/08/2026 at 19:02.
Pushed by ehustad into branch 'master'.
Refactor ProtocolLogWidget to use smartpointer
To simplify error handling.
M +3 -4 src/Gui/ProtocolLoggerWidget.cpp
M +2 -1 src/Gui/ProtocolLoggerWidget.h
https://invent.kde.org/pim/trojita/-/commit/936aeacd12c544ff65b49a3a6a214f62eb2856f3
diff --git a/src/Gui/ProtocolLoggerWidget.cpp b/src/Gui/ProtocolLoggerWidget.cpp
index 179ad13c1..c470ac22d 100644
--- a/src/Gui/ProtocolLoggerWidget.cpp
+++ b/src/Gui/ProtocolLoggerWidget.cpp
@@ -39,7 +39,7 @@ ConnectionLog::ConnectionLog(): widget(nullptr), buffer(Common::RingBuffer<Commo
}
ProtocolLoggerWidget::ProtocolLoggerWidget(QWidget *parent) :
- QWidget(parent), loggingActive(false), m_fileLogger(nullptr)
+ QWidget(parent), loggingActive(false)
{
QVBoxLayout *layout = new QVBoxLayout(this);
tabs = new QTabWidget(this);
@@ -65,12 +65,11 @@ void ProtocolLoggerWidget::slotSetPersistentLogging(const bool enabled)
if (enabled) {
Q_ASSERT(!m_fileLogger);
- m_fileLogger = new Common::FileLogger(this);
+ m_fileLogger.reset(new Common::FileLogger(nullptr));
m_fileLogger->setFileLogging(true, Imap::Mailbox::persistentLogFileName());
m_fileLogger->setAutoFlush(true);
} else {
- delete m_fileLogger;
- m_fileLogger = nullptr;
+ m_fileLogger.reset();
}
emit persistentLoggingChanged(!!m_fileLogger);
}
diff --git a/src/Gui/ProtocolLoggerWidget.h b/src/Gui/ProtocolLoggerWidget.h
index 5c46cc4d7..e186f5851 100644
--- a/src/Gui/ProtocolLoggerWidget.h
+++ b/src/Gui/ProtocolLoggerWidget.h
@@ -24,6 +24,7 @@
#ifndef GUI_PROTOCOLLOGGERWIDGET_H
#define GUI_PROTOCOLLOGGERWIDGET_H
+#include <QScopedPointer>
#include <QMap>
#include <QWidget>
#include "Common/FileLogger.h"
@@ -84,7 +85,7 @@ private:
QPushButton *clearAll;
bool loggingActive;
QTimer *delayedDisplay;
- Common::FileLogger *m_fileLogger;
+ QScopedPointer<Common::FileLogger, QScopedPointerDeleteLater> m_fileLogger;
/** @short Return (possibly newly created) logger widget for a given parser */
QPlainTextEdit *getLogger(const uint connectionId);