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

