diff options
Diffstat (limited to 'linden/indra/llcommon/llavatarname.cpp')
-rw-r--r-- | linden/indra/llcommon/llavatarname.cpp | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/linden/indra/llcommon/llavatarname.cpp b/linden/indra/llcommon/llavatarname.cpp new file mode 100644 index 0000000..ebe8c88 --- /dev/null +++ b/linden/indra/llcommon/llavatarname.cpp | |||
@@ -0,0 +1,150 @@ | |||
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 | bool LLAvatarName::sOmitResidentAsLastName = false; | ||
36 | |||
37 | // Store these in pre-built std::strings to avoid memory allocations in | ||
38 | // LLSD map lookups | ||
39 | static const std::string USERNAME("username"); | ||
40 | static const std::string DISPLAY_NAME("display_name"); | ||
41 | static const std::string LEGACY_FIRST_NAME("legacy_first_name"); | ||
42 | static const std::string LEGACY_LAST_NAME("legacy_last_name"); | ||
43 | static const std::string IS_DISPLAY_NAME_DEFAULT("is_display_name_default"); | ||
44 | static const std::string DISPLAY_NAME_EXPIRES("display_name_expires"); | ||
45 | static const std::string DISPLAY_NAME_NEXT_UPDATE("display_name_next_update"); | ||
46 | |||
47 | LLAvatarName::LLAvatarName() | ||
48 | : mUsername(), | ||
49 | mDisplayName(), | ||
50 | mLegacyFirstName(), | ||
51 | mLegacyLastName(), | ||
52 | mIsDisplayNameDefault(false), | ||
53 | mIsDummy(false), | ||
54 | mExpires(F64_MAX), | ||
55 | mNextUpdate(0.0) | ||
56 | { } | ||
57 | |||
58 | bool LLAvatarName::operator<(const LLAvatarName& rhs) const | ||
59 | { | ||
60 | if (mUsername == rhs.mUsername) | ||
61 | return mDisplayName < rhs.mDisplayName; | ||
62 | else | ||
63 | return mUsername < rhs.mUsername; | ||
64 | } | ||
65 | |||
66 | LLSD LLAvatarName::asLLSD() const | ||
67 | { | ||
68 | LLSD sd; | ||
69 | sd[USERNAME] = mUsername; | ||
70 | sd[DISPLAY_NAME] = mDisplayName; | ||
71 | sd[LEGACY_FIRST_NAME] = mLegacyFirstName; | ||
72 | sd[LEGACY_LAST_NAME] = mLegacyLastName; | ||
73 | sd[IS_DISPLAY_NAME_DEFAULT] = mIsDisplayNameDefault; | ||
74 | sd[DISPLAY_NAME_EXPIRES] = LLDate(mExpires); | ||
75 | sd[DISPLAY_NAME_NEXT_UPDATE] = LLDate(mNextUpdate); | ||
76 | return sd; | ||
77 | } | ||
78 | |||
79 | void LLAvatarName::fromLLSD(const LLSD& sd) | ||
80 | { | ||
81 | mUsername = sd[USERNAME].asString(); | ||
82 | mDisplayName = sd[DISPLAY_NAME].asString(); | ||
83 | mLegacyFirstName = sd[LEGACY_FIRST_NAME].asString(); | ||
84 | mLegacyLastName = sd[LEGACY_LAST_NAME].asString(); | ||
85 | mIsDisplayNameDefault = sd[IS_DISPLAY_NAME_DEFAULT].asBoolean(); | ||
86 | LLDate expires = sd[DISPLAY_NAME_EXPIRES]; | ||
87 | mExpires = expires.secondsSinceEpoch(); | ||
88 | LLDate next_update = sd[DISPLAY_NAME_NEXT_UPDATE]; | ||
89 | mNextUpdate = next_update.secondsSinceEpoch(); | ||
90 | } | ||
91 | |||
92 | std::string LLAvatarName::getCompleteName() const | ||
93 | { | ||
94 | std::string name; | ||
95 | if (!mUsername.empty()) | ||
96 | { | ||
97 | name = mDisplayName + " (" + mUsername + ")"; | ||
98 | } | ||
99 | else | ||
100 | { | ||
101 | // ...display names are off, legacy name is in mDisplayName | ||
102 | name = mDisplayName; | ||
103 | } | ||
104 | return name; | ||
105 | } | ||
106 | |||
107 | std::string LLAvatarName::getLegacyName() const | ||
108 | { | ||
109 | std::string name; | ||
110 | name.reserve(mLegacyFirstName.size() + 1 + mLegacyLastName.size()); | ||
111 | name = mLegacyFirstName; | ||
112 | if (!sOmitResidentAsLastName || mLegacyLastName != "Resident") | ||
113 | { | ||
114 | name += " "; | ||
115 | name += mLegacyLastName; | ||
116 | } | ||
117 | return name; | ||
118 | } | ||
119 | |||
120 | std::string LLAvatarName::getNames(bool linefeed) const | ||
121 | { | ||
122 | std::string name; | ||
123 | |||
124 | if (mUsername.empty()) | ||
125 | { | ||
126 | // ...display names are off, legacy name is in mDisplayName | ||
127 | name = mDisplayName; | ||
128 | if (sOmitResidentAsLastName) | ||
129 | { | ||
130 | LLStringUtil::replaceString(name, " Resident", ""); | ||
131 | } | ||
132 | } | ||
133 | else | ||
134 | { | ||
135 | name = getLegacyName(); | ||
136 | if (name != mDisplayName) | ||
137 | { | ||
138 | if (linefeed) | ||
139 | { | ||
140 | name = mDisplayName + "\n[" + name + "]"; | ||
141 | } | ||
142 | else | ||
143 | { | ||
144 | name = mDisplayName + " [" + name + "]"; | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | |||
149 | return name; | ||
150 | } | ||