Sync last message id per buffer
[quassel.git] / src / uisupport / contextmenuactionprovider.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2020 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
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                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #pragma once
22
23 #include "uisupport-export.h"
24
25 #include <functional>
26
27 #include "networkmodelcontroller.h"
28
29 class UISUPPORT_EXPORT ContextMenuActionProvider : public NetworkModelController
30 {
31     Q_OBJECT
32
33 public:
34     ContextMenuActionProvider(QObject* parent = nullptr);
35     ~ContextMenuActionProvider() override;
36
37     //! Provide a list of actions applying to the given item
38     /**
39      * Note that this list ist not persistent, hence it should only be used immediately after
40      * calling this function (e.g. in a context menu). Optionally one can provide a QObject and a slot
41      * (that should take a QAction * as parameter) that is invoked for actions that require external
42      * handling.
43      * @param index The item index in the NetworkModel
44      * @param receiver The optional object that is notified for actions that need to be handled externally.
45      *                 The action type will be stored in the QAction's data().
46      * @param slot     The receiving slot
47      * @return A list of actions applying to the given item
48      */
49     template<typename Receiver, typename Slot>
50     void addActions(QMenu* menu, const QModelIndex& index, Receiver* receiver, Slot slot, bool isCustomBufferView = false)
51     {
52         addActions(menu, index, buildActionSlot(receiver, std::move(slot)), isCustomBufferView);
53     }
54     void addActions(QMenu* menu, const QModelIndex& index, ActionSlot = {}, bool isCustomBufferView = false);
55
56     template<typename Receiver, typename Slot>
57     void addActions(QMenu* menu, const QList<QModelIndex>& indexList, Receiver* receiver, Slot slot, bool isCustomBufferView = false)
58     {
59         addActions(menu, indexList, buildActionSlot(receiver, std::move(slot)), isCustomBufferView);
60     }
61     void addActions(QMenu* menu, const QList<QModelIndex>& indexList, ActionSlot = {}, bool isCustomBufferView = false);
62
63     template<typename Receiver, typename Slot>
64     void addActions(QMenu* menu, BufferId id, Receiver* receiver, Slot slot)
65     {
66         addActions(menu, id, buildActionSlot(receiver, std::move(slot)));
67     }
68     void addActions(QMenu* menu, BufferId id, ActionSlot = {});
69
70     template<typename Receiver, typename Slot>
71     void addActions(QMenu* menu, MessageFilter* filter, BufferId msgBuffer, Receiver* receiver, Slot slot)
72     {
73         addActions(menu, filter, msgBuffer, buildActionSlot(receiver, std::move(slot)));
74     }
75     void addActions(QMenu* menu, MessageFilter* filter, BufferId msgBuffer, ActionSlot = {});
76
77     template<typename Receiver, typename Slot>
78     void addActions(QMenu* menu, MessageFilter* filter, BufferId msgBuffer, const QString& chanOrNick, Receiver* receiver, Slot slot)
79     {
80         addActions(menu, filter, msgBuffer, chanOrNick, buildActionSlot(receiver, std::move(slot)));
81     }
82     void addActions(QMenu* menu, MessageFilter* filter, BufferId msgBuffer, const QString& chanOrNick, ActionSlot = {});
83
84 private:
85     void addActions(QMenu* menu,
86                     const QList<QModelIndex>& indexList,
87                     MessageFilter* filter,
88                     const QString& chanOrNick,
89                     ActionSlot actionSlot,
90                     bool isCustomBufferView);
91
92     Action* addAction(ActionType, QMenu*, bool condition = true);
93     Action* addAction(Action*, QMenu*, bool condition = true);
94     Action* addAction(ActionType,
95                       QMenu*,
96                       const QModelIndex& index,
97                       ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState | InactiveState));
98     Action* addAction(Action*,
99                       QMenu*,
100                       const QModelIndex& index,
101                       ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState | InactiveState));
102
103     void addHideEventsMenu(QMenu*, BufferId bufferId);
104     void addHideEventsMenu(QMenu*, MessageFilter* msgFilter);
105     void addHideEventsMenu(QMenu*, int filter = -1);
106     void addIgnoreMenu(QMenu* menu, const QString& hostmask, const QMap<QString, bool>& ignoreMap);
107
108     void addNetworkItemActions(QMenu*, const QModelIndex&);
109     void addBufferItemActions(QMenu*, const QModelIndex&, bool isCustomBufferView = false);
110     void addIrcUserActions(QMenu*, const QModelIndex&);
111
112     Action* _hideEventsMenuAction;
113     Action* _nickCtcpMenuAction;
114     Action* _nickModeMenuAction;
115     Action* _nickIgnoreMenuAction;
116     QList<QAction*> _ignoreDescriptions;
117 };