diff options
Diffstat (limited to 'indra/newview/llpanelgroupinvite.cpp')
-rw-r--r-- | indra/newview/llpanelgroupinvite.cpp | 221 |
1 files changed, 139 insertions, 82 deletions
diff --git a/indra/newview/llpanelgroupinvite.cpp b/indra/newview/llpanelgroupinvite.cpp index f5b4fc83ca..ca48e8561b 100644 --- a/indra/newview/llpanelgroupinvite.cpp +++ b/indra/newview/llpanelgroupinvite.cpp @@ -1,30 +1,25 @@ /** * @file llpanelgroupinvite.cpp * - * $LicenseInfo:firstyear=2006&license=viewergpl$ - * - * Copyright (c) 2006-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * 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. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * 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. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * 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 * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -33,16 +28,21 @@ #include "llpanelgroupinvite.h" #include "llagent.h" +#include "llavatarnamecache.h" #include "llfloateravatarpicker.h" #include "llbutton.h" +#include "llcallingcard.h" #include "llcombobox.h" +#include "llgroupactions.h" #include "llgroupmgr.h" #include "llnamelistctrl.h" +#include "llnotificationsutil.h" +#include "llscrolllistitem.h" #include "llspinctrl.h" #include "lltextbox.h" #include "llviewerobject.h" #include "llviewerobjectlist.h" -#include "llvieweruictrlfactory.h" +#include "lluictrlfactory.h" #include "llviewerwindow.h" class LLPanelGroupInvite::impl @@ -52,7 +52,7 @@ public: ~impl(); void addUsers(const std::vector<std::string>& names, - const std::vector<LLUUID>& agent_ids); + const uuid_vec_t& agent_ids); void submitInvitations(); void addRoleNames(LLGroupMgrGroupData* gdatap); void handleRemove(); @@ -63,21 +63,26 @@ public: static void callbackClickAdd(void* userdata); static void callbackClickRemove(void* userdata); static void callbackSelect(LLUICtrl* ctrl, void* userdata); - static void callbackAddUsers(const std::vector<std::string>& names, - const std::vector<LLUUID>& agent_ids, + static void callbackAddUsers(const uuid_vec_t& agent_ids, void* user_data); - static void inviteOwnerCallback(S32 option, void* userdata); + + static void onAvatarNameCache(const LLUUID& agent_id, + const LLAvatarName& av_name, + void* user_data); + + bool inviteOwnerCallback(const LLSD& notification, const LLSD& response); public: LLUUID mGroupID; - LLString mLoadingText; + std::string mLoadingText; LLNameListCtrl *mInvitees; LLComboBox *mRoleNames; LLButton *mOKButton; LLButton *mRemoveButton; LLTextBox *mGroupName; - LLTextBox *mOwnerWarning; + std::string mOwnerWarning; + std::string mAlreadyInGroup; bool mConfirmedOwnerInvite; void (*mCloseCallback)(void* data); @@ -94,7 +99,6 @@ LLPanelGroupInvite::impl::impl(const LLUUID& group_id): mOKButton ( NULL ), mRemoveButton( NULL ), mGroupName( NULL ), - mOwnerWarning ( NULL ), mConfirmedOwnerInvite( false ), mCloseCallback( NULL ), mCloseCallbackUserData( NULL ) @@ -106,7 +110,7 @@ LLPanelGroupInvite::impl::~impl() } void LLPanelGroupInvite::impl::addUsers(const std::vector<std::string>& names, - const std::vector<LLUUID>& agent_ids) + const uuid_vec_t& agent_ids) { std::string name; LLUUID id; @@ -147,7 +151,7 @@ void LLPanelGroupInvite::impl::submitInvitations() { std::map<LLUUID, LLUUID> role_member_pairs; - LLGroupMgrGroupData* gdatap = gGroupMgr->getGroupData(mGroupID); + LLGroupMgrGroupData* gdatap = LLGroupMgr::getInstance()->getGroupData(mGroupID); // Default to everyone role. LLUUID role_id = LLUUID::null; @@ -159,46 +163,58 @@ void LLPanelGroupInvite::impl::submitInvitations() // owner role: display confirmation and wait for callback if ((role_id == gdatap->mOwnerRole) && (!mConfirmedOwnerInvite)) { - LLString::format_map_t args; - args["[MESSAGE]"] = mOwnerWarning->getText(); - gViewerWindow->alertXml("GenericAlertYesCancel", args, inviteOwnerCallback, this); + LLSD args; + args["MESSAGE"] = mOwnerWarning; + LLNotificationsUtil::add("GenericAlertYesCancel", args, LLSD(), boost::bind(&LLPanelGroupInvite::impl::inviteOwnerCallback, this, _1, _2)); return; // we'll be called again if user confirms } } + bool already_in_group = false; //loop over the users std::vector<LLScrollListItem*> items = mInvitees->getAllData(); for (std::vector<LLScrollListItem*>::iterator iter = items.begin(); iter != items.end(); ++iter) { LLScrollListItem* item = *iter; + if(LLGroupActions::isAvatarMemberOfGroup(mGroupID, item->getUUID())) + { + already_in_group = true; + continue; + } role_member_pairs[item->getUUID()] = role_id; } - - gGroupMgr->sendGroupMemberInvites(mGroupID, role_member_pairs); + + LLGroupMgr::getInstance()->sendGroupMemberInvites(mGroupID, role_member_pairs); + + if(already_in_group) + { + LLSD msg; + msg["MESSAGE"] = mAlreadyInGroup; + LLNotificationsUtil::add("GenericAlert", msg); + } //then close (*mCloseCallback)(mCloseCallbackUserData); } -//static -void LLPanelGroupInvite::impl::inviteOwnerCallback(S32 option, void* userdata) +bool LLPanelGroupInvite::impl::inviteOwnerCallback(const LLSD& notification, const LLSD& response) { - LLPanelGroupInvite::impl* self = (LLPanelGroupInvite::impl*)userdata; - if (!self) return; + S32 option = LLNotificationsUtil::getSelectedOption(notification, response); switch(option) { case 0: // user confirmed that they really want a new group owner - self->mConfirmedOwnerInvite = true; - self->submitInvitations(); + mConfirmedOwnerInvite = true; + submitInvitations(); break; case 1: // fall through default: break; } + return false; } @@ -276,8 +292,8 @@ void LLPanelGroupInvite::impl::callbackClickAdd(void* userdata) LLFloater* parentp; parentp = gFloaterView->getParentFloater(panelp); - parentp->addDependentFloater(LLFloaterAvatarPicker::show(callbackAddUsers, - panelp->mImplementation, + parentp->addDependentFloater(LLFloaterAvatarPicker::show(boost::bind(impl::callbackAddUsers, _1, + panelp->mImplementation), TRUE)); } } @@ -342,28 +358,45 @@ void LLPanelGroupInvite::impl::callbackClickOK(void* userdata) if ( selfp ) selfp->submitInvitations(); } + + //static -void LLPanelGroupInvite::impl::callbackAddUsers(const std::vector<std::string>& names, - const std::vector<LLUUID>& ids, - void* user_data) +void LLPanelGroupInvite::impl::callbackAddUsers(const uuid_vec_t& agent_ids, void* user_data) +{ + std::vector<std::string> names; + for (S32 i = 0; i < (S32)agent_ids.size(); i++) + { + LLAvatarNameCache::get(agent_ids[i], + boost::bind(&LLPanelGroupInvite::impl::onAvatarNameCache, _1, _2, user_data)); + } + +} + +void LLPanelGroupInvite::impl::onAvatarNameCache(const LLUUID& agent_id, + const LLAvatarName& av_name, + void* user_data) { impl* selfp = (impl*) user_data; - if ( selfp) selfp->addUsers(names, ids); + if (selfp) + { + std::vector<std::string> names; + uuid_vec_t agent_ids; + agent_ids.push_back(agent_id); + names.push_back(av_name.getCompleteName()); + + selfp->addUsers(names, agent_ids); + } } -LLPanelGroupInvite::LLPanelGroupInvite(const std::string& name, - const LLUUID& group_id) - : LLPanel(name) -{ - mImplementation = new impl(group_id); - mPendingUpdate = FALSE; - mStoreSelected = LLUUID::null; - - std::string panel_def_file; +LLPanelGroupInvite::LLPanelGroupInvite(const LLUUID& group_id) + : LLPanel(), + mImplementation(new impl(group_id)), + mPendingUpdate(FALSE) +{ // Pass on construction of this panel to the control factory. - gUICtrlFactory->buildPanel(this, "panel_group_invite.xml", &getFactoryMap()); + buildFromFile( "panel_group_invite.xml"); } LLPanelGroupInvite::~LLPanelGroupInvite() @@ -387,26 +420,23 @@ void LLPanelGroupInvite::clear() mImplementation->mOKButton->setEnabled(FALSE); } -void LLPanelGroupInvite::addUsers(std::vector<LLUUID>& agent_ids) +void LLPanelGroupInvite::addUsers(uuid_vec_t& agent_ids) { std::vector<std::string> names; for (S32 i = 0; i < (S32)agent_ids.size(); i++) { + std::string fullname; LLUUID agent_id = agent_ids[i]; LLViewerObject* dest = gObjectList.findObject(agent_id); if(dest && dest->isAvatar()) { - LLString fullname; - LLString::format_map_t args; LLNameValue* nvfirst = dest->getNVPair("FirstName"); LLNameValue* nvlast = dest->getNVPair("LastName"); if(nvfirst && nvlast) { - args["[FIRST]"] = nvfirst->getString(); - args["[LAST]"] = nvlast->getString(); - fullname = nvfirst->getString(); - fullname += " "; - fullname += nvlast->getString(); + fullname = LLCacheName::buildFullName( + nvfirst->getString(), nvlast->getString()); + } if (!fullname.empty()) { @@ -418,10 +448,43 @@ void LLPanelGroupInvite::addUsers(std::vector<LLUUID>& agent_ids) names.push_back("(Unknown)"); } } + else + { + //looks like user try to invite offline friend + //for offline avatar_id gObjectList.findObject() will return null + //so we need to do this additional search in avatar tracker, see EXT-4732 + if (LLAvatarTracker::instance().isBuddy(agent_id)) + { + if (!gCacheName->getFullName(agent_id, fullname)) + { + // actually it should happen, just in case + gCacheName->get(LLUUID(agent_id), false, boost::bind( + &LLPanelGroupInvite::addUserCallback, this, _1, _2)); + // for this special case! + //when there is no cached name we should remove resident from agent_ids list to avoid breaking of sequence + // removed id will be added in callback + agent_ids.erase(agent_ids.begin() + i); + } + else + { + names.push_back(fullname); + } + } + } } mImplementation->addUsers(names, agent_ids); } +void LLPanelGroupInvite::addUserCallback(const LLUUID& id, const std::string& full_name) +{ + std::vector<std::string> names; + uuid_vec_t agent_ids; + agent_ids.push_back(id); + names.push_back(full_name); + + mImplementation->addUsers(names, agent_ids); +} + void LLPanelGroupInvite::draw() { LLPanel::draw(); @@ -452,7 +515,7 @@ void LLPanelGroupInvite::update() void LLPanelGroupInvite::updateLists() { - LLGroupMgrGroupData* gdatap = gGroupMgr->getGroupData(mImplementation->mGroupID); + LLGroupMgrGroupData* gdatap = LLGroupMgr::getInstance()->getGroupData(mImplementation->mGroupID); bool waiting = false; if (gdatap) @@ -494,9 +557,9 @@ void LLPanelGroupInvite::updateLists() { if (!mPendingUpdate) { - gGroupMgr->sendGroupPropertiesRequest(mImplementation->mGroupID); - gGroupMgr->sendGroupMembersRequest(mImplementation->mGroupID); - gGroupMgr->sendGroupRoleDataRequest(mImplementation->mGroupID); + LLGroupMgr::getInstance()->sendGroupPropertiesRequest(mImplementation->mGroupID); + LLGroupMgr::getInstance()->sendGroupMembersRequest(mImplementation->mGroupID); + LLGroupMgr::getInstance()->sendGroupRoleDataRequest(mImplementation->mGroupID); } mPendingUpdate = TRUE; } @@ -522,9 +585,8 @@ BOOL LLPanelGroupInvite::postBuild() getChild<LLNameListCtrl>("invitee_list", recurse); if ( mImplementation->mInvitees ) { - mImplementation->mInvitees->setCallbackUserData(mImplementation); mImplementation->mInvitees->setCommitOnSelectionChange(TRUE); - mImplementation->mInvitees->setCommitCallback(impl::callbackSelect); + mImplementation->mInvitees->setCommitCallback(impl::callbackSelect, mImplementation); } LLButton* button = getChild<LLButton>("add_button", recurse); @@ -532,17 +594,14 @@ BOOL LLPanelGroupInvite::postBuild() { // default to opening avatarpicker automatically // (*impl::callbackClickAdd)((void*)this); - button->setClickedCallback(impl::callbackClickAdd); - button->setCallbackUserData(this); + button->setClickedCallback(impl::callbackClickAdd, this); } mImplementation->mRemoveButton = getChild<LLButton>("remove_button", recurse); if ( mImplementation->mRemoveButton ) { - mImplementation->mRemoveButton-> - setClickedCallback(impl::callbackClickRemove); - mImplementation->mRemoveButton->setCallbackUserData(mImplementation); + mImplementation->mRemoveButton->setClickedCallback(impl::callbackClickRemove, mImplementation); mImplementation->mRemoveButton->setEnabled(FALSE); } @@ -550,20 +609,18 @@ BOOL LLPanelGroupInvite::postBuild() getChild<LLButton>("ok_button", recurse); if ( mImplementation->mOKButton ) { - mImplementation->mOKButton-> - setClickedCallback(impl::callbackClickOK); - mImplementation->mOKButton->setCallbackUserData(mImplementation); + mImplementation->mOKButton->setClickedCallback(impl::callbackClickOK, mImplementation); mImplementation->mOKButton->setEnabled(FALSE); } button = getChild<LLButton>("cancel_button", recurse); if ( button ) { - button->setClickedCallback(impl::callbackClickCancel); - button->setCallbackUserData(mImplementation); + button->setClickedCallback(impl::callbackClickCancel, mImplementation); } - mImplementation->mOwnerWarning = (LLTextBox*)getChildByName("confirm_invite_owner_str", recurse); + mImplementation->mOwnerWarning = getString("confirm_invite_owner_str"); + mImplementation->mAlreadyInGroup = getString("already_in_group"); update(); |