PageRenderTime 57ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llimhandler.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 130 lines | 70 code | 23 blank | 37 comment | 12 complexity | 6611039c1d4c46fe572adf9e13944411 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llimhandler.cpp
  3. * @brief Notification Handler Class for IM 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 "llagentdata.h"
  29. #include "llnotifications.h"
  30. #include "lltoastimpanel.h"
  31. #include "llviewerwindow.h"
  32. using namespace LLNotificationsUI;
  33. //--------------------------------------------------------------------------
  34. LLIMHandler::LLIMHandler(e_notification_type type, const LLSD& id)
  35. {
  36. mType = type;
  37. // Getting a Channel for our notifications
  38. mChannel = LLChannelManager::getInstance()->createNotificationChannel();
  39. }
  40. //--------------------------------------------------------------------------
  41. LLIMHandler::~LLIMHandler()
  42. {
  43. }
  44. //--------------------------------------------------------------------------
  45. void LLIMHandler::initChannel()
  46. {
  47. S32 channel_right_bound = gViewerWindow->getWorldViewRectScaled().mRight - gSavedSettings.getS32("NotificationChannelRightMargin");
  48. S32 channel_width = gSavedSettings.getS32("NotifyBoxWidth");
  49. mChannel->init(channel_right_bound - channel_width, channel_right_bound);
  50. }
  51. //--------------------------------------------------------------------------
  52. bool LLIMHandler::processNotification(const LLSD& notify)
  53. {
  54. if(!mChannel)
  55. {
  56. return false;
  57. }
  58. LLNotificationPtr notification = LLNotifications::instance().find(notify["id"].asUUID());
  59. if(!notification)
  60. return false;
  61. // arrange a channel on a screen
  62. if(!mChannel->getVisible())
  63. {
  64. initChannel();
  65. }
  66. if(notify["sigtype"].asString() == "add" || notify["sigtype"].asString() == "change")
  67. {
  68. LLSD substitutions = notification->getSubstitutions();
  69. // According to comments in LLIMMgr::addMessage(), if we get message
  70. // from ourselves, the sender id is set to null. This fixes EXT-875.
  71. LLUUID avatar_id = substitutions["FROM_ID"].asUUID();
  72. if (avatar_id.isNull())
  73. avatar_id = gAgentID;
  74. LLToastIMPanel::Params im_p;
  75. im_p.notification = notification;
  76. im_p.avatar_id = avatar_id;
  77. im_p.from = substitutions["FROM"].asString();
  78. im_p.time = substitutions["TIME"].asString();
  79. im_p.message = substitutions["MESSAGE"].asString();
  80. im_p.session_id = substitutions["SESSION_ID"].asUUID();
  81. LLToastIMPanel* im_box = new LLToastIMPanel(im_p);
  82. LLToast::Params p;
  83. p.notif_id = notification->getID();
  84. p.session_id = im_p.session_id;
  85. p.notification = notification;
  86. p.panel = im_box;
  87. p.can_be_stored = false;
  88. p.on_delete_toast = boost::bind(&LLIMHandler::onDeleteToast, this, _1);
  89. LLScreenChannel* channel = dynamic_cast<LLScreenChannel*>(mChannel);
  90. if(channel)
  91. channel->addToast(p);
  92. // send a signal to the counter manager;
  93. mNewNotificationSignal();
  94. }
  95. else if (notify["sigtype"].asString() == "delete")
  96. {
  97. mChannel->killToastByNotificationID(notification->getID());
  98. }
  99. return false;
  100. }
  101. //--------------------------------------------------------------------------
  102. void LLIMHandler::onDeleteToast(LLToast* toast)
  103. {
  104. // send a signal to the counter manager
  105. mDelNotificationSignal();
  106. }
  107. //--------------------------------------------------------------------------