1 /***************************************************************************
2 * Copyright (C) 2005-2018 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"
25 #include <QContextMenuEvent>
28 #include "buffermodel.h"
29 #include "chatmonitorfilter.h"
30 #include "chatlinemodel.h"
32 #include "chatscene.h"
34 #include "clientignorelistmanager.h"
36 #include "networkmodel.h"
37 #include "messagemodel.h"
38 #include "qtuisettings.h"
39 #include "settingspagedlg.h"
40 #include "settingspages/chatmonitorsettingspage.h"
42 ChatMonitorView::ChatMonitorView(ChatMonitorFilter *filter, QWidget *parent)
43 : ChatView(filter, parent),
46 scene()->setSenderCutoffMode(ChatScene::CutoffLeft);
47 // The normal message prefixes get replaced by the network and buffer name. Re-add brackets for
49 scene()->setAlwaysBracketSender(true);
50 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, SLOT(setShowOwnMessages(bool)));
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, SLOT(showFieldsChanged(bool)));
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, SLOT(showFieldsChanged(bool)));
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, SLOT(showSettingsPage())));
84 void ChatMonitorView::mouseDoubleClickEvent(QMouseEvent *event)
86 if (scene()->columnByScenePos(event->pos()) != ChatLineModel::SenderColumn) {
87 ChatView::mouseDoubleClickEvent(event);
91 ChatItem *chatItem = scene()->chatItemAt(mapToScene(event->pos()));
98 BufferId bufferId = chatItem->data(MessageModel::BufferIdRole).value<BufferId>();
99 if (!bufferId.isValid())
102 Client::bufferModel()->switchToBuffer(bufferId);
106 void ChatMonitorView::showFieldsChanged(bool checked)
108 auto *showAction = qobject_cast<QAction *>(sender());
113 _filter->addShowField(showAction->data().toInt());
115 _filter->removeShowField(showAction->data().toInt());
119 void ChatMonitorView::showSettingsPage()
121 SettingsPageDlg dlg(new ChatMonitorSettingsPage(), this);
126 // connect only after client is synced to core since ChatMonitorView is created before
127 // the ignoreListManager
128 void ChatMonitorView::coreConnectionStateChanged(bool connected)
131 connect(Client::ignoreListManager(), &ClientIgnoreListManager::ignoreListChanged, _filter, &ChatMonitorFilter::invalidateFilter);