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
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
|
/**
* @file llnotificationlistitem.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 "llnotificationlistitem.h"
#include "llagent.h"
#include "llgroupactions.h"
#include "llinventoryicon.h"
#include "llwindow.h"
#include "v4color.h"
#include "lltrans.h"
#include "lluicolortable.h"
#include "message.h"
#include "llnotificationsutil.h"
#include <boost/regex.hpp>
LLNotificationListItem::LLNotificationListItem(const Params& p) : LLPanel(p),
mParams(p),
mTitleBox(NULL),
mExpandBtn(NULL),
mCondenseBtn(NULL),
mCloseBtn(NULL),
mCondensedViewPanel(NULL),
mExpandedViewPanel(NULL),
mCondensedHeight(0),
mExpandedHeight(0),
mExpandedHeightResize(0),
mExpanded(false)
{
mNotificationName = p.notification_name;
}
bool LLNotificationListItem::postBuild()
{
bool rv = LLPanel::postBuild();
mTitleBox = getChild<LLTextBox>("notification_title");
mTitleBoxExp = getChild<LLTextBox>("notification_title_exp");
mNoticeTextExp = getChild<LLChatEntry>("notification_text_exp");
mTimeBox = getChild<LLTextBox>("notification_time");
mTimeBoxExp = getChild<LLTextBox>("notification_time_exp");
mExpandBtn = getChild<LLButton>("expand_btn");
mCondenseBtn = getChild<LLButton>("condense_btn");
mCloseBtn = getChild<LLButton>("close_btn");
mCloseBtnExp = getChild<LLButton>("close_expanded_btn");
mTitleBox->setValue(mParams.title);
mTitleBoxExp->setValue(mParams.title);
mNoticeTextExp->setValue(mParams.title);
mNoticeTextExp->setEnabled(FALSE);
mNoticeTextExp->setTextExpandedCallback(boost::bind(&LLNotificationListItem::reshapeNotification, this));
mTitleBox->setContentTrusted(false);
mTitleBoxExp->setContentTrusted(false);
mNoticeTextExp->setContentTrusted(false);
mTimeBox->setValue(buildNotificationDate(mParams.time_stamp));
mTimeBoxExp->setValue(buildNotificationDate(mParams.time_stamp));
mExpandBtn->setClickedCallback(boost::bind(&LLNotificationListItem::onClickExpandBtn,this));
mCondenseBtn->setClickedCallback(boost::bind(&LLNotificationListItem::onClickCondenseBtn,this));
//mCloseBtn and mCloseExpandedBtn share the same callback
mCloseBtn->setClickedCallback(boost::bind(&LLNotificationListItem::onClickCloseBtn,this));
mCloseBtnExp->setClickedCallback(boost::bind(&LLNotificationListItem::onClickCloseBtn,this));
mCondensedViewPanel = getChild<LLPanel>("layout_panel_condensed_view");
mExpandedViewPanel = getChild<LLPanel>("layout_panel_expanded_view");
std::string expanded_height_str = getString("item_expanded_height");
std::string condensed_height_str = getString("item_condensed_height");
mExpandedHeight = (S32)atoi(expanded_height_str.c_str());
mCondensedHeight = (S32)atoi(condensed_height_str.c_str());
setExpanded(FALSE);
return rv;
}
LLNotificationListItem::~LLNotificationListItem()
{
}
//static
std::string LLNotificationListItem::buildNotificationDate(const LLDate& time_stamp, ETimeType time_type)
{
std::string timeStr;
switch(time_type)
{
case Local:
timeStr = "[" + LLTrans::getString("LTimeMthNum") + "]/["
+LLTrans::getString("LTimeDay")+"]/["
+LLTrans::getString("LTimeYear")+"] ["
+LLTrans::getString("LTimeHour")+"]:["
+LLTrans::getString("LTimeMin")+ "]";
break;
case UTC:
timeStr = "[" + LLTrans::getString("UTCTimeMth") + "]/["
+LLTrans::getString("UTCTimeDay")+"]/["
+LLTrans::getString("UTCTimeYr")+"] ["
+LLTrans::getString("UTCTimeHr")+"]:["
+LLTrans::getString("UTCTimeMin")+"] ["
+LLTrans::getString("UTCTimeTimezone")+"]";
break;
case SLT:
default:
timeStr = "[" + LLTrans::getString("TimeMonth") + "]/["
+LLTrans::getString("TimeDay")+"]/["
+LLTrans::getString("TimeYear")+"] ["
+LLTrans::getString("TimeHour")+"]:["
+LLTrans::getString("TimeMin")+"] ["
+LLTrans::getString("TimeTimezone")+"]";
break;
}
LLSD substitution;
substitution["datetime"] = time_stamp;
LLStringUtil::format(timeStr, substitution);
return timeStr;
}
void LLNotificationListItem::onClickCloseBtn()
{
mOnItemClose(this);
close();
}
bool LLNotificationListItem::handleMouseUp(S32 x, S32 y, MASK mask)
{
bool res = LLPanel::handleMouseUp(x, y, mask);
mOnItemClick(this);
return res;
}
void LLNotificationListItem::onMouseEnter(S32 x, S32 y, MASK mask)
{
mCondensedViewPanel->setTransparentColor(LLUIColorTable::instance().getColor( "ScrollHoveredColor" ));
mExpandedViewPanel->setTransparentColor(LLUIColorTable::instance().getColor( "ScrollHoveredColor" ));
}
void LLNotificationListItem::onMouseLeave(S32 x, S32 y, MASK mask)
{
mCondensedViewPanel->setTransparentColor(LLUIColorTable::instance().getColor( "SysWellItemUnselected" ));
mExpandedViewPanel->setTransparentColor(LLUIColorTable::instance().getColor( "SysWellItemUnselected" ));
}
//static
LLNotificationListItem* LLNotificationListItem::create(const Params& p)
{
if (LLNotificationListItem::getGroupInviteTypes().count(p.notification_name))
{
return new LLGroupInviteNotificationListItem(p);
}
else if (LLNotificationListItem::getGroupNoticeTypes().count(p.notification_name))
{
return new LLGroupNoticeNotificationListItem(p);
}
else if (LLNotificationListItem::getTransactionTypes().count(p.notification_name))
{
return new LLTransactionNotificationListItem(p);
}
return new LLSystemNotificationListItem(p);
}
//static
std::set<std::string> LLNotificationListItem::getGroupInviteTypes()
{
return LLGroupInviteNotificationListItem::getTypes();
}
std::set<std::string> LLNotificationListItem::getGroupNoticeTypes()
{
return LLGroupNoticeNotificationListItem::getTypes();
}
//static
std::set<std::string> LLNotificationListItem::getTransactionTypes()
{
return LLTransactionNotificationListItem::getTypes();
}
void LLNotificationListItem::onClickExpandBtn()
{
setExpanded(TRUE);
}
void LLNotificationListItem::onClickCondenseBtn()
{
setExpanded(FALSE);
}
void LLNotificationListItem::reshapeNotification()
{
if(mExpanded)
{
S32 width = this->getRect().getWidth();
this->reshape(width, mNoticeTextExp->getRect().getHeight() + mExpandedHeight, FALSE);
}
}
void LLNotificationListItem::setExpanded(BOOL value)
{
mCondensedViewPanel->setVisible(!value);
mExpandedViewPanel->setVisible(value);
S32 width = this->getRect().getWidth();
if (value)
{
this->reshape(width, mNoticeTextExp->getRect().getHeight() + mExpandedHeight, FALSE);
}
else
{
this->reshape(width, mCondensedHeight, FALSE);
}
mExpanded = value;
}
std::set<std::string> LLGroupInviteNotificationListItem::getTypes()
{
std::set<std::string> types;
types.insert("JoinGroup");
return types;
}
std::set<std::string> LLGroupNoticeNotificationListItem::getTypes()
{
std::set<std::string> types;
types.insert("GroupNotice");
return types;
}
std::set<std::string> LLTransactionNotificationListItem::getTypes()
{
std::set<std::string> types;
types.insert("PaymentReceived");
types.insert("PaymentSent");
types.insert("UploadPayment");
return types;
}
LLGroupNotificationListItem::LLGroupNotificationListItem(const Params& p)
: LLNotificationListItem(p),
mSenderOrFeeBox(NULL)
{
}
LLGroupInviteNotificationListItem::LLGroupInviteNotificationListItem(const Params& p)
: LLGroupNotificationListItem(p)
{
buildFromFile("panel_notification_list_item.xml");
}
bool LLGroupInviteNotificationListItem::postBuild()
{
bool rv = LLGroupNotificationListItem::postBuild();
setFee(mParams.fee);
mInviteButtonPanel = getChild<LLPanel>("button_panel");
mInviteButtonPanel->setVisible(true);
mJoinBtn = getChild<LLButton>("join_btn");
mDeclineBtn = getChild<LLButton>("decline_btn");
mInfoBtn = getChild<LLButton>("info_btn");
//invitation with any non-default group role, doesn't have newline characters at the end unlike simple invitations
std::string invitation_desc = mNoticeTextExp->getValue().asString();
if (invitation_desc.substr(invitation_desc.size() - 2) != "\n\n")
{
invitation_desc += "\n\n";
mNoticeTextExp->setValue(invitation_desc);
}
mJoinBtn->setClickedCallback(boost::bind(&LLGroupInviteNotificationListItem::onClickJoinBtn,this));
mDeclineBtn->setClickedCallback(boost::bind(&LLGroupInviteNotificationListItem::onClickDeclineBtn,this));
mInfoBtn->setClickedCallback(boost::bind(&LLGroupInviteNotificationListItem::onClickInfoBtn,this));
std::string expanded_height_resize_str = getString("expanded_height_resize_for_attachment");
mExpandedHeightResize = (S32)atoi(expanded_height_resize_str.c_str());
return rv;
}
void LLGroupInviteNotificationListItem::onClickJoinBtn()
{
if (!gAgent.canJoinGroups())
{
LLNotificationsUtil::add("JoinedTooManyGroups");
return;
}
send_join_group_response(mParams.group_id, mParams.transaction_id, true, mParams.fee, mParams.use_offline_cap);
LLNotificationListItem::onClickCloseBtn();
}
void LLGroupInviteNotificationListItem::onClickDeclineBtn()
{
send_join_group_response(mParams.group_id, mParams.transaction_id, false, mParams.fee, mParams.use_offline_cap);
LLNotificationListItem::onClickCloseBtn();
}
void LLGroupInviteNotificationListItem::onClickInfoBtn()
{
LLGroupActions::show(mParams.group_id);
}
void LLGroupInviteNotificationListItem::setFee(S32 fee)
{
LLStringUtil::format_map_t string_args;
string_args["[GROUP_FEE]"] = llformat("%d", fee);
std::string fee_text = getString("group_fee_text", string_args);
mSenderOrFeeBox->setValue(fee_text);
mSenderOrFeeBoxExp->setValue(fee_text);
mSenderOrFeeBox->setVisible(TRUE);
mSenderOrFeeBoxExp->setVisible(TRUE);
}
LLGroupNoticeNotificationListItem::LLGroupNoticeNotificationListItem(const Params& p)
: LLGroupNotificationListItem(p),
mAttachmentPanel(NULL),
mAttachmentTextBox(NULL),
mAttachmentIcon(NULL),
mAttachmentIconExp(NULL),
mInventoryOffer(NULL)
{
if (mParams.inventory_offer.isDefined())
{
mInventoryOffer = new LLOfferInfo(mParams.inventory_offer);
}
buildFromFile("panel_notification_list_item.xml");
}
LLGroupNotificationListItem::~LLGroupNotificationListItem()
{
LLGroupMgr::getInstance()->removeObserver(this);
}
bool LLGroupNoticeNotificationListItem::postBuild()
{
bool rv = LLGroupNotificationListItem::postBuild();
mAttachmentTextBox = getChild<LLTextBox>("attachment_text");
mAttachmentIcon = getChild<LLIconCtrl>("attachment_icon");
mAttachmentIconExp = getChild<LLIconCtrl>("attachment_icon_exp");
mAttachmentPanel = getChild<LLPanel>("attachment_panel");
mAttachmentPanel->setVisible(FALSE);
mTitleBox->setValue(mParams.subject);
mTitleBoxExp->setValue(mParams.subject);
mNoticeTextExp->setValue(mParams.message);
mTimeBox->setValue(buildNotificationDate(mParams.time_stamp));
mTimeBoxExp->setValue(buildNotificationDate(mParams.time_stamp));
//Workaround: in case server timestamp is 0 - we use the time when notification was actually received
if (mParams.time_stamp.isNull())
{
mTimeBox->setValue(buildNotificationDate(mParams.received_time));
mTimeBoxExp->setValue(buildNotificationDate(mParams.received_time));
}
setSender(mParams.sender);
if (mInventoryOffer != NULL)
{
mAttachmentTextBox->setValue(mInventoryOffer->mDesc);
mAttachmentTextBox->setVisible(TRUE);
mAttachmentIcon->setVisible(TRUE);
std::string icon_name = LLInventoryIcon::getIconName(mInventoryOffer->mType,
LLInventoryType::IT_TEXTURE);
mAttachmentIconExp->setValue(icon_name);
mAttachmentIconExp->setVisible(TRUE);
mAttachmentTextBox->setClickedCallback(boost::bind(
&LLGroupNoticeNotificationListItem::onClickAttachment, this));
std::string expanded_height_resize_str = getString("expanded_height_resize_for_attachment");
mExpandedHeightResize = (S32)atoi(expanded_height_resize_str.c_str());
mAttachmentPanel->setVisible(TRUE);
}
return rv;
}
bool LLGroupNotificationListItem::postBuild()
{
bool rv = LLNotificationListItem::postBuild();
mGroupIcon = getChild<LLGroupIconCtrl>("group_icon");
mGroupIconExp = getChild<LLGroupIconCtrl>("group_icon_exp");
mGroupNameBoxExp = getChild<LLTextBox>("group_name_exp");
mGroupIcon->setValue(mParams.group_id);
mGroupIconExp->setValue(mParams.group_id);
mGroupIcon->setVisible(TRUE);
mGroupIconExp->setVisible(TRUE);
mGroupId = mParams.group_id;
mSenderOrFeeBox = getChild<LLTextBox>("sender_or_fee_box");
mSenderOrFeeBoxExp = getChild<LLTextBox>("sender_or_fee_box_exp");
LLSD value(mParams.group_id);
setGroupId(value);
return rv;
}
void LLGroupNotificationListItem::changed(LLGroupChange gc)
{
if (GC_PROPERTIES == gc)
{
updateFromCache();
LLGroupMgr::getInstance()->removeObserver(this);
}
}
bool LLGroupNotificationListItem::updateFromCache()
{
LLGroupMgrGroupData* group_data = LLGroupMgr::getInstance()->getGroupData(mGroupId);
if (!group_data) return false;
setGroupName(group_data->mName);
return true;
}
void LLGroupNotificationListItem::setGroupId(const LLUUID& value)
{
LLGroupMgr* gm = LLGroupMgr::getInstance();
if (mGroupId.notNull())
{
gm->removeObserver(this);
mID = mGroupId;
// Check if cache already contains image_id for that group
if (!updateFromCache())
{
gm->addObserver(this);
gm->sendGroupPropertiesRequest(mGroupId);
}
}
}
void LLGroupNotificationListItem::setGroupName(std::string name)
{
if (!name.empty())
{
LLStringUtil::format_map_t string_args;
string_args["[GROUP_NAME]"] = llformat("%s", name.c_str());
std::string group_box_str = getString("group_name_text", string_args);
mGroupNameBoxExp->setValue(group_box_str);
mGroupNameBoxExp->setVisible(TRUE);
}
else
{
mGroupNameBoxExp->setValue(LLStringUtil::null);
mGroupNameBoxExp->setVisible(FALSE);
}
}
void LLGroupNoticeNotificationListItem::setSender(std::string sender)
{
if (!sender.empty())
{
LLStringUtil::format_map_t string_args;
string_args["[SENDER_RESIDENT]"] = llformat("%s", sender.c_str());
std::string sender_text = getString("sender_resident_text", string_args);
mSenderOrFeeBox->setValue(sender_text);
mSenderOrFeeBoxExp->setValue(sender_text);
mSenderOrFeeBox->setVisible(TRUE);
mSenderOrFeeBoxExp->setVisible(TRUE);
} else {
mSenderOrFeeBox->setValue(LLStringUtil::null);
mSenderOrFeeBoxExp->setValue(LLStringUtil::null);
mSenderOrFeeBox->setVisible(FALSE);
mSenderOrFeeBoxExp->setVisible(FALSE);
}
}
void LLGroupNoticeNotificationListItem::close()
{
// The group notice dialog may be an inventory offer.
// If it has an inventory save button and that button is still enabled
// Then we need to send the inventory declined message
if (mInventoryOffer != NULL)
{
mInventoryOffer->forceResponse(IOR_DECLINE);
mInventoryOffer = NULL;
}
}
void LLGroupNoticeNotificationListItem::onClickAttachment()
{
if (mInventoryOffer != NULL) {
static const LLUIColor textColor = LLUIColorTable::instance().getColor(
"GroupNotifyDimmedTextColor");
mAttachmentTextBox->setColor(textColor);
mAttachmentIconExp->setEnabled(FALSE);
//if attachment isn't openable - notify about saving
if (!isAttachmentOpenable(mInventoryOffer->mType)) {
LLNotifications::instance().add("AttachmentSaved", LLSD(), LLSD());
}
mInventoryOffer->forceResponse(IOR_ACCEPT);
mInventoryOffer = NULL;
}
}
//static
bool LLGroupNoticeNotificationListItem::isAttachmentOpenable(LLAssetType::EType type)
{
switch (type)
{
case LLAssetType::AT_LANDMARK:
case LLAssetType::AT_NOTECARD:
case LLAssetType::AT_IMAGE_JPEG:
case LLAssetType::AT_IMAGE_TGA:
case LLAssetType::AT_TEXTURE:
case LLAssetType::AT_TEXTURE_TGA:
return true;
default:
return false;
}
}
LLTransactionNotificationListItem::LLTransactionNotificationListItem(const Params& p)
: LLNotificationListItem(p),
mAvatarIcon(NULL)
{
buildFromFile("panel_notification_list_item.xml");
}
bool LLTransactionNotificationListItem::postBuild()
{
bool rv = LLNotificationListItem::postBuild();
mAvatarIcon = getChild<LLAvatarIconCtrl>("avatar_icon");
mAvatarIconExp = getChild<LLAvatarIconCtrl>("avatar_icon_exp");
mAvatarIcon->setValue("System_Notification");
mAvatarIconExp->setValue("System_Notification");
mAvatarIcon->setVisible(TRUE);
mAvatarIconExp->setVisible(TRUE);
if((GOVERNOR_LINDEN_ID == mParams.paid_to_id) ||
(GOVERNOR_LINDEN_ID == mParams.paid_from_id))
{
return rv;
}
if (mParams.notification_name == "PaymentReceived")
{
mAvatarIcon->setValue(mParams.paid_from_id);
mAvatarIconExp->setValue(mParams.paid_from_id);
}
else if (mParams.notification_name == "PaymentSent")
{
mAvatarIcon->setValue(mParams.paid_to_id);
mAvatarIconExp->setValue(mParams.paid_to_id);
}
return rv;
}
LLSystemNotificationListItem::LLSystemNotificationListItem(const Params& p)
: LLNotificationListItem(p),
mSystemNotificationIcon(NULL),
mIsCaution(false)
{
buildFromFile("panel_notification_list_item.xml");
mIsCaution = p.notification_priority >= NOTIFICATION_PRIORITY_HIGH;
if (mIsCaution)
{
mTitleBox->setColor(LLUIColorTable::instance().getColor("NotifyCautionBoxColor"));
mTitleBoxExp->setColor(LLUIColorTable::instance().getColor("NotifyCautionBoxColor"));
mNoticeTextExp->setReadOnlyColor(LLUIColorTable::instance().getColor("NotifyCautionBoxColor"));
mTimeBox->setColor(LLUIColorTable::instance().getColor("NotifyCautionBoxColor"));
mTimeBoxExp->setColor(LLUIColorTable::instance().getColor("NotifyCautionBoxColor"));
}
}
bool LLSystemNotificationListItem::postBuild()
{
bool rv = LLNotificationListItem::postBuild();
mSystemNotificationIcon = getChild<LLIconCtrl>("system_notification_icon");
mSystemNotificationIconExp = getChild<LLIconCtrl>("system_notification_icon_exp");
if (mSystemNotificationIcon)
mSystemNotificationIcon->setVisible(TRUE);
if (mSystemNotificationIconExp)
mSystemNotificationIconExp->setVisible(TRUE);
return rv;
}
|