PageRenderTime 65ms CodeModel.GetById 28ms app.highlight 31ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llchannelmanager.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 254 lines | 167 code | 44 blank | 43 comment | 26 complexity | 71adfcf7a98a819ac500b5e5f7da9a90 MD5 | raw file
  1/** 
  2 * @file llchannelmanager.cpp
  3 * @brief This class rules screen notification channels.
  4 *
  5 * $LicenseInfo:firstyear=2000&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
 27#include "llviewerprecompiledheaders.h" // must be first include
 28
 29#include "llchannelmanager.h"
 30
 31#include "llappviewer.h"
 32#include "llnotificationstorage.h"
 33#include "llviewercontrol.h"
 34#include "llviewerwindow.h"
 35#include "llrootview.h"
 36#include "llsyswellwindow.h"
 37#include "llfloaterreg.h"
 38
 39#include <algorithm>
 40
 41using namespace LLNotificationsUI;
 42
 43//--------------------------------------------------------------------------
 44LLChannelManager::LLChannelManager()
 45{
 46	LLAppViewer::instance()->setOnLoginCompletedCallback(boost::bind(&LLChannelManager::onLoginCompleted, this));
 47	mChannelList.clear();
 48	mStartUpChannel = NULL;
 49	
 50	if(!gViewerWindow)
 51	{
 52		llerrs << "LLChannelManager::LLChannelManager() - viwer window is not initialized yet" << llendl;
 53	}
 54}
 55
 56//--------------------------------------------------------------------------
 57LLChannelManager::~LLChannelManager()
 58{
 59	for(std::vector<ChannelElem>::iterator it = mChannelList.begin(); it !=  mChannelList.end(); ++it)
 60	{
 61		LLScreenChannelBase* channel = it->channel.get();
 62		if (!channel) continue;
 63
 64		delete channel;
 65	}
 66
 67	mChannelList.clear();
 68}
 69
 70//--------------------------------------------------------------------------
 71LLScreenChannel* LLChannelManager::createNotificationChannel()
 72{
 73	//  creating params for a channel
 74	LLScreenChannelBase::Params p;
 75	p.id = LLUUID(gSavedSettings.getString("NotificationChannelUUID"));
 76	p.channel_align = CA_RIGHT;
 77	p.toast_align = NA_TOP;
 78
 79	// Getting a Channel for our notifications
 80	return dynamic_cast<LLScreenChannel*> (LLChannelManager::getInstance()->getChannel(p));
 81}
 82
 83//--------------------------------------------------------------------------
 84void LLChannelManager::onLoginCompleted()
 85{
 86	S32 away_notifications = 0;
 87
 88	// calc a number of all offline notifications
 89	for(std::vector<ChannelElem>::iterator it = mChannelList.begin(); it !=  mChannelList.end(); ++it)
 90	{
 91		LLScreenChannelBase* channel = it->channel.get();
 92		if (!channel) continue;
 93
 94		// don't calc notifications for Nearby Chat
 95		if(channel->getChannelID() == LLUUID(gSavedSettings.getString("NearByChatChannelUUID")))
 96		{
 97			continue;
 98		}
 99
100		// don't calc notifications for channels that always show their notifications
101		if(!channel->getDisplayToastsAlways())
102		{
103			away_notifications +=channel->getNumberOfHiddenToasts();
104		}
105	}
106
107	away_notifications += gIMMgr->getNumberOfUnreadIM();
108
109	if(!away_notifications)
110	{
111		onStartUpToastClose();
112	}
113	else
114	{
115		// create a channel for the StartUp Toast
116		LLScreenChannelBase::Params p;
117		p.id = LLUUID(gSavedSettings.getString("StartUpChannelUUID"));
118		p.channel_align = CA_RIGHT;
119		mStartUpChannel = createChannel(p);
120
121		if(!mStartUpChannel)
122		{
123			onStartUpToastClose();
124		}
125		else
126		{
127			gViewerWindow->getRootView()->addChild(mStartUpChannel);
128
129			// init channel's position and size
130			S32 channel_right_bound = gViewerWindow->getWorldViewRectScaled().mRight - gSavedSettings.getS32("NotificationChannelRightMargin"); 
131			S32 channel_width = gSavedSettings.getS32("NotifyBoxWidth");
132			mStartUpChannel->init(channel_right_bound - channel_width, channel_right_bound);
133			mStartUpChannel->setMouseDownCallback(boost::bind(&LLNotificationWellWindow::onStartUpToastClick, LLNotificationWellWindow::getInstance(), _2, _3, _4));
134
135			mStartUpChannel->setCommitCallback(boost::bind(&LLChannelManager::onStartUpToastClose, this));
136			mStartUpChannel->createStartUpToast(away_notifications, gSavedSettings.getS32("StartUpToastLifeTime"));
137		}
138	}
139
140	LLPersistentNotificationStorage::getInstance()->loadNotifications();
141}
142
143//--------------------------------------------------------------------------
144void LLChannelManager::onStartUpToastClose()
145{
146	if(mStartUpChannel)
147	{
148		mStartUpChannel->setVisible(FALSE);
149		mStartUpChannel->closeStartUpToast();
150		removeChannelByID(LLUUID(gSavedSettings.getString("StartUpChannelUUID")));
151		mStartUpChannel = NULL;
152	}
153
154	// set StartUp Toast Flag to allow all other channels to show incoming toasts
155	LLScreenChannel::setStartUpToastShown();
156}
157
158//--------------------------------------------------------------------------
159
160LLScreenChannelBase*	LLChannelManager::addChannel(LLScreenChannelBase* channel)
161{
162	if(!channel)
163		return 0;
164
165	ChannelElem new_elem;
166	new_elem.id = channel->getChannelID();
167	new_elem.channel = channel->getHandle();
168
169	mChannelList.push_back(new_elem); 
170
171	return channel;
172}
173
174LLScreenChannel* LLChannelManager::createChannel(LLScreenChannelBase::Params& p)
175{
176	LLScreenChannel* new_channel = new LLScreenChannel(p); 
177
178	addChannel(new_channel);
179	return new_channel;
180}
181
182LLScreenChannelBase* LLChannelManager::getChannel(LLScreenChannelBase::Params& p)
183{
184	LLScreenChannelBase* new_channel = findChannelByID(p.id);
185
186	if(new_channel)
187		return new_channel;
188
189	return createChannel(p);
190
191}
192
193//--------------------------------------------------------------------------
194LLScreenChannelBase* LLChannelManager::findChannelByID(const LLUUID& id)
195{
196	std::vector<ChannelElem>::iterator it = find(mChannelList.begin(), mChannelList.end(), id); 
197	if(it != mChannelList.end())
198	{
199		return (*it).channel.get();
200	}
201
202	return NULL;
203}
204
205//--------------------------------------------------------------------------
206void LLChannelManager::removeChannelByID(const LLUUID& id)
207{
208	std::vector<ChannelElem>::iterator it = find(mChannelList.begin(), mChannelList.end(), id); 
209	if(it != mChannelList.end())
210	{
211		mChannelList.erase(it);
212	}
213}
214
215//--------------------------------------------------------------------------
216void LLChannelManager::muteAllChannels(bool mute)
217{
218	for (std::vector<ChannelElem>::iterator it = mChannelList.begin();
219			it != mChannelList.end(); it++)
220	{
221		if (it->channel.get())
222		{
223			it->channel.get()->setShowToasts(!mute);
224		}
225	}
226}
227
228void LLChannelManager::killToastsFromChannel(const LLUUID& channel_id, const LLScreenChannel::Matcher& matcher)
229{
230	LLScreenChannel
231			* screen_channel =
232					dynamic_cast<LLScreenChannel*> (findChannelByID(channel_id));
233	if (screen_channel != NULL)
234	{
235		screen_channel->killMatchedToasts(matcher);
236	}
237}
238
239// static
240LLNotificationsUI::LLScreenChannel* LLChannelManager::getNotificationScreenChannel()
241{
242	LLNotificationsUI::LLScreenChannel* channel = static_cast<LLNotificationsUI::LLScreenChannel*>
243	(LLNotificationsUI::LLChannelManager::getInstance()->
244										findChannelByID(LLUUID(gSavedSettings.getString("NotificationChannelUUID"))));
245
246	if (channel == NULL)
247	{
248		llwarns << "Can't find screen channel by NotificationChannelUUID" << llendl;
249		llassert(!"Can't find screen channel by NotificationChannelUUID");
250	}
251
252	return channel;
253}
254