llpanelimcontrolpanel.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:10k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llpanelavatar.cpp
  3.  * @brief LLPanelAvatar and related class implementations
  4.  *
  5.  * $LicenseInfo:firstyear=2004&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2004-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llfloaterreg.h"
  34. #include "llpanelimcontrolpanel.h"
  35. #include "llagent.h"
  36. #include "llavataractions.h"
  37. #include "llavatariconctrl.h"
  38. #include "llbutton.h"
  39. #include "llgroupactions.h"
  40. #include "llavatarlist.h"
  41. #include "llparticipantlist.h"
  42. #include "llimview.h"
  43. #include "llvoicechannel.h"
  44. #include "llsidetray.h"
  45. #include "llspeakers.h"
  46. #include "lltrans.h"
  47. void LLPanelChatControlPanel::onCallButtonClicked()
  48. {
  49. gIMMgr->startCall(mSessionId);
  50. }
  51. void LLPanelChatControlPanel::onEndCallButtonClicked()
  52. {
  53. gIMMgr->endCall(mSessionId);
  54. }
  55. void LLPanelChatControlPanel::onOpenVoiceControlsClicked()
  56. {
  57. LLFloaterReg::showInstance("voice_controls");
  58. }
  59. void LLPanelChatControlPanel::onChange(EStatusType status, const std::string &channelURI, bool proximal)
  60. {
  61. if(status == STATUS_JOINING || status == STATUS_LEFT_CHANNEL)
  62. {
  63. return;
  64. }
  65. updateCallButton();
  66. }
  67. void LLPanelChatControlPanel::onVoiceChannelStateChanged(const LLVoiceChannel::EState& old_state, const LLVoiceChannel::EState& new_state)
  68. {
  69. updateButtons(new_state >= LLVoiceChannel::STATE_CALL_STARTED);
  70. }
  71. void LLPanelChatControlPanel::updateCallButton()
  72. {
  73. bool voice_enabled = LLVoiceClient::voiceEnabled() && gVoiceClient->voiceWorking();
  74. LLIMModel::LLIMSession* session = LLIMModel::getInstance()->findIMSession(mSessionId);
  75. if (!session) 
  76. {
  77. childSetEnabled("call_btn", false);
  78. return;
  79. }
  80. bool session_initialized = session->mSessionInitialized;
  81. bool callback_enabled = session->mCallBackEnabled;
  82. BOOL enable_connect = session_initialized
  83. && voice_enabled
  84. && callback_enabled;
  85. childSetEnabled("call_btn", enable_connect);
  86. }
  87. void LLPanelChatControlPanel::updateButtons(bool is_call_started)
  88. {
  89. childSetVisible("end_call_btn_panel", is_call_started);
  90. childSetVisible("voice_ctrls_btn_panel", is_call_started);
  91. childSetVisible("call_btn_panel", ! is_call_started);
  92. updateCallButton();
  93. }
  94. LLPanelChatControlPanel::~LLPanelChatControlPanel()
  95. {
  96. mVoiceChannelStateChangeConnection.disconnect();
  97. if(LLVoiceClient::getInstance())
  98. LLVoiceClient::getInstance()->removeObserver(this);
  99. }
  100. BOOL LLPanelChatControlPanel::postBuild()
  101. {
  102. childSetAction("call_btn", boost::bind(&LLPanelChatControlPanel::onCallButtonClicked, this));
  103. childSetAction("end_call_btn", boost::bind(&LLPanelChatControlPanel::onEndCallButtonClicked, this));
  104. childSetAction("voice_ctrls_btn", boost::bind(&LLPanelChatControlPanel::onOpenVoiceControlsClicked, this));
  105. gVoiceClient->addObserver(this);
  106. return TRUE;
  107. }
  108. void LLPanelChatControlPanel::setSessionId(const LLUUID& session_id)
  109. {
  110. //Method is called twice for AdHoc and Group chat. Second time when server init reply received
  111. mSessionId = session_id;
  112. LLVoiceChannel* voice_channel = LLIMModel::getInstance()->getVoiceChannel(mSessionId);
  113. if(voice_channel)
  114. {
  115. mVoiceChannelStateChangeConnection = voice_channel->setStateChangedCallback(boost::bind(&LLPanelChatControlPanel::onVoiceChannelStateChanged, this, _1, _2));
  116. //call (either p2p, group or ad-hoc) can be already in started state
  117. updateButtons(voice_channel->getState() >= LLVoiceChannel::STATE_CALL_STARTED);
  118. }
  119. }
  120. LLPanelIMControlPanel::LLPanelIMControlPanel()
  121. {
  122. }
  123. LLPanelIMControlPanel::~LLPanelIMControlPanel()
  124. {
  125. LLAvatarTracker::instance().removeParticularFriendObserver(mAvatarID, this);
  126. }
  127. BOOL LLPanelIMControlPanel::postBuild()
  128. {
  129. childSetAction("view_profile_btn", boost::bind(&LLPanelIMControlPanel::onViewProfileButtonClicked, this));
  130. childSetAction("add_friend_btn", boost::bind(&LLPanelIMControlPanel::onAddFriendButtonClicked, this));
  131. childSetAction("share_btn", boost::bind(&LLPanelIMControlPanel::onShareButtonClicked, this));
  132. childSetAction("teleport_btn", boost::bind(&LLPanelIMControlPanel::onTeleportButtonClicked, this));
  133. childSetAction("pay_btn", boost::bind(&LLPanelIMControlPanel::onPayButtonClicked, this));
  134. childSetEnabled("add_friend_btn", !LLAvatarActions::isFriend(getChild<LLAvatarIconCtrl>("avatar_icon")->getAvatarId()));
  135. return LLPanelChatControlPanel::postBuild();
  136. }
  137. void LLPanelIMControlPanel::onTeleportButtonClicked()
  138. {
  139. LLAvatarActions::offerTeleport(mAvatarID);
  140. }
  141. void LLPanelIMControlPanel::onPayButtonClicked()
  142. {
  143. LLAvatarActions::pay(mAvatarID);
  144. }
  145. void LLPanelIMControlPanel::onViewProfileButtonClicked()
  146. {
  147. LLAvatarActions::showProfile(mAvatarID);
  148. }
  149. void LLPanelIMControlPanel::onAddFriendButtonClicked()
  150. {
  151. LLAvatarIconCtrl* avatar_icon = getChild<LLAvatarIconCtrl>("avatar_icon");
  152. std::string full_name = avatar_icon->getFirstName() + " " + avatar_icon->getLastName();
  153. LLAvatarActions::requestFriendshipDialog(mAvatarID, full_name);
  154. }
  155. void LLPanelIMControlPanel::onShareButtonClicked()
  156. {
  157. LLAvatarActions::share(mAvatarID);
  158. }
  159. void LLPanelIMControlPanel::setSessionId(const LLUUID& session_id)
  160. {
  161. LLPanelChatControlPanel::setSessionId(session_id);
  162. LLIMModel& im_model = LLIMModel::instance();
  163. LLAvatarTracker::instance().removeParticularFriendObserver(mAvatarID, this);
  164. mAvatarID = im_model.getOtherParticipantID(session_id);
  165. LLAvatarTracker::instance().addParticularFriendObserver(mAvatarID, this);
  166. // Disable "Add friend" button for friends.
  167. childSetEnabled("add_friend_btn", !LLAvatarActions::isFriend(mAvatarID));
  168. // Disable "Teleport" button if friend is offline
  169. if(LLAvatarActions::isFriend(mAvatarID))
  170. {
  171. childSetEnabled("teleport_btn", LLAvatarTracker::instance().isBuddyOnline(mAvatarID));
  172. }
  173. getChild<LLAvatarIconCtrl>("avatar_icon")->setValue(mAvatarID);
  174. // Disable most profile buttons if the participant is
  175. // not really an SL avatar (e.g., an Avaline caller).
  176. LLIMModel::LLIMSession* im_session =
  177. im_model.findIMSession(session_id);
  178. if( im_session && !im_session->mOtherParticipantIsAvatar )
  179. {
  180. childSetEnabled("view_profile_btn", FALSE);
  181. childSetEnabled("add_friend_btn", FALSE);
  182. childSetEnabled("share_btn", FALSE);
  183. childSetEnabled("teleport_btn", FALSE);
  184. childSetEnabled("pay_btn", FALSE);
  185. }
  186. }
  187. //virtual
  188. void LLPanelIMControlPanel::changed(U32 mask)
  189. {
  190. childSetEnabled("add_friend_btn", !LLAvatarActions::isFriend(mAvatarID));
  191. // Disable "Teleport" button if friend is offline
  192. if(LLAvatarActions::isFriend(mAvatarID))
  193. {
  194. childSetEnabled("teleport_btn", LLAvatarTracker::instance().isBuddyOnline(mAvatarID));
  195. }
  196. }
  197. LLPanelGroupControlPanel::LLPanelGroupControlPanel(const LLUUID& session_id):
  198. mParticipantList(NULL)
  199. {
  200. }
  201. BOOL LLPanelGroupControlPanel::postBuild()
  202. {
  203. childSetAction("group_info_btn", boost::bind(&LLPanelGroupControlPanel::onGroupInfoButtonClicked, this));
  204. return LLPanelChatControlPanel::postBuild();
  205. }
  206. LLPanelGroupControlPanel::~LLPanelGroupControlPanel()
  207. {
  208. delete mParticipantList;
  209. mParticipantList = NULL;
  210. }
  211. // virtual
  212. void LLPanelGroupControlPanel::draw()
  213. {
  214. // Need to resort the participant list if it's in sort by recent speaker order.
  215. if (mParticipantList)
  216. mParticipantList->updateRecentSpeakersOrder();
  217. LLPanelChatControlPanel::draw();
  218. }
  219. void LLPanelGroupControlPanel::onGroupInfoButtonClicked()
  220. {
  221. LLGroupActions::show(mGroupID);
  222. }
  223. void LLPanelGroupControlPanel::onSortMenuItemClicked(const LLSD& userdata)
  224. {
  225. // TODO: Check this code when when sort order menu will be added. (EM)
  226. if (false && !mParticipantList)
  227. return;
  228. std::string chosen_item = userdata.asString();
  229. if (chosen_item == "sort_name")
  230. {
  231. mParticipantList->setSortOrder(LLParticipantList::E_SORT_BY_NAME);
  232. }
  233. }
  234. void LLPanelGroupControlPanel::onVoiceChannelStateChanged(const LLVoiceChannel::EState& old_state, const LLVoiceChannel::EState& new_state)
  235. {
  236. LLPanelChatControlPanel::onVoiceChannelStateChanged(old_state, new_state);
  237. mParticipantList->setSpeakingIndicatorsVisible(new_state >= LLVoiceChannel::STATE_CALL_STARTED);
  238. }
  239. void LLPanelGroupControlPanel::setSessionId(const LLUUID& session_id)
  240. {
  241. LLPanelChatControlPanel::setSessionId(session_id);
  242. mGroupID = session_id;
  243. // for group and Ad-hoc chat we need to include agent into list 
  244. if(!mParticipantList)
  245. {
  246. LLSpeakerMgr* speaker_manager = LLIMModel::getInstance()->getSpeakerManager(session_id);
  247. mParticipantList = new LLParticipantList(speaker_manager, getChild<LLAvatarList>("speakers_list"), true,false);
  248. }
  249. }
  250. LLPanelAdHocControlPanel::LLPanelAdHocControlPanel(const LLUUID& session_id):LLPanelGroupControlPanel(session_id)
  251. {
  252. }
  253. BOOL LLPanelAdHocControlPanel::postBuild()
  254. {
  255. //We don't need LLPanelGroupControlPanel::postBuild() to be executed as there is no group_info_btn at AdHoc chat
  256. return LLPanelChatControlPanel::postBuild();
  257. }