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