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)
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 {
73 return _channels.toList();
76 // ====================
78 // ====================
79 void IrcUser::setUser(const QString &user) {
80 if(!user.isEmpty() && _user != user) {
86 void IrcUser::setHost(const QString &host) {
87 if(!host.isEmpty() && _host != host) {
93 void IrcUser::setNick(const QString &nick) {
94 if(!nick.isEmpty() && nick != _nick) {
95 QString oldnick(_nick);
102 void IrcUser::updateObjectName() {
103 QString oldName(objectName());
104 setObjectName(QString::number(networkInfo->networkId()) + "/" + _nick);
105 if(!oldName.isEmpty()) {
106 emit renameObject(oldName, objectName());
111 void IrcUser::updateHostmask(const QString &mask) {
112 if(mask == hostmask())
115 QString user = userFromMask(mask);
116 QString host = hostFromMask(mask);
121 void IrcUser::joinChannel(const QString &channel) {
122 if(!_channels.contains(channel)) {
123 _channels.insert(channel);
124 networkInfo->newIrcChannel(channel)->join(this);
125 emit channelJoined(channel);
129 void IrcUser::partChannel(const QString &channel) {
130 if(_channels.contains(channel)) {
131 _channels.remove(channel);
133 Q_ASSERT(networkInfo->ircChannel(channel));
134 networkInfo->ircChannel(channel)->part(this);
136 emit channelParted(channel);
140 void IrcUser::setUserModes(const QString &modes) {
142 emit userModesSet(modes);
145 void IrcUser::addUserMode(const QString &mode) {
146 if(!_userModes.contains(mode)) {
148 emit userModeAdded(mode);
152 void IrcUser::removeUserMode(const QString &mode) {
153 if(_userModes.contains(mode)) {
154 _userModes.remove(mode);
155 emit userModeRemoved(mode);
159 void IrcUser::initSetChannels(const QStringList channels) {
160 foreach(QString channel, channels) {
161 joinChannel(channel);
165 void IrcUser::setInitialized() {