1 /* 2 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 3 4 SPDX-FileCopyrightText: 2010 Eike Hein <hein@kde.org> 5 */ 6 7 #ifndef IRCCONTEXTMENUS_H 8 #define IRCCONTEXTMENUS_H 9 10 #include <QIcon> 11 #include <QObject> 12 #include <QPoint> 13 14 15 16 17 class Server; 18 19 class QAction; 20 21 class QMenu; 22 23 24 class IrcContextMenus : public QObject 25 { 26 Q_OBJECT 27 28 public: 29 enum ActionId 30 { 31 TextCopy, TextSelectAll, 32 LinkOpenWith, LinkCopy, LinkBookmark, LinkSaveAs, 33 Join, Topic, Names, 34 OpenQuery, 35 Whois, Version, Ping, 36 GiveOp, TakeOp, GiveHalfOp, TakeHalfOp, GiveVoice, TakeVoice, 37 Kick, KickBan, BanNick, BanHost, BanDomain, BanUserHost, BanUserDomain, 38 KickBanHost, KickBanDomain, KickBanUserHost, KickBanUserDomain, 39 IgnoreNick, UnignoreNick, 40 AddNotify, RemoveNotify, 41 DccSend, StartDccChat, StartDccWhiteboard, 42 }; 43 44 enum MenuOption 45 { 46 NoOptions = 0x00000000, 47 ShowTitle = 0x00000001, 48 ShowLinkActions = 0x00000002, 49 ShowFindAction = 0x00000004, 50 ShowNickActions = 0x00000008, 51 ShowChannelActions = 0x00000010, 52 ShowLogAction = 0x00000020 53 54 }; 55 Q_DECLARE_FLAGS(MenuOptions, MenuOption) 56 57 ~IrcContextMenus() override = default; 58 59 static void setupUi(QWidget* parent); 60 61 static int textMenu(const QPoint& pos, MenuOptions options, Server* server, 62 const QString& selectedText, const QString& link, const QString& nick = QString()); 63 64 static void channelMenu(const QPoint& pos, Server* server, const QString& channel); 65 66 static void nickMenu(const QPoint& pos, MenuOptions options, Server* server, 67 const QStringList& nicks, const QString& context); 68 static void processNickAction(int actionId, Server* server, const QStringList& nicks, 69 const QString& context); 70 71 static void processLinkAction(int actionId, const QString& link); 72 73 static void topicHistoryMenu(const QPoint& pos, Server* server, const QString& text, 74 const QString& author); 75 76 77 private Q_SLOTS: 78 void processWebShortcutAction(); 79 void configureWebShortcuts(); 80 void updateQuickButtonMenu(); 81 82 83 private: 84 static IrcContextMenus* self(); 85 void doSetupUi(QWidget* parent); 86 87 explicit IrcContextMenus(); 88 friend class IrcContextMenusPrivate; 89 90 void setupQuickButtonMenu(); 91 bool shouldShowQuickButtonMenu(); 92 static void processQuickButtonAction(QAction* action, Server* server, const QString& context, 93 const QStringList &nicks = QStringList()); 94 95 void setupTextMenu(); 96 void updateWebShortcutsMenu(const QString& selectedText); 97 98 void setupChannelMenu(); 99 100 void setupNickMenu(); 101 void createSharedBasicNickActions(); 102 void createSharedNickSettingsActions(); 103 static void updateSharedNickSettingsActions(Server* server, const QStringList& nicks); 104 void createSharedDccActions(); 105 106 void setupTopicHistoryMenu(); 107 108 inline QAction* createAction(ActionId id, const QString& text); 109 inline QAction* createAction(ActionId id, const QIcon& icon); 110 inline QAction* createAction(ActionId id, const QIcon& icon, const QString& text); 111 inline QAction* createAction(QMenu* menu, ActionId id, const QString& text); 112 inline QAction* createAction(QMenu* menu, ActionId id, const QIcon& icon, 113 const QString& text); 114 115 static int extractActionId(QAction* action); 116 117 static void commandToServer(Server* server, const QString& command, 118 const QString& destination = QString()); 119 static inline void commandToServer(Server* server, const QString& command, 120 const QStringList& arguments, const QString& destination = QString()); 121 122 private: 123 QWidget* m_parent; 124 QMenu* m_quickButtonMenu; 125 QMenu* m_textMenu; 126 QAction* m_textCopyAction; 127 QAction* m_textActionsSeparator; 128 QList<QAction*> m_linkActions; 129 QMenu* m_webShortcutsMenu; 130 QMenu* m_channelMenu; 131 QMenu* m_nickMenu; 132 QList<QAction*> m_sharedBasicNickActions; 133 QMenu* m_modesMenu; 134 QMenu* m_kickBanMenu; 135 QList<QAction*> m_sharedNickSettingsActions; 136 QAction* m_ignoreAction; 137 QAction* m_unignoreAction; 138 QAction* m_addNotifyAction; 139 QAction* m_removeNotifyAction; 140 QList<QAction*> m_sharedDccActions; 141 QMenu* m_topicHistoryMenu; 142 QAction* m_queryTopicAuthorAction; 143 144 Q_DISABLE_COPY(IrcContextMenus) 145 }; 146 147 Q_DECLARE_OPERATORS_FOR_FLAGS(IrcContextMenus::MenuOptions) 148 149 #endif 150