PageRenderTime 28ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/indra/newview/llviewerfoldertype.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 316 lines | 245 code | 35 blank | 36 comment | 29 complexity | a06bb8676d4721028e961c61d13de32d MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfoldertype.cpp
  3. * @brief Implementation of LLViewerFolderType functionality.
  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 "llviewerprecompiledheaders.h"
  27. #include "llviewerfoldertype.h"
  28. #include "lldictionary.h"
  29. #include "llmemory.h"
  30. #include "llvisualparam.h"
  31. static const std::string empty_string;
  32. struct ViewerFolderEntry : public LLDictionaryEntry
  33. {
  34. // Constructor for non-ensembles
  35. ViewerFolderEntry(const std::string &new_category_name, // default name when creating a new category of this type
  36. const std::string &icon_name_open, // name of the folder icon
  37. const std::string &icon_name_closed,
  38. BOOL is_quiet, // folder doesn't need a UI update when changed
  39. bool hide_if_empty, // folder not shown if empty
  40. const std::string &dictionary_name = empty_string // no reverse lookup needed on non-ensembles, so in most cases just leave this blank
  41. )
  42. :
  43. LLDictionaryEntry(dictionary_name),
  44. mNewCategoryName(new_category_name),
  45. mIconNameOpen(icon_name_open),
  46. mIconNameClosed(icon_name_closed),
  47. mIsQuiet(is_quiet),
  48. mHideIfEmpty(hide_if_empty)
  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. :
  59. LLDictionaryEntry(xui_name),
  60. /* Just use default icons until we actually support ensembles
  61. mIconNameOpen(icon_name),
  62. mIconNameClosed(icon_name),
  63. */
  64. mIconNameOpen("Inv_FolderOpen"), mIconNameClosed("Inv_FolderClosed"),
  65. mNewCategoryName(new_category_name),
  66. mIsQuiet(FALSE),
  67. mHideIfEmpty(false)
  68. {
  69. const std::string delims (",");
  70. LLStringUtilBase<char>::getTokens(allowed_names, mAllowedNames, delims);
  71. }
  72. bool getIsAllowedName(const std::string &name) const
  73. {
  74. if (mAllowedNames.empty())
  75. return false;
  76. for (name_vec_t::const_iterator iter = mAllowedNames.begin();
  77. iter != mAllowedNames.end();
  78. iter++)
  79. {
  80. if (name == (*iter))
  81. return true;
  82. }
  83. return false;
  84. }
  85. const std::string mIconNameOpen;
  86. const std::string mIconNameClosed;
  87. const std::string mNewCategoryName;
  88. typedef std::vector<std::string> name_vec_t;
  89. name_vec_t mAllowedNames;
  90. BOOL mIsQuiet;
  91. bool mHideIfEmpty;
  92. };
  93. class LLViewerFolderDictionary : public LLSingleton<LLViewerFolderDictionary>,
  94. public LLDictionary<LLFolderType::EType, ViewerFolderEntry>
  95. {
  96. public:
  97. LLViewerFolderDictionary();
  98. protected:
  99. bool initEnsemblesFromFile(); // Reads in ensemble information from foldertypes.xml
  100. };
  101. LLViewerFolderDictionary::LLViewerFolderDictionary()
  102. {
  103. // NEW CATEGORY NAME FOLDER OPEN FOLDER CLOSED QUIET? HIDE IF EMPTY?
  104. // |-------------------------|-----------------------|----------------------|-----------|--------------|
  105. addEntry(LLFolderType::FT_TEXTURE, new ViewerFolderEntry("Textures", "Inv_SysOpen", "Inv_SysClosed", FALSE, true));
  106. addEntry(LLFolderType::FT_SOUND, new ViewerFolderEntry("Sounds", "Inv_SysOpen", "Inv_SysClosed", FALSE, true));
  107. addEntry(LLFolderType::FT_CALLINGCARD, new ViewerFolderEntry("Calling Cards", "Inv_SysOpen", "Inv_SysClosed", FALSE, true));
  108. addEntry(LLFolderType::FT_LANDMARK, new ViewerFolderEntry("Landmarks", "Inv_SysOpen", "Inv_SysClosed", FALSE, true));
  109. addEntry(LLFolderType::FT_CLOTHING, new ViewerFolderEntry("Clothing", "Inv_SysOpen", "Inv_SysClosed", FALSE, true));
  110. addEntry(LLFolderType::FT_OBJECT, new ViewerFolderEntry("Objects", "Inv_SysOpen", "Inv_SysClosed", FALSE, true));
  111. addEntry(LLFolderType::FT_NOTECARD, new ViewerFolderEntry("Notecards", "Inv_SysOpen", "Inv_SysClosed", FALSE, true));
  112. addEntry(LLFolderType::FT_ROOT_INVENTORY, new ViewerFolderEntry("My Inventory", "Inv_SysOpen", "Inv_SysClosed", FALSE, false));
  113. addEntry(LLFolderType::FT_LSL_TEXT, new ViewerFolderEntry("Scripts", "Inv_SysOpen", "Inv_SysClosed", FALSE, true));
  114. addEntry(LLFolderType::FT_BODYPART, new ViewerFolderEntry("Body Parts", "Inv_SysOpen", "Inv_SysClosed", FALSE, true));
  115. addEntry(LLFolderType::FT_TRASH, new ViewerFolderEntry("Trash", "Inv_TrashOpen", "Inv_TrashClosed", TRUE, false));
  116. addEntry(LLFolderType::FT_SNAPSHOT_CATEGORY, new ViewerFolderEntry("Photo Album", "Inv_SysOpen", "Inv_SysClosed", FALSE, true));
  117. addEntry(LLFolderType::FT_LOST_AND_FOUND, new ViewerFolderEntry("Lost And Found", "Inv_LostOpen", "Inv_LostClosed", TRUE, true));
  118. addEntry(LLFolderType::FT_ANIMATION, new ViewerFolderEntry("Animations", "Inv_SysOpen", "Inv_SysClosed", FALSE, true));
  119. addEntry(LLFolderType::FT_GESTURE, new ViewerFolderEntry("Gestures", "Inv_SysOpen", "Inv_SysClosed", FALSE, true));
  120. addEntry(LLFolderType::FT_FAVORITE, new ViewerFolderEntry("Favorites", "Inv_SysOpen", "Inv_SysClosed", FALSE, true));
  121. addEntry(LLFolderType::FT_CURRENT_OUTFIT, new ViewerFolderEntry("Current Outfit", "Inv_SysOpen", "Inv_SysClosed", TRUE, false));
  122. addEntry(LLFolderType::FT_OUTFIT, new ViewerFolderEntry("New Outfit", "Inv_LookFolderOpen", "Inv_LookFolderClosed", TRUE, true));
  123. addEntry(LLFolderType::FT_MY_OUTFITS, new ViewerFolderEntry("My Outfits", "Inv_SysOpen", "Inv_SysClosed", TRUE, true));
  124. addEntry(LLFolderType::FT_MESH, new ViewerFolderEntry("Meshes", "Inv_SysOpen", "Inv_SysClosed", FALSE, true));
  125. addEntry(LLFolderType::FT_INBOX, new ViewerFolderEntry("Inbox", "Inv_SysOpen", "Inv_SysClosed", FALSE, true));
  126. addEntry(LLFolderType::FT_OUTBOX, new ViewerFolderEntry("Outbox", "Inv_SysOpen", "Inv_SysClosed", FALSE, true));
  127. addEntry(LLFolderType::FT_BASIC_ROOT, new ViewerFolderEntry("Basic Root", "Inv_SysOpen", "Inv_SysClosed", FALSE, true));
  128. addEntry(LLFolderType::FT_NONE, new ViewerFolderEntry("New Folder", "Inv_FolderOpen", "Inv_FolderClosed", FALSE, false, "default"));
  129. #if SUPPORT_ENSEMBLES
  130. initEnsemblesFromFile();
  131. #else
  132. for (U32 type = (U32)LLFolderType::FT_ENSEMBLE_START; type <= (U32)LLFolderType::FT_ENSEMBLE_END; ++type)
  133. {
  134. addEntry((LLFolderType::EType)type, new ViewerFolderEntry("New Folder", "Inv_FolderOpen", "Inv_FolderClosed", FALSE, false));
  135. }
  136. #endif
  137. }
  138. bool LLViewerFolderDictionary::initEnsemblesFromFile()
  139. {
  140. std::string xml_filename = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,"foldertypes.xml");
  141. LLXmlTree folder_def;
  142. if (!folder_def.parseFile(xml_filename))
  143. {
  144. llerrs << "Failed to parse folders file " << xml_filename << llendl;
  145. return false;
  146. }
  147. LLXmlTreeNode* rootp = folder_def.getRoot();
  148. for (LLXmlTreeNode* ensemble = rootp->getFirstChild();
  149. ensemble;
  150. ensemble = rootp->getNextChild())
  151. {
  152. if (!ensemble->hasName("ensemble"))
  153. {
  154. llwarns << "Invalid ensemble definition node " << ensemble->getName() << llendl;
  155. continue;
  156. }
  157. S32 ensemble_type;
  158. static LLStdStringHandle ensemble_num_string = LLXmlTree::addAttributeString("foldertype_num");
  159. if (!ensemble->getFastAttributeS32(ensemble_num_string, ensemble_type))
  160. {
  161. llwarns << "No ensemble type defined" << llendl;
  162. continue;
  163. }
  164. if (ensemble_type < S32(LLFolderType::FT_ENSEMBLE_START) || ensemble_type > S32(LLFolderType::FT_ENSEMBLE_END))
  165. {
  166. llwarns << "Exceeded maximum ensemble index" << LLFolderType::FT_ENSEMBLE_END << llendl;
  167. break;
  168. }
  169. std::string xui_name;
  170. static LLStdStringHandle xui_name_string = LLXmlTree::addAttributeString("xui_name");
  171. if (!ensemble->getFastAttributeString(xui_name_string, xui_name))
  172. {
  173. llwarns << "No xui name defined" << llendl;
  174. continue;
  175. }
  176. std::string icon_name;
  177. static LLStdStringHandle icon_name_string = LLXmlTree::addAttributeString("icon_name");
  178. if (!ensemble->getFastAttributeString(icon_name_string, icon_name))
  179. {
  180. llwarns << "No ensemble icon name defined" << llendl;
  181. continue;
  182. }
  183. std::string allowed_names;
  184. static LLStdStringHandle allowed_names_string = LLXmlTree::addAttributeString("allowed");
  185. if (!ensemble->getFastAttributeString(allowed_names_string, allowed_names))
  186. {
  187. }
  188. // Add the entry and increment the asset number.
  189. const static std::string new_ensemble_name = "New Ensemble";
  190. addEntry(LLFolderType::EType(ensemble_type), new ViewerFolderEntry(xui_name, new_ensemble_name, icon_name, allowed_names));
  191. }
  192. return true;
  193. }
  194. const std::string &LLViewerFolderType::lookupXUIName(LLFolderType::EType folder_type)
  195. {
  196. const ViewerFolderEntry *entry = LLViewerFolderDictionary::getInstance()->lookup(folder_type);
  197. if (entry)
  198. {
  199. return entry->mName;
  200. }
  201. return badLookup();
  202. }
  203. LLFolderType::EType LLViewerFolderType::lookupTypeFromXUIName(const std::string &name)
  204. {
  205. return LLViewerFolderDictionary::getInstance()->lookup(name);
  206. }
  207. const std::string &LLViewerFolderType::lookupIconName(LLFolderType::EType folder_type, BOOL is_open)
  208. {
  209. const ViewerFolderEntry *entry = LLViewerFolderDictionary::getInstance()->lookup(folder_type);
  210. if (entry)
  211. {
  212. if (is_open)
  213. return entry->mIconNameOpen;
  214. else
  215. return entry->mIconNameClosed;
  216. }
  217. // Error condition. Return something so that we don't show a grey box in inventory view.
  218. const ViewerFolderEntry *default_entry = LLViewerFolderDictionary::getInstance()->lookup(LLFolderType::FT_NONE);
  219. if (default_entry)
  220. {
  221. return default_entry->mIconNameClosed;
  222. }
  223. // Should not get here unless there's something corrupted with the FT_NONE entry.
  224. return badLookup();
  225. }
  226. BOOL LLViewerFolderType::lookupIsQuietType(LLFolderType::EType folder_type)
  227. {
  228. const ViewerFolderEntry *entry = LLViewerFolderDictionary::getInstance()->lookup(folder_type);
  229. if (entry)
  230. {
  231. return entry->mIsQuiet;
  232. }
  233. return FALSE;
  234. }
  235. bool LLViewerFolderType::lookupIsHiddenIfEmpty(LLFolderType::EType folder_type)
  236. {
  237. const ViewerFolderEntry *entry = LLViewerFolderDictionary::getInstance()->lookup(folder_type);
  238. if (entry)
  239. {
  240. return entry->mHideIfEmpty;
  241. }
  242. return false;
  243. }
  244. const std::string &LLViewerFolderType::lookupNewCategoryName(LLFolderType::EType folder_type)
  245. {
  246. const ViewerFolderEntry *entry = LLViewerFolderDictionary::getInstance()->lookup(folder_type);
  247. if (entry)
  248. {
  249. return entry->mNewCategoryName;
  250. }
  251. return badLookup();
  252. }
  253. LLFolderType::EType LLViewerFolderType::lookupTypeFromNewCategoryName(const std::string& name)
  254. {
  255. for (LLViewerFolderDictionary::const_iterator iter = LLViewerFolderDictionary::getInstance()->begin();
  256. iter != LLViewerFolderDictionary::getInstance()->end();
  257. iter++)
  258. {
  259. const ViewerFolderEntry *entry = iter->second;
  260. if (entry->mNewCategoryName == name)
  261. {
  262. return iter->first;
  263. }
  264. }
  265. return FT_NONE;
  266. }
  267. U64 LLViewerFolderType::lookupValidFolderTypes(const std::string& item_name)
  268. {
  269. U64 matching_folders = 0;
  270. for (LLViewerFolderDictionary::const_iterator iter = LLViewerFolderDictionary::getInstance()->begin();
  271. iter != LLViewerFolderDictionary::getInstance()->end();
  272. iter++)
  273. {
  274. const ViewerFolderEntry *entry = iter->second;
  275. if (entry->getIsAllowedName(item_name))
  276. {
  277. matching_folders |= 1LL << iter->first;
  278. }
  279. }
  280. return matching_folders;
  281. }