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 ***************************************************************************/
23 #include "uisupport-export.h"
27 #include "networkmodelcontroller.h"
29 class UISUPPORT_EXPORT ContextMenuActionProvider : public NetworkModelController
34 ContextMenuActionProvider(QObject* parent = nullptr);
35 ~ContextMenuActionProvider() override;
37 //! Provide a list of actions applying to the given item
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
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
49 template<typename Receiver, typename Slot>
50 void addActions(QMenu* menu, const QModelIndex& index, Receiver* receiver, Slot slot, bool isCustomBufferView = false)
52 addActions(menu, index, buildActionSlot(receiver, std::move(slot)), isCustomBufferView);
54 void addActions(QMenu* menu, const QModelIndex& index, ActionSlot = {}, bool isCustomBufferView = false);
56 template<typename Receiver, typename Slot>
57 void addActions(QMenu* menu, const QList<QModelIndex>& indexList, Receiver* receiver, Slot slot, bool isCustomBufferView = false)
59 addActions(menu, indexList, buildActionSlot(receiver, std::move(slot)), isCustomBufferView);
61 void addActions(QMenu* menu, const QList<QModelIndex>& indexList, ActionSlot = {}, bool isCustomBufferView = false);
63 template<typename Receiver, typename Slot>
64 void addActions(QMenu* menu, BufferId id, Receiver* receiver, Slot slot)
66 addActions(menu, id, buildActionSlot(receiver, std::move(slot)));
68 void addActions(QMenu* menu, BufferId id, ActionSlot = {});
70 template<typename Receiver, typename Slot>
71 void addActions(QMenu* menu, MessageFilter* filter, BufferId msgBuffer, Receiver* receiver, Slot slot)
73 addActions(menu, filter, msgBuffer, buildActionSlot(receiver, std::move(slot)));
75 void addActions(QMenu* menu, MessageFilter* filter, BufferId msgBuffer, ActionSlot = {});
77 template<typename Receiver, typename Slot>
78 void addActions(QMenu* menu, MessageFilter* filter, BufferId msgBuffer, const QString& chanOrNick, Receiver* receiver, Slot slot)
80 addActions(menu, filter, msgBuffer, chanOrNick, buildActionSlot(receiver, std::move(slot)));
82 void addActions(QMenu* menu, MessageFilter* filter, BufferId msgBuffer, const QString& chanOrNick, ActionSlot = {});
85 void addActions(QMenu* menu,
86 const QList<QModelIndex>& indexList,
87 MessageFilter* filter,
88 const QString& chanOrNick,
89 ActionSlot actionSlot,
90 bool isCustomBufferView);
92 Action* addAction(ActionType, QMenu*, bool condition = true);
93 Action* addAction(Action*, QMenu*, bool condition = true);
94 Action* addAction(ActionType,
96 const QModelIndex& index,
97 ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState | InactiveState));
98 Action* addAction(Action*,
100 const QModelIndex& index,
101 ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState | InactiveState));
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);
108 void addNetworkItemActions(QMenu*, const QModelIndex&);
109 void addBufferItemActions(QMenu*, const QModelIndex&, bool isCustomBufferView = false);
110 void addIrcUserActions(QMenu*, const QModelIndex&);
112 Action* _hideEventsMenuAction;
113 Action* _nickCtcpMenuAction;
114 Action* _nickModeMenuAction;
115 Action* _nickIgnoreMenuAction;
116 QList<QAction*> _ignoreDescriptions;