1 | /*************************************************************************** |
2 | * Copyright (C) 2005-2014 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 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * |
19 | ***************************************************************************/ |
20 | |
21 | #ifndef IRCCHANNEL_H |
22 | #define IRCCHANNEL_H |
23 | |
24 | #include <QHash> |
25 | #include <QSet> |
26 | #include <QString> |
27 | #include <QStringList> |
28 | #include <QVariantMap> |
29 | |
30 | #include "syncableobject.h" |
31 | |
32 | class IrcUser; |
33 | class Network; |
34 | |
35 | class IrcChannel : public SyncableObject |
36 | { |
37 | SYNCABLE_OBJECT |
38 | Q_OBJECT |
39 | |
40 | Q_PROPERTY(QString name READ name) |
41 | Q_PROPERTY(QString topic READ topic WRITE setTopic) |
42 | Q_PROPERTY(QString password READ password WRITE setPassword) |
43 | Q_PROPERTY(bool encrypted READ encrypted WRITE setEncrypted) |
44 | |
45 | public : |
46 | IrcChannel(const QString &channelname, Network *network); |
47 | ~IrcChannel(); |
48 | |
49 | bool isKnownUser(IrcUser *ircuser) const; |
50 | bool isValidChannelUserMode(const QString &mode) const; |
51 | |
52 | inline QString name() const { return _name; } |
53 | inline QString topic() const { return _topic; } |
54 | inline QString password() const { return _password; } |
55 | inline bool encrypted() const { return _encrypted; } |
56 | inline Network *network() const { return _network; } |
57 | |
58 | inline QList<IrcUser *> ircUsers() const { return _userModes.keys(); } |
59 | |
60 | QString userModes(IrcUser *ircuser) const; |
61 | QString userModes(const QString &nick) const; |
62 | |
63 | bool hasMode(const QChar &mode) const; |
64 | QString modeValue(const QChar &mode) const; |
65 | QStringList modeValueList(const QChar &mode) const; |
66 | QString channelModeString() const; |
67 | |
68 | inline QTextCodec *codecForEncoding() const { return _codecForEncoding; } |
69 | inline QTextCodec *codecForDecoding() const { return _codecForDecoding; } |
70 | void setCodecForEncoding(const QString &codecName); |
71 | void setCodecForEncoding(QTextCodec *codec); |
72 | void setCodecForDecoding(const QString &codecName); |
73 | void setCodecForDecoding(QTextCodec *codec); |
74 | |
75 | QString decodeString(const QByteArray &text) const; |
76 | QByteArray encodeString(const QString &string) const; |
77 | |
78 | public slots: |
79 | void setTopic(const QString &topic); |
80 | void setPassword(const QString &password); |
81 | void setEncrypted(bool encrypted); |
82 | |
83 | void joinIrcUsers(const QList<IrcUser *> &users, const QStringList &modes); |
84 | void joinIrcUsers(const QStringList &nicks, const QStringList &modes); |
85 | void joinIrcUser(IrcUser *ircuser); |
86 | |
87 | void part(IrcUser *ircuser); |
88 | void part(const QString &nick); |
89 | |
90 | void setUserModes(IrcUser *ircuser, const QString &modes); |
91 | void setUserModes(const QString &nick, const QString &modes); |
92 | |
93 | void addUserMode(IrcUser *ircuser, const QString &mode); |
94 | void addUserMode(const QString &nick, const QString &mode); |
95 | |
96 | void removeUserMode(IrcUser *ircuser, const QString &mode); |
97 | void removeUserMode(const QString &nick, const QString &mode); |
98 | |
99 | void addChannelMode(const QChar &mode, const QString &value); |
100 | void removeChannelMode(const QChar &mode, const QString &value); |
101 | |
102 | // init geters |
103 | QVariantMap initUserModes() const; |
104 | QVariantMap initChanModes() const; |
105 | |
106 | // init seters |
107 | void initSetUserModes(const QVariantMap &usermodes); |
108 | void initSetChanModes(const QVariantMap &chanModes); |
109 | |
110 | signals: |
111 | void topicSet(const QString &topic); // needed by NetworkModel |
112 | void encryptedSet(bool encrypted); |
113 | // void passwordSet(const QString &password); |
114 | // void userModesSet(QString nick, QString modes); |
115 | // void userModeAdded(QString nick, QString mode); |
116 | // void userModeRemoved(QString nick, QString mode); |
117 | // void channelModeAdded(const QChar &mode, const QString &value); |
118 | // void channelModeRemoved(const QChar &mode, const QString &value); |
119 | |
120 | void ircUsersJoined(QList<IrcUser *> ircusers); |
121 | // void ircUsersJoined(QStringList nicks, QStringList modes); |
122 | void ircUserParted(IrcUser *ircuser); |
123 | void ircUserNickSet(IrcUser *ircuser, QString nick); |
124 | void ircUserModeAdded(IrcUser *ircuser, QString mode); |
125 | void ircUserModeRemoved(IrcUser *ircuser, QString mode); |
126 | void ircUserModesSet(IrcUser *ircuser, QString modes); |
127 | |
128 | void parted(); // convenience signal emitted before channels destruction |
129 | |
130 | private slots: |
131 | void ircUserDestroyed(); |
132 | void ircUserNickSet(QString nick); |
133 | |
134 | private: |
135 | bool _initialized; |
136 | QString _name; |
137 | QString _topic; |
138 | QString _password; |
139 | bool _encrypted; |
140 | |
141 | QHash<IrcUser *, QString> _userModes; |
142 | |
143 | Network *_network; |
144 | |
145 | QTextCodec *_codecForEncoding; |
146 | QTextCodec *_codecForDecoding; |
147 | |
148 | QHash<QChar, QStringList> _A_channelModes; |
149 | QHash<QChar, QString> _B_channelModes; |
150 | QHash<QChar, QString> _C_channelModes; |
151 | QSet<QChar> _D_channelModes; |
152 | }; |
153 | |
154 | |
155 | #endif |
156 | |