1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2011 Christophe Dumez
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 * In addition, as a special exception, the copyright holders give permission to
20 * link this program with the OpenSSL project's "OpenSSL" library (or with
21 * modified versions of it that use the same license as the "OpenSSL" library),
22 * and distribute the linked executables. You must obey the GNU General Public
23 * License in all respects for all of the code used other than "OpenSSL". If you
24 * modify file(s), you may extend this exception to your version of the file(s),
25 * but you are not obligated to do so. If you do not wish to do so, delete this
26 * exception statement from your version.
27 */
28
29 #include "executionlogwidget.h"
30
31 #include <QDateTime>
32 #include <QMenu>
33 #include <QPalette>
34
35 #include "log/logfiltermodel.h"
36 #include "log/loglistview.h"
37 #include "log/logmodel.h"
38 #include "ui_executionlogwidget.h"
39 #include "uithememanager.h"
40
ExecutionLogWidget(const Log::MsgTypes types,QWidget * parent)41 ExecutionLogWidget::ExecutionLogWidget(const Log::MsgTypes types, QWidget *parent)
42 : QWidget(parent)
43 , m_ui(new Ui::ExecutionLogWidget)
44 , m_messageFilterModel(new LogFilterModel(types, this))
45 {
46 m_ui->setupUi(this);
47
48 LogMessageModel *messageModel = new LogMessageModel(this);
49 m_messageFilterModel->setSourceModel(messageModel);
50 LogListView *messageView = new LogListView(this);
51 messageView->setModel(m_messageFilterModel);
52 messageView->setContextMenuPolicy(Qt::CustomContextMenu);
53 connect(messageView, &LogListView::customContextMenuRequested, this, [this, messageView, messageModel](const QPoint &pos)
54 {
55 displayContextMenu(pos, messageView, messageModel);
56 });
57
58 LogPeerModel *peerModel = new LogPeerModel(this);
59 LogListView *peerView = new LogListView(this);
60 peerView->setModel(peerModel);
61 peerView->setContextMenuPolicy(Qt::CustomContextMenu);
62 connect(peerView, &LogListView::customContextMenuRequested, this, [this, peerView, peerModel](const QPoint &pos)
63 {
64 displayContextMenu(pos, peerView, peerModel);
65 });
66
67 m_ui->tabGeneral->layout()->addWidget(messageView);
68 m_ui->tabBan->layout()->addWidget(peerView);
69
70 #ifndef Q_OS_MACOS
71 m_ui->tabConsole->setTabIcon(0, UIThemeManager::instance()->getIcon("view-calendar-journal"));
72 m_ui->tabConsole->setTabIcon(1, UIThemeManager::instance()->getIcon("view-filter"));
73 #endif
74 }
75
~ExecutionLogWidget()76 ExecutionLogWidget::~ExecutionLogWidget()
77 {
78 delete m_ui;
79 }
80
setMessageTypes(const Log::MsgTypes types)81 void ExecutionLogWidget::setMessageTypes(const Log::MsgTypes types)
82 {
83 m_messageFilterModel->setMessageTypes(types);
84 }
85
displayContextMenu(const QPoint & pos,const LogListView * view,const BaseLogModel * model) const86 void ExecutionLogWidget::displayContextMenu(const QPoint &pos, const LogListView *view, const BaseLogModel *model) const
87 {
88 QMenu *menu = new QMenu;
89 menu->setAttribute(Qt::WA_DeleteOnClose);
90
91 // only show copy action if any of the row is selected
92 if (view->currentIndex().isValid())
93 {
94 menu->addAction(UIThemeManager::instance()->getIcon("edit-copy"), tr("Copy")
95 , view, &LogListView::copySelection);
96 }
97
98 menu->addAction(UIThemeManager::instance()->getIcon("edit-clear"), tr("Clear")
99 , model, &BaseLogModel::reset);
100
101 menu->popup(view->mapToGlobal(pos));
102 }
103