PageRenderTime 83ms CodeModel.GetById 40ms app.highlight 18ms RepoModel.GetById 23ms app.codeStats 0ms

/indra/newview/llpanelpeoplemenus.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 197 lines | 118 code | 32 blank | 47 comment | 30 complexity | 1cb575ee32121c11d3f956f28b1ba81c MD5 | raw file
  1/** 
  2 * @file llpanelpeoplemenus.h
  3 * @brief Menus used by the side tray "People" panel
  4 *
  5 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29// libs
 30#include "llmenugl.h"
 31#include "lluictrlfactory.h"
 32
 33#include "llpanelpeoplemenus.h"
 34
 35// newview
 36#include "llagent.h"
 37#include "llagentdata.h"			// for gAgentID
 38#include "llavataractions.h"
 39#include "llcallingcard.h"			// for LLAvatarTracker
 40#include "llviewermenu.h"			// for gMenuHolder
 41
 42namespace LLPanelPeopleMenus
 43{
 44
 45NearbyMenu gNearbyMenu;
 46
 47//== NearbyMenu ===============================================================
 48
 49LLContextMenu* NearbyMenu::createMenu()
 50{
 51	// set up the callbacks for all of the avatar menu items
 52	LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar;
 53	LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registrar;
 54
 55	if ( mUUIDs.size() == 1 )
 56	{
 57		// Set up for one person selected menu
 58
 59		const LLUUID& id = mUUIDs.front();
 60		registrar.add("Avatar.Profile",			boost::bind(&LLAvatarActions::showProfile,				id));
 61		registrar.add("Avatar.AddFriend",		boost::bind(&LLAvatarActions::requestFriendshipDialog,	id));
 62		registrar.add("Avatar.RemoveFriend",	boost::bind(&LLAvatarActions::removeFriendDialog, 		id));
 63		registrar.add("Avatar.IM",				boost::bind(&LLAvatarActions::startIM,					id));
 64		registrar.add("Avatar.Call",			boost::bind(&LLAvatarActions::startCall,				id));
 65		registrar.add("Avatar.OfferTeleport",	boost::bind(&NearbyMenu::offerTeleport,					this));
 66		registrar.add("Avatar.ShowOnMap",		boost::bind(&LLAvatarActions::showOnMap,				id));
 67		registrar.add("Avatar.Share",			boost::bind(&LLAvatarActions::share,					id));
 68		registrar.add("Avatar.Pay",				boost::bind(&LLAvatarActions::pay,						id));
 69		registrar.add("Avatar.BlockUnblock",	boost::bind(&LLAvatarActions::toggleBlock,				id));
 70
 71		enable_registrar.add("Avatar.EnableItem", boost::bind(&NearbyMenu::enableContextMenuItem,	this, _2));
 72		enable_registrar.add("Avatar.CheckItem",  boost::bind(&NearbyMenu::checkContextMenuItem,	this, _2));
 73
 74		// create the context menu from the XUI
 75		return createFromFile("menu_people_nearby.xml");
 76	}
 77	else
 78	{
 79		// Set up for multi-selected People
 80
 81		// registrar.add("Avatar.AddFriend",	boost::bind(&LLAvatarActions::requestFriendshipDialog,	mUUIDs)); // *TODO: unimplemented
 82		registrar.add("Avatar.IM",			boost::bind(&LLAvatarActions::startConference,			mUUIDs));
 83		registrar.add("Avatar.Call",		boost::bind(&LLAvatarActions::startAdhocCall,			mUUIDs));
 84		registrar.add("Avatar.OfferTeleport",	boost::bind(&NearbyMenu::offerTeleport,					this));
 85		registrar.add("Avatar.RemoveFriend",boost::bind(&LLAvatarActions::removeFriendsDialog,		mUUIDs));
 86		// registrar.add("Avatar.Share",		boost::bind(&LLAvatarActions::startIM,					mUUIDs)); // *TODO: unimplemented
 87		// registrar.add("Avatar.Pay",		boost::bind(&LLAvatarActions::pay,						mUUIDs)); // *TODO: unimplemented
 88		enable_registrar.add("Avatar.EnableItem",	boost::bind(&NearbyMenu::enableContextMenuItem,	this, _2));
 89
 90		// create the context menu from the XUI
 91		return createFromFile("menu_people_nearby_multiselect.xml");
 92	}
 93}
 94
 95bool NearbyMenu::enableContextMenuItem(const LLSD& userdata)
 96{
 97	std::string item = userdata.asString();
 98
 99	// Note: can_block and can_delete is used only for one person selected menu
100	// so we don't need to go over all uuids.
101
102	if (item == std::string("can_block"))
103	{
104		const LLUUID& id = mUUIDs.front();
105		return LLAvatarActions::canBlock(id);
106	}
107	else if (item == std::string("can_add"))
108	{
109		// We can add friends if:
110		// - there are selected people
111		// - and there are no friends among selection yet.
112
113		//EXT-7389 - disable for more than 1
114		if(mUUIDs.size() > 1)
115		{
116			return false;
117		}
118
119		bool result = (mUUIDs.size() > 0);
120
121		uuid_vec_t::const_iterator
122			id = mUUIDs.begin(),
123			uuids_end = mUUIDs.end();
124
125		for (;id != uuids_end; ++id)
126		{
127			if ( LLAvatarActions::isFriend(*id) )
128			{
129				result = false;
130				break;
131			}
132		}
133
134		return result;
135	}
136	else if (item == std::string("can_delete"))
137	{
138		// We can remove friends if:
139		// - there are selected people
140		// - and there are only friends among selection.
141
142		bool result = (mUUIDs.size() > 0);
143
144		uuid_vec_t::const_iterator
145			id = mUUIDs.begin(),
146			uuids_end = mUUIDs.end();
147
148		for (;id != uuids_end; ++id)
149		{
150			if ( !LLAvatarActions::isFriend(*id) )
151			{
152				result = false;
153				break;
154			}
155		}
156
157		return result;
158	}
159	else if (item == std::string("can_call"))
160	{
161		return LLAvatarActions::canCall();
162	}
163	else if (item == std::string("can_show_on_map"))
164	{
165		const LLUUID& id = mUUIDs.front();
166
167		return (LLAvatarTracker::instance().isBuddyOnline(id) && is_agent_mappable(id))
168					|| gAgent.isGodlike();
169	}
170	else if(item == std::string("can_offer_teleport"))
171	{
172		return LLAvatarActions::canOfferTeleport(mUUIDs);
173	}
174	return false;
175}
176
177bool NearbyMenu::checkContextMenuItem(const LLSD& userdata)
178{
179	std::string item = userdata.asString();
180	const LLUUID& id = mUUIDs.front();
181
182	if (item == std::string("is_blocked"))
183	{
184		return LLAvatarActions::isBlocked(id);
185	}
186
187	return false;
188}
189
190void NearbyMenu::offerTeleport()
191{
192	// boost::bind cannot recognize overloaded method LLAvatarActions::offerTeleport(),
193	// so we have to use a wrapper.
194	LLAvatarActions::offerTeleport(mUUIDs);
195}
196
197} // namespace LLPanelPeopleMenus