Make Message a proper class rather than a struct (i.e. use setters/getters and
[quassel.git] / src / common / ircuser.h
1 /***************************************************************************
2  *   Copyright (C) 2005/06 by The Quassel 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) any later version.                                   *
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 <QtCore>
25 #include <QObject>
26 #include <QHash>
27 #include <QSet>
28 #include <QString>
29 #include <QStringList>
30
31 #include "global.h"
32
33 class IrcUser : public QObject {
34   Q_OBJECT
35   
36 //  Q_PROPERTY(QString user READ user WRITE setUser)
37 //  Q_PROPERTY(QString host READ host WRITE setHost)
38 //  Q_PROPERTY(QString nick READ nick WRITE setNick)
39 //  Q_PROPERTY(QSet<QString> usermodes READ usermodes WRITE setUsermodes)
40 //  Q_PROPERTY(QStringList channels READ channels)
41   
42 public:
43   IrcUser(QObject *parent = 0);
44   IrcUser(const QString &hostmask, QObject *parent = 0);
45   ~IrcUser();
46   
47   void setUser(const QString &user);
48   QString user() const;
49   
50   void setHost(const QString &host);
51   QString host() const;
52   
53   void setNick(const QString &nick);
54   QString nick() const;
55   
56   void setUsermodes(const QSet<QString> &usermodes);
57   QSet<QString> usermodes() const;
58   
59   void setChannelmode(const QString &channel, const QSet<QString> &channelmode);
60   QSet<QString> channelmode(const QString &channel) const;
61   
62   void updateChannelmode(const QString &channel, const QString &channelmode, bool add=true);
63   void addChannelmode(const QString &channel, const QString &channelmode);
64   void removeChannelmode(const QString &channel, const QString &channelmode);
65
66   QStringList channels() const;
67   
68   void joinChannel(const QString &channel);
69   void partChannel(const QString &channel);
70   
71 private:
72   inline bool operator==(const IrcUser &ircuser2) {
73     return (nick_.toLower() == ircuser2.nick().toLower());
74   }
75
76   inline bool operator==(const QString &nickname) {
77     return (nick_.toLower() == nickname.toLower());
78   }
79   
80   QString nick_;
81   QString user_;
82   QString host_;
83   
84   QHash<QString, QSet<QString> > channelmodes_; //keys: channelnames; values: Set of Channelmodes
85   QSet<QString> usermodes_;
86 };
87
88 struct IrcUserException : public Exception {};
89 struct NoSuchChannelException : public IrcUserException {};
90 struct NoSuchNickException : public IrcUserException {};
91
92
93 #endif