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, const QList<QModelIndex> &indexList, MessageFilter *filter, const QString &chanOrNick, ActionSlot actionSlot, bool isCustomBufferView);
87 Action *addAction(ActionType, QMenu *, bool condition = true);
88 Action *addAction(Action *, QMenu *, bool condition = true);
89 Action *addAction(ActionType, QMenu *, const QModelIndex &index, ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState | InactiveState));
90 Action *addAction(Action *, QMenu *, const QModelIndex &index, ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState | InactiveState));
92 void addHideEventsMenu(QMenu *, BufferId bufferId);
93 void addHideEventsMenu(QMenu *, MessageFilter *msgFilter);
94 void addHideEventsMenu(QMenu *, int filter = -1);
95 void addIgnoreMenu(QMenu *menu, const QString &hostmask, const QMap<QString, bool> &ignoreMap);
97 void addNetworkItemActions(QMenu *, const QModelIndex &);
98 void addBufferItemActions(QMenu *, const QModelIndex &, bool isCustomBufferView = false);
99 void addIrcUserActions(QMenu *, const QModelIndex &);
101 Action *_hideEventsMenuAction;
102 Action *_nickCtcpMenuAction;
103 Action *_nickModeMenuAction;
104 Action *_nickIgnoreMenuAction;
105 QList<QAction *> _ignoreDescriptions;