/indra/newview/llgroupiconctrl.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 140 lines · 86 code · 17 blank · 37 comment · 12 complexity · 63115396bcc114a0ef23cb0fd61a6417 MD5 · raw file

  1. /**
  2. * @file llgroupiconctrl.cpp
  3. * @brief LLGroupIconCtrl class implementation
  4. *
  5. * $LicenseInfo:firstyear=2009&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 "llgroupiconctrl.h"
  28. #include "llagent.h"
  29. /*
  30. #include "llavatarconstants.h"
  31. #include "llcallingcard.h" // for LLAvatarTracker
  32. #include "llavataractions.h"
  33. #include "llmenugl.h"
  34. #include "lluictrlfactory.h"
  35. #include "llcachename.h"
  36. #include "llagentdata.h"
  37. #include "llimfloater.h"
  38. */
  39. static LLDefaultChildRegistry::Register<LLGroupIconCtrl> g_i("group_icon");
  40. LLGroupIconCtrl::Params::Params()
  41. : group_id("group_id")
  42. , draw_tooltip("draw_tooltip", true)
  43. , default_icon_name("default_icon_name")
  44. {
  45. }
  46. LLGroupIconCtrl::LLGroupIconCtrl(const LLGroupIconCtrl::Params& p)
  47. : LLIconCtrl(p)
  48. , mGroupId(LLUUID::null)
  49. , mDrawTooltip(p.draw_tooltip)
  50. , mDefaultIconName(p.default_icon_name)
  51. {
  52. mPriority = LLViewerFetchedTexture::BOOST_ICON;
  53. if (p.group_id.isProvided())
  54. {
  55. LLSD value(p.group_id);
  56. setValue(value);
  57. }
  58. else
  59. {
  60. LLIconCtrl::setValue(mDefaultIconName);
  61. }
  62. }
  63. LLGroupIconCtrl::~LLGroupIconCtrl()
  64. {
  65. LLGroupMgr::getInstance()->removeObserver(this);
  66. }
  67. void LLGroupIconCtrl::setValue(const LLSD& value)
  68. {
  69. if (value.isUUID())
  70. {
  71. LLGroupMgr* gm = LLGroupMgr::getInstance();
  72. if (mGroupId.notNull())
  73. {
  74. gm->removeObserver(this);
  75. }
  76. if (mGroupId != value.asUUID())
  77. {
  78. mGroupId = value.asUUID();
  79. mID = mGroupId; // set LLGroupMgrObserver::mID to make callbacks work
  80. // Check if cache already contains image_id for that group
  81. if (!updateFromCache())
  82. {
  83. LLIconCtrl::setValue(mDefaultIconName);
  84. gm->addObserver(this);
  85. gm->sendGroupPropertiesRequest(mGroupId);
  86. }
  87. }
  88. }
  89. else
  90. {
  91. LLIconCtrl::setValue(value);
  92. }
  93. }
  94. void LLGroupIconCtrl::changed(LLGroupChange gc)
  95. {
  96. if (GC_PROPERTIES == gc)
  97. {
  98. updateFromCache();
  99. }
  100. }
  101. bool LLGroupIconCtrl::updateFromCache()
  102. {
  103. LLGroupMgrGroupData* group_data = LLGroupMgr::getInstance()->getGroupData(mGroupId);
  104. if (!group_data) return false;
  105. if (group_data->mInsigniaID.notNull())
  106. {
  107. LLIconCtrl::setValue(group_data->mInsigniaID);
  108. }
  109. else
  110. {
  111. LLIconCtrl::setValue(mDefaultIconName);
  112. }
  113. if (mDrawTooltip && !group_data->mName.empty())
  114. {
  115. setToolTip(group_data->mName);
  116. }
  117. else
  118. {
  119. setToolTip(LLStringUtil::null);
  120. }
  121. return true;
  122. }