File indexing completed on 2024-04-21 15:07:58

0001 // Copyright (c) 2003 Rob Kaper <cap@capsi.com>
0002 //
0003 // This library is free software; you can redistribute it and/or
0004 // modify it under the terms of the GNU Lesser General Public
0005 // License version 2.1 as published by the Free Software Foundation.
0006 //
0007 // This library is distributed in the hope that it will be useful,
0008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
0009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0010 // Lesser General Public License for more details.
0011 //
0012 // You should have received a copy of the GNU Lesser General Public License
0013 // along with this library; see the file COPYING.LIB.  If not, write to
0014 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0015 // Boston, MA 02110-1301, USA.
0016 
0017 #ifndef ATLANTIK_EVENTLOGWIDGET_H
0018 #define ATLANTIK_EVENTLOGWIDGET_H
0019 
0020 #include <network_defs.h>
0021 
0022 #include <QSortFilterProxyModel>
0023 #include <QList>
0024 #include <QDialog>
0025 #include <QIcon>
0026 
0027 class QString;
0028 
0029 class Event;
0030 
0031 class QTextStream;
0032 class QTreeView;
0033 
0034 class EventLog : public QAbstractItemModel
0035 {
0036 Q_OBJECT
0037 
0038 public:
0039     EventLog(QObject *parent = nullptr);
0040     ~EventLog();
0041 
0042     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0043     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0044     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0045     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0046     QModelIndex parent(const QModelIndex &index) const override;
0047     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0048 
0049 public Q_SLOTS:
0050     void addEvent(const QString &description, EventType type);
0051     void clear();
0052     void saveAsText(QTextStream &stream) const;
0053 
0054 private:
0055     QIcon cachedIcon(EventType type) const;
0056 
0057     QList<Event*> m_events;
0058     mutable QIcon m_iconCache[ET_LastEvent];
0059 };
0060 
0061 class LastMessagesProxyModel : public QSortFilterProxyModel
0062 {
0063 Q_OBJECT
0064 
0065 public:
0066     LastMessagesProxyModel(QObject *parent = nullptr);
0067 
0068     void setMessagesCount(int n);
0069 
0070     void setSourceModel(QAbstractItemModel *model) override;
0071 
0072 protected:
0073     bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
0074 
0075 private:
0076     int m_count;
0077 };
0078 
0079 class EventLogWidget : public QDialog
0080 {
0081 Q_OBJECT
0082 
0083 public:
0084     EventLogWidget(EventLog *eventLog, QWidget *parent=nullptr);
0085     ~EventLogWidget();
0086     void restoreSettings();
0087 
0088 private Q_SLOTS:
0089     void save();
0090 
0091 private:
0092     EventLog *m_eventLog;
0093     QTreeView *m_eventList;
0094 };
0095 
0096 #endif