1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
25 #include "signalproxy.h"
26 #include "ircchannel.h"
31 IrcUser::IrcUser(const QString &hostmask, Network *network)
32 : SyncableObject(network),
34 _nick(nickFromMask(hostmask)),
35 _user(userFromMask(hostmask)),
36 _host(hostFromMask(hostmask)),
45 //qDebug() << nick() << "destroyed.";
48 // ====================
50 // ====================
51 bool IrcUser::initialized() const {
55 QString IrcUser::user() const {
59 QString IrcUser::host() const {
63 QString IrcUser::nick() const {
67 QString IrcUser::hostmask() const {
68 return QString("%1!%2@%3").arg(nick()).arg(user()).arg(host());
71 QString IrcUser::userModes() const {
75 QStringList IrcUser::channels() const {
78 foreach(channel, _channels) {
79 chanList << channel->name();
84 Network* IrcUser::network() const {
88 QTextCodec *IrcUser::codecForEncoding() const {
89 return _codecForEncoding;
92 void IrcUser::setCodecForEncoding(const QString &name) {
93 setCodecForEncoding(QTextCodec::codecForName(name.toAscii()));
96 void IrcUser::setCodecForEncoding(QTextCodec *codec) {
97 _codecForEncoding = codec;
100 QTextCodec *IrcUser::codecForDecoding() const {
101 return _codecForDecoding;
104 void IrcUser::setCodecForDecoding(const QString &name) {
105 setCodecForDecoding(QTextCodec::codecForName(name.toAscii()));
108 void IrcUser::setCodecForDecoding(QTextCodec *codec) {
109 _codecForDecoding = codec;
112 QString IrcUser::decodeString(const QByteArray &text) const {
113 if(!codecForDecoding()) return network()->decodeString(text);
114 return ::decodeString(text, codecForDecoding());
117 QByteArray IrcUser::encodeString(const QString string) const {
118 if(codecForEncoding()) {
119 return codecForEncoding()->fromUnicode(string);
121 return network()->encodeString(string);
124 // ====================
126 // ====================
127 void IrcUser::setUser(const QString &user) {
128 if(!user.isEmpty() && _user != user) {
134 void IrcUser::setHost(const QString &host) {
135 if(!host.isEmpty() && _host != host) {
141 void IrcUser::setNick(const QString &nick) {
142 if(!nick.isEmpty() && nick != _nick) {
149 void IrcUser::updateObjectName() {
150 QString newName = QString::number(network()->networkId()) + "/" + _nick;
151 QString oldName = objectName();
152 if(oldName != newName) {
153 setObjectName(newName);
154 emit renameObject(oldName, newName);
158 void IrcUser::updateHostmask(const QString &mask) {
159 if(mask == hostmask())
162 QString user = userFromMask(mask);
163 QString host = hostFromMask(mask);
168 void IrcUser::joinChannel(IrcChannel *channel) {
170 if(!_channels.contains(channel)) {
171 _channels.insert(channel);
173 connect(channel, SIGNAL(destroyed()), this, SLOT(channelDestroyed()));
174 emit channelJoined(channel->name());
178 void IrcUser::joinChannel(const QString &channelname) {
179 joinChannel(network()->newIrcChannel(channelname));
182 void IrcUser::partChannel(IrcChannel *channel) {
183 if(_channels.contains(channel)) {
184 _channels.remove(channel);
185 disconnect(channel, 0, this, 0);
187 emit channelParted(channel->name());
191 void IrcUser::partChannel(const QString &channelname) {
192 IrcChannel *channel = network()->ircChannel(channelname);
194 qWarning() << "IrcUser::partChannel(): received part for unknown Channel" << channelname;
196 partChannel(channel);
200 void IrcUser::channelDestroyed() {
202 IrcChannel *channel = static_cast<IrcChannel*>(sender());
204 if(_channels.contains(channel)) {
205 _channels.remove(channel);
206 disconnect(channel, 0, this, 0);
210 void IrcUser::setUserModes(const QString &modes) {
212 emit userModesSet(modes);
215 void IrcUser::addUserMode(const QString &mode) {
216 if(!_userModes.contains(mode)) {
218 emit userModeAdded(mode);
222 void IrcUser::removeUserMode(const QString &mode) {
223 if(_userModes.contains(mode)) {
224 _userModes.remove(mode);
225 emit userModeRemoved(mode);
229 void IrcUser::initSetChannels(const QStringList channels) {
230 foreach(QString channel, channels) {
231 joinChannel(channel);
235 void IrcUser::setInitialized() {