PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcommon/llfoldertype.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 168 lines | 111 code | 18 blank | 39 comment | 7 complexity | 751df2013b02193977ad2a80e2a4456d MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfoldertype.cpp
  3. * @brief Implementatino of LLFolderType 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 "linden_common.h"
  27. #include "llfoldertype.h"
  28. #include "lldictionary.h"
  29. #include "llmemory.h"
  30. #include "llsingleton.h"
  31. ///----------------------------------------------------------------------------
  32. /// Class LLFolderType
  33. ///----------------------------------------------------------------------------
  34. struct FolderEntry : public LLDictionaryEntry
  35. {
  36. FolderEntry(const std::string &type_name, // 8 character limit!
  37. bool is_protected) // can the viewer change categories of this type?
  38. :
  39. LLDictionaryEntry(type_name),
  40. mIsProtected(is_protected)
  41. {
  42. llassert(type_name.length() <= 8);
  43. }
  44. const bool mIsProtected;
  45. };
  46. class LLFolderDictionary : public LLSingleton<LLFolderDictionary>,
  47. public LLDictionary<LLFolderType::EType, FolderEntry>
  48. {
  49. public:
  50. LLFolderDictionary();
  51. protected:
  52. virtual LLFolderType::EType notFound() const
  53. {
  54. return LLFolderType::FT_NONE;
  55. }
  56. };
  57. LLFolderDictionary::LLFolderDictionary()
  58. {
  59. // TYPE NAME PROTECTED
  60. // |-----------|---------|
  61. addEntry(LLFolderType::FT_TEXTURE, new FolderEntry("texture", TRUE));
  62. addEntry(LLFolderType::FT_SOUND, new FolderEntry("sound", TRUE));
  63. addEntry(LLFolderType::FT_CALLINGCARD, new FolderEntry("callcard", TRUE));
  64. addEntry(LLFolderType::FT_LANDMARK, new FolderEntry("landmark", TRUE));
  65. addEntry(LLFolderType::FT_CLOTHING, new FolderEntry("clothing", TRUE));
  66. addEntry(LLFolderType::FT_OBJECT, new FolderEntry("object", TRUE));
  67. addEntry(LLFolderType::FT_NOTECARD, new FolderEntry("notecard", TRUE));
  68. addEntry(LLFolderType::FT_ROOT_INVENTORY, new FolderEntry("root_inv", TRUE));
  69. addEntry(LLFolderType::FT_LSL_TEXT, new FolderEntry("lsltext", TRUE));
  70. addEntry(LLFolderType::FT_BODYPART, new FolderEntry("bodypart", TRUE));
  71. addEntry(LLFolderType::FT_TRASH, new FolderEntry("trash", TRUE));
  72. addEntry(LLFolderType::FT_SNAPSHOT_CATEGORY, new FolderEntry("snapshot", TRUE));
  73. addEntry(LLFolderType::FT_LOST_AND_FOUND, new FolderEntry("lstndfnd", TRUE));
  74. addEntry(LLFolderType::FT_ANIMATION, new FolderEntry("animatn", TRUE));
  75. addEntry(LLFolderType::FT_GESTURE, new FolderEntry("gesture", TRUE));
  76. addEntry(LLFolderType::FT_FAVORITE, new FolderEntry("favorite", TRUE));
  77. for (S32 ensemble_num = S32(LLFolderType::FT_ENSEMBLE_START); ensemble_num <= S32(LLFolderType::FT_ENSEMBLE_END); ensemble_num++)
  78. {
  79. addEntry(LLFolderType::EType(ensemble_num), new FolderEntry("ensemble", FALSE));
  80. }
  81. addEntry(LLFolderType::FT_CURRENT_OUTFIT, new FolderEntry("current", TRUE));
  82. addEntry(LLFolderType::FT_OUTFIT, new FolderEntry("outfit", FALSE));
  83. addEntry(LLFolderType::FT_MY_OUTFITS, new FolderEntry("my_otfts", TRUE));
  84. addEntry(LLFolderType::FT_MESH, new FolderEntry("mesh", TRUE));
  85. addEntry(LLFolderType::FT_INBOX, new FolderEntry("inbox", TRUE));
  86. addEntry(LLFolderType::FT_OUTBOX, new FolderEntry("outbox", TRUE));
  87. addEntry(LLFolderType::FT_BASIC_ROOT, new FolderEntry("basic_rt", TRUE));
  88. addEntry(LLFolderType::FT_NONE, new FolderEntry("-1", FALSE));
  89. };
  90. // static
  91. LLFolderType::EType LLFolderType::lookup(const std::string& name)
  92. {
  93. return LLFolderDictionary::getInstance()->lookup(name);
  94. }
  95. // static
  96. const std::string &LLFolderType::lookup(LLFolderType::EType folder_type)
  97. {
  98. const FolderEntry *entry = LLFolderDictionary::getInstance()->lookup(folder_type);
  99. if (entry)
  100. {
  101. return entry->mName;
  102. }
  103. else
  104. {
  105. return badLookup();
  106. }
  107. }
  108. // static
  109. // Only ensembles and plain folders aren't protected. "Protected" means
  110. // you can't change certain properties such as their type.
  111. bool LLFolderType::lookupIsProtectedType(EType folder_type)
  112. {
  113. const LLFolderDictionary *dict = LLFolderDictionary::getInstance();
  114. const FolderEntry *entry = dict->lookup(folder_type);
  115. if (entry)
  116. {
  117. return entry->mIsProtected;
  118. }
  119. return true;
  120. }
  121. // static
  122. bool LLFolderType::lookupIsEnsembleType(EType folder_type)
  123. {
  124. return (folder_type >= FT_ENSEMBLE_START &&
  125. folder_type <= FT_ENSEMBLE_END);
  126. }
  127. // static
  128. LLAssetType::EType LLFolderType::folderTypeToAssetType(LLFolderType::EType folder_type)
  129. {
  130. if (LLAssetType::lookup(LLAssetType::EType(folder_type)) == LLAssetType::badLookup())
  131. {
  132. llwarns << "Converting to unknown asset type " << folder_type << llendl;
  133. }
  134. return (LLAssetType::EType)folder_type;
  135. }
  136. // static
  137. LLFolderType::EType LLFolderType::assetTypeToFolderType(LLAssetType::EType asset_type)
  138. {
  139. if (LLFolderType::lookup(LLFolderType::EType(asset_type)) == LLFolderType::badLookup())
  140. {
  141. llwarns << "Converting to unknown folder type " << asset_type << llendl;
  142. }
  143. return (LLFolderType::EType)asset_type;
  144. }
  145. // static
  146. const std::string &LLFolderType::badLookup()
  147. {
  148. static const std::string sBadLookup = "llfoldertype_bad_lookup";
  149. return sBadLookup;
  150. }