PageRenderTime 57ms CodeModel.GetById 37ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llpanelimcontrolpanel.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 431 lines | 301 code | 86 blank | 44 comment | 28 complexity | 5f039506db63f7fa031f929f0ac51827 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpanelavatar.cpp
  3. * @brief LLPanelAvatar and related class implementations
  4. *
  5. * $LicenseInfo:firstyear=2004&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. #include "llfloaterreg.h"
  28. #include "llpanelimcontrolpanel.h"
  29. #include "llagent.h"
  30. #include "llappviewer.h" // for gDisconnected
  31. #include "llavataractions.h"
  32. #include "llavatariconctrl.h"
  33. #include "llbutton.h"
  34. #include "llgroupactions.h"
  35. #include "llavatarlist.h"
  36. #include "llparticipantlist.h"
  37. #include "llimview.h"
  38. #include "llvoicechannel.h"
  39. #include "llspeakers.h"
  40. #include "lltrans.h"
  41. void LLPanelChatControlPanel::onCallButtonClicked()
  42. {
  43. gIMMgr->startCall(mSessionId);
  44. }
  45. void LLPanelChatControlPanel::onEndCallButtonClicked()
  46. {
  47. gIMMgr->endCall(mSessionId);
  48. }
  49. void LLPanelChatControlPanel::onOpenVoiceControlsClicked()
  50. {
  51. LLFloaterReg::showInstance("voice_controls");
  52. }
  53. void LLPanelChatControlPanel::onChange(EStatusType status, const std::string &channelURI, bool proximal)
  54. {
  55. if(status == STATUS_JOINING || status == STATUS_LEFT_CHANNEL)
  56. {
  57. return;
  58. }
  59. updateCallButton();
  60. }
  61. void LLPanelChatControlPanel::onVoiceChannelStateChanged(const LLVoiceChannel::EState& old_state, const LLVoiceChannel::EState& new_state)
  62. {
  63. updateButtons(new_state);
  64. }
  65. void LLPanelChatControlPanel::updateCallButton()
  66. {
  67. // hide/show call button
  68. bool voice_enabled = LLVoiceClient::getInstance()->voiceEnabled() && LLVoiceClient::getInstance()->isVoiceWorking();
  69. LLIMModel::LLIMSession* session = LLIMModel::getInstance()->findIMSession(mSessionId);
  70. if (!session)
  71. {
  72. getChildView("call_btn")->setEnabled(false);
  73. return;
  74. }
  75. bool session_initialized = session->mSessionInitialized;
  76. bool callback_enabled = session->mCallBackEnabled;
  77. BOOL enable_connect = session_initialized
  78. && voice_enabled
  79. && callback_enabled;
  80. getChildView("call_btn")->setEnabled(enable_connect);
  81. }
  82. void LLPanelChatControlPanel::updateButtons(LLVoiceChannel::EState state)
  83. {
  84. bool is_call_started = state >= LLVoiceChannel::STATE_CALL_STARTED;
  85. getChildView("end_call_btn_panel")->setVisible( is_call_started);
  86. getChildView("voice_ctrls_btn_panel")->setVisible( is_call_started && findChild<LLView>("voice_ctrls_btn_panel"));
  87. getChildView("call_btn_panel")->setVisible( ! is_call_started);
  88. getChildView("volume_ctrl_panel")->setVisible(state == LLVoiceChannel::STATE_CONNECTED);
  89. updateCallButton();
  90. }
  91. LLPanelChatControlPanel::~LLPanelChatControlPanel()
  92. {
  93. mVoiceChannelStateChangeConnection.disconnect();
  94. if(LLVoiceClient::instanceExists())
  95. {
  96. LLVoiceClient::getInstance()->removeObserver(this);
  97. }
  98. }
  99. BOOL LLPanelChatControlPanel::postBuild()
  100. {
  101. childSetAction("call_btn", boost::bind(&LLPanelChatControlPanel::onCallButtonClicked, this));
  102. childSetAction("end_call_btn", boost::bind(&LLPanelChatControlPanel::onEndCallButtonClicked, this));
  103. childSetAction("voice_ctrls_btn", boost::bind(&LLPanelChatControlPanel::onOpenVoiceControlsClicked, this));
  104. LLVoiceClient::getInstance()->addObserver(this);
  105. return TRUE;
  106. }
  107. void LLPanelChatControlPanel::setSessionId(const LLUUID& session_id)
  108. {
  109. //Method is called twice for AdHoc and Group chat. Second time when server init reply received
  110. mSessionId = session_id;
  111. LLVoiceChannel* voice_channel = LLIMModel::getInstance()->getVoiceChannel(mSessionId);
  112. if(voice_channel)
  113. {
  114. mVoiceChannelStateChangeConnection = voice_channel->setStateChangedCallback(boost::bind(&LLPanelChatControlPanel::onVoiceChannelStateChanged, this, _1, _2));
  115. //call (either p2p, group or ad-hoc) can be already in started state
  116. updateButtons(voice_channel->getState());
  117. }
  118. }
  119. LLPanelIMControlPanel::LLPanelIMControlPanel()
  120. {
  121. }
  122. LLPanelIMControlPanel::~LLPanelIMControlPanel()
  123. {
  124. LLAvatarTracker::instance().removeParticularFriendObserver(mAvatarID, this);
  125. }
  126. BOOL LLPanelIMControlPanel::postBuild()
  127. {
  128. childSetAction("view_profile_btn", boost::bind(&LLPanelIMControlPanel::onViewProfileButtonClicked, this));
  129. childSetAction("add_friend_btn", boost::bind(&LLPanelIMControlPanel::onAddFriendButtonClicked, this));
  130. childSetAction("share_btn", boost::bind(&LLPanelIMControlPanel::onShareButtonClicked, this));
  131. childSetAction("teleport_btn", boost::bind(&LLPanelIMControlPanel::onTeleportButtonClicked, this));
  132. childSetAction("pay_btn", boost::bind(&LLPanelIMControlPanel::onPayButtonClicked, this));
  133. childSetAction("mute_btn", boost::bind(&LLPanelIMControlPanel::onClickMuteVolume, this));
  134. childSetAction("block_btn", boost::bind(&LLPanelIMControlPanel::onClickBlock, this));
  135. childSetAction("unblock_btn", boost::bind(&LLPanelIMControlPanel::onClickUnblock, this));
  136. getChild<LLUICtrl>("volume_slider")->setCommitCallback(boost::bind(&LLPanelIMControlPanel::onVolumeChange, this, _2));
  137. getChildView("add_friend_btn")->setEnabled(!LLAvatarActions::isFriend(getChild<LLAvatarIconCtrl>("avatar_icon")->getAvatarId()));
  138. setFocusReceivedCallback(boost::bind(&LLPanelIMControlPanel::onFocusReceived, this));
  139. return LLPanelChatControlPanel::postBuild();
  140. }
  141. void LLPanelIMControlPanel::draw()
  142. {
  143. bool is_muted = LLMuteList::getInstance()->isMuted(mAvatarID);
  144. getChild<LLUICtrl>("block_btn_panel")->setVisible(!is_muted);
  145. getChild<LLUICtrl>("unblock_btn_panel")->setVisible(is_muted);
  146. if (getChildView("volume_ctrl_panel")->getVisible())
  147. {
  148. bool is_muted_voice = LLMuteList::getInstance()->isMuted(mAvatarID, LLMute::flagVoiceChat);
  149. LLUICtrl* mute_btn = getChild<LLUICtrl>("mute_btn");
  150. mute_btn->setValue( is_muted_voice );
  151. LLUICtrl* volume_slider = getChild<LLUICtrl>("volume_slider");
  152. volume_slider->setEnabled( !is_muted_voice );
  153. F32 volume;
  154. if (is_muted_voice)
  155. {
  156. // it's clearer to display their volume as zero
  157. volume = 0.f;
  158. }
  159. else
  160. {
  161. // actual volume
  162. volume = LLVoiceClient::getInstance()->getUserVolume(mAvatarID);
  163. }
  164. volume_slider->setValue( (F64)volume );
  165. }
  166. LLPanelChatControlPanel::draw();
  167. }
  168. void LLPanelIMControlPanel::onClickMuteVolume()
  169. {
  170. // By convention, we only display and toggle voice mutes, not all mutes
  171. LLMuteList* mute_list = LLMuteList::getInstance();
  172. bool is_muted = mute_list->isMuted(mAvatarID, LLMute::flagVoiceChat);
  173. LLMute mute(mAvatarID, getChild<LLTextBox>("avatar_name")->getText(), LLMute::AGENT);
  174. if (!is_muted)
  175. {
  176. mute_list->add(mute, LLMute::flagVoiceChat);
  177. }
  178. else
  179. {
  180. mute_list->remove(mute, LLMute::flagVoiceChat);
  181. }
  182. }
  183. void LLPanelIMControlPanel::onClickBlock()
  184. {
  185. LLMute mute(mAvatarID, getChild<LLTextBox>("avatar_name")->getText(), LLMute::AGENT);
  186. LLMuteList::getInstance()->add(mute);
  187. }
  188. void LLPanelIMControlPanel::onClickUnblock()
  189. {
  190. LLMute mute(mAvatarID, getChild<LLTextBox>("avatar_name")->getText(), LLMute::AGENT);
  191. LLMuteList::getInstance()->remove(mute);
  192. }
  193. void LLPanelIMControlPanel::onVolumeChange(const LLSD& data)
  194. {
  195. F32 volume = (F32)data.asReal();
  196. LLVoiceClient::getInstance()->setUserVolume(mAvatarID, volume);
  197. }
  198. void LLPanelIMControlPanel::onTeleportButtonClicked()
  199. {
  200. LLAvatarActions::offerTeleport(mAvatarID);
  201. }
  202. void LLPanelIMControlPanel::onPayButtonClicked()
  203. {
  204. LLAvatarActions::pay(mAvatarID);
  205. }
  206. void LLPanelIMControlPanel::onViewProfileButtonClicked()
  207. {
  208. LLAvatarActions::showProfile(mAvatarID);
  209. }
  210. void LLPanelIMControlPanel::onAddFriendButtonClicked()
  211. {
  212. LLAvatarIconCtrl* avatar_icon = getChild<LLAvatarIconCtrl>("avatar_icon");
  213. std::string full_name = avatar_icon->getFullName();
  214. LLAvatarActions::requestFriendshipDialog(mAvatarID, full_name);
  215. }
  216. void LLPanelIMControlPanel::onShareButtonClicked()
  217. {
  218. LLAvatarActions::share(mAvatarID);
  219. }
  220. void LLPanelIMControlPanel::onFocusReceived()
  221. {
  222. // Disable all the buttons (Call, Teleport, etc) if disconnected.
  223. if (gDisconnected)
  224. {
  225. setAllChildrenEnabled(FALSE);
  226. }
  227. }
  228. void LLPanelIMControlPanel::setSessionId(const LLUUID& session_id)
  229. {
  230. LLPanelChatControlPanel::setSessionId(session_id);
  231. LLIMModel& im_model = LLIMModel::instance();
  232. LLAvatarTracker::instance().removeParticularFriendObserver(mAvatarID, this);
  233. mAvatarID = im_model.getOtherParticipantID(session_id);
  234. LLAvatarTracker::instance().addParticularFriendObserver(mAvatarID, this);
  235. // Disable "Add friend" button for friends.
  236. getChildView("add_friend_btn")->setEnabled(!LLAvatarActions::isFriend(mAvatarID));
  237. // Disable "Teleport" button if friend is offline
  238. if(LLAvatarActions::isFriend(mAvatarID))
  239. {
  240. getChildView("teleport_btn")->setEnabled(LLAvatarTracker::instance().isBuddyOnline(mAvatarID));
  241. }
  242. getChild<LLAvatarIconCtrl>("avatar_icon")->setValue(mAvatarID);
  243. // Disable most profile buttons if the participant is
  244. // not really an SL avatar (e.g., an Avaline caller).
  245. LLIMModel::LLIMSession* im_session =
  246. im_model.findIMSession(session_id);
  247. if( im_session && !im_session->mOtherParticipantIsAvatar )
  248. {
  249. getChildView("view_profile_btn")->setEnabled(FALSE);
  250. getChildView("add_friend_btn")->setEnabled(FALSE);
  251. getChildView("share_btn")->setEnabled(FALSE);
  252. getChildView("teleport_btn")->setEnabled(FALSE);
  253. getChildView("pay_btn")->setEnabled(FALSE);
  254. getChild<LLTextBox>("avatar_name")->setValue(im_session->mName);
  255. getChild<LLTextBox>("avatar_name")->setToolTip(im_session->mName);
  256. }
  257. else
  258. {
  259. // If the participant is an avatar, fetch the currect name
  260. gCacheName->get(mAvatarID, false,
  261. boost::bind(&LLPanelIMControlPanel::onNameCache, this, _1, _2, _3));
  262. }
  263. }
  264. //virtual
  265. void LLPanelIMControlPanel::changed(U32 mask)
  266. {
  267. getChildView("add_friend_btn")->setEnabled(!LLAvatarActions::isFriend(mAvatarID));
  268. // Disable "Teleport" button if friend is offline
  269. if(LLAvatarActions::isFriend(mAvatarID))
  270. {
  271. getChildView("teleport_btn")->setEnabled(LLAvatarTracker::instance().isBuddyOnline(mAvatarID));
  272. }
  273. }
  274. void LLPanelIMControlPanel::onNameCache(const LLUUID& id, const std::string& full_name, bool is_group)
  275. {
  276. if ( id == mAvatarID )
  277. {
  278. std::string avatar_name = full_name;
  279. getChild<LLTextBox>("avatar_name")->setValue(avatar_name);
  280. getChild<LLTextBox>("avatar_name")->setToolTip(avatar_name);
  281. bool is_linden = LLStringUtil::endsWith(full_name, " Linden");
  282. getChild<LLUICtrl>("mute_btn")->setEnabled( !is_linden);
  283. }
  284. }
  285. LLPanelGroupControlPanel::LLPanelGroupControlPanel(const LLUUID& session_id):
  286. mParticipantList(NULL)
  287. {
  288. }
  289. BOOL LLPanelGroupControlPanel::postBuild()
  290. {
  291. childSetAction("group_info_btn", boost::bind(&LLPanelGroupControlPanel::onGroupInfoButtonClicked, this));
  292. return LLPanelChatControlPanel::postBuild();
  293. }
  294. LLPanelGroupControlPanel::~LLPanelGroupControlPanel()
  295. {
  296. delete mParticipantList;
  297. mParticipantList = NULL;
  298. }
  299. // virtual
  300. void LLPanelGroupControlPanel::draw()
  301. {
  302. // Need to resort the participant list if it's in sort by recent speaker order.
  303. if (mParticipantList)
  304. mParticipantList->updateRecentSpeakersOrder();
  305. LLPanelChatControlPanel::draw();
  306. }
  307. void LLPanelGroupControlPanel::onGroupInfoButtonClicked()
  308. {
  309. LLGroupActions::show(mGroupID);
  310. }
  311. void LLPanelGroupControlPanel::onSortMenuItemClicked(const LLSD& userdata)
  312. {
  313. // TODO: Check this code when when sort order menu will be added. (EM)
  314. if (false && !mParticipantList)
  315. return;
  316. std::string chosen_item = userdata.asString();
  317. if (chosen_item == "sort_name")
  318. {
  319. mParticipantList->setSortOrder(LLParticipantList::E_SORT_BY_NAME);
  320. }
  321. }
  322. void LLPanelGroupControlPanel::onVoiceChannelStateChanged(const LLVoiceChannel::EState& old_state, const LLVoiceChannel::EState& new_state)
  323. {
  324. LLPanelChatControlPanel::onVoiceChannelStateChanged(old_state, new_state);
  325. mParticipantList->setSpeakingIndicatorsVisible(new_state >= LLVoiceChannel::STATE_CALL_STARTED);
  326. }
  327. void LLPanelGroupControlPanel::setSessionId(const LLUUID& session_id)
  328. {
  329. LLPanelChatControlPanel::setSessionId(session_id);
  330. mGroupID = session_id;
  331. // for group and Ad-hoc chat we need to include agent into list
  332. if(!mParticipantList)
  333. {
  334. LLSpeakerMgr* speaker_manager = LLIMModel::getInstance()->getSpeakerManager(session_id);
  335. mParticipantList = new LLParticipantList(speaker_manager, getChild<LLAvatarList>("speakers_list"), true,false);
  336. }
  337. }
  338. LLPanelAdHocControlPanel::LLPanelAdHocControlPanel(const LLUUID& session_id):LLPanelGroupControlPanel(session_id)
  339. {
  340. }
  341. BOOL LLPanelAdHocControlPanel::postBuild()
  342. {
  343. //We don't need LLPanelGroupControlPanel::postBuild() to be executed as there is no group_info_btn at AdHoc chat
  344. return LLPanelChatControlPanel::postBuild();
  345. }