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());
44 // ====================
46 // ====================
47 bool IrcUser::initialized() const {
51 QString IrcUser::user() const {
55 QString IrcUser::host() const {
59 QString IrcUser::nick() const {
63 QString IrcUser::hostmask() const {
64 return QString("%1!%2@%3").arg(nick()).arg(user()).arg(host());
67 QString IrcUser::userModes() const {
71 QStringList IrcUser::channels() const {
72 return _channels.toList();
75 void IrcUser::updateObjectName() {
76 setObjectName(QString::number(networkInfo->networkId()) + "/" + hostmask());
80 // ====================
82 // ====================
83 void IrcUser::setUser(const QString &user) {
84 if(!user.isEmpty() && _user != user) {
88 setObjectName(hostmask());
93 void IrcUser::setHost(const QString &host) {
94 if(!host.isEmpty() && _host != host) {
101 void IrcUser::setNick(const QString &nick) {
102 if(!nick.isEmpty() && nick != _nick) {
103 QString oldnick(_nick);
110 void IrcUser::updateHostmask(const QString &mask) {
111 if(mask == hostmask())
114 QString user = userFromMask(mask);
115 QString host = hostFromMask(mask);
117 // we only need to check user and hostmask.
118 // nick can't have changed since we're identifying IrcUsers by nick
120 // we don't use setUser and setHost here.
121 // though this is unpretty code duplication this saves us one emit objectNameSet()
122 // the second one would be erroneous
124 if(!user.isEmpty() && _user != user) {
128 if(!host.isEmpty() && _host != host) {
132 emit hostmaskUpdated(mask);
136 void IrcUser::joinChannel(const QString &channel) {
137 if(!_channels.contains(channel)) {
138 _channels.insert(channel);
139 networkInfo->newIrcChannel(channel)->join(this);
140 emit channelJoined(channel);
144 void IrcUser::partChannel(const QString &channel) {
145 if(_channels.contains(channel)) {
146 _channels.remove(channel);
148 Q_ASSERT(networkInfo->ircChannel(channel));
149 networkInfo->ircChannel(channel)->part(this);
151 emit channelParted(channel);
155 void IrcUser::setUserModes(const QString &modes) {
157 emit userModesSet(modes);
160 void IrcUser::addUserMode(const QString &mode) {
161 if(!_userModes.contains(mode)) {
163 emit userModeAdded(mode);
167 void IrcUser::removeUserMode(const QString &mode) {
168 if(_userModes.contains(mode)) {
169 _userModes.remove(mode);
170 emit userModeRemoved(mode);
174 void IrcUser::initSetChannels(const QStringList channels) {
175 foreach(QString channel, channels) {
176 joinChannel(channel);
180 void IrcUser::setInitialized() {