#BR127: user can now set the style of the application in the config menu (behaviour...
[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(QDateTime loginTime READ loginTime WRITE setLoginTime STORED false)
47   Q_PROPERTY(QString server READ server WRITE setServer STORED false)
48   Q_PROPERTY(QString ircOperator READ ircOperator WRITE setIrcOperator STORED false)
49   Q_PROPERTY(int lastAwayMessage READ lastAwayMessage WRITE setLastAwayMessage STORED false)
50
51   Q_PROPERTY(QStringList channels READ channels STORED false)
52   Q_PROPERTY(QString userModes READ userModes WRITE setUserModes)
53
54 public:
55   IrcUser(const QString &hostmask, Network *network);
56   virtual ~IrcUser();
57
58   QString user() const;
59   QString host() const;
60   QString nick() const;
61   QString realName() const; 
62   QString hostmask() const;
63   bool isAway() const;
64   QString awayMessage() const;
65   QDateTime idleTime();
66   QDateTime loginTime() const;
67   QString server() const;
68   QString ircOperator() const;
69   int lastAwayMessage() const;
70   Network *network() const;
71
72   QString userModes() const;
73
74   QStringList channels() const;
75
76   // user-specific encodings
77   QTextCodec *codecForEncoding() const;
78   QTextCodec *codecForDecoding() const;
79   void setCodecForEncoding(const QString &codecName);
80   void setCodecForEncoding(QTextCodec *codec);
81   void setCodecForDecoding(const QString &codecName);
82   void setCodecForDecoding(QTextCodec *codec);
83
84   QString decodeString(const QByteArray &text) const;
85   QByteArray encodeString(const QString &string) const;
86
87 public slots:
88   void setUser(const QString &user);
89   void setHost(const QString &host);
90   void setNick(const QString &nick);
91   void setRealName(const QString &realName);
92   void setAway(const bool &away);
93   void setAwayMessage(const QString &awayMessage);
94   void setIdleTime(const QDateTime &idleTime);
95   void setLoginTime(const QDateTime &loginTime);
96   void setServer(const QString &server);
97   void setIrcOperator(const QString &ircOperator);
98   void setLastAwayMessage(const int &lastAwayMessage);
99   void updateHostmask(const QString &mask);
100
101   void setUserModes(const QString &modes);
102
103   void joinChannel(IrcChannel *channel);
104   void joinChannel(const QString &channelname);
105   void partChannel(IrcChannel *channel);
106   void partChannel(const QString &channelname);
107
108   void addUserModes(const QString &modes);
109   void removeUserModes(const QString &modes);
110
111 signals:
112   void userSet(QString user);
113   void hostSet(QString host);
114   void nickSet(QString newnick);
115   void realNameSet(QString realName);
116   void awaySet(bool away);
117   void awayMessageSet(QString awayMessage);
118   void idleTimeSet(QDateTime idleTime);
119   void loginTimeSet(QDateTime loginTime);
120   void serverSet(QString server);
121   void ircOperatorSet(QString ircOperator);
122   void lastAwayMessageSet(int lastAwayMessage);
123   void hostmaskUpdated(QString mask);
124
125   void userModesSet(QString modes);
126
127   // void channelJoined(QString channel);
128   void channelParted(QString channel);
129
130   void userModesAdded(QString modes);
131   void userModesRemoved(QString modes);
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   QDateTime _idleTimeSet;
157   QDateTime _loginTime;
158   QString _ircOperator;
159   int _lastAwayMessage;
160   
161   // QSet<QString> _channels;
162   QSet<IrcChannel *> _channels;
163   QString _userModes;
164
165   Network *_network;
166
167   QTextCodec *_codecForEncoding;
168   QTextCodec *_codecForDecoding;
169 };
170
171 #endif