Event backend porting
[quassel.git] / src / common / ircuser.h
1 /***************************************************************************
2  *   Copyright (C) 2005-09 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 #include "types.h"
32
33 class SignalProxy;
34 class Network;
35 class IrcChannel;
36
37 class IrcUser : public SyncableObject {
38   SYNCABLE_OBJECT
39   Q_OBJECT
40
41   Q_PROPERTY(QString user READ user WRITE setUser STORED false)
42   Q_PROPERTY(QString host READ host WRITE setHost STORED false)
43   Q_PROPERTY(QString nick READ nick WRITE setNick STORED false)
44   Q_PROPERTY(QString realName READ realName WRITE setRealName STORED false)
45   Q_PROPERTY(bool away READ isAway WRITE setAway STORED false)
46   Q_PROPERTY(QString awayMessage READ awayMessage WRITE setAwayMessage STORED false)
47   Q_PROPERTY(QDateTime idleTime READ idleTime WRITE setIdleTime STORED false)
48   Q_PROPERTY(QDateTime loginTime READ loginTime WRITE setLoginTime STORED false)
49   Q_PROPERTY(QString server READ server WRITE setServer STORED false)
50   Q_PROPERTY(QString ircOperator READ ircOperator WRITE setIrcOperator STORED false)
51   Q_PROPERTY(int lastAwayMessage READ lastAwayMessage WRITE setLastAwayMessage STORED false)
52   Q_PROPERTY(QString whoisServiceReply READ whoisServiceReply WRITE setWhoisServiceReply STORED false)
53   Q_PROPERTY(QString suserHost READ suserHost WRITE setSuserHost STORED false)
54
55   Q_PROPERTY(QStringList channels READ channels STORED false)
56   Q_PROPERTY(QString userModes READ userModes WRITE setUserModes)
57
58 public:
59   IrcUser(const QString &hostmask, Network *network);
60   virtual ~IrcUser();
61
62   inline QString user() const { return _user; }
63   inline QString host() const { return _host; }
64   inline QString nick() const { return _nick; }
65   inline QString realName() const { return _realName; }
66   QString hostmask() const;
67   inline bool isAway() const { return _away; }
68   inline QString awayMessage() const { return _awayMessage; }
69   QDateTime idleTime();
70   inline QDateTime loginTime() const { return _loginTime; }
71   inline QString server() const { return _server; }
72   inline QString ircOperator() const { return _ircOperator; }
73   inline int lastAwayMessage() const { return _lastAwayMessage; }
74   inline QString whoisServiceReply() const { return _whoisServiceReply; }
75   inline QString suserHost() const { return _suserHost; }
76   inline Network *network() const { return _network; }
77
78   inline QString userModes() const { return _userModes; }
79
80   QStringList channels() const;
81
82   // user-specific encodings
83   inline QTextCodec *codecForEncoding() const { return _codecForEncoding; }
84   inline QTextCodec *codecForDecoding() const { return _codecForDecoding; }
85   void setCodecForEncoding(const QString &codecName);
86   void setCodecForEncoding(QTextCodec *codec);
87   void setCodecForDecoding(const QString &codecName);
88   void setCodecForDecoding(QTextCodec *codec);
89
90   QString decodeString(const QByteArray &text) const;
91   QByteArray encodeString(const QString &string) const;
92
93   // only valid on client side, these are not synced!
94   inline QDateTime lastChannelActivity(BufferId id) const { return _lastActivity.value(id); }
95   void setLastChannelActivity(BufferId id, const QDateTime &time);
96   inline QDateTime lastSpokenTo(BufferId id) const { return _lastSpokenTo.value(id); }
97   void setLastSpokenTo(BufferId id, const QDateTime &time);
98
99 public slots:
100   void setUser(const QString &user);
101   void setHost(const QString &host);
102   void setNick(const QString &nick);
103   void setRealName(const QString &realName);
104   void setAway(const bool &away);
105   void setAwayMessage(const QString &awayMessage);
106   void setIdleTime(const QDateTime &idleTime);
107   void setLoginTime(const QDateTime &loginTime);
108   void setServer(const QString &server);
109   void setIrcOperator(const QString &ircOperator);
110   void setLastAwayMessage(const int &lastAwayMessage);
111   void setWhoisServiceReply(const QString &whoisServiceReply);
112   void setSuserHost(const QString &suserHost);
113   void updateHostmask(const QString &mask);
114
115   void setUserModes(const QString &modes);
116
117   void joinChannel(IrcChannel *channel);
118   void joinChannel(const QString &channelname);
119   void partChannel(IrcChannel *channel);
120   void partChannel(const QString &channelname);
121   void quit();
122
123   void addUserModes(const QString &modes);
124   void removeUserModes(const QString &modes);
125
126 signals:
127 //   void userSet(QString user);
128 //   void hostSet(QString host);
129   void nickSet(QString newnick); // needed in NetworkModel
130 //   void realNameSet(QString realName);
131   void awaySet(bool away); // needed in NetworkModel
132 //   void awayMessageSet(QString awayMessage);
133 //   void idleTimeSet(QDateTime idleTime);
134 //   void loginTimeSet(QDateTime loginTime);
135 //   void serverSet(QString server);
136 //   void ircOperatorSet(QString ircOperator);
137 //   void lastAwayMessageSet(int lastAwayMessage);
138 //   void whoisServiceReplySet(QString whoisServiceReply);
139 //   void suserHostSet(QString suserHost);
140
141   void userModesSet(QString modes);
142   void userModesAdded(QString modes);
143   void userModesRemoved(QString modes);
144
145   // void channelJoined(QString channel);
146   void channelParted(QString channel);
147   void quited();
148
149   void lastChannelActivityUpdated(BufferId id, const QDateTime &newTime);
150   void lastSpokenToUpdated(BufferId id, const QDateTime &newTime);
151
152 private slots:
153   void updateObjectName();
154   void channelDestroyed();
155
156 private:
157   inline bool operator==(const IrcUser &ircuser2) {
158     return (_nick.toLower() == ircuser2.nick().toLower());
159   }
160
161   inline bool operator==(const QString &nickname) {
162     return (_nick.toLower() == nickname.toLower());
163   }
164
165   bool _initialized;
166
167   QString _nick;
168   QString _user;
169   QString _host;
170   QString _realName;
171   QString _awayMessage;
172   bool _away;
173   QString _server;
174   QDateTime _idleTime;
175   QDateTime _idleTimeSet;
176   QDateTime _loginTime;
177   QString _ircOperator;
178   int _lastAwayMessage;
179   QString _whoisServiceReply;
180   QString _suserHost;
181
182   // QSet<QString> _channels;
183   QSet<IrcChannel *> _channels;
184   QString _userModes;
185
186   Network *_network;
187
188   QTextCodec *_codecForEncoding;
189   QTextCodec *_codecForDecoding;
190
191   QHash<BufferId, QDateTime> _lastActivity;
192   QHash<BufferId, QDateTime> _lastSpokenTo;
193 };
194
195 #endif