llchannelmanager.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:7k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llchannelmanager.cpp
  3.  * @brief This class rules screen notification channels.
  4.  *
  5.  * $LicenseInfo:firstyear=2000&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2000-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h" // must be first include
  33. #include "llchannelmanager.h"
  34. #include "llappviewer.h"
  35. #include "llviewercontrol.h"
  36. #include "llviewerwindow.h"
  37. #include "llrootview.h"
  38. #include "llsyswellwindow.h"
  39. #include "llfloaterreg.h"
  40. #include <algorithm>
  41. using namespace LLNotificationsUI;
  42. //--------------------------------------------------------------------------
  43. LLChannelManager::LLChannelManager()
  44. {
  45. LLAppViewer::instance()->setOnLoginCompletedCallback(boost::bind(&LLChannelManager::onLoginCompleted, this));
  46. mChannelList.clear();
  47. mStartUpChannel = NULL;
  48. if(!gViewerWindow)
  49. {
  50. llerrs << "LLChannelManager::LLChannelManager() - viwer window is not initialized yet" << llendl;
  51. }
  52. }
  53. //--------------------------------------------------------------------------
  54. LLChannelManager::~LLChannelManager()
  55. {
  56. for(std::vector<ChannelElem>::iterator it = mChannelList.begin(); it !=  mChannelList.end(); ++it)
  57. {
  58. delete (*it).channel;
  59. }
  60. mChannelList.clear();
  61. }
  62. //--------------------------------------------------------------------------
  63. LLScreenChannel* LLChannelManager::createNotificationChannel()
  64. {
  65. //  creating params for a channel
  66. LLChannelManager::Params p;
  67. p.id = LLUUID(gSavedSettings.getString("NotificationChannelUUID"));
  68. p.channel_align = CA_RIGHT;
  69. // Getting a Channel for our notifications
  70. return dynamic_cast<LLScreenChannel*> (LLChannelManager::getInstance()->getChannel(p));
  71. }
  72. //--------------------------------------------------------------------------
  73. void LLChannelManager::onLoginCompleted()
  74. {
  75. S32 away_notifications = 0;
  76. // calc a number of all offline notifications
  77. for(std::vector<ChannelElem>::iterator it = mChannelList.begin(); it !=  mChannelList.end(); ++it)
  78. {
  79. // don't calc notifications for Nearby Chat
  80. if((*it).channel->getChannelID() == LLUUID(gSavedSettings.getString("NearByChatChannelUUID")))
  81. {
  82. continue;
  83. }
  84. // don't calc notifications for channels that always show their notifications
  85. if(!(*it).channel->getDisplayToastsAlways())
  86. {
  87. away_notifications +=(*it).channel->getNumberOfHiddenToasts();
  88. }
  89. }
  90. away_notifications += gIMMgr->getNumberOfUnreadIM();
  91. if(!away_notifications)
  92. {
  93. onStartUpToastClose();
  94. return;
  95. }
  96. // create a channel for the StartUp Toast
  97. LLChannelManager::Params p;
  98. p.id = LLUUID(gSavedSettings.getString("StartUpChannelUUID"));
  99. p.channel_align = CA_RIGHT;
  100. mStartUpChannel = createChannel(p);
  101. if(!mStartUpChannel)
  102. {
  103. onStartUpToastClose();
  104. return;
  105. }
  106. gViewerWindow->getRootView()->addChild(mStartUpChannel);
  107. // init channel's position and size
  108. S32 channel_right_bound = gViewerWindow->getWorldViewRectScaled().mRight - gSavedSettings.getS32("NotificationChannelRightMargin"); 
  109. S32 channel_width = gSavedSettings.getS32("NotifyBoxWidth");
  110. mStartUpChannel->init(channel_right_bound - channel_width, channel_right_bound);
  111. mStartUpChannel->setMouseDownCallback(boost::bind(&LLNotificationWellWindow::onStartUpToastClick, LLNotificationWellWindow::getInstance(), _2, _3, _4));
  112. mStartUpChannel->setCommitCallback(boost::bind(&LLChannelManager::onStartUpToastClose, this));
  113. mStartUpChannel->createStartUpToast(away_notifications, gSavedSettings.getS32("StartUpToastLifeTime"));
  114. }
  115. //--------------------------------------------------------------------------
  116. void LLChannelManager::onStartUpToastClose()
  117. {
  118. if(mStartUpChannel)
  119. {
  120. mStartUpChannel->setVisible(FALSE);
  121. mStartUpChannel->closeStartUpToast();
  122. removeChannelByID(LLUUID(gSavedSettings.getString("StartUpChannelUUID")));
  123. mStartUpChannel = NULL;
  124. }
  125. // set StartUp Toast Flag to allow all other channels to show incoming toasts
  126. LLScreenChannel::setStartUpToastShown();
  127. }
  128. //--------------------------------------------------------------------------
  129. LLScreenChannelBase* LLChannelManager::addChannel(LLScreenChannelBase* channel)
  130. {
  131. if(!channel)
  132. return 0;
  133. ChannelElem new_elem;
  134. new_elem.id = channel->getChannelID();
  135. new_elem.channel = channel;
  136. mChannelList.push_back(new_elem); 
  137. return channel;
  138. }
  139. LLScreenChannel* LLChannelManager::createChannel(LLChannelManager::Params& p)
  140. {
  141. LLScreenChannel* new_channel = new LLScreenChannel(p.id); 
  142. if(!new_channel)
  143. {
  144. llerrs << "LLChannelManager::getChannel(LLChannelManager::Params& p) - can't create a channel!" << llendl;
  145. }
  146. else
  147. {
  148. new_channel->setToastAlignment(p.toast_align);
  149. new_channel->setChannelAlignment(p.channel_align);
  150. new_channel->setDisplayToastsAlways(p.display_toasts_always);
  151. addChannel(new_channel);
  152. }
  153. return new_channel;
  154. }
  155. LLScreenChannelBase* LLChannelManager::getChannel(LLChannelManager::Params& p)
  156. {
  157. LLScreenChannelBase* new_channel = findChannelByID(p.id);
  158. if(new_channel)
  159. return new_channel;
  160. return createChannel(p);
  161. }
  162. //--------------------------------------------------------------------------
  163. LLScreenChannelBase* LLChannelManager::findChannelByID(const LLUUID id)
  164. {
  165. std::vector<ChannelElem>::iterator it = find(mChannelList.begin(), mChannelList.end(), id); 
  166. if(it != mChannelList.end())
  167. {
  168. return (*it).channel;
  169. }
  170. return NULL;
  171. }
  172. //--------------------------------------------------------------------------
  173. void LLChannelManager::removeChannelByID(const LLUUID id)
  174. {
  175. std::vector<ChannelElem>::iterator it = find(mChannelList.begin(), mChannelList.end(), id); 
  176. if(it != mChannelList.end())
  177. {
  178. mChannelList.erase(it);
  179. }
  180. }
  181. //--------------------------------------------------------------------------
  182. void LLChannelManager::muteAllChannels(bool mute)
  183. {
  184. for (std::vector<ChannelElem>::iterator it = mChannelList.begin();
  185. it != mChannelList.end(); it++)
  186. {
  187. it->channel->setShowToasts(!mute);
  188. }
  189. }
  190. void LLChannelManager::killToastsFromChannel(const LLUUID& channel_id, const LLScreenChannel::Matcher& matcher)
  191. {
  192. LLScreenChannel
  193. * screen_channel =
  194. dynamic_cast<LLScreenChannel*> (findChannelByID(channel_id));
  195. if (screen_channel != NULL)
  196. {
  197. screen_channel->killMatchedToasts(matcher);
  198. }
  199. }