/indra/newview/llnotificationgrouphandler.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 133 lines · 73 code · 22 blank · 38 comment · 15 complexity · 6602f0a0258654f56af87a0bcf69491c MD5 · raw file

  1. /**
  2. * @file llnotificationgrouphandler.cpp
  3. * @brief Notification Handler Class for Group 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 "lltoastgroupnotifypanel.h"
  29. #include "llgroupactions.h"
  30. #include "llviewercontrol.h"
  31. #include "llviewerwindow.h"
  32. #include "llnotificationmanager.h"
  33. #include "llnotifications.h"
  34. using namespace LLNotificationsUI;
  35. //--------------------------------------------------------------------------
  36. LLGroupHandler::LLGroupHandler(e_notification_type type, const LLSD& id)
  37. {
  38. mType = type;
  39. // Getting a Channel for our notifications
  40. mChannel = LLChannelManager::getInstance()->createNotificationChannel();
  41. LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
  42. if(channel)
  43. channel->setOnRejectToastCallback(boost::bind(&LLGroupHandler::onRejectToast, this, _1));
  44. }
  45. //--------------------------------------------------------------------------
  46. LLGroupHandler::~LLGroupHandler()
  47. {
  48. }
  49. //--------------------------------------------------------------------------
  50. void LLGroupHandler::initChannel()
  51. {
  52. S32 channel_right_bound = gViewerWindow->getWorldViewRectScaled().mRight - gSavedSettings.getS32("NotificationChannelRightMargin");
  53. S32 channel_width = gSavedSettings.getS32("NotifyBoxWidth");
  54. mChannel->init(channel_right_bound - channel_width, channel_right_bound);
  55. }
  56. //--------------------------------------------------------------------------
  57. bool LLGroupHandler::processNotification(const LLSD& notify)
  58. {
  59. if(!mChannel)
  60. {
  61. return false;
  62. }
  63. LLNotificationPtr notification = LLNotifications::instance().find(notify["id"].asUUID());
  64. if(!notification)
  65. return false;
  66. // arrange a channel on a screen
  67. if(!mChannel->getVisible())
  68. {
  69. initChannel();
  70. }
  71. if(notify["sigtype"].asString() == "add" || notify["sigtype"].asString() == "change")
  72. {
  73. LLHandlerUtil::logGroupNoticeToIMGroup(notification);
  74. LLPanel* notify_box = new LLToastGroupNotifyPanel(notification);
  75. LLToast::Params p;
  76. p.notif_id = notification->getID();
  77. p.notification = notification;
  78. p.panel = notify_box;
  79. p.on_delete_toast = boost::bind(&LLGroupHandler::onDeleteToast, this, _1);
  80. LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
  81. if(channel)
  82. channel->addToast(p);
  83. // send a signal to the counter manager
  84. mNewNotificationSignal();
  85. LLGroupActions::refresh_notices();
  86. }
  87. else if (notify["sigtype"].asString() == "delete")
  88. {
  89. mChannel->killToastByNotificationID(notification->getID());
  90. }
  91. return false;
  92. }
  93. //--------------------------------------------------------------------------
  94. void LLGroupHandler::onDeleteToast(LLToast* toast)
  95. {
  96. // send a signal to the counter manager
  97. mDelNotificationSignal();
  98. // send a signal to a listener to let him perform some action
  99. // in this case listener is a SysWellWindow and it will remove a corresponding item from its list
  100. mNotificationIDSignal(toast->getNotificationID());
  101. }
  102. //--------------------------------------------------------------------------
  103. void LLGroupHandler::onRejectToast(LLUUID& id)
  104. {
  105. LLNotificationPtr notification = LLNotifications::instance().find(id);
  106. if (notification && LLNotificationManager::getInstance()->getHandlerForNotification(notification->getType()) == this)
  107. {
  108. LLNotifications::instance().cancel(notification);
  109. }
  110. }
  111. //--------------------------------------------------------------------------