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
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
|
/**
* @file llsidepanelinventory.cpp
* @brief LLPanelObjectInventory class implementation
*
* $LicenseInfo:firstyear=2002&license=viewergpl$
*
* Copyright (c) 2002-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$
*/
//*****************************************************************************
//
// Implementation of the panel inventory - used to view and control a
// task's inventory.
//
//*****************************************************************************
#include "llviewerprecompiledheaders.h"
#include "llpanelobjectinventory.h"
#include "roles_constants.h"
#include "llagent.h"
#include "llcallbacklist.h"
#include "llfloaterbuycurrency.h"
#include "llfloaterreg.h"
#include "llinventorybridge.h"
#include "llinventoryfunctions.h"
#include "llpreviewanim.h"
#include "llpreviewgesture.h"
#include "llpreviewnotecard.h"
#include "llpreviewscript.h"
#include "llpreviewsound.h"
#include "llpreviewtexture.h"
#include "llscrollcontainer.h"
#include "llselectmgr.h"
#include "llsidetray.h"
#include "llstatusbar.h"
#include "lltrans.h"
#include "llviewerregion.h"
#include "llviewerobjectlist.h"
#include "llviewermessage.h"
///----------------------------------------------------------------------------
/// Class LLTaskInvFVBridge
///----------------------------------------------------------------------------
class LLTaskInvFVBridge : public LLFolderViewEventListener
{
protected:
LLUUID mUUID;
std::string mName;
mutable std::string mDisplayName;
LLPanelObjectInventory* mPanel;
U32 mFlags;
LLInventoryItem* findItem() const;
public:
LLTaskInvFVBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name,
U32 flags=0);
virtual ~LLTaskInvFVBridge( void ) {}
virtual LLFontGL::StyleFlags getLabelStyle() const { return LLFontGL::NORMAL; }
virtual std::string getLabelSuffix() const { return LLStringUtil::null; }
static LLTaskInvFVBridge* createObjectBridge(LLPanelObjectInventory* panel,
LLInventoryObject* object);
void showProperties();
void buyItem();
S32 getPrice();
static bool commitBuyItem(const LLSD& notification, const LLSD& response);
// LLFolderViewEventListener functionality
virtual const std::string& getName() const;
virtual const std::string& getDisplayName() const;
virtual PermissionMask getPermissionMask() const { return PERM_NONE; }
/*virtual*/ LLAssetType::EType getPreferredType() const { return LLAssetType::AT_NONE; }
virtual const LLUUID& getUUID() const { return mUUID; }
virtual time_t getCreationDate() const;
virtual LLUIImagePtr getIcon() const;
virtual void openItem();
virtual void closeItem() {}
virtual void previewItem();
virtual void selectItem() {}
virtual BOOL isItemRenameable() const;
virtual BOOL renameItem(const std::string& new_name);
virtual BOOL isItemMovable() const;
virtual BOOL isItemRemovable();
virtual BOOL removeItem();
virtual void removeBatch(LLDynamicArray<LLFolderViewEventListener*>& batch);
virtual void move(LLFolderViewEventListener* parent_listener);
virtual BOOL isItemCopyable() const;
virtual BOOL copyToClipboard() const;
virtual void cutToClipboard();
virtual BOOL isClipboardPasteable() const;
virtual void pasteFromClipboard();
virtual void pasteLinkFromClipboard();
virtual void buildContextMenu(LLMenuGL& menu, U32 flags);
virtual void performAction(LLFolderView* folder, LLInventoryModel* model, std::string action);
virtual BOOL isUpToDate() const { return TRUE; }
virtual BOOL hasChildren() const { return FALSE; }
virtual LLInventoryType::EType getInventoryType() const { return LLInventoryType::IT_NONE; }
// LLDragAndDropBridge functionality
virtual BOOL startDrag(EDragAndDropType* type, LLUUID* id) const;
virtual BOOL dragOrDrop(MASK mask, BOOL drop,
EDragAndDropType cargo_type,
void* cargo_data);
};
LLTaskInvFVBridge::LLTaskInvFVBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name,
U32 flags):
mUUID(uuid),
mName(name),
mPanel(panel),
mFlags(flags)
{
}
LLInventoryItem* LLTaskInvFVBridge::findItem() const
{
LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
if(object)
{
return (LLInventoryItem*)(object->getInventoryObject(mUUID));
}
return NULL;
}
void LLTaskInvFVBridge::showProperties()
{
LLSD key;
key["object"] = mPanel->getTaskUUID();
key["id"] = mUUID;
LLSideTray::getInstance()->showPanel("sidepanel_inventory", key);
/*
LLFloaterProperties* floater = LLFloaterReg::showTypedInstance<LLFloaterProperties>("properties", mUUID);
if (floater)
{
floater->setObjectID(mPanel->getTaskUUID());
}
*/
}
struct LLBuyInvItemData
{
LLUUID mTaskID;
LLUUID mItemID;
LLAssetType::EType mType;
LLBuyInvItemData(const LLUUID& task,
const LLUUID& item,
LLAssetType::EType type) :
mTaskID(task), mItemID(item), mType(type)
{}
};
void LLTaskInvFVBridge::buyItem()
{
llinfos << "LLTaskInvFVBridge::buyItem()" << llendl;
LLInventoryItem* item = findItem();
if(!item || !item->getSaleInfo().isForSale()) return;
LLBuyInvItemData* inv = new LLBuyInvItemData(mPanel->getTaskUUID(),
mUUID,
item->getType());
const LLSaleInfo& sale_info = item->getSaleInfo();
const LLPermissions& perm = item->getPermissions();
const std::string owner_name; // no owner name currently... FIXME?
LLViewerObject* obj;
if( ( obj = gObjectList.findObject( mPanel->getTaskUUID() ) ) && obj->isAttachment() )
{
LLNotifications::instance().add("Cannot_Purchase_an_Attachment");
llinfos << "Attempt to purchase an attachment" << llendl;
delete inv;
}
else
{
LLSD args;
args["PRICE"] = llformat("%d",sale_info.getSalePrice());
args["OWNER"] = owner_name;
if (sale_info.getSaleType() != LLSaleInfo::FS_CONTENTS)
{
U32 next_owner_mask = perm.getMaskNextOwner();
args["MODIFYPERM"] = LLNotifications::instance().getGlobalString((next_owner_mask & PERM_MODIFY) ? "PermYes" : "PermNo");
args["COPYPERM"] = LLNotifications::instance().getGlobalString((next_owner_mask & PERM_COPY) ? "PermYes" : "PermNo");
args["RESELLPERM"] = LLNotifications::instance().getGlobalString((next_owner_mask & PERM_TRANSFER) ? "PermYes" : "PermNo");
}
std::string alertdesc;
switch(sale_info.getSaleType())
{
case LLSaleInfo::FS_ORIGINAL:
alertdesc = owner_name.empty() ? "BuyOriginalNoOwner" : "BuyOriginal";
break;
case LLSaleInfo::FS_CONTENTS:
alertdesc = owner_name.empty() ? "BuyContentsNoOwner" : "BuyContents";
break;
case LLSaleInfo::FS_COPY:
default:
alertdesc = owner_name.empty() ? "BuyCopyNoOwner" : "BuyCopy";
break;
}
LLSD payload;
payload["task_id"] = inv->mTaskID;
payload["item_id"] = inv->mItemID;
payload["type"] = inv->mType;
LLNotifications::instance().add(alertdesc, args, payload, LLTaskInvFVBridge::commitBuyItem);
}
}
S32 LLTaskInvFVBridge::getPrice()
{
LLInventoryItem* item = findItem();
if(item)
{
return item->getSaleInfo().getSalePrice();
}
else
{
return -1;
}
}
// static
bool LLTaskInvFVBridge::commitBuyItem(const LLSD& notification, const LLSD& response)
{
S32 option = LLNotification::getSelectedOption(notification, response);
if(0 == option)
{
LLViewerObject* object = gObjectList.findObject(notification["payload"]["task_id"].asUUID());
if(!object || !object->getRegion()) return false;
LLMessageSystem* msg = gMessageSystem;
msg->newMessageFast(_PREHASH_BuyObjectInventory);
msg->nextBlockFast(_PREHASH_AgentData);
msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
msg->nextBlockFast(_PREHASH_Data);
msg->addUUIDFast(_PREHASH_ObjectID, notification["payload"]["task_id"].asUUID());
msg->addUUIDFast(_PREHASH_ItemID, notification["payload"]["item_id"].asUUID());
msg->addUUIDFast(_PREHASH_FolderID,
gInventory.findCategoryUUIDForType((LLAssetType::EType)notification["payload"]["type"].asInteger()));
msg->sendReliable(object->getRegion()->getHost());
}
return false;
}
const std::string& LLTaskInvFVBridge::getName() const
{
return mName;
}
const std::string& LLTaskInvFVBridge::getDisplayName() const
{
LLInventoryItem* item = findItem();
if(item)
{
if(item->getParentUUID().isNull())
{
if(item->getName() == "Contents")
{
mDisplayName.assign(LLTrans::getString("ViewerObjectContents"));
}
else
{
mDisplayName.assign(item->getName());
}
}
else
{
mDisplayName.assign(item->getName());
}
const LLPermissions& perm(item->getPermissions());
BOOL copy = gAgent.allowOperation(PERM_COPY, perm, GP_OBJECT_MANIPULATE);
BOOL mod = gAgent.allowOperation(PERM_MODIFY, perm, GP_OBJECT_MANIPULATE);
BOOL xfer = gAgent.allowOperation(PERM_TRANSFER, perm, GP_OBJECT_MANIPULATE);
if(!copy)
{
mDisplayName.append(LLTrans::getString("no_copy"));
}
if(!mod)
{
mDisplayName.append(LLTrans::getString("no_modify"));
}
if(!xfer)
{
mDisplayName.append(LLTrans::getString("no_transfer"));
}
}
return mDisplayName;
}
// BUG: No creation dates for task inventory
time_t LLTaskInvFVBridge::getCreationDate() const
{
return 0;
}
LLUIImagePtr LLTaskInvFVBridge::getIcon() const
{
BOOL item_is_multi = FALSE;
if ( mFlags & LLInventoryItem::II_FLAGS_OBJECT_HAS_MULTIPLE_ITEMS )
{
item_is_multi = TRUE;
}
return get_item_icon(LLAssetType::AT_OBJECT, LLInventoryType::IT_OBJECT, 0, item_is_multi );
}
void LLTaskInvFVBridge::openItem()
{
// no-op.
lldebugs << "LLTaskInvFVBridge::openItem()" << llendl;
}
void LLTaskInvFVBridge::previewItem()
{
openItem();
}
BOOL LLTaskInvFVBridge::isItemRenameable() const
{
if(gAgent.isGodlike()) return TRUE;
LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
if(object)
{
LLInventoryItem* item;
item = (LLInventoryItem*)(object->getInventoryObject(mUUID));
if(item && gAgent.allowOperation(PERM_MODIFY, item->getPermissions(),
GP_OBJECT_MANIPULATE, GOD_LIKE))
{
return TRUE;
}
}
return FALSE;
}
BOOL LLTaskInvFVBridge::renameItem(const std::string& new_name)
{
LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
if(object)
{
LLViewerInventoryItem* item = NULL;
item = (LLViewerInventoryItem*)object->getInventoryObject(mUUID);
if(item && (gAgent.allowOperation(PERM_MODIFY, item->getPermissions(),
GP_OBJECT_MANIPULATE, GOD_LIKE)))
{
LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
new_item->rename(new_name);
object->updateInventory(
new_item,
TASK_INVENTORY_ITEM_KEY,
false);
}
}
return TRUE;
}
BOOL LLTaskInvFVBridge::isItemMovable() const
{
//LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
//if(object && (object->permModify() || gAgent.isGodlike()))
//{
// return TRUE;
//}
//return FALSE;
return TRUE;
}
BOOL LLTaskInvFVBridge::isItemRemovable()
{
LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
if(object
&& (object->permModify() || object->permYouOwner()))
{
return TRUE;
}
return FALSE;
}
bool remove_task_inventory_callback(const LLSD& notification, const LLSD& response, LLPanelObjectInventory* panel)
{
S32 option = LLNotification::getSelectedOption(notification, response);
LLViewerObject* object = gObjectList.findObject(notification["payload"]["task_id"].asUUID());
if(option == 0 && object)
{
// yes
LLSD::array_const_iterator list_end = notification["payload"]["inventory_ids"].endArray();
for (LLSD::array_const_iterator list_it = notification["payload"]["inventory_ids"].beginArray();
list_it != list_end;
++list_it)
{
object->removeInventory(list_it->asUUID());
}
// refresh the UI.
panel->refresh();
}
return false;
}
// helper for remove
// ! REFACTOR ! two_uuids_list_t is also defined in llinevntorybridge.h, but differently.
typedef std::pair<LLUUID, std::list<LLUUID> > panel_two_uuids_list_t;
typedef std::pair<LLPanelObjectInventory*, panel_two_uuids_list_t> remove_data_t;
BOOL LLTaskInvFVBridge::removeItem()
{
if(isItemRemovable() && mPanel)
{
LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
if(object)
{
if(object->permModify())
{
// just do it.
object->removeInventory(mUUID);
return TRUE;
}
else
{
remove_data_t* data = new remove_data_t;
data->first = mPanel;
data->second.first = mPanel->getTaskUUID();
data->second.second.push_back(mUUID);
LLSD payload;
payload["task_id"] = mPanel->getTaskUUID();
payload["inventory_ids"].append(mUUID);
LLNotifications::instance().add("RemoveItemWarn", LLSD(), payload, boost::bind(&remove_task_inventory_callback, _1, _2, mPanel));
return FALSE;
}
}
}
return FALSE;
}
void LLTaskInvFVBridge::removeBatch(LLDynamicArray<LLFolderViewEventListener*>& batch)
{
if (!mPanel)
{
return;
}
LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
if (!object)
{
return;
}
if (!object->permModify())
{
LLSD payload;
payload["task_id"] = mPanel->getTaskUUID();
for (S32 i = 0; i < (S32)batch.size(); i++)
{
LLTaskInvFVBridge* itemp = (LLTaskInvFVBridge*)batch[i];
payload["inventory_ids"].append(itemp->getUUID());
}
LLNotifications::instance().add("RemoveItemWarn", LLSD(), payload, boost::bind(&remove_task_inventory_callback, _1, _2, mPanel));
}
else
{
for (S32 i = 0; i < (S32)batch.size(); i++)
{
LLTaskInvFVBridge* itemp = (LLTaskInvFVBridge*)batch[i];
if(itemp->isItemRemovable())
{
// just do it.
object->removeInventory(itemp->getUUID());
}
}
}
}
void LLTaskInvFVBridge::move(LLFolderViewEventListener* parent_listener)
{
}
BOOL LLTaskInvFVBridge::isItemCopyable() const
{
LLInventoryItem* item = findItem();
if(!item) return FALSE;
return gAgent.allowOperation(PERM_COPY, item->getPermissions(),
GP_OBJECT_MANIPULATE);
}
BOOL LLTaskInvFVBridge::copyToClipboard() const
{
return FALSE;
}
void LLTaskInvFVBridge::cutToClipboard()
{
}
BOOL LLTaskInvFVBridge::isClipboardPasteable() const
{
return FALSE;
}
void LLTaskInvFVBridge::pasteFromClipboard()
{
}
void LLTaskInvFVBridge::pasteLinkFromClipboard()
{
}
BOOL LLTaskInvFVBridge::startDrag(EDragAndDropType* type, LLUUID* id) const
{
//llinfos << "LLTaskInvFVBridge::startDrag()" << llendl;
if(mPanel)
{
LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
if(object)
{
LLInventoryItem* inv = NULL;
if((inv = (LLInventoryItem*)object->getInventoryObject(mUUID)))
{
const LLPermissions& perm = inv->getPermissions();
bool can_copy = gAgent.allowOperation(PERM_COPY, perm,
GP_OBJECT_MANIPULATE);
if (object->isAttachment() && !can_copy)
{
//RN: no copy contents of attachments cannot be dragged out
// due to a race condition and possible exploit where
// attached objects do not update their inventory items
// when their contents are manipulated
return FALSE;
}
if((can_copy && perm.allowTransferTo(gAgent.getID()))
|| object->permYouOwner())
// || gAgent.isGodlike())
{
*type = LLAssetType::lookupDragAndDropType(inv->getType());
*id = inv->getUUID();
return TRUE;
}
}
}
}
return FALSE;
}
BOOL LLTaskInvFVBridge::dragOrDrop(MASK mask, BOOL drop,
EDragAndDropType cargo_type,
void* cargo_data)
{
//llinfos << "LLTaskInvFVBridge::dragOrDrop()" << llendl;
return FALSE;
}
// virtual
void LLTaskInvFVBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
{
if (action == "task_buy")
{
// Check the price of the item.
S32 price = getPrice();
if (-1 == price)
{
llwarns << "label_buy_task_bridged_item: Invalid price" << llendl;
}
else
{
if (price > 0 && price > gStatusBar->getBalance())
{
LLFloaterBuyCurrency::buyCurrency("This costs", price);
}
else
{
buyItem();
}
}
}
else if (action == "task_open")
{
openItem();
}
else if (action == "task_properties")
{
showProperties();
}
}
void LLTaskInvFVBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
{
LLInventoryItem* item = findItem();
std::vector<std::string> items;
std::vector<std::string> disabled_items;
if (!item)
{
hide_context_entries(menu, items, disabled_items);
return;
}
if(gAgent.allowOperation(PERM_OWNER, item->getPermissions(),
GP_OBJECT_MANIPULATE)
&& item->getSaleInfo().isForSale())
{
items.push_back(std::string("Task Buy"));
std::string label= LLTrans::getString("Buy");
// Check the price of the item.
S32 price = getPrice();
if (-1 == price)
{
llwarns << "label_buy_task_bridged_item: Invalid price" << llendl;
}
else
{
std::ostringstream info;
info << LLTrans::getString("BuyforL$") << price;
label.assign(info.str());
}
const LLView::child_list_t *list = menu.getChildList();
LLView::child_list_t::const_iterator itor;
for (itor = list->begin(); itor != list->end(); ++itor)
{
std::string name = (*itor)->getName();
LLMenuItemCallGL* menu_itemp = dynamic_cast<LLMenuItemCallGL*>(*itor);
if (name == "Task Buy" && menu_itemp)
{
menu_itemp->setLabel(label);
}
}
}
else
{
items.push_back(std::string("Task Open"));
if (!isItemCopyable())
{
disabled_items.push_back(std::string("Task Open"));
}
}
items.push_back(std::string("Task Properties"));
if(isItemRenameable())
{
items.push_back(std::string("Task Rename"));
}
if(isItemRemovable())
{
items.push_back(std::string("Task Remove"));
}
hide_context_entries(menu, items, disabled_items);
}
///----------------------------------------------------------------------------
/// Class LLTaskFolderBridge
///----------------------------------------------------------------------------
class LLTaskCategoryBridge : public LLTaskInvFVBridge
{
public:
LLTaskCategoryBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name);
virtual LLUIImagePtr getIcon() const;
virtual const std::string& getDisplayName() const { return getName(); }
virtual BOOL isItemRenameable() const;
virtual BOOL renameItem(const std::string& new_name);
virtual BOOL isItemRemovable();
virtual void buildContextMenu(LLMenuGL& menu, U32 flags);
virtual BOOL hasChildren() const;
virtual BOOL startDrag(EDragAndDropType* type, LLUUID* id) const;
virtual BOOL dragOrDrop(MASK mask, BOOL drop,
EDragAndDropType cargo_type,
void* cargo_data);
};
LLTaskCategoryBridge::LLTaskCategoryBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name) :
LLTaskInvFVBridge(panel, uuid, name)
{
}
LLUIImagePtr LLTaskCategoryBridge::getIcon() const
{
return LLUI::getUIImage("Inv_FolderClosed");
}
BOOL LLTaskCategoryBridge::isItemRenameable() const
{
return FALSE;
}
BOOL LLTaskCategoryBridge::renameItem(const std::string& new_name)
{
return FALSE;
}
BOOL LLTaskCategoryBridge::isItemRemovable()
{
return FALSE;
}
void LLTaskCategoryBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
{
std::vector<std::string> items;
std::vector<std::string> disabled_items;
items.push_back(std::string("Task Open"));
hide_context_entries(menu, items, disabled_items);
}
BOOL LLTaskCategoryBridge::hasChildren() const
{
// return TRUE if we have or do know know if we have children.
// *FIX: For now, return FALSE - we will know for sure soon enough.
return FALSE;
}
BOOL LLTaskCategoryBridge::startDrag(EDragAndDropType* type, LLUUID* id) const
{
//llinfos << "LLTaskInvFVBridge::startDrag()" << llendl;
if(mPanel)
{
LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
if(object)
{
LLInventoryItem* inv = NULL;
if((inv = (LLInventoryItem*)object->getInventoryObject(mUUID)))
{
const LLPermissions& perm = inv->getPermissions();
bool can_copy = gAgent.allowOperation(PERM_COPY, perm,
GP_OBJECT_MANIPULATE);
if((can_copy && perm.allowTransferTo(gAgent.getID()))
|| object->permYouOwner())
// || gAgent.isGodlike())
{
*type = LLAssetType::lookupDragAndDropType(inv->getType());
*id = inv->getUUID();
return TRUE;
}
}
}
}
return FALSE;
}
BOOL LLTaskCategoryBridge::dragOrDrop(MASK mask, BOOL drop,
EDragAndDropType cargo_type,
void* cargo_data)
{
//llinfos << "LLTaskCategoryBridge::dragOrDrop()" << llendl;
BOOL accept = FALSE;
LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
if(object)
{
switch(cargo_type)
{
case DAD_CATEGORY:
accept = LLToolDragAndDrop::getInstance()->dadUpdateInventoryCategory(object,drop);
break;
case DAD_TEXTURE:
case DAD_SOUND:
case DAD_LANDMARK:
case DAD_OBJECT:
case DAD_NOTECARD:
case DAD_CLOTHING:
case DAD_BODYPART:
case DAD_ANIMATION:
case DAD_GESTURE:
case DAD_CALLINGCARD:
accept = LLToolDragAndDrop::isInventoryDropAcceptable(object, (LLViewerInventoryItem*)cargo_data);
if(accept && drop)
{
LLToolDragAndDrop::dropInventory(object,
(LLViewerInventoryItem*)cargo_data,
LLToolDragAndDrop::getInstance()->getSource(),
LLToolDragAndDrop::getInstance()->getSourceID());
}
break;
case DAD_SCRIPT:
// *HACK: In order to resolve SL-22177, we need to block
// drags from notecards and objects onto other
// objects. uncomment the simpler version when we have
// that right.
//accept = LLToolDragAndDrop::isInventoryDropAcceptable(object, (LLViewerInventoryItem*)cargo_data);
if(LLToolDragAndDrop::isInventoryDropAcceptable(
object, (LLViewerInventoryItem*)cargo_data)
&& (LLToolDragAndDrop::SOURCE_WORLD != LLToolDragAndDrop::getInstance()->getSource())
&& (LLToolDragAndDrop::SOURCE_NOTECARD != LLToolDragAndDrop::getInstance()->getSource()))
{
accept = TRUE;
}
if(accept && drop)
{
LLViewerInventoryItem* item = (LLViewerInventoryItem*)cargo_data;
// rez in the script active by default, rez in
// inactive if the control key is being held down.
BOOL active = ((mask & MASK_CONTROL) == 0);
LLToolDragAndDrop::dropScript(object, item, active,
LLToolDragAndDrop::getInstance()->getSource(),
LLToolDragAndDrop::getInstance()->getSourceID());
}
break;
default:
break;
}
}
return accept;
}
///----------------------------------------------------------------------------
/// Class LLTaskTextureBridge
///----------------------------------------------------------------------------
class LLTaskTextureBridge : public LLTaskInvFVBridge
{
public:
LLTaskTextureBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name,
LLInventoryType::EType it);
virtual LLUIImagePtr getIcon() const;
virtual void openItem();
protected:
LLInventoryType::EType mInventoryType;
};
LLTaskTextureBridge::LLTaskTextureBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name,
LLInventoryType::EType it) :
LLTaskInvFVBridge(panel, uuid, name),
mInventoryType(it)
{
}
LLUIImagePtr LLTaskTextureBridge::getIcon() const
{
return get_item_icon(LLAssetType::AT_TEXTURE, mInventoryType, 0, FALSE);
}
void LLTaskTextureBridge::openItem()
{
llinfos << "LLTaskTextureBridge::openItem()" << llendl;
LLPreviewTexture* preview = LLFloaterReg::showTypedInstance<LLPreviewTexture>("preview_texture", LLSD(mUUID), TAKE_FOCUS_YES);
if(preview)
{
preview->setObjectID(mPanel->getTaskUUID());
}
}
///----------------------------------------------------------------------------
/// Class LLTaskSoundBridge
///----------------------------------------------------------------------------
class LLTaskSoundBridge : public LLTaskInvFVBridge
{
public:
LLTaskSoundBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name);
virtual LLUIImagePtr getIcon() const;
virtual void openItem();
virtual void performAction(LLFolderView* folder, LLInventoryModel* model, std::string action);
virtual void buildContextMenu(LLMenuGL& menu, U32 flags);
static void openSoundPreview(void* data);
};
LLTaskSoundBridge::LLTaskSoundBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name) :
LLTaskInvFVBridge(panel, uuid, name)
{
}
LLUIImagePtr LLTaskSoundBridge::getIcon() const
{
return get_item_icon(LLAssetType::AT_SOUND, LLInventoryType::IT_SOUND, 0, FALSE);
}
void LLTaskSoundBridge::openItem()
{
openSoundPreview((void*)this);
}
void LLTaskSoundBridge::openSoundPreview(void* data)
{
LLTaskSoundBridge* self = (LLTaskSoundBridge*)data;
if(!self)
return;
LLPreviewSound* preview = LLFloaterReg::showTypedInstance<LLPreviewSound>("preview_sound", LLSD(self->mUUID), TAKE_FOCUS_YES);
if (preview)
{
preview->setObjectID(self->mPanel->getTaskUUID());
}
}
// virtual
void LLTaskSoundBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
{
if (action == "task_play")
{
LLInventoryItem* item = findItem();
if(item)
{
send_sound_trigger(item->getAssetUUID(), 1.0);
}
}
LLTaskInvFVBridge::performAction(folder, model, action);
}
void LLTaskSoundBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
{
LLInventoryItem* item = findItem();
if(!item) return;
std::vector<std::string> items;
std::vector<std::string> disabled_items;
if(item->getPermissions().getOwner() != gAgent.getID()
&& item->getSaleInfo().isForSale())
{
items.push_back(std::string("Task Buy"));
std::string label= LLTrans::getString("Buy");
// Check the price of the item.
S32 price = getPrice();
if (-1 == price)
{
llwarns << "label_buy_task_bridged_item: Invalid price" << llendl;
}
else
{
std::ostringstream info;
info << LLTrans::getString("BuyforL$") << price;
label.assign(info.str());
}
const LLView::child_list_t *list = menu.getChildList();
LLView::child_list_t::const_iterator itor;
for (itor = list->begin(); itor != list->end(); ++itor)
{
std::string name = (*itor)->getName();
LLMenuItemCallGL* menu_itemp = dynamic_cast<LLMenuItemCallGL*>(*itor);
if (name == "Task Buy" && menu_itemp)
{
menu_itemp->setLabel(label);
}
}
}
else
{
items.push_back(std::string("Task Open"));
if (!isItemCopyable())
{
disabled_items.push_back(std::string("Task Open"));
}
}
items.push_back(std::string("Task Properties"));
if(isItemRenameable())
{
items.push_back(std::string("Task Rename"));
}
if(isItemRemovable())
{
items.push_back(std::string("Task Remove"));
}
items.push_back(std::string("Task Play"));
hide_context_entries(menu, items, disabled_items);
}
///----------------------------------------------------------------------------
/// Class LLTaskLandmarkBridge
///----------------------------------------------------------------------------
class LLTaskLandmarkBridge : public LLTaskInvFVBridge
{
public:
LLTaskLandmarkBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name);
virtual LLUIImagePtr getIcon() const;
};
LLTaskLandmarkBridge::LLTaskLandmarkBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name) :
LLTaskInvFVBridge(panel, uuid, name)
{
}
LLUIImagePtr LLTaskLandmarkBridge::getIcon() const
{
return get_item_icon(LLAssetType::AT_LANDMARK, LLInventoryType::IT_LANDMARK, 0, FALSE);
}
///----------------------------------------------------------------------------
/// Class LLTaskCallingCardBridge
///----------------------------------------------------------------------------
class LLTaskCallingCardBridge : public LLTaskInvFVBridge
{
public:
LLTaskCallingCardBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name);
virtual LLUIImagePtr getIcon() const;
virtual BOOL isItemRenameable() const;
virtual BOOL renameItem(const std::string& new_name);
};
LLTaskCallingCardBridge::LLTaskCallingCardBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name) :
LLTaskInvFVBridge(panel, uuid, name)
{
}
LLUIImagePtr LLTaskCallingCardBridge::getIcon() const
{
return get_item_icon(LLAssetType::AT_CALLINGCARD, LLInventoryType::IT_CALLINGCARD, 0, FALSE);
}
BOOL LLTaskCallingCardBridge::isItemRenameable() const
{
return FALSE;
}
BOOL LLTaskCallingCardBridge::renameItem(const std::string& new_name)
{
return FALSE;
}
///----------------------------------------------------------------------------
/// Class LLTaskScriptBridge
///----------------------------------------------------------------------------
class LLTaskScriptBridge : public LLTaskInvFVBridge
{
public:
LLTaskScriptBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name);
virtual LLUIImagePtr getIcon() const;
//static BOOL enableIfCopyable( void* userdata );
};
LLTaskScriptBridge::LLTaskScriptBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name) :
LLTaskInvFVBridge(panel, uuid, name)
{
}
LLUIImagePtr LLTaskScriptBridge::getIcon() const
{
return get_item_icon(LLAssetType::AT_SCRIPT, LLInventoryType::IT_LSL, 0, FALSE);
}
class LLTaskLSLBridge : public LLTaskScriptBridge
{
public:
LLTaskLSLBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name);
virtual void openItem();
virtual BOOL removeItem();
//virtual void buildContextMenu(LLMenuGL& menu);
//static void copyToInventory(void* userdata);
};
LLTaskLSLBridge::LLTaskLSLBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name) :
LLTaskScriptBridge(panel, uuid, name)
{
}
void LLTaskLSLBridge::openItem()
{
llinfos << "LLTaskLSLBridge::openItem() " << mUUID << llendl;
LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
if(!object || object->isInventoryPending())
{
return;
}
LLLiveLSLEditor* preview = LLFloaterReg::showTypedInstance<LLLiveLSLEditor>("preview_scriptedit", LLSD(mUUID), TAKE_FOCUS_YES);
if (preview && (object->permModify() || gAgent.isGodlike()))
{
preview->setObjectID(mPanel->getTaskUUID());
}
}
BOOL LLTaskLSLBridge::removeItem()
{
LLFloaterReg::hideInstance("preview_scriptedit", LLSD(mUUID));
return LLTaskInvFVBridge::removeItem();
}
///----------------------------------------------------------------------------
/// Class LLTaskObjectBridge
///----------------------------------------------------------------------------
class LLTaskObjectBridge : public LLTaskInvFVBridge
{
public:
LLTaskObjectBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name);
virtual LLUIImagePtr getIcon() const;
};
LLTaskObjectBridge::LLTaskObjectBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name) :
LLTaskInvFVBridge(panel, uuid, name)
{
}
LLUIImagePtr LLTaskObjectBridge::getIcon() const
{
BOOL item_is_multi = FALSE;
if ( mFlags & LLInventoryItem::II_FLAGS_OBJECT_HAS_MULTIPLE_ITEMS )
{
item_is_multi = TRUE;
}
return get_item_icon(LLAssetType::AT_OBJECT, LLInventoryType::IT_OBJECT, 0, item_is_multi);
}
///----------------------------------------------------------------------------
/// Class LLTaskNotecardBridge
///----------------------------------------------------------------------------
class LLTaskNotecardBridge : public LLTaskInvFVBridge
{
public:
LLTaskNotecardBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name);
virtual LLUIImagePtr getIcon() const;
virtual void openItem();
virtual BOOL removeItem();
};
LLTaskNotecardBridge::LLTaskNotecardBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name) :
LLTaskInvFVBridge(panel, uuid, name)
{
}
LLUIImagePtr LLTaskNotecardBridge::getIcon() const
{
return get_item_icon(LLAssetType::AT_NOTECARD, LLInventoryType::IT_NOTECARD, 0, FALSE);
}
void LLTaskNotecardBridge::openItem()
{
LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
if(!object || object->isInventoryPending())
{
return;
}
if(object->permModify() || gAgent.isGodlike())
{
LLPreviewNotecard* preview = LLFloaterReg::showTypedInstance<LLPreviewNotecard>("preview_notecard", LLSD(mUUID), TAKE_FOCUS_YES);
if (preview)
{
preview->setObjectID(mPanel->getTaskUUID());
}
}
}
BOOL LLTaskNotecardBridge::removeItem()
{
LLFloaterReg::hideInstance("preview_notecard", LLSD(mUUID));
return LLTaskInvFVBridge::removeItem();
}
///----------------------------------------------------------------------------
/// Class LLTaskGestureBridge
///----------------------------------------------------------------------------
class LLTaskGestureBridge : public LLTaskInvFVBridge
{
public:
LLTaskGestureBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name);
virtual LLUIImagePtr getIcon() const;
virtual void openItem();
virtual BOOL removeItem();
};
LLTaskGestureBridge::LLTaskGestureBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name) :
LLTaskInvFVBridge(panel, uuid, name)
{
}
LLUIImagePtr LLTaskGestureBridge::getIcon() const
{
return get_item_icon(LLAssetType::AT_GESTURE, LLInventoryType::IT_GESTURE, 0, FALSE);
}
void LLTaskGestureBridge::openItem()
{
LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
if(!object || object->isInventoryPending())
{
return;
}
LLPreviewGesture::show(mUUID, mPanel->getTaskUUID());
}
BOOL LLTaskGestureBridge::removeItem()
{
// Don't need to deactivate gesture because gestures inside objects can never be active.
LLFloaterReg::hideInstance("preview_gesture", LLSD(mUUID));
return LLTaskInvFVBridge::removeItem();
}
///----------------------------------------------------------------------------
/// Class LLTaskAnimationBridge
///----------------------------------------------------------------------------
class LLTaskAnimationBridge : public LLTaskInvFVBridge
{
public:
LLTaskAnimationBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name);
virtual LLUIImagePtr getIcon() const;
virtual void openItem();
virtual BOOL removeItem();
};
LLTaskAnimationBridge::LLTaskAnimationBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name) :
LLTaskInvFVBridge(panel, uuid, name)
{
}
LLUIImagePtr LLTaskAnimationBridge::getIcon() const
{
return get_item_icon(LLAssetType::AT_ANIMATION, LLInventoryType::IT_ANIMATION, 0, FALSE);
}
void LLTaskAnimationBridge::openItem()
{
LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
if(!object || object->isInventoryPending())
{
return;
}
LLPreviewAnim* preview = LLFloaterReg::showTypedInstance<LLPreviewAnim>("preview_anim", LLSD(mUUID), TAKE_FOCUS_YES);
if (preview && (object->permModify() || gAgent.isGodlike()))
{
preview->setObjectID(mPanel->getTaskUUID());
}
}
BOOL LLTaskAnimationBridge::removeItem()
{
LLFloaterReg::hideInstance("preview_anim", LLSD(mUUID));
return LLTaskInvFVBridge::removeItem();
}
///----------------------------------------------------------------------------
/// Class LLTaskWearableBridge
///----------------------------------------------------------------------------
class LLTaskWearableBridge : public LLTaskInvFVBridge
{
public:
LLTaskWearableBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name,
LLAssetType::EType asset_type,
U32 flags);
virtual LLUIImagePtr getIcon() const;
protected:
LLAssetType::EType mAssetType;
};
LLTaskWearableBridge::LLTaskWearableBridge(
LLPanelObjectInventory* panel,
const LLUUID& uuid,
const std::string& name,
LLAssetType::EType asset_type,
U32 flags) :
LLTaskInvFVBridge(panel, uuid, name, flags),
mAssetType( asset_type )
{
}
LLUIImagePtr LLTaskWearableBridge::getIcon() const
{
return get_item_icon(mAssetType, LLInventoryType::IT_WEARABLE, mFlags, FALSE );
}
///----------------------------------------------------------------------------
/// LLTaskInvFVBridge impl
//----------------------------------------------------------------------------
LLTaskInvFVBridge* LLTaskInvFVBridge::createObjectBridge(LLPanelObjectInventory* panel,
LLInventoryObject* object)
{
LLTaskInvFVBridge* new_bridge = NULL;
LLAssetType::EType type = object->getType();
LLInventoryItem* item = NULL;
switch(type)
{
case LLAssetType::AT_TEXTURE:
item = (LLInventoryItem*)object;
new_bridge = new LLTaskTextureBridge(panel,
object->getUUID(),
object->getName(),
item->getInventoryType());
break;
case LLAssetType::AT_SOUND:
new_bridge = new LLTaskSoundBridge(panel,
object->getUUID(),
object->getName());
break;
case LLAssetType::AT_LANDMARK:
new_bridge = new LLTaskLandmarkBridge(panel,
object->getUUID(),
object->getName());
break;
case LLAssetType::AT_CALLINGCARD:
new_bridge = new LLTaskCallingCardBridge(panel,
object->getUUID(),
object->getName());
break;
case LLAssetType::AT_SCRIPT:
// OLD SCRIPTS DEPRECATED - JC
llwarns << "Old script" << llendl;
//new_bridge = new LLTaskOldScriptBridge(panel,
// object->getUUID(),
// object->getName());
break;
case LLAssetType::AT_OBJECT:
new_bridge = new LLTaskObjectBridge(panel,
object->getUUID(),
object->getName());
break;
case LLAssetType::AT_NOTECARD:
new_bridge = new LLTaskNotecardBridge(panel,
object->getUUID(),
object->getName());
break;
case LLAssetType::AT_ANIMATION:
new_bridge = new LLTaskAnimationBridge(panel,
object->getUUID(),
object->getName());
break;
case LLAssetType::AT_GESTURE:
new_bridge = new LLTaskGestureBridge(panel,
object->getUUID(),
object->getName());
break;
case LLAssetType::AT_CLOTHING:
case LLAssetType::AT_BODYPART:
item = (LLInventoryItem*)object;
new_bridge = new LLTaskWearableBridge(panel,
object->getUUID(),
object->getName(),
type,
item->getFlags());
break;
case LLAssetType::AT_CATEGORY:
case LLAssetType::AT_FAVORITE:
new_bridge = new LLTaskCategoryBridge(panel,
object->getUUID(),
object->getName());
break;
case LLAssetType::AT_LSL_TEXT:
new_bridge = new LLTaskLSLBridge(panel,
object->getUUID(),
object->getName());
break;
break;
default:
llinfos << "Unhandled inventory type (llassetstorage.h): "
<< (S32)type << llendl;
break;
}
return new_bridge;
}
///----------------------------------------------------------------------------
/// Class LLPanelObjectInventory
///----------------------------------------------------------------------------
static LLDefaultChildRegistry::Register<LLPanelObjectInventory> r("panel_inventory_object");
void do_nothing()
{
}
// Default constructor
LLPanelObjectInventory::LLPanelObjectInventory(const LLPanelObjectInventory::Params& p) :
LLPanel(p),
mScroller(NULL),
mFolders(NULL),
mHaveInventory(FALSE),
mIsInventoryEmpty(TRUE),
mInventoryNeedsUpdate(FALSE)
{
// Setup context menu callbacks
mCommitCallbackRegistrar.add("Inventory.DoToSelected", boost::bind(&LLPanelObjectInventory::doToSelected, this, _2));
mCommitCallbackRegistrar.add("Inventory.EmptyTrash", boost::bind(&LLInventoryModel::emptyFolderType, &gInventory, "ConfirmEmptyTrash", LLAssetType::AT_TRASH));
mCommitCallbackRegistrar.add("Inventory.EmptyLostAndFound", boost::bind(&LLInventoryModel::emptyFolderType, &gInventory, "ConfirmEmptyLostAndFound", LLAssetType::AT_LOST_AND_FOUND));
mCommitCallbackRegistrar.add("Inventory.DoCreate", boost::bind(&do_nothing));
mCommitCallbackRegistrar.add("Inventory.AttachObject", boost::bind(&do_nothing));
mCommitCallbackRegistrar.add("Inventory.BeginIMSession", boost::bind(&do_nothing));
}
// Destroys the object
LLPanelObjectInventory::~LLPanelObjectInventory()
{
if (!gIdleCallbacks.deleteFunction(idle, this))
{
llwarns << "LLPanelObjectInventory::~LLPanelObjectInventory() failed to delete callback" << llendl;
}
}
BOOL LLPanelObjectInventory::postBuild()
{
// clear contents and initialize menus, sets up mFolders
reset();
// Register an idle update callback
gIdleCallbacks.addFunction(idle, this);
return TRUE;
}
void LLPanelObjectInventory::doToSelected(const LLSD& userdata)
{
mFolders->doToSelected(&gInventory, userdata);
}
void LLPanelObjectInventory::clearContents()
{
mHaveInventory = FALSE;
mIsInventoryEmpty = TRUE;
if (LLToolDragAndDrop::getInstance() && LLToolDragAndDrop::getInstance()->getSource() == LLToolDragAndDrop::SOURCE_WORLD)
{
LLToolDragAndDrop::getInstance()->endDrag();
}
if( mScroller )
{
// removes mFolders
removeChild( mScroller ); //*TODO: Really shouldn't do this during draw()/refresh()
mScroller->die();
mScroller = NULL;
mFolders = NULL;
}
}
void LLPanelObjectInventory::reset()
{
clearContents();
setBorderVisible(FALSE);
mCommitCallbackRegistrar.pushScope(); // push local callbacks
LLRect dummy_rect(0, 1, 1, 0);
LLFolderView::Params p;
p.name = "task inventory";
p.task_id = getTaskUUID();
p.parent_panel = this;
mFolders = LLUICtrlFactory::create<LLFolderView>(p);
// this ensures that we never say "searching..." or "no items found"
mFolders->getFilter()->setShowFolderState(LLInventoryFilter::SHOW_ALL_FOLDERS);
mFolders->setCallbackRegistrar(&mCommitCallbackRegistrar);
LLRect scroller_rect(0, getRect().getHeight(), getRect().getWidth(), 0);
LLScrollContainer::Params scroll_p;
scroll_p.name("task inventory scroller");
scroll_p.rect(scroller_rect);
scroll_p.follows.flags(FOLLOWS_ALL);
mScroller = LLUICtrlFactory::create<LLScrollContainer>(scroll_p);
addChild(mScroller);
mScroller->addChild(mFolders);
mFolders->setScrollContainer( mScroller );
mCommitCallbackRegistrar.popScope();
}
void LLPanelObjectInventory::inventoryChanged(LLViewerObject* object,
InventoryObjectList* inventory,
S32 serial_num,
void* data)
{
if(!object) return;
//llinfos << "invetnory arrived: \n"
// << " panel UUID: " << panel->mTaskUUID << "\n"
// << " task UUID: " << object->mID << llendl;
if(mTaskUUID == object->mID)
{
mInventoryNeedsUpdate = TRUE;
}
// refresh any properties floaters that are hanging around.
if(inventory)
{
for (InventoryObjectList::const_iterator iter = inventory->begin();
iter != inventory->end(); )
{
LLInventoryObject* item = *iter++;
LLFloaterProperties* floater = LLFloaterReg::findTypedInstance<LLFloaterProperties>("properites", item->getUUID());
if(floater)
{
floater->refresh();
}
}
}
}
void LLPanelObjectInventory::updateInventory()
{
//llinfos << "inventory arrived: \n"
// << " panel UUID: " << panel->mTaskUUID << "\n"
// << " task UUID: " << object->mID << llendl;
// We're still interested in this task's inventory.
std::set<LLUUID> selected_items;
BOOL inventory_has_focus = FALSE;
if (mHaveInventory && mFolders->getNumSelectedDescendants())
{
mFolders->getSelectionList(selected_items);
inventory_has_focus = gFocusMgr.childHasKeyboardFocus(mFolders);
}
reset();
LLViewerObject* objectp = gObjectList.findObject(mTaskUUID);
if (objectp)
{
LLInventoryObject* inventory_root = objectp->getInventoryRoot();
InventoryObjectList contents;
objectp->getInventoryContents(contents);
if (inventory_root)
{
createFolderViews(inventory_root, contents);
mHaveInventory = TRUE;
mIsInventoryEmpty = FALSE;
mFolders->setEnabled(TRUE);
}
else
{
// TODO: create an empty inventory
mIsInventoryEmpty = TRUE;
mHaveInventory = TRUE;
}
}
else
{
// TODO: create an empty inventory
mIsInventoryEmpty = TRUE;
mHaveInventory = TRUE;
}
// restore previous selection
std::set<LLUUID>::iterator selection_it;
BOOL first_item = TRUE;
for (selection_it = selected_items.begin(); selection_it != selected_items.end(); ++selection_it)
{
LLFolderViewItem* selected_item = mFolders->getItemByID(*selection_it);
if (selected_item)
{
//HACK: "set" first item then "change" each other one to get keyboard focus right
if (first_item)
{
mFolders->setSelection(selected_item, TRUE, inventory_has_focus);
first_item = FALSE;
}
else
{
mFolders->changeSelection(selected_item, TRUE);
}
}
}
mFolders->requestArrange();
mInventoryNeedsUpdate = FALSE;
}
// *FIX: This is currently a very expensive operation, because we have
// to iterate through the inventory one time for each category. This
// leads to an N^2 based on the category count. This could be greatly
// speeded with an efficient multimap implementation, but we don't
// have that in our current arsenal.
void LLPanelObjectInventory::createFolderViews(LLInventoryObject* inventory_root, InventoryObjectList& contents)
{
if (!inventory_root)
{
return;
}
// Create a visible root category.
LLTaskInvFVBridge* bridge = NULL;
bridge = LLTaskInvFVBridge::createObjectBridge(this, inventory_root);
if(bridge)
{
LLFolderViewFolder* new_folder = NULL;
LLFolderViewFolder::Params p;
p.name = inventory_root->getName();
p.icon = LLUI::getUIImage("Inv_FolderClosed");
p.icon_open = LLUI::getUIImage("Inv_FolderOpen");
p.root = mFolders;
p.listener = bridge;
new_folder = LLUICtrlFactory::create<LLFolderViewFolder>(p);
new_folder->addToFolder(mFolders, mFolders);
new_folder->toggleOpen();
createViewsForCategory(&contents, inventory_root, new_folder);
}
}
typedef std::pair<LLInventoryObject*, LLFolderViewFolder*> obj_folder_pair;
void LLPanelObjectInventory::createViewsForCategory(InventoryObjectList* inventory,
LLInventoryObject* parent,
LLFolderViewFolder* folder)
{
// Find all in the first pass
LLDynamicArray<obj_folder_pair*> child_categories;
LLTaskInvFVBridge* bridge;
LLFolderViewItem* view;
InventoryObjectList::iterator it = inventory->begin();
InventoryObjectList::iterator end = inventory->end();
for( ; it != end; ++it)
{
LLInventoryObject* obj = *it;
if(parent->getUUID() == obj->getParentUUID())
{
bridge = LLTaskInvFVBridge::createObjectBridge(this, obj);
if(!bridge)
{
continue;
}
if(LLAssetType::AT_CATEGORY == obj->getType())
{
LLFolderViewFolder::Params p;
p.name = obj->getName();
p.icon = LLUI::getUIImage("Inv_FolderClosed");
p.icon_open = LLUI::getUIImage("Inv_FolderOpen");
p.root = mFolders;
p.listener = bridge;
view = LLUICtrlFactory::create<LLFolderViewFolder>(p);
child_categories.put(new obj_folder_pair(obj,
(LLFolderViewFolder*)view));
}
else
{
LLFolderViewItem::Params params;
params.name(obj->getName());
params.icon(bridge->getIcon());
params.creation_date(bridge->getCreationDate());
params.root(mFolders);
params.listener(bridge);
params.rect(LLRect());
view = LLUICtrlFactory::create<LLFolderViewItem> (params);
}
view->addToFolder(folder, mFolders);
}
}
// now, for each category, do the second pass
for(S32 i = 0; i < child_categories.count(); i++)
{
createViewsForCategory(inventory, child_categories[i]->first,
child_categories[i]->second );
delete child_categories[i];
}
}
void LLPanelObjectInventory::refresh()
{
//llinfos << "LLPanelObjectInventory::refresh()" << llendl;
BOOL has_inventory = FALSE;
const BOOL non_root_ok = TRUE;
LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode(NULL, non_root_ok);
if(node)
{
LLViewerObject* object = node->getObject();
if(object && ((LLSelectMgr::getInstance()->getSelection()->getRootObjectCount() == 1)
|| (LLSelectMgr::getInstance()->getSelection()->getObjectCount() == 1)))
{
// determine if we need to make a request. Start with a
// default based on if we have inventory at all.
BOOL make_request = !mHaveInventory;
// If the task id is different than what we've stored,
// then make the request.
if(mTaskUUID != object->mID)
{
mTaskUUID = object->mID;
make_request = TRUE;
// This is a new object so pre-emptively clear the contents
// Otherwise we show the old stuff until the update comes in
clearContents();
// Register for updates from this object,
registerVOInventoryListener(object,NULL);
}
// Based on the node information, we may need to dirty the
// object inventory and get it again.
if(node->mValid)
{
if(node->mInventorySerial != object->getInventorySerial() || object->isInventoryDirty())
{
make_request = TRUE;
}
}
// do the request if necessary.
if(make_request)
{
requestVOInventory();
}
has_inventory = TRUE;
}
}
if(!has_inventory)
{
mTaskUUID = LLUUID::null;
removeVOInventoryListener();
clearContents();
}
//llinfos << "LLPanelObjectInventory::refresh() " << mTaskUUID << llendl;
}
void LLPanelObjectInventory::removeSelectedItem()
{
if(mFolders)
{
mFolders->removeSelectedItems();
}
}
void LLPanelObjectInventory::startRenamingSelectedItem()
{
if(mFolders)
{
mFolders->startRenamingSelectedItem();
}
}
void LLPanelObjectInventory::draw()
{
LLPanel::draw();
if(mIsInventoryEmpty)
{
if((LLUUID::null != mTaskUUID) && (!mHaveInventory))
{
LLFontGL::getFontSansSerif()->renderUTF8(LLTrans::getString("LoadingContents"), 0,
(S32)(getRect().getWidth() * 0.5f),
10,
LLColor4( 1, 1, 1, 1 ),
LLFontGL::HCENTER,
LLFontGL::BOTTOM);
}
else if(mHaveInventory)
{
LLFontGL::getFontSansSerif()->renderUTF8(LLTrans::getString("NoContents"), 0,
(S32)(getRect().getWidth() * 0.5f),
10,
LLColor4( 1, 1, 1, 1 ),
LLFontGL::HCENTER,
LLFontGL::BOTTOM);
}
}
}
void LLPanelObjectInventory::deleteAllChildren()
{
mScroller = NULL;
mFolders = NULL;
LLView::deleteAllChildren();
}
BOOL LLPanelObjectInventory::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, EDragAndDropType cargo_type, void *cargo_data, EAcceptance *accept, std::string& tooltip_msg)
{
if (mFolders && mHaveInventory)
{
LLFolderViewItem* folderp = mFolders->getNextFromChild(NULL);
if (!folderp)
{
return FALSE;
}
// Try to pass on unmodified mouse coordinates
S32 local_x = x - mFolders->getRect().mLeft;
S32 local_y = y - mFolders->getRect().mBottom;
if (mFolders->pointInView(local_x, local_y))
{
return mFolders->handleDragAndDrop(local_x, local_y, mask, drop, cargo_type, cargo_data, accept, tooltip_msg);
}
else
{
//force mouse coordinates to be inside folder rectangle
return mFolders->handleDragAndDrop(5, 1, mask, drop, cargo_type, cargo_data, accept, tooltip_msg);
}
}
else
{
return FALSE;
}
}
//static
void LLPanelObjectInventory::idle(void* user_data)
{
LLPanelObjectInventory* self = (LLPanelObjectInventory*)user_data;
if (self->mInventoryNeedsUpdate)
{
self->updateInventory();
}
}
|