test: Add build system support and a main function for unit tests
[quassel.git] / src / uisupport / contextmenuactionprovider.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 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, const QList<QModelIndex> &indexList, MessageFilter *filter, const QString &chanOrNick, ActionSlot actionSlot, bool isCustomBufferView);
86
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));
91
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);
96
97     void addNetworkItemActions(QMenu *, const QModelIndex &);
98     void addBufferItemActions(QMenu *, const QModelIndex &, bool isCustomBufferView = false);
99     void addIrcUserActions(QMenu *, const QModelIndex &);
100
101     Action *_hideEventsMenuAction;
102     Action *_nickCtcpMenuAction;
103     Action *_nickModeMenuAction;
104     Action *_nickIgnoreMenuAction;
105     QList<QAction *> _ignoreDescriptions;
106 };