PageRenderTime 93ms CodeModel.GetById 50ms app.highlight 17ms RepoModel.GetById 13ms app.codeStats 0ms

/indra/newview/llparticipantlist.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 288 lines | 138 code | 41 blank | 109 comment | 0 complexity | 830091906810fe577f992263bd7ca9c9 MD5 | raw file
  1/** 
  2 * @file llparticipantlist.h
  3 * @brief LLParticipantList intended to update view(LLAvatarList) according to incoming messages
  4 *
  5 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_PARTICIPANTLIST_H
 28#define LL_PARTICIPANTLIST_H
 29
 30#include "llviewerprecompiledheaders.h"
 31#include "llevent.h"
 32#include "llavatarlist.h" // for LLAvatarItemRecentSpeakerComparator
 33#include "lllistcontextmenu.h"
 34
 35class LLSpeakerMgr;
 36class LLAvatarList;
 37class LLUICtrl;
 38class LLAvalineUpdater;
 39
 40class LLParticipantList
 41{
 42	LOG_CLASS(LLParticipantList);
 43public:
 44
 45	typedef boost::function<bool (const LLUUID& speaker_id)> validate_speaker_callback_t;
 46
 47	LLParticipantList(LLSpeakerMgr* data_source, 
 48					  LLAvatarList* avatar_list, 
 49					  bool use_context_menu = true, 
 50					  bool exclude_agent = true, 
 51					  bool can_toggle_icons = true);
 52	~LLParticipantList();
 53	void setSpeakingIndicatorsVisible(BOOL visible);
 54
 55	enum EParticipantSortOrder
 56	{
 57		E_SORT_BY_NAME = 0,
 58		E_SORT_BY_RECENT_SPEAKERS = 1,
 59	};
 60
 61	/**
 62	 * Adds specified avatar ID to the existing list if it is not Agent's ID
 63	 *
 64	 * @param[in] avatar_id - Avatar UUID to be added into the list
 65	 */
 66	void addAvatarIDExceptAgent(const LLUUID& avatar_id);
 67
 68	/**
 69	 * Set and sort Avatarlist by given order
 70	 */
 71	void setSortOrder(EParticipantSortOrder order = E_SORT_BY_NAME);
 72	const EParticipantSortOrder getSortOrder() const;
 73
 74	/**
 75	 * Refreshes the participant list if it's in sort by recent speaker order.
 76	 */
 77	void updateRecentSpeakersOrder();
 78
 79	/**
 80	 * Set a callback to be called before adding a speaker. Invalid speakers will not be added.
 81	 *
 82	 * If the callback is unset all speakers are considered as valid.
 83	 *
 84	 * @see onAddItemEvent()
 85	 */
 86	void setValidateSpeakerCallback(validate_speaker_callback_t cb);
 87
 88protected:
 89	/**
 90	 * LLSpeakerMgr event handlers
 91	 */
 92	bool onAddItemEvent(LLPointer<LLOldEvents::LLEvent> event, const LLSD& userdata);
 93	bool onRemoveItemEvent(LLPointer<LLOldEvents::LLEvent> event, const LLSD& userdata);
 94	bool onClearListEvent(LLPointer<LLOldEvents::LLEvent> event, const LLSD& userdata);
 95	bool onModeratorUpdateEvent(LLPointer<LLOldEvents::LLEvent> event, const LLSD& userdata);
 96	bool onSpeakerMuteEvent(LLPointer<LLOldEvents::LLEvent> event, const LLSD& userdata);
 97
 98	/**
 99	 * Sorts the Avatarlist by stored order
100	 */
101	void sort();
102
103	/**
104	 * List of listeners implementing LLOldEvents::LLSimpleListener.
105	 * There is no way to handle all the events in one listener as LLSpeakerMgr registers
106	 * listeners in such a way that one listener can handle only one type of event
107	 **/
108	class BaseSpeakerListener : public LLOldEvents::LLSimpleListener
109	{
110	public:
111		BaseSpeakerListener(LLParticipantList& parent) : mParent(parent) {}
112	protected:
113		LLParticipantList& mParent;
114	};
115
116	class SpeakerAddListener : public BaseSpeakerListener
117	{
118	public:
119		SpeakerAddListener(LLParticipantList& parent) : BaseSpeakerListener(parent) {}
120		/*virtual*/ bool handleEvent(LLPointer<LLOldEvents::LLEvent> event, const LLSD& userdata);
121	};
122
123	class SpeakerRemoveListener : public BaseSpeakerListener
124	{
125	public:
126		SpeakerRemoveListener(LLParticipantList& parent) : BaseSpeakerListener(parent) {}
127		/*virtual*/ bool handleEvent(LLPointer<LLOldEvents::LLEvent> event, const LLSD& userdata);
128	};
129
130	class SpeakerClearListener : public BaseSpeakerListener
131	{
132	public:
133		SpeakerClearListener(LLParticipantList& parent) : BaseSpeakerListener(parent) {}
134		/*virtual*/ bool handleEvent(LLPointer<LLOldEvents::LLEvent> event, const LLSD& userdata);
135	};
136
137	class SpeakerModeratorUpdateListener : public BaseSpeakerListener
138	{
139	public:
140		SpeakerModeratorUpdateListener(LLParticipantList& parent) : BaseSpeakerListener(parent) {}
141		/*virtual*/ bool handleEvent(LLPointer<LLOldEvents::LLEvent> event, const LLSD& userdata);
142	};
143		
144	class SpeakerMuteListener : public BaseSpeakerListener
145	{
146	public:
147		SpeakerMuteListener(LLParticipantList& parent) : BaseSpeakerListener(parent) {}
148
149		/*virtual*/ bool handleEvent(LLPointer<LLOldEvents::LLEvent> event, const LLSD& userdata);
150	};
151
152	/**
153	 * Menu used in the participant list.
154	 */
155	class LLParticipantListMenu : public LLListContextMenu
156	{
157	public:
158		LLParticipantListMenu(LLParticipantList& parent):mParent(parent){};
159		/*virtual*/ LLContextMenu* createMenu();
160		/*virtual*/ void show(LLView* spawning_view, const uuid_vec_t& uuids, S32 x, S32 y);
161	protected:
162		LLParticipantList& mParent;
163	private:
164		bool enableContextMenuItem(const LLSD& userdata);
165		bool enableModerateContextMenuItem(const LLSD& userdata);
166		bool checkContextMenuItem(const LLSD& userdata);
167
168		void sortParticipantList(const LLSD& userdata);
169		void toggleAllowTextChat(const LLSD& userdata);
170		void toggleMute(const LLSD& userdata, U32 flags);
171		void toggleMuteText(const LLSD& userdata);
172		void toggleMuteVoice(const LLSD& userdata);
173		
174		/**
175		 * Return true if Agent is group moderator(and moderator of group call).
176		 */
177		bool isGroupModerator();
178
179		// Voice moderation support
180		/**
181		 * Check whether specified by argument avatar is muted for group chat or not.
182		 */
183		bool isMuted(const LLUUID& avatar_id);
184
185		/**
186		 * Processes Voice moderation menu items.
187		 *
188		 * It calls either moderateVoiceParticipant() or moderateVoiceParticipant() depend on
189		 * passed parameter.
190		 *
191		 * @param userdata can be "selected" or "others".
192		 *
193		 * @see moderateVoiceParticipant()
194		 * @see moderateVoiceAllParticipants()
195		 */
196		void moderateVoice(const LLSD& userdata);
197
198		/**
199		 * Mutes/Unmutes avatar for current group voice chat.
200		 *
201		 * It only marks avatar as muted for session and does not use local Agent's Block list.
202		 * It does not mute Agent itself.
203		 *
204		 * @param[in] avatar_id UUID of avatar to be processed
205		 * @param[in] unmute if true - specified avatar will be muted, otherwise - unmuted.
206		 *
207		 * @see moderateVoiceAllParticipants()
208		 */
209		void moderateVoiceParticipant(const LLUUID& avatar_id, bool unmute);
210
211		/**
212		 * Mutes/Unmutes all avatars for current group voice chat.
213		 *
214		 * It only marks avatars as muted for session and does not use local Agent's Block list.
215		 *
216		 * @param[in] unmute if true - avatars will be muted, otherwise - unmuted.
217		 *
218		 * @see moderateVoiceParticipant()
219		 */
220		void moderateVoiceAllParticipants(bool unmute);
221
222		static void confirmMuteAllCallback(const LLSD& notification, const LLSD& response);
223	};
224
225	/**
226	 * Comparator for comparing avatar items by last spoken time
227	 */
228	class LLAvatarItemRecentSpeakerComparator : public LLAvatarItemNameComparator, public LLRefCount
229	{
230		LOG_CLASS(LLAvatarItemRecentSpeakerComparator);
231	public:
232		LLAvatarItemRecentSpeakerComparator(LLParticipantList& parent):mParent(parent){};
233		virtual ~LLAvatarItemRecentSpeakerComparator() {};
234	protected:
235		virtual bool doCompare(const LLAvatarListItem* avatar_item1, const LLAvatarListItem* avatar_item2) const;
236	private:
237		LLParticipantList& mParent;
238	};
239
240private:
241	void onAvatarListDoubleClicked(LLUICtrl* ctrl);
242	void onAvatarListRefreshed(LLUICtrl* ctrl, const LLSD& param);
243
244	void onAvalineCallerFound(const LLUUID& participant_id);
245	void onAvalineCallerRemoved(const LLUUID& participant_id);
246
247	/**
248	 * Adjusts passed participant to work properly.
249	 *
250	 * Adds SpeakerMuteListener to process moderation actions.
251	 */
252	void adjustParticipant(const LLUUID& speaker_id);
253
254	bool isHovered();
255
256	LLSpeakerMgr*		mSpeakerMgr;
257	LLAvatarList*		mAvatarList;
258
259	std::set<LLUUID>	mModeratorList;
260	std::set<LLUUID>	mModeratorToRemoveList;
261
262	LLPointer<SpeakerAddListener>				mSpeakerAddListener;
263	LLPointer<SpeakerRemoveListener>			mSpeakerRemoveListener;
264	LLPointer<SpeakerClearListener>				mSpeakerClearListener;
265	LLPointer<SpeakerModeratorUpdateListener>	mSpeakerModeratorListener;
266	LLPointer<SpeakerMuteListener>				mSpeakerMuteListener;
267
268	LLParticipantListMenu*    mParticipantListMenu;
269
270	/**
271	 * This field manages an adding  a new avatar_id in the mAvatarList
272	 * If true, then agent_id wont  be added into mAvatarList
273	 * Also by default this field is controlling a sort procedure, @c sort() 
274	 */
275	bool mExcludeAgent;
276
277	// boost::connections
278	boost::signals2::connection mAvatarListDoubleClickConnection;
279	boost::signals2::connection mAvatarListRefreshConnection;
280	boost::signals2::connection mAvatarListReturnConnection;
281	boost::signals2::connection mAvatarListToggleIconsConnection;
282
283	LLPointer<LLAvatarItemRecentSpeakerComparator> mSortByRecentSpeakers;
284	validate_speaker_callback_t mValidateSpeakerCallback;
285	LLAvalineUpdater* mAvalineUpdater;
286};
287
288#endif // LL_PARTICIPANTLIST_H