llnotificationalerthandler.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:5k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llnotificationalerthandler.cpp
  3.  * @brief Notification Handler Class for Alert Notifications
  4.  *
  5.  * $LicenseInfo:firstyear=2000&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2000-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h" // must be first include
  33. #include "llnotificationhandler.h"
  34. #include "llnotifications.h"
  35. #include "llprogressview.h"
  36. #include "lltoastnotifypanel.h"
  37. #include "llviewercontrol.h"
  38. #include "llviewerwindow.h"
  39. #include "lltoastalertpanel.h"
  40. using namespace LLNotificationsUI;
  41. //--------------------------------------------------------------------------
  42. LLAlertHandler::LLAlertHandler(e_notification_type type, const LLSD& id) : mIsModal(false)
  43. {
  44. mType = type;
  45. LLChannelManager::Params p;
  46. p.id = LLUUID(gSavedSettings.getString("AlertChannelUUID"));
  47. p.display_toasts_always = true;
  48. p.toast_align = NA_CENTRE;
  49. p.channel_align = CA_CENTRE;
  50. // Getting a Channel for our notifications
  51. mChannel = LLChannelManager::getInstance()->getChannel(p);
  52. mChannel->setCanStoreToasts(false);
  53. }
  54. //--------------------------------------------------------------------------
  55. LLAlertHandler::~LLAlertHandler()
  56. {
  57. }
  58. //--------------------------------------------------------------------------
  59. void LLAlertHandler::initChannel()
  60. {
  61. S32 channel_right_bound = gViewerWindow->getWorldViewRectScaled().getWidth() / 2;
  62. mChannel->init(channel_right_bound, channel_right_bound);
  63. }
  64. //--------------------------------------------------------------------------
  65. bool LLAlertHandler::processNotification(const LLSD& notify)
  66. {
  67. if(!mChannel)
  68. {
  69. return false;
  70. }
  71. LLNotificationPtr notification = LLNotifications::instance().find(notify["id"].asUUID());
  72. if(!notification)
  73. return false;
  74. // arrange a channel on a screen
  75. if(!mChannel->getVisible())
  76. {
  77. initChannel();
  78. }
  79. if (notify["sigtype"].asString() == "add" || notify["sigtype"].asString() == "load")
  80. {
  81. if (LLHandlerUtil::canSpawnSessionAndLogToIM(notification))
  82. {
  83. const std::string name = LLHandlerUtil::getSubstitutionName(notification);
  84. LLUUID from_id = notification->getPayload()["from_id"];
  85. // firstly create session...
  86. LLHandlerUtil::spawnIMSession(name, from_id);
  87. // ...then log message to have IM Well notified about new message
  88. LLHandlerUtil::logToIMP2P(notification);
  89. }
  90. LLToastAlertPanel* alert_dialog = new LLToastAlertPanel(notification, mIsModal);
  91. LLToast::Params p;
  92. p.notif_id = notification->getID();
  93. p.notification = notification;
  94. p.panel = dynamic_cast<LLToastPanel*>(alert_dialog);
  95. p.enable_hide_btn = false;
  96. p.can_fade = false;
  97. p.is_modal = mIsModal;
  98. p.on_delete_toast = boost::bind(&LLAlertHandler::onDeleteToast, this, _1);
  99. // Show alert in middle of progress view (during teleport) (EXT-1093)
  100. LLProgressView* progress = gViewerWindow->getProgressView();
  101. LLRect rc = progress && progress->getVisible() ? progress->getRect() : gViewerWindow->getWorldViewRectScaled();
  102. mChannel->updatePositionAndSize(rc, rc);
  103. LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
  104. if(channel)
  105. channel->addToast(p);
  106. }
  107. else if (notify["sigtype"].asString() == "change")
  108. {
  109. LLToastAlertPanel* alert_dialog = new LLToastAlertPanel(notification, mIsModal);
  110. LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
  111. if(channel)
  112. channel->modifyToastByNotificationID(notification->getID(), (LLToastPanel*)alert_dialog);
  113. }
  114. else
  115. {
  116. LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
  117. if(channel)
  118. channel->killToastByNotificationID(notification->getID());
  119. }
  120. return true;
  121. }
  122. //--------------------------------------------------------------------------
  123. void LLAlertHandler::onDeleteToast(LLToast* toast)
  124. {
  125. }
  126. //--------------------------------------------------------------------------