PageRenderTime 80ms CodeModel.GetById 24ms app.highlight 51ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llinventoryfunctions.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 502 lines | 292 code | 68 blank | 142 comment | 9 complexity | 838907803eeaaf9a36284088c3d7f522 MD5 | raw file
  1/** 
  2 * @file llinventoryfunctions.h
  3 * @brief Miscellaneous inventory-related functions and classes
  4 * class definition
  5 *
  6 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#ifndef LL_LLINVENTORYFUNCTIONS_H
 29#define LL_LLINVENTORYFUNCTIONS_H
 30
 31#include "llinventorymodel.h"
 32#include "llinventory.h"
 33#include "llwearabletype.h"
 34
 35/********************************************************************************
 36 **                                                                            **
 37 **                    MISCELLANEOUS GLOBAL FUNCTIONS
 38 **/
 39
 40// Is this a parent folder to a worn item
 41BOOL get_is_parent_to_worn_item(const LLUUID& id);
 42
 43// Is this item or its baseitem is worn, attached, etc...
 44BOOL get_is_item_worn(const LLUUID& id);
 45
 46// Could this item be worn (correct type + not already being worn)
 47BOOL get_can_item_be_worn(const LLUUID& id);
 48
 49BOOL get_is_item_removable(const LLInventoryModel* model, const LLUUID& id);
 50
 51BOOL get_is_category_removable(const LLInventoryModel* model, const LLUUID& id);
 52
 53BOOL get_is_category_renameable(const LLInventoryModel* model, const LLUUID& id);
 54
 55void show_item_profile(const LLUUID& item_uuid);
 56void show_task_item_profile(const LLUUID& item_uuid, const LLUUID& object_id);
 57
 58void show_item_original(const LLUUID& item_uuid);
 59
 60void change_item_parent(LLInventoryModel* model,
 61									 LLViewerInventoryItem* item,
 62									 const LLUUID& new_parent_id,
 63									 BOOL restamp);
 64
 65void change_category_parent(LLInventoryModel* model,
 66	LLViewerInventoryCategory* cat,
 67	const LLUUID& new_parent_id,
 68	BOOL restamp);
 69
 70void remove_category(LLInventoryModel* model, const LLUUID& cat_id);
 71
 72void rename_category(LLInventoryModel* model, const LLUUID& cat_id, const std::string& new_name);
 73
 74// Generates a string containing the path to the item specified by item_id.
 75void append_path(const LLUUID& id, std::string& path);
 76
 77void copy_item_to_outbox(LLInventoryItem* inv_item, LLUUID dest_folder, const LLUUID& top_level_folder, S32 operation_id);
 78void move_item_within_outbox(LLInventoryItem* inv_item, LLUUID dest_folder, S32 operation_id);
 79
 80void copy_folder_to_outbox(LLInventoryCategory* inv_cat, const LLUUID& dest_folder, const LLUUID& top_level_folder, S32 operation_id);
 81
 82/**                    Miscellaneous global functions
 83 **                                                                            **
 84 *******************************************************************************/
 85
 86/********************************************************************************
 87 **                                                                            **
 88 **                    INVENTORY COLLECTOR FUNCTIONS
 89 **/
 90
 91//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 92// Class LLInventoryCollectFunctor
 93//
 94// Base class for LLInventoryModel::collectDescendentsIf() method
 95// which accepts an instance of one of these objects to use as the
 96// function to determine if it should be added. Derive from this class
 97// and override the () operator to return TRUE if you want to collect
 98// the category or item passed in.
 99//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100class LLInventoryCollectFunctor
101{
102public:
103	virtual ~LLInventoryCollectFunctor(){};
104	virtual bool operator()(LLInventoryCategory* cat, LLInventoryItem* item) = 0;
105
106	static bool itemTransferCommonlyAllowed(const LLInventoryItem* item);
107};
108
109//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110// Class LLAssetIDMatches
111//
112// This functor finds inventory items pointing to the specified asset
113//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114class LLViewerInventoryItem;
115
116class LLAssetIDMatches : public LLInventoryCollectFunctor
117{
118public:
119	LLAssetIDMatches(const LLUUID& asset_id) : mAssetID(asset_id) {}
120	virtual ~LLAssetIDMatches() {}
121	bool operator()(LLInventoryCategory* cat, LLInventoryItem* item);
122	
123protected:
124	LLUUID mAssetID;
125};
126
127//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
128// Class LLLinkedItemIDMatches
129//
130// This functor finds inventory items linked to the specific inventory id.
131// Assumes the inventory id is itself not a linked item.
132//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
133class LLLinkedItemIDMatches : public LLInventoryCollectFunctor
134{
135public:
136	LLLinkedItemIDMatches(const LLUUID& item_id) : mBaseItemID(item_id) {}
137	virtual ~LLLinkedItemIDMatches() {}
138	bool operator()(LLInventoryCategory* cat, LLInventoryItem* item);
139	
140protected:
141	LLUUID mBaseItemID;
142};
143
144//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145// Class LLIsType
146//
147// Implementation of a LLInventoryCollectFunctor which returns TRUE if
148// the type is the type passed in during construction.
149//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150
151class LLIsType : public LLInventoryCollectFunctor
152{
153public:
154	LLIsType(LLAssetType::EType type) : mType(type) {}
155	virtual ~LLIsType() {}
156	virtual bool operator()(LLInventoryCategory* cat,
157							LLInventoryItem* item);
158protected:
159	LLAssetType::EType mType;
160};
161
162//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
163// Class LLIsNotType
164//
165// Implementation of a LLInventoryCollectFunctor which returns FALSE if the
166// type is the type passed in during construction, otherwise false.
167//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
168class LLIsNotType : public LLInventoryCollectFunctor
169{
170public:
171	LLIsNotType(LLAssetType::EType type) : mType(type) {}
172	virtual ~LLIsNotType() {}
173	virtual bool operator()(LLInventoryCategory* cat,
174							LLInventoryItem* item);
175protected:
176	LLAssetType::EType mType;
177};
178
179//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
180// Class LLIsOfAssetType
181//
182// Implementation of a LLInventoryCollectFunctor which returns TRUE if
183// the item or category is of asset type passed in during construction.
184// Link types are treated as links, not as the types they point to.
185//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
186
187class LLIsOfAssetType : public LLInventoryCollectFunctor
188{
189public:
190	LLIsOfAssetType(LLAssetType::EType type) : mType(type) {}
191	virtual ~LLIsOfAssetType() {}
192	virtual bool operator()(LLInventoryCategory* cat,
193							LLInventoryItem* item);
194protected:
195	LLAssetType::EType mType;
196};
197
198class LLIsTypeWithPermissions : public LLInventoryCollectFunctor
199{
200public:
201	LLIsTypeWithPermissions(LLAssetType::EType type, const PermissionBit perms, const LLUUID &agent_id, const LLUUID &group_id) 
202		: mType(type), mPerm(perms), mAgentID(agent_id), mGroupID(group_id) {}
203	virtual ~LLIsTypeWithPermissions() {}
204	virtual bool operator()(LLInventoryCategory* cat,
205							LLInventoryItem* item);
206protected:
207	LLAssetType::EType mType;
208	PermissionBit mPerm;
209	LLUUID			mAgentID;
210	LLUUID			mGroupID;
211};
212
213//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
214// Class LLBuddyCollector
215//
216// Simple class that collects calling cards that are not null, and not
217// the agent. Duplicates are possible.
218//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
219class LLBuddyCollector : public LLInventoryCollectFunctor
220{
221public:
222	LLBuddyCollector() {}
223	virtual ~LLBuddyCollector() {}
224	virtual bool operator()(LLInventoryCategory* cat,
225							LLInventoryItem* item);
226};
227
228//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
229// Class LLUniqueBuddyCollector
230//
231// Simple class that collects calling cards that are not null, and not
232// the agent. Duplicates are discarded.
233//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
234class LLUniqueBuddyCollector : public LLInventoryCollectFunctor
235{
236public:
237	LLUniqueBuddyCollector() {}
238	virtual ~LLUniqueBuddyCollector() {}
239	virtual bool operator()(LLInventoryCategory* cat,
240							LLInventoryItem* item);
241
242protected:
243	std::set<LLUUID> mSeen;
244};
245
246//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
247// Class LLParticularBuddyCollector
248//
249// Simple class that collects calling cards that match a particular uuid
250//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
251
252class LLParticularBuddyCollector : public LLInventoryCollectFunctor
253{
254public:
255	LLParticularBuddyCollector(const LLUUID& id) : mBuddyID(id) {}
256	virtual ~LLParticularBuddyCollector() {}
257	virtual bool operator()(LLInventoryCategory* cat,
258							LLInventoryItem* item);
259protected:
260	LLUUID mBuddyID;
261};
262
263//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
264// Class LLNameCategoryCollector
265//
266// Collects categories based on case-insensitive match of prefix
267//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
268class LLNameCategoryCollector : public LLInventoryCollectFunctor
269{
270public:
271	LLNameCategoryCollector(const std::string& name) : mName(name) {}
272	virtual ~LLNameCategoryCollector() {}
273	virtual bool operator()(LLInventoryCategory* cat,
274							LLInventoryItem* item);
275protected:
276	std::string mName;
277};
278
279//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
280// Class LLFindCOFValidItems
281//
282// Collects items that can be legitimately linked to in the COF.
283//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
284class LLFindCOFValidItems : public LLInventoryCollectFunctor
285{
286public:
287	LLFindCOFValidItems() {}
288	virtual ~LLFindCOFValidItems() {}
289	virtual bool operator()(LLInventoryCategory* cat,
290							LLInventoryItem* item);
291	
292};
293
294//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
295// Class LLFindByMask
296//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
297class LLFindByMask : public LLInventoryCollectFunctor
298{
299public:
300	LLFindByMask(U64 mask)
301		: mFilterMask(mask)
302	{}
303
304	virtual bool operator()(LLInventoryCategory* cat, LLInventoryItem* item)
305	{
306		//converting an inventory type to a bitmap filter mask
307		if(item && (mFilterMask & (1LL << item->getInventoryType())) )
308		{
309			return true;
310		}
311
312		return false;
313	}
314
315private:
316	U64 mFilterMask;
317};
318
319//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
320// Class LLFindNonLinksByMask
321//
322//
323//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
324class LLFindNonLinksByMask : public LLInventoryCollectFunctor
325{
326public:
327	LLFindNonLinksByMask(U64 mask)
328		: mFilterMask(mask)
329	{}
330
331	virtual bool operator()(LLInventoryCategory* cat, LLInventoryItem* item)
332	{
333		if(item && !item->getIsLinkType() && (mFilterMask & (1LL << item->getInventoryType())) )
334		{
335			return true;
336		}
337
338		return false;
339	}
340
341	void setFilterMask(U64 mask)
342	{
343		mFilterMask = mask;
344	}
345
346private:
347	U64 mFilterMask;
348};
349
350//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
351// Class LLFindWearables
352//
353// Collects wearables based on item type.
354//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
355class LLFindWearables : public LLInventoryCollectFunctor
356{
357public:
358	LLFindWearables() {}
359	virtual ~LLFindWearables() {}
360	virtual bool operator()(LLInventoryCategory* cat,
361							LLInventoryItem* item);
362};
363
364//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
365// Class LLFindWearablesEx
366//
367// Collects wearables based on given criteria.
368//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
369class LLFindWearablesEx : public LLInventoryCollectFunctor
370{
371public:
372	LLFindWearablesEx(bool is_worn, bool include_body_parts = true);
373	virtual bool operator()(LLInventoryCategory* cat, LLInventoryItem* item);
374private:
375	bool mIncludeBodyParts;
376	bool mIsWorn;
377};
378
379//Inventory collect functor collecting wearables of a specific wearable type
380class LLFindWearablesOfType : public LLInventoryCollectFunctor
381{
382public:
383	LLFindWearablesOfType(LLWearableType::EType type) : mWearableType(type) {}
384	virtual ~LLFindWearablesOfType() {}
385	virtual bool operator()(LLInventoryCategory* cat, LLInventoryItem* item);
386	void setType(LLWearableType::EType type);
387
388private:
389	LLWearableType::EType mWearableType;
390};
391
392/** Filter out wearables-links */
393class LLFindActualWearablesOfType : public LLFindWearablesOfType
394{
395public:
396	LLFindActualWearablesOfType(LLWearableType::EType type) : LLFindWearablesOfType(type) {}
397	virtual ~LLFindActualWearablesOfType() {}
398	virtual bool operator()(LLInventoryCategory* cat, LLInventoryItem* item)
399	{
400		if (item && item->getIsLinkType()) return false;
401		return LLFindWearablesOfType::operator()(cat, item);
402	}
403};
404
405/* Filters out items of a particular asset type */
406class LLIsTypeActual : public LLIsType
407{
408public:
409	LLIsTypeActual(LLAssetType::EType type) : LLIsType(type) {}
410	virtual ~LLIsTypeActual() {}
411	virtual bool operator()(LLInventoryCategory* cat, LLInventoryItem* item)
412	{
413		if (item && item->getIsLinkType()) return false;
414		return LLIsType::operator()(cat, item);
415	}
416};
417
418// Collect non-removable folders and items.
419class LLFindNonRemovableObjects : public LLInventoryCollectFunctor
420{
421public:
422	virtual bool operator()(LLInventoryCategory* cat, LLInventoryItem* item);
423};
424
425/**                    Inventory Collector Functions
426 **                                                                            **
427 *******************************************************************************/
428class LLFolderViewItem;
429class LLFolderViewFolder;
430
431//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
432// Class LLFolderViewFunctor
433//
434// Simple abstract base class for applying a functor to folders and
435// items in a folder view hierarchy. This is suboptimal for algorithms
436// that only work folders or only work on items, but I'll worry about
437// that later when it's determined to be too slow.
438//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
439class LLFolderViewFunctor
440{
441public:
442	virtual ~LLFolderViewFunctor() {}
443	virtual void doFolder(LLFolderViewFolder* folder) = 0;
444	virtual void doItem(LLFolderViewItem* item) = 0;
445};
446
447class LLInventoryState
448{
449public:
450	// HACK: Until we can route this info through the instant message hierarchy
451	static BOOL sWearNewClothing;
452	static LLUUID sWearNewClothingTransactionID;	// wear all clothing in this transaction	
453};
454
455class LLSelectFirstFilteredItem : public LLFolderViewFunctor
456{
457public:
458	LLSelectFirstFilteredItem() : mItemSelected(FALSE) {}
459	virtual ~LLSelectFirstFilteredItem() {}
460	virtual void doFolder(LLFolderViewFolder* folder);
461	virtual void doItem(LLFolderViewItem* item);
462	BOOL wasItemSelected() { return mItemSelected; }
463protected:
464	BOOL mItemSelected;
465};
466
467class LLOpenFilteredFolders : public LLFolderViewFunctor
468{
469public:
470	LLOpenFilteredFolders()  {}
471	virtual ~LLOpenFilteredFolders() {}
472	virtual void doFolder(LLFolderViewFolder* folder);
473	virtual void doItem(LLFolderViewItem* item);
474};
475
476class LLSaveFolderState : public LLFolderViewFunctor
477{
478public:
479	LLSaveFolderState() : mApply(FALSE) {}
480	virtual ~LLSaveFolderState() {}
481	virtual void doFolder(LLFolderViewFolder* folder);
482	virtual void doItem(LLFolderViewItem* item) {}
483	void setApply(BOOL apply);
484	void clearOpenFolders() { mOpenFolders.clear(); }
485protected:
486	std::set<LLUUID> mOpenFolders;
487	BOOL mApply;
488};
489
490class LLOpenFoldersWithSelection : public LLFolderViewFunctor
491{
492public:
493	LLOpenFoldersWithSelection() {}
494	virtual ~LLOpenFoldersWithSelection() {}
495	virtual void doFolder(LLFolderViewFolder* folder);
496	virtual void doItem(LLFolderViewItem* item);
497};
498
499#endif // LL_LLINVENTORYFUNCTIONS_H
500
501
502