1 /***************************************************************************
2 * Copyright (C) 2005-07 by The Quassel 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) any later version. *
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)
38 setObjectName(QString::number(networkInfo->networkId()) + "/" + IrcUser::hostmask());
41 // ====================
43 // ====================
44 bool IrcUser::initialized() const {
48 QString IrcUser::user() const {
52 QString IrcUser::host() const {
56 QString IrcUser::nick() const {
60 QString IrcUser::hostmask() const {
61 return QString("%1!%2@%3").arg(nick()).arg(user()).arg(host());
64 QString IrcUser::userModes() const {
68 QStringList IrcUser::channels() const {
69 return _channels.toList();
72 void IrcUser::updateObjectName() {
73 setObjectName(QString::number(networkInfo->networkId()) + "/" + hostmask());
77 // ====================
79 // ====================
80 void IrcUser::setUser(const QString &user) {
81 if(!user.isEmpty() && _user != user) {
85 setObjectName(hostmask());
90 void IrcUser::setHost(const QString &host) {
91 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::updateHostmask(const QString &mask) {
108 if(mask == hostmask())
111 QString user = userFromMask(mask);
112 QString host = hostFromMask(mask);
114 // we only need to check user and hostmask.
115 // nick can't have changed since we're identifying IrcUsers by nick
117 // we don't use setUser and setHost here.
118 // though this is unpretty code duplication this saves us one emit objectNameSet()
119 // the second one would be erroneous
121 if(!user.isEmpty() && _user != user) {
125 if(!host.isEmpty() && _host != host) {
129 emit hostmaskUpdated(mask);
133 void IrcUser::joinChannel(const QString &channel) {
134 if(!_channels.contains(channel)) {
135 _channels.insert(channel);
136 networkInfo->newIrcChannel(channel)->join(this);
137 emit channelJoined(channel);
141 void IrcUser::partChannel(const QString &channel) {
142 if(_channels.contains(channel)) {
143 _channels.remove(channel);
145 Q_ASSERT(networkInfo->ircChannel(channel));
146 networkInfo->ircChannel(channel)->part(this);
148 emit channelParted(channel);
152 void IrcUser::setUserModes(const QString &modes) {
154 emit userModesSet(modes);
157 void IrcUser::addUserMode(const QString &mode) {
158 if(!_userModes.contains(mode)) {
160 emit userModeAdded(mode);
164 void IrcUser::removeUserMode(const QString &mode) {
165 if(_userModes.contains(mode)) {
166 _userModes.remove(mode);
167 emit userModeRemoved(mode);
171 void IrcUser::initSetChannels(const QStringList channels) {
172 foreach(QString channel, channels) {
173 joinChannel(channel);
177 void IrcUser::setInitialized() {