/indra/newview/llnotificationmanager.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 140 lines · 80 code · 27 blank · 33 comment · 6 complexity · 38bb480ca569f1185c37fb8dbb1ebd23 MD5 · raw file

  1. /**
  2. * @file llnotificationmanager.cpp
  3. * @brief Class implements a brige between the old and a new notification sistems
  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 "llnotificationmanager.h"
  28. #include "llnearbychathandler.h"
  29. #include "llnotifications.h"
  30. #include <boost/bind.hpp>
  31. using namespace LLNotificationsUI;
  32. //--------------------------------------------------------------------------
  33. LLNotificationManager::LLNotificationManager()
  34. {
  35. mNotifyHandlers.clear();
  36. init();
  37. }
  38. //--------------------------------------------------------------------------
  39. LLNotificationManager::~LLNotificationManager()
  40. {
  41. }
  42. //--------------------------------------------------------------------------
  43. void LLNotificationManager::init()
  44. {
  45. LLNotificationChannel::buildChannel("Notifications", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "notify"));
  46. LLNotificationChannel::buildChannel("NotificationTips", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "notifytip"));
  47. LLNotificationChannel::buildChannel("Group Notifications", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "groupnotify"));
  48. LLNotificationChannel::buildChannel("Alerts", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "alert"));
  49. LLNotificationChannel::buildChannel("AlertModal", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "alertmodal"));
  50. LLNotificationChannel::buildChannel("IM Notifications", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "notifytoast"));
  51. LLNotificationChannel::buildChannel("Offer", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "offer"));
  52. LLNotificationChannel::buildChannel("Hints", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "hint"));
  53. LLNotificationChannel::buildChannel("Browser", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "browser"));
  54. LLNotificationChannel::buildChannel("Outbox", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "outbox"));
  55. LLNotifications::instance().getChannel("Notifications")->connectChanged(boost::bind(&LLNotificationManager::onNotification, this, _1));
  56. LLNotifications::instance().getChannel("NotificationTips")->connectChanged(boost::bind(&LLNotificationManager::onNotification, this, _1));
  57. LLNotifications::instance().getChannel("Group Notifications")->connectChanged(boost::bind(&LLNotificationManager::onNotification, this, _1));
  58. LLNotifications::instance().getChannel("Alerts")->connectChanged(boost::bind(&LLNotificationManager::onNotification, this, _1));
  59. LLNotifications::instance().getChannel("AlertModal")->connectChanged(boost::bind(&LLNotificationManager::onNotification, this, _1));
  60. LLNotifications::instance().getChannel("IM Notifications")->connectChanged(boost::bind(&LLNotificationManager::onNotification, this, _1));
  61. LLNotifications::instance().getChannel("Offer")->connectChanged(boost::bind(&LLNotificationManager::onNotification, this, _1));
  62. LLNotifications::instance().getChannel("Hints")->connectChanged(boost::bind(&LLHintHandler::processNotification, LLHintHandler::getInstance(), _1));
  63. LLNotifications::instance().getChannel("Browser")->connectChanged(boost::bind(&LLBrowserNotification::processNotification, LLBrowserNotification::getInstance(), _1));
  64. LLNotifications::instance().getChannel("Outbox")->connectChanged(boost::bind(&LLOutboxNotification::processNotification, LLOutboxNotification::getInstance(), _1));
  65. mNotifyHandlers["notify"] = boost::shared_ptr<LLEventHandler>(new LLScriptHandler(NT_NOTIFY, LLSD()));
  66. mNotifyHandlers["notifytip"] = boost::shared_ptr<LLEventHandler>(new LLTipHandler(NT_NOTIFY, LLSD()));
  67. mNotifyHandlers["groupnotify"] = boost::shared_ptr<LLEventHandler>(new LLGroupHandler(NT_GROUPNOTIFY, LLSD()));
  68. mNotifyHandlers["alert"] = boost::shared_ptr<LLEventHandler>(new LLAlertHandler(NT_ALERT, LLSD()));
  69. mNotifyHandlers["alertmodal"] = boost::shared_ptr<LLEventHandler>(new LLAlertHandler(NT_ALERT, LLSD()));
  70. static_cast<LLAlertHandler*>(mNotifyHandlers["alertmodal"].get())->setAlertMode(true);
  71. mNotifyHandlers["notifytoast"] = boost::shared_ptr<LLEventHandler>(new LLIMHandler(NT_IMCHAT, LLSD()));
  72. mNotifyHandlers["nearbychat"] = boost::shared_ptr<LLEventHandler>(new LLNearbyChatHandler(NT_NEARBYCHAT, LLSD()));
  73. mNotifyHandlers["offer"] = boost::shared_ptr<LLEventHandler>(new LLOfferHandler(NT_OFFER, LLSD()));
  74. }
  75. //--------------------------------------------------------------------------
  76. bool LLNotificationManager::onNotification(const LLSD& notify)
  77. {
  78. LLSysHandler* handle = NULL;
  79. LLNotificationPtr notification = LLNotifications::instance().find(notify["id"].asUUID());
  80. if (!notification)
  81. return false;
  82. std::string notification_type = notification->getType();
  83. handle = static_cast<LLSysHandler*>(mNotifyHandlers[notification_type].get());
  84. if(!handle)
  85. return false;
  86. return handle->processNotification(notify);
  87. }
  88. //--------------------------------------------------------------------------
  89. void LLNotificationManager::onChat(const LLChat& msg, const LLSD &args)
  90. {
  91. // check ENotificationType argument
  92. switch(args["type"].asInteger())
  93. {
  94. case NT_NEARBYCHAT:
  95. {
  96. LLNearbyChatHandler* handle = dynamic_cast<LLNearbyChatHandler*>(mNotifyHandlers["nearbychat"].get());
  97. if(handle)
  98. handle->processChat(msg, args);
  99. }
  100. break;
  101. default: //no need to handle all enum types
  102. break;
  103. }
  104. }
  105. //--------------------------------------------------------------------------
  106. LLEventHandler* LLNotificationManager::getHandlerForNotification(std::string notification_type)
  107. {
  108. std::map<std::string, boost::shared_ptr<LLEventHandler> >::iterator it = mNotifyHandlers.find(notification_type);
  109. if(it != mNotifyHandlers.end())
  110. return (*it).second.get();
  111. return NULL;
  112. }
  113. //--------------------------------------------------------------------------