PageRenderTime 1143ms CodeModel.GetById 166ms app.highlight 130ms RepoModel.GetById 786ms app.codeStats 0ms

/indra/newview/llnotificationofferhandler.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 213 lines | 139 code | 30 blank | 44 comment | 33 complexity | 394093bc212e106fb6bb3a1b4fb1bcfc MD5 | raw file
  1/**
  2 * @file llnotificationofferhandler.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#include "llimview.h"
 38#include "llnotificationsutil.h"
 39
 40using namespace LLNotificationsUI;
 41
 42//--------------------------------------------------------------------------
 43LLOfferHandler::LLOfferHandler(e_notification_type type, const LLSD& id)
 44{
 45	mType = type;
 46
 47	// Getting a Channel for our notifications
 48	mChannel = LLChannelManager::getInstance()->createNotificationChannel();
 49	mChannel->setControlHovering(true);
 50
 51	LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
 52	if(channel)
 53		channel->setOnRejectToastCallback(boost::bind(&LLOfferHandler::onRejectToast, this, _1));
 54}
 55
 56//--------------------------------------------------------------------------
 57LLOfferHandler::~LLOfferHandler()
 58{
 59}
 60
 61//--------------------------------------------------------------------------
 62void LLOfferHandler::initChannel()
 63{
 64	S32 channel_right_bound = gViewerWindow->getWorldViewRectScaled().mRight - gSavedSettings.getS32("NotificationChannelRightMargin");
 65	S32 channel_width = gSavedSettings.getS32("NotifyBoxWidth");
 66	mChannel->init(channel_right_bound - channel_width, channel_right_bound);
 67}
 68
 69//--------------------------------------------------------------------------
 70bool LLOfferHandler::processNotification(const LLSD& notify)
 71{
 72	if(!mChannel)
 73	{
 74		return false;
 75	}
 76
 77	LLNotificationPtr notification = LLNotifications::instance().find(notify["id"].asUUID());
 78
 79	if(!notification)
 80		return false;
 81
 82	// arrange a channel on a screen
 83	if(!mChannel->getVisible())
 84	{
 85		initChannel();
 86	}
 87
 88	if(notify["sigtype"].asString() == "add" || notify["sigtype"].asString() == "change")
 89	{
 90
 91
 92		if( notification->getPayload().has("give_inventory_notification")
 93			&& !notification->getPayload()["give_inventory_notification"] )
 94		{
 95			// This is an original inventory offer, so add a script floater
 96			LLScriptFloaterManager::instance().onAddNotification(notification->getID());
 97		}
 98		else
 99		{
100			notification->setReusable(LLHandlerUtil::isNotificationReusable(notification));
101
102			LLUUID session_id;
103			if (LLHandlerUtil::canSpawnIMSession(notification))
104			{
105				const std::string name = LLHandlerUtil::getSubstitutionName(notification);
106
107				LLUUID from_id = notification->getPayload()["from_id"];
108
109				session_id = LLHandlerUtil::spawnIMSession(name, from_id);
110			}
111
112			bool show_toast = LLHandlerUtil::canSpawnToast(notification);
113			bool add_notid_to_im = LLHandlerUtil::canAddNotifPanelToIM(notification);
114			if (add_notid_to_im)
115			{
116				LLHandlerUtil::addNotifPanelToIM(notification);
117			}
118
119			if (notification->getPayload().has("SUPPRESS_TOAST")
120						&& notification->getPayload()["SUPPRESS_TOAST"])
121			{
122				LLNotificationsUtil::cancel(notification);
123			}
124			else if(show_toast)
125			{
126				LLToastNotifyPanel* notify_box = new LLToastNotifyPanel(notification);
127				// don't close notification on panel destroy since it will be used by IM floater
128				notify_box->setCloseNotificationOnDestroy(!add_notid_to_im);
129				LLToast::Params p;
130				p.notif_id = notification->getID();
131				p.notification = notification;
132				p.panel = notify_box;
133				p.on_delete_toast = boost::bind(&LLOfferHandler::onDeleteToast, this, _1);
134				// we not save offer notifications to the syswell floater that should be added to the IM floater
135				p.can_be_stored = !add_notid_to_im;
136
137				LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
138				if(channel)
139					channel->addToast(p);
140
141				// if we not add notification to IM - add it to notification well
142				if (!add_notid_to_im)
143				{
144					// send a signal to the counter manager
145					mNewNotificationSignal();
146				}
147			}
148
149			if (LLHandlerUtil::canLogToIM(notification))
150			{
151				// log only to file if notif panel can be embedded to IM and IM is opened
152				if (add_notid_to_im && LLHandlerUtil::isIMFloaterOpened(notification))
153				{
154					LLHandlerUtil::logToIMP2P(notification, true);
155				}
156				else
157				{
158					LLHandlerUtil::logToIMP2P(notification);
159				}
160			}
161		}
162	}
163	else if (notify["sigtype"].asString() == "delete")
164	{
165		if( notification->getPayload().has("give_inventory_notification")
166			&& !notification->getPayload()["give_inventory_notification"] )
167		{
168			// Remove original inventory offer script floater
169			LLScriptFloaterManager::instance().onRemoveNotification(notification->getID());
170		}
171		else
172		{
173			if (LLHandlerUtil::canAddNotifPanelToIM(notification)
174					&& !LLHandlerUtil::isIMFloaterOpened(notification))
175			{
176				LLHandlerUtil::decIMMesageCounter(notification);
177			}
178			mChannel->killToastByNotificationID(notification->getID());
179		}
180	}
181
182	return false;
183}
184
185//--------------------------------------------------------------------------
186
187void LLOfferHandler::onDeleteToast(LLToast* toast)
188{
189	if (!LLHandlerUtil::canAddNotifPanelToIM(toast->getNotification()))
190	{
191		// send a signal to the counter manager
192		mDelNotificationSignal();
193	}
194
195	// send a signal to a listener to let him perform some action
196	// in this case listener is a SysWellWindow and it will remove a corresponding item from its list
197	mNotificationIDSignal(toast->getNotificationID());
198}
199
200//--------------------------------------------------------------------------
201void LLOfferHandler::onRejectToast(LLUUID& id)
202{
203	LLNotificationPtr notification = LLNotifications::instance().find(id);
204
205	if (notification
206			&& LLNotificationManager::getInstance()->getHandlerForNotification(
207					notification->getType()) == this
208					// don't delete notification since it may be used by IM floater
209					&& !LLHandlerUtil::canAddNotifPanelToIM(notification))
210	{
211		LLNotifications::instance().cancel(notification);
212	}
213}