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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
|
/**
* @file llfloaternotificationstabbed.cpp
* @brief
* $LicenseInfo:firstyear=2015&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2015, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h" // must be first include
#include "llfloaternotificationstabbed.h"
#include "llchiclet.h"
#include "llchicletbar.h"
#include "llflatlistview.h"
#include "llfloaterreg.h"
#include "llnotificationmanager.h"
#include "llnotificationsutil.h"
#include "llscriptfloater.h"
#include "llspeakers.h"
#include "lltoastpanel.h"
#include "lltoastnotifypanel.h"
//---------------------------------------------------------------------------------
LLFloaterNotificationsTabbed::LLFloaterNotificationsTabbed(const LLSD& key) : LLTransientDockableFloater(NULL, true, key),
mChannel(NULL),
mSysWellChiclet(NULL),
mGroupInviteMessageList(NULL),
mGroupNoticeMessageList(NULL),
mTransactionMessageList(NULL),
mSystemMessageList(NULL),
mNotificationsSeparator(NULL),
mNotificationsTabContainer(NULL),
NOTIFICATION_TABBED_ANCHOR_NAME("notification_well_panel"),
IM_WELL_ANCHOR_NAME("im_well_panel"),
mIsReshapedByUser(false)
{
setOverlapsScreenChannel(true);
mNotificationUpdates.reset(new NotificationTabbedChannel(this));
mNotificationsSeparator = new LLNotificationSeparator();
}
//---------------------------------------------------------------------------------
BOOL LLFloaterNotificationsTabbed::postBuild()
{
mGroupInviteMessageList = getChild<LLNotificationListView>("group_invite_notification_list");
mGroupNoticeMessageList = getChild<LLNotificationListView>("group_notice_notification_list");
mTransactionMessageList = getChild<LLNotificationListView>("transaction_notification_list");
mSystemMessageList = getChild<LLNotificationListView>("system_notification_list");
mNotificationsSeparator->initTaggedList(LLNotificationListItem::getGroupInviteTypes(), mGroupInviteMessageList);
mNotificationsSeparator->initTaggedList(LLNotificationListItem::getGroupNoticeTypes(), mGroupNoticeMessageList);
mNotificationsSeparator->initTaggedList(LLNotificationListItem::getTransactionTypes(), mTransactionMessageList);
mNotificationsSeparator->initUnTaggedList(mSystemMessageList);
mNotificationsTabContainer = getChild<LLTabContainer>("notifications_tab_container");
mDeleteAllBtn = getChild<LLButton>("delete_all_button");
mDeleteAllBtn->setClickedCallback(boost::bind(&LLFloaterNotificationsTabbed::onClickDeleteAllBtn,this));
mCollapseAllBtn = getChild<LLButton>("collapse_all_button");
mCollapseAllBtn->setClickedCallback(boost::bind(&LLFloaterNotificationsTabbed::onClickCollapseAllBtn,this));
// get a corresponding channel
initChannel();
BOOL rv = LLTransientDockableFloater::postBuild();
setTitle(getString("title_notification_tabbed_window"));
return rv;
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::setMinimized(BOOL minimize)
{
LLTransientDockableFloater::setMinimized(minimize);
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::handleReshape(const LLRect& rect, bool by_user)
{
mIsReshapedByUser |= by_user; // mark floater that it is reshaped by user
LLTransientDockableFloater::handleReshape(rect, by_user);
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::onStartUpToastClick(S32 x, S32 y, MASK mask)
{
// just set floater visible. Screen channels will be cleared.
setVisible(TRUE);
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::setSysWellChiclet(LLSysWellChiclet* chiclet)
{
mSysWellChiclet = chiclet;
if(NULL != mSysWellChiclet)
{
mSysWellChiclet->updateWidget(isWindowEmpty());
}
}
//---------------------------------------------------------------------------------
LLFloaterNotificationsTabbed::~LLFloaterNotificationsTabbed()
{
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::removeItemByID(const LLUUID& id, std::string type)
{
if(mNotificationsSeparator->removeItemByID(type, id))
{
if (NULL != mSysWellChiclet)
{
mSysWellChiclet->updateWidget(isWindowEmpty());
}
reshapeWindow();
updateNotificationCounters();
}
else
{
LL_WARNS() << "Unable to remove notification from the list, ID: " << id
<< LL_ENDL;
}
// hide chiclet window if there are no items left
if(isWindowEmpty())
{
setVisible(FALSE);
}
}
//---------------------------------------------------------------------------------
LLPanel * LLFloaterNotificationsTabbed::findItemByID(const LLUUID& id, std::string type)
{
return mNotificationsSeparator->findItemByID(type, id);
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::initChannel()
{
LLNotificationsUI::LLScreenChannelBase* channel = LLNotificationsUI::LLChannelManager::getInstance()->findChannelByID(
LLUUID(gSavedSettings.getString("NotificationChannelUUID")));
mChannel = dynamic_cast<LLNotificationsUI::LLScreenChannel*>(channel);
if(NULL == mChannel)
{
LL_WARNS() << "LLSysWellWindow::initChannel() - could not get a requested screen channel" << LL_ENDL;
}
if(mChannel)
{
mChannel->addOnStoreToastCallback(boost::bind(&LLFloaterNotificationsTabbed::onStoreToast, this, _1, _2));
}
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::setVisible(BOOL visible)
{
if (visible)
{
// when Notification channel is cleared, storable toasts will be added into the list.
clearScreenChannels();
}
if (visible)
{
if (NULL == getDockControl() && getDockTongue().notNull())
{
setDockControl(new LLDockControl(
LLChicletBar::getInstance()->getChild<LLView>(getAnchorViewName()), this,
getDockTongue(), LLDockControl::BOTTOM));
}
}
// do not show empty window
if (NULL == mNotificationsSeparator || isWindowEmpty()) visible = FALSE;
LLTransientDockableFloater::setVisible(visible);
// update notification channel state
initChannel(); // make sure the channel still exists
if(mChannel)
{
mChannel->updateShowToastsState();
mChannel->redrawToasts();
}
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::setDocked(bool docked, bool pop_on_undock)
{
LLTransientDockableFloater::setDocked(docked, pop_on_undock);
// update notification channel state
if(mChannel)
{
mChannel->updateShowToastsState();
mChannel->redrawToasts();
}
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::reshapeWindow()
{
// update notification channel state
// update on a window reshape is important only when a window is visible and docked
if(mChannel && getVisible() && isDocked())
{
mChannel->updateShowToastsState();
}
}
//---------------------------------------------------------------------------------
bool LLFloaterNotificationsTabbed::isWindowEmpty()
{
return mNotificationsSeparator->size() == 0;
}
//---------------------------------------------------------------------------------
LLFloaterNotificationsTabbed::NotificationTabbedChannel::NotificationTabbedChannel(LLFloaterNotificationsTabbed* notifications_tabbed_window)
: LLNotificationChannel(LLNotificationChannel::Params().name(notifications_tabbed_window->getPathname())),
mNotificationsTabbedWindow(notifications_tabbed_window)
{
connectToChannel("Notifications");
connectToChannel("Group Notifications");
connectToChannel("Offer");
}
// static
//---------------------------------------------------------------------------------
LLFloaterNotificationsTabbed* LLFloaterNotificationsTabbed::getInstance(const LLSD& key /*= LLSD()*/)
{
return LLFloaterReg::getTypedInstance<LLFloaterNotificationsTabbed>("notification_well_window", key);
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::updateNotificationCounter(S32 panelIndex, S32 counterValue, std::string stringName)
{
LLStringUtil::format_map_t string_args;
string_args["[COUNT]"] = llformat("%d", counterValue);
std::string label = getString(stringName, string_args);
mNotificationsTabContainer->setPanelTitle(panelIndex, label);
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::updateNotificationCounters()
{
updateNotificationCounter(0, mSystemMessageList->size(), "system_tab_title");
updateNotificationCounter(1, mTransactionMessageList->size(), "transactions_tab_title");
updateNotificationCounter(2, mGroupInviteMessageList->size(), "group_invitations_tab_title");
updateNotificationCounter(3, mGroupNoticeMessageList->size(), "group_notices_tab_title");
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::addItem(LLNotificationListItem::Params p)
{
// do not add clones
if (mNotificationsSeparator->findItemByID(p.notification_name, p.notification_id))
return;
LLNotificationListItem* new_item = LLNotificationListItem::create(p);
if (new_item == NULL)
{
return;
}
if (mNotificationsSeparator->addItem(new_item->getNotificationName(), new_item))
{
mSysWellChiclet->updateWidget(isWindowEmpty());
reshapeWindow();
updateNotificationCounters();
new_item->setOnItemCloseCallback(boost::bind(&LLFloaterNotificationsTabbed::onItemClose, this, _1));
new_item->setOnItemClickCallback(boost::bind(&LLFloaterNotificationsTabbed::onItemClick, this, _1));
}
else
{
LL_WARNS() << "Unable to add Notification into the list, notification ID: " << p.notification_id
<< ", title: " << new_item->getTitle()
<< LL_ENDL;
new_item->die();
}
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::closeAll()
{
// Need to clear notification channel, to add storable toasts into the list.
clearScreenChannels();
std::vector<LLNotificationListItem*> items;
mNotificationsSeparator->getItems(items);
std::vector<LLNotificationListItem*>::iterator iter = items.begin();
for (; iter != items.end(); ++iter)
{
onItemClose(*iter);
}
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::getAllItemsOnCurrentTab(std::vector<LLPanel*>& items) const
{
switch (mNotificationsTabContainer->getCurrentPanelIndex())
{
case 0:
mSystemMessageList->getItems(items);
break;
case 1:
mTransactionMessageList->getItems(items);
break;
case 2:
mGroupInviteMessageList->getItems(items);
break;
case 3:
mGroupNoticeMessageList->getItems(items);
break;
default:
break;
}
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::closeAllOnCurrentTab()
{
// Need to clear notification channel, to add storable toasts into the list.
clearScreenChannels();
std::vector<LLPanel*> items;
getAllItemsOnCurrentTab(items);
std::vector<LLPanel*>::iterator iter = items.begin();
for (; iter != items.end(); ++iter)
{
LLNotificationListItem* notify_item = dynamic_cast<LLNotificationListItem*>(*iter);
if (notify_item)
onItemClose(notify_item);
}
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::collapseAllOnCurrentTab()
{
std::vector<LLPanel*> items;
getAllItemsOnCurrentTab(items);
std::vector<LLPanel*>::iterator iter = items.begin();
for (; iter != items.end(); ++iter)
{
LLNotificationListItem* notify_item = dynamic_cast<LLNotificationListItem*>(*iter);
if (notify_item)
notify_item->setExpanded(FALSE);
}
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::clearScreenChannels()
{
// 1 - remove StartUp toast and channel if present
if(!LLNotificationsUI::LLScreenChannel::getStartUpToastShown())
{
LLNotificationsUI::LLChannelManager::getInstance()->onStartUpToastClose();
}
// 2 - remove toasts in Notification channel
if(mChannel)
{
mChannel->removeAndStoreAllStorableToasts();
}
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::onStoreToast(LLPanel* info_panel, LLUUID id)
{
LLNotificationListItem::Params p;
p.notification_id = id;
p.title = static_cast<LLToastPanel*>(info_panel)->getTitle();
LLNotificationPtr notify = mChannel->getToastByNotificationID(id)->getNotification();
LLSD payload = notify->getPayload();
p.notification_name = notify->getName();
p.transaction_id = payload["transaction_id"];
p.group_id = payload["group_id"];
p.fee = payload["fee"];
p.use_offline_cap = payload["use_offline_cap"].asInteger();
p.subject = payload["subject"].asString();
p.message = payload["message"].asString();
p.sender = payload["sender_name"].asString();
p.time_stamp = notify->getDate();
p.received_time = payload["received_time"].asDate();
p.paid_from_id = payload["from_id"];
p.paid_to_id = payload["dest_id"];
p.inventory_offer = payload["inventory_offer"];
p.notification_priority = notify->getPriority();
addItem(p);
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::onItemClick(LLNotificationListItem* item)
{
LLUUID id = item->getID();
if (item->showPopup())
{
LLFloaterReg::showInstance("inspect_toast", id);
}
else
{
item->setExpanded(TRUE);
}
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::onItemClose(LLNotificationListItem* item)
{
LLUUID id = item->getID();
if(mChannel)
{
// removeItemByID() is invoked from killToastByNotificationID() and item will removed;
mChannel->killToastByNotificationID(id);
}
else
{
// removeItemByID() should be called one time for each item to remove it from notification well
removeItemByID(id, item->getNotificationName());
}
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::onAdd( LLNotificationPtr notify )
{
removeItemByID(notify->getID(), notify->getName());
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::onClickDeleteAllBtn()
{
closeAllOnCurrentTab();
}
//---------------------------------------------------------------------------------
void LLFloaterNotificationsTabbed::onClickCollapseAllBtn()
{
collapseAllOnCurrentTab();
}
//---------------------------------------------------------------------------------
void LLNotificationSeparator::initTaggedList(const std::string& tag, LLNotificationListView* list)
{
mNotificationListMap.insert(notification_list_map_t::value_type(tag, list));
mNotificationLists.push_back(list);
}
//---------------------------------------------------------------------------------
void LLNotificationSeparator::initTaggedList(const std::set<std::string>& tags, LLNotificationListView* list)
{
std::set<std::string>::const_iterator it = tags.begin();
for(;it != tags.end();it++)
{
initTaggedList(*it, list);
}
}
//---------------------------------------------------------------------------------
void LLNotificationSeparator::initUnTaggedList(LLNotificationListView* list)
{
mUnTaggedList = list;
}
//---------------------------------------------------------------------------------
bool LLNotificationSeparator::addItem(std::string& tag, LLNotificationListItem* item)
{
notification_list_map_t::iterator it = mNotificationListMap.find(tag);
if (it != mNotificationListMap.end())
{
return it->second->addNotification(item);
}
else if (mUnTaggedList != NULL)
{
return mUnTaggedList->addNotification(item);
}
return false;
}
//---------------------------------------------------------------------------------
bool LLNotificationSeparator::removeItemByID(std::string& tag, const LLUUID& id)
{
notification_list_map_t::iterator it = mNotificationListMap.find(tag);
if (it != mNotificationListMap.end())
{
return it->second->removeItemByValue(id);
}
else if (mUnTaggedList != NULL)
{
return mUnTaggedList->removeItemByValue(id);
}
return false;
}
//---------------------------------------------------------------------------------
U32 LLNotificationSeparator::size() const
{
U32 size = 0;
notification_list_list_t::const_iterator it = mNotificationLists.begin();
for (; it != mNotificationLists.end(); it++)
{
size = size + (*it)->size();
}
if (mUnTaggedList != NULL)
{
size = size + mUnTaggedList->size();
}
return size;
}
//---------------------------------------------------------------------------------
LLPanel* LLNotificationSeparator::findItemByID(std::string& tag, const LLUUID& id)
{
notification_list_map_t::iterator it = mNotificationListMap.find(tag);
if (it != mNotificationListMap.end())
{
return it->second->getItemByValue(id);
}
else if (mUnTaggedList != NULL)
{
return mUnTaggedList->getItemByValue(id);
}
return NULL;
}
//static
//---------------------------------------------------------------------------------
void LLNotificationSeparator::getItemsFromList(std::vector<LLNotificationListItem*>& items, LLNotificationListView* list)
{
std::vector<LLPanel*> list_items;
list->getItems(list_items);
std::vector<LLPanel*>::iterator it = list_items.begin();
for (; it != list_items.end(); ++it)
{
LLNotificationListItem* notify_item = dynamic_cast<LLNotificationListItem*>(*it);
if (notify_item)
items.push_back(notify_item);
}
}
//---------------------------------------------------------------------------------
void LLNotificationSeparator::getItems(std::vector<LLNotificationListItem*>& items) const
{
items.clear();
notification_list_list_t::const_iterator lists_it = mNotificationLists.begin();
for (; lists_it != mNotificationLists.end(); lists_it++)
{
getItemsFromList(items, *lists_it);
}
if (mUnTaggedList != NULL)
{
getItemsFromList(items, mUnTaggedList);
}
}
//---------------------------------------------------------------------------------
LLNotificationSeparator::LLNotificationSeparator()
: mUnTaggedList(NULL)
{}
//---------------------------------------------------------------------------------
LLNotificationSeparator::~LLNotificationSeparator()
{}
|