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