PageRenderTime 14ms CodeModel.GetById 1ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/llnotificationalerthandler.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 146 lines | 84 code | 26 blank | 36 comment | 15 complexity | 861cc4ac8ceed6f137362b8947fa7e3e MD5 | raw file
  1/** 
  2 * @file llnotificationalerthandler.cpp
  3 * @brief Notification Handler Class for Alert Notifications
  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
 32#include "llnotifications.h"
 33#include "llprogressview.h"
 34#include "lltoastnotifypanel.h"
 35#include "llviewercontrol.h"
 36#include "llviewerwindow.h"
 37
 38#include "lltoastalertpanel.h"
 39
 40using namespace LLNotificationsUI;
 41
 42//--------------------------------------------------------------------------
 43LLAlertHandler::LLAlertHandler(e_notification_type type, const LLSD& id) : mIsModal(false)
 44{
 45	mType = type;
 46
 47	LLScreenChannelBase::Params p;
 48	p.id = LLUUID(gSavedSettings.getString("AlertChannelUUID"));
 49	p.display_toasts_always = true;
 50	p.toast_align = NA_CENTRE;
 51	p.channel_align = CA_CENTRE;
 52
 53	// Getting a Channel for our notifications
 54	mChannel = LLChannelManager::getInstance()->getChannel(p);
 55	mChannel->setCanStoreToasts(false);
 56}
 57
 58//--------------------------------------------------------------------------
 59LLAlertHandler::~LLAlertHandler()
 60{
 61}
 62
 63//--------------------------------------------------------------------------
 64void LLAlertHandler::initChannel()
 65{
 66	S32 channel_right_bound = gViewerWindow->getWorldViewRectScaled().getWidth() / 2;
 67	mChannel->init(channel_right_bound, channel_right_bound);
 68}
 69
 70//--------------------------------------------------------------------------
 71bool LLAlertHandler::processNotification(const LLSD& notify)
 72{
 73	if(!mChannel)
 74	{
 75		return false;
 76	}
 77
 78	LLNotificationPtr notification = LLNotifications::instance().find(notify["id"].asUUID());
 79
 80	if(!notification)
 81		return false;
 82
 83	// arrange a channel on a screen
 84	if(!mChannel->getVisible())
 85	{
 86		initChannel();
 87	}
 88
 89	if (notify["sigtype"].asString() == "add" || notify["sigtype"].asString() == "load")
 90	{
 91		if (LLHandlerUtil::canSpawnSessionAndLogToIM(notification))
 92		{
 93			const std::string name = LLHandlerUtil::getSubstitutionName(notification);
 94
 95			LLUUID from_id = notification->getPayload()["from_id"];
 96
 97			// firstly create session...
 98			LLHandlerUtil::spawnIMSession(name, from_id);
 99
100			// ...then log message to have IM Well notified about new message
101			LLHandlerUtil::logToIMP2P(notification);
102		}
103
104		LLToastAlertPanel* alert_dialog = new LLToastAlertPanel(notification, mIsModal);
105		LLToast::Params p;
106		p.notif_id = notification->getID();
107		p.notification = notification;
108		p.panel = dynamic_cast<LLToastPanel*>(alert_dialog);
109		p.enable_hide_btn = false;
110		p.can_fade = false;
111		p.is_modal = mIsModal;
112		p.on_delete_toast = boost::bind(&LLAlertHandler::onDeleteToast, this, _1);
113
114		// Show alert in middle of progress view (during teleport) (EXT-1093)
115		LLProgressView* progress = gViewerWindow->getProgressView();
116		LLRect rc = progress && progress->getVisible() ? progress->getRect() : gViewerWindow->getWorldViewRectScaled();
117		mChannel->updatePositionAndSize(rc);
118
119		LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
120		if(channel)
121			channel->addToast(p);
122	}
123	else if (notify["sigtype"].asString() == "change")
124	{
125		LLToastAlertPanel* alert_dialog = new LLToastAlertPanel(notification, mIsModal);
126		LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
127		if(channel)
128			channel->modifyToastByNotificationID(notification->getID(), (LLToastPanel*)alert_dialog);
129	}
130	else
131	{
132		LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
133		if(channel)
134			channel->killToastByNotificationID(notification->getID());
135	}
136	return false;
137}
138
139//--------------------------------------------------------------------------
140
141void LLAlertHandler::onDeleteToast(LLToast* toast)
142{
143}
144
145//--------------------------------------------------------------------------
146