1 /***************************************************************************
2 * Copyright (C) 2005-07 by the Quassel IRC Team *
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 ***************************************************************************/
24 #include "networkinfo.h"
25 #include "signalproxy.h"
26 #include "ircchannel.h"
30 IrcUser::IrcUser(const QString &hostmask, NetworkInfo *networkinfo)
31 : QObject(networkinfo),
33 _nick(nickFromMask(hostmask)),
34 _user(userFromMask(hostmask)),
35 _host(hostFromMask(hostmask)),
36 networkInfo(networkinfo)
42 qDebug() << nick() << "destroyed.";
45 // ====================
47 // ====================
48 bool IrcUser::initialized() const {
52 QString IrcUser::user() const {
56 QString IrcUser::host() const {
60 QString IrcUser::nick() const {
64 QString IrcUser::hostmask() const {
65 return QString("%1!%2@%3").arg(nick()).arg(user()).arg(host());
68 QString IrcUser::userModes() const {
72 QStringList IrcUser::channels() const {
75 foreach(channel, _channels) {
76 chanList << channel->name();
81 // ====================
83 // ====================
84 void IrcUser::setUser(const QString &user) {
85 if(!user.isEmpty() && _user != user) {
91 void IrcUser::setHost(const QString &host) {
92 if(!host.isEmpty() && _host != host) {
98 void IrcUser::setNick(const QString &nick) {
99 if(!nick.isEmpty() && nick != _nick) {
100 QString oldnick(_nick);
107 void IrcUser::updateObjectName() {
108 QString oldName(objectName());
109 setObjectName(QString::number(networkInfo->networkId()) + "/" + _nick);
110 if(!oldName.isEmpty()) {
111 emit renameObject(oldName, objectName());
116 void IrcUser::updateHostmask(const QString &mask) {
117 if(mask == hostmask())
120 QString user = userFromMask(mask);
121 QString host = hostFromMask(mask);
126 void IrcUser::joinChannel(IrcChannel *channel) {
128 if(!_channels.contains(channel)) {
130 connect(channel, SIGNAL(destroyed()), this, SLOT(channelDestroyed()));
131 _channels.insert(channel);
132 emit channelJoined(channel->name());
136 void IrcUser::joinChannel(const QString &channelname) {
137 joinChannel(networkInfo->newIrcChannel(channelname));
140 void IrcUser::partChannel(IrcChannel *channel) {
141 if(_channels.contains(channel)) {
142 _channels.remove(channel);
143 disconnect(channel, 0, this, 0);
145 emit channelParted(channel->name());
149 void IrcUser::partChannel(const QString &channelname) {
150 IrcChannel *channel = networkInfo->ircChannel(channelname);
152 qWarning() << "IrcUser::partChannel(): received part for unknown Channel" << channelname;
154 partChannel(channel);
158 void IrcUser::channelDestroyed() {
160 IrcChannel *channel = static_cast<IrcChannel*>(sender());
162 if(_channels.contains(channel)) {
163 _channels.remove(channel);
164 disconnect(channel, 0, this, 0);
168 void IrcUser::setUserModes(const QString &modes) {
170 emit userModesSet(modes);
173 void IrcUser::addUserMode(const QString &mode) {
174 if(!_userModes.contains(mode)) {
176 emit userModeAdded(mode);
180 void IrcUser::removeUserMode(const QString &mode) {
181 if(_userModes.contains(mode)) {
182 _userModes.remove(mode);
183 emit userModeRemoved(mode);
187 void IrcUser::initSetChannels(const QStringList channels) {
188 foreach(QString channel, channels) {
189 joinChannel(channel);
193 void IrcUser::setInitialized() {