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