PageRenderTime 35ms CodeModel.GetById 9ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llinventory/llinventorytype.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 224 lines | 163 code | 20 blank | 41 comment | 11 complexity | f813b080f30560d5ffd0e54e03ea9b2e MD5 | raw file
  1/** 
  2 * @file llinventorytype.cpp
  3 * @brief Inventory item type, more specific than an asset type.
  4 *
  5 * $LicenseInfo:firstyear=2001&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#include "linden_common.h"
 28
 29#include "llinventorytype.h"
 30#include "lldictionary.h"
 31#include "llmemory.h"
 32#include "llsingleton.h"
 33
 34static const std::string empty_string;
 35
 36///----------------------------------------------------------------------------
 37/// Class LLInventoryType
 38///----------------------------------------------------------------------------
 39struct InventoryEntry : public LLDictionaryEntry
 40{
 41	InventoryEntry(const std::string &name, // unlike asset type names, not limited to 8 characters; need not match asset type names
 42				   const std::string &human_name, // for decoding to human readable form; put any and as many printable characters you want in each one.
 43				   int num_asset_types = 0, ...)
 44		:
 45		LLDictionaryEntry(name),
 46		mHumanName(human_name)
 47	{
 48		va_list argp;
 49		va_start(argp, num_asset_types);
 50		// Read in local textures
 51		for (U8 i=0; i < num_asset_types; i++)
 52		{
 53			LLAssetType::EType t = (LLAssetType::EType)va_arg(argp,int);
 54			mAssetTypes.push_back(t);
 55		}
 56	}
 57		
 58	const std::string mHumanName;
 59	typedef std::vector<LLAssetType::EType> asset_vec_t;
 60	asset_vec_t mAssetTypes;
 61};
 62
 63class LLInventoryDictionary : public LLSingleton<LLInventoryDictionary>,
 64							  public LLDictionary<LLInventoryType::EType, InventoryEntry>
 65{
 66public:
 67	LLInventoryDictionary();
 68};
 69
 70LLInventoryDictionary::LLInventoryDictionary()
 71{
 72	addEntry(LLInventoryType::IT_TEXTURE,             new InventoryEntry("texture",   "texture",       1, LLAssetType::AT_TEXTURE));
 73	addEntry(LLInventoryType::IT_SOUND,               new InventoryEntry("sound",     "sound",         1, LLAssetType::AT_SOUND));
 74	addEntry(LLInventoryType::IT_CALLINGCARD,         new InventoryEntry("callcard",  "calling card",  1, LLAssetType::AT_CALLINGCARD));
 75	addEntry(LLInventoryType::IT_LANDMARK,            new InventoryEntry("landmark",  "landmark",      1, LLAssetType::AT_LANDMARK));
 76	addEntry(LLInventoryType::IT_OBJECT,              new InventoryEntry("object",    "object",        1, LLAssetType::AT_OBJECT));
 77	addEntry(LLInventoryType::IT_NOTECARD,            new InventoryEntry("notecard",  "note card",     1, LLAssetType::AT_NOTECARD));
 78	addEntry(LLInventoryType::IT_CATEGORY,            new InventoryEntry("category",  "folder"         ));
 79	addEntry(LLInventoryType::IT_ROOT_CATEGORY,       new InventoryEntry("root",      "root"           ));
 80	addEntry(LLInventoryType::IT_LSL,                 new InventoryEntry("script",    "script",        2, LLAssetType::AT_LSL_TEXT, LLAssetType::AT_LSL_BYTECODE));
 81	addEntry(LLInventoryType::IT_SNAPSHOT,            new InventoryEntry("snapshot",  "snapshot",      1, LLAssetType::AT_TEXTURE));
 82	addEntry(LLInventoryType::IT_ATTACHMENT,          new InventoryEntry("attach",    "attachment",    1, LLAssetType::AT_OBJECT));
 83	addEntry(LLInventoryType::IT_WEARABLE,            new InventoryEntry("wearable",  "wearable",      2, LLAssetType::AT_CLOTHING, LLAssetType::AT_BODYPART));
 84	addEntry(LLInventoryType::IT_ANIMATION,           new InventoryEntry("animation", "animation",     1, LLAssetType::AT_ANIMATION));  
 85	addEntry(LLInventoryType::IT_GESTURE,             new InventoryEntry("gesture",   "gesture",       1, LLAssetType::AT_GESTURE)); 
 86	addEntry(LLInventoryType::IT_MESH,                new InventoryEntry("mesh",      "mesh",          1, LLAssetType::AT_MESH));
 87	addEntry(LLInventoryType::IT_WIDGET,              new InventoryEntry("widget",    "widget",        1, LLAssetType::AT_WIDGET));
 88}
 89
 90
 91// Maps asset types to the default inventory type for that kind of asset.
 92// Thus, "Lost and Found" is a "Category"
 93static const LLInventoryType::EType
 94DEFAULT_ASSET_FOR_INV_TYPE[LLAssetType::AT_COUNT] =
 95{
 96	LLInventoryType::IT_TEXTURE,		// 0	AT_TEXTURE
 97	LLInventoryType::IT_SOUND,			// 1	AT_SOUND
 98	LLInventoryType::IT_CALLINGCARD,	// 2	AT_CALLINGCARD
 99	LLInventoryType::IT_LANDMARK,		// 3	AT_LANDMARK
100	LLInventoryType::IT_LSL,			// 4	AT_SCRIPT
101	LLInventoryType::IT_WEARABLE,		// 5	AT_CLOTHING
102	LLInventoryType::IT_OBJECT,			// 6	AT_OBJECT
103	LLInventoryType::IT_NOTECARD,		// 7	AT_NOTECARD
104	LLInventoryType::IT_CATEGORY,		// 8	AT_CATEGORY
105	LLInventoryType::IT_NONE,			// 9	(null entry)
106	LLInventoryType::IT_LSL,			// 10	AT_LSL_TEXT
107	LLInventoryType::IT_LSL,			// 11	AT_LSL_BYTECODE
108	LLInventoryType::IT_TEXTURE,		// 12	AT_TEXTURE_TGA
109	LLInventoryType::IT_WEARABLE,		// 13	AT_BODYPART
110	LLInventoryType::IT_CATEGORY,		// 14	AT_TRASH
111	LLInventoryType::IT_CATEGORY,		// 15	AT_SNAPSHOT_CATEGORY
112	LLInventoryType::IT_CATEGORY,		// 16	AT_LOST_AND_FOUND
113	LLInventoryType::IT_SOUND,			// 17	AT_SOUND_WAV
114	LLInventoryType::IT_NONE,			// 18	AT_IMAGE_TGA
115	LLInventoryType::IT_NONE,			// 19	AT_IMAGE_JPEG
116	LLInventoryType::IT_ANIMATION,		// 20	AT_ANIMATION
117	LLInventoryType::IT_GESTURE,		// 21	AT_GESTURE
118	LLInventoryType::IT_NONE,			// 22	AT_SIMSTATE
119
120	LLInventoryType::IT_NONE,			// 23	AT_LINK
121	LLInventoryType::IT_NONE,			// 24	AT_LINK_FOLDER
122
123	LLInventoryType::IT_NONE,			// 25	AT_NONE
124	LLInventoryType::IT_NONE,			// 26	AT_NONE
125	LLInventoryType::IT_NONE,			// 27	AT_NONE
126	LLInventoryType::IT_NONE,			// 28	AT_NONE
127	LLInventoryType::IT_NONE,			// 29	AT_NONE
128	LLInventoryType::IT_NONE,			// 30	AT_NONE
129	LLInventoryType::IT_NONE,			// 31	AT_NONE
130	LLInventoryType::IT_NONE,			// 32	AT_NONE
131	LLInventoryType::IT_NONE,			// 33	AT_NONE
132	LLInventoryType::IT_NONE,			// 34	AT_NONE
133	LLInventoryType::IT_NONE,			// 35	AT_NONE
134	LLInventoryType::IT_NONE,			// 36	AT_NONE
135	LLInventoryType::IT_NONE,			// 37	AT_NONE
136	LLInventoryType::IT_NONE,			// 38	AT_NONE
137	LLInventoryType::IT_NONE,			// 39	AT_NONE
138	LLInventoryType::IT_WIDGET,			// 40	AT_WIDGET
139	LLInventoryType::IT_NONE,			// 41	AT_NONE
140	LLInventoryType::IT_NONE,			// 42	AT_NONE
141	LLInventoryType::IT_NONE,			// 43	AT_NONE
142	LLInventoryType::IT_NONE,			// 44	AT_NONE
143	LLInventoryType::IT_NONE,			// 45	AT_NONE
144	LLInventoryType::IT_NONE,			// 46	AT_NONE
145	LLInventoryType::IT_NONE,			// 47	AT_NONE
146	LLInventoryType::IT_NONE,			// 48	AT_NONE
147	LLInventoryType::IT_MESH,			// 49	AT_MESH
148};
149
150// static
151const std::string &LLInventoryType::lookup(EType type)
152{
153	const InventoryEntry *entry = LLInventoryDictionary::getInstance()->lookup(type);
154	if (!entry) return empty_string;
155	return entry->mName;
156}
157
158// static
159LLInventoryType::EType LLInventoryType::lookup(const std::string& name)
160{
161	return LLInventoryDictionary::getInstance()->lookup(name);
162}
163
164// XUI:translate
165// translation from a type to a human readable form.
166// static
167const std::string &LLInventoryType::lookupHumanReadable(EType type)
168{
169	const InventoryEntry *entry = LLInventoryDictionary::getInstance()->lookup(type);
170	if (!entry) return empty_string;
171	return entry->mHumanName;
172}
173
174// return the default inventory for the given asset type.
175// static
176LLInventoryType::EType LLInventoryType::defaultForAssetType(LLAssetType::EType asset_type)
177{
178	if((asset_type >= 0) && (asset_type < LLAssetType::AT_COUNT))
179	{
180		return DEFAULT_ASSET_FOR_INV_TYPE[S32(asset_type)];
181	}
182	else
183	{
184		return IT_NONE;
185	}
186}
187
188
189// add any types that we don't want the user to be able to change permissions on.
190// static
191bool LLInventoryType::cannotRestrictPermissions(LLInventoryType::EType type)
192{
193	switch(type)
194	{
195		case IT_CALLINGCARD:
196		case IT_LANDMARK:
197			return true;
198		default:
199			return false;
200	}
201}
202
203bool inventory_and_asset_types_match(LLInventoryType::EType inventory_type,
204									 LLAssetType::EType asset_type)
205{
206	// Links can be of any inventory type.
207	if (LLAssetType::lookupIsLinkType(asset_type))
208		return true;
209
210	const InventoryEntry *entry = LLInventoryDictionary::getInstance()->lookup(inventory_type);
211	if (!entry) return false;
212
213	for (InventoryEntry::asset_vec_t::const_iterator iter = entry->mAssetTypes.begin();
214		 iter != entry->mAssetTypes.end();
215		 iter++)
216	{
217		const LLAssetType::EType type = (*iter);
218		if(type == asset_type)
219		{
220			return true;
221		}
222	}
223	return false;
224}