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)
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 // ====================
77 // ====================
78 void IrcUser::setUser(const QString &user) {
79 if(!user.isEmpty() && _user != user) {
85 void IrcUser::setHost(const QString &host) {
86 if(!host.isEmpty() && _host != host) {
92 void IrcUser::setNick(const QString &nick) {
93 if(!nick.isEmpty() && nick != _nick) {
94 QString oldnick(_nick);
101 void IrcUser::updateObjectName() {
102 QString oldName(objectName());
103 setObjectName(QString::number(networkInfo->networkId()) + "/" + _nick);
104 if(!oldName.isEmpty()) {
105 emit renameObject(oldName, objectName());
110 void IrcUser::updateHostmask(const QString &mask) {
111 if(mask == hostmask())
114 QString user = userFromMask(mask);
115 QString host = hostFromMask(mask);
120 void IrcUser::joinChannel(const QString &channel) {
121 if(!_channels.contains(channel)) {
122 _channels.insert(channel);
123 networkInfo->newIrcChannel(channel)->join(this);
124 emit channelJoined(channel);
128 void IrcUser::partChannel(const QString &channel) {
129 if(_channels.contains(channel)) {
130 _channels.remove(channel);
132 Q_ASSERT(networkInfo->ircChannel(channel));
133 networkInfo->ircChannel(channel)->part(this);
135 emit channelParted(channel);
139 void IrcUser::setUserModes(const QString &modes) {
141 emit userModesSet(modes);
144 void IrcUser::addUserMode(const QString &mode) {
145 if(!_userModes.contains(mode)) {
147 emit userModeAdded(mode);
151 void IrcUser::removeUserMode(const QString &mode) {
152 if(_userModes.contains(mode)) {
153 _userModes.remove(mode);
154 emit userModeRemoved(mode);
158 void IrcUser::initSetChannels(const QStringList channels) {
159 foreach(QString channel, channels) {
160 joinChannel(channel);
164 void IrcUser::setInitialized() {