llviewerfoldertype.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /**
  2. * @file llviewerfoldertype.cpp
  3. * @brief Implementation of LLViewerFolderType 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 "llviewerprecompiledheaders.h"
  33. #include "llviewerfoldertype.h"
  34. #include "lldictionary.h"
  35. static const std::string empty_string;
  36. struct ViewerFolderEntry : public LLDictionaryEntry
  37. {
  38. // Constructor for non-ensembles
  39. ViewerFolderEntry(const std::string& category_name,
  40. const std::string& icon_name,
  41. const LLUIImagePtr icon, bool is_quiet,
  42. bool hide_if_empty = false,
  43. // No reverse lookup needed, so in most cases just
  44. // leave this blank:
  45. const std::string& dictionary_name = empty_string)
  46. : LLDictionaryEntry(dictionary_name),
  47. mNewCategoryName(category_name),
  48. mIconName(icon_name),
  49. mIcon(icon),
  50. mIsQuiet(is_quiet),
  51. mHideIfEmpty(hide_if_empty)
  52. {
  53. }
  54. const std::string mIconName; // Name of the folder icon
  55. const LLUIImagePtr mIcon; // Pointer to the icon itself
  56. // Default name when creating a new folder of this type
  57. const std::string mNewCategoryName;
  58. // When true, folder does not need an UI update when changed
  59. bool mIsQuiet;
  60. bool mHideIfEmpty; // Folder not shown if empty when true
  61. };
  62. class LLViewerFolderDictionary final : public LLSingleton<LLViewerFolderDictionary>,
  63. public LLDictionary<LLFolderType::EType,
  64. ViewerFolderEntry>
  65. {
  66. friend class LLSingleton<LLViewerFolderDictionary>;
  67. public:
  68. LLViewerFolderDictionary();
  69. };
  70. LLViewerFolderDictionary::LLViewerFolderDictionary()
  71. {
  72. static const LLUIImagePtr plain_icon = LLUI::getUIImage("inv_folder_plain_closed.tga");
  73. static const LLUIImagePtr texture_icon = LLUI::getUIImage("inv_folder_texture.tga");
  74. static const LLUIImagePtr sound_icon = LLUI::getUIImage("inv_folder_sound.tga");
  75. static const LLUIImagePtr callingcard_icon = LLUI::getUIImage("inv_folder_callingcard.tga");
  76. static const LLUIImagePtr landmark_icon = LLUI::getUIImage("inv_folder_landmark.tga");
  77. static const LLUIImagePtr clothing_icon = LLUI::getUIImage("inv_folder_clothing.tga");
  78. static const LLUIImagePtr object_icon = LLUI::getUIImage("inv_folder_object.tga");
  79. static const LLUIImagePtr notecard_icon = LLUI::getUIImage("inv_folder_notecard.tga");
  80. static const LLUIImagePtr script_icon = LLUI::getUIImage("inv_folder_script.tga");
  81. static const LLUIImagePtr bodypart_icon = LLUI::getUIImage("inv_folder_bodypart.tga");
  82. static const LLUIImagePtr trash_icon = LLUI::getUIImage("inv_folder_trash.tga");
  83. static const LLUIImagePtr snapshot_icon = LLUI::getUIImage("inv_folder_snapshot.tga");
  84. static const LLUIImagePtr lostandfound_icon = LLUI::getUIImage("inv_folder_lostandfound.tga");
  85. static const LLUIImagePtr animation_icon = LLUI::getUIImage("inv_folder_animation.tga");
  86. static const LLUIImagePtr gesture_icon = LLUI::getUIImage("inv_folder_gesture.tga");
  87. static const LLUIImagePtr settings_icon = LLUI::getUIImage("inv_folder_settings.tga");
  88. static const LLUIImagePtr materials_icon = LLUI::getUIImage("inv_folder_materials.tga");
  89. static const LLUIImagePtr inbox_icon = LLUI::getUIImage("inv_folder_inbox.tga");
  90. static const LLUIImagePtr outbox_icon = LLUI::getUIImage("inv_folder_outbox.tga");
  91. static const LLUIImagePtr stock_icon = LLUI::getUIImage("inv_folder_stock.tga");
  92. static const LLUIImagePtr version_icon = LLUI::getUIImage("inv_folder_version.tga");
  93. // NEW CATEGORY NAME FOLDER ICON NAME FOLDER ICON POINTER QUIET HIDE IF EMPTY
  94. // |-------------------------|-------------------------------|-------------------|-------|-------------|
  95. addEntry(LLFolderType::FT_TEXTURE, new ViewerFolderEntry("Textures", "inv_folder_texture.tga", texture_icon, false, true));
  96. addEntry(LLFolderType::FT_SOUND, new ViewerFolderEntry("Sounds", "inv_folder_sound.tga", sound_icon, false, true));
  97. addEntry(LLFolderType::FT_CALLINGCARD, new ViewerFolderEntry("Calling Cards", "inv_folder_callingcard.tga", callingcard_icon, true, true));
  98. addEntry(LLFolderType::FT_LANDMARK, new ViewerFolderEntry("Landmarks", "inv_folder_landmark.tga", landmark_icon, false, true));
  99. addEntry(LLFolderType::FT_CLOTHING, new ViewerFolderEntry("Clothing", "inv_folder_clothing.tga", clothing_icon, false, true));
  100. addEntry(LLFolderType::FT_OBJECT, new ViewerFolderEntry("Objects", "inv_folder_object.tga", object_icon, false, true));
  101. addEntry(LLFolderType::FT_NOTECARD, new ViewerFolderEntry("Notecards", "inv_folder_notecard.tga", notecard_icon, false, true));
  102. addEntry(LLFolderType::FT_ROOT_INVENTORY, new ViewerFolderEntry("My Inventory", "inv_folder_plain_closed.tga", plain_icon, false, false));
  103. addEntry(LLFolderType::FT_ROOT_INVENTORY_OS, new ViewerFolderEntry("My Inventory", "inv_folder_plain_closed.tga", plain_icon, false, false));
  104. addEntry(LLFolderType::FT_LSL_TEXT, new ViewerFolderEntry("Scripts", "inv_folder_script.tga", script_icon, false, true));
  105. addEntry(LLFolderType::FT_BODYPART, new ViewerFolderEntry("Body Parts", "inv_folder_bodypart.tga", bodypart_icon, false, true));
  106. addEntry(LLFolderType::FT_TRASH, new ViewerFolderEntry("Trash", "inv_folder_trash.tga", trash_icon, true, false));
  107. addEntry(LLFolderType::FT_SNAPSHOT_CATEGORY, new ViewerFolderEntry("Photo Album", "inv_folder_snapshot.tga", snapshot_icon, false, true));
  108. addEntry(LLFolderType::FT_LOST_AND_FOUND, new ViewerFolderEntry("Lost And Found", "inv_folder_lostandfound.tga", lostandfound_icon, true, true));
  109. addEntry(LLFolderType::FT_ANIMATION, new ViewerFolderEntry("Animations", "inv_folder_animation.tga", animation_icon, false, true));
  110. addEntry(LLFolderType::FT_GESTURE, new ViewerFolderEntry("Gestures", "inv_folder_gesture.tga", gesture_icon, false, true));
  111. addEntry(LLFolderType::FT_MESH, new ViewerFolderEntry("Meshes", "inv_folder_plain_closed.tga", plain_icon, false, true));
  112. addEntry(LLFolderType::FT_CURRENT_OUTFIT, new ViewerFolderEntry("Current Outfit", "inv_folder_plain_closed.tga", plain_icon, true, true));
  113. addEntry(LLFolderType::FT_INBOX, new ViewerFolderEntry("Received Items", "inv_folder_inbox.tga", inbox_icon, false, true));
  114. addEntry(LLFolderType::FT_SETTINGS, new ViewerFolderEntry("Settings", "inv_folder_settings.tga", settings_icon, false, true));
  115. addEntry(LLFolderType::FT_MATERIAL, new ViewerFolderEntry("Materials", "inv_folder_materials.tga", materials_icon, false, true));
  116. addEntry(LLFolderType::FT_SUITCASE, new ViewerFolderEntry("My Suitcase", "inv_folder_plain_closed.tga", plain_icon, false, true));
  117. addEntry(LLFolderType::FT_MARKETPLACE_LISTINGS, new ViewerFolderEntry("Marketplace Listings", "inv_folder_outbox.tga", outbox_icon, false, true));
  118. addEntry(LLFolderType::FT_MARKETPLACE_STOCK, new ViewerFolderEntry("New Stock", "inv_folder_stock.tga", stock_icon, false, false));
  119. addEntry(LLFolderType::FT_MARKETPLACE_VERSION, new ViewerFolderEntry("New Version", "inv_folder_version.tga", version_icon, false, false));
  120. addEntry(LLFolderType::FT_NONE, new ViewerFolderEntry("New Folder", "inv_folder_plain_closed.tga", plain_icon, false, false, "default"));
  121. #if 0 // Viewer 2 folders: useless for v1 !
  122. addEntry(LLFolderType::FT_BASIC_ROOT, new ViewerFolderEntry("Basic Root", "inv_folder_plain_closed.tga", plain_icon, true, false));
  123. addEntry(LLFolderType::FT_FAVORITE, new ViewerFolderEntry("Favorites", "inv_folder_plain_closed.tga", plain_icon, true, false));
  124. addEntry(LLFolderType::FT_OUTFIT, new ViewerFolderEntry("New Outfit", "inv_folder_plain_closed.tga", plain_icon, true, false));
  125. addEntry(LLFolderType::FT_MY_OUTFITS, new ViewerFolderEntry("My Outfits", "inv_folder_plain_closed.tga", plain_icon, true, false));
  126. #endif
  127. }
  128. //static
  129. const std::string& LLViewerFolderType::lookupXUIName(LLFolderType::EType type)
  130. {
  131. const ViewerFolderEntry* entry =
  132. LLViewerFolderDictionary::getInstance()->lookup(type);
  133. if (entry)
  134. {
  135. return entry->mName;
  136. }
  137. return badLookup();
  138. }
  139. //static
  140. LLFolderType::EType LLViewerFolderType::lookupTypeFromXUIName(const std::string& name)
  141. {
  142. return LLViewerFolderDictionary::getInstance()->lookup(name);
  143. }
  144. //static
  145. const std::string& LLViewerFolderType::lookupIconName(LLFolderType::EType type)
  146. {
  147. const ViewerFolderEntry* entry =
  148. LLViewerFolderDictionary::getInstance()->lookup(type);
  149. if (entry)
  150. {
  151. return entry->mIconName;
  152. }
  153. // Error condition. Return something so that we do not show a grey box in
  154. // inventory floater.
  155. const ViewerFolderEntry* default_entry =
  156. LLViewerFolderDictionary::getInstance()->lookup(LLFolderType::FT_NONE);
  157. if (!default_entry)
  158. {
  159. llerrs << "Missing FT_NONE entry in LLViewerFolderDictionary !"
  160. << llendl;
  161. }
  162. return default_entry->mIconName;
  163. }
  164. //static
  165. const LLUIImagePtr LLViewerFolderType::lookupIcon(LLFolderType::EType type)
  166. {
  167. const ViewerFolderEntry* entry =
  168. LLViewerFolderDictionary::getInstance()->lookup(type);
  169. if (entry)
  170. {
  171. return entry->mIcon;
  172. }
  173. const ViewerFolderEntry* default_entry =
  174. LLViewerFolderDictionary::getInstance()->lookup(LLFolderType::FT_NONE);
  175. if (!default_entry)
  176. {
  177. llerrs << "Missing FT_NONE entry in LLViewerFolderDictionary !"
  178. << llendl;
  179. }
  180. return default_entry->mIcon;
  181. }
  182. //static
  183. bool LLViewerFolderType::lookupIsQuietType(LLFolderType::EType type)
  184. {
  185. const ViewerFolderEntry* entry =
  186. LLViewerFolderDictionary::getInstance()->lookup(type);
  187. if (entry)
  188. {
  189. return entry->mIsQuiet;
  190. }
  191. return false;
  192. }
  193. //static
  194. bool LLViewerFolderType::lookupIsHiddenIfEmpty(LLFolderType::EType type)
  195. {
  196. const ViewerFolderEntry* entry =
  197. LLViewerFolderDictionary::getInstance()->lookup(type);
  198. if (entry)
  199. {
  200. return entry->mHideIfEmpty;
  201. }
  202. return false;
  203. }
  204. //static
  205. const std::string& LLViewerFolderType::lookupNewCategoryName(LLFolderType::EType type)
  206. {
  207. const ViewerFolderEntry* entry =
  208. LLViewerFolderDictionary::getInstance()->lookup(type);
  209. if (entry)
  210. {
  211. return entry->mNewCategoryName;
  212. }
  213. return badLookup();
  214. }
  215. #if 0 // Not used
  216. //static
  217. LLFolderType::EType LLViewerFolderType::lookupTypeFromNewCatName(const std::string& name)
  218. {
  219. LLViewerFolderDictionary* dictp = LLViewerFolderDictionary::getInstance();
  220. for (LLViewerFolderDictionary::const_iterator iter = dictp->begin(),
  221. end = dictp->end();
  222. iter != end; ++iter)
  223. {
  224. const ViewerFolderEntry* entry = iter->second;
  225. if (entry->mNewCategoryName == name)
  226. {
  227. return iter->first;
  228. }
  229. }
  230. return FT_NONE;
  231. }
  232. #endif