modernize: Replace most remaining old-style connects by PMF ones
[quassel.git] / src / core / corebasichandler.cpp
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 #include "corebasichandler.h"
22
23 #include "util.h"
24 #include "logmessage.h"
25
26 CoreBasicHandler::CoreBasicHandler(CoreNetwork *parent)
27     : BasicHandler(parent),
28     _network(parent)
29 {
30     connect(this, &CoreBasicHandler::displayMsg, network(), &CoreNetwork::onDisplayMsg);
31     connect(this, &CoreBasicHandler::putRawLine, network(), &CoreNetwork::putRawLine);
32     connect(this,      selectOverload<const QString&, const QList<QByteArray>&, const QByteArray&, bool>(&CoreBasicHandler::putCmd),
33             network(), selectOverload<const QString&, const QList<QByteArray>&, const QByteArray&, bool>(&CoreNetwork::putCmd));
34     connect(this,      selectOverload<const QString&, const QList<QList<QByteArray>>&, const QByteArray&, bool>(&CoreBasicHandler::putCmd),
35             network(), selectOverload<const QString&, const QList<QList<QByteArray>>&, const QByteArray&, bool>(&CoreNetwork::putCmd));
36 }
37
38
39 QString CoreBasicHandler::serverDecode(const QByteArray &string)
40 {
41     return network()->serverDecode(string);
42 }
43
44
45 QStringList CoreBasicHandler::serverDecode(const QList<QByteArray> &stringlist)
46 {
47     QStringList list;
48     foreach(QByteArray s, stringlist) list << network()->serverDecode(s);
49     return list;
50 }
51
52
53 QString CoreBasicHandler::channelDecode(const QString &bufferName, const QByteArray &string)
54 {
55     return network()->channelDecode(bufferName, string);
56 }
57
58
59 QStringList CoreBasicHandler::channelDecode(const QString &bufferName, const QList<QByteArray> &stringlist)
60 {
61     QStringList list;
62     foreach(QByteArray s, stringlist) list << network()->channelDecode(bufferName, s);
63     return list;
64 }
65
66
67 QString CoreBasicHandler::userDecode(const QString &userNick, const QByteArray &string)
68 {
69     return network()->userDecode(userNick, string);
70 }
71
72
73 QStringList CoreBasicHandler::userDecode(const QString &userNick, const QList<QByteArray> &stringlist)
74 {
75     QStringList list;
76     foreach(QByteArray s, stringlist) list << network()->userDecode(userNick, s);
77     return list;
78 }
79
80
81 /*** ***/
82
83 QByteArray CoreBasicHandler::serverEncode(const QString &string)
84 {
85     return network()->serverEncode(string);
86 }
87
88
89 QList<QByteArray> CoreBasicHandler::serverEncode(const QStringList &stringlist)
90 {
91     QList<QByteArray> list;
92     foreach(QString s, stringlist) list << network()->serverEncode(s);
93     return list;
94 }
95
96
97 QByteArray CoreBasicHandler::channelEncode(const QString &bufferName, const QString &string)
98 {
99     return network()->channelEncode(bufferName, string);
100 }
101
102
103 QList<QByteArray> CoreBasicHandler::channelEncode(const QString &bufferName, const QStringList &stringlist)
104 {
105     QList<QByteArray> list;
106     foreach(QString s, stringlist) list << network()->channelEncode(bufferName, s);
107     return list;
108 }
109
110
111 QByteArray CoreBasicHandler::userEncode(const QString &userNick, const QString &string)
112 {
113     return network()->userEncode(userNick, string);
114 }
115
116
117 QList<QByteArray> CoreBasicHandler::userEncode(const QString &userNick, const QStringList &stringlist)
118 {
119     QList<QByteArray> list;
120     foreach(QString s, stringlist) list << network()->userEncode(userNick, s);
121     return list;
122 }
123
124
125 // ====================
126 //  protected:
127 // ====================
128 BufferInfo::Type CoreBasicHandler::typeByTarget(const QString &target) const
129 {
130     if (target.isEmpty())
131         return BufferInfo::StatusBuffer;
132
133     if (network()->isChannelName(target))
134         return BufferInfo::ChannelBuffer;
135
136     return BufferInfo::QueryBuffer;
137 }
138
139
140 void CoreBasicHandler::putCmd(const QString &cmd, const QByteArray &param, const QByteArray &prefix, const bool prepend)
141 {
142     QList<QByteArray> list;
143     list << param;
144     emit putCmd(cmd, list, prefix, prepend);
145 }