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