2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2020 Prince Gupta <jagannatharjun11@gmail.com>
4 * Copyright (C) 2019 sledgehammer999 <hammered999@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * In addition, as a special exception, the copyright holders give permission to
21 * link this program with the OpenSSL project's "OpenSSL" library (or with
22 * modified versions of it that use the same license as the "OpenSSL" library),
23 * and distribute the linked executables. You must obey the GNU General Public
24 * License in all respects for all of the code used other than "OpenSSL". If you
25 * modify file(s), you may extend this exception to your version of the file(s),
26 * but you are not obligated to do so. If you do not wish to do so, delete this
27 * exception statement from your version.
32 #include <boost/circular_buffer.hpp>
34 #include <QAbstractListModel>
38 #include "base/logger.h"
40 class BaseLogModel
: public QAbstractListModel
42 Q_DISABLE_COPY_MOVE(BaseLogModel
)
47 TimeRole
= Qt::UserRole
,
50 MessageForegroundRole
,
54 explicit BaseLogModel(QObject
*parent
= nullptr);
56 int rowCount(const QModelIndex
&parent
= {}) const override
;
57 int columnCount(const QModelIndex
&parent
= {}) const override
;
58 QVariant
data(const QModelIndex
&index
, int role
= Qt::DisplayRole
) const override
;
65 Message(const QString
&time
, const QString
&message
, const QColor
&foreground
, Log::MsgType type
);
67 QVariant
time() const;
68 QVariant
message() const;
69 QVariant
foreground() const;
70 QVariant
type() const;
75 QVariant m_foreground
;
79 void addNewMessage(const Message
&message
);
82 boost::circular_buffer_space_optimized
<Message
> m_messages
;
83 const QColor m_timeForeground
;
86 class LogMessageModel
: public BaseLogModel
89 Q_DISABLE_COPY_MOVE(LogMessageModel
)
92 explicit LogMessageModel(QObject
*parent
= nullptr);
95 void handleNewMessage(const Log::Msg
&message
);
98 const QHash
<int, QColor
> m_foregroundForMessageTypes
;
101 class LogPeerModel
: public BaseLogModel
104 Q_DISABLE_COPY_MOVE(LogPeerModel
)
107 explicit LogPeerModel(QObject
*parent
= nullptr);
110 void handleNewMessage(const Log::Peer
&peer
);
113 const QColor m_bannedPeerForeground
;