PageRenderTime 20ms CodeModel.GetById 1ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llnotificationtiphandler.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 168 lines | 106 code | 26 blank | 36 comment | 23 complexity | e054593102d1645ee7cea98df43002ae MD5 | raw file
  1/** 
  2 * @file llnotificationtiphandler.cpp
  3 * @brief Notification Handler Class for 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 "llfloaterreg.h"
 31#include "llnearbychat.h"
 32#include "llnearbychatbar.h"
 33#include "llnotificationhandler.h"
 34#include "llnotifications.h"
 35#include "lltoastnotifypanel.h"
 36#include "llviewercontrol.h"
 37#include "llviewerwindow.h"
 38#include "llnotificationmanager.h"
 39#include "llpaneltiptoast.h"
 40
 41using namespace LLNotificationsUI;
 42
 43//--------------------------------------------------------------------------
 44LLTipHandler::LLTipHandler(e_notification_type type, const LLSD& id)
 45{
 46	mType = type;	
 47
 48	// Getting a Channel for our notifications
 49	mChannel = LLChannelManager::getInstance()->createNotificationChannel();
 50
 51	LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
 52	if(channel)
 53		channel->setOnRejectToastCallback(boost::bind(&LLTipHandler::onRejectToast, this, _1));
 54}
 55
 56//--------------------------------------------------------------------------
 57LLTipHandler::~LLTipHandler()
 58{
 59}
 60
 61//--------------------------------------------------------------------------
 62void LLTipHandler::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 LLTipHandler::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		// archive message in nearby chat
 91		if (LLHandlerUtil::canLogToNearbyChat(notification))
 92		{
 93			LLHandlerUtil::logToNearbyChat(notification, CHAT_SOURCE_SYSTEM);
 94
 95			// don't show toast if Nearby Chat is opened
 96			LLNearbyChat* nearby_chat = LLNearbyChat::getInstance();
 97			LLNearbyChatBar* nearby_chat_bar = LLNearbyChatBar::getInstance();
 98			if (!nearby_chat_bar->isMinimized() && nearby_chat_bar->getVisible() && nearby_chat->getVisible())
 99			{
100				return false;
101			}
102		}
103
104		std::string session_name = notification->getPayload()["SESSION_NAME"];
105		const std::string name = notification->getSubstitutions()["NAME"];
106		if (session_name.empty())
107		{
108			session_name = name;
109		}
110		LLUUID from_id = notification->getPayload()["from_id"];
111		if (LLHandlerUtil::canLogToIM(notification))
112		{
113			LLHandlerUtil::logToIM(IM_NOTHING_SPECIAL, session_name, name,
114					notification->getMessage(), from_id, from_id);
115		}
116
117		if (LLHandlerUtil::canSpawnIMSession(notification))
118		{
119			LLHandlerUtil::spawnIMSession(name, from_id);
120		}
121
122		// don't spawn toast for inventory accepted/declined offers if respective IM window is open (EXT-5909)
123		if (!LLHandlerUtil::canSpawnToast(notification))
124		{
125			return false;
126		}
127
128		LLToastPanel* notify_box = LLToastPanel::buidPanelFromNotification(notification);
129
130		LLToast::Params p;
131		p.notif_id = notification->getID();
132		p.notification = notification;
133		p.lifetime_secs = gSavedSettings.getS32("NotificationTipToastLifeTime");
134		p.panel = notify_box;
135		p.is_tip = true;
136		p.can_be_stored = false;
137		
138		removeExclusiveNotifications(notification);
139
140		LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
141		if(channel)
142			channel->addToast(p);
143	}
144	else if (notify["sigtype"].asString() == "delete")
145	{
146		mChannel->killToastByNotificationID(notification->getID());
147	}
148	return false;
149}
150
151//--------------------------------------------------------------------------
152void LLTipHandler::onDeleteToast(LLToast* toast)
153{
154}
155
156//--------------------------------------------------------------------------
157
158void LLTipHandler::onRejectToast(const LLUUID& id)
159{
160	LLNotificationPtr notification = LLNotifications::instance().find(id);
161
162	if (notification
163			&& LLNotificationManager::getInstance()->getHandlerForNotification(
164					notification->getType()) == this)
165	{
166		LLNotifications::instance().cancel(notification);
167	}
168}