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

/indra/newview/llnamebox.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 122 lines | 76 code | 18 blank | 28 comment | 8 complexity | d560b538e660d26bf020a29579decf99 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llnamebox.cpp
  3. * @brief A text display widget
  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 "llviewerprecompiledheaders.h"
  27. #include "llnamebox.h"
  28. #include "llerror.h"
  29. #include "llfontgl.h"
  30. #include "llui.h"
  31. #include "llviewercontrol.h"
  32. #include "lluuid.h"
  33. #include "llcachename.h"
  34. // statics
  35. std::set<LLNameBox*> LLNameBox::sInstances;
  36. static LLDefaultChildRegistry::Register<LLNameBox> r("name_box");
  37. LLNameBox::LLNameBox(const Params& p)
  38. : LLTextBox(p)
  39. {
  40. mNameID = LLUUID::null;
  41. mLink = p.link;
  42. mParseHTML = mLink; // STORM-215
  43. mInitialValue = p.initial_value().asString();
  44. LLNameBox::sInstances.insert(this);
  45. setText(LLStringUtil::null);
  46. }
  47. LLNameBox::~LLNameBox()
  48. {
  49. LLNameBox::sInstances.erase(this);
  50. }
  51. void LLNameBox::setNameID(const LLUUID& name_id, BOOL is_group)
  52. {
  53. mNameID = name_id;
  54. std::string name;
  55. BOOL got_name = FALSE;
  56. if (!is_group)
  57. {
  58. got_name = gCacheName->getFullName(name_id, name);
  59. }
  60. else
  61. {
  62. got_name = gCacheName->getGroupName(name_id, name);
  63. }
  64. // Got the name already? Set it.
  65. // Otherwise it will be set later in refresh().
  66. if (got_name)
  67. setName(name, is_group);
  68. else
  69. setText(mInitialValue);
  70. }
  71. void LLNameBox::refresh(const LLUUID& id, const std::string& full_name, bool is_group)
  72. {
  73. if (id == mNameID)
  74. {
  75. setName(full_name, is_group);
  76. }
  77. }
  78. void LLNameBox::refreshAll(const LLUUID& id, const std::string& full_name, bool is_group)
  79. {
  80. std::set<LLNameBox*>::iterator it;
  81. for (it = LLNameBox::sInstances.begin();
  82. it != LLNameBox::sInstances.end();
  83. ++it)
  84. {
  85. LLNameBox* box = *it;
  86. box->refresh(id, full_name, is_group);
  87. }
  88. }
  89. void LLNameBox::setName(const std::string& name, BOOL is_group)
  90. {
  91. if (mLink)
  92. {
  93. std::string url;
  94. if (is_group)
  95. url = "[secondlife:///app/group/" + mNameID.asString() + "/about " + name + "]";
  96. else
  97. url = "[secondlife:///app/agent/" + mNameID.asString() + "/about " + name + "]";
  98. setText(url);
  99. }
  100. else
  101. {
  102. setText(name);
  103. }
  104. }