PageRenderTime 27ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llnotificationscripthandler.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 173 lines | 103 code | 32 blank | 38 comment | 31 complexity | 257b2a180083f7b215d26ad27de0bc59 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llnotificationscripthandler.cpp
  3. * @brief Notification Handler Class for Simple Notifications and 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. #include "llviewerprecompiledheaders.h" // must be first include
  27. #include "llnotificationhandler.h"
  28. #include "lltoastnotifypanel.h"
  29. #include "llviewercontrol.h"
  30. #include "llviewerwindow.h"
  31. #include "llnotificationmanager.h"
  32. #include "llnotifications.h"
  33. #include "llscriptfloater.h"
  34. using namespace LLNotificationsUI;
  35. static const std::string SCRIPT_DIALOG ("ScriptDialog");
  36. static const std::string SCRIPT_DIALOG_GROUP ("ScriptDialogGroup");
  37. static const std::string SCRIPT_LOAD_URL ("LoadWebPage");
  38. //--------------------------------------------------------------------------
  39. LLScriptHandler::LLScriptHandler(e_notification_type type, const LLSD& id)
  40. {
  41. mType = type;
  42. // Getting a Channel for our notifications
  43. mChannel = LLChannelManager::getInstance()->createNotificationChannel();
  44. mChannel->setControlHovering(true);
  45. LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
  46. if(channel)
  47. channel->setOnRejectToastCallback(boost::bind(&LLScriptHandler::onRejectToast, this, _1));
  48. }
  49. //--------------------------------------------------------------------------
  50. LLScriptHandler::~LLScriptHandler()
  51. {
  52. }
  53. //--------------------------------------------------------------------------
  54. void LLScriptHandler::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. bool LLScriptHandler::processNotification(const LLSD& notify)
  62. {
  63. if(!mChannel)
  64. {
  65. return false;
  66. }
  67. LLNotificationPtr notification = LLNotifications::instance().find(notify["id"].asUUID());
  68. if(!notification)
  69. return false;
  70. // arrange a channel on a screen
  71. if(!mChannel->getVisible())
  72. {
  73. initChannel();
  74. }
  75. if(notify["sigtype"].asString() == "add")
  76. {
  77. if (LLHandlerUtil::canLogToIM(notification))
  78. {
  79. LLHandlerUtil::logToIMP2P(notification);
  80. }
  81. if(SCRIPT_DIALOG == notification->getName() || SCRIPT_DIALOG_GROUP == notification->getName() || SCRIPT_LOAD_URL == notification->getName())
  82. {
  83. LLScriptFloaterManager::getInstance()->onAddNotification(notification->getID());
  84. }
  85. else
  86. {
  87. LLToastNotifyPanel* notify_box = new LLToastNotifyPanel(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(&LLScriptHandler::onDeleteToast, this, _1);
  93. LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
  94. if(channel)
  95. {
  96. channel->addToast(p);
  97. }
  98. // send a signal to the counter manager
  99. mNewNotificationSignal();
  100. }
  101. }
  102. else if (notify["sigtype"].asString() == "delete")
  103. {
  104. if(SCRIPT_DIALOG == notification->getName() || SCRIPT_DIALOG_GROUP == notification->getName() || SCRIPT_LOAD_URL == notification->getName())
  105. {
  106. LLScriptFloaterManager::getInstance()->onRemoveNotification(notification->getID());
  107. }
  108. else
  109. {
  110. mChannel->killToastByNotificationID(notification->getID());
  111. }
  112. }
  113. return false;
  114. }
  115. //--------------------------------------------------------------------------
  116. void LLScriptHandler::onDeleteToast(LLToast* toast)
  117. {
  118. // send a signal to the counter manager
  119. mDelNotificationSignal();
  120. // send a signal to a listener to let him perform some action
  121. // in this case listener is a SysWellWindow and it will remove a corresponding item from its list
  122. mNotificationIDSignal(toast->getNotificationID());
  123. LLNotificationPtr notification = LLNotifications::getInstance()->find(toast->getNotificationID());
  124. if( notification &&
  125. (SCRIPT_DIALOG == notification->getName() || SCRIPT_DIALOG_GROUP == notification->getName()) )
  126. {
  127. LLScriptFloaterManager::getInstance()->onRemoveNotification(notification->getID());
  128. }
  129. }
  130. //--------------------------------------------------------------------------
  131. void LLScriptHandler::onRejectToast(LLUUID& id)
  132. {
  133. LLNotificationPtr notification = LLNotifications::instance().find(id);
  134. if (notification
  135. && LLNotificationManager::getInstance()->getHandlerForNotification(
  136. notification->getType()) == this)
  137. {
  138. LLNotifications::instance().cancel(notification);
  139. }
  140. }
  141. //--------------------------------------------------------------------------