Closing BR #126
[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 #include <QDateTime>
29
30 #include "syncableobject.h"
31
32 class SignalProxy;
33 class Network;
34 class IrcChannel;
35
36 class IrcUser : public SyncableObject {
37   Q_OBJECT
38
39   Q_PROPERTY(QString user READ user WRITE setUser STORED false)
40   Q_PROPERTY(QString host READ host WRITE setHost STORED false)
41   Q_PROPERTY(QString nick READ nick WRITE setNick STORED false)
42   Q_PROPERTY(QString realName READ realName WRITE setRealName STORED false)
43   Q_PROPERTY(bool away READ isAway WRITE setAway STORED false)
44   Q_PROPERTY(QString awayMessage READ awayMessage WRITE setAwayMessage STORED false)
45   Q_PROPERTY(QDateTime idleTime READ idleTime WRITE setIdleTime STORED false)
46   Q_PROPERTY(QString server READ server WRITE setServer STORED false)
47   Q_PROPERTY(QString ircOperator READ ircOperator WRITE setIrcOperator STORED false)
48   Q_PROPERTY(int lastAwayMessage READ lastAwayMessage WRITE setLastAwayMessage STORED false)
49
50   Q_PROPERTY(QStringList channels READ channels STORED false)
51   Q_PROPERTY(QString userModes READ userModes WRITE setUserModes)
52
53 public:
54   IrcUser(const QString &hostmask, Network *network);
55   virtual ~IrcUser();
56
57   QString user() const;
58   QString host() const;
59   QString nick() const;
60   QString realName() const; 
61   QString hostmask() const;
62   bool isAway() const;
63   QString awayMessage() const;
64   QDateTime idleTime() const;
65   QString server() const;
66   QString ircOperator() const;
67   int lastAwayMessage() const;
68   Network *network() const;
69
70   QString userModes() const;
71
72   QStringList channels() const;
73
74   // user-specific encodings
75   QTextCodec *codecForEncoding() const;
76   QTextCodec *codecForDecoding() const;
77   void setCodecForEncoding(const QString &codecName);
78   void setCodecForEncoding(QTextCodec *codec);
79   void setCodecForDecoding(const QString &codecName);
80   void setCodecForDecoding(QTextCodec *codec);
81
82   QString decodeString(const QByteArray &text) const;
83   QByteArray encodeString(const QString &string) const;
84
85 public slots:
86   void setUser(const QString &user);
87   void setHost(const QString &host);
88   void setNick(const QString &nick);
89   void setRealName(const QString &realName);
90   void setAway(const bool &away);
91   void setAwayMessage(const QString &awayMessage);
92   void setIdleTime(const QDateTime &idleTime);
93   void setServer(const QString &server);
94   void setIrcOperator(const QString &ircOperator);
95   void setLastAwayMessage(const int &lastAwayMessage);
96   void updateHostmask(const QString &mask);
97
98   void setUserModes(const QString &modes);
99
100   void joinChannel(IrcChannel *channel);
101   void joinChannel(const QString &channelname);
102   void partChannel(IrcChannel *channel);
103   void partChannel(const QString &channelname);
104
105   void addUserModes(const QString &modes);
106   void removeUserModes(const QString &modes);
107
108 signals:
109   void userSet(QString user);
110   void hostSet(QString host);
111   void nickSet(QString newnick);
112   void realNameSet(QString realName);
113   void awaySet(bool away);
114   void awayMessageSet(QString awayMessage);
115   void idleTimeSet(QDateTime idleTime);
116   void serverSet(QString server);
117   void ircOperatorSet(QString ircOperator);
118   void lastAwayMessageSet(int lastAwayMessage);
119   void hostmaskUpdated(QString mask);
120
121   void userModesSet(QString modes);
122
123   // void channelJoined(QString channel);
124   void channelParted(QString channel);
125
126   void userModesAdded(QString modes);
127   void userModesRemoved(QString modes);
128
129 private slots:
130   void updateObjectName();
131   void channelDestroyed();
132
133 private:
134   inline bool operator==(const IrcUser &ircuser2) {
135     return (_nick.toLower() == ircuser2.nick().toLower());
136   }
137
138   inline bool operator==(const QString &nickname) {
139     return (_nick.toLower() == nickname.toLower());
140   }
141
142   bool _initialized;
143
144   QString _nick;
145   QString _user;
146   QString _host;
147   QString _realName;
148   QString _awayMessage;
149   bool _away;
150   QString _server;
151   QDateTime _idleTime;
152   QString _ircOperator;
153   int _lastAwayMessage;
154   
155   // QSet<QString> _channels;
156   QSet<IrcChannel *> _channels;
157   QString _userModes;
158
159   Network *_network;
160
161   QTextCodec *_codecForEncoding;
162   QTextCodec *_codecForDecoding;
163 };
164
165 #endif