/** * @file llpanelme.cpp * @brief Side tray "Me" (My Profile) panel * * $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$ */ #include "llviewerprecompiledheaders.h" #include "llpanelme.h" // Viewer includes #include "llpanelprofile.h" #include "llavatarconstants.h" #include "llagent.h" #include "llagentcamera.h" #include "llagentwearables.h" #include "llfirstuse.h" #include "llfloaterreg.h" #include "llhints.h" #include "llviewercontrol.h" #include "llviewerdisplayname.h" // Linden libraries #include "llavatarnamecache.h" // IDEVO #include "lliconctrl.h" #include "llnotifications.h" #include "llnotificationsutil.h" // IDEVO #include "lltabcontainer.h" #include "lltexturectrl.h" #define PICKER_SECOND_LIFE "2nd_life_pic" #define PICKER_FIRST_LIFE "real_world_pic" #define PANEL_PROFILE "panel_profile" static LLRegisterPanelClassWrapper t_panel_me_profile_edit("edit_profile_panel"); static LLRegisterPanelClassWrapper t_panel_me_profile("panel_me"); LLPanelMe::LLPanelMe(void) : LLPanelProfile() , mEditPanel(NULL) { setAvatarId(gAgent.getID()); } BOOL LLPanelMe::postBuild() { LLPanelProfile::postBuild(); return TRUE; } void LLPanelMe::onOpen(const LLSD& key) { LLPanelProfile::onOpen(key); } void LLPanelMe::buildEditPanel() { if (NULL == mEditPanel) { mEditPanel = new LLPanelMyProfileEdit(); // Note: Remove support for editing profile through this method. // All profile editing should go through the web. //mEditPanel->childSetAction("save_btn", boost::bind(&LLPanelMe::onSaveChangesClicked, this), this); mEditPanel->childSetAction("cancel_btn", boost::bind(&LLPanelMe::onCancelClicked, this), this); } } void LLPanelMe::onEditProfileClicked() { buildEditPanel(); togglePanel(mEditPanel, getAvatarId()); // open } void LLPanelMe::onCancelClicked() { togglePanel(mEditPanel); // close } ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// LLPanelMyProfileEdit::LLPanelMyProfileEdit() : LLPanelMyProfile() { buildFromFile( "panel_edit_profile.xml"); setAvatarId(gAgent.getID()); LLAvatarNameCache::addUseDisplayNamesCallback(boost::bind(&LLPanelMyProfileEdit::onAvatarNameChanged, this)); } void LLPanelMyProfileEdit::onOpen(const LLSD& key) { resetData(); // Disable editing until data is loaded, or edited fields will be overwritten when data // is loaded. enableEditing(false); // force new avatar name fetch so we have latest update time LLAvatarNameCache::fetch(gAgent.getID()); LLPanelMyProfile::onOpen(getAvatarId()); LLAvatarName av_name; if (LLAvatarNameCache::useDisplayNames()) { if (LLAvatarNameCache::get(gAgent.getID(), &av_name) && av_name.mIsDisplayNameDefault) { LLFirstUse::setDisplayName(); } else { LLFirstUse::setDisplayName(false); } } if (LLAvatarNameCache::useDisplayNames()) { getChild("user_label")->setVisible( true ); getChild("user_slid")->setVisible( true ); getChild("display_name_label")->setVisible( true ); getChild("set_name")->setVisible( true ); getChild("set_name")->setEnabled( true ); getChild("solo_user_name")->setVisible( false ); getChild("solo_username_label")->setVisible( false ); } else { getChild("user_label")->setVisible( false ); getChild("user_slid")->setVisible( false ); getChild("display_name_label")->setVisible( false ); getChild("set_name")->setVisible( false ); getChild("set_name")->setEnabled( false ); getChild("solo_user_name")->setVisible( true ); getChild("solo_username_label")->setVisible( true ); } } void LLPanelMyProfileEdit::onClose(const LLSD& key) { if (LLAvatarNameCache::useDisplayNames()) { LLFirstUse::setDisplayName(false); } } void LLPanelMyProfileEdit::processProperties(void* data, EAvatarProcessorType type) { if(APT_PROPERTIES == type) { const LLAvatarData* avatar_data = static_cast(data); if(avatar_data && getAvatarId() == avatar_data->avatar_id) { // *TODO dzaporozhan // Workaround for ticket EXT-1099, waiting for fix for ticket EXT-1128 enableEditing(true); processProfileProperties(avatar_data); LLAvatarPropertiesProcessor::getInstance()->removeObserver(getAvatarId(),this); } } } void LLPanelMyProfileEdit::processProfileProperties(const LLAvatarData* avatar_data) { fillCommonData(avatar_data); // 'Home page' was hidden in LLPanelAvatarProfile::fillCommonData() to fix EXT-4734 // Show 'Home page' in Edit My Profile (EXT-4873) getChildView("homepage_edit")->setVisible( true); fillPartnerData(avatar_data); fillAccountStatus(avatar_data); getChild("show_in_search_checkbox")->setValue((BOOL)(avatar_data->flags & AVATAR_ALLOW_PUBLISH)); LLAvatarNameCache::get(avatar_data->avatar_id, boost::bind(&LLPanelMyProfileEdit::onNameCache, this, _1, _2)); } void LLPanelMyProfileEdit::onNameCache(const LLUUID& agent_id, const LLAvatarName& av_name) { getChild("user_name")->setValue( av_name.mDisplayName ); getChild("user_slid")->setValue( av_name.mUsername ); getChild("user_name_small")->setValue( av_name.mDisplayName ); getChild("solo_user_name")->setValue( av_name.mDisplayName ); if (LLAvatarNameCache::useDisplayNames()) { getChild("user_label")->setVisible( true ); getChild("user_slid")->setVisible( true ); getChild("display_name_label")->setVisible( true ); getChild("set_name")->setVisible( true ); getChild("set_name")->setEnabled( true ); getChild("solo_user_name")->setVisible( false ); getChild("solo_username_label")->setVisible( false ); // show smaller display name if too long to display in regular size if (getChild("user_name")->getTextPixelWidth() > getChild("user_name")->getRect().getWidth()) { getChild("user_name_small")->setVisible( true ); getChild("user_name")->setVisible( false ); } else { getChild("user_name_small")->setVisible( false ); getChild("user_name")->setVisible( true ); } } else { getChild("user_label")->setVisible( false ); getChild("user_slid")->setVisible( false ); getChild("display_name_label")->setVisible( false ); getChild("set_name")->setVisible( false ); getChild("set_name")->setEnabled( false ); getChild("solo_user_name")->setVisible( true ); getChild("user_name_small")->setVisible( false ); getChild("user_name")->setVisible( false ); getChild("solo_username_label")->setVisible( true ); } } void LLPanelMyProfileEdit::onAvatarNameChanged() { LLAvatarNameCache::get(getAvatarId(), boost::bind(&LLPanelMyProfileEdit::onNameCache, this, _1, _2)); } BOOL LLPanelMyProfileEdit::postBuild() { initTexturePickerMouseEvents(); getChild("partner_edit_link")->setTextArg("[URL]", getString("partner_edit_link_url")); getChild("my_account_link")->setTextArg("[URL]", getString("my_account_link_url")); getChild("set_name")->setCommitCallback( boost::bind(&LLPanelMyProfileEdit::onClickSetName, this)); LLHints::registerHintTarget("set_display_name", getChild("set_name")->getHandle()); LLViewerDisplayName::addNameChangedCallback(boost::bind(&LLPanelMyProfileEdit::onAvatarNameChanged, this)); return LLPanelAvatarProfile::postBuild(); } /** * Inits map with texture picker and appropriate edit icon. * Sets callbacks of Mouse Enter and Mouse Leave signals of Texture Pickers */ void LLPanelMyProfileEdit::initTexturePickerMouseEvents() { LLTextureCtrl* text_pic = getChild(PICKER_SECOND_LIFE); LLIconCtrl* text_icon = getChild("2nd_life_edit_icon"); mTextureEditIconMap[text_pic->getName()] = text_icon; text_pic->setMouseEnterCallback(boost::bind(&LLPanelMyProfileEdit::onTexturePickerMouseEnter, this, _1)); text_pic->setMouseLeaveCallback(boost::bind(&LLPanelMyProfileEdit::onTexturePickerMouseLeave, this, _1)); text_icon->setVisible(FALSE); text_pic = getChild(PICKER_FIRST_LIFE); text_icon = getChild("real_world_edit_icon"); mTextureEditIconMap[text_pic->getName()] = text_icon; text_pic->setMouseEnterCallback(boost::bind(&LLPanelMyProfileEdit::onTexturePickerMouseEnter, this, _1)); text_pic->setMouseLeaveCallback(boost::bind(&LLPanelMyProfileEdit::onTexturePickerMouseLeave, this, _1)); text_icon->setVisible(FALSE); } void LLPanelMyProfileEdit::resetData() { LLPanelMyProfile::resetData(); //childSetTextArg("name_text", "[FIRST]", LLStringUtil::null); //childSetTextArg("name_text", "[LAST]", LLStringUtil::null); getChild("user_name")->setValue( LLSD() ); getChild("user_slid")->setValue( LLSD() ); getChild("solo_user_name")->setValue( LLSD() ); getChild("user_name_small")->setValue( LLSD() ); } void LLPanelMyProfileEdit::onTexturePickerMouseEnter(LLUICtrl* ctrl) { mTextureEditIconMap[ctrl->getName()]->setVisible(TRUE); } void LLPanelMyProfileEdit::onTexturePickerMouseLeave(LLUICtrl* ctrl) { mTextureEditIconMap[ctrl->getName()]->setVisible(FALSE); } void LLPanelMyProfileEdit::onClickSetName() { LLAvatarNameCache::get(getAvatarId(), boost::bind(&LLPanelMyProfileEdit::onAvatarNameCache, this, _1, _2)); LLFirstUse::setDisplayName(false); } void LLPanelMyProfileEdit::onAvatarNameCache(const LLUUID& agent_id, const LLAvatarName& av_name) { if (av_name.mDisplayName.empty()) { // something is wrong, tell user to try again later LLNotificationsUtil::add("SetDisplayNameFailedGeneric"); return; } llinfos << "name-change now " << LLDate::now() << " next_update " << LLDate(av_name.mNextUpdate) << llendl; F64 now_secs = LLDate::now().secondsSinceEpoch(); if (now_secs < av_name.mNextUpdate) { // if the update time is more than a year in the future, it means updates have been blocked // show a more general message const int YEAR = 60*60*24*365; if (now_secs + YEAR < av_name.mNextUpdate) { LLNotificationsUtil::add("SetDisplayNameBlocked"); return; } } LLFloaterReg::showInstance("display_name"); } void LLPanelMyProfileEdit::enableEditing(bool enable) { getChildView("2nd_life_pic")->setEnabled(enable); getChildView("real_world_pic")->setEnabled(enable); getChildView("sl_description_edit")->setEnabled(enable); getChildView("fl_description_edit")->setEnabled(enable); getChildView("homepage_edit")->setEnabled(enable); getChildView("show_in_search_checkbox")->setEnabled(enable); }