PageRenderTime 32ms CodeModel.GetById 19ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/llavatarname.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 115 lines | 74 code | 9 blank | 32 comment | 4 complexity | cc2d4b5a9ba90564461fc96f36bd8238 MD5 | raw file
  1/** 
  2 * @file llavatarname.cpp
  3 * @brief Represents name-related data for an avatar, such as the
  4 * username/SLID ("bobsmith123" or "james.linden") and the display
  5 * name ("James Cook")
  6 *
  7 * $LicenseInfo:firstyear=2010&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28#include "linden_common.h"
 29
 30#include "llavatarname.h"
 31
 32#include "lldate.h"
 33#include "llsd.h"
 34
 35// Store these in pre-built std::strings to avoid memory allocations in
 36// LLSD map lookups
 37static const std::string USERNAME("username");
 38static const std::string DISPLAY_NAME("display_name");
 39static const std::string LEGACY_FIRST_NAME("legacy_first_name");
 40static const std::string LEGACY_LAST_NAME("legacy_last_name");
 41static const std::string IS_DISPLAY_NAME_DEFAULT("is_display_name_default");
 42static const std::string DISPLAY_NAME_EXPIRES("display_name_expires");
 43static const std::string DISPLAY_NAME_NEXT_UPDATE("display_name_next_update");
 44
 45LLAvatarName::LLAvatarName()
 46:	mUsername(),
 47	mDisplayName(),
 48	mLegacyFirstName(),
 49	mLegacyLastName(),
 50	mIsDisplayNameDefault(false),
 51	mIsTemporaryName(false),
 52	mExpires(F64_MAX),
 53	mNextUpdate(0.0)
 54{ }
 55
 56bool LLAvatarName::operator<(const LLAvatarName& rhs) const
 57{
 58	if (mUsername == rhs.mUsername)
 59		return mDisplayName < rhs.mDisplayName;
 60	else
 61		return mUsername < rhs.mUsername;
 62}
 63
 64LLSD LLAvatarName::asLLSD() const
 65{
 66	LLSD sd;
 67	sd[USERNAME] = mUsername;
 68	sd[DISPLAY_NAME] = mDisplayName;
 69	sd[LEGACY_FIRST_NAME] = mLegacyFirstName;
 70	sd[LEGACY_LAST_NAME] = mLegacyLastName;
 71	sd[IS_DISPLAY_NAME_DEFAULT] = mIsDisplayNameDefault;
 72	sd[DISPLAY_NAME_EXPIRES] = LLDate(mExpires);
 73	sd[DISPLAY_NAME_NEXT_UPDATE] = LLDate(mNextUpdate);
 74	return sd;
 75}
 76
 77void LLAvatarName::fromLLSD(const LLSD& sd)
 78{
 79	mUsername = sd[USERNAME].asString();
 80	mDisplayName = sd[DISPLAY_NAME].asString();
 81	mLegacyFirstName = sd[LEGACY_FIRST_NAME].asString();
 82	mLegacyLastName = sd[LEGACY_LAST_NAME].asString();
 83	mIsDisplayNameDefault = sd[IS_DISPLAY_NAME_DEFAULT].asBoolean();
 84	LLDate expires = sd[DISPLAY_NAME_EXPIRES];
 85	mExpires = expires.secondsSinceEpoch();
 86	LLDate next_update = sd[DISPLAY_NAME_NEXT_UPDATE];
 87	mNextUpdate = next_update.secondsSinceEpoch();
 88}
 89
 90std::string LLAvatarName::getCompleteName() const
 91{
 92	std::string name;
 93	if (mUsername.empty() || mIsDisplayNameDefault)
 94	// If the display name feature is off
 95	// OR this particular display name is defaulted (i.e. based on user name),
 96	// then display only the easier to read instance of the person's name.
 97	{
 98		name = mDisplayName;
 99	}
100	else
101	{
102		name = mDisplayName + " (" + mUsername + ")";
103	}
104	return name;
105}
106
107std::string LLAvatarName::getLegacyName() const
108{
109	std::string name;
110	name.reserve( mLegacyFirstName.size() + 1 + mLegacyLastName.size() );
111	name = mLegacyFirstName;
112	name += " ";
113	name += mLegacyLastName;
114	return name;
115}