diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llviewerinventory.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r-- | linden/indra/newview/llviewerinventory.cpp | 724 |
1 files changed, 724 insertions, 0 deletions
diff --git a/linden/indra/newview/llviewerinventory.cpp b/linden/indra/newview/llviewerinventory.cpp new file mode 100644 index 0000000..1ed6525 --- /dev/null +++ b/linden/indra/newview/llviewerinventory.cpp | |||
@@ -0,0 +1,724 @@ | |||
1 | /** | ||
2 | * @file llviewerinventory.cpp | ||
3 | * @brief Implementation of the viewer side inventory objects. | ||
4 | * | ||
5 | * Copyright (c) 2002-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #include "llviewerprecompiledheaders.h" | ||
29 | #include "llviewerinventory.h" | ||
30 | |||
31 | #include "message.h" | ||
32 | #include "indra_constants.h" | ||
33 | |||
34 | #include "llagent.h" | ||
35 | #include "llviewercontrol.h" | ||
36 | #include "llconsole.h" | ||
37 | #include "llinventorymodel.h" | ||
38 | #include "llnotify.h" | ||
39 | #include "llimview.h" | ||
40 | #include "viewer.h" | ||
41 | #include "llgesturemgr.h" | ||
42 | |||
43 | #include "llinventoryview.h" | ||
44 | |||
45 | ///---------------------------------------------------------------------------- | ||
46 | /// Local function declarations, constants, enums, and typedefs | ||
47 | ///---------------------------------------------------------------------------- | ||
48 | |||
49 | ///---------------------------------------------------------------------------- | ||
50 | /// Class LLViewerInventoryItem | ||
51 | ///---------------------------------------------------------------------------- | ||
52 | |||
53 | LLViewerInventoryItem::LLViewerInventoryItem(const LLUUID& uuid, | ||
54 | const LLUUID& parent_uuid, | ||
55 | const LLPermissions& perm, | ||
56 | const LLUUID& asset_uuid, | ||
57 | LLAssetType::EType type, | ||
58 | LLInventoryType::EType inv_type, | ||
59 | const LLString& name, | ||
60 | const LLString& desc, | ||
61 | const LLSaleInfo& sale_info, | ||
62 | U32 flags, | ||
63 | S32 creation_date_utc) : | ||
64 | LLInventoryItem(uuid, parent_uuid, perm, asset_uuid, type, inv_type, | ||
65 | name, desc, sale_info, flags, creation_date_utc), | ||
66 | mIsComplete(TRUE) | ||
67 | { | ||
68 | } | ||
69 | |||
70 | LLViewerInventoryItem::LLViewerInventoryItem(const LLUUID& item_id, | ||
71 | const LLUUID& parent_id, | ||
72 | const char* name, | ||
73 | LLInventoryType::EType inv_type) : | ||
74 | LLInventoryItem(), | ||
75 | mIsComplete(FALSE) | ||
76 | { | ||
77 | mUUID = item_id; | ||
78 | mParentUUID = parent_id; | ||
79 | mInventoryType = inv_type; | ||
80 | mName.assign(name); | ||
81 | } | ||
82 | |||
83 | LLViewerInventoryItem::LLViewerInventoryItem() : | ||
84 | LLInventoryItem(), | ||
85 | mIsComplete(FALSE) | ||
86 | { | ||
87 | } | ||
88 | |||
89 | LLViewerInventoryItem::LLViewerInventoryItem(const LLViewerInventoryItem* other) : | ||
90 | LLInventoryItem() | ||
91 | { | ||
92 | copy(other); | ||
93 | if (!mIsComplete) | ||
94 | { | ||
95 | llwarns << "LLViewerInventoryItem copy constructor for incomplete item" | ||
96 | << mUUID << llendl; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | LLViewerInventoryItem::LLViewerInventoryItem(const LLInventoryItem *other) : | ||
101 | LLInventoryItem(other) | ||
102 | { | ||
103 | LLInventoryItem::copy(other); | ||
104 | if (!mIsComplete) | ||
105 | { | ||
106 | llwarns << "LLViewerInventoryItem copy constructor for incomplete item" | ||
107 | << mUUID << llendl; | ||
108 | } | ||
109 | } | ||
110 | |||
111 | |||
112 | LLViewerInventoryItem::~LLViewerInventoryItem() | ||
113 | { | ||
114 | } | ||
115 | |||
116 | // virtual | ||
117 | void LLViewerInventoryItem::copy(const LLViewerInventoryItem* other) | ||
118 | { | ||
119 | LLInventoryItem::copy(other); | ||
120 | mIsComplete = other->mIsComplete; | ||
121 | mTransactionID = other->mTransactionID; | ||
122 | } | ||
123 | |||
124 | void LLViewerInventoryItem::copy(const LLInventoryItem *other) | ||
125 | { | ||
126 | LLInventoryItem::copy(other); | ||
127 | mIsComplete = true; | ||
128 | mTransactionID.setNull(); | ||
129 | } | ||
130 | |||
131 | // virtual | ||
132 | void LLViewerInventoryItem::clone(LLPointer<LLViewerInventoryItem>& newitem) const | ||
133 | { | ||
134 | newitem = new LLViewerInventoryItem(this); | ||
135 | if(newitem.notNull()) | ||
136 | { | ||
137 | LLUUID item_id; | ||
138 | item_id.generate(); | ||
139 | newitem->setUUID(item_id); | ||
140 | } | ||
141 | } | ||
142 | |||
143 | void LLViewerInventoryItem::removeFromServer() | ||
144 | { | ||
145 | llinfos << "Removing inventory item " << mUUID << " from server." | ||
146 | << llendl; | ||
147 | |||
148 | LLInventoryModel::LLCategoryUpdate up(mParentUUID, -1); | ||
149 | gInventory.accountForUpdate(up); | ||
150 | |||
151 | LLMessageSystem* msg = gMessageSystem; | ||
152 | msg->newMessageFast(_PREHASH_RemoveInventoryItem); | ||
153 | msg->nextBlockFast(_PREHASH_AgentData); | ||
154 | msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); | ||
155 | msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); | ||
156 | msg->nextBlockFast(_PREHASH_InventoryData); | ||
157 | msg->addUUIDFast(_PREHASH_ItemID, mUUID); | ||
158 | gAgent.sendReliableMessage(); | ||
159 | } | ||
160 | |||
161 | void LLViewerInventoryItem::updateServer(BOOL is_new) const | ||
162 | { | ||
163 | if(!mIsComplete) | ||
164 | { | ||
165 | // *FIX: deal with this better. | ||
166 | // If we're crashing here then the UI is incorrectly enabled. | ||
167 | llerrs << "LLViewerInventoryItem::updateServer() - for incomplete item" | ||
168 | << llendl; | ||
169 | return; | ||
170 | } | ||
171 | if(gAgent.getID() != mPermissions.getOwner()) | ||
172 | { | ||
173 | // *FIX: deal with this better. | ||
174 | llwarns << "LLViewerInventoryItem::updateServer() - for unowned item" | ||
175 | << llendl; | ||
176 | return; | ||
177 | } | ||
178 | LLInventoryModel::LLCategoryUpdate up(mParentUUID, is_new ? 1 : 0); | ||
179 | gInventory.accountForUpdate(up); | ||
180 | |||
181 | LLMessageSystem* msg = gMessageSystem; | ||
182 | msg->newMessageFast(_PREHASH_UpdateInventoryItem); | ||
183 | msg->nextBlockFast(_PREHASH_AgentData); | ||
184 | msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); | ||
185 | msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); | ||
186 | msg->nextBlockFast(_PREHASH_InventoryData); | ||
187 | msg->addU32Fast(_PREHASH_CallbackID, 0); | ||
188 | packMessage(msg); | ||
189 | gAgent.sendReliableMessage(); | ||
190 | } | ||
191 | |||
192 | void LLViewerInventoryItem::fetchFromServer(void) const | ||
193 | { | ||
194 | if(!mIsComplete) | ||
195 | { | ||
196 | LLMessageSystem* msg = gMessageSystem; | ||
197 | msg->newMessage("FetchInventory"); | ||
198 | msg->nextBlock("AgentData"); | ||
199 | msg->addUUID("AgentID", gAgent.getID()); | ||
200 | msg->addUUID("SessionID", gAgent.getSessionID()); | ||
201 | msg->nextBlock("InventoryData"); | ||
202 | msg->addUUID("OwnerID", mPermissions.getOwner()); | ||
203 | msg->addUUID("ItemID", mUUID); | ||
204 | gAgent.sendReliableMessage(); | ||
205 | } | ||
206 | else | ||
207 | { | ||
208 | // *FIX: this can be removed after a bit. | ||
209 | llwarns << "request to fetch complete item" << llendl; | ||
210 | } | ||
211 | } | ||
212 | |||
213 | // virtual | ||
214 | BOOL LLViewerInventoryItem::unpackMessage( | ||
215 | LLMessageSystem* msg, const char* block, S32 block_num) | ||
216 | { | ||
217 | BOOL rv = LLInventoryItem::unpackMessage(msg, block, block_num); | ||
218 | mIsComplete = TRUE; | ||
219 | return rv; | ||
220 | } | ||
221 | |||
222 | void LLViewerInventoryItem::setTransactionID(const LLTransactionID& transaction_id) | ||
223 | { | ||
224 | mTransactionID = transaction_id; | ||
225 | } | ||
226 | // virtual | ||
227 | void LLViewerInventoryItem::packMessage(LLMessageSystem* msg) const | ||
228 | { | ||
229 | msg->addUUIDFast(_PREHASH_ItemID, mUUID); | ||
230 | msg->addUUIDFast(_PREHASH_FolderID, mParentUUID); | ||
231 | mPermissions.packMessage(msg); | ||
232 | msg->addUUIDFast(_PREHASH_TransactionID, mTransactionID); | ||
233 | S8 type = static_cast<S8>(mType); | ||
234 | msg->addS8Fast(_PREHASH_Type, type); | ||
235 | type = static_cast<S8>(mInventoryType); | ||
236 | msg->addS8Fast(_PREHASH_InvType, type); | ||
237 | msg->addU32Fast(_PREHASH_Flags, mFlags); | ||
238 | mSaleInfo.packMessage(msg); | ||
239 | msg->addStringFast(_PREHASH_Name, mName); | ||
240 | msg->addStringFast(_PREHASH_Description, mDescription); | ||
241 | msg->addS32Fast(_PREHASH_CreationDate, mCreationDate); | ||
242 | U32 crc = getCRC32(); | ||
243 | msg->addU32Fast(_PREHASH_CRC, crc); | ||
244 | } | ||
245 | // virtual | ||
246 | BOOL LLViewerInventoryItem::importFile(FILE* fp) | ||
247 | { | ||
248 | BOOL rv = LLInventoryItem::importFile(fp); | ||
249 | mIsComplete = TRUE; | ||
250 | return rv; | ||
251 | } | ||
252 | |||
253 | // virtual | ||
254 | BOOL LLViewerInventoryItem::importLegacyStream(std::istream& input_stream) | ||
255 | { | ||
256 | BOOL rv = LLInventoryItem::importLegacyStream(input_stream); | ||
257 | mIsComplete = TRUE; | ||
258 | return rv; | ||
259 | } | ||
260 | |||
261 | bool LLViewerInventoryItem::importFileLocal(FILE* fp) | ||
262 | { | ||
263 | // TODO: convert all functions that return BOOL to return bool | ||
264 | bool rv = (LLInventoryItem::importFile(fp) ? true : false); | ||
265 | mIsComplete = false; | ||
266 | return rv; | ||
267 | } | ||
268 | |||
269 | bool LLViewerInventoryItem::exportFileLocal(FILE* fp) const | ||
270 | { | ||
271 | char uuid_str[UUID_STR_LENGTH]; | ||
272 | fprintf(fp, "\tinv_item\t0\n\t{\n"); | ||
273 | mUUID.toString(uuid_str); | ||
274 | fprintf(fp, "\t\titem_id\t%s\n", uuid_str); | ||
275 | mParentUUID.toString(uuid_str); | ||
276 | fprintf(fp, "\t\tparent_id\t%s\n", uuid_str); | ||
277 | mPermissions.exportFile(fp); | ||
278 | fprintf(fp, "\t\ttype\t%s\n", LLAssetType::lookup(mType)); | ||
279 | const char* inv_type_str = LLInventoryType::lookup(mInventoryType); | ||
280 | if(inv_type_str) fprintf(fp, "\t\tinv_type\t%s\n", inv_type_str); | ||
281 | fprintf(fp, "\t\tname\t%s|\n", mName.c_str()); | ||
282 | fprintf(fp, "\t\tcreation_date\t%d\n", mCreationDate); | ||
283 | fprintf(fp,"\t}\n"); | ||
284 | return true; | ||
285 | } | ||
286 | |||
287 | void LLViewerInventoryItem::updateParentOnServer(BOOL restamp) const | ||
288 | { | ||
289 | LLMessageSystem* msg = gMessageSystem; | ||
290 | msg->newMessageFast(_PREHASH_MoveInventoryItem); | ||
291 | msg->nextBlockFast(_PREHASH_AgentData); | ||
292 | msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); | ||
293 | msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); | ||
294 | msg->addBOOLFast(_PREHASH_Stamp, restamp); | ||
295 | msg->nextBlockFast(_PREHASH_InventoryData); | ||
296 | msg->addUUIDFast(_PREHASH_ItemID, mUUID); | ||
297 | msg->addUUIDFast(_PREHASH_FolderID, mParentUUID); | ||
298 | msg->addString("NewName", NULL); | ||
299 | gAgent.sendReliableMessage(); | ||
300 | } | ||
301 | |||
302 | //void LLViewerInventoryItem::setCloneCount(S32 clones) | ||
303 | //{ | ||
304 | // mClones = clones; | ||
305 | //} | ||
306 | |||
307 | //S32 LLViewerInventoryItem::getCloneCount() const | ||
308 | //{ | ||
309 | // return mClones; | ||
310 | //} | ||
311 | |||
312 | ///---------------------------------------------------------------------------- | ||
313 | /// Class LLViewerInventoryCategory | ||
314 | ///---------------------------------------------------------------------------- | ||
315 | |||
316 | LLViewerInventoryCategory::LLViewerInventoryCategory(const LLUUID& uuid, | ||
317 | const LLUUID& parent_uuid, | ||
318 | LLAssetType::EType pref, | ||
319 | const LLString& name, | ||
320 | const LLUUID& owner_id) : | ||
321 | LLInventoryCategory(uuid, parent_uuid, pref, name), | ||
322 | mOwnerID(owner_id), | ||
323 | mVersion(LLViewerInventoryCategory::VERSION_UNKNOWN), | ||
324 | mDescendentCount(LLViewerInventoryCategory::DESCENDENT_COUNT_UNKNOWN) | ||
325 | { | ||
326 | mDescendentsRequested.reset(); | ||
327 | } | ||
328 | |||
329 | LLViewerInventoryCategory::LLViewerInventoryCategory(const LLUUID& owner_id) : | ||
330 | mOwnerID(owner_id), | ||
331 | mVersion(LLViewerInventoryCategory::VERSION_UNKNOWN), | ||
332 | mDescendentCount(LLViewerInventoryCategory::DESCENDENT_COUNT_UNKNOWN) | ||
333 | { | ||
334 | mDescendentsRequested.reset(); | ||
335 | } | ||
336 | |||
337 | LLViewerInventoryCategory::LLViewerInventoryCategory(const LLViewerInventoryCategory* other) | ||
338 | { | ||
339 | copy(other); | ||
340 | } | ||
341 | |||
342 | LLViewerInventoryCategory::~LLViewerInventoryCategory() | ||
343 | { | ||
344 | } | ||
345 | |||
346 | // virtual | ||
347 | void LLViewerInventoryCategory::copy(const LLViewerInventoryCategory* other) | ||
348 | { | ||
349 | LLInventoryCategory::copy(other); | ||
350 | mOwnerID = other->mOwnerID; | ||
351 | mVersion = other->mVersion; | ||
352 | mDescendentCount = other->mDescendentCount; | ||
353 | mDescendentsRequested = other->mDescendentsRequested; | ||
354 | } | ||
355 | |||
356 | |||
357 | void LLViewerInventoryCategory::updateParentOnServer(BOOL restamp) const | ||
358 | { | ||
359 | LLMessageSystem* msg = gMessageSystem; | ||
360 | msg->newMessageFast(_PREHASH_MoveInventoryFolder); | ||
361 | msg->nextBlockFast(_PREHASH_AgentData); | ||
362 | msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); | ||
363 | msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); | ||
364 | |||
365 | msg->addBOOL("Stamp", restamp); | ||
366 | msg->nextBlockFast(_PREHASH_InventoryData); | ||
367 | msg->addUUIDFast(_PREHASH_FolderID, mUUID); | ||
368 | msg->addUUIDFast(_PREHASH_ParentID, mParentUUID); | ||
369 | gAgent.sendReliableMessage(); | ||
370 | } | ||
371 | |||
372 | void LLViewerInventoryCategory::updateServer(BOOL is_new) const | ||
373 | { | ||
374 | // communicate that change with the server. | ||
375 | if(LLAssetType::AT_NONE != mPreferredType) | ||
376 | { | ||
377 | LLNotifyBox::showXml("CannotModifyProtectedCategories"); | ||
378 | return; | ||
379 | } | ||
380 | |||
381 | LLInventoryModel::LLCategoryUpdate up(mParentUUID, is_new ? 1 : 0); | ||
382 | gInventory.accountForUpdate(up); | ||
383 | |||
384 | LLMessageSystem* msg = gMessageSystem; | ||
385 | msg->newMessageFast(_PREHASH_UpdateInventoryFolder); | ||
386 | msg->nextBlockFast(_PREHASH_AgentData); | ||
387 | msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); | ||
388 | msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); | ||
389 | msg->nextBlockFast(_PREHASH_FolderData); | ||
390 | packMessage(msg); | ||
391 | gAgent.sendReliableMessage(); | ||
392 | } | ||
393 | |||
394 | void LLViewerInventoryCategory::removeFromServer( void ) | ||
395 | { | ||
396 | llinfos << "Removing inventory category " << mUUID << " from server." | ||
397 | << llendl; | ||
398 | // communicate that change with the server. | ||
399 | if(LLAssetType::AT_NONE != mPreferredType) | ||
400 | { | ||
401 | LLNotifyBox::showXml("CannotRemoveProtectedCategories"); | ||
402 | return; | ||
403 | } | ||
404 | |||
405 | LLInventoryModel::LLCategoryUpdate up(mParentUUID, -1); | ||
406 | gInventory.accountForUpdate(up); | ||
407 | |||
408 | LLMessageSystem* msg = gMessageSystem; | ||
409 | msg->newMessageFast(_PREHASH_RemoveInventoryFolder); | ||
410 | msg->nextBlockFast(_PREHASH_AgentData); | ||
411 | msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); | ||
412 | msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); | ||
413 | msg->nextBlockFast(_PREHASH_FolderData); | ||
414 | msg->addUUIDFast(_PREHASH_FolderID, mUUID); | ||
415 | gAgent.sendReliableMessage(); | ||
416 | } | ||
417 | |||
418 | bool LLViewerInventoryCategory::fetchDescendents() | ||
419 | { | ||
420 | if((VERSION_UNKNOWN == mVersion) | ||
421 | && mDescendentsRequested.hasExpired()) | ||
422 | { | ||
423 | const F32 FETCH_TIMER_EXPIRY = 10.0f; | ||
424 | mDescendentsRequested.reset(); | ||
425 | mDescendentsRequested.setTimerExpirySec(FETCH_TIMER_EXPIRY); | ||
426 | |||
427 | LLMessageSystem* msg = gMessageSystem; | ||
428 | msg->newMessage("FetchInventoryDescendents"); | ||
429 | msg->nextBlock("AgentData"); | ||
430 | msg->addUUID("AgentID", gAgent.getID()); | ||
431 | msg->addUUID("SessionID", gAgent.getSessionID()); | ||
432 | msg->nextBlock("InventoryData"); | ||
433 | msg->addUUID("FolderID", mUUID); | ||
434 | msg->addUUID("OwnerID", mOwnerID); | ||
435 | // bitfield | ||
436 | // 1 = by date | ||
437 | // 2 = folders by date | ||
438 | // Need to mask off anything but the first bit. | ||
439 | // This comes from LLInventoryFilter from llfolderview.h | ||
440 | U32 sort_order = gSavedSettings.getU32("InventorySortOrder") & 0x1; | ||
441 | msg->addS32("SortOrder", sort_order); | ||
442 | msg->addBOOL("FetchFolders", FALSE); | ||
443 | msg->addBOOL("FetchItems", TRUE); | ||
444 | gAgent.sendReliableMessage(); | ||
445 | return true; | ||
446 | } | ||
447 | return false; | ||
448 | } | ||
449 | |||
450 | bool LLViewerInventoryCategory::importFileLocal(FILE* fp) | ||
451 | { | ||
452 | char buffer[MAX_STRING]; | ||
453 | char keyword[MAX_STRING]; | ||
454 | char valuestr[MAX_STRING]; | ||
455 | |||
456 | keyword[0] = '\0'; | ||
457 | valuestr[0] = '\0'; | ||
458 | while(!feof(fp)) | ||
459 | { | ||
460 | fgets(buffer, MAX_STRING, fp); | ||
461 | sscanf(buffer, " %s %s", keyword, valuestr); | ||
462 | if(!keyword) | ||
463 | { | ||
464 | continue; | ||
465 | } | ||
466 | if(0 == strcmp("{",keyword)) | ||
467 | { | ||
468 | continue; | ||
469 | } | ||
470 | if(0 == strcmp("}", keyword)) | ||
471 | { | ||
472 | break; | ||
473 | } | ||
474 | else if(0 == strcmp("cat_id", keyword)) | ||
475 | { | ||
476 | mUUID.set(valuestr); | ||
477 | } | ||
478 | else if(0 == strcmp("parent_id", keyword)) | ||
479 | { | ||
480 | mParentUUID.set(valuestr); | ||
481 | } | ||
482 | else if(0 == strcmp("type", keyword)) | ||
483 | { | ||
484 | mType = LLAssetType::lookup(valuestr); | ||
485 | } | ||
486 | else if(0 == strcmp("pref_type", keyword)) | ||
487 | { | ||
488 | mPreferredType = LLAssetType::lookup(valuestr); | ||
489 | } | ||
490 | else if(0 == strcmp("name", keyword)) | ||
491 | { | ||
492 | //strcpy(valuestr, buffer + strlen(keyword) + 3); | ||
493 | // *NOTE: Not ANSI C, but widely supported. | ||
494 | sscanf(buffer, " %s %[^|]", keyword, valuestr); | ||
495 | mName.assign(valuestr); | ||
496 | LLString::replaceNonstandardASCII(mName, ' '); | ||
497 | LLString::replaceChar(mName, '|', ' '); | ||
498 | } | ||
499 | else if(0 == strcmp("owner_id", keyword)) | ||
500 | { | ||
501 | mOwnerID.set(valuestr); | ||
502 | } | ||
503 | else if(0 == strcmp("version", keyword)) | ||
504 | { | ||
505 | sscanf(valuestr, "%d", &mVersion); | ||
506 | } | ||
507 | else | ||
508 | { | ||
509 | llwarns << "unknown keyword '" << keyword | ||
510 | << "' in inventory import category " << mUUID << llendl; | ||
511 | } | ||
512 | } | ||
513 | return true; | ||
514 | } | ||
515 | |||
516 | bool LLViewerInventoryCategory::exportFileLocal(FILE* fp) const | ||
517 | { | ||
518 | char uuid_str[UUID_STR_LENGTH]; | ||
519 | fprintf(fp, "\tinv_category\t0\n\t{\n"); | ||
520 | mUUID.toString(uuid_str); | ||
521 | fprintf(fp, "\t\tcat_id\t%s\n", uuid_str); | ||
522 | mParentUUID.toString(uuid_str); | ||
523 | fprintf(fp, "\t\tparent_id\t%s\n", uuid_str); | ||
524 | fprintf(fp, "\t\ttype\t%s\n", LLAssetType::lookup(mType)); | ||
525 | fprintf(fp, "\t\tpref_type\t%s\n", LLAssetType::lookup(mPreferredType)); | ||
526 | fprintf(fp, "\t\tname\t%s|\n", mName.c_str()); | ||
527 | mOwnerID.toString(uuid_str); | ||
528 | fprintf(fp, "\t\towner_id\t%s\n", uuid_str); | ||
529 | fprintf(fp, "\t\tversion\t%d\n", mVersion); | ||
530 | fprintf(fp,"\t}\n"); | ||
531 | return true; | ||
532 | } | ||
533 | |||
534 | ///---------------------------------------------------------------------------- | ||
535 | /// Local function definitions | ||
536 | ///---------------------------------------------------------------------------- | ||
537 | |||
538 | /* | ||
539 | void inventory_reliable_callback(void**, S32 status) | ||
540 | { | ||
541 | if(0 != status) | ||
542 | { | ||
543 | char buffer[MAX_STRING]; | ||
544 | sprintf(buffer, "Reliable packet failure: %d", status); | ||
545 | llwarns << buffer << llendl; | ||
546 | } | ||
547 | } | ||
548 | */ | ||
549 | LLInventoryCallbackManager::LLInventoryCallbackManager() : | ||
550 | mLastCallback(0) | ||
551 | { | ||
552 | } | ||
553 | |||
554 | LLInventoryCallbackManager::~LLInventoryCallbackManager() | ||
555 | { | ||
556 | } | ||
557 | |||
558 | U32 LLInventoryCallbackManager::registerCB(LLPointer<LLInventoryCallback> cb) | ||
559 | { | ||
560 | if (cb.isNull()) | ||
561 | return 0; | ||
562 | |||
563 | mLastCallback++; | ||
564 | if (!mLastCallback) | ||
565 | mLastCallback++; | ||
566 | |||
567 | mMap[mLastCallback] = cb; | ||
568 | return mLastCallback; | ||
569 | } | ||
570 | |||
571 | void LLInventoryCallbackManager::fire(U32 callback_id, const LLUUID& item_id) | ||
572 | { | ||
573 | if (!callback_id) | ||
574 | return; | ||
575 | |||
576 | std::map<U32, LLPointer<LLInventoryCallback> >::iterator i; | ||
577 | |||
578 | i = mMap.find(callback_id); | ||
579 | if (i != mMap.end()) | ||
580 | { | ||
581 | (*i).second->fire(item_id); | ||
582 | mMap.erase(i); | ||
583 | } | ||
584 | } | ||
585 | |||
586 | void WearOnAvatarCallback::fire(const LLUUID& inv_item) | ||
587 | { | ||
588 | if (inv_item.isNull()) | ||
589 | return; | ||
590 | |||
591 | LLViewerInventoryItem *item = gInventory.getItem(inv_item); | ||
592 | if (item) | ||
593 | { | ||
594 | wear_inventory_item_on_avatar(item); | ||
595 | } | ||
596 | } | ||
597 | |||
598 | RezAttachmentCallback::RezAttachmentCallback(LLViewerJointAttachment *attachmentp) | ||
599 | { | ||
600 | mAttach = attachmentp; | ||
601 | } | ||
602 | RezAttachmentCallback::~RezAttachmentCallback() | ||
603 | { | ||
604 | } | ||
605 | |||
606 | void RezAttachmentCallback::fire(const LLUUID& inv_item) | ||
607 | { | ||
608 | if (inv_item.isNull()) | ||
609 | return; | ||
610 | |||
611 | LLViewerInventoryItem *item = gInventory.getItem(inv_item); | ||
612 | if (item) | ||
613 | { | ||
614 | rez_attachment(item, mAttach); | ||
615 | } | ||
616 | } | ||
617 | |||
618 | extern LLGestureManager gGestureManager; | ||
619 | void ActivateGestureCallback::fire(const LLUUID& inv_item) | ||
620 | { | ||
621 | if (inv_item.isNull()) | ||
622 | return; | ||
623 | |||
624 | gGestureManager.activateGesture(inv_item); | ||
625 | } | ||
626 | |||
627 | LLInventoryCallbackManager gInventoryCallbacks; | ||
628 | |||
629 | void create_inventory_item(const LLUUID& agent_id, const LLUUID& session_id, | ||
630 | const LLUUID& parent, const LLTransactionID& transaction_id, | ||
631 | const std::string& name, | ||
632 | const std::string& desc, LLAssetType::EType asset_type, | ||
633 | LLInventoryType::EType inv_type, EWearableType wtype, | ||
634 | U32 next_owner_perm, | ||
635 | LLPointer<LLInventoryCallback> cb) | ||
636 | { | ||
637 | LLMessageSystem* msg = gMessageSystem; | ||
638 | msg->newMessageFast(_PREHASH_CreateInventoryItem); | ||
639 | msg->nextBlock(_PREHASH_AgentData); | ||
640 | msg->addUUIDFast(_PREHASH_AgentID, agent_id); | ||
641 | msg->addUUIDFast(_PREHASH_SessionID, session_id); | ||
642 | msg->nextBlock(_PREHASH_InventoryBlock); | ||
643 | msg->addU32Fast(_PREHASH_CallbackID, gInventoryCallbacks.registerCB(cb)); | ||
644 | msg->addUUIDFast(_PREHASH_FolderID, parent); | ||
645 | msg->addUUIDFast(_PREHASH_TransactionID, transaction_id); | ||
646 | msg->addU32Fast(_PREHASH_NextOwnerMask, next_owner_perm); | ||
647 | msg->addS8Fast(_PREHASH_Type, (S8)asset_type); | ||
648 | msg->addS8Fast(_PREHASH_InvType, (S8)inv_type); | ||
649 | msg->addU8Fast(_PREHASH_WearableType, (U8)wtype); | ||
650 | msg->addStringFast(_PREHASH_Name, name); | ||
651 | msg->addStringFast(_PREHASH_Description, desc); | ||
652 | |||
653 | gAgent.sendReliableMessage(); | ||
654 | } | ||
655 | |||
656 | void copy_inventory_item( | ||
657 | const LLUUID& agent_id, | ||
658 | const LLUUID& current_owner, | ||
659 | const LLUUID& item_id, | ||
660 | const LLUUID& parent_id, | ||
661 | const std::string& new_name, | ||
662 | LLPointer<LLInventoryCallback> cb) | ||
663 | { | ||
664 | LLMessageSystem* msg = gMessageSystem; | ||
665 | msg->newMessageFast(_PREHASH_CopyInventoryItem); | ||
666 | msg->nextBlockFast(_PREHASH_AgentData); | ||
667 | msg->addUUIDFast(_PREHASH_AgentID, agent_id); | ||
668 | msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); | ||
669 | msg->nextBlockFast(_PREHASH_InventoryData); | ||
670 | msg->addU32Fast(_PREHASH_CallbackID, gInventoryCallbacks.registerCB(cb)); | ||
671 | msg->addUUIDFast(_PREHASH_OldAgentID, current_owner); | ||
672 | msg->addUUIDFast(_PREHASH_OldItemID, item_id); | ||
673 | msg->addUUIDFast(_PREHASH_NewFolderID, parent_id); | ||
674 | msg->addString("NewName", new_name); | ||
675 | gAgent.sendReliableMessage(); | ||
676 | } | ||
677 | |||
678 | void move_inventory_item( | ||
679 | const LLUUID& agent_id, | ||
680 | const LLUUID& session_id, | ||
681 | const LLUUID& item_id, | ||
682 | const LLUUID& parent_id, | ||
683 | const std::string& new_name, | ||
684 | LLPointer<LLInventoryCallback> cb) | ||
685 | { | ||
686 | LLMessageSystem* msg = gMessageSystem; | ||
687 | msg->newMessageFast(_PREHASH_MoveInventoryItem); | ||
688 | msg->nextBlockFast(_PREHASH_AgentData); | ||
689 | msg->addUUIDFast(_PREHASH_AgentID, agent_id); | ||
690 | msg->addUUIDFast(_PREHASH_SessionID, session_id); | ||
691 | msg->addBOOLFast(_PREHASH_Stamp, false); | ||
692 | msg->nextBlockFast(_PREHASH_InventoryData); | ||
693 | msg->addUUIDFast(_PREHASH_ItemID, item_id); | ||
694 | msg->addUUIDFast(_PREHASH_FolderID, parent_id); | ||
695 | msg->addString("NewName", new_name); | ||
696 | gAgent.sendReliableMessage(); | ||
697 | } | ||
698 | |||
699 | void _copy_inventory_from_notecard_hdr(const LLUUID& object_id, const LLUUID& notecard_inv_id) | ||
700 | { | ||
701 | LLMessageSystem* msg = gMessageSystem; | ||
702 | msg->newMessageFast(_PREHASH_CopyInventoryFromNotecard); | ||
703 | msg->nextBlock(_PREHASH_AgentData); | ||
704 | msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); | ||
705 | msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); | ||
706 | msg->nextBlock(_PREHASH_NotecardData); | ||
707 | msg->addUUIDFast(_PREHASH_NotecardItemID, notecard_inv_id); | ||
708 | msg->addUUIDFast(_PREHASH_ObjectID, object_id); | ||
709 | } | ||
710 | |||
711 | void copy_inventory_from_notecard(const LLUUID& object_id, const LLUUID& notecard_inv_id, const LLInventoryItem *src) | ||
712 | { | ||
713 | LLMessageSystem* msg = gMessageSystem; | ||
714 | /* | ||
715 | * I was going to handle multiple inventory items here, but then I realized that | ||
716 | * we are only handling one at a time. Perhaps you can only select one at a | ||
717 | * time from the notecard? | ||
718 | */ | ||
719 | _copy_inventory_from_notecard_hdr(object_id, notecard_inv_id); | ||
720 | msg->nextBlockFast(_PREHASH_InventoryData); | ||
721 | msg->addUUIDFast(_PREHASH_ItemID, src->getUUID()); | ||
722 | msg->addUUIDFast(_PREHASH_FolderID, gInventory.findCategoryUUIDForType(src->getType())); | ||
723 | gAgent.sendReliableMessage(); | ||
724 | } | ||