Reformat ALL the source!
[quassel.git] / src / core / corebasichandler.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-09 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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #include "corebasichandler.h"
21
22 #include "util.h"
23 #include "logger.h"
24
25 CoreBasicHandler::CoreBasicHandler(CoreNetwork *parent)
26     : BasicHandler(parent),
27     _network(parent)
28 {
29     connect(this, SIGNAL(displayMsg(Message::Type, BufferInfo::Type, const QString &, const QString &, const QString &, Message::Flags)),
30         network(), SLOT(displayMsg(Message::Type, BufferInfo::Type, const QString &, const QString &, const QString &, Message::Flags)));
31
32     connect(this, SIGNAL(putCmd(QString, const QList<QByteArray> &, const QByteArray &)),
33         network(), SLOT(putCmd(QString, const QList<QByteArray> &, const QByteArray &)));
34
35     connect(this, SIGNAL(putRawLine(const QByteArray &)),
36         network(), SLOT(putRawLine(const QByteArray &)));
37 }
38
39
40 QString CoreBasicHandler::serverDecode(const QByteArray &string)
41 {
42     return network()->serverDecode(string);
43 }
44
45
46 QStringList CoreBasicHandler::serverDecode(const QList<QByteArray> &stringlist)
47 {
48     QStringList list;
49     foreach(QByteArray s, stringlist) list << network()->serverDecode(s);
50     return list;
51 }
52
53
54 QString CoreBasicHandler::channelDecode(const QString &bufferName, const QByteArray &string)
55 {
56     return network()->channelDecode(bufferName, string);
57 }
58
59
60 QStringList CoreBasicHandler::channelDecode(const QString &bufferName, const QList<QByteArray> &stringlist)
61 {
62     QStringList list;
63     foreach(QByteArray s, stringlist) list << network()->channelDecode(bufferName, s);
64     return list;
65 }
66
67
68 QString CoreBasicHandler::userDecode(const QString &userNick, const QByteArray &string)
69 {
70     return network()->userDecode(userNick, string);
71 }
72
73
74 QStringList CoreBasicHandler::userDecode(const QString &userNick, const QList<QByteArray> &stringlist)
75 {
76     QStringList list;
77     foreach(QByteArray s, stringlist) list << network()->userDecode(userNick, s);
78     return list;
79 }
80
81
82 /*** ***/
83
84 QByteArray CoreBasicHandler::serverEncode(const QString &string)
85 {
86     return network()->serverEncode(string);
87 }
88
89
90 QList<QByteArray> CoreBasicHandler::serverEncode(const QStringList &stringlist)
91 {
92     QList<QByteArray> list;
93     foreach(QString s, stringlist) list << network()->serverEncode(s);
94     return list;
95 }
96
97
98 QByteArray CoreBasicHandler::channelEncode(const QString &bufferName, const QString &string)
99 {
100     return network()->channelEncode(bufferName, string);
101 }
102
103
104 QList<QByteArray> CoreBasicHandler::channelEncode(const QString &bufferName, const QStringList &stringlist)
105 {
106     QList<QByteArray> list;
107     foreach(QString s, stringlist) list << network()->channelEncode(bufferName, s);
108     return list;
109 }
110
111
112 QByteArray CoreBasicHandler::userEncode(const QString &userNick, const QString &string)
113 {
114     return network()->userEncode(userNick, string);
115 }
116
117
118 QList<QByteArray> CoreBasicHandler::userEncode(const QString &userNick, const QStringList &stringlist)
119 {
120     QList<QByteArray> list;
121     foreach(QString s, stringlist) list << network()->userEncode(userNick, s);
122     return list;
123 }
124
125
126 // ====================
127 //  protected:
128 // ====================
129 BufferInfo::Type CoreBasicHandler::typeByTarget(const QString &target) const
130 {
131     if (target.isEmpty())
132         return BufferInfo::StatusBuffer;
133
134     if (network()->isChannelName(target))
135         return BufferInfo::ChannelBuffer;
136
137     return BufferInfo::QueryBuffer;
138 }
139
140
141 void CoreBasicHandler::putCmd(const QString &cmd, const QByteArray &param, const QByteArray &prefix)
142 {
143     QList<QByteArray> list;
144     list << param;
145     emit putCmd(cmd, list, prefix);
146 }
147
148
149 void CoreBasicHandler::displayMsg(Message::Type msgType, QString target, const QString &text, const QString &sender, Message::Flags flags)
150 {
151     IrcChannel *channel = network()->ircChannel(target);
152     if (!channel) {
153         if (!target.isEmpty() && network()->prefixes().contains(target[0]))
154             target = target.mid(1);
155
156         if (target.startsWith('$') || target.startsWith('#'))
157             target = nickFromMask(sender);
158     }
159
160     emit displayMsg(msgType, typeByTarget(target), target, text, sender, flags);
161 }