PageRenderTime 405ms CodeModel.GetById 242ms app.highlight 10ms RepoModel.GetById 151ms app.codeStats 0ms

/indra/newview/llimhandler.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 130 lines | 70 code | 23 blank | 37 comment | 12 complexity | 6611039c1d4c46fe572adf9e13944411 MD5 | raw file
  1/** 
  2 * @file llimhandler.cpp
  3 * @brief Notification Handler Class for IM 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 "llagentdata.h"
 33#include "llnotifications.h"
 34#include "lltoastimpanel.h"
 35#include "llviewerwindow.h"
 36
 37using namespace LLNotificationsUI;
 38
 39//--------------------------------------------------------------------------
 40LLIMHandler::LLIMHandler(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}
 47
 48//--------------------------------------------------------------------------
 49LLIMHandler::~LLIMHandler()
 50{
 51}
 52
 53//--------------------------------------------------------------------------
 54void LLIMHandler::initChannel()
 55{
 56	S32 channel_right_bound = gViewerWindow->getWorldViewRectScaled().mRight - gSavedSettings.getS32("NotificationChannelRightMargin"); 
 57	S32 channel_width = gSavedSettings.getS32("NotifyBoxWidth");
 58	mChannel->init(channel_right_bound - channel_width, channel_right_bound);
 59}
 60
 61//--------------------------------------------------------------------------
 62bool LLIMHandler::processNotification(const LLSD& notify)
 63{
 64	if(!mChannel)
 65	{
 66		return false;
 67	}
 68
 69	LLNotificationPtr notification = LLNotifications::instance().find(notify["id"].asUUID());
 70
 71	if(!notification)
 72		return false;
 73
 74	// arrange a channel on a screen
 75	if(!mChannel->getVisible())
 76	{
 77		initChannel();
 78	}
 79
 80	if(notify["sigtype"].asString() == "add" || notify["sigtype"].asString() == "change")
 81	{
 82		LLSD substitutions = notification->getSubstitutions();
 83
 84		// According to comments in LLIMMgr::addMessage(), if we get message
 85		// from ourselves, the sender id is set to null. This fixes EXT-875.
 86		LLUUID avatar_id = substitutions["FROM_ID"].asUUID();
 87		if (avatar_id.isNull())
 88			avatar_id = gAgentID;
 89
 90		LLToastIMPanel::Params im_p;
 91		im_p.notification = notification;
 92		im_p.avatar_id = avatar_id;
 93		im_p.from = substitutions["FROM"].asString();
 94		im_p.time = substitutions["TIME"].asString();
 95		im_p.message = substitutions["MESSAGE"].asString();
 96		im_p.session_id = substitutions["SESSION_ID"].asUUID();
 97
 98		LLToastIMPanel* im_box = new LLToastIMPanel(im_p);
 99
100		LLToast::Params p;
101		p.notif_id = notification->getID();
102		p.session_id = im_p.session_id;
103		p.notification = notification;
104		p.panel = im_box;
105		p.can_be_stored = false;
106		p.on_delete_toast = boost::bind(&LLIMHandler::onDeleteToast, this, _1);
107		LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
108		if(channel)
109			channel->addToast(p);
110
111		// send a signal to the counter manager;
112		mNewNotificationSignal();
113	}
114	else if (notify["sigtype"].asString() == "delete")
115	{
116		mChannel->killToastByNotificationID(notification->getID());
117	}
118	return false;
119}
120
121//--------------------------------------------------------------------------
122void LLIMHandler::onDeleteToast(LLToast* toast)
123{
124	// send a signal to the counter manager
125	mDelNotificationSignal();
126}
127
128//--------------------------------------------------------------------------
129
130