llsettingstype.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * @file llsettingstype.cpp
  3. * @brief LLSettingsType class implementation
  4. *
  5. * $LicenseInfo:firstyear=2018&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2019, 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 "llsettingstype.h"
  34. #include "lldictionary.h"
  35. #include "llinventory.h"
  36. static LLTranslationBridge::ptr_t sTrans;
  37. void LLSettingsType::initClass(LLTranslationBridge::ptr_t& trans)
  38. {
  39. sTrans = trans;
  40. }
  41. void LLSettingsType::cleanupClass()
  42. {
  43. sTrans.reset();
  44. }
  45. struct SettingsEntry : public LLDictionaryEntry
  46. {
  47. SettingsEntry(const std::string& name, const std::string& default_new_name,
  48. LLInventoryType::EIconName icon_name)
  49. : LLDictionaryEntry(name),
  50. mDefaultNewName(default_new_name),
  51. mIconName(icon_name)
  52. {
  53. if (sTrans)
  54. {
  55. mLabel = sTrans->getString(name);
  56. }
  57. else
  58. {
  59. llwarns << "No translation bridge: SettingsEntry '" << name
  60. << "' will be left untranslated." << llendl;
  61. }
  62. if (mLabel.empty())
  63. {
  64. mLabel = name;
  65. }
  66. }
  67. LLInventoryType::EIconName mIconName;
  68. std::string mLabel;
  69. std::string mDefaultNewName;
  70. };
  71. class LLSettingsDictionary : public LLDictionary<LLSettingsType::EType, SettingsEntry>
  72. {
  73. public:
  74. LLSettingsDictionary();
  75. };
  76. // Since it is a small structure, let's initialize it unconditionally (i.e.
  77. // even if we do not log in) at global scope. This saves having to bother with
  78. // a costly LLSingleton (slow, lot's of CPU cycles and cache lines wasted) or
  79. // to find the right place where to construct the class on login... HB
  80. LLSettingsDictionary gSettingsDictionary;
  81. LLSettingsDictionary::LLSettingsDictionary()
  82. {
  83. addEntry(LLSettingsType::ST_SKY, new SettingsEntry("sky", "New Sky", LLInventoryType::ICONNAME_SETTINGS_SKY));
  84. addEntry(LLSettingsType::ST_WATER, new SettingsEntry("water", "New Water", LLInventoryType::ICONNAME_SETTINGS_WATER));
  85. addEntry(LLSettingsType::ST_DAYCYCLE, new SettingsEntry("day", "New Daycycle", LLInventoryType::ICONNAME_SETTINGS_DAY));
  86. addEntry(LLSettingsType::ST_NONE, new SettingsEntry("none", "New Settings", LLInventoryType::ICONNAME_SETTINGS));
  87. addEntry(LLSettingsType::ST_INVALID, new SettingsEntry("invalid", "New Settings", LLInventoryType::ICONNAME_SETTINGS));
  88. }
  89. LLSettingsType::EType LLSettingsType::fromInventoryFlags(U32 flags)
  90. {
  91. return (LLSettingsType::EType)(flags & LLInventoryItem::II_FLAGS_SUBTYPE_MASK);
  92. }
  93. LLInventoryType::EIconName LLSettingsType::getIconName(LLSettingsType::EType type)
  94. {
  95. const SettingsEntry* entry = gSettingsDictionary.lookup(type);
  96. return entry ? entry->mIconName : getIconName(ST_INVALID);
  97. }
  98. std::string LLSettingsType::getDefaultName(LLSettingsType::EType type)
  99. {
  100. const SettingsEntry* entry = gSettingsDictionary.lookup(type);
  101. return entry ? entry->mDefaultNewName : getDefaultName(ST_INVALID);
  102. }