cmake: avoid de-duplication of user's CXXFLAGS
[quassel.git] / src / core / coreuserinputhandler.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 <utility>
24
25 #include "corebasichandler.h"
26 #include "corenetwork.h"
27
28 class Cipher;
29 class Server;
30
31 class CoreUserInputHandler : public CoreBasicHandler
32 {
33     Q_OBJECT
34
35 public:
36     CoreUserInputHandler(CoreNetwork* parent = nullptr);
37     inline CoreNetwork* coreNetwork() const { return qobject_cast<CoreNetwork*>(parent()); }
38
39     void handleUserInput(const BufferInfo& bufferInfo, const QString& text);
40     int lastParamOverrun(const QString& cmd, const QList<QByteArray>& params);
41
42 public slots:
43     /**
44      * Handle the away command, marking as away or unaway
45      *
46      * Applies to the current network unless text begins with "-all".
47      *
48      * @param[in] bufferInfo      Currently active buffer
49      * @param[in] text            Away message, or blank to set unaway
50      * @param[in] skipFormatting  If true, skip timestamp formatting codes (e.g. if already done)
51      */
52     void handleAway(const BufferInfo& bufferInfo, const QString& text, const bool skipFormatting = false);
53     void handleBan(const BufferInfo& bufferInfo, const QString& text);
54     void handleUnban(const BufferInfo& bufferInfo, const QString& text);
55     void handleCtcp(const BufferInfo& bufferInfo, const QString& text);
56     void handleDelkey(const BufferInfo& bufferInfo, const QString& text);
57     void handleDeop(const BufferInfo& bufferInfo, const QString& nicks);
58     void handleDehalfop(const BufferInfo& bufferInfo, const QString& nicks);
59     void handleDevoice(const BufferInfo& bufferInfo, const QString& nicks);
60     void handleInvite(const BufferInfo& bufferInfo, const QString& text);
61     void handleJoin(const BufferInfo& bufferInfo, const QString& text);
62     void handleKeyx(const BufferInfo& bufferInfo, const QString& text);
63     void handleKick(const BufferInfo& bufferInfo, const QString& text);
64     void handleKill(const BufferInfo& bufferInfo, const QString& text);
65     void handleList(const BufferInfo& bufferInfo, const QString& text);
66     void handleMe(const BufferInfo& bufferInfo, const QString& text);
67     void handleMode(const BufferInfo& bufferInfo, const QString& text);
68     void handleMsg(const BufferInfo& bufferInfo, const QString& text);
69     void handleNick(const BufferInfo& bufferInfo, const QString& text);
70     void handleNotice(const BufferInfo& bufferInfo, const QString& text);
71     void handleOper(const BufferInfo& bufferInfo, const QString& text);
72     void handleOp(const BufferInfo& bufferInfo, const QString& nicks);
73     void handleHalfop(const BufferInfo& bufferInfo, const QString& nicks);
74     void handlePart(const BufferInfo& bufferInfo, const QString& text);
75     void handlePing(const BufferInfo& bufferInfo, const QString& text);
76     void handlePrint(const BufferInfo& bufferInfo, const QString& text);
77     void handleQuery(const BufferInfo& bufferInfo, const QString& text);
78     void handleQuit(const BufferInfo& bufferInfo, const QString& text);
79     void handleQuote(const BufferInfo& bufferInfo, const QString& text);
80     void handleSay(const BufferInfo& bufferInfo, const QString& text);
81     void handleSetkey(const BufferInfo& bufferInfo, const QString& text);
82     /**
83      * Handle the setname command, setting the user's realname
84      *
85      * @param bufferInfo  Currently active buffer
86      * @param text        New realname
87      */
88     void handleSetname(const BufferInfo& bufferInfo, const QString& text);
89     void handleShowkey(const BufferInfo& bufferInfo, const QString& text);
90     void handleTopic(const BufferInfo& bufferInfo, const QString& text);
91     void handleVoice(const BufferInfo& bufferInfo, const QString& text);
92     void handleWait(const BufferInfo& bufferInfo, const QString& text);
93     void handleWho(const BufferInfo& bufferInfo, const QString& text);
94     void handleWhois(const BufferInfo& bufferInfo, const QString& text);
95     void handleWhowas(const BufferInfo& bufferInfo, const QString& text);
96
97     void defaultHandler(QString cmd, const BufferInfo& bufferInfo, const QString& text);
98
99     /**
100      * Send a QUIT to the IRC server, optionally skipping the command queue.
101      *
102      * @param reason          Reason for quitting, often displayed to other IRC clients
103      * @param forceImmediate  Immediately quit, skipping queue of other commands
104      */
105     void issueQuit(const QString& reason, bool forceImmediate = false);
106
107     /**
108      * Issues the away command, marking as away or unaway on the current network
109      *
110      * @param[in] msg             Away message, or blank to set unaway
111      * @param[in] autoCheck       If true, always set away, defaulting to the identity away message
112      * @param[in] skipFormatting  If true, skip timestamp formatting codes (e.g. if already done)
113      */
114     void issueAway(const QString& msg, bool autoCheck = true, const bool skipFormatting = false);
115
116 protected:
117     void timerEvent(QTimerEvent* event) override;
118
119 private:
120     void doMode(const BufferInfo& bufferInfo, const QChar& addOrRemove, const QChar& mode, const QString& nickList);
121     void banOrUnban(const BufferInfo& bufferInfo, const QString& text, bool ban);
122     void putPrivmsg(const QString& target,
123                     const QString& message,
124                     std::function<QByteArray(const QString&, const QString&)> encodeFunc,
125                     Cipher* cipher = nullptr);
126
127 #ifdef HAVE_QCA2
128     QByteArray encrypt(const QString& target, const QByteArray& message, bool* didEncrypt = nullptr) const;
129 #endif
130
131     struct Command
132     {
133         BufferInfo bufferInfo;
134         QString command;
135         Command(BufferInfo info, QString command)
136             : bufferInfo(std::move(info))
137             , command(std::move(command))
138         {}
139         Command() = default;
140     };
141
142     QHash<int, Command> _delayedCommands;
143 };