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