PageRenderTime 34ms CodeModel.GetById 1ms app.highlight 28ms RepoModel.GetById 1ms 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
  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
 29
 30#include "llviewerprecompiledheaders.h"
 31
 32#include "llfloaterreg.h"
 33#include "llfloaterchatterbox.h"
 34#include "lluictrlfactory.h"
 35#include "llfloaterfriends.h"
 36#include "llfloatergroups.h"
 37#include "llviewercontrol.h"
 38#include "llvoicechannel.h"
 39#include "llimpanel.h"
 40#include "llimview.h"
 41
 42//
 43// LLFloaterMyFriends
 44//
 45
 46LLFloaterMyFriends::LLFloaterMyFriends(const LLSD& seed)
 47	: LLFloater(seed)
 48{
 49	mFactoryMap["friends_panel"] = LLCallbackMap(LLFloaterMyFriends::createFriendsPanel, NULL);
 50	mFactoryMap["groups_panel"] = LLCallbackMap(LLFloaterMyFriends::createGroupsPanel, NULL);
 51	//Called from floater reg: LLUICtrlFactory::getInstance()->buildFloater(this, "floater_my_friends.xml");
 52}
 53
 54LLFloaterMyFriends::~LLFloaterMyFriends()
 55{
 56}
 57
 58BOOL LLFloaterMyFriends::postBuild()
 59{
 60	return TRUE;
 61}
 62
 63void LLFloaterMyFriends::onOpen(const LLSD& key)
 64{
 65	if (key.asString() == "friends")
 66	{
 67		childShowTab("friends_and_groups", "friends_panel");
 68	}
 69	else if (key.asString() == "groups")
 70	{
 71		childShowTab("friends_and_groups", "groups_panel");
 72	}
 73}
 74
 75//static
 76void* LLFloaterMyFriends::createFriendsPanel(void* data)
 77{
 78	return new LLPanelFriends();
 79}
 80
 81//static
 82void* LLFloaterMyFriends::createGroupsPanel(void* data)
 83{
 84	return new LLPanelGroups();
 85}
 86
 87//static
 88LLFloaterMyFriends* LLFloaterMyFriends::getInstance()
 89{
 90	return LLFloaterReg::getTypedInstance<LLFloaterMyFriends>("contacts", "friends") ;
 91}
 92
 93//
 94// LLFloaterChatterBox
 95//
 96LLFloaterChatterBox::LLFloaterChatterBox(const LLSD& seed)
 97:	LLMultiFloater(seed),
 98	mActiveVoiceFloater(NULL)
 99{
100	mAutoResize = FALSE;
101
102	//Called from floater reg: LLUICtrlFactory::getInstance()->buildFloater(this, "floater_chatterbox.xml", FALSE);
103}
104
105LLFloaterChatterBox::~LLFloaterChatterBox()
106{
107}
108
109BOOL LLFloaterChatterBox::postBuild()
110{
111	setVisibleCallback(boost::bind(&LLFloaterChatterBox::onVisibilityChange, this, _2));
112	
113	if (gSavedSettings.getBOOL("ContactsTornOff"))
114	{
115		LLFloaterMyFriends* floater_contacts = LLFloaterMyFriends::getInstance();
116		if(floater_contacts)
117		{
118			// add then remove to set up relationship for re-attach
119			addFloater(floater_contacts, FALSE);
120			removeFloater(floater_contacts);
121			// reparent to floater view
122			gFloaterView->addChild(floater_contacts);
123		}
124	}
125	else
126	{
127		addFloater(LLFloaterMyFriends::getInstance(), TRUE);
128	}
129
130	mTabContainer->lockTabs();
131	return TRUE;
132}
133
134BOOL LLFloaterChatterBox::handleKeyHere(KEY key, MASK mask)
135{
136	if (key == 'W' && mask == MASK_CONTROL)
137	{
138		LLFloater* floater = getActiveFloater();
139		// is user closeable and is system closeable
140		if (floater && floater->canClose())
141		{
142			if (floater->isCloseable())
143			{
144				floater->closeFloater();
145			}
146			else
147			{
148				// close chatterbox window if frontmost tab is reserved, non-closeable tab
149				// such as contacts or near me
150				closeFloater();
151			}
152		}
153		return TRUE;
154	}
155
156	return LLMultiFloater::handleKeyHere(key, mask);
157}
158
159void LLFloaterChatterBox::draw()
160{
161	// clear new im notifications when chatterbox is visible
162	if (!isMinimized()) 
163	{
164		gIMMgr->clearNewIMNotification();
165	}
166	LLFloater* current_active_floater = getCurrentVoiceFloater();
167	// set icon on tab for floater currently associated with active voice channel
168	if(mActiveVoiceFloater != current_active_floater)
169	{
170		// remove image from old floater's tab
171		if (mActiveVoiceFloater)
172		{
173			mTabContainer->setTabImage(mActiveVoiceFloater, "");
174		}
175	}
176
177	// update image on current active tab
178	if (current_active_floater)
179	{
180		LLColor4 icon_color = LLColor4::white;
181		LLVoiceChannel* channelp = LLVoiceChannel::getCurrentVoiceChannel();
182		if (channelp)
183		{
184			if (channelp->isActive())
185			{
186				icon_color = LLColor4::green;
187			}
188			else if (channelp->getState() == LLVoiceChannel::STATE_ERROR)
189			{
190				icon_color = LLColor4::red;
191			}
192			else // active, but not connected
193			{
194				icon_color = LLColor4::yellow;
195			}
196		}
197		mTabContainer->setTabImage(current_active_floater, "active_voice_tab.tga", icon_color);
198	}
199
200	mActiveVoiceFloater = current_active_floater;
201
202	LLMultiFloater::draw();
203}
204
205void LLFloaterChatterBox::onOpen(const LLSD& key)
206{
207	//*TODO:Skinning show the session id associated with key
208	if (key.asString() == "local")
209	{
210	}
211	else if (key.isDefined())
212	{
213		/*LLFloaterIMPanel* impanel = gIMMgr->findFloaterBySession(key.asUUID());
214		if (impanel)
215		{
216			impanel->openFloater();
217		}*/
218	}
219}
220
221void LLFloaterChatterBox::onVisibilityChange ( const LLSD& new_visibility )
222{
223}
224
225void LLFloaterChatterBox::removeFloater(LLFloater* floaterp)
226{
227	if(!floaterp) return;
228		
229	if (floaterp->getName() == "chat floater")
230	{
231		// only my friends floater now locked
232		mTabContainer->lockTabs(mTabContainer->getNumLockedTabs() - 1);
233		gSavedSettings.setBOOL("ChatHistoryTornOff", TRUE);
234		floaterp->setCanClose(TRUE);
235	}
236	else if (floaterp->getName() == "floater_my_friends")
237	{
238		// only chat floater now locked
239		mTabContainer->lockTabs(mTabContainer->getNumLockedTabs() - 1);
240		gSavedSettings.setBOOL("ContactsTornOff", TRUE);
241		floaterp->setCanClose(TRUE);
242	}
243	LLMultiFloater::removeFloater(floaterp);
244}
245
246void LLFloaterChatterBox::addFloater(LLFloater* floaterp, 
247									BOOL select_added_floater, 
248									LLTabContainer::eInsertionPoint insertion_point)
249{
250	if(!floaterp) return;
251	
252	S32 num_locked_tabs = mTabContainer->getNumLockedTabs();
253
254	// already here
255	if (floaterp->getHost() == this)
256	{
257		openFloater(floaterp->getKey());
258		return;
259	}
260
261	// make sure my friends and chat history both locked when re-attaching chat history
262	if (floaterp->getName() == "chat floater")
263	{
264		mTabContainer->unlockTabs();
265		// add chat history as second tab if contact window is present, first tab otherwise
266		if (getChildView("floater_my_friends"))
267		{
268			// assuming contacts window is first tab, select it
269			mTabContainer->selectFirstTab();
270			// and add ourselves after
271			LLMultiFloater::addFloater(floaterp, select_added_floater, LLTabContainer::RIGHT_OF_CURRENT);
272		}
273		else
274		{
275			LLMultiFloater::addFloater(floaterp, select_added_floater, LLTabContainer::START);
276		}
277		
278		// make sure first two tabs are now locked
279		mTabContainer->lockTabs(num_locked_tabs + 1);
280		gSavedSettings.setBOOL("ChatHistoryTornOff", FALSE);
281		floaterp->setCanClose(FALSE);
282	}
283	else if (floaterp->getName() == "floater_my_friends")
284	{
285		mTabContainer->unlockTabs();
286		// add contacts window as first tab
287		LLMultiFloater::addFloater(floaterp, select_added_floater, LLTabContainer::START);
288		// make sure first two tabs are now locked
289		mTabContainer->lockTabs(num_locked_tabs + 1);
290		gSavedSettings.setBOOL("ContactsTornOff", FALSE);
291		floaterp->setCanClose(FALSE);
292	}
293	else
294	{
295		LLMultiFloater::addFloater(floaterp, select_added_floater, insertion_point);
296		// openFloater(floaterp->getKey());
297	}
298
299	// make sure active voice icon shows up for new tab
300	if (floaterp == mActiveVoiceFloater)
301	{
302		mTabContainer->setTabImage(floaterp, "active_voice_tab.tga");	
303	}
304}
305
306//static
307LLFloaterChatterBox* LLFloaterChatterBox::getInstance()
308{
309	return LLFloaterReg::getTypedInstance<LLFloaterChatterBox>("communicate", LLSD()) ; 
310}
311
312//static 
313LLFloater* LLFloaterChatterBox::getCurrentVoiceFloater()
314{
315	if (!LLVoiceClient::getInstance()->voiceEnabled())
316	{
317		return NULL;
318	}
319	if (LLVoiceChannelProximal::getInstance() == LLVoiceChannel::getCurrentVoiceChannel())
320	{
321		return NULL;
322	}
323	else
324	{
325		LLFloaterChatterBox* floater = LLFloaterChatterBox::getInstance();
326		if(!floater) return NULL;
327		// iterator over all IM tabs (skip friends and near me)
328		for (S32 i = 0; i < floater->getFloaterCount(); i++)
329		{
330			LLPanel* panelp = floater->mTabContainer->getPanelByIndex(i);
331			if (panelp->getName() == "im_floater")
332			{
333				// only LLFloaterIMPanels are called "im_floater"
334				LLFloaterIMPanel* im_floaterp = (LLFloaterIMPanel*)panelp;
335				LLVoiceChannel* voice_channel = LLIMModel::getInstance()->getVoiceChannel(im_floaterp->getSessionID());
336				if (voice_channel  == LLVoiceChannel::getCurrentVoiceChannel())
337				{
338					return im_floaterp;
339				}
340			}
341		}
342	}
343	return NULL;
344}