1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
/**
* @file LLNearbyChatHandler.cpp
* @brief Nearby chat notification managment
*
* $LicenseInfo:firstyear=2009&license=viewergpl$
*
* Copyright (c) 2009, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "llnearbychathandler.h"
#include "llchatitemscontainerctrl.h"
#include "llnearbychat.h"
#include "llrecentpeople.h"
#include "llviewercontrol.h"
#include "llfloaterreg.h"//for LLFloaterReg::getTypedInstance
#include "llviewerwindow.h"//for screen channel position
//add LLNearbyChatHandler to LLNotificationsUI namespace
using namespace LLNotificationsUI;
//-----------------------------------------------------------------------------------------------
//LLNearbyChatScreenChannel
//-----------------------------------------------------------------------------------------------
LLToastPanelBase* createToastPanel()
{
LLNearbyChatToastPanel* item = LLNearbyChatToastPanel::createInstance();
static S32 chat_item_width = 304;
item->setWidth(chat_item_width);
return item;
}
class LLNearbyChatScreenChannel: public LLScreenChannelBase
{
public:
LLNearbyChatScreenChannel(const LLUUID& id):LLScreenChannelBase(id) { mActiveMessages = 0;};
void init (S32 channel_left, S32 channel_right);
void addNotification (LLSD& notification);
void arrangeToasts ();
void showToastsBottom ();
typedef boost::function<LLToastPanelBase* (void )> create_toast_panel_callback_t;
void setCreatePanelCallback(create_toast_panel_callback_t value) { m_create_toast_panel_callback_t = value;}
void onToastDestroyed (LLToast* toast);
void onToastFade (LLToast* toast);
// hide all toasts from screen, but not remove them from a channel
virtual void hideToastsFromScreen()
{
};
// removes all toasts from a channel
virtual void removeToastsFromChannel()
{
for(std::vector<LLToast*>::iterator it = m_active_toasts.begin(); it != m_active_toasts.end(); ++it)
{
LLToast* toast = (*it);
toast->setVisible(FALSE);
toast->stopTimer();
m_toast_pool.push_back(toast);
}
m_active_toasts.clear();
};
protected:
void createOverflowToast(S32 bottom, F32 timer);
create_toast_panel_callback_t m_create_toast_panel_callback_t;
bool createPoolToast();
std::vector<LLToast*> m_active_toasts;
std::list<LLToast*> m_toast_pool;
S32 mActiveMessages;
};
void LLNearbyChatScreenChannel::init(S32 channel_left, S32 channel_right)
{
S32 channel_top = gViewerWindow->getWorldViewRect().getHeight();
S32 channel_bottom = gViewerWindow->getWorldViewRect().mBottom;
setRect(LLRect(channel_left, channel_top, channel_right, channel_bottom));
setVisible(TRUE);
}
void LLNearbyChatScreenChannel::createOverflowToast(S32 bottom, F32 timer)
{
//we don't need overflow toast in nearby chat
}
void LLNearbyChatScreenChannel::onToastDestroyed(LLToast* toast)
{
}
void LLNearbyChatScreenChannel::onToastFade(LLToast* toast)
{
//fade mean we put toast to toast pool
if(!toast)
return;
m_toast_pool.push_back(toast);
std::vector<LLToast*>::iterator pos = std::find(m_active_toasts.begin(),m_active_toasts.end(),toast);
if(pos!=m_active_toasts.end())
m_active_toasts.erase(pos);
arrangeToasts();
}
bool LLNearbyChatScreenChannel::createPoolToast()
{
LLToastPanelBase* panel= m_create_toast_panel_callback_t();
if(!panel)
return false;
LLToast::Params p;
p.panel = panel;
LLToast* toast = new LLToast(p);
toast->setOnFadeCallback(boost::bind(&LLNearbyChatScreenChannel::onToastFade, this, _1));
toast->setOnToastDestroyedCallback(boost::bind(&LLNearbyChatScreenChannel::onToastDestroyed, this, _1));
m_toast_pool.push_back(toast);
return true;
}
void LLNearbyChatScreenChannel::addNotification(LLSD& notification)
{
//look in pool. if there is any message
if(m_toast_pool.empty())
{
//"pool" is empty - create one more panel
if(!createPoolToast())//created toast will go to pool. so next call will find it
return;
addNotification(notification);
return;
}
//take 1st element from pool, (re)initialize it, put it in active toasts
LLToast* toast = m_toast_pool.back();
m_toast_pool.pop_back();
LLToastPanelBase* panel = dynamic_cast<LLToastPanelBase*>(toast->getPanel());
if(!panel)
return;
panel->init(notification);
toast->reshapeToPanel();
toast->resetTimer();
m_active_toasts.insert(m_active_toasts.begin(),toast);
arrangeToasts();
}
void LLNearbyChatScreenChannel::arrangeToasts()
{
if(m_active_toasts.size() == 0 || mIsHovering)
return;
hideToastsFromScreen();
showToastsBottom();
}
void LLNearbyChatScreenChannel::showToastsBottom()
{
LLRect rect = getRect();
LLRect toast_rect;
S32 bottom = getRect().mBottom;
for(std::vector<LLToast*>::iterator it = m_active_toasts.begin(); it != m_active_toasts.end(); ++it)
{
LLToast* toast = (*it);
toast_rect = toast->getRect();
toast_rect.setLeftTopAndSize(getRect().mLeft, bottom + toast_rect.getHeight()+gSavedSettings.getS32("ToastMargin"), toast_rect.getWidth() ,toast_rect.getHeight());
toast->setRect(toast_rect);
if(toast->getRect().mTop > getRect().getHeight())
{
while(it!=m_active_toasts.end())
{
(*it)->setVisible(FALSE);
(*it)->stopTimer();
m_toast_pool.push_back(*it);
it=m_active_toasts.erase(it);
}
break;
}
toast->setVisible(TRUE);
bottom = toast->getRect().mTop;
}
}
//-----------------------------------------------------------------------------------------------
//LLNearbyChatHandler
//-----------------------------------------------------------------------------------------------
LLNearbyChatHandler::LLNearbyChatHandler(e_notification_type type, const LLSD& id)
{
mType = type;
// Getting a Channel for our notifications
LLNearbyChatScreenChannel* channel = new LLNearbyChatScreenChannel(LLUUID(gSavedSettings.getString("NearByChatChannelUUID")));
LLNearbyChatScreenChannel::create_toast_panel_callback_t callback = createToastPanel;
channel->setCreatePanelCallback(callback);
mChannel = LLChannelManager::getInstance()->addChannel(channel);
mChannel->setOverflowFormatString("You have %d unread nearby chat messages");
}
LLNearbyChatHandler::~LLNearbyChatHandler()
{
}
void LLNearbyChatHandler::initChannel()
{
LLNearbyChat* nearby_chat = LLFloaterReg::getTypedInstance<LLNearbyChat>("nearby_chat", LLSD());
S32 channel_right_bound = nearby_chat->getRect().mRight;
S32 channel_width = nearby_chat->getRect().mRight;
mChannel->init(channel_right_bound - channel_width, channel_right_bound);
}
void LLNearbyChatHandler::processChat(const LLChat& chat_msg)
{
if(chat_msg.mMuted == TRUE)
return;
if(chat_msg.mSourceType == CHAT_SOURCE_AGENT && chat_msg.mFromID.notNull())
LLRecentPeople::instance().add(chat_msg.mFromID);
if(chat_msg.mText.empty())
return;//don't process empty messages
LLNearbyChat* nearby_chat = LLFloaterReg::getTypedInstance<LLNearbyChat>("nearby_chat", LLSD());
nearby_chat->addMessage(chat_msg);
if(nearby_chat->getVisible())
return;//no need in toast if chat is visible
// arrange a channel on a screen
if(!mChannel->getVisible())
{
initChannel();
}
LLUUID id;
id.generate();
LLNearbyChatScreenChannel* channel = dynamic_cast<LLNearbyChatScreenChannel*>(mChannel);
if(channel)
{
LLSD notification;
notification["id"] = id;
notification["message"] = chat_msg.mText;
notification["from"] = chat_msg.mFromName;
notification["from_id"] = chat_msg.mFromID;
notification["time"] = chat_msg.mTime;
notification["source"] = (S32)chat_msg.mSourceType;
channel->addNotification(notification);
}
}
void LLNearbyChatHandler::onDeleteToast(LLToast* toast)
{
}
|