~qutim/jreen/ubuntu

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/****************************************************************************
**
** Jreen
**
** Copyright © 2011 Ruslan Nigmatullin <euroelessar@yandex.ru>
** Copyright © 2011 Aleksey Sidorov <gorthauer87@yandex.ru>
**
*****************************************************************************
**
** $JREEN_BEGIN_LICENSE$
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see http://www.gnu.org/licenses/.
** $JREEN_END_LICENSE$
**
****************************************************************************/

#ifndef MUCROOM_P_H
#define MUCROOM_P_H

#include "mucroom.h"
#include "mucmessagesession_p.h"
#include "client_p.h"

namespace Jreen
{
class MUCRoomUserQuery;

class MUCRoomPrivate
{
public:
	Q_DECLARE_PUBLIC(MUCRoom)

	MUCRoomPrivate(MUCRoom *room) :
		q_ptr(room), client(0), affiliation(MUCRoom::AffiliationOutcast),
		role(MUCRoom::RoleNone), maxChars(-1), maxStanzas(-1), seconds(-1),
		currentPresence(Presence::Unavailable, JID(), QString()), isJoined(false),
	    startedJoining(false)
	{
	}

	static MUCRoomPrivate *get(MUCRoom *room) { return room->d_func(); }
	void handlePresence(const Presence &pres);
	void handleMessage(const Message &msg);

	MUCRoom *q_ptr;
	QPointer<Client> client;
	JID jid;
	MUCRoom::Affiliation affiliation;
	MUCRoom::Role role;
	QHash<QString, QSharedPointer<MUCRoomUserQuery> > participantsHash;
	QString password;
	int maxChars;
	int maxStanzas;
	int seconds;
	Presence currentPresence;
	bool isJoined;
	bool startedJoining;
	QDateTime since;
	MUCMessageSession *session;
	QString subject;
};

class MUCRoomQuery : public Payload
{
	J_PAYLOAD(Jreen::MUCRoomQuery)
	public:
		MUCRoomQuery(const QString &password)
	  : m_password(password), m_maxChars(-1), m_maxStanzas(-1), m_seconds(-1) {}
	void setMaxChars(int maxChars) { m_maxChars = qMax(-1, maxChars); }
	void setMaxStanzas(int maxStanzas) { m_maxStanzas = qMax(-1, maxStanzas); }
	void setSeconds(int seconds) { m_seconds = qMax(-1, seconds); }
	void setSince(const QDateTime &since) { m_since = since; }
private:
	QString m_password;
	int m_maxChars;
	int m_maxStanzas;
	int m_seconds;
	QDateTime m_since;
	friend class JREEN_AUTOTEST_EXPORT MUCRoomQueryFactory;
};

class MUCRoomItem
{
public:
	MUCRoomItem() : affiliation(MUCRoom::AffiliationInvalid), role(MUCRoom::RoleInvalid) {}

	MUCRoom::Affiliation affiliation;
	MUCRoom::Role role;
	JID jid;
	QString reason;
	JID actor;
	QString nick;
};

class MUCRoomUserQuery : public Payload
{
	J_PAYLOAD(Jreen::MUCRoomUserQuery)
public:
	enum Flag
	{
		NonAnonymous         = 0x0001,
		SemiAnonymous        = 0x0002,
		FullyAnonymous       = 0x0004,
		AffiliationChangeWNR = 0x0008,
		Self                 = 0x0010,
		LoggingEnabled       = 0x0020,
		LoggingDisabled      = 0x0040,
		NewRoom              = 0x0080,
		NickAssigned         = 0x0100,
		Banned               = 0x0200,
		NickChanged          = 0x0400,
		Kicked               = 0x0800,
		AffiliationChanged   = 0x1000,
		MembershipRequired   = 0x2000,
		RoomSegfaulted       = 0x4000
	};
	enum Operation
	{
		Invite = 1,
		Decline = 2
	};
	
	MUCRoomUserQuery() : flags(0), operation(0)
	{
	}
	
	MUCRoomUserQuery(Operation op, const JID &to, const QString &reason, const QString &thread)
	    : flags(0), operation(op), thread(thread)
	{
		item.jid = to;
		item.reason = reason;
	}

	MUCRoomItem item;
	JID alternate;
	int flags : 24;
	int operation : 8;
	QString status;
	QString password;
	QString thread;
};

class MUCRoomAdminQuery : public Payload
{
	J_PAYLOAD(Jreen::MUCRoomAdminQuery)
	public:
	MUCRoomAdminQuery() {}
	MUCRoomAdminQuery(MUCRoom::Affiliation a)
	{
		MUCRoomItem item;
		item.affiliation = a;
		items << item;
	}
	MUCRoomAdminQuery(const JID &jid, MUCRoom::Affiliation a, const QString &reason)
	{
		MUCRoomItem item;
		item.affiliation = a;
		item.jid = jid;
		item.reason = reason;
		items << item;
	}
	MUCRoomAdminQuery(const QString &nick, MUCRoom::Affiliation a, const QString &reason)
	{
		MUCRoomItem item;
		item.affiliation = a;
		item.nick = nick;
		item.reason = reason;
		items << item;
	}
	MUCRoomAdminQuery(const QString &nick, MUCRoom::Role r, const QString &reason)
	{
		MUCRoomItem item;
		item.role = r;
		item.nick = nick;
		item.reason = reason;
		items << item;
	}
	QList<MUCRoomItem> items;
};

class MUCRoomOwnerQuery : public Payload
{
	J_PAYLOAD(Jreen::MUCRoomOwnerQuery)
	public:
		MUCRoomOwnerQuery() {}
	MUCRoomOwnerQuery(const DataForm::Ptr &f) : form(f) {}
	DataForm::Ptr form;
};
}

#endif // MUCROOM_P_H