Don't overwrite stored layout of main window with incorrect one
[qBittorrent.git] / src / gui / executionlogwidget.cpp
blobcd064139fee2822375b1876087762151f3f963ba
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2011 Christophe Dumez
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.
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.
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.
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.
29 #include "executionlogwidget.h"
31 #include <QDateTime>
32 #include <QMenu>
33 #include <QPalette>
35 #include "base/global.h"
36 #include "log/logfiltermodel.h"
37 #include "log/loglistview.h"
38 #include "log/logmodel.h"
39 #include "ui_executionlogwidget.h"
40 #include "uithememanager.h"
42 ExecutionLogWidget::ExecutionLogWidget(const Log::MsgTypes types, QWidget *parent)
43 : QWidget(parent)
44 , m_ui(new Ui::ExecutionLogWidget)
45 , m_messageFilterModel(new LogFilterModel(types, this))
47 m_ui->setupUi(this);
49 LogMessageModel *messageModel = new LogMessageModel(this);
50 m_messageFilterModel->setSourceModel(messageModel);
51 LogListView *messageView = new LogListView(this);
52 messageView->setModel(m_messageFilterModel);
53 messageView->setContextMenuPolicy(Qt::CustomContextMenu);
54 connect(messageView, &LogListView::customContextMenuRequested, this, [this, messageView, messageModel]()
56 displayContextMenu(messageView, messageModel);
57 });
59 LogPeerModel *peerModel = new LogPeerModel(this);
60 LogListView *peerView = new LogListView(this);
61 peerView->setModel(peerModel);
62 peerView->setContextMenuPolicy(Qt::CustomContextMenu);
63 connect(peerView, &LogListView::customContextMenuRequested, this, [this, peerView, peerModel]()
65 displayContextMenu(peerView, peerModel);
66 });
68 m_ui->tabGeneral->layout()->addWidget(messageView);
69 m_ui->tabBan->layout()->addWidget(peerView);
71 #ifndef Q_OS_MACOS
72 m_ui->tabConsole->setTabIcon(0, UIThemeManager::instance()->getIcon(u"help-contents"_s, u"view-calendar-journal"_s));
73 m_ui->tabConsole->setTabIcon(1, UIThemeManager::instance()->getIcon(u"ip-blocked"_s, u"view-filter"_s));
74 #endif
77 ExecutionLogWidget::~ExecutionLogWidget()
79 delete m_ui;
82 void ExecutionLogWidget::setMessageTypes(const Log::MsgTypes types)
84 m_messageFilterModel->setMessageTypes(types);
87 void ExecutionLogWidget::displayContextMenu(const LogListView *view, const BaseLogModel *model) const
89 QMenu *menu = new QMenu;
90 menu->setAttribute(Qt::WA_DeleteOnClose);
92 // only show copy action if any of the row is selected
93 if (view->currentIndex().isValid())
95 menu->addAction(UIThemeManager::instance()->getIcon(u"edit-copy"_s), tr("Copy")
96 , view, &LogListView::copySelection);
99 menu->addAction(UIThemeManager::instance()->getIcon(u"edit-clear"_s), tr("Clear")
100 , model, &BaseLogModel::reset);
102 menu->popup(QCursor::pos());