llfoldertype.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /**
  2. * @file llfoldertype.cpp
  3. * @brief Implementatino of LLFolderType functionality.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 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 "linden_common.h"
  33. #include "llfoldertype.h"
  34. #include "lldictionary.h"
  35. #include "llsingleton.h"
  36. //static
  37. bool LLFolderType::sCanDeleteCOF = false;
  38. struct FolderEntry : public LLDictionaryEntry
  39. {
  40. FolderEntry(const std::string& type_name, // 8 character limit !
  41. // Can the viewer change categories of this type ?
  42. bool is_protected)
  43. : LLDictionaryEntry(type_name),
  44. mIsProtected(is_protected)
  45. {
  46. llassert_always(type_name.length() <= 8);
  47. }
  48. const bool mIsProtected;
  49. };
  50. class LLFolderDictionary : public LLSingleton<LLFolderDictionary>,
  51. public LLDictionary<LLFolderType::EType, FolderEntry>
  52. {
  53. friend class LLSingleton<LLFolderDictionary>;
  54. public:
  55. LLFolderDictionary();
  56. protected:
  57. virtual LLFolderType::EType notFound() const
  58. {
  59. return LLFolderType::FT_NONE;
  60. }
  61. };
  62. LLFolderDictionary::LLFolderDictionary()
  63. {
  64. // TYPE NAME PROTECTED
  65. // |-----------|---------|
  66. addEntry(LLFolderType::FT_TEXTURE, new FolderEntry("texture", true));
  67. addEntry(LLFolderType::FT_SOUND, new FolderEntry("sound", true));
  68. addEntry(LLFolderType::FT_CALLINGCARD, new FolderEntry("callcard", true));
  69. addEntry(LLFolderType::FT_LANDMARK, new FolderEntry("landmark", true));
  70. addEntry(LLFolderType::FT_CLOTHING, new FolderEntry("clothing", true));
  71. addEntry(LLFolderType::FT_OBJECT, new FolderEntry("object", true));
  72. addEntry(LLFolderType::FT_NOTECARD, new FolderEntry("notecard", true));
  73. addEntry(LLFolderType::FT_ROOT_INVENTORY, new FolderEntry("root_inv", true));
  74. addEntry(LLFolderType::FT_ROOT_INVENTORY_OS, new FolderEntry("root_os", true));
  75. addEntry(LLFolderType::FT_LSL_TEXT, new FolderEntry("lsltext", true));
  76. addEntry(LLFolderType::FT_BODYPART, new FolderEntry("bodypart", true));
  77. addEntry(LLFolderType::FT_TRASH, new FolderEntry("trash", true));
  78. addEntry(LLFolderType::FT_SNAPSHOT_CATEGORY, new FolderEntry("snapshot", true));
  79. addEntry(LLFolderType::FT_LOST_AND_FOUND, new FolderEntry("lstndfnd", true));
  80. addEntry(LLFolderType::FT_ANIMATION, new FolderEntry("animatn", true));
  81. addEntry(LLFolderType::FT_GESTURE, new FolderEntry("gesture", true));
  82. addEntry(LLFolderType::FT_MESH, new FolderEntry("mesh", false));
  83. #if 0 // Viewer 2 folder: useless for v1 !
  84. addEntry(LLFolderType::FT_FAVORITE, new FolderEntry("favorite", false));
  85. #endif
  86. addEntry(LLFolderType::FT_CURRENT_OUTFIT, new FolderEntry("current", true));
  87. #if 0 // Viewer 2 folders: useless for v1 !
  88. addEntry(LLFolderType::FT_OUTFIT, new FolderEntry("outfit", false));
  89. addEntry(LLFolderType::FT_MY_OUTFITS, new FolderEntry("my_otfts", false));
  90. addEntry(LLFolderType::FT_BASIC_ROOT, new FolderEntry("basic_rt", true));
  91. #endif
  92. addEntry(LLFolderType::FT_MARKETPLACE_LISTINGS, new FolderEntry("merchant", true));
  93. addEntry(LLFolderType::FT_MARKETPLACE_STOCK, new FolderEntry("stock", false));
  94. addEntry(LLFolderType::FT_MARKETPLACE_VERSION, new FolderEntry("version", false));
  95. addEntry(LLFolderType::FT_INBOX, new FolderEntry("inbox", false));
  96. addEntry(LLFolderType::FT_SETTINGS, new FolderEntry("settings", false));
  97. addEntry(LLFolderType::FT_MATERIAL, new FolderEntry("material", false));
  98. // NOTE: OpenSim servers refuse to delete the Suitcase folder, meaning it would
  99. // reapear at next login if deleted in the viewer...
  100. addEntry(LLFolderType::FT_SUITCASE, new FolderEntry("suitcase", true));
  101. addEntry(LLFolderType::FT_NONE, new FolderEntry("-1", false));
  102. };
  103. //static
  104. LLFolderType::EType LLFolderType::lookup(const std::string& name)
  105. {
  106. return LLFolderDictionary::getInstance()->lookup(name);
  107. }
  108. //static
  109. const std::string& LLFolderType::lookup(LLFolderType::EType folder_type)
  110. {
  111. const FolderEntry* entry = LLFolderDictionary::getInstance()->lookup(folder_type);
  112. if (entry)
  113. {
  114. return entry->mName;
  115. }
  116. return badLookup();
  117. }
  118. //static
  119. // Only basic v1 folders are protected (i.e. we allow to destroy all the stupid
  120. // and useless v2 folders).
  121. bool LLFolderType::lookupIsProtectedType(EType folder_type)
  122. {
  123. if (folder_type == FT_CURRENT_OUTFIT && sCanDeleteCOF)
  124. {
  125. return false;
  126. }
  127. const LLFolderDictionary* dict = LLFolderDictionary::getInstance();
  128. const FolderEntry* entry = dict->lookup(folder_type);
  129. return entry && entry->mIsProtected;
  130. }
  131. //static
  132. LLAssetType::EType LLFolderType::folderTypeToAssetType(LLFolderType::EType folder_type)
  133. {
  134. if (LLAssetType::lookup(LLAssetType::EType(folder_type)) == LLAssetType::badLookup())
  135. {
  136. llwarns << "Converting to unknown asset type " << folder_type << llendl;
  137. }
  138. return (LLAssetType::EType)folder_type;
  139. }
  140. //static
  141. LLFolderType::EType LLFolderType::assetTypeToFolderType(LLAssetType::EType asset_type)
  142. {
  143. if (LLFolderType::lookup(LLFolderType::EType(asset_type)) == LLFolderType::badLookup())
  144. {
  145. llwarns << "Converting to unknown folder type " << asset_type << llendl;
  146. }
  147. return (LLFolderType::EType)asset_type;
  148. }
  149. //static
  150. const std::string &LLFolderType::badLookup()
  151. {
  152. static const std::string sBadLookup = "llfoldertype_bad_lookup";
  153. return sBadLookup;
  154. }