File indexing completed on 2024-11-24 04:53:03
0001 0002 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net> 0003 0004 This file is part of the Trojita Qt IMAP e-mail client, 0005 http://trojita.flaska.net/ 0006 0007 This program is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU General Public License as 0009 published by the Free Software Foundation; either version 2 of 0010 the License or (at your option) version 3 or any later version 0011 accepted by the membership of KDE e.V. (or its successor approved 0012 by the membership of KDE e.V.), which shall act as a proxy 0013 defined in Section 14 of version 3 of the license. 0014 0015 This program is distributed in the hope that it will be useful, 0016 but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 GNU General Public License for more details. 0019 0020 You should have received a copy of the GNU General Public License 0021 along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 */ 0023 0024 #ifndef GUI_PROTOCOLLOGGERWIDGET_H 0025 #define GUI_PROTOCOLLOGGERWIDGET_H 0026 0027 #include <QMap> 0028 #include <QWidget> 0029 #include "Common/FileLogger.h" 0030 #include "Common/RingBuffer.h" 0031 #include "Imap/ConnectionState.h" 0032 0033 class QPushButton; 0034 class QTabWidget; 0035 class QPlainTextEdit; 0036 class QTimer; 0037 0038 namespace Common { 0039 class FileLogger; 0040 } 0041 0042 namespace Gui { 0043 0044 /** @short Widget (etc) for a single connection */ 0045 struct ConnectionLog { 0046 ConnectionLog(); 0047 QPlainTextEdit *widget; 0048 Common::RingBuffer<Common::LogMessage> buffer; 0049 qint64 closedTime; 0050 }; 0051 0052 /** @short Protocol chat logger 0053 0054 A widget used for displaying a log of textual communication between 0055 the client and the IMAP mail server. 0056 */ 0057 class ProtocolLoggerWidget : public QWidget 0058 { 0059 Q_OBJECT 0060 public: 0061 explicit ProtocolLoggerWidget(QWidget *parent = 0); 0062 virtual ~ProtocolLoggerWidget(); 0063 0064 public slots: 0065 /** @short A protocol handler wants to log something */ 0066 void log(uint connectionId, Common::LogMessage message); 0067 0068 void onConnectionClosed(uint connectionId, Imap::ConnectionState state); 0069 0070 /** @short Enable/disable persistent logging */ 0071 void slotSetPersistentLogging(const bool enabled); 0072 0073 private slots: 0074 /** @short A tab is requested to close */ 0075 void closeTab(int index); 0076 /** @short Clear all logs */ 0077 void clearLogDisplay(); 0078 0079 /** @short Copy contents of all buffers into the GUI widgets */ 0080 void slotShowLogs(); 0081 0082 signals: 0083 void persistentLoggingChanged(const bool active); 0084 0085 private: 0086 QTabWidget *tabs; 0087 QMap<uint, ConnectionLog> logs; 0088 QPushButton *clearAll; 0089 bool loggingActive; 0090 QTimer *delayedDisplay; 0091 Common::FileLogger *m_fileLogger; 0092 0093 /** @short Return (possibly newly created) logger widget for a given parser */ 0094 QPlainTextEdit *getLogger(const uint connectionId); 0095 0096 /** @short Dump the log bufer contents to the GUI widget */ 0097 void flushToWidget(const uint connectionId, Common::RingBuffer<Common::LogMessage> &buf); 0098 0099 virtual void showEvent(QShowEvent *e); 0100 virtual void hideEvent(QHideEvent *e); 0101 }; 0102 0103 } 0104 0105 #endif // GUI_PROTOCOLLOGGERWIDGET_H