This is it, the long-awaited huge commit with the new Network handling.
[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
49   Q_PROPERTY(QStringList channels READ channels STORED false)
50   //  Q_PROPERTY(QStringList usermodes READ usermodes WRITE setUsermodes)
51
52 public:
53   IrcUser(const QString &hostmask, Network *network);
54   virtual ~IrcUser();
55
56   QString user() const;
57   QString host() const;
58   QString nick() const;
59   QString realName() const; 
60   QString hostmask() const;
61   bool isAway() const;
62   QString awayMessage() const;
63   QDateTime idleTime() const;
64   QString server() const;
65   QString ircOperator() const;
66   Network *network() const;
67
68   QString userModes() const;
69
70   QStringList channels() const;
71
72   // user-specific encodings
73   QTextCodec *codecForEncoding() const;
74   QTextCodec *codecForDecoding() const;
75   void setCodecForEncoding(const QString &codecName);
76   void setCodecForEncoding(QTextCodec *codec);
77   void setCodecForDecoding(const QString &codecName);
78   void setCodecForDecoding(QTextCodec *codec);
79
80   QString decodeString(const QByteArray &text) const;
81   QByteArray encodeString(const QString string) const;
82
83 public slots:
84   void setUser(const QString &user);
85   void setHost(const QString &host);
86   void setNick(const QString &nick);
87   void setRealName(const QString &realName);
88   void setAway(const bool &away);
89   void setAwayMessage(const QString &awayMessage);
90   void setIdleTime(const QDateTime &idleTime);
91   void setServer(const QString &server);
92   void setIrcOperator(const QString &ircOperator);
93   void updateHostmask(const QString &mask);
94
95   void setUserModes(const QString &modes);
96
97   void joinChannel(IrcChannel *channel);
98   void joinChannel(const QString &channelname);
99   void partChannel(IrcChannel *channel);
100   void partChannel(const QString &channelname);
101
102   void addUserMode(const QString &mode);
103   void removeUserMode(const QString &mode);
104
105   // init seters
106   void initSetChannels(const QStringList channels);
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 hostmaskUpdated(QString mask);
119
120   void userModesSet(QString modes);
121
122   void channelJoined(QString channel);
123   void channelParted(QString channel);
124
125   void userModeAdded(QString mode);
126   void userModeRemoved(QString mode);
127
128   void renameObject(QString oldname, QString newname);
129
130 //   void setUsermodes(const QSet<QString> &usermodes);
131 //   QSet<QString> usermodes() const;
132
133 private slots:
134   void updateObjectName();
135   void channelDestroyed();
136
137 private:
138   inline bool operator==(const IrcUser &ircuser2) {
139     return (_nick.toLower() == ircuser2.nick().toLower());
140   }
141
142   inline bool operator==(const QString &nickname) {
143     return (_nick.toLower() == nickname.toLower());
144   }
145
146   bool _initialized;
147
148   QString _nick;
149   QString _user;
150   QString _host;
151   QString _realName;
152   QString _awayMessage;
153   bool _away;
154   QString _server;
155   QDateTime _idleTime;
156   QString _ircOperator;
157   
158   // QSet<QString> _channels;
159   QSet<IrcChannel *> _channels;
160   QString _userModes;
161
162   Network *_network;
163
164   QTextCodec *_codecForEncoding;
165   QTextCodec *_codecForDecoding;
166 };
167
168 #endif