PageRenderTime 32ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llnotificationofferhandler.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 213 lines | 139 code | 30 blank | 44 comment | 33 complexity | 394093bc212e106fb6bb3a1b4fb1bcfc MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llnotificationofferhandler.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. #include "llimview.h"
  35. #include "llnotificationsutil.h"
  36. using namespace LLNotificationsUI;
  37. //--------------------------------------------------------------------------
  38. LLOfferHandler::LLOfferHandler(e_notification_type type, const LLSD& id)
  39. {
  40. mType = type;
  41. // Getting a Channel for our notifications
  42. mChannel = LLChannelManager::getInstance()->createNotificationChannel();
  43. mChannel->setControlHovering(true);
  44. LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
  45. if(channel)
  46. channel->setOnRejectToastCallback(boost::bind(&LLOfferHandler::onRejectToast, this, _1));
  47. }
  48. //--------------------------------------------------------------------------
  49. LLOfferHandler::~LLOfferHandler()
  50. {
  51. }
  52. //--------------------------------------------------------------------------
  53. void LLOfferHandler::initChannel()
  54. {
  55. S32 channel_right_bound = gViewerWindow->getWorldViewRectScaled().mRight - gSavedSettings.getS32("NotificationChannelRightMargin");
  56. S32 channel_width = gSavedSettings.getS32("NotifyBoxWidth");
  57. mChannel->init(channel_right_bound - channel_width, channel_right_bound);
  58. }
  59. //--------------------------------------------------------------------------
  60. bool LLOfferHandler::processNotification(const LLSD& notify)
  61. {
  62. if(!mChannel)
  63. {
  64. return false;
  65. }
  66. LLNotificationPtr notification = LLNotifications::instance().find(notify["id"].asUUID());
  67. if(!notification)
  68. return false;
  69. // arrange a channel on a screen
  70. if(!mChannel->getVisible())
  71. {
  72. initChannel();
  73. }
  74. if(notify["sigtype"].asString() == "add" || notify["sigtype"].asString() == "change")
  75. {
  76. if( notification->getPayload().has("give_inventory_notification")
  77. && !notification->getPayload()["give_inventory_notification"] )
  78. {
  79. // This is an original inventory offer, so add a script floater
  80. LLScriptFloaterManager::instance().onAddNotification(notification->getID());
  81. }
  82. else
  83. {
  84. notification->setReusable(LLHandlerUtil::isNotificationReusable(notification));
  85. LLUUID session_id;
  86. if (LLHandlerUtil::canSpawnIMSession(notification))
  87. {
  88. const std::string name = LLHandlerUtil::getSubstitutionName(notification);
  89. LLUUID from_id = notification->getPayload()["from_id"];
  90. session_id = LLHandlerUtil::spawnIMSession(name, from_id);
  91. }
  92. bool show_toast = LLHandlerUtil::canSpawnToast(notification);
  93. bool add_notid_to_im = LLHandlerUtil::canAddNotifPanelToIM(notification);
  94. if (add_notid_to_im)
  95. {
  96. LLHandlerUtil::addNotifPanelToIM(notification);
  97. }
  98. if (notification->getPayload().has("SUPPRESS_TOAST")
  99. && notification->getPayload()["SUPPRESS_TOAST"])
  100. {
  101. LLNotificationsUtil::cancel(notification);
  102. }
  103. else if(show_toast)
  104. {
  105. LLToastNotifyPanel* notify_box = new LLToastNotifyPanel(notification);
  106. // don't close notification on panel destroy since it will be used by IM floater
  107. notify_box->setCloseNotificationOnDestroy(!add_notid_to_im);
  108. LLToast::Params p;
  109. p.notif_id = notification->getID();
  110. p.notification = notification;
  111. p.panel = notify_box;
  112. p.on_delete_toast = boost::bind(&LLOfferHandler::onDeleteToast, this, _1);
  113. // we not save offer notifications to the syswell floater that should be added to the IM floater
  114. p.can_be_stored = !add_notid_to_im;
  115. LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
  116. if(channel)
  117. channel->addToast(p);
  118. // if we not add notification to IM - add it to notification well
  119. if (!add_notid_to_im)
  120. {
  121. // send a signal to the counter manager
  122. mNewNotificationSignal();
  123. }
  124. }
  125. if (LLHandlerUtil::canLogToIM(notification))
  126. {
  127. // log only to file if notif panel can be embedded to IM and IM is opened
  128. if (add_notid_to_im && LLHandlerUtil::isIMFloaterOpened(notification))
  129. {
  130. LLHandlerUtil::logToIMP2P(notification, true);
  131. }
  132. else
  133. {
  134. LLHandlerUtil::logToIMP2P(notification);
  135. }
  136. }
  137. }
  138. }
  139. else if (notify["sigtype"].asString() == "delete")
  140. {
  141. if( notification->getPayload().has("give_inventory_notification")
  142. && !notification->getPayload()["give_inventory_notification"] )
  143. {
  144. // Remove original inventory offer script floater
  145. LLScriptFloaterManager::instance().onRemoveNotification(notification->getID());
  146. }
  147. else
  148. {
  149. if (LLHandlerUtil::canAddNotifPanelToIM(notification)
  150. && !LLHandlerUtil::isIMFloaterOpened(notification))
  151. {
  152. LLHandlerUtil::decIMMesageCounter(notification);
  153. }
  154. mChannel->killToastByNotificationID(notification->getID());
  155. }
  156. }
  157. return false;
  158. }
  159. //--------------------------------------------------------------------------
  160. void LLOfferHandler::onDeleteToast(LLToast* toast)
  161. {
  162. if (!LLHandlerUtil::canAddNotifPanelToIM(toast->getNotification()))
  163. {
  164. // send a signal to the counter manager
  165. mDelNotificationSignal();
  166. }
  167. // send a signal to a listener to let him perform some action
  168. // in this case listener is a SysWellWindow and it will remove a corresponding item from its list
  169. mNotificationIDSignal(toast->getNotificationID());
  170. }
  171. //--------------------------------------------------------------------------
  172. void LLOfferHandler::onRejectToast(LLUUID& id)
  173. {
  174. LLNotificationPtr notification = LLNotifications::instance().find(id);
  175. if (notification
  176. && LLNotificationManager::getInstance()->getHandlerForNotification(
  177. notification->getType()) == this
  178. // don't delete notification since it may be used by IM floater
  179. && !LLHandlerUtil::canAddNotifPanelToIM(notification))
  180. {
  181. LLNotifications::instance().cancel(notification);
  182. }
  183. }