PageRenderTime 374ms CodeModel.GetById 201ms app.highlight 15ms RepoModel.GetById 156ms app.codeStats 0ms

/indra/newview/llnotificationscripthandler.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 173 lines | 103 code | 32 blank | 38 comment | 31 complexity | 257b2a180083f7b215d26ad27de0bc59 MD5 | raw file
  1/** 
  2 * @file llnotificationscripthandler.cpp
  3 * @brief Notification Handler Class for Simple Notifications and Notification Tips
  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#include "llviewerprecompiledheaders.h" // must be first include
 29
 30#include "llnotificationhandler.h"
 31#include "lltoastnotifypanel.h"
 32#include "llviewercontrol.h"
 33#include "llviewerwindow.h"
 34#include "llnotificationmanager.h"
 35#include "llnotifications.h"
 36#include "llscriptfloater.h"
 37
 38using namespace LLNotificationsUI;
 39
 40static const std::string SCRIPT_DIALOG				("ScriptDialog");
 41static const std::string SCRIPT_DIALOG_GROUP		("ScriptDialogGroup");
 42static const std::string SCRIPT_LOAD_URL			("LoadWebPage");
 43
 44//--------------------------------------------------------------------------
 45LLScriptHandler::LLScriptHandler(e_notification_type type, const LLSD& id)
 46{
 47	mType = type;
 48
 49	// Getting a Channel for our notifications
 50	mChannel = LLChannelManager::getInstance()->createNotificationChannel();
 51	mChannel->setControlHovering(true);
 52	
 53	LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
 54	if(channel)
 55		channel->setOnRejectToastCallback(boost::bind(&LLScriptHandler::onRejectToast, this, _1));
 56
 57}
 58
 59//--------------------------------------------------------------------------
 60LLScriptHandler::~LLScriptHandler()
 61{
 62}
 63
 64//--------------------------------------------------------------------------
 65void LLScriptHandler::initChannel()
 66{
 67	S32 channel_right_bound = gViewerWindow->getWorldViewRectScaled().mRight - gSavedSettings.getS32("NotificationChannelRightMargin"); 
 68	S32 channel_width = gSavedSettings.getS32("NotifyBoxWidth");
 69	mChannel->init(channel_right_bound - channel_width, channel_right_bound);
 70}
 71
 72//--------------------------------------------------------------------------
 73bool LLScriptHandler::processNotification(const LLSD& notify)
 74{
 75	if(!mChannel)
 76	{
 77		return false;
 78	}
 79
 80	LLNotificationPtr notification = LLNotifications::instance().find(notify["id"].asUUID());
 81
 82	if(!notification)
 83		return false;
 84
 85	// arrange a channel on a screen
 86	if(!mChannel->getVisible())
 87	{
 88		initChannel();
 89	}
 90	
 91	if(notify["sigtype"].asString() == "add")
 92	{
 93		if (LLHandlerUtil::canLogToIM(notification))
 94		{
 95			LLHandlerUtil::logToIMP2P(notification);
 96		}
 97
 98		if(SCRIPT_DIALOG == notification->getName() || SCRIPT_DIALOG_GROUP == notification->getName() || SCRIPT_LOAD_URL == notification->getName())
 99		{
100			LLScriptFloaterManager::getInstance()->onAddNotification(notification->getID());
101		}
102		else
103		{
104			LLToastNotifyPanel* notify_box = new LLToastNotifyPanel(notification);
105
106			LLToast::Params p;
107			p.notif_id = notification->getID();
108			p.notification = notification;
109			p.panel = notify_box;	
110			p.on_delete_toast = boost::bind(&LLScriptHandler::onDeleteToast, this, _1);
111
112			LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
113			if(channel)
114			{
115				channel->addToast(p);
116			}
117
118			// send a signal to the counter manager
119			mNewNotificationSignal();
120		}
121	}
122	else if (notify["sigtype"].asString() == "delete")
123	{
124		if(SCRIPT_DIALOG == notification->getName() || SCRIPT_DIALOG_GROUP == notification->getName() || SCRIPT_LOAD_URL == notification->getName())
125		{
126			LLScriptFloaterManager::getInstance()->onRemoveNotification(notification->getID());
127		}
128		else
129		{
130			mChannel->killToastByNotificationID(notification->getID());
131		}
132	}
133	return false;
134}
135
136//--------------------------------------------------------------------------
137
138void LLScriptHandler::onDeleteToast(LLToast* toast)
139{
140	// send a signal to the counter manager
141	mDelNotificationSignal();
142
143	// send a signal to a listener to let him perform some action
144	// in this case listener is a SysWellWindow and it will remove a corresponding item from its list
145	mNotificationIDSignal(toast->getNotificationID());
146
147	LLNotificationPtr notification = LLNotifications::getInstance()->find(toast->getNotificationID());
148	
149	if( notification && 
150		(SCRIPT_DIALOG == notification->getName() || SCRIPT_DIALOG_GROUP == notification->getName()) )
151	{
152		LLScriptFloaterManager::getInstance()->onRemoveNotification(notification->getID());
153	}
154}
155
156//--------------------------------------------------------------------------
157void LLScriptHandler::onRejectToast(LLUUID& id)
158{
159	LLNotificationPtr notification = LLNotifications::instance().find(id);
160
161	if (notification
162			&& LLNotificationManager::getInstance()->getHandlerForNotification(
163					notification->getType()) == this)
164	{
165		LLNotifications::instance().cancel(notification);
166	}
167}
168
169//--------------------------------------------------------------------------
170
171
172
173