PageRenderTime 27ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llfloaterdisplayname.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 223 lines | 146 code | 36 blank | 41 comment | 9 complexity | 562126f279291b0db6ddd9365a7ed6a0 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfloaterdisplayname.cpp
  3. * @author Leyla Farazha
  4. * @brief Implementation of the LLFloaterDisplayName class.
  5. *
  6. * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #include "llviewerprecompiledheaders.h"
  28. #include "llfloaterreg.h"
  29. #include "llfloater.h"
  30. #include "llnotificationsutil.h"
  31. #include "llviewerdisplayname.h"
  32. #include "llnotifications.h"
  33. #include "llfloaterdisplayname.h"
  34. #include "llavatarnamecache.h"
  35. #include "llagent.h"
  36. class LLFloaterDisplayName : public LLFloater
  37. {
  38. public:
  39. LLFloaterDisplayName(const LLSD& key);
  40. virtual ~LLFloaterDisplayName() {};
  41. /*virtual*/ BOOL postBuild();
  42. void onSave();
  43. void onReset();
  44. void onCancel();
  45. /*virtual*/ void onOpen(const LLSD& key);
  46. private:
  47. void onCacheSetName(bool success,
  48. const std::string& reason,
  49. const LLSD& content);
  50. };
  51. LLFloaterDisplayName::LLFloaterDisplayName(const LLSD& key)
  52. : LLFloater(key)
  53. {
  54. }
  55. void LLFloaterDisplayName::onOpen(const LLSD& key)
  56. {
  57. getChild<LLUICtrl>("display_name_editor")->clear();
  58. getChild<LLUICtrl>("display_name_confirm")->clear();
  59. LLAvatarName av_name;
  60. LLAvatarNameCache::get(gAgent.getID(), &av_name);
  61. F64 now_secs = LLDate::now().secondsSinceEpoch();
  62. if (now_secs < av_name.mNextUpdate)
  63. {
  64. // ...can't update until some time in the future
  65. F64 next_update_local_secs =
  66. av_name.mNextUpdate - LLStringOps::getLocalTimeOffset();
  67. LLDate next_update_local(next_update_local_secs);
  68. // display as "July 18 12:17 PM"
  69. std::string next_update_string =
  70. next_update_local.toHTTPDateString("%B %d %I:%M %p");
  71. getChild<LLUICtrl>("lockout_text")->setTextArg("[TIME]", next_update_string);
  72. getChild<LLUICtrl>("lockout_text")->setVisible(true);
  73. getChild<LLUICtrl>("save_btn")->setEnabled(false);
  74. getChild<LLUICtrl>("display_name_editor")->setEnabled(false);
  75. getChild<LLUICtrl>("display_name_confirm")->setEnabled(false);
  76. getChild<LLUICtrl>("cancel_btn")->setFocus(TRUE);
  77. }
  78. else
  79. {
  80. getChild<LLUICtrl>("lockout_text")->setVisible(false);
  81. getChild<LLUICtrl>("save_btn")->setEnabled(true);
  82. getChild<LLUICtrl>("display_name_editor")->setEnabled(true);
  83. getChild<LLUICtrl>("display_name_confirm")->setEnabled(true);
  84. }
  85. }
  86. BOOL LLFloaterDisplayName::postBuild()
  87. {
  88. getChild<LLUICtrl>("reset_btn")->setCommitCallback(boost::bind(&LLFloaterDisplayName::onReset, this));
  89. getChild<LLUICtrl>("cancel_btn")->setCommitCallback(boost::bind(&LLFloaterDisplayName::onCancel, this));
  90. getChild<LLUICtrl>("save_btn")->setCommitCallback(boost::bind(&LLFloaterDisplayName::onSave, this));
  91. center();
  92. return TRUE;
  93. }
  94. void LLFloaterDisplayName::onCacheSetName(bool success,
  95. const std::string& reason,
  96. const LLSD& content)
  97. {
  98. if (success)
  99. {
  100. // Inform the user that the change took place, but will take a while
  101. // to percolate.
  102. LLSD args;
  103. args["DISPLAY_NAME"] = content["display_name"];
  104. LLNotificationsUtil::add("SetDisplayNameSuccess", args);
  105. // Re-fetch my name, as it may have been sanitized by the service
  106. //LLAvatarNameCache::get(getAvatarId(),
  107. // boost::bind(&LLPanelMyProfileEdit::onNameCache, this, _1, _2));
  108. return;
  109. }
  110. // Request failed, notify the user
  111. std::string error_tag = content["error_tag"].asString();
  112. llinfos << "set name failure error_tag " << error_tag << llendl;
  113. // We might have a localized string for this message
  114. // error_args will usually be empty from the server.
  115. if (!error_tag.empty()
  116. && LLNotifications::getInstance()->templateExists(error_tag))
  117. {
  118. LLNotificationsUtil::add(error_tag);
  119. return;
  120. }
  121. // The server error might have a localized message for us
  122. std::string lang_code = LLUI::getLanguage();
  123. LLSD error_desc = content["error_description"];
  124. if (error_desc.has( lang_code ))
  125. {
  126. LLSD args;
  127. args["MESSAGE"] = error_desc[lang_code].asString();
  128. LLNotificationsUtil::add("GenericAlert", args);
  129. return;
  130. }
  131. // No specific error, throw a generic one
  132. LLNotificationsUtil::add("SetDisplayNameFailedGeneric");
  133. }
  134. void LLFloaterDisplayName::onCancel()
  135. {
  136. setVisible(false);
  137. }
  138. void LLFloaterDisplayName::onReset()
  139. {
  140. if (LLAvatarNameCache::useDisplayNames())
  141. {
  142. LLViewerDisplayName::set("",
  143. boost::bind(&LLFloaterDisplayName::onCacheSetName, this, _1, _2, _3));
  144. }
  145. else
  146. {
  147. LLNotificationsUtil::add("SetDisplayNameFailedGeneric");
  148. }
  149. setVisible(false);
  150. }
  151. void LLFloaterDisplayName::onSave()
  152. {
  153. std::string display_name_utf8 = getChild<LLUICtrl>("display_name_editor")->getValue().asString();
  154. std::string display_name_confirm = getChild<LLUICtrl>("display_name_confirm")->getValue().asString();
  155. if (display_name_utf8.compare(display_name_confirm))
  156. {
  157. LLNotificationsUtil::add("SetDisplayNameMismatch");
  158. return;
  159. }
  160. const U32 DISPLAY_NAME_MAX_LENGTH = 31; // characters, not bytes
  161. LLWString display_name_wstr = utf8string_to_wstring(display_name_utf8);
  162. if (display_name_wstr.size() > DISPLAY_NAME_MAX_LENGTH)
  163. {
  164. LLSD args;
  165. args["LENGTH"] = llformat("%d", DISPLAY_NAME_MAX_LENGTH);
  166. LLNotificationsUtil::add("SetDisplayNameFailedLength", args);
  167. return;
  168. }
  169. if (LLAvatarNameCache::useDisplayNames())
  170. {
  171. LLViewerDisplayName::set(display_name_utf8,
  172. boost::bind(&LLFloaterDisplayName::onCacheSetName, this, _1, _2, _3));
  173. }
  174. else
  175. {
  176. LLNotificationsUtil::add("SetDisplayNameFailedGeneric");
  177. }
  178. setVisible(false);
  179. }
  180. //////////////////////////////////////////////////////////////////////////////
  181. // LLInspectObjectUtil
  182. //////////////////////////////////////////////////////////////////////////////
  183. void LLFloaterDisplayNameUtil::registerFloater()
  184. {
  185. LLFloaterReg::add("display_name", "floater_display_name.xml",
  186. &LLFloaterReg::build<LLFloaterDisplayName>);
  187. }