PageRenderTime 29ms CodeModel.GetById 17ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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