1 /***************************************************************************
2 * Copyright (C) 2005-2022 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
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 *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "chatmonitorview.h"
24 #include <QContextMenuEvent>
28 #include "buffermodel.h"
30 #include "chatlinemodel.h"
31 #include "chatmonitorfilter.h"
32 #include "chatscene.h"
34 #include "clientignorelistmanager.h"
36 #include "messagemodel.h"
37 #include "networkmodel.h"
38 #include "qtuisettings.h"
39 #include "settingspagedlg.h"
41 #include "settingspages/chatmonitorsettingspage.h"
43 ChatMonitorView::ChatMonitorView(ChatMonitorFilter* filter, QWidget* parent)
44 : ChatView(filter, parent)
47 scene()->setSenderCutoffMode(ChatScene::CutoffLeft);
48 // The normal message prefixes get replaced by the network and buffer name. Re-add brackets for
50 scene()->setAlwaysBracketSender(true);
51 connect(Client::instance(), &Client::coreConnectionStateChanged, this, &ChatMonitorView::coreConnectionStateChanged);
54 void ChatMonitorView::addActionsToMenu(QMenu* menu, const QPointF& pos)
56 ChatView::addActionsToMenu(menu, pos);
58 auto showOwnNicksAction = new Action(tr("Show Own Messages"), menu, _filter, &ChatMonitorFilter::setShowOwnMessages);
59 showOwnNicksAction->setCheckable(true);
60 showOwnNicksAction->setChecked(_filter->showOwnMessages());
61 menu->addAction(showOwnNicksAction);
63 if (scene()->columnByScenePos(pos) == ChatLineModel::SenderColumn) {
66 auto showNetworkAction = new Action(tr("Show Network Name"), menu, this, &ChatMonitorView::showFieldsChanged);
67 showNetworkAction->setCheckable(true);
68 showNetworkAction->setChecked(_filter->showFields() & ChatMonitorFilter::NetworkField);
69 showNetworkAction->setData(ChatMonitorFilter::NetworkField);
70 menu->addAction(showNetworkAction);
72 auto showBufferAction = new Action(tr("Show Buffer Name"), menu, this, &ChatMonitorView::showFieldsChanged);
73 showBufferAction->setCheckable(true);
74 showBufferAction->setChecked(_filter->showFields() & ChatMonitorFilter::BufferField);
75 showBufferAction->setData(ChatMonitorFilter::BufferField);
76 menu->addAction(showBufferAction);
80 menu->addAction(new Action(icon::get("configure"), tr("Configure..."), menu, this, &ChatMonitorView::showSettingsPage));
83 void ChatMonitorView::mouseDoubleClickEvent(QMouseEvent* event)
85 if (scene()->columnByScenePos(event->pos()) != ChatLineModel::SenderColumn) {
86 ChatView::mouseDoubleClickEvent(event);
90 ChatItem* chatItem = scene()->chatItemAt(mapToScene(event->pos()));
97 BufferId bufferId = chatItem->data(MessageModel::BufferIdRole).value<BufferId>();
98 if (!bufferId.isValid())
101 Client::bufferModel()->switchToBuffer(bufferId);
104 void ChatMonitorView::showFieldsChanged(bool checked)
106 auto* showAction = qobject_cast<QAction*>(sender());
111 _filter->addShowField(showAction->data().toInt());
113 _filter->removeShowField(showAction->data().toInt());
116 void ChatMonitorView::showSettingsPage()
118 SettingsPageDlg dlg(new ChatMonitorSettingsPage(), this);
122 // connect only after client is synced to core since ChatMonitorView is created before
123 // the ignoreListManager
124 void ChatMonitorView::coreConnectionStateChanged(bool connected)
127 connect(Client::ignoreListManager(), &ClientIgnoreListManager::ignoreListChanged, _filter, &ChatMonitorFilter::invalidateFilter);