From 7ffc9b06c820d70724af2aef361ff9964e584e73 Mon Sep 17 00:00:00 2001 From: Leyla Farazha Date: Fri, 8 Oct 2010 16:56:02 -0700 Subject: Created a floater for setting display name --- indra/newview/CMakeLists.txt | 2 + indra/newview/llcallfloater.cpp | 3 + indra/newview/llfloaterdisplayname.cpp | 178 +++++++++++++++++++++ indra/newview/llfloaterdisplayname.h | 38 +++++ indra/newview/llhints.cpp | 5 + indra/newview/llpanelme.cpp | 106 ++---------- indra/newview/llpanelme.h | 5 +- indra/newview/llviewerdisplayname.cpp | 13 ++ indra/newview/llviewerdisplayname.h | 7 +- indra/newview/llviewerfloaterreg.cpp | 2 + .../skins/default/xui/en/floater_display_name.xml | 83 ++++++++++ .../newview/skins/default/xui/en/notifications.xml | 41 +---- 12 files changed, 358 insertions(+), 125 deletions(-) create mode 100644 indra/newview/llfloaterdisplayname.cpp create mode 100644 indra/newview/llfloaterdisplayname.h create mode 100644 indra/newview/skins/default/xui/en/floater_display_name.xml (limited to 'indra/newview') diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index 74b9179cb4..bd2489769a 100644 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -169,6 +169,7 @@ set(viewer_SOURCE_FILES llfloatercamera.cpp llfloatercolorpicker.cpp llfloaterdaycycle.cpp + llfloaterdisplayname.cpp llfloaterenvsettings.cpp llfloaterevent.cpp llfloaterfonttest.cpp @@ -701,6 +702,7 @@ set(viewer_HEADER_FILES llfloatercamera.h llfloatercolorpicker.h llfloaterdaycycle.h + llfloaterdisplayname.h llfloaterenvsettings.h llfloaterevent.h llfloaterfonttest.h diff --git a/indra/newview/llcallfloater.cpp b/indra/newview/llcallfloater.cpp index d3ef144ea8..078bd73379 100644 --- a/indra/newview/llcallfloater.cpp +++ b/indra/newview/llcallfloater.cpp @@ -45,6 +45,7 @@ #include "llspeakers.h" #include "lltextutil.h" #include "lltransientfloatermgr.h" +#include "llviewerdisplayname.h" #include "llviewerwindow.h" #include "llvoicechannel.h" #include "llviewerparcelmgr.h" @@ -117,6 +118,8 @@ LLCallFloater::LLCallFloater(const LLSD& key) // update the agent's name if display name setting change LLAvatarNameCache::addUseDisplayNamesCallback(boost::bind(&LLCallFloater::updateAgentModeratorState, this)); + LLViewerDisplayName::addNameChangedCallback(boost::bind(&LLCallFloater::updateAgentModeratorState, this)); + } LLCallFloater::~LLCallFloater() diff --git a/indra/newview/llfloaterdisplayname.cpp b/indra/newview/llfloaterdisplayname.cpp new file mode 100644 index 0000000000..11ac3d8fdf --- /dev/null +++ b/indra/newview/llfloaterdisplayname.cpp @@ -0,0 +1,178 @@ +/** + * @file llfloaterdisplayname.cpp + * @author Leyla Farazha + * @brief Implementation of the LLFloaterDisplayName class. + * + * $LicenseInfo:firstyear=2002&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + + +#include "llviewerprecompiledheaders.h" +#include "llfloaterreg.h" +#include "llfloater.h" + +#include "llnotificationsutil.h" +#include "llviewerdisplayname.h" + +#include "llnotifications.h" +#include "llfloaterdisplayname.h" +#include "llavatarnamecache.h" + +#include "llagent.h" + + +class LLFloaterDisplayName : public LLFloater +{ +public: + LLFloaterDisplayName(const LLSD& key); + virtual ~LLFloaterDisplayName() {}; + /*virtual*/ BOOL postBuild(); + void onSave(); + void onReset(); + void onCancel(); + /*virtual*/ void onOpen(const LLSD& key); + +private: + + void onCacheSetName(bool success, + const std::string& reason, + const LLSD& content); +}; + +LLFloaterDisplayName::LLFloaterDisplayName(const LLSD& key) + : LLFloater(key) +{ +} + +void LLFloaterDisplayName::onOpen(const LLSD& key) +{ + getChild("display_name_editor")->clear(); + getChild("display_name_confirm")->clear(); +} + +BOOL LLFloaterDisplayName::postBuild() +{ + getChild("reset_btn")->setCommitCallback(boost::bind(&LLFloaterDisplayName::onReset, this)); + getChild("cancel_btn")->setCommitCallback(boost::bind(&LLFloaterDisplayName::onCancel, this)); + getChild("save_btn")->setCommitCallback(boost::bind(&LLFloaterDisplayName::onSave, this)); + + center(); + + return TRUE; +} + +void LLFloaterDisplayName::onCacheSetName(bool success, + const std::string& reason, + const LLSD& content) +{ + if (success) + { + // Inform the user that the change took place, but will take a while + // to percolate. + LLSD args; + args["DISPLAY_NAME"] = content["display_name"]; + LLNotificationsUtil::add("SetDisplayNameSuccess", args); + + // Re-fetch my name, as it may have been sanitized by the service + //LLAvatarNameCache::get(getAvatarId(), + // boost::bind(&LLPanelMyProfileEdit::onNameCache, this, _1, _2)); + return; + } + + // Request failed, notify the user + std::string error_tag = content["error_tag"].asString(); + llinfos << "set name failure error_tag " << error_tag << llendl; + + // We might have a localized string for this message + // error_args will usually be empty from the server. + if (!error_tag.empty() + && LLNotifications::getInstance()->templateExists(error_tag)) + { + LLNotificationsUtil::add(error_tag); + return; + } + + // The server error might have a localized message for us + std::string lang_code = LLUI::getLanguage(); + LLSD error_desc = content["error_description"]; + if (error_desc.has( lang_code )) + { + LLSD args; + args["MESSAGE"] = error_desc[lang_code].asString(); + LLNotificationsUtil::add("GenericAlert", args); + return; + } + + // No specific error, throw a generic one + LLNotificationsUtil::add("SetDisplayNameFailedGeneric"); +} + +void LLFloaterDisplayName::onCancel() +{ + setVisible(false); +} + +void LLFloaterDisplayName::onReset() +{ + LLViewerDisplayName::set("", + boost::bind(&LLFloaterDisplayName::onCacheSetName, this, _1, _2, _3)); + + setVisible(false); +} + + +void LLFloaterDisplayName::onSave() +{ + std::string display_name_utf8 = getChild("display_name_editor")->getValue().asString(); + std::string display_name_confirm = getChild("display_name_confirm")->getValue().asString(); + + if (display_name_utf8.compare(display_name_confirm)) + { + LLNotificationsUtil::add("SetDisplayNameMismatch"); + return; + } + + const U32 DISPLAY_NAME_MAX_LENGTH = 31; // characters, not bytes + LLWString display_name_wstr = utf8string_to_wstring(display_name_utf8); + if (display_name_wstr.size() > DISPLAY_NAME_MAX_LENGTH) + { + LLSD args; + args["LENGTH"] = llformat("%d", DISPLAY_NAME_MAX_LENGTH); + LLNotificationsUtil::add("SetDisplayNameFailedLength", args); + return; + } + + LLViewerDisplayName::set(display_name_utf8, + boost::bind(&LLFloaterDisplayName::onCacheSetName, this, _1, _2, _3)); + + setVisible(false); +} + + +////////////////////////////////////////////////////////////////////////////// +// LLInspectObjectUtil +////////////////////////////////////////////////////////////////////////////// +void LLFloaterDisplayNameUtil::registerFloater() +{ + LLFloaterReg::add("display_name", "floater_display_name.xml", + &LLFloaterReg::build); +} diff --git a/indra/newview/llfloaterdisplayname.h b/indra/newview/llfloaterdisplayname.h new file mode 100644 index 0000000000..a00bf56712 --- /dev/null +++ b/indra/newview/llfloaterdisplayname.h @@ -0,0 +1,38 @@ +/** + * @file llfloaterdisplayname.h + * + * $LicenseInfo:firstyear=2009&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LLFLOATERDISPLAYNAME_H +#define LLFLOATERDISPLAYNAME_H + + +namespace LLFloaterDisplayNameUtil +{ + // Register with LLFloaterReg + void registerFloater(); +} + + + +#endif diff --git a/indra/newview/llhints.cpp b/indra/newview/llhints.cpp index d837ed8205..b326fc26f2 100644 --- a/indra/newview/llhints.cpp +++ b/indra/newview/llhints.cpp @@ -210,10 +210,15 @@ void LLHintPopup::draw() } else if (!targetp->isInVisibleChain()) { + setEnabled(false); + setMouseOpaque(false); // if target is invisible, don't draw, but keep alive in case widget comes back } else { + setEnabled(true); + setMouseOpaque(true); + LLRect target_rect; targetp->localRectToOtherView(targetp->getLocalRect(), &target_rect, getParent()); diff --git a/indra/newview/llpanelme.cpp b/indra/newview/llpanelme.cpp index 3cc6b32678..9a13d00685 100644 --- a/indra/newview/llpanelme.cpp +++ b/indra/newview/llpanelme.cpp @@ -35,6 +35,7 @@ #include "llagentcamera.h" #include "llagentwearables.h" #include "llfirstuse.h" +#include "llfloaterreg.h" #include "llhints.h" #include "llsidetray.h" #include "llviewercontrol.h" @@ -208,6 +209,14 @@ void LLPanelMyProfileEdit::onOpen(const LLSD& key) } } +void LLPanelMyProfileEdit::onClose(const LLSD& key) +{ + if (LLAvatarNameCache::useDisplayNames()) + { + LLFirstUse::setDisplayName(false); + } +} + void LLPanelMyProfileEdit::processProperties(void* data, EAvatarProcessorType type) { if(APT_PROPERTIES == type) @@ -262,6 +271,12 @@ void LLPanelMyProfileEdit::onNameCache(const LLUUID& agent_id, const LLAvatarNam } } +void LLPanelMyProfileEdit::onAvatarNameChanged() +{ + LLAvatarNameCache::get(getAvatarId(), + boost::bind(&LLPanelMyProfileEdit::onNameCache, this, _1, _2)); +} + BOOL LLPanelMyProfileEdit::postBuild() { initTexturePickerMouseEvents(); @@ -273,7 +288,7 @@ BOOL LLPanelMyProfileEdit::postBuild() boost::bind(&LLPanelMyProfileEdit::onClickSetName, this)); LLHints::registerHintTarget("set_display_name", getChild("set_name")->getHandle()); - + LLViewerDisplayName::addNameChangedCallback(boost::bind(&LLPanelMyProfileEdit::onAvatarNameChanged, this)); return LLPanelAvatarProfile::postBuild(); } /** @@ -316,88 +331,6 @@ void LLPanelMyProfileEdit::onTexturePickerMouseLeave(LLUICtrl* ctrl) mTextureEditIconMap[ctrl->getName()]->setVisible(FALSE); } -void LLPanelMyProfileEdit::onCacheSetName(bool success, - const std::string& reason, - const LLSD& content) -{ - if (success) - { - // Inform the user that the change took place, but will take a while - // to percolate. - LLSD args; - args["DISPLAY_NAME"] = content["display_name"]; - LLNotificationsUtil::add("SetDisplayNameSuccess", args); - - // Re-fetch my name, as it may have been sanitized by the service - LLAvatarNameCache::get(getAvatarId(), - boost::bind(&LLPanelMyProfileEdit::onNameCache, this, _1, _2)); - return; - } - - // Request failed, notify the user - std::string error_tag = content["error_tag"].asString(); - llinfos << "set name failure error_tag " << error_tag << llendl; - - // We might have a localized string for this message - // error_args will usually be empty from the server. - if (!error_tag.empty() - && LLNotifications::getInstance()->templateExists(error_tag)) - { - LLNotificationsUtil::add(error_tag); - return; - } - - // The server error might have a localized message for us - std::string lang_code = LLUI::getLanguage(); - LLSD error_desc = content["error_description"]; - if (error_desc.has( lang_code )) - { - LLSD args; - args["MESSAGE"] = error_desc[lang_code].asString(); - LLNotificationsUtil::add("GenericAlert", args); - return; - } - - // No specific error, throw a generic one - LLNotificationsUtil::add("SetDisplayNameFailedGeneric"); -} - -void LLPanelMyProfileEdit::onDialogSetName(const LLSD& notification, const LLSD& response) -{ - S32 option = LLNotificationsUtil::getSelectedOption(notification, response); - if (option == 0 || option == 1) - { - LLUUID agent_id = notification["payload"]["agent_id"]; - if (agent_id.isNull()) return; - - std::string display_name_utf8; - if (option == 0) - { - // user gave us a name - display_name_utf8 = response["display_name"].asString(); - } - else - { - // reset back to People API default - display_name_utf8 = ""; - } - - const U32 DISPLAY_NAME_MAX_LENGTH = 31; // characters, not bytes - LLWString display_name_wstr = utf8string_to_wstring(display_name_utf8); - if (display_name_wstr.size() > DISPLAY_NAME_MAX_LENGTH) - { - LLSD args; - args["LENGTH"] = llformat("%d", DISPLAY_NAME_MAX_LENGTH); - LLNotificationsUtil::add("SetDisplayNameFailedLength", args); - return; - } - - LLViewerDisplayName::set(display_name_utf8, - boost::bind(&LLPanelMyProfileEdit::onCacheSetName, this, - _1, _2, _3)); - } -} - void LLPanelMyProfileEdit::onClickSetName() { LLAvatarNameCache::get(getAvatarId(), @@ -444,12 +377,7 @@ void LLPanelMyProfileEdit::onAvatarNameCache(const LLUUID& agent_id, const LLAva return; } - LLSD args; - args["DISPLAY_NAME"] = av_name.mDisplayName; - LLSD payload; - payload["agent_id"] = agent_id; - LLNotificationsUtil::add("SetDisplayName", args, payload, - boost::bind(&LLPanelMyProfileEdit::onDialogSetName, this, _1, _2)); + LLFloaterReg::showInstance("display_name"); } void LLPanelMyProfileEdit::enableEditing(bool enable) diff --git a/indra/newview/llpanelme.h b/indra/newview/llpanelme.h index 93264922f6..d5b2fee869 100644 --- a/indra/newview/llpanelme.h +++ b/indra/newview/llpanelme.h @@ -78,6 +78,9 @@ public: /*virtual*/BOOL postBuild(); /*virtual*/ void onOpen(const LLSD& key); + /*virtual*/ void onClose(const LLSD& key); + + void onAvatarNameChanged(); protected: @@ -91,8 +94,6 @@ private: void onTexturePickerMouseEnter(LLUICtrl* ctrl); void onTexturePickerMouseLeave(LLUICtrl* ctrl); void onClickSetName(); - void onDialogSetName(const LLSD& notification, const LLSD& response); - void onCacheSetName(bool success, const std::string& reason, const LLSD& content); void onAvatarNameCache(const LLUUID& id, const LLAvatarName& av_name); /** diff --git a/indra/newview/llviewerdisplayname.cpp b/indra/newview/llviewerdisplayname.cpp index f71a7c2d20..5741fab29a 100644 --- a/indra/newview/llviewerdisplayname.cpp +++ b/indra/newview/llviewerdisplayname.cpp @@ -44,6 +44,15 @@ namespace LLViewerDisplayName { // Fired when viewer receives server response to display name change set_name_signal_t sSetDisplayNameSignal; + + // Fired when there is a change in the agent's name + name_changed_signal_t sNameChangedSignal; + + void addNameChangedCallback(const name_changed_signal_t::slot_type& cb) + { + sNameChangedSignal.connect(cb); + } + } class LLSetDisplayNameResponder : public LLHTTPClient::Responder @@ -183,6 +192,10 @@ class LLDisplayNameUpdate : public LLHTTPNode args["SLID"] = av_name.mUsername; args["NEW_NAME"] = av_name.mDisplayName; LLNotificationsUtil::add("DisplayNameUpdate", args); + if (agent_id == gAgent.getID()) + { + LLViewerDisplayName::sNameChangedSignal(); + } } }; diff --git a/indra/newview/llviewerdisplayname.h b/indra/newview/llviewerdisplayname.h index 922263eb12..16d59ae43b 100644 --- a/indra/newview/llviewerdisplayname.h +++ b/indra/newview/llviewerdisplayname.h @@ -38,11 +38,16 @@ namespace LLViewerDisplayName void (bool success, const std::string& reason, const LLSD& content)> set_name_signal_t; typedef set_name_signal_t::slot_type set_name_slot_t; + + typedef boost::signals2::signal name_changed_signal_t; + typedef name_changed_signal_t::slot_type name_changed_slot_t; // Sends an update to the server to change a display name // and call back when done. May not succeed due to service // unavailable or name not available. - void set(const std::string& display_name, const set_name_slot_t& slot); + void set(const std::string& display_name, const set_name_slot_t& slot); + + void addNameChangedCallback(const name_changed_signal_t::slot_type& cb); } #endif // LLVIEWERDISPLAYNAME_H diff --git a/indra/newview/llviewerfloaterreg.cpp b/indra/newview/llviewerfloaterreg.cpp index 7490ccf77a..b3f14b441d 100644 --- a/indra/newview/llviewerfloaterreg.cpp +++ b/indra/newview/llviewerfloaterreg.cpp @@ -49,6 +49,7 @@ #include "llfloaterbump.h" #include "llfloatercamera.h" #include "llfloaterdaycycle.h" +#include "llfloaterdisplayname.h" #include "llfloaterevent.h" #include "llfloatersearch.h" #include "llfloaterenvsettings.h" @@ -176,6 +177,7 @@ void LLViewerFloaterReg::registerFloaters() LLInspectObjectUtil::registerFloater(); LLInspectRemoteObjectUtil::registerFloater(); LLNotificationsUI::registerFloater(); + LLFloaterDisplayNameUtil::registerFloater(); LLFloaterReg::add("lagmeter", "floater_lagmeter.xml", (LLFloaterBuildFunc)&LLFloaterReg::build); LLFloaterReg::add("land_holdings", "floater_land_holdings.xml", (LLFloaterBuildFunc)&LLFloaterReg::build); diff --git a/indra/newview/skins/default/xui/en/floater_display_name.xml b/indra/newview/skins/default/xui/en/floater_display_name.xml new file mode 100644 index 0000000000..ecf2e524aa --- /dev/null +++ b/indra/newview/skins/default/xui/en/floater_display_name.xml @@ -0,0 +1,83 @@ + + + + The name you give your avatar is called your Display Name. You can change it once a week. + + + New display name: + + + + Type your new name again to confirm: + + +