PageRenderTime 96ms CodeModel.GetById 42ms app.highlight 49ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/newview/llviewerinventory.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 380 lines | 237 code | 67 blank | 76 comment | 1 complexity | cc9428a05aa24e79a985179ba8ff4bf6 MD5 | raw file
  1/** 
  2 * @file llviewerinventory.h
  3 * @brief Declaration of the inventory bits that only used on the viewer.
  4 *
  5 * $LicenseInfo:firstyear=2002&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_LLVIEWERINVENTORY_H
 28#define LL_LLVIEWERINVENTORY_H
 29
 30#include "llinventory.h"
 31#include "llframetimer.h"
 32#include "llwearable.h"
 33#include "llui.h" //for LLDestroyClass
 34
 35#include <boost/signals2.hpp>	// boost::signals2::trackable
 36
 37class LLFolderView;
 38class LLFolderBridge;
 39class LLViewerInventoryCategory;
 40
 41//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 42// Class LLViewerInventoryItem
 43//
 44// An inventory item represents something that the current user has in
 45// their inventory.
 46//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 47
 48class LLViewerInventoryItem : public LLInventoryItem, public boost::signals2::trackable
 49{
 50public:
 51	typedef LLDynamicArray<LLPointer<LLViewerInventoryItem> > item_array_t;
 52	
 53protected:
 54	~LLViewerInventoryItem( void ); // ref counted
 55	BOOL extractSortFieldAndDisplayName(S32* sortField, std::string* displayName) const { return extractSortFieldAndDisplayName(mName, sortField, displayName); }
 56	mutable std::string mDisplayName;
 57	
 58public:
 59	virtual LLAssetType::EType getType() const;
 60	virtual const LLUUID& getAssetUUID() const;
 61	virtual const LLUUID& getProtectedAssetUUID() const; // returns LLUUID::null if current agent does not have permission to expose this asset's UUID to the user
 62	virtual const std::string& getName() const;
 63	virtual S32 getSortField() const;
 64	virtual void setSortField(S32 sortField);
 65	virtual void getSLURL(); //Caches SLURL for landmark. //*TODO: Find a better way to do it and remove this method from here.
 66	virtual const LLPermissions& getPermissions() const;
 67	virtual const bool getIsFullPerm() const; // 'fullperm' in the popular sense: modify-ok & copy-ok & transfer-ok, no special god rules applied
 68	virtual const LLUUID& getCreatorUUID() const;
 69	virtual const std::string& getDescription() const;
 70	virtual const LLSaleInfo& getSaleInfo() const;
 71	virtual LLInventoryType::EType getInventoryType() const;
 72	virtual bool isWearableType() const;
 73	virtual LLWearableType::EType getWearableType() const;
 74	virtual U32 getFlags() const;
 75	virtual time_t getCreationDate() const;
 76	virtual U32 getCRC32() const; // really more of a checksum.
 77
 78	static BOOL extractSortFieldAndDisplayName(const std::string& name, S32* sortField, std::string* displayName);
 79
 80	// construct a complete viewer inventory item
 81	LLViewerInventoryItem(const LLUUID& uuid, const LLUUID& parent_uuid,
 82						  const LLPermissions& permissions,
 83						  const LLUUID& asset_uuid,
 84						  LLAssetType::EType type,
 85						  LLInventoryType::EType inv_type,
 86						  const std::string& name, 
 87						  const std::string& desc,
 88						  const LLSaleInfo& sale_info,
 89						  U32 flags,
 90						  time_t creation_date_utc);
 91
 92	// construct a viewer inventory item which has the minimal amount
 93	// of information to use in the UI.
 94	LLViewerInventoryItem(
 95		const LLUUID& item_id,
 96		const LLUUID& parent_id,
 97		const std::string& name,
 98		LLInventoryType::EType inv_type);
 99
100	// construct an invalid and incomplete viewer inventory item.
101	// usually useful for unpacking or importing or what have you.
102	// *NOTE: it is important to call setComplete() if you expect the
103	// operations to provide all necessary information.
104	LLViewerInventoryItem();
105	// Create a copy of an inventory item from a pointer to another item
106	// Note: Because InventoryItems are ref counted,
107	//       reference copy (a = b) is prohibited
108	LLViewerInventoryItem(const LLViewerInventoryItem* other);
109	LLViewerInventoryItem(const LLInventoryItem* other);
110
111	void copyViewerItem(const LLViewerInventoryItem* other);
112	/*virtual*/ void copyItem(const LLInventoryItem* other);
113
114	// construct a new clone of this item - it creates a new viewer
115	// inventory item using the copy constructor, and returns it.
116	// It is up to the caller to delete (unref) the item.
117	void cloneViewerItem(LLPointer<LLViewerInventoryItem>& newitem) const;
118
119	// virtual methods
120	virtual void removeFromServer( void );
121	virtual void updateParentOnServer(BOOL restamp) const;
122	virtual void updateServer(BOOL is_new) const;
123	void fetchFromServer(void) const;
124
125	//virtual void packMessage(LLMessageSystem* msg) const;
126	virtual BOOL unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);
127	virtual BOOL unpackMessage(LLSD item);
128	virtual BOOL importFile(LLFILE* fp);
129	virtual BOOL importLegacyStream(std::istream& input_stream);
130
131	// file handling on the viewer. These are not meant for anything
132	// other than cacheing.
133	bool exportFileLocal(LLFILE* fp) const;
134	bool importFileLocal(LLFILE* fp);
135
136	// new methods
137	BOOL isFinished() const { return mIsComplete; }
138	void setComplete(BOOL complete) { mIsComplete = complete; }
139	//void updateAssetOnServer() const;
140
141	virtual void packMessage(LLMessageSystem* msg) const;
142	virtual void setTransactionID(const LLTransactionID& transaction_id);
143	struct comparePointers
144	{
145		bool operator()(const LLPointer<LLViewerInventoryItem>& a, const LLPointer<LLViewerInventoryItem>& b)
146		{
147			return a->getName().compare(b->getName()) < 0;
148		}
149	};
150	LLTransactionID getTransactionID() const { return mTransactionID; }
151	
152	bool getIsBrokenLink() const; // true if the baseitem this points to doesn't exist in memory.
153	LLViewerInventoryItem *getLinkedItem() const;
154	LLViewerInventoryCategory *getLinkedCategory() const;
155	
156	// Checks the items permissions (for owner, group, or everyone) and returns true if all mask bits are set.
157	bool checkPermissionsSet(PermissionMask mask) const;
158	PermissionMask getPermissionMask() const;
159
160	// callback
161	void onCallingCardNameLookup(const LLUUID& id, const std::string& name, bool is_group);
162
163	// If this is a broken link, try to fix it and any other identical link.
164	BOOL regenerateLink();
165
166public:
167	BOOL mIsComplete;
168	LLTransactionID mTransactionID;
169};
170
171
172//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
173// Class LLViewerInventoryCategory
174//
175// An instance of this class represents a category of inventory
176// items. Users come with a set of default categories, and can create
177// new ones as needed.
178//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
179
180class LLViewerInventoryCategory  : public LLInventoryCategory
181{
182public:
183	typedef LLDynamicArray<LLPointer<LLViewerInventoryCategory> > cat_array_t;
184	
185protected:
186	~LLViewerInventoryCategory();
187	
188public:
189	LLViewerInventoryCategory(const LLUUID& uuid, const LLUUID& parent_uuid,
190							  LLFolderType::EType preferred_type,
191							  const std::string& name,
192							  const LLUUID& owner_id);
193	LLViewerInventoryCategory(const LLUUID& owner_id);
194	// Create a copy of an inventory category from a pointer to another category
195	// Note: Because InventoryCategorys are ref counted, reference copy (a = b)
196	// is prohibited
197	LLViewerInventoryCategory(const LLViewerInventoryCategory* other);
198	void copyViewerCategory(const LLViewerInventoryCategory* other);
199
200	virtual void removeFromServer();
201	virtual void updateParentOnServer(BOOL restamp_children) const;
202	virtual void updateServer(BOOL is_new) const;
203
204	const LLUUID& getOwnerID() const { return mOwnerID; }
205
206	// Version handling
207	enum { VERSION_UNKNOWN = -1, VERSION_INITIAL = 1 };
208	S32 getVersion() const { return mVersion; }
209	void setVersion(S32 version) { mVersion = version; }
210
211	// Returns true if a fetch was issued.
212	bool fetch();
213
214	// used to help make cacheing more robust - for example, if
215	// someone is getting 4 packets but logs out after 3. the viewer
216	// may never know the cache is wrong.
217	enum { DESCENDENT_COUNT_UNKNOWN = -1 };
218	S32 getDescendentCount() const { return mDescendentCount; }
219	void setDescendentCount(S32 descendents) { mDescendentCount = descendents; }
220
221	// file handling on the viewer. These are not meant for anything
222	// other than cacheing.
223	bool exportFileLocal(LLFILE* fp) const;
224	bool importFileLocal(LLFILE* fp);
225	void determineFolderType();
226	void changeType(LLFolderType::EType new_folder_type);
227
228private:
229	friend class LLInventoryModel;
230	void localizeName(); // intended to be called from the LLInventoryModel
231
232protected:
233	LLUUID mOwnerID;
234	S32 mVersion;
235	S32 mDescendentCount;
236	LLFrameTimer mDescendentsRequested;
237};
238
239class LLInventoryCallback : public LLRefCount
240{
241public:
242	virtual void fire(const LLUUID& inv_item) = 0;
243};
244
245class WearOnAvatarCallback : public LLInventoryCallback
246{
247public:
248	WearOnAvatarCallback(bool do_replace = false) : mReplace(do_replace) {}
249	
250	void fire(const LLUUID& inv_item);
251
252protected:
253	bool mReplace;
254};
255
256class ModifiedCOFCallback : public LLInventoryCallback
257{
258	void fire(const LLUUID& inv_item);
259};
260
261class LLViewerJointAttachment;
262
263class RezAttachmentCallback : public LLInventoryCallback
264{
265public:
266	RezAttachmentCallback(LLViewerJointAttachment *attachmentp);
267	void fire(const LLUUID& inv_item);
268
269protected:
270	~RezAttachmentCallback();
271
272private:
273	LLViewerJointAttachment* mAttach;
274};
275
276class ActivateGestureCallback : public LLInventoryCallback
277{
278public:
279	void fire(const LLUUID& inv_item);
280};
281
282class CreateGestureCallback : public LLInventoryCallback
283{
284public:
285	void fire(const LLUUID& inv_item);
286};
287
288class AddFavoriteLandmarkCallback : public LLInventoryCallback
289{
290public:
291	AddFavoriteLandmarkCallback() : mTargetLandmarkId(LLUUID::null) {}
292	void setTargetLandmarkId(const LLUUID& target_uuid) { mTargetLandmarkId = target_uuid; }
293
294private:
295	void fire(const LLUUID& inv_item);
296
297	LLUUID mTargetLandmarkId;
298};
299
300// misc functions
301//void inventory_reliable_callback(void**, S32 status);
302
303class LLInventoryCallbackManager : public LLDestroyClass<LLInventoryCallbackManager>
304{
305	friend class LLDestroyClass<LLInventoryCallbackManager>;
306public:
307	LLInventoryCallbackManager();
308	~LLInventoryCallbackManager();
309
310	void fire(U32 callback_id, const LLUUID& item_id);
311	U32 registerCB(LLPointer<LLInventoryCallback> cb);
312private:
313	typedef std::map<U32, LLPointer<LLInventoryCallback> > callback_map_t;
314	callback_map_t mMap;
315	U32 mLastCallback;
316	static LLInventoryCallbackManager *sInstance;
317	static void destroyClass();
318
319public:
320	static bool is_instantiated() { return sInstance != NULL; }
321};
322extern LLInventoryCallbackManager gInventoryCallbacks;
323
324
325#define NOT_WEARABLE (LLWearableType::EType)0
326
327// *TODO: Find a home for these
328void create_inventory_item(const LLUUID& agent_id, const LLUUID& session_id,
329						   const LLUUID& parent, const LLTransactionID& transaction_id,
330						   const std::string& name,
331						   const std::string& desc, LLAssetType::EType asset_type,
332						   LLInventoryType::EType inv_type, LLWearableType::EType wtype,
333						   U32 next_owner_perm,
334						   LLPointer<LLInventoryCallback> cb);
335
336void create_inventory_callingcard(const LLUUID& avatar_id, const LLUUID& parent = LLUUID::null, LLPointer<LLInventoryCallback> cb=NULL);
337
338/**
339 * @brief Securely create a new inventory item by copying from another.
340 */
341void copy_inventory_item(
342	const LLUUID& agent_id,
343	const LLUUID& current_owner,
344	const LLUUID& item_id,
345	const LLUUID& parent_id,
346	const std::string& new_name,
347	LLPointer<LLInventoryCallback> cb);
348
349void link_inventory_item(
350	const LLUUID& agent_id,
351	const LLUUID& item_id,
352	const LLUUID& parent_id,
353	const std::string& new_name,
354	const std::string& new_description,
355	const LLAssetType::EType asset_type,
356	LLPointer<LLInventoryCallback> cb);
357
358void move_inventory_item(
359	const LLUUID& agent_id,
360	const LLUUID& session_id,
361	const LLUUID& item_id,
362	const LLUUID& parent_id,
363	const std::string& new_name,
364	LLPointer<LLInventoryCallback> cb);
365
366const LLUUID get_folder_by_itemtype(const LLInventoryItem *src);
367
368void copy_inventory_from_notecard(const LLUUID& destination_id,
369								  const LLUUID& object_id,
370								  const LLUUID& notecard_inv_id,
371								  const LLInventoryItem *src,
372								  U32 callback_id = 0);
373
374
375void menu_create_inventory_item(LLFolderView* root,
376								LLFolderBridge* bridge,
377								const LLSD& userdata,
378								const LLUUID& default_parent_uuid = LLUUID::null);
379
380#endif // LL_LLVIEWERINVENTORY_H