PageRenderTime 1051ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llfloaterchatterbox.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 344 lines | 240 code | 35 blank | 69 comment | 55 complexity | 6dcb33a3bcd6de7abbb7f95fdc739047 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfloaterchatterbox.cpp
  3. * @author Richard
  4. * @date 2007-05-08
  5. * @brief Implementation of the chatterbox integrated conversation ui
  6. *
  7. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. #include "llviewerprecompiledheaders.h"
  29. #include "llfloaterreg.h"
  30. #include "llfloaterchatterbox.h"
  31. #include "lluictrlfactory.h"
  32. #include "llfloaterfriends.h"
  33. #include "llfloatergroups.h"
  34. #include "llviewercontrol.h"
  35. #include "llvoicechannel.h"
  36. #include "llimpanel.h"
  37. #include "llimview.h"
  38. //
  39. // LLFloaterMyFriends
  40. //
  41. LLFloaterMyFriends::LLFloaterMyFriends(const LLSD& seed)
  42. : LLFloater(seed)
  43. {
  44. mFactoryMap["friends_panel"] = LLCallbackMap(LLFloaterMyFriends::createFriendsPanel, NULL);
  45. mFactoryMap["groups_panel"] = LLCallbackMap(LLFloaterMyFriends::createGroupsPanel, NULL);
  46. //Called from floater reg: LLUICtrlFactory::getInstance()->buildFloater(this, "floater_my_friends.xml");
  47. }
  48. LLFloaterMyFriends::~LLFloaterMyFriends()
  49. {
  50. }
  51. BOOL LLFloaterMyFriends::postBuild()
  52. {
  53. return TRUE;
  54. }
  55. void LLFloaterMyFriends::onOpen(const LLSD& key)
  56. {
  57. if (key.asString() == "friends")
  58. {
  59. childShowTab("friends_and_groups", "friends_panel");
  60. }
  61. else if (key.asString() == "groups")
  62. {
  63. childShowTab("friends_and_groups", "groups_panel");
  64. }
  65. }
  66. //static
  67. void* LLFloaterMyFriends::createFriendsPanel(void* data)
  68. {
  69. return new LLPanelFriends();
  70. }
  71. //static
  72. void* LLFloaterMyFriends::createGroupsPanel(void* data)
  73. {
  74. return new LLPanelGroups();
  75. }
  76. //static
  77. LLFloaterMyFriends* LLFloaterMyFriends::getInstance()
  78. {
  79. return LLFloaterReg::getTypedInstance<LLFloaterMyFriends>("contacts", "friends") ;
  80. }
  81. //
  82. // LLFloaterChatterBox
  83. //
  84. LLFloaterChatterBox::LLFloaterChatterBox(const LLSD& seed)
  85. : LLMultiFloater(seed),
  86. mActiveVoiceFloater(NULL)
  87. {
  88. mAutoResize = FALSE;
  89. //Called from floater reg: LLUICtrlFactory::getInstance()->buildFloater(this, "floater_chatterbox.xml", FALSE);
  90. }
  91. LLFloaterChatterBox::~LLFloaterChatterBox()
  92. {
  93. }
  94. BOOL LLFloaterChatterBox::postBuild()
  95. {
  96. setVisibleCallback(boost::bind(&LLFloaterChatterBox::onVisibilityChange, this, _2));
  97. if (gSavedSettings.getBOOL("ContactsTornOff"))
  98. {
  99. LLFloaterMyFriends* floater_contacts = LLFloaterMyFriends::getInstance();
  100. if(floater_contacts)
  101. {
  102. // add then remove to set up relationship for re-attach
  103. addFloater(floater_contacts, FALSE);
  104. removeFloater(floater_contacts);
  105. // reparent to floater view
  106. gFloaterView->addChild(floater_contacts);
  107. }
  108. }
  109. else
  110. {
  111. addFloater(LLFloaterMyFriends::getInstance(), TRUE);
  112. }
  113. mTabContainer->lockTabs();
  114. return TRUE;
  115. }
  116. BOOL LLFloaterChatterBox::handleKeyHere(KEY key, MASK mask)
  117. {
  118. if (key == 'W' && mask == MASK_CONTROL)
  119. {
  120. LLFloater* floater = getActiveFloater();
  121. // is user closeable and is system closeable
  122. if (floater && floater->canClose())
  123. {
  124. if (floater->isCloseable())
  125. {
  126. floater->closeFloater();
  127. }
  128. else
  129. {
  130. // close chatterbox window if frontmost tab is reserved, non-closeable tab
  131. // such as contacts or near me
  132. closeFloater();
  133. }
  134. }
  135. return TRUE;
  136. }
  137. return LLMultiFloater::handleKeyHere(key, mask);
  138. }
  139. void LLFloaterChatterBox::draw()
  140. {
  141. // clear new im notifications when chatterbox is visible
  142. if (!isMinimized())
  143. {
  144. gIMMgr->clearNewIMNotification();
  145. }
  146. LLFloater* current_active_floater = getCurrentVoiceFloater();
  147. // set icon on tab for floater currently associated with active voice channel
  148. if(mActiveVoiceFloater != current_active_floater)
  149. {
  150. // remove image from old floater's tab
  151. if (mActiveVoiceFloater)
  152. {
  153. mTabContainer->setTabImage(mActiveVoiceFloater, "");
  154. }
  155. }
  156. // update image on current active tab
  157. if (current_active_floater)
  158. {
  159. LLColor4 icon_color = LLColor4::white;
  160. LLVoiceChannel* channelp = LLVoiceChannel::getCurrentVoiceChannel();
  161. if (channelp)
  162. {
  163. if (channelp->isActive())
  164. {
  165. icon_color = LLColor4::green;
  166. }
  167. else if (channelp->getState() == LLVoiceChannel::STATE_ERROR)
  168. {
  169. icon_color = LLColor4::red;
  170. }
  171. else // active, but not connected
  172. {
  173. icon_color = LLColor4::yellow;
  174. }
  175. }
  176. mTabContainer->setTabImage(current_active_floater, "active_voice_tab.tga", icon_color);
  177. }
  178. mActiveVoiceFloater = current_active_floater;
  179. LLMultiFloater::draw();
  180. }
  181. void LLFloaterChatterBox::onOpen(const LLSD& key)
  182. {
  183. //*TODO:Skinning show the session id associated with key
  184. if (key.asString() == "local")
  185. {
  186. }
  187. else if (key.isDefined())
  188. {
  189. /*LLFloaterIMPanel* impanel = gIMMgr->findFloaterBySession(key.asUUID());
  190. if (impanel)
  191. {
  192. impanel->openFloater();
  193. }*/
  194. }
  195. }
  196. void LLFloaterChatterBox::onVisibilityChange ( const LLSD& new_visibility )
  197. {
  198. }
  199. void LLFloaterChatterBox::removeFloater(LLFloater* floaterp)
  200. {
  201. if(!floaterp) return;
  202. if (floaterp->getName() == "chat floater")
  203. {
  204. // only my friends floater now locked
  205. mTabContainer->lockTabs(mTabContainer->getNumLockedTabs() - 1);
  206. gSavedSettings.setBOOL("ChatHistoryTornOff", TRUE);
  207. floaterp->setCanClose(TRUE);
  208. }
  209. else if (floaterp->getName() == "floater_my_friends")
  210. {
  211. // only chat floater now locked
  212. mTabContainer->lockTabs(mTabContainer->getNumLockedTabs() - 1);
  213. gSavedSettings.setBOOL("ContactsTornOff", TRUE);
  214. floaterp->setCanClose(TRUE);
  215. }
  216. LLMultiFloater::removeFloater(floaterp);
  217. }
  218. void LLFloaterChatterBox::addFloater(LLFloater* floaterp,
  219. BOOL select_added_floater,
  220. LLTabContainer::eInsertionPoint insertion_point)
  221. {
  222. if(!floaterp) return;
  223. S32 num_locked_tabs = mTabContainer->getNumLockedTabs();
  224. // already here
  225. if (floaterp->getHost() == this)
  226. {
  227. openFloater(floaterp->getKey());
  228. return;
  229. }
  230. // make sure my friends and chat history both locked when re-attaching chat history
  231. if (floaterp->getName() == "chat floater")
  232. {
  233. mTabContainer->unlockTabs();
  234. // add chat history as second tab if contact window is present, first tab otherwise
  235. if (getChildView("floater_my_friends"))
  236. {
  237. // assuming contacts window is first tab, select it
  238. mTabContainer->selectFirstTab();
  239. // and add ourselves after
  240. LLMultiFloater::addFloater(floaterp, select_added_floater, LLTabContainer::RIGHT_OF_CURRENT);
  241. }
  242. else
  243. {
  244. LLMultiFloater::addFloater(floaterp, select_added_floater, LLTabContainer::START);
  245. }
  246. // make sure first two tabs are now locked
  247. mTabContainer->lockTabs(num_locked_tabs + 1);
  248. gSavedSettings.setBOOL("ChatHistoryTornOff", FALSE);
  249. floaterp->setCanClose(FALSE);
  250. }
  251. else if (floaterp->getName() == "floater_my_friends")
  252. {
  253. mTabContainer->unlockTabs();
  254. // add contacts window as first tab
  255. LLMultiFloater::addFloater(floaterp, select_added_floater, LLTabContainer::START);
  256. // make sure first two tabs are now locked
  257. mTabContainer->lockTabs(num_locked_tabs + 1);
  258. gSavedSettings.setBOOL("ContactsTornOff", FALSE);
  259. floaterp->setCanClose(FALSE);
  260. }
  261. else
  262. {
  263. LLMultiFloater::addFloater(floaterp, select_added_floater, insertion_point);
  264. // openFloater(floaterp->getKey());
  265. }
  266. // make sure active voice icon shows up for new tab
  267. if (floaterp == mActiveVoiceFloater)
  268. {
  269. mTabContainer->setTabImage(floaterp, "active_voice_tab.tga");
  270. }
  271. }
  272. //static
  273. LLFloaterChatterBox* LLFloaterChatterBox::getInstance()
  274. {
  275. return LLFloaterReg::getTypedInstance<LLFloaterChatterBox>("communicate", LLSD()) ;
  276. }
  277. //static
  278. LLFloater* LLFloaterChatterBox::getCurrentVoiceFloater()
  279. {
  280. if (!LLVoiceClient::getInstance()->voiceEnabled())
  281. {
  282. return NULL;
  283. }
  284. if (LLVoiceChannelProximal::getInstance() == LLVoiceChannel::getCurrentVoiceChannel())
  285. {
  286. return NULL;
  287. }
  288. else
  289. {
  290. LLFloaterChatterBox* floater = LLFloaterChatterBox::getInstance();
  291. if(!floater) return NULL;
  292. // iterator over all IM tabs (skip friends and near me)
  293. for (S32 i = 0; i < floater->getFloaterCount(); i++)
  294. {
  295. LLPanel* panelp = floater->mTabContainer->getPanelByIndex(i);
  296. if (panelp->getName() == "im_floater")
  297. {
  298. // only LLFloaterIMPanels are called "im_floater"
  299. LLFloaterIMPanel* im_floaterp = (LLFloaterIMPanel*)panelp;
  300. LLVoiceChannel* voice_channel = LLIMModel::getInstance()->getVoiceChannel(im_floaterp->getSessionID());
  301. if (voice_channel == LLVoiceChannel::getCurrentVoiceChannel())
  302. {
  303. return im_floaterp;
  304. }
  305. }
  306. }
  307. }
  308. return NULL;
  309. }