llfloaterchatterbox.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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=viewergpl$
  8. *
  9. * Copyright (c) 2007-2009, Linden Research, Inc.
  10. *
  11. * Second Life Viewer Source Code
  12. * The source code in this file ("Source Code") is provided by Linden Lab
  13. * to you under the terms of the GNU General Public License, version 2.0
  14. * ("GPL"), unless you have obtained a separate licensing agreement
  15. * ("Other License"), formally executed by you and Linden Lab. Terms of
  16. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  17. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  18. *
  19. * There are special exceptions to the terms and conditions of the GPL as
  20. * it is applied to this Source Code. View the full text of the exception
  21. * in the file doc/FLOSS-exception.txt in this software distribution, or
  22. * online at
  23. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  24. *
  25. * By copying, modifying or distributing this software, you acknowledge
  26. * that you have read and understood your obligations described above,
  27. * and agree to abide by those obligations.
  28. *
  29. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  30. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  31. * COMPLETENESS OR PERFORMANCE.
  32. * $/LicenseInfo$
  33. */
  34. #include "llviewerprecompiledheaders.h"
  35. #include "llfloaterchatterbox.h"
  36. #include "lluictrlfactory.h"
  37. #include "llfloaterchat.h"
  38. #include "llfloaterfriends.h"
  39. #include "llfloatergroups.h"
  40. #include "llfloaterim.h"
  41. #include "llfloaternewim.h"
  42. #include "llimmgr.h"
  43. #include "llviewercontrol.h"
  44. #include "llvoicechannel.h"
  45. // Visibility policy for LLUISingleton
  46. //static
  47. bool LLFloaterChatterBox::visible(LLFloater* instance, const LLSD& key)
  48. {
  49. LLFloater* floater_to_check;
  50. floater_to_check = ((LLFloaterChatterBox*)instance)->getFloater(key);
  51. if (floater_to_check)
  52. {
  53. return floater_to_check->isInVisibleChain();
  54. }
  55. // otherwise use default visibility rule for chatterbox
  56. return VisibilityPolicy<LLFloater>::visible(instance, key);
  57. }
  58. //static
  59. void LLFloaterChatterBox::show(LLFloater* instance, const LLSD& key)
  60. {
  61. LLFloater* floater_to_show = ((LLFloaterChatterBox*)instance)->getFloater(key);
  62. VisibilityPolicy<LLFloater>::show(instance, key);
  63. if (floater_to_show)
  64. {
  65. floater_to_show->open();
  66. }
  67. }
  68. //static
  69. void LLFloaterChatterBox::hide(LLFloater* instance, const LLSD& key)
  70. {
  71. VisibilityPolicy<LLFloater>::hide(instance, key);
  72. }
  73. LLFloater* LLFloaterChatterBox::getFloater(const LLSD& key)
  74. {
  75. LLFloater* floater = NULL;
  76. // Try to show requested session
  77. LLUUID session_id = key.asUUID();
  78. if (session_id.notNull())
  79. {
  80. floater = LLFloaterIMSession::findInstance(session_id);
  81. }
  82. // If true, show tab for active voice channel, otherwise, just show last
  83. // tab
  84. if (key.asBoolean())
  85. {
  86. floater = getCurrentVoiceFloater();
  87. }
  88. return floater;
  89. }
  90. LLFloaterChatterBox::LLFloaterChatterBox(const LLSD& seed)
  91. : mActiveVoiceFloater(NULL),
  92. mFirstOpen(true)
  93. {
  94. mAutoResize = false;
  95. if (gSavedSettings.getBool("IMTabsVerticalStacking"))
  96. {
  97. LLUICtrlFactory::getInstance()->buildFloater(this,
  98. "floater_chatterbox2.xml",
  99. NULL, false);
  100. }
  101. else
  102. {
  103. LLUICtrlFactory::getInstance()->buildFloater(this,
  104. "floater_chatterbox.xml",
  105. NULL, false);
  106. }
  107. addFloater(mFloaterNewIM = new LLFloaterNewIM(), false);
  108. if (gSavedSettings.getBool("ChatHistoryTornOff"))
  109. {
  110. LLFloaterChat* floater_chat = LLFloaterChat::getInstance();
  111. // Add then remove to set up relationship for re-attach
  112. addFloater(floater_chat, false);
  113. removeFloater(floater_chat);
  114. // Reparent to floater view
  115. gFloaterViewp->addChild(floater_chat);
  116. }
  117. else
  118. {
  119. addFloater(LLFloaterChat::getInstance(LLSD()), false);
  120. }
  121. mTabContainer->lockTabs();
  122. }
  123. bool LLFloaterChatterBox::handleKeyHere(KEY key, MASK mask)
  124. {
  125. if (key == 'W' && mask == MASK_CONTROL)
  126. {
  127. LLFloater* floater = getActiveFloater();
  128. // Is user closeable and is system closeable
  129. if (floater && floater->canClose())
  130. {
  131. if (floater->isCloseable())
  132. {
  133. floater->close();
  134. }
  135. else
  136. {
  137. // Close chatterbox window if frontmost tab is reserved,
  138. // non-closeable tab such as contacts or near me
  139. close();
  140. }
  141. }
  142. return true;
  143. }
  144. return LLMultiFloater::handleKeyHere(key, mask);
  145. }
  146. void LLFloaterChatterBox::draw()
  147. {
  148. // Clear new im notifications when chatterbox is visible
  149. if (!isMinimized() && gIMMgrp)
  150. {
  151. gIMMgrp->clearNewIMNotification();
  152. }
  153. LLFloater* current_active_floater = getCurrentVoiceFloater();
  154. // Set icon on tab for floater currently associated with active voice
  155. // channel
  156. if (mActiveVoiceFloater != current_active_floater)
  157. {
  158. // remove image from old floater's tab
  159. if (mActiveVoiceFloater)
  160. {
  161. mTabContainer->setTabImage(mActiveVoiceFloater, "");
  162. }
  163. }
  164. // Update image on current active tab
  165. if (current_active_floater)
  166. {
  167. LLColor4 icon_color = LLColor4::white;
  168. LLVoiceChannel* channelp = LLVoiceChannel::getCurrentVoiceChannel();
  169. if (channelp)
  170. {
  171. if (channelp->isActive())
  172. {
  173. icon_color = LLColor4::green;
  174. }
  175. else if (channelp->getState() == LLVoiceChannel::STATE_ERROR)
  176. {
  177. icon_color = LLColor4::red;
  178. }
  179. else // active, but not connected
  180. {
  181. icon_color = LLColor4::yellow;
  182. }
  183. }
  184. mTabContainer->setTabImage(current_active_floater,
  185. "active_voice_tab.tga", icon_color);
  186. }
  187. mActiveVoiceFloater = current_active_floater;
  188. LLMultiFloater::draw();
  189. }
  190. void LLFloaterChatterBox::onOpen()
  191. {
  192. gSavedSettings.setBool("ShowCommunicate", true);
  193. if (mFirstOpen)
  194. {
  195. mFirstOpen = false;
  196. // Reposition floater from saved settings
  197. LLRect rect = gSavedSettings.getRect("ChatterboxRect");
  198. reshape(rect.getWidth(), rect.getHeight(), false);
  199. setRect(rect);
  200. }
  201. // Force a refresh to get latest display names in the new IM panel.
  202. gAvatarTracker.dirtyBuddies();
  203. }
  204. void LLFloaterChatterBox::onClose(bool app_quitting)
  205. {
  206. setVisible(false);
  207. gSavedSettings.setBool("ShowCommunicate", false);
  208. }
  209. void LLFloaterChatterBox::setMinimized(bool minimized)
  210. {
  211. LLFloater::setMinimized(minimized);
  212. // *HACK: potentially need to toggle console
  213. LLFloaterChat::getInstance()->updateConsoleVisibility();
  214. }
  215. void LLFloaterChatterBox::removeFloater(LLFloater* floaterp)
  216. {
  217. // Only my friends floater now locked
  218. mTabContainer->lockTabs(mTabContainer->getNumLockedTabs() - 1);
  219. if (floaterp->getName() == gChatFloaterName)
  220. {
  221. gSavedSettings.setBool("ChatHistoryTornOff", true);
  222. }
  223. floaterp->setCanClose(true);
  224. LLMultiFloater::removeFloater(floaterp);
  225. }
  226. void LLFloaterChatterBox::addFloater(LLFloater* floaterp,
  227. bool select_added_floater,
  228. LLTabContainer::eInsertionPoint insertion_point)
  229. {
  230. S32 num_locked_tabs = mTabContainer->getNumLockedTabs();
  231. // Already here
  232. if (floaterp->getHost() == this) return;
  233. // Make sure chat history is locked when re-attaching it
  234. if (floaterp->getName() == gChatFloaterName)
  235. {
  236. mTabContainer->unlockTabs();
  237. // Add chat history as second tab if contact window is present, first
  238. // tab otherwise
  239. LLMultiFloater::addFloater(floaterp, select_added_floater,
  240. LLTabContainer::START);
  241. // Make sure first two tabs are now locked
  242. mTabContainer->lockTabs(num_locked_tabs + 1);
  243. gSavedSettings.setBool("ChatHistoryTornOff", false);
  244. floaterp->setCanClose(false);
  245. }
  246. else
  247. {
  248. LLMultiFloater::addFloater(floaterp, select_added_floater,
  249. insertion_point);
  250. }
  251. // Make sure active voice icon shows up for new tab
  252. if (floaterp == mActiveVoiceFloater)
  253. {
  254. mTabContainer->setTabImage(floaterp, "active_voice_tab.tga");
  255. }
  256. }
  257. //static
  258. LLFloater* LLFloaterChatterBox::getCurrentVoiceFloater()
  259. {
  260. if (!LLVoiceClient::voiceEnabled())
  261. {
  262. return NULL;
  263. }
  264. LLVoiceChannel* cur_voicep = LLVoiceChannel::getCurrentVoiceChannel();
  265. if (LLVoiceChannelProximal::getInstance() == cur_voicep)
  266. {
  267. // Show near me tab if in proximal channel
  268. return LLFloaterChat::getInstance(LLSD());
  269. }
  270. LLFloaterChatterBox* floater = LLFloaterChatterBox::getInstance(LLSD());
  271. // Iterate over all IM tabs
  272. for (S32 i = 0; i < floater->getFloaterCount(); i++)
  273. {
  274. LLPanel* panelp = floater->mTabContainer->getPanelByIndex(i);
  275. if (panelp->getName() == gIMFloaterName)
  276. {
  277. // Only LLFloaterIMSessions are called gIMFloaterName
  278. LLFloaterIMSession* im_floaterp = (LLFloaterIMSession*)panelp;
  279. if (im_floaterp->getVoiceChannel() == cur_voicep)
  280. {
  281. return im_floaterp;
  282. }
  283. }
  284. }
  285. return NULL;
  286. }