PageRenderTime 30ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/indra/newview/llchannelmanager.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 254 lines | 167 code | 44 blank | 43 comment | 26 complexity | 71adfcf7a98a819ac500b5e5f7da9a90 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llchannelmanager.cpp
  3. * @brief This class rules screen notification channels.
  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 "llchannelmanager.h"
  28. #include "llappviewer.h"
  29. #include "llnotificationstorage.h"
  30. #include "llviewercontrol.h"
  31. #include "llviewerwindow.h"
  32. #include "llrootview.h"
  33. #include "llsyswellwindow.h"
  34. #include "llfloaterreg.h"
  35. #include <algorithm>
  36. using namespace LLNotificationsUI;
  37. //--------------------------------------------------------------------------
  38. LLChannelManager::LLChannelManager()
  39. {
  40. LLAppViewer::instance()->setOnLoginCompletedCallback(boost::bind(&LLChannelManager::onLoginCompleted, this));
  41. mChannelList.clear();
  42. mStartUpChannel = NULL;
  43. if(!gViewerWindow)
  44. {
  45. llerrs << "LLChannelManager::LLChannelManager() - viwer window is not initialized yet" << llendl;
  46. }
  47. }
  48. //--------------------------------------------------------------------------
  49. LLChannelManager::~LLChannelManager()
  50. {
  51. for(std::vector<ChannelElem>::iterator it = mChannelList.begin(); it != mChannelList.end(); ++it)
  52. {
  53. LLScreenChannelBase* channel = it->channel.get();
  54. if (!channel) continue;
  55. delete channel;
  56. }
  57. mChannelList.clear();
  58. }
  59. //--------------------------------------------------------------------------
  60. LLScreenChannel* LLChannelManager::createNotificationChannel()
  61. {
  62. // creating params for a channel
  63. LLScreenChannelBase::Params p;
  64. p.id = LLUUID(gSavedSettings.getString("NotificationChannelUUID"));
  65. p.channel_align = CA_RIGHT;
  66. p.toast_align = NA_TOP;
  67. // Getting a Channel for our notifications
  68. return dynamic_cast<LLScreenChannel*> (LLChannelManager::getInstance()->getChannel(p));
  69. }
  70. //--------------------------------------------------------------------------
  71. void LLChannelManager::onLoginCompleted()
  72. {
  73. S32 away_notifications = 0;
  74. // calc a number of all offline notifications
  75. for(std::vector<ChannelElem>::iterator it = mChannelList.begin(); it != mChannelList.end(); ++it)
  76. {
  77. LLScreenChannelBase* channel = it->channel.get();
  78. if (!channel) continue;
  79. // don't calc notifications for Nearby Chat
  80. if(channel->getChannelID() == LLUUID(gSavedSettings.getString("NearByChatChannelUUID")))
  81. {
  82. continue;
  83. }
  84. // don't calc notifications for channels that always show their notifications
  85. if(!channel->getDisplayToastsAlways())
  86. {
  87. away_notifications +=channel->getNumberOfHiddenToasts();
  88. }
  89. }
  90. away_notifications += gIMMgr->getNumberOfUnreadIM();
  91. if(!away_notifications)
  92. {
  93. onStartUpToastClose();
  94. }
  95. else
  96. {
  97. // create a channel for the StartUp Toast
  98. LLScreenChannelBase::Params p;
  99. p.id = LLUUID(gSavedSettings.getString("StartUpChannelUUID"));
  100. p.channel_align = CA_RIGHT;
  101. mStartUpChannel = createChannel(p);
  102. if(!mStartUpChannel)
  103. {
  104. onStartUpToastClose();
  105. }
  106. else
  107. {
  108. gViewerWindow->getRootView()->addChild(mStartUpChannel);
  109. // init channel's position and size
  110. S32 channel_right_bound = gViewerWindow->getWorldViewRectScaled().mRight - gSavedSettings.getS32("NotificationChannelRightMargin");
  111. S32 channel_width = gSavedSettings.getS32("NotifyBoxWidth");
  112. mStartUpChannel->init(channel_right_bound - channel_width, channel_right_bound);
  113. mStartUpChannel->setMouseDownCallback(boost::bind(&LLNotificationWellWindow::onStartUpToastClick, LLNotificationWellWindow::getInstance(), _2, _3, _4));
  114. mStartUpChannel->setCommitCallback(boost::bind(&LLChannelManager::onStartUpToastClose, this));
  115. mStartUpChannel->createStartUpToast(away_notifications, gSavedSettings.getS32("StartUpToastLifeTime"));
  116. }
  117. }
  118. LLPersistentNotificationStorage::getInstance()->loadNotifications();
  119. }
  120. //--------------------------------------------------------------------------
  121. void LLChannelManager::onStartUpToastClose()
  122. {
  123. if(mStartUpChannel)
  124. {
  125. mStartUpChannel->setVisible(FALSE);
  126. mStartUpChannel->closeStartUpToast();
  127. removeChannelByID(LLUUID(gSavedSettings.getString("StartUpChannelUUID")));
  128. mStartUpChannel = NULL;
  129. }
  130. // set StartUp Toast Flag to allow all other channels to show incoming toasts
  131. LLScreenChannel::setStartUpToastShown();
  132. }
  133. //--------------------------------------------------------------------------
  134. LLScreenChannelBase* LLChannelManager::addChannel(LLScreenChannelBase* channel)
  135. {
  136. if(!channel)
  137. return 0;
  138. ChannelElem new_elem;
  139. new_elem.id = channel->getChannelID();
  140. new_elem.channel = channel->getHandle();
  141. mChannelList.push_back(new_elem);
  142. return channel;
  143. }
  144. LLScreenChannel* LLChannelManager::createChannel(LLScreenChannelBase::Params& p)
  145. {
  146. LLScreenChannel* new_channel = new LLScreenChannel(p);
  147. addChannel(new_channel);
  148. return new_channel;
  149. }
  150. LLScreenChannelBase* LLChannelManager::getChannel(LLScreenChannelBase::Params& p)
  151. {
  152. LLScreenChannelBase* new_channel = findChannelByID(p.id);
  153. if(new_channel)
  154. return new_channel;
  155. return createChannel(p);
  156. }
  157. //--------------------------------------------------------------------------
  158. LLScreenChannelBase* LLChannelManager::findChannelByID(const LLUUID& id)
  159. {
  160. std::vector<ChannelElem>::iterator it = find(mChannelList.begin(), mChannelList.end(), id);
  161. if(it != mChannelList.end())
  162. {
  163. return (*it).channel.get();
  164. }
  165. return NULL;
  166. }
  167. //--------------------------------------------------------------------------
  168. void LLChannelManager::removeChannelByID(const LLUUID& id)
  169. {
  170. std::vector<ChannelElem>::iterator it = find(mChannelList.begin(), mChannelList.end(), id);
  171. if(it != mChannelList.end())
  172. {
  173. mChannelList.erase(it);
  174. }
  175. }
  176. //--------------------------------------------------------------------------
  177. void LLChannelManager::muteAllChannels(bool mute)
  178. {
  179. for (std::vector<ChannelElem>::iterator it = mChannelList.begin();
  180. it != mChannelList.end(); it++)
  181. {
  182. if (it->channel.get())
  183. {
  184. it->channel.get()->setShowToasts(!mute);
  185. }
  186. }
  187. }
  188. void LLChannelManager::killToastsFromChannel(const LLUUID& channel_id, const LLScreenChannel::Matcher& matcher)
  189. {
  190. LLScreenChannel
  191. * screen_channel =
  192. dynamic_cast<LLScreenChannel*> (findChannelByID(channel_id));
  193. if (screen_channel != NULL)
  194. {
  195. screen_channel->killMatchedToasts(matcher);
  196. }
  197. }
  198. // static
  199. LLNotificationsUI::LLScreenChannel* LLChannelManager::getNotificationScreenChannel()
  200. {
  201. LLNotificationsUI::LLScreenChannel* channel = static_cast<LLNotificationsUI::LLScreenChannel*>
  202. (LLNotificationsUI::LLChannelManager::getInstance()->
  203. findChannelByID(LLUUID(gSavedSettings.getString("NotificationChannelUUID"))));
  204. if (channel == NULL)
  205. {
  206. llwarns << "Can't find screen channel by NotificationChannelUUID" << llendl;
  207. llassert(!"Can't find screen channel by NotificationChannelUUID");
  208. }
  209. return channel;
  210. }