PageRenderTime 83ms CodeModel.GetById 30ms app.highlight 33ms RepoModel.GetById 17ms app.codeStats 1ms

/indra/newview/llnotificationmanager.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 140 lines | 80 code | 27 blank | 33 comment | 5 complexity | 38bb480ca569f1185c37fb8dbb1ebd23 MD5 | raw file
  1/** 
  2 * @file llnotificationmanager.cpp
  3 * @brief Class implements a brige between the old and a new notification sistems
  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
 28
 29#include "llviewerprecompiledheaders.h" // must be first include
 30
 31
 32#include "llnotificationmanager.h"
 33
 34#include "llnearbychathandler.h"
 35#include "llnotifications.h"
 36
 37#include <boost/bind.hpp>
 38
 39using namespace LLNotificationsUI;
 40
 41//--------------------------------------------------------------------------
 42LLNotificationManager::LLNotificationManager()
 43{
 44	mNotifyHandlers.clear();
 45	init();
 46}
 47
 48//--------------------------------------------------------------------------
 49LLNotificationManager::~LLNotificationManager()
 50{
 51}
 52
 53//--------------------------------------------------------------------------
 54void LLNotificationManager::init()
 55{
 56	LLNotificationChannel::buildChannel("Notifications", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "notify"));
 57	LLNotificationChannel::buildChannel("NotificationTips", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "notifytip"));
 58	LLNotificationChannel::buildChannel("Group Notifications", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "groupnotify"));
 59	LLNotificationChannel::buildChannel("Alerts", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "alert"));
 60	LLNotificationChannel::buildChannel("AlertModal", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "alertmodal"));
 61	LLNotificationChannel::buildChannel("IM Notifications", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "notifytoast"));
 62	LLNotificationChannel::buildChannel("Offer", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "offer"));
 63	LLNotificationChannel::buildChannel("Hints", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "hint"));
 64	LLNotificationChannel::buildChannel("Browser", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "browser"));
 65	LLNotificationChannel::buildChannel("Outbox", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "outbox"));
 66  
 67	LLNotifications::instance().getChannel("Notifications")->connectChanged(boost::bind(&LLNotificationManager::onNotification, this, _1));
 68	LLNotifications::instance().getChannel("NotificationTips")->connectChanged(boost::bind(&LLNotificationManager::onNotification, this, _1));
 69	LLNotifications::instance().getChannel("Group Notifications")->connectChanged(boost::bind(&LLNotificationManager::onNotification, this, _1));
 70	LLNotifications::instance().getChannel("Alerts")->connectChanged(boost::bind(&LLNotificationManager::onNotification, this, _1));
 71	LLNotifications::instance().getChannel("AlertModal")->connectChanged(boost::bind(&LLNotificationManager::onNotification, this, _1));
 72	LLNotifications::instance().getChannel("IM Notifications")->connectChanged(boost::bind(&LLNotificationManager::onNotification, this, _1));
 73	LLNotifications::instance().getChannel("Offer")->connectChanged(boost::bind(&LLNotificationManager::onNotification, this, _1));
 74	LLNotifications::instance().getChannel("Hints")->connectChanged(boost::bind(&LLHintHandler::processNotification, LLHintHandler::getInstance(), _1));
 75	LLNotifications::instance().getChannel("Browser")->connectChanged(boost::bind(&LLBrowserNotification::processNotification, LLBrowserNotification::getInstance(), _1));
 76	LLNotifications::instance().getChannel("Outbox")->connectChanged(boost::bind(&LLOutboxNotification::processNotification, LLOutboxNotification::getInstance(), _1));
 77
 78	mNotifyHandlers["notify"] = boost::shared_ptr<LLEventHandler>(new LLScriptHandler(NT_NOTIFY, LLSD()));
 79	mNotifyHandlers["notifytip"] =  boost::shared_ptr<LLEventHandler>(new LLTipHandler(NT_NOTIFY, LLSD()));
 80	mNotifyHandlers["groupnotify"] = boost::shared_ptr<LLEventHandler>(new LLGroupHandler(NT_GROUPNOTIFY, LLSD()));
 81	mNotifyHandlers["alert"] = boost::shared_ptr<LLEventHandler>(new LLAlertHandler(NT_ALERT, LLSD()));
 82	mNotifyHandlers["alertmodal"] = boost::shared_ptr<LLEventHandler>(new LLAlertHandler(NT_ALERT, LLSD()));
 83	static_cast<LLAlertHandler*>(mNotifyHandlers["alertmodal"].get())->setAlertMode(true);
 84	mNotifyHandlers["notifytoast"] = boost::shared_ptr<LLEventHandler>(new LLIMHandler(NT_IMCHAT, LLSD()));
 85	
 86	mNotifyHandlers["nearbychat"] = boost::shared_ptr<LLEventHandler>(new LLNearbyChatHandler(NT_NEARBYCHAT, LLSD()));
 87	mNotifyHandlers["offer"] = boost::shared_ptr<LLEventHandler>(new LLOfferHandler(NT_OFFER, LLSD()));
 88}
 89
 90//--------------------------------------------------------------------------
 91bool LLNotificationManager::onNotification(const LLSD& notify)
 92{
 93	LLSysHandler* handle = NULL;
 94
 95	LLNotificationPtr notification = LLNotifications::instance().find(notify["id"].asUUID());
 96	
 97	if (!notification) 
 98		return false;
 99
100	std::string notification_type = notification->getType();
101	handle = static_cast<LLSysHandler*>(mNotifyHandlers[notification_type].get());
102
103	if(!handle)
104		return false;
105	
106	return handle->processNotification(notify);
107}
108
109//--------------------------------------------------------------------------
110void LLNotificationManager::onChat(const LLChat& msg, const LLSD &args)
111{
112	// check ENotificationType argument
113	switch(args["type"].asInteger())
114	{
115	case NT_NEARBYCHAT:
116		{
117			LLNearbyChatHandler* handle = dynamic_cast<LLNearbyChatHandler*>(mNotifyHandlers["nearbychat"].get());
118
119			if(handle)
120				handle->processChat(msg, args);
121		}
122		break;
123	default: 	//no need to handle all enum types
124		break;
125	}
126}
127
128//--------------------------------------------------------------------------
129LLEventHandler* LLNotificationManager::getHandlerForNotification(std::string notification_type) 
130{ 
131	std::map<std::string, boost::shared_ptr<LLEventHandler> >::iterator it = mNotifyHandlers.find(notification_type);
132
133	if(it != mNotifyHandlers.end())
134		return (*it).second.get();
135
136	return NULL;
137}
138
139//--------------------------------------------------------------------------
140