PageRenderTime 33ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/lloutfitobserver.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 153 lines | 98 code | 25 blank | 30 comment | 21 complexity | d086fdb1c96c4b7a9cc1aa995543ec5e MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lloutfitobserver.cpp
  3. * @brief Outfit observer facade.
  4. *
  5. * $LicenseInfo:firstyear=2010&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 "llappearancemgr.h"
  28. #include "lloutfitobserver.h"
  29. #include "llinventorymodel.h"
  30. #include "llviewerinventory.h"
  31. LLOutfitObserver::LLOutfitObserver() :
  32. mCOFLastVersion(LLViewerInventoryCategory::VERSION_UNKNOWN)
  33. {
  34. mItemNameHash.finalize();
  35. gInventory.addObserver(this);
  36. }
  37. LLOutfitObserver::~LLOutfitObserver()
  38. {
  39. if (gInventory.containsObserver(this))
  40. {
  41. gInventory.removeObserver(this);
  42. }
  43. }
  44. void LLOutfitObserver::changed(U32 mask)
  45. {
  46. if (!gInventory.isInventoryUsable())
  47. return;
  48. checkCOF();
  49. checkBaseOutfit();
  50. }
  51. // static
  52. S32 LLOutfitObserver::getCategoryVersion(const LLUUID& cat_id)
  53. {
  54. LLViewerInventoryCategory* cat = gInventory.getCategory(cat_id);
  55. if (!cat)
  56. return LLViewerInventoryCategory::VERSION_UNKNOWN;
  57. return cat->getVersion();
  58. }
  59. // static
  60. const std::string& LLOutfitObserver::getCategoryName(const LLUUID& cat_id)
  61. {
  62. LLViewerInventoryCategory* cat = gInventory.getCategory(cat_id);
  63. if (!cat)
  64. return LLStringUtil::null;
  65. return cat->getName();
  66. }
  67. bool LLOutfitObserver::checkCOF()
  68. {
  69. LLUUID cof = LLAppearanceMgr::getInstance()->getCOF();
  70. if (cof.isNull())
  71. return false;
  72. bool cof_changed = false;
  73. LLMD5 item_name_hash = gInventory.hashDirectDescendentNames(cof);
  74. if (item_name_hash != mItemNameHash)
  75. {
  76. cof_changed = true;
  77. mItemNameHash = item_name_hash;
  78. }
  79. S32 cof_version = getCategoryVersion(cof);
  80. if (cof_version != mCOFLastVersion)
  81. {
  82. cof_changed = true;
  83. mCOFLastVersion = cof_version;
  84. }
  85. if (!cof_changed)
  86. return false;
  87. // dirtiness state should be updated before sending signal
  88. LLAppearanceMgr::getInstance()->updateIsDirty();
  89. mCOFChanged();
  90. return true;
  91. }
  92. void LLOutfitObserver::checkBaseOutfit()
  93. {
  94. LLUUID baseoutfit_id =
  95. LLAppearanceMgr::getInstance()->getBaseOutfitUUID();
  96. if (baseoutfit_id == mBaseOutfitId)
  97. {
  98. if (baseoutfit_id.isNull())
  99. return;
  100. const S32 baseoutfit_ver = getCategoryVersion(baseoutfit_id);
  101. const std::string& baseoutfit_name = getCategoryName(baseoutfit_id);
  102. if (baseoutfit_ver == mBaseOutfitLastVersion
  103. // renaming category doesn't change version, so it's need to check it
  104. && baseoutfit_name == mLastBaseOutfitName)
  105. return;
  106. }
  107. else
  108. {
  109. mBaseOutfitId = baseoutfit_id;
  110. mBOFReplaced();
  111. if (baseoutfit_id.isNull())
  112. return;
  113. }
  114. mBaseOutfitLastVersion = getCategoryVersion(mBaseOutfitId);
  115. mLastBaseOutfitName = getCategoryName(baseoutfit_id);
  116. LLAppearanceMgr& app_mgr = LLAppearanceMgr::instance();
  117. // dirtiness state should be updated before sending signal
  118. app_mgr.updateIsDirty();
  119. mBOFChanged();
  120. if (mLastOutfitDirtiness != app_mgr.isOutfitDirty())
  121. {
  122. if(!app_mgr.isOutfitDirty())
  123. {
  124. mCOFSaved();
  125. }
  126. mLastOutfitDirtiness = app_mgr.isOutfitDirty();
  127. }
  128. }