PageRenderTime 17ms CodeModel.GetById 2ms app.highlight 13ms RepoModel.GetById 1ms 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
  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
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llappearancemgr.h"
 30#include "lloutfitobserver.h"
 31#include "llinventorymodel.h"
 32#include "llviewerinventory.h"
 33
 34LLOutfitObserver::LLOutfitObserver() :
 35	mCOFLastVersion(LLViewerInventoryCategory::VERSION_UNKNOWN)
 36{
 37	mItemNameHash.finalize();
 38	gInventory.addObserver(this);
 39}
 40
 41LLOutfitObserver::~LLOutfitObserver()
 42{
 43	if (gInventory.containsObserver(this))
 44	{
 45		gInventory.removeObserver(this);
 46	}
 47}
 48
 49void LLOutfitObserver::changed(U32 mask)
 50{
 51	if (!gInventory.isInventoryUsable())
 52		return;
 53
 54	checkCOF();
 55
 56	checkBaseOutfit();
 57}
 58
 59// static
 60S32 LLOutfitObserver::getCategoryVersion(const LLUUID& cat_id)
 61{
 62	LLViewerInventoryCategory* cat = gInventory.getCategory(cat_id);
 63	if (!cat)
 64		return LLViewerInventoryCategory::VERSION_UNKNOWN;
 65
 66	return cat->getVersion();
 67}
 68
 69// static
 70const std::string& LLOutfitObserver::getCategoryName(const LLUUID& cat_id)
 71{
 72	LLViewerInventoryCategory* cat = gInventory.getCategory(cat_id);
 73	if (!cat)
 74		return LLStringUtil::null;
 75
 76	return cat->getName();
 77}
 78
 79bool LLOutfitObserver::checkCOF()
 80{
 81	LLUUID cof = LLAppearanceMgr::getInstance()->getCOF();
 82	if (cof.isNull())
 83		return false;
 84
 85	bool cof_changed = false;
 86	LLMD5 item_name_hash = gInventory.hashDirectDescendentNames(cof);
 87	if (item_name_hash != mItemNameHash)
 88	{
 89		cof_changed = true;
 90		mItemNameHash = item_name_hash;
 91	}
 92
 93	S32 cof_version = getCategoryVersion(cof);
 94	if (cof_version != mCOFLastVersion)
 95	{
 96		cof_changed = true;
 97		mCOFLastVersion = cof_version;
 98	}
 99
100	if (!cof_changed)
101		return false;
102	
103	// dirtiness state should be updated before sending signal
104	LLAppearanceMgr::getInstance()->updateIsDirty();
105	mCOFChanged();
106
107	return true;
108}
109
110void LLOutfitObserver::checkBaseOutfit()
111{
112	LLUUID baseoutfit_id =
113			LLAppearanceMgr::getInstance()->getBaseOutfitUUID();
114
115	if (baseoutfit_id == mBaseOutfitId)
116	{
117		if (baseoutfit_id.isNull())
118			return;
119
120		const S32 baseoutfit_ver = getCategoryVersion(baseoutfit_id);
121		const std::string& baseoutfit_name = getCategoryName(baseoutfit_id);
122
123		if (baseoutfit_ver == mBaseOutfitLastVersion
124				// renaming category doesn't change version, so it's need to check it
125				&& baseoutfit_name == mLastBaseOutfitName)
126			return;
127	}
128	else
129	{
130		mBaseOutfitId = baseoutfit_id;
131		mBOFReplaced();
132
133		if (baseoutfit_id.isNull())
134			return;
135	}
136
137	mBaseOutfitLastVersion = getCategoryVersion(mBaseOutfitId);
138	mLastBaseOutfitName = getCategoryName(baseoutfit_id);
139
140	LLAppearanceMgr& app_mgr = LLAppearanceMgr::instance();
141	// dirtiness state should be updated before sending signal
142	app_mgr.updateIsDirty();
143	mBOFChanged();
144
145	if (mLastOutfitDirtiness != app_mgr.isOutfitDirty())
146	{
147		if(!app_mgr.isOutfitDirty())
148		{
149			mCOFSaved();
150		}
151		mLastOutfitDirtiness = app_mgr.isOutfitDirty();
152	}
153}