added ircserverhandler for whois, who and whowas
[quassel.git] / src / common / ircuser.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
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) version 3.                                           *
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 #ifndef _IRCUSER_H_
22 #define _IRCUSER_H_
23
24 #include <QSet>
25 #include <QString>
26 #include <QStringList>
27 #include <QVariantMap>
28
29 #include "syncableobject.h"
30
31 class SignalProxy;
32 class Network;
33 class IrcChannel;
34
35 class IrcUser : public SyncableObject {
36   Q_OBJECT
37
38   Q_PROPERTY(QString user READ user WRITE setUser STORED false)
39   Q_PROPERTY(QString host READ host WRITE setHost STORED false)
40   Q_PROPERTY(QString nick READ nick WRITE setNick STORED false)
41   Q_PROPERTY(QString realName READ realName WRITE setRealName STORED false)
42   Q_PROPERTY(bool away READ isAway WRITE setAway STORED false)
43   Q_PROPERTY(QString awayMessage READ awayMessage WRITE setAwayMessage STORED false)
44
45   Q_PROPERTY(QStringList channels READ channels STORED false)
46   //  Q_PROPERTY(QStringList usermodes READ usermodes WRITE setUsermodes)
47
48 public:
49   IrcUser(const QString &hostmask, Network *network);
50   virtual ~IrcUser();
51
52   QString user() const;
53   QString host() const;
54   QString nick() const;
55   QString realName() const; 
56   QString hostmask() const;
57   bool isAway() const;
58   QString awayMessage() const;
59   Network *network() const;
60
61   QString userModes() const;
62
63   QStringList channels() const;
64
65   // user-specific encodings
66   QTextCodec *codecForEncoding() const;
67   QTextCodec *codecForDecoding() const;
68   void setCodecForEncoding(const QString &codecName);
69   void setCodecForEncoding(QTextCodec *codec);
70   void setCodecForDecoding(const QString &codecName);
71   void setCodecForDecoding(QTextCodec *codec);
72
73   QString decodeString(const QByteArray &text) const;
74   QByteArray encodeString(const QString string) const;
75
76 public slots:
77   void setUser(const QString &user);
78   void setHost(const QString &host);
79   void setNick(const QString &nick);
80   void setRealName(const QString &realName);
81   void setAway(const bool &away);
82   void setAwayMessage(const QString &awayMessage);
83   void updateHostmask(const QString &mask);
84
85   void setUserModes(const QString &modes);
86
87   void joinChannel(IrcChannel *channel);
88   void joinChannel(const QString &channelname);
89   void partChannel(IrcChannel *channel);
90   void partChannel(const QString &channelname);
91
92   void addUserMode(const QString &mode);
93   void removeUserMode(const QString &mode);
94
95   // init seters
96   void initSetChannels(const QStringList channels);
97
98 signals:
99   void userSet(QString user);
100   void hostSet(QString host);
101   void nickSet(QString newnick);
102   void realNameSet(QString realName);
103   void awaySet(bool away);
104   void awayMessageSet(QString awayMessage);
105   void hostmaskUpdated(QString mask);
106
107   void userModesSet(QString modes);
108
109   void channelJoined(QString channel);
110   void channelParted(QString channel);
111
112   void userModeAdded(QString mode);
113   void userModeRemoved(QString mode);
114
115   void renameObject(QString oldname, QString newname);
116
117 //   void setUsermodes(const QSet<QString> &usermodes);
118 //   QSet<QString> usermodes() const;
119
120 private slots:
121   void updateObjectName();
122   void channelDestroyed();
123
124 private:
125   inline bool operator==(const IrcUser &ircuser2) {
126     return (_nick.toLower() == ircuser2.nick().toLower());
127   }
128
129   inline bool operator==(const QString &nickname) {
130     return (_nick.toLower() == nickname.toLower());
131   }
132
133   bool _initialized;
134
135   QString _nick;
136   QString _user;
137   QString _host;
138   QString _realName;
139   QString _awayMessage;
140   bool _away;
141
142   // QSet<QString> _channels;
143   QSet<IrcChannel *> _channels;
144   QString _userModes;
145
146   Network *_network;
147
148   QTextCodec *_codecForEncoding;
149   QTextCodec *_codecForDecoding;
150 };
151
152 #endif