PageRenderTime 63ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/llavatarname.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 115 lines | 74 code | 9 blank | 32 comment | 4 complexity | cc2d4b5a9ba90564461fc96f36bd8238 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llavatarname.cpp
  3. * @brief Represents name-related data for an avatar, such as the
  4. * username/SLID ("bobsmith123" or "james.linden") and the display
  5. * name ("James Cook")
  6. *
  7. * $LicenseInfo:firstyear=2010&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. #include "linden_common.h"
  29. #include "llavatarname.h"
  30. #include "lldate.h"
  31. #include "llsd.h"
  32. // Store these in pre-built std::strings to avoid memory allocations in
  33. // LLSD map lookups
  34. static const std::string USERNAME("username");
  35. static const std::string DISPLAY_NAME("display_name");
  36. static const std::string LEGACY_FIRST_NAME("legacy_first_name");
  37. static const std::string LEGACY_LAST_NAME("legacy_last_name");
  38. static const std::string IS_DISPLAY_NAME_DEFAULT("is_display_name_default");
  39. static const std::string DISPLAY_NAME_EXPIRES("display_name_expires");
  40. static const std::string DISPLAY_NAME_NEXT_UPDATE("display_name_next_update");
  41. LLAvatarName::LLAvatarName()
  42. : mUsername(),
  43. mDisplayName(),
  44. mLegacyFirstName(),
  45. mLegacyLastName(),
  46. mIsDisplayNameDefault(false),
  47. mIsTemporaryName(false),
  48. mExpires(F64_MAX),
  49. mNextUpdate(0.0)
  50. { }
  51. bool LLAvatarName::operator<(const LLAvatarName& rhs) const
  52. {
  53. if (mUsername == rhs.mUsername)
  54. return mDisplayName < rhs.mDisplayName;
  55. else
  56. return mUsername < rhs.mUsername;
  57. }
  58. LLSD LLAvatarName::asLLSD() const
  59. {
  60. LLSD sd;
  61. sd[USERNAME] = mUsername;
  62. sd[DISPLAY_NAME] = mDisplayName;
  63. sd[LEGACY_FIRST_NAME] = mLegacyFirstName;
  64. sd[LEGACY_LAST_NAME] = mLegacyLastName;
  65. sd[IS_DISPLAY_NAME_DEFAULT] = mIsDisplayNameDefault;
  66. sd[DISPLAY_NAME_EXPIRES] = LLDate(mExpires);
  67. sd[DISPLAY_NAME_NEXT_UPDATE] = LLDate(mNextUpdate);
  68. return sd;
  69. }
  70. void LLAvatarName::fromLLSD(const LLSD& sd)
  71. {
  72. mUsername = sd[USERNAME].asString();
  73. mDisplayName = sd[DISPLAY_NAME].asString();
  74. mLegacyFirstName = sd[LEGACY_FIRST_NAME].asString();
  75. mLegacyLastName = sd[LEGACY_LAST_NAME].asString();
  76. mIsDisplayNameDefault = sd[IS_DISPLAY_NAME_DEFAULT].asBoolean();
  77. LLDate expires = sd[DISPLAY_NAME_EXPIRES];
  78. mExpires = expires.secondsSinceEpoch();
  79. LLDate next_update = sd[DISPLAY_NAME_NEXT_UPDATE];
  80. mNextUpdate = next_update.secondsSinceEpoch();
  81. }
  82. std::string LLAvatarName::getCompleteName() const
  83. {
  84. std::string name;
  85. if (mUsername.empty() || mIsDisplayNameDefault)
  86. // If the display name feature is off
  87. // OR this particular display name is defaulted (i.e. based on user name),
  88. // then display only the easier to read instance of the person's name.
  89. {
  90. name = mDisplayName;
  91. }
  92. else
  93. {
  94. name = mDisplayName + " (" + mUsername + ")";
  95. }
  96. return name;
  97. }
  98. std::string LLAvatarName::getLegacyName() const
  99. {
  100. std::string name;
  101. name.reserve( mLegacyFirstName.size() + 1 + mLegacyLastName.size() );
  102. name = mLegacyFirstName;
  103. name += " ";
  104. name += mLegacyLastName;
  105. return name;
  106. }