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

/indra/newview/llnotificationalerthandler.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 146 lines | 84 code | 26 blank | 36 comment | 15 complexity | 861cc4ac8ceed6f137362b8947fa7e3e MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llnotificationalerthandler.cpp
  3. * @brief Notification Handler Class for Alert 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. #include "llviewerprecompiledheaders.h" // must be first include
  27. #include "llnotificationhandler.h"
  28. #include "llnotifications.h"
  29. #include "llprogressview.h"
  30. #include "lltoastnotifypanel.h"
  31. #include "llviewercontrol.h"
  32. #include "llviewerwindow.h"
  33. #include "lltoastalertpanel.h"
  34. using namespace LLNotificationsUI;
  35. //--------------------------------------------------------------------------
  36. LLAlertHandler::LLAlertHandler(e_notification_type type, const LLSD& id) : mIsModal(false)
  37. {
  38. mType = type;
  39. LLScreenChannelBase::Params p;
  40. p.id = LLUUID(gSavedSettings.getString("AlertChannelUUID"));
  41. p.display_toasts_always = true;
  42. p.toast_align = NA_CENTRE;
  43. p.channel_align = CA_CENTRE;
  44. // Getting a Channel for our notifications
  45. mChannel = LLChannelManager::getInstance()->getChannel(p);
  46. mChannel->setCanStoreToasts(false);
  47. }
  48. //--------------------------------------------------------------------------
  49. LLAlertHandler::~LLAlertHandler()
  50. {
  51. }
  52. //--------------------------------------------------------------------------
  53. void LLAlertHandler::initChannel()
  54. {
  55. S32 channel_right_bound = gViewerWindow->getWorldViewRectScaled().getWidth() / 2;
  56. mChannel->init(channel_right_bound, channel_right_bound);
  57. }
  58. //--------------------------------------------------------------------------
  59. bool LLAlertHandler::processNotification(const LLSD& notify)
  60. {
  61. if(!mChannel)
  62. {
  63. return false;
  64. }
  65. LLNotificationPtr notification = LLNotifications::instance().find(notify["id"].asUUID());
  66. if(!notification)
  67. return false;
  68. // arrange a channel on a screen
  69. if(!mChannel->getVisible())
  70. {
  71. initChannel();
  72. }
  73. if (notify["sigtype"].asString() == "add" || notify["sigtype"].asString() == "load")
  74. {
  75. if (LLHandlerUtil::canSpawnSessionAndLogToIM(notification))
  76. {
  77. const std::string name = LLHandlerUtil::getSubstitutionName(notification);
  78. LLUUID from_id = notification->getPayload()["from_id"];
  79. // firstly create session...
  80. LLHandlerUtil::spawnIMSession(name, from_id);
  81. // ...then log message to have IM Well notified about new message
  82. LLHandlerUtil::logToIMP2P(notification);
  83. }
  84. LLToastAlertPanel* alert_dialog = new LLToastAlertPanel(notification, mIsModal);
  85. LLToast::Params p;
  86. p.notif_id = notification->getID();
  87. p.notification = notification;
  88. p.panel = dynamic_cast<LLToastPanel*>(alert_dialog);
  89. p.enable_hide_btn = false;
  90. p.can_fade = false;
  91. p.is_modal = mIsModal;
  92. p.on_delete_toast = boost::bind(&LLAlertHandler::onDeleteToast, this, _1);
  93. // Show alert in middle of progress view (during teleport) (EXT-1093)
  94. LLProgressView* progress = gViewerWindow->getProgressView();
  95. LLRect rc = progress && progress->getVisible() ? progress->getRect() : gViewerWindow->getWorldViewRectScaled();
  96. mChannel->updatePositionAndSize(rc);
  97. LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
  98. if(channel)
  99. channel->addToast(p);
  100. }
  101. else if (notify["sigtype"].asString() == "change")
  102. {
  103. LLToastAlertPanel* alert_dialog = new LLToastAlertPanel(notification, mIsModal);
  104. LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
  105. if(channel)
  106. channel->modifyToastByNotificationID(notification->getID(), (LLToastPanel*)alert_dialog);
  107. }
  108. else
  109. {
  110. LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
  111. if(channel)
  112. channel->killToastByNotificationID(notification->getID());
  113. }
  114. return false;
  115. }
  116. //--------------------------------------------------------------------------
  117. void LLAlertHandler::onDeleteToast(LLToast* toast)
  118. {
  119. }
  120. //--------------------------------------------------------------------------