PageRenderTime 274ms CodeModel.GetById 156ms app.highlight 11ms RepoModel.GetById 105ms app.codeStats 0ms

/indra/newview/llnotificationgrouphandler.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 133 lines | 73 code | 22 blank | 38 comment | 15 complexity | 6602f0a0258654f56af87a0bcf69491c MD5 | raw file
  1/** 
  2 * @file llnotificationgrouphandler.cpp
  3 * @brief Notification Handler Class for Group 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#include "llviewerprecompiledheaders.h" // must be first include
 28
 29#include "llnotificationhandler.h"
 30#include "lltoastgroupnotifypanel.h"
 31#include "llgroupactions.h"
 32#include "llviewercontrol.h"
 33#include "llviewerwindow.h"
 34#include "llnotificationmanager.h"
 35#include "llnotifications.h"
 36
 37using namespace LLNotificationsUI;
 38
 39//--------------------------------------------------------------------------
 40LLGroupHandler::LLGroupHandler(e_notification_type type, const LLSD& id)
 41{
 42	mType = type;
 43
 44	// Getting a Channel for our notifications
 45	mChannel = LLChannelManager::getInstance()->createNotificationChannel();
 46	LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
 47	if(channel)
 48		channel->setOnRejectToastCallback(boost::bind(&LLGroupHandler::onRejectToast, this, _1));
 49}
 50
 51//--------------------------------------------------------------------------
 52LLGroupHandler::~LLGroupHandler()
 53{
 54}
 55
 56//--------------------------------------------------------------------------
 57void LLGroupHandler::initChannel()
 58{
 59	S32 channel_right_bound = gViewerWindow->getWorldViewRectScaled().mRight - gSavedSettings.getS32("NotificationChannelRightMargin"); 
 60	S32 channel_width = gSavedSettings.getS32("NotifyBoxWidth");
 61	mChannel->init(channel_right_bound - channel_width, channel_right_bound);
 62}
 63
 64//--------------------------------------------------------------------------
 65bool LLGroupHandler::processNotification(const LLSD& notify)
 66{
 67	if(!mChannel)
 68	{
 69		return false;
 70	}
 71
 72	LLNotificationPtr notification = LLNotifications::instance().find(notify["id"].asUUID());
 73
 74	if(!notification)
 75		return false;
 76
 77	// arrange a channel on a screen
 78	if(!mChannel->getVisible())
 79	{
 80		initChannel();
 81	}
 82	
 83	if(notify["sigtype"].asString() == "add" || notify["sigtype"].asString() == "change")
 84	{
 85		LLHandlerUtil::logGroupNoticeToIMGroup(notification);
 86
 87		LLPanel* notify_box = new LLToastGroupNotifyPanel(notification);
 88		LLToast::Params p;
 89		p.notif_id = notification->getID();
 90		p.notification = notification;
 91		p.panel = notify_box;
 92		p.on_delete_toast = boost::bind(&LLGroupHandler::onDeleteToast, this, _1);
 93
 94		LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
 95		if(channel)
 96			channel->addToast(p);
 97
 98		// send a signal to the counter manager
 99		mNewNotificationSignal();
100
101		LLGroupActions::refresh_notices();
102	}
103	else if (notify["sigtype"].asString() == "delete")
104	{
105		mChannel->killToastByNotificationID(notification->getID());
106	}
107	return false;
108}
109
110//--------------------------------------------------------------------------
111void LLGroupHandler::onDeleteToast(LLToast* toast)
112{
113	// send a signal to the counter manager
114	mDelNotificationSignal();
115
116	// send a signal to a listener to let him perform some action
117	// in this case listener is a SysWellWindow and it will remove a corresponding item from its list
118	mNotificationIDSignal(toast->getNotificationID());
119}
120
121//--------------------------------------------------------------------------
122void LLGroupHandler::onRejectToast(LLUUID& id)
123{
124	LLNotificationPtr notification = LLNotifications::instance().find(id);
125
126	if (notification && LLNotificationManager::getInstance()->getHandlerForNotification(notification->getType()) == this)
127	{
128		LLNotifications::instance().cancel(notification);
129	}
130}
131
132//--------------------------------------------------------------------------
133