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