PageRenderTime 49ms CodeModel.GetById 14ms app.highlight 27ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/llmutelist.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 178 lines | 97 code | 37 blank | 44 comment | 0 complexity | 56336d0538b2ba91e9770d16bb40c861 MD5 | raw file
  1/** 
  2 * @file llmutelist.h
  3 * @brief Management of list of muted players
  4 *
  5 * $LicenseInfo:firstyear=2003&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_MUTELIST_H
 28#define LL_MUTELIST_H
 29
 30#include "llstring.h"
 31#include "lluuid.h"
 32
 33class LLViewerObject;
 34class LLMessageSystem;
 35class LLMuteListObserver;
 36
 37// An entry in the mute list.
 38class LLMute
 39{
 40public:
 41	// Legacy mutes are BY_NAME and have null UUID.
 42	// EXTERNAL mutes are only processed through an external system (e.g. Voice) and not stored.
 43	enum EType { BY_NAME = 0, AGENT = 1, OBJECT = 2, GROUP = 3, EXTERNAL = 4, COUNT = 5 };
 44	
 45	// Bits in the mute flags.  For backwards compatibility (since any mute list entries that were created before the flags existed
 46	// will have a flags field of 0), some of the flags are "inverted".
 47	// Note that it's possible, through flags, to completely disable an entry in the mute list.  The code should detect this case
 48	// and remove the mute list entry instead.
 49	enum 
 50	{
 51		flagTextChat		= 0x00000001,		// If set, don't mute user's text chat
 52		flagVoiceChat		= 0x00000002,		// If set, don't mute user's voice chat
 53		flagParticles		= 0x00000004,		// If set, don't mute user's particles
 54		flagObjectSounds 	= 0x00000008,		// If set, mute user's object sounds
 55		
 56		flagAll				= 0x0000000F		// Mask of all currently defined flags
 57	};
 58	
 59	LLMute(const LLUUID& id, const std::string& name = std::string(), EType type = BY_NAME, U32 flags = 0);
 60
 61	// Returns localized type name of muted item
 62	std::string getDisplayType() const;
 63	
 64public:
 65	LLUUID		mID;	// agent or object id
 66	std::string	mName;	// agent or object name, does not store last name "Resident"
 67	EType		mType;	// needed for UI display of existing mutes
 68	U32			mFlags;	// flags pertaining to this mute entry
 69};
 70
 71class LLMuteList : public LLSingleton<LLMuteList>
 72{
 73public:
 74	// reasons for auto-unmuting a resident
 75	enum EAutoReason 
 76	{ 
 77		AR_IM = 0,			// agent IMed a muted resident
 78		AR_MONEY = 1,			// agent paid L$ to a muted resident
 79		AR_INVENTORY = 2,	// agent offered inventory to a muted resident
 80		AR_COUNT			// enum count
 81	};
 82
 83	LLMuteList();
 84	~LLMuteList();
 85
 86	// Implemented locally so that we can perform some delayed initialization. 
 87	// Callers should be careful to call this one and not LLSingleton<LLMuteList>::getInstance()
 88	// which would circumvent that mechanism. -MG
 89	static LLMuteList* getInstance();
 90
 91	void addObserver(LLMuteListObserver* observer);
 92	void removeObserver(LLMuteListObserver* observer);
 93
 94	// Add either a normal or a BY_NAME mute, for any or all properties.
 95	BOOL add(const LLMute& mute, U32 flags = 0);
 96
 97	// Remove both normal and legacy mutes, for any or all properties.
 98	BOOL remove(const LLMute& mute, U32 flags = 0);
 99	BOOL autoRemove(const LLUUID& agent_id, const EAutoReason reason);
100	
101	// Name is required to test against legacy text-only mutes.
102	BOOL isMuted(const LLUUID& id, const std::string& name = LLStringUtil::null, U32 flags = 0) const;
103	
104	// Alternate (convenience) form for places we don't need to pass the name, but do need flags
105	BOOL isMuted(const LLUUID& id, U32 flags) const { return isMuted(id, LLStringUtil::null, flags); };
106	
107	BOOL isLinden(const std::string& name) const;
108	
109	BOOL isLoaded() const { return mIsLoaded; }
110
111	std::vector<LLMute> getMutes() const;
112	
113	// request the mute list
114	void requestFromServer(const LLUUID& agent_id);
115
116	// call this method on logout to save everything.
117	void cache(const LLUUID& agent_id);
118
119private:
120	BOOL loadFromFile(const std::string& filename);
121	BOOL saveToFile(const std::string& filename);
122
123	void setLoaded();
124	void notifyObservers();
125
126	void updateAdd(const LLMute& mute);
127	void updateRemove(const LLMute& mute);
128
129	// TODO: NULL out mute_id in database
130	static void processMuteListUpdate(LLMessageSystem* msg, void**);
131	static void processUseCachedMuteList(LLMessageSystem* msg, void**);
132
133	static void onFileMuteList(void** user_data, S32 code, LLExtStat ext_status);
134
135private:
136	struct compare_by_name
137	{
138		bool operator()(const LLMute& a, const LLMute& b) const
139		{
140			std::string name1 = a.mName;
141			std::string name2 = b.mName;
142
143			LLStringUtil::toUpper(name1);
144			LLStringUtil::toUpper(name2);
145
146			return name1 < name2;
147		}
148	};
149	struct compare_by_id
150	{
151		bool operator()(const LLMute& a, const LLMute& b) const
152		{
153			return a.mID < b.mID;
154		}
155	};
156	typedef std::set<LLMute, compare_by_id> mute_set_t;
157	mute_set_t mMutes;
158	
159	typedef std::set<std::string> string_set_t;
160	string_set_t mLegacyMutes;
161	
162	typedef std::set<LLMuteListObserver*> observer_set_t;
163	observer_set_t mObservers;
164
165	BOOL mIsLoaded;
166
167	friend class LLDispatchEmptyMuteList;
168};
169
170class LLMuteListObserver
171{
172public:
173	virtual ~LLMuteListObserver() { }
174	virtual void onChange() = 0;
175};
176
177
178#endif //LL_MUTELIST_H