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