qa: Replace deprecated qVariantFromValue() by QVariant::fromValue()
[quassel.git] / src / core / corebasichandler.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2019 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 COREBASICHANDLER_H
22 #define COREBASICHANDLER_H
23
24 #include <QString>
25 #include <QStringList>
26
27 #include "basichandler.h"
28 #include "corenetwork.h"
29 #include "message.h"
30
31 class CoreSession;
32
33 class CoreBasicHandler : public BasicHandler
34 {
35     Q_OBJECT
36
37 public:
38     CoreBasicHandler(CoreNetwork* parent = nullptr);
39
40     QString serverDecode(const QByteArray& string);
41     QStringList serverDecode(const QList<QByteArray>& stringlist);
42     QString channelDecode(const QString& bufferName, const QByteArray& string);
43     QStringList channelDecode(const QString& bufferName, const QList<QByteArray>& stringlist);
44     QString userDecode(const QString& userNick, const QByteArray& string);
45     QStringList userDecode(const QString& userNick, const QList<QByteArray>& stringlist);
46
47     QByteArray serverEncode(const QString& string);
48     QList<QByteArray> serverEncode(const QStringList& stringlist);
49     QByteArray channelEncode(const QString& bufferName, const QString& string);
50     QList<QByteArray> channelEncode(const QString& bufferName, const QStringList& stringlist);
51     QByteArray userEncode(const QString& userNick, const QString& string);
52     QList<QByteArray> userEncode(const QString& userNick, const QStringList& stringlist);
53
54 signals:
55     void displayMsg(const NetworkInternalMessage& msg);
56
57     /**
58      * Sends the raw (encoded) line, adding to the queue if needed, optionally with higher priority.
59      *
60      * @see CoreNetwork::putRawLine()
61      */
62     void putRawLine(const QByteArray& msg, bool prepend = false);
63
64     /**
65      * Sends the command with encoded parameters, with optional prefix or high priority.
66      *
67      * @see CoreNetwork::putCmd(const QString &cmd, const QList<QByteArray> &params, const QByteArray &prefix = QByteArray(), const
68      * QHash<IrcTagKey, QString>& tags = {}, bool prepend = false)
69      */
70     void putCmd(const QString& cmd, const QList<QByteArray>& params, const QByteArray& prefix = {}, const QHash<IrcTagKey, QString>& tags = {}, bool prepend = false);
71
72     /**
73      * Sends the command for each set of encoded parameters, with optional prefix or high priority.
74      *
75      * @see CoreNetwork::putCmd(const QString &cmd, const QList<QList<QByteArray>> &params, const QByteArray &prefix = QByteArray(), const
76      * QHash<IrcTagKey, QString>& tags = {}, bool prepend = false)
77      */
78     void putCmd(const QString& cmd, const QList<QList<QByteArray>>& params, const QByteArray& prefix = {}, const QHash<IrcTagKey, QString>& tags = {}, bool prepend = false);
79
80 protected:
81     /**
82      * Sends the command with one parameter, with optional prefix or high priority.
83      *
84      * @param[in] cmd      Command to send, ignoring capitalization
85      * @param[in] param    Parameter for the command, encoded within a QByteArray
86      * @param[in] prefix   Optional command prefix
87      * @param[in] tags     Optional command tags
88      * @param[in] prepend
89      * @parmblock
90      * If true, the command is prepended into the start of the queue, otherwise, it's appended to
91      * the end.  This should be used sparingly, for if either the core or the IRC server cannot
92      * maintain PING/PONG replies, the other side will close the connection.
93      * @endparmblock
94      */
95     void putCmd(const QString& cmd, const QByteArray& param, const QByteArray& prefix = QByteArray(), const QHash<IrcTagKey, QString>& tags = {}, bool prepend = false);
96
97     inline CoreNetwork* network() const { return _network; }
98     inline CoreSession* coreSession() const { return _network->coreSession(); }
99
100     BufferInfo::Type typeByTarget(const QString& target) const;
101
102 private:
103     CoreNetwork* _network;
104 };
105
106 #endif