/indra/newview/llnotificationtiphandler.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 168 lines · 106 code · 26 blank · 36 comment · 23 complexity · e054593102d1645ee7cea98df43002ae MD5 · raw file

  1. /**
  2. * @file llnotificationtiphandler.cpp
  3. * @brief Notification Handler Class for 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 "llfloaterreg.h"
  28. #include "llnearbychat.h"
  29. #include "llnearbychatbar.h"
  30. #include "llnotificationhandler.h"
  31. #include "llnotifications.h"
  32. #include "lltoastnotifypanel.h"
  33. #include "llviewercontrol.h"
  34. #include "llviewerwindow.h"
  35. #include "llnotificationmanager.h"
  36. #include "llpaneltiptoast.h"
  37. using namespace LLNotificationsUI;
  38. //--------------------------------------------------------------------------
  39. LLTipHandler::LLTipHandler(e_notification_type type, const LLSD& id)
  40. {
  41. mType = type;
  42. // Getting a Channel for our notifications
  43. mChannel = LLChannelManager::getInstance()->createNotificationChannel();
  44. LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
  45. if(channel)
  46. channel->setOnRejectToastCallback(boost::bind(&LLTipHandler::onRejectToast, this, _1));
  47. }
  48. //--------------------------------------------------------------------------
  49. LLTipHandler::~LLTipHandler()
  50. {
  51. }
  52. //--------------------------------------------------------------------------
  53. void LLTipHandler::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 LLTipHandler::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. // archive message in nearby chat
  77. if (LLHandlerUtil::canLogToNearbyChat(notification))
  78. {
  79. LLHandlerUtil::logToNearbyChat(notification, CHAT_SOURCE_SYSTEM);
  80. // don't show toast if Nearby Chat is opened
  81. LLNearbyChat* nearby_chat = LLNearbyChat::getInstance();
  82. LLNearbyChatBar* nearby_chat_bar = LLNearbyChatBar::getInstance();
  83. if (!nearby_chat_bar->isMinimized() && nearby_chat_bar->getVisible() && nearby_chat->getVisible())
  84. {
  85. return false;
  86. }
  87. }
  88. std::string session_name = notification->getPayload()["SESSION_NAME"];
  89. const std::string name = notification->getSubstitutions()["NAME"];
  90. if (session_name.empty())
  91. {
  92. session_name = name;
  93. }
  94. LLUUID from_id = notification->getPayload()["from_id"];
  95. if (LLHandlerUtil::canLogToIM(notification))
  96. {
  97. LLHandlerUtil::logToIM(IM_NOTHING_SPECIAL, session_name, name,
  98. notification->getMessage(), from_id, from_id);
  99. }
  100. if (LLHandlerUtil::canSpawnIMSession(notification))
  101. {
  102. LLHandlerUtil::spawnIMSession(name, from_id);
  103. }
  104. // don't spawn toast for inventory accepted/declined offers if respective IM window is open (EXT-5909)
  105. if (!LLHandlerUtil::canSpawnToast(notification))
  106. {
  107. return false;
  108. }
  109. LLToastPanel* notify_box = LLToastPanel::buidPanelFromNotification(notification);
  110. LLToast::Params p;
  111. p.notif_id = notification->getID();
  112. p.notification = notification;
  113. p.lifetime_secs = gSavedSettings.getS32("NotificationTipToastLifeTime");
  114. p.panel = notify_box;
  115. p.is_tip = true;
  116. p.can_be_stored = false;
  117. removeExclusiveNotifications(notification);
  118. LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
  119. if(channel)
  120. channel->addToast(p);
  121. }
  122. else if (notify["sigtype"].asString() == "delete")
  123. {
  124. mChannel->killToastByNotificationID(notification->getID());
  125. }
  126. return false;
  127. }
  128. //--------------------------------------------------------------------------
  129. void LLTipHandler::onDeleteToast(LLToast* toast)
  130. {
  131. }
  132. //--------------------------------------------------------------------------
  133. void LLTipHandler::onRejectToast(const LLUUID& id)
  134. {
  135. LLNotificationPtr notification = LLNotifications::instance().find(id);
  136. if (notification
  137. && LLNotificationManager::getInstance()->getHandlerForNotification(
  138. notification->getType()) == this)
  139. {
  140. LLNotifications::instance().cancel(notification);
  141. }
  142. }