PageRenderTime 58ms CodeModel.GetById 13ms RepoModel.GetById 1ms 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
Possible License(s): LGPL-2.1
  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. #include "llviewerprecompiledheaders.h"
  27. // libs
  28. #include "llmenugl.h"
  29. #include "lluictrlfactory.h"
  30. #include "llpanelpeoplemenus.h"
  31. // newview
  32. #include "llagent.h"
  33. #include "llagentdata.h" // for gAgentID
  34. #include "llavataractions.h"
  35. #include "llcallingcard.h" // for LLAvatarTracker
  36. #include "llviewermenu.h" // for gMenuHolder
  37. namespace LLPanelPeopleMenus
  38. {
  39. NearbyMenu gNearbyMenu;
  40. //== NearbyMenu ===============================================================
  41. LLContextMenu* NearbyMenu::createMenu()
  42. {
  43. // set up the callbacks for all of the avatar menu items
  44. LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar;
  45. LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registrar;
  46. if ( mUUIDs.size() == 1 )
  47. {
  48. // Set up for one person selected menu
  49. const LLUUID& id = mUUIDs.front();
  50. registrar.add("Avatar.Profile", boost::bind(&LLAvatarActions::showProfile, id));
  51. registrar.add("Avatar.AddFriend", boost::bind(&LLAvatarActions::requestFriendshipDialog, id));
  52. registrar.add("Avatar.RemoveFriend", boost::bind(&LLAvatarActions::removeFriendDialog, id));
  53. registrar.add("Avatar.IM", boost::bind(&LLAvatarActions::startIM, id));
  54. registrar.add("Avatar.Call", boost::bind(&LLAvatarActions::startCall, id));
  55. registrar.add("Avatar.OfferTeleport", boost::bind(&NearbyMenu::offerTeleport, this));
  56. registrar.add("Avatar.ShowOnMap", boost::bind(&LLAvatarActions::showOnMap, id));
  57. registrar.add("Avatar.Share", boost::bind(&LLAvatarActions::share, id));
  58. registrar.add("Avatar.Pay", boost::bind(&LLAvatarActions::pay, id));
  59. registrar.add("Avatar.BlockUnblock", boost::bind(&LLAvatarActions::toggleBlock, id));
  60. enable_registrar.add("Avatar.EnableItem", boost::bind(&NearbyMenu::enableContextMenuItem, this, _2));
  61. enable_registrar.add("Avatar.CheckItem", boost::bind(&NearbyMenu::checkContextMenuItem, this, _2));
  62. // create the context menu from the XUI
  63. return createFromFile("menu_people_nearby.xml");
  64. }
  65. else
  66. {
  67. // Set up for multi-selected People
  68. // registrar.add("Avatar.AddFriend", boost::bind(&LLAvatarActions::requestFriendshipDialog, mUUIDs)); // *TODO: unimplemented
  69. registrar.add("Avatar.IM", boost::bind(&LLAvatarActions::startConference, mUUIDs));
  70. registrar.add("Avatar.Call", boost::bind(&LLAvatarActions::startAdhocCall, mUUIDs));
  71. registrar.add("Avatar.OfferTeleport", boost::bind(&NearbyMenu::offerTeleport, this));
  72. registrar.add("Avatar.RemoveFriend",boost::bind(&LLAvatarActions::removeFriendsDialog, mUUIDs));
  73. // registrar.add("Avatar.Share", boost::bind(&LLAvatarActions::startIM, mUUIDs)); // *TODO: unimplemented
  74. // registrar.add("Avatar.Pay", boost::bind(&LLAvatarActions::pay, mUUIDs)); // *TODO: unimplemented
  75. enable_registrar.add("Avatar.EnableItem", boost::bind(&NearbyMenu::enableContextMenuItem, this, _2));
  76. // create the context menu from the XUI
  77. return createFromFile("menu_people_nearby_multiselect.xml");
  78. }
  79. }
  80. bool NearbyMenu::enableContextMenuItem(const LLSD& userdata)
  81. {
  82. std::string item = userdata.asString();
  83. // Note: can_block and can_delete is used only for one person selected menu
  84. // so we don't need to go over all uuids.
  85. if (item == std::string("can_block"))
  86. {
  87. const LLUUID& id = mUUIDs.front();
  88. return LLAvatarActions::canBlock(id);
  89. }
  90. else if (item == std::string("can_add"))
  91. {
  92. // We can add friends if:
  93. // - there are selected people
  94. // - and there are no friends among selection yet.
  95. //EXT-7389 - disable for more than 1
  96. if(mUUIDs.size() > 1)
  97. {
  98. return false;
  99. }
  100. bool result = (mUUIDs.size() > 0);
  101. uuid_vec_t::const_iterator
  102. id = mUUIDs.begin(),
  103. uuids_end = mUUIDs.end();
  104. for (;id != uuids_end; ++id)
  105. {
  106. if ( LLAvatarActions::isFriend(*id) )
  107. {
  108. result = false;
  109. break;
  110. }
  111. }
  112. return result;
  113. }
  114. else if (item == std::string("can_delete"))
  115. {
  116. // We can remove friends if:
  117. // - there are selected people
  118. // - and there are only friends among selection.
  119. bool result = (mUUIDs.size() > 0);
  120. uuid_vec_t::const_iterator
  121. id = mUUIDs.begin(),
  122. uuids_end = mUUIDs.end();
  123. for (;id != uuids_end; ++id)
  124. {
  125. if ( !LLAvatarActions::isFriend(*id) )
  126. {
  127. result = false;
  128. break;
  129. }
  130. }
  131. return result;
  132. }
  133. else if (item == std::string("can_call"))
  134. {
  135. return LLAvatarActions::canCall();
  136. }
  137. else if (item == std::string("can_show_on_map"))
  138. {
  139. const LLUUID& id = mUUIDs.front();
  140. return (LLAvatarTracker::instance().isBuddyOnline(id) && is_agent_mappable(id))
  141. || gAgent.isGodlike();
  142. }
  143. else if(item == std::string("can_offer_teleport"))
  144. {
  145. return LLAvatarActions::canOfferTeleport(mUUIDs);
  146. }
  147. return false;
  148. }
  149. bool NearbyMenu::checkContextMenuItem(const LLSD& userdata)
  150. {
  151. std::string item = userdata.asString();
  152. const LLUUID& id = mUUIDs.front();
  153. if (item == std::string("is_blocked"))
  154. {
  155. return LLAvatarActions::isBlocked(id);
  156. }
  157. return false;
  158. }
  159. void NearbyMenu::offerTeleport()
  160. {
  161. // boost::bind cannot recognize overloaded method LLAvatarActions::offerTeleport(),
  162. // so we have to use a wrapper.
  163. LLAvatarActions::offerTeleport(mUUIDs);
  164. }
  165. } // namespace LLPanelPeopleMenus