PageRenderTime 102ms CodeModel.GetById 54ms app.highlight 10ms RepoModel.GetById 31ms 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
  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
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llnamebox.h"
 30
 31#include "llerror.h"
 32#include "llfontgl.h"
 33#include "llui.h"
 34#include "llviewercontrol.h"
 35#include "lluuid.h"
 36
 37#include "llcachename.h"
 38
 39// statics
 40std::set<LLNameBox*> LLNameBox::sInstances;
 41
 42static LLDefaultChildRegistry::Register<LLNameBox> r("name_box");
 43
 44
 45LLNameBox::LLNameBox(const Params& p)
 46:	LLTextBox(p)
 47{
 48	mNameID = LLUUID::null;
 49	mLink = p.link;
 50	mParseHTML = mLink; // STORM-215
 51	mInitialValue = p.initial_value().asString();
 52	LLNameBox::sInstances.insert(this);
 53	setText(LLStringUtil::null);
 54}
 55
 56LLNameBox::~LLNameBox()
 57{
 58	LLNameBox::sInstances.erase(this);
 59}
 60
 61void LLNameBox::setNameID(const LLUUID& name_id, BOOL is_group)
 62{
 63	mNameID = name_id;
 64
 65	std::string name;
 66	BOOL got_name = FALSE;
 67
 68	if (!is_group)
 69	{
 70		got_name = gCacheName->getFullName(name_id, name);
 71	}
 72	else
 73	{
 74		got_name = gCacheName->getGroupName(name_id, name);
 75	}
 76
 77	// Got the name already? Set it.
 78	// Otherwise it will be set later in refresh().
 79	if (got_name)
 80		setName(name, is_group);
 81	else
 82		setText(mInitialValue);
 83}
 84
 85void LLNameBox::refresh(const LLUUID& id, const std::string& full_name, bool is_group)
 86{
 87	if (id == mNameID)
 88	{
 89		setName(full_name, is_group);
 90	}
 91}
 92
 93void LLNameBox::refreshAll(const LLUUID& id, const std::string& full_name, bool is_group)
 94{
 95	std::set<LLNameBox*>::iterator it;
 96	for (it = LLNameBox::sInstances.begin();
 97		 it != LLNameBox::sInstances.end();
 98		 ++it)
 99	{
100		LLNameBox* box = *it;
101		box->refresh(id, full_name, is_group);
102	}
103}
104
105void LLNameBox::setName(const std::string& name, BOOL is_group)
106{
107	if (mLink)
108	{
109		std::string url;
110
111		if (is_group)
112			url = "[secondlife:///app/group/" + mNameID.asString() + "/about " + name + "]";
113		else
114			url = "[secondlife:///app/agent/" + mNameID.asString() + "/about " + name + "]";
115
116		setText(url);
117	}
118	else
119	{
120		setText(name);
121	}
122}