removing some debug messages
[quassel.git] / src / common / ircuser.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by The Quassel Team                             *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                   *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #include "ircuser.h"
22 #include "util.h"
23
24 #include "networkinfo.h"
25 #include "signalproxy.h"
26 #include "ircchannel.h"
27
28 #include <QDebug>
29
30 IrcUser::IrcUser(const QString &hostmask, NetworkInfo *networkinfo)
31   : QObject(networkinfo),
32     _initialized(false),
33     _nick(nickFromMask(hostmask)),
34     _user(userFromMask(hostmask)),
35     _host(hostFromMask(hostmask)),
36     networkInfo(networkinfo)
37 {
38   updateObjectName();
39 }
40
41 IrcUser::~IrcUser() {
42   qDebug() << nick() << "destroyed.";
43 }
44
45 // ====================
46 //  PUBLIC:
47 // ====================
48 bool IrcUser::initialized() const {
49   return _initialized;
50 }
51
52 QString IrcUser::user() const {
53   return _user;
54 }
55
56 QString IrcUser::host() const {
57   return _host;
58 }
59
60 QString IrcUser::nick() const {
61   return _nick;
62 }
63
64 QString IrcUser::hostmask() const {
65   return QString("%1!%2@%3").arg(nick()).arg(user()).arg(host());
66 }
67
68 QString IrcUser::userModes() const {
69   return _userModes;
70 }
71
72 QStringList IrcUser::channels() const {
73   return _channels.toList();
74 }
75
76 // ====================
77 //  PUBLIC SLOTS:
78 // ====================
79 void IrcUser::setUser(const QString &user) {
80   if(!user.isEmpty() && _user != user) {
81     _user = user;
82     emit userSet(user);
83   }
84 }
85
86 void IrcUser::setHost(const QString &host) {
87   if(!host.isEmpty() && _host != host) {
88     _host = host;
89     emit hostSet(host);
90   }
91 }
92
93 void IrcUser::setNick(const QString &nick) {
94   if(!nick.isEmpty() && nick != _nick) {
95     QString oldnick(_nick);
96     _nick = nick;
97     updateObjectName();
98     emit nickSet(nick);
99   }
100 }
101
102 void IrcUser::updateObjectName() {
103   QString oldName(objectName());
104   setObjectName(QString::number(networkInfo->networkId()) + "/" + _nick);
105   if(!oldName.isEmpty()) {
106     emit renameObject(oldName, objectName());
107   }
108 }
109
110
111 void IrcUser::updateHostmask(const QString &mask) {
112   if(mask == hostmask())
113     return;
114
115   QString user = userFromMask(mask);
116   QString host = hostFromMask(mask);
117   setUser(user);
118   setHost(host);
119 }
120
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);
126   }
127 }
128
129 void IrcUser::partChannel(const QString &channel) {
130   if(_channels.contains(channel)) {
131     _channels.remove(channel);
132
133     Q_ASSERT(networkInfo->ircChannel(channel));
134     networkInfo->ircChannel(channel)->part(this);
135     
136     emit channelParted(channel);
137   }
138 }
139
140 void IrcUser::setUserModes(const QString &modes) {
141   _userModes = modes;
142   emit userModesSet(modes);
143 }
144
145 void IrcUser::addUserMode(const QString &mode) {
146   if(!_userModes.contains(mode)) {
147     _userModes += mode;
148     emit userModeAdded(mode);
149   }
150 }
151
152 void IrcUser::removeUserMode(const QString &mode) {
153   if(_userModes.contains(mode)) {
154     _userModes.remove(mode);
155     emit userModeRemoved(mode);
156   }
157 }
158
159 void IrcUser::initSetChannels(const QStringList channels) {
160   foreach(QString channel, channels) {
161     joinChannel(channel);
162   }
163 }
164
165 void IrcUser::setInitialized() {
166   _initialized = true;
167   emit initDone();
168 }
169