llviewerfoldertype.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:10k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llfoldertype.cpp
  3.  * @brief Implementation of LLViewerFolderType functionality.
  4.  *
  5.  * $LicenseInfo:firstyear=2001&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2001-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llviewerfoldertype.h"
  34. #include "lldictionary.h"
  35. #include "llmemory.h"
  36. #include "llvisualparam.h"
  37. static const std::string empty_string;
  38. struct ViewerFolderEntry : public LLDictionaryEntry
  39. {
  40. // Constructor for non-ensembles
  41. ViewerFolderEntry(const std::string &new_category_name, // default name when creating a new category of this type
  42.   const std::string &icon_name, // name of the folder icon
  43.   BOOL is_quiet // folder doesn't need a UI update when changed
  44. :
  45. LLDictionaryEntry(empty_string), // no reverse lookup needed on non-ensembles, so just leave this blank
  46. mIconName(icon_name),
  47. mNewCategoryName(new_category_name),
  48. mIsQuiet(is_quiet)
  49. {
  50. mAllowedNames.clear();
  51. }
  52. // Constructor for ensembles
  53. ViewerFolderEntry(const std::string &xui_name,  // name of the xui menu item
  54.   const std::string &new_category_name, // default name when creating a new category of this type
  55.   const std::string &icon_name,  // name of the folder icon
  56.   const std::string allowed_names  // allowed item typenames for this folder type
  57. :
  58. LLDictionaryEntry(xui_name),
  59. mIconName(icon_name),
  60. mNewCategoryName(new_category_name),
  61. mIsQuiet(FALSE)
  62. {
  63. const std::string delims (",");
  64. LLStringUtilBase<char>::getTokens(allowed_names, mAllowedNames, delims);
  65. }
  66. bool getIsAllowedName(const std::string &name) const
  67. {
  68. if (mAllowedNames.empty())
  69. return false;
  70. for (name_vec_t::const_iterator iter = mAllowedNames.begin();
  71.  iter != mAllowedNames.end();
  72.  iter++)
  73. {
  74. if (name == (*iter))
  75. return true;
  76. }
  77. return false;
  78. }
  79. const std::string mIconName;
  80. const std::string mNewCategoryName;
  81. typedef std::vector<std::string> name_vec_t;
  82. name_vec_t mAllowedNames;
  83. BOOL mIsQuiet;
  84. };
  85. class LLViewerFolderDictionary : public LLSingleton<LLViewerFolderDictionary>,
  86.  public LLDictionary<LLFolderType::EType, ViewerFolderEntry>
  87. {
  88. public:
  89. LLViewerFolderDictionary();
  90. protected:
  91. bool initEnsemblesFromFile(); // Reads in ensemble information from foldertypes.xml
  92. };
  93. LLViewerFolderDictionary::LLViewerFolderDictionary()
  94. {
  95. initEnsemblesFromFile();
  96. //               NEW CATEGORY NAME         FOLDER ICON NAME                QUIET?
  97. //               |-------------------------|-------------------------------|-----------|
  98. addEntry(LLFolderType::FT_TEXTURE,  new ViewerFolderEntry("Textures", "inv_folder_texture.tga", FALSE));
  99. addEntry(LLFolderType::FT_SOUND,  new ViewerFolderEntry("Sounds", "inv_folder_sound.tga", FALSE));
  100. addEntry(LLFolderType::FT_CALLINGCARD,  new ViewerFolderEntry("Calling Cards", "inv_folder_callingcard.tga", FALSE));
  101. addEntry(LLFolderType::FT_LANDMARK,  new ViewerFolderEntry("Landmarks", "inv_folder_landmark.tga", FALSE));
  102. addEntry(LLFolderType::FT_CLOTHING,  new ViewerFolderEntry("Clothing", "inv_folder_clothing.tga", FALSE));
  103. addEntry(LLFolderType::FT_OBJECT,  new ViewerFolderEntry("Objects", "inv_folder_object.tga", FALSE));
  104. addEntry(LLFolderType::FT_NOTECARD,  new ViewerFolderEntry("Notecards", "inv_folder_notecard.tga", FALSE));
  105. addEntry(LLFolderType::FT_ROOT_INVENTORY,  new ViewerFolderEntry("My Inventory", "", FALSE));
  106. addEntry(LLFolderType::FT_LSL_TEXT,  new ViewerFolderEntry("Scripts", "inv_folder_script.tga", FALSE));
  107. addEntry(LLFolderType::FT_BODYPART,  new ViewerFolderEntry("Body Parts", "inv_folder_bodypart.tga", FALSE));
  108. addEntry(LLFolderType::FT_TRASH,  new ViewerFolderEntry("Trash", "inv_folder_trash.tga", TRUE));
  109. addEntry(LLFolderType::FT_SNAPSHOT_CATEGORY,  new ViewerFolderEntry("Photo Album", "inv_folder_snapshot.tga", FALSE));
  110. addEntry(LLFolderType::FT_LOST_AND_FOUND,  new ViewerFolderEntry("Lost And Found",     "inv_folder_lostandfound.tga", TRUE));
  111. addEntry(LLFolderType::FT_ANIMATION,  new ViewerFolderEntry("Animations", "inv_folder_animation.tga", FALSE));
  112. addEntry(LLFolderType::FT_GESTURE,  new ViewerFolderEntry("Gestures", "inv_folder_gesture.tga", FALSE));
  113. addEntry(LLFolderType::FT_FAVORITE,  new ViewerFolderEntry("Favorites", "inv_folder_plain_closed.tga", FALSE));
  114. addEntry(LLFolderType::FT_CURRENT_OUTFIT,  new ViewerFolderEntry("Current Outfit", "inv_folder_current_outfit.tga",TRUE));
  115. addEntry(LLFolderType::FT_OUTFIT,  new ViewerFolderEntry("New Outfit", "inv_folder_outfit.tga", TRUE));
  116. addEntry(LLFolderType::FT_MY_OUTFITS,  new ViewerFolderEntry("My Outfits", "inv_folder_my_outfits.tga", TRUE));
  117. addEntry(LLFolderType::FT_INBOX,  new ViewerFolderEntry("Inbox", "inv_folder_inbox.tga", FALSE));
  118.  
  119. addEntry(LLFolderType::FT_NONE,  new ViewerFolderEntry("New Folder", "inv_folder_plain_closed.tga", FALSE));
  120. }
  121. bool LLViewerFolderDictionary::initEnsemblesFromFile()
  122. {
  123. std::string xml_filename = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,"foldertypes.xml");
  124. LLXmlTree folder_def;
  125. if (!folder_def.parseFile(xml_filename))
  126. {
  127. llerrs << "Failed to parse folders file " << xml_filename << llendl;
  128. return false;
  129. }
  130. LLXmlTreeNode* rootp = folder_def.getRoot();
  131. for (LLXmlTreeNode* ensemble = rootp->getFirstChild();
  132.  ensemble;
  133.  ensemble = rootp->getNextChild())
  134. {
  135. if (!ensemble->hasName("ensemble"))
  136. {
  137. llwarns << "Invalid ensemble definition node " << ensemble->getName() << llendl;
  138. continue;
  139. }
  140. S32 ensemble_type;
  141. static LLStdStringHandle ensemble_num_string = LLXmlTree::addAttributeString("foldertype_num");
  142. if (!ensemble->getFastAttributeS32(ensemble_num_string, ensemble_type))
  143. {
  144. llwarns << "No ensemble type defined" << llendl;
  145. continue;
  146. }
  147. if (ensemble_type < S32(LLFolderType::FT_ENSEMBLE_START) || ensemble_type > S32(LLFolderType::FT_ENSEMBLE_END))
  148. {
  149. llwarns << "Exceeded maximum ensemble index" << LLFolderType::FT_ENSEMBLE_END << llendl;
  150. break;
  151. }
  152. std::string xui_name;
  153. static LLStdStringHandle xui_name_string = LLXmlTree::addAttributeString("xui_name");
  154. if (!ensemble->getFastAttributeString(xui_name_string, xui_name))
  155. {
  156. llwarns << "No xui name defined" << llendl;
  157. continue;
  158. }
  159. std::string icon_name;
  160. static LLStdStringHandle icon_name_string = LLXmlTree::addAttributeString("icon_name");
  161. if (!ensemble->getFastAttributeString(icon_name_string, icon_name))
  162. {
  163. llwarns << "No ensemble icon name defined" << llendl;
  164. continue;
  165. }
  166. std::string allowed_names;
  167. static LLStdStringHandle allowed_names_string = LLXmlTree::addAttributeString("allowed");
  168. if (!ensemble->getFastAttributeString(allowed_names_string, allowed_names))
  169. {
  170. }
  171. // Add the entry and increment the asset number.
  172. const static std::string new_ensemble_name = "New Ensemble";
  173. addEntry(LLFolderType::EType(ensemble_type), new ViewerFolderEntry(xui_name, new_ensemble_name, icon_name, allowed_names));
  174. }
  175. return true;
  176. }
  177. const std::string &LLViewerFolderType::lookupXUIName(LLFolderType::EType folder_type)
  178. {
  179. const ViewerFolderEntry *entry = LLViewerFolderDictionary::getInstance()->lookup(folder_type);
  180. if (entry)
  181. {
  182. return entry->mName;
  183. }
  184. return badLookup();
  185. }
  186. LLFolderType::EType LLViewerFolderType::lookupTypeFromXUIName(const std::string &name)
  187. {
  188. return LLViewerFolderDictionary::getInstance()->lookup(name);
  189. }
  190. const std::string &LLViewerFolderType::lookupIconName(LLFolderType::EType folder_type)
  191. {
  192. const ViewerFolderEntry *entry = LLViewerFolderDictionary::getInstance()->lookup(folder_type);
  193. if (entry)
  194. {
  195. return entry->mIconName;
  196. }
  197. return badLookup();
  198. }
  199. BOOL LLViewerFolderType::lookupIsQuietType(LLFolderType::EType folder_type)
  200. {
  201. const ViewerFolderEntry *entry = LLViewerFolderDictionary::getInstance()->lookup(folder_type);
  202. if (entry)
  203. {
  204. return entry->mIsQuiet;
  205. }
  206. return FALSE;
  207. }
  208. const std::string &LLViewerFolderType::lookupNewCategoryName(LLFolderType::EType folder_type)
  209. {
  210. const ViewerFolderEntry *entry = LLViewerFolderDictionary::getInstance()->lookup(folder_type);
  211. if (entry)
  212. {
  213. return entry->mNewCategoryName;
  214. }
  215. return badLookup();
  216. }
  217. LLFolderType::EType LLViewerFolderType::lookupTypeFromNewCategoryName(const std::string& name)
  218. {
  219. for (LLViewerFolderDictionary::const_iterator iter = LLViewerFolderDictionary::getInstance()->begin();
  220.  iter != LLViewerFolderDictionary::getInstance()->end();
  221.  iter++)
  222. {
  223. const ViewerFolderEntry *entry = iter->second;
  224. if (entry->mNewCategoryName == name)
  225. {
  226. return iter->first;
  227. }
  228. }
  229. return FT_NONE;
  230. }
  231. U64 LLViewerFolderType::lookupValidFolderTypes(const std::string& item_name)
  232. {
  233. U64 matching_folders = 0;
  234. for (LLViewerFolderDictionary::const_iterator iter = LLViewerFolderDictionary::getInstance()->begin();
  235.  iter != LLViewerFolderDictionary::getInstance()->end();
  236.  iter++)
  237. {
  238. const ViewerFolderEntry *entry = iter->second;
  239. if (entry->getIsAllowedName(item_name))
  240. {
  241. matching_folders |= 1LL << iter->first;
  242. }
  243. }
  244. return matching_folders;
  245. }