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