- Implemented IrcServerHandler::handleMode(). In the current state only
[quassel.git] / src / common / ircuser.h
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by the Quassel IRC Team                         *
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
29 class SignalProxy;
30 class NetworkInfo;
31 class IrcChannel;
32
33 class IrcUser : public QObject {
34   Q_OBJECT
35
36   Q_PROPERTY(QString user READ user WRITE setUser STORED false)
37   Q_PROPERTY(QString host READ host WRITE setHost STORED false)
38   Q_PROPERTY(QString nick READ nick WRITE setNick STORED false)
39
40   Q_PROPERTY(QStringList channels READ channels STORED false)
41   //  Q_PROPERTY(QStringList usermodes READ usermodes WRITE setUsermodes)
42
43 public:
44   IrcUser(const QString &hostmask, NetworkInfo *networkInfo);
45   virtual ~IrcUser();
46
47   bool initialized() const;
48
49   QString user() const;
50   QString host() const;
51   QString nick() const;
52   QString hostmask() const;
53
54   QString userModes() const;
55
56   QStringList channels() const;
57
58   // user-specific encodings
59   QTextCodec *codecForEncoding() const;
60   QTextCodec *codecForDecoding() const;
61   void setCodecForEncoding(const QString &codecName);
62   void setCodecForEncoding(QTextCodec *codec);
63   void setCodecForDecoding(const QString &codecName);
64   void setCodecForDecoding(QTextCodec *codec);
65
66   QString decodeString(const QByteArray &text) const;
67   QByteArray encodeString(const QString string) const;
68
69 public slots:
70   void setUser(const QString &user);
71   void setHost(const QString &host);
72   void setNick(const QString &nick);
73   void updateHostmask(const QString &mask);
74
75   void setUserModes(const QString &modes);
76
77   void joinChannel(IrcChannel *channel);
78   void joinChannel(const QString &channelname);
79   void partChannel(IrcChannel *channel);
80   void partChannel(const QString &channelname);
81
82   void addUserMode(const QString &mode);
83   void removeUserMode(const QString &mode);
84
85   // init seters
86   void initSetChannels(const QStringList channels);
87
88   void setInitialized();
89
90 signals:
91   void userSet(QString user);
92   void hostSet(QString host);
93   void nickSet(QString newnick);
94   void hostmaskUpdated(QString mask);
95
96   void userModesSet(QString modes);
97
98   void channelJoined(QString channel);
99   void channelParted(QString channel);
100
101   void userModeAdded(QString mode);
102   void userModeRemoved(QString mode);
103
104   void renameObject(QString oldname, QString newname);
105
106 //   void setUsermodes(const QSet<QString> &usermodes);
107 //   QSet<QString> usermodes() const;
108
109   void initDone();
110
111 private slots:
112   void updateObjectName();
113   void channelDestroyed();
114
115 private:
116   inline bool operator==(const IrcUser &ircuser2) {
117     return (_nick.toLower() == ircuser2.nick().toLower());
118   }
119
120   inline bool operator==(const QString &nickname) {
121     return (_nick.toLower() == nickname.toLower());
122   }
123
124   bool _initialized;
125
126   QString _nick;
127   QString _user;
128   QString _host;
129
130   // QSet<QString> _channels;
131   QSet<IrcChannel *> _channels;
132   QString _userModes;
133
134   NetworkInfo *networkInfo;
135
136   QTextCodec *_codecForEncoding;
137   QTextCodec *_codecForDecoding;
138 };
139
140 #endif