llviewerinventory.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 #include "llviewerinventory.h"
00034 
00035 #include "message.h"
00036 #include "indra_constants.h"
00037 
00038 #include "llagent.h"
00039 #include "llviewercontrol.h"
00040 #include "llconsole.h"
00041 #include "llinventorymodel.h"
00042 #include "llnotify.h"
00043 #include "llimview.h"
00044 #include "viewer.h"
00045 #include "llgesturemgr.h"
00046 
00047 #include "llinventoryview.h"
00048 
00049 #include "llviewerregion.h"
00050 #include "llviewerobjectlist.h"
00051 
00055 
00059 
00060 LLViewerInventoryItem::LLViewerInventoryItem(const LLUUID& uuid,
00061                                                                                          const LLUUID& parent_uuid,
00062                                                                                          const LLPermissions& perm,
00063                                                                                          const LLUUID& asset_uuid,
00064                                                                                          LLAssetType::EType type,
00065                                                                                          LLInventoryType::EType inv_type,
00066                                                                                          const LLString& name,
00067                                                                                          const LLString& desc,
00068                                                                                          const LLSaleInfo& sale_info,
00069                                                                                          U32 flags,
00070                                                                                          S32 creation_date_utc) :
00071         LLInventoryItem(uuid, parent_uuid, perm, asset_uuid, type, inv_type,
00072                                         name, desc, sale_info, flags, creation_date_utc),
00073         mIsComplete(TRUE)
00074 {
00075 }
00076 
00077 LLViewerInventoryItem::LLViewerInventoryItem(const LLUUID& item_id,
00078                                                                                          const LLUUID& parent_id,
00079                                                                                          const char* name,
00080                                                                                          LLInventoryType::EType inv_type) :
00081         LLInventoryItem(),
00082         mIsComplete(FALSE)
00083 {
00084         mUUID = item_id;
00085         mParentUUID = parent_id;
00086         mInventoryType = inv_type;
00087         mName.assign(name);
00088 }
00089 
00090 LLViewerInventoryItem::LLViewerInventoryItem() :
00091         LLInventoryItem(),
00092         mIsComplete(FALSE)
00093 {
00094 }
00095 
00096 LLViewerInventoryItem::LLViewerInventoryItem(const LLViewerInventoryItem* other) :
00097         LLInventoryItem()
00098 {
00099         copy(other);
00100         if (!mIsComplete)
00101         {
00102                 llwarns << "LLViewerInventoryItem copy constructor for incomplete item"
00103                         << mUUID << llendl;
00104         }
00105 }
00106 
00107 LLViewerInventoryItem::LLViewerInventoryItem(const LLInventoryItem *other) :
00108         LLInventoryItem(other)
00109 {
00110         LLInventoryItem::copy(other);
00111         if (!mIsComplete)
00112         {
00113                 llwarns << "LLViewerInventoryItem copy constructor for incomplete item"
00114                         << mUUID << llendl;
00115         }
00116 }
00117 
00118 
00119 LLViewerInventoryItem::~LLViewerInventoryItem()
00120 {
00121 }
00122 
00123 // virtual
00124 void LLViewerInventoryItem::copy(const LLViewerInventoryItem* other)
00125 {
00126         LLInventoryItem::copy(other);
00127         mIsComplete = other->mIsComplete;
00128         mTransactionID = other->mTransactionID;
00129 }
00130 
00131 void LLViewerInventoryItem::copy(const LLInventoryItem *other)
00132 {
00133         LLInventoryItem::copy(other);
00134         mIsComplete = true;
00135         mTransactionID.setNull();
00136 }
00137 
00138 // virtual
00139 void LLViewerInventoryItem::clone(LLPointer<LLViewerInventoryItem>& newitem) const
00140 {
00141         newitem = new LLViewerInventoryItem(this);
00142         if(newitem.notNull())
00143         {
00144                 LLUUID item_id;
00145                 item_id.generate();
00146                 newitem->setUUID(item_id);
00147         }
00148 }
00149 
00150 void LLViewerInventoryItem::removeFromServer()
00151 {
00152         llinfos << "Removing inventory item " << mUUID << " from server."
00153                         << llendl;
00154 
00155         LLInventoryModel::LLCategoryUpdate up(mParentUUID, -1);
00156         gInventory.accountForUpdate(up);
00157 
00158         LLMessageSystem* msg = gMessageSystem;
00159         msg->newMessageFast(_PREHASH_RemoveInventoryItem);
00160         msg->nextBlockFast(_PREHASH_AgentData);
00161         msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
00162         msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); 
00163         msg->nextBlockFast(_PREHASH_InventoryData);
00164         msg->addUUIDFast(_PREHASH_ItemID, mUUID);
00165         gAgent.sendReliableMessage();
00166 }
00167 
00168 void LLViewerInventoryItem::updateServer(BOOL is_new) const
00169 {
00170         if(!mIsComplete)
00171         {
00172                 // *FIX: deal with this better.
00173                 // If we're crashing here then the UI is incorrectly enabled.
00174                 llerrs << "LLViewerInventoryItem::updateServer() - for incomplete item"
00175                            << llendl;
00176                 return;
00177         }
00178         if(gAgent.getID() != mPermissions.getOwner())
00179         {
00180                 // *FIX: deal with this better.
00181                 llwarns << "LLViewerInventoryItem::updateServer() - for unowned item"
00182                                 << llendl;
00183                 return;
00184         }
00185         LLInventoryModel::LLCategoryUpdate up(mParentUUID, is_new ? 1 : 0);
00186         gInventory.accountForUpdate(up);
00187 
00188         LLMessageSystem* msg = gMessageSystem;
00189         msg->newMessageFast(_PREHASH_UpdateInventoryItem);
00190         msg->nextBlockFast(_PREHASH_AgentData);
00191         msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
00192         msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
00193         msg->addUUIDFast(_PREHASH_TransactionID, mTransactionID);
00194         msg->nextBlockFast(_PREHASH_InventoryData);
00195         msg->addU32Fast(_PREHASH_CallbackID, 0);
00196         packMessage(msg);
00197         gAgent.sendReliableMessage();
00198 }
00199 
00200 void LLViewerInventoryItem::fetchFromServer(void) const
00201 {
00202         if(!mIsComplete)
00203         {
00204                 LLMessageSystem* msg = gMessageSystem;
00205                 msg->newMessage("FetchInventory");
00206                 msg->nextBlock("AgentData");
00207                 msg->addUUID("AgentID", gAgent.getID());
00208                 msg->addUUID("SessionID", gAgent.getSessionID());
00209                 msg->nextBlock("InventoryData");
00210                 msg->addUUID("OwnerID", mPermissions.getOwner());
00211                 msg->addUUID("ItemID", mUUID);
00212                 gAgent.sendReliableMessage();
00213         }
00214         else
00215         {
00216                 // *FIX: this can be removed after a bit.
00217                 llwarns << "request to fetch complete item" << llendl;
00218         }
00219 }
00220 
00221 // virtual
00222 BOOL LLViewerInventoryItem::unpackMessage(
00223         LLMessageSystem* msg, const char* block, S32 block_num)
00224 {
00225         BOOL rv = LLInventoryItem::unpackMessage(msg, block, block_num);
00226         mIsComplete = TRUE;
00227         return rv;
00228 }
00229 
00230 void LLViewerInventoryItem::setTransactionID(const LLTransactionID& transaction_id)
00231 {
00232         mTransactionID = transaction_id;
00233 }
00234 // virtual
00235 void LLViewerInventoryItem::packMessage(LLMessageSystem* msg) const
00236 {
00237         msg->addUUIDFast(_PREHASH_ItemID, mUUID);
00238         msg->addUUIDFast(_PREHASH_FolderID, mParentUUID);
00239         mPermissions.packMessage(msg);
00240         msg->addUUIDFast(_PREHASH_TransactionID, mTransactionID);
00241         S8 type = static_cast<S8>(mType);
00242         msg->addS8Fast(_PREHASH_Type, type);
00243         type = static_cast<S8>(mInventoryType);
00244         msg->addS8Fast(_PREHASH_InvType, type);
00245         msg->addU32Fast(_PREHASH_Flags, mFlags);
00246         mSaleInfo.packMessage(msg);
00247         msg->addStringFast(_PREHASH_Name, mName);
00248         msg->addStringFast(_PREHASH_Description, mDescription);
00249         msg->addS32Fast(_PREHASH_CreationDate, mCreationDate);
00250         U32 crc = getCRC32();
00251         msg->addU32Fast(_PREHASH_CRC, crc);
00252 }
00253 // virtual
00254 BOOL LLViewerInventoryItem::importFile(FILE* fp)
00255 {
00256         BOOL rv = LLInventoryItem::importFile(fp);
00257         mIsComplete = TRUE;
00258         return rv;
00259 }
00260 
00261 // virtual
00262 BOOL LLViewerInventoryItem::importLegacyStream(std::istream& input_stream)
00263 {
00264         BOOL rv = LLInventoryItem::importLegacyStream(input_stream);
00265         mIsComplete = TRUE;
00266         return rv;
00267 }
00268 
00269 bool LLViewerInventoryItem::importFileLocal(FILE* fp)
00270 {
00271         // TODO: convert all functions that return BOOL to return bool
00272         bool rv = (LLInventoryItem::importFile(fp) ? true : false);
00273         mIsComplete = false;
00274         return rv;
00275 }
00276 
00277 bool LLViewerInventoryItem::exportFileLocal(FILE* fp) const
00278 {
00279         char uuid_str[UUID_STR_LENGTH];         /* Flawfinder: ignore */
00280         fprintf(fp, "\tinv_item\t0\n\t{\n");
00281         mUUID.toString(uuid_str);
00282         fprintf(fp, "\t\titem_id\t%s\n", uuid_str);
00283         mParentUUID.toString(uuid_str);
00284         fprintf(fp, "\t\tparent_id\t%s\n", uuid_str);
00285         mPermissions.exportFile(fp);
00286         fprintf(fp, "\t\ttype\t%s\n", LLAssetType::lookup(mType));
00287         const char* inv_type_str = LLInventoryType::lookup(mInventoryType);
00288         if(inv_type_str) fprintf(fp, "\t\tinv_type\t%s\n", inv_type_str);
00289         fprintf(fp, "\t\tname\t%s|\n", mName.c_str());
00290         fprintf(fp, "\t\tcreation_date\t%d\n", mCreationDate);
00291         fprintf(fp,"\t}\n");
00292         return true;
00293 }
00294 
00295 void LLViewerInventoryItem::updateParentOnServer(BOOL restamp) const
00296 {
00297         LLMessageSystem* msg = gMessageSystem;
00298         msg->newMessageFast(_PREHASH_MoveInventoryItem);
00299         msg->nextBlockFast(_PREHASH_AgentData);
00300         msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
00301         msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
00302         msg->addBOOLFast(_PREHASH_Stamp, restamp);
00303         msg->nextBlockFast(_PREHASH_InventoryData);
00304         msg->addUUIDFast(_PREHASH_ItemID, mUUID);
00305         msg->addUUIDFast(_PREHASH_FolderID, mParentUUID);
00306         msg->addString("NewName", NULL);
00307         gAgent.sendReliableMessage();
00308 }
00309 
00310 //void LLViewerInventoryItem::setCloneCount(S32 clones)
00311 //{
00312 //      mClones = clones;
00313 //}
00314 
00315 //S32 LLViewerInventoryItem::getCloneCount() const
00316 //{
00317 //      return mClones;
00318 //}
00319 
00323 
00324 LLViewerInventoryCategory::LLViewerInventoryCategory(const LLUUID& uuid,
00325                                                                                                          const LLUUID& parent_uuid,
00326                                                                                                          LLAssetType::EType pref,
00327                                                                                                          const LLString& name,
00328                                                                                                          const LLUUID& owner_id) :
00329         LLInventoryCategory(uuid, parent_uuid, pref, name),
00330         mOwnerID(owner_id),
00331         mVersion(LLViewerInventoryCategory::VERSION_UNKNOWN),
00332         mDescendentCount(LLViewerInventoryCategory::DESCENDENT_COUNT_UNKNOWN)
00333 {
00334         mDescendentsRequested.reset();
00335 }
00336 
00337 LLViewerInventoryCategory::LLViewerInventoryCategory(const LLUUID& owner_id) :
00338         mOwnerID(owner_id),
00339         mVersion(LLViewerInventoryCategory::VERSION_UNKNOWN),
00340         mDescendentCount(LLViewerInventoryCategory::DESCENDENT_COUNT_UNKNOWN)
00341 {
00342         mDescendentsRequested.reset();
00343 }
00344 
00345 LLViewerInventoryCategory::LLViewerInventoryCategory(const LLViewerInventoryCategory* other)
00346 {
00347         copy(other);
00348 }
00349 
00350 LLViewerInventoryCategory::~LLViewerInventoryCategory()
00351 {
00352 }
00353 
00354 // virtual
00355 void LLViewerInventoryCategory::copy(const LLViewerInventoryCategory* other)
00356 {
00357         LLInventoryCategory::copy(other);
00358         mOwnerID = other->mOwnerID;
00359         mVersion = other->mVersion;
00360         mDescendentCount = other->mDescendentCount;
00361         mDescendentsRequested = other->mDescendentsRequested;
00362 }
00363 
00364 
00365 void LLViewerInventoryCategory::updateParentOnServer(BOOL restamp) const
00366 {
00367         LLMessageSystem* msg = gMessageSystem;
00368         msg->newMessageFast(_PREHASH_MoveInventoryFolder);
00369         msg->nextBlockFast(_PREHASH_AgentData);
00370         msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
00371         msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
00372 
00373         msg->addBOOL("Stamp", restamp);
00374         msg->nextBlockFast(_PREHASH_InventoryData);
00375         msg->addUUIDFast(_PREHASH_FolderID, mUUID);
00376         msg->addUUIDFast(_PREHASH_ParentID, mParentUUID);
00377         gAgent.sendReliableMessage();
00378 }
00379 
00380 void LLViewerInventoryCategory::updateServer(BOOL is_new) const
00381 {
00382         // communicate that change with the server.
00383         if(LLAssetType::AT_NONE != mPreferredType)
00384         {
00385                 LLNotifyBox::showXml("CannotModifyProtectedCategories");
00386                 return;
00387         }
00388 
00389         LLInventoryModel::LLCategoryUpdate up(mParentUUID, is_new ? 1 : 0);
00390         gInventory.accountForUpdate(up);
00391 
00392         LLMessageSystem* msg = gMessageSystem;
00393         msg->newMessageFast(_PREHASH_UpdateInventoryFolder);
00394         msg->nextBlockFast(_PREHASH_AgentData);
00395         msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
00396         msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
00397         msg->nextBlockFast(_PREHASH_FolderData);
00398         packMessage(msg);
00399         gAgent.sendReliableMessage();
00400 }
00401 
00402 void LLViewerInventoryCategory::removeFromServer( void )
00403 {
00404         llinfos << "Removing inventory category " << mUUID << " from server."
00405                         << llendl;
00406         // communicate that change with the server.
00407         if(LLAssetType::AT_NONE != mPreferredType)
00408         {
00409                 LLNotifyBox::showXml("CannotRemoveProtectedCategories");
00410                 return;
00411         }
00412 
00413         LLInventoryModel::LLCategoryUpdate up(mParentUUID, -1);
00414         gInventory.accountForUpdate(up);
00415 
00416         LLMessageSystem* msg = gMessageSystem;
00417         msg->newMessageFast(_PREHASH_RemoveInventoryFolder);
00418         msg->nextBlockFast(_PREHASH_AgentData);
00419         msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
00420         msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
00421         msg->nextBlockFast(_PREHASH_FolderData);
00422         msg->addUUIDFast(_PREHASH_FolderID, mUUID);
00423         gAgent.sendReliableMessage();
00424 }
00425 
00426 bool LLViewerInventoryCategory::fetchDescendents()
00427 {
00428         if((VERSION_UNKNOWN == mVersion)
00429            && mDescendentsRequested.hasExpired())
00430         {
00431                 const F32 FETCH_TIMER_EXPIRY = 10.0f;
00432                 mDescendentsRequested.reset();
00433                 mDescendentsRequested.setTimerExpirySec(FETCH_TIMER_EXPIRY);
00434 
00435                 LLMessageSystem* msg = gMessageSystem;
00436                 msg->newMessage("FetchInventoryDescendents");
00437                 msg->nextBlock("AgentData");
00438                 msg->addUUID("AgentID", gAgent.getID());
00439                 msg->addUUID("SessionID", gAgent.getSessionID());
00440                 msg->nextBlock("InventoryData");
00441                 msg->addUUID("FolderID", mUUID);
00442                 msg->addUUID("OwnerID", mOwnerID);
00443                 // bitfield
00444                 // 1 = by date
00445                 // 2 = folders by date
00446                 // Need to mask off anything but the first bit.
00447                 // This comes from LLInventoryFilter from llfolderview.h
00448                 U32 sort_order = gSavedSettings.getU32("InventorySortOrder") & 0x1;
00449                 msg->addS32("SortOrder", sort_order);
00450                 msg->addBOOL("FetchFolders", FALSE);
00451                 msg->addBOOL("FetchItems", TRUE);
00452                 gAgent.sendReliableMessage();
00453                 return true;
00454         }
00455         return false;
00456 }
00457 
00458 bool LLViewerInventoryCategory::importFileLocal(FILE* fp)
00459 {
00460         // *NOTE: This buffer size is hard coded into scanf() below.
00461         char buffer[MAX_STRING];                /* Flawfinder: ignore */
00462         char keyword[MAX_STRING];               /* Flawfinder: ignore */
00463         char valuestr[MAX_STRING];              /* Flawfinder: ignore */
00464 
00465         keyword[0] = '\0';
00466         valuestr[0] = '\0';
00467         while(!feof(fp))
00468         {
00469                 if (fgets(buffer, MAX_STRING, fp) == NULL)
00470                 {
00471                         buffer[0] = '\0';
00472                 }
00473                 
00474                 sscanf( /* Flawfinder: ignore */
00475                         buffer, " %254s %254s", keyword, valuestr); 
00476                 if(0 == strcmp("{",keyword))
00477                 {
00478                         continue;
00479                 }
00480                 if(0 == strcmp("}", keyword))
00481                 {
00482                         break;
00483                 }
00484                 else if(0 == strcmp("cat_id", keyword))
00485                 {
00486                         mUUID.set(valuestr);
00487                 }
00488                 else if(0 == strcmp("parent_id", keyword))
00489                 {
00490                         mParentUUID.set(valuestr);
00491                 }
00492                 else if(0 == strcmp("type", keyword))
00493                 {
00494                         mType = LLAssetType::lookup(valuestr);
00495                 }
00496                 else if(0 == strcmp("pref_type", keyword))
00497                 {
00498                         mPreferredType = LLAssetType::lookup(valuestr);
00499                 }
00500                 else if(0 == strcmp("name", keyword))
00501                 {
00502                         //strcpy(valuestr, buffer + strlen(keyword) + 3);
00503                         // *NOTE: Not ANSI C, but widely supported.
00504                         sscanf( /* Flawfinder: ignore */
00505                                 buffer, " %254s %254[^|]", keyword, valuestr);
00506                         mName.assign(valuestr);
00507                         LLString::replaceNonstandardASCII(mName, ' ');
00508                         LLString::replaceChar(mName, '|', ' ');
00509                 }
00510                 else if(0 == strcmp("owner_id", keyword))
00511                 {
00512                         mOwnerID.set(valuestr);
00513                 }
00514                 else if(0 == strcmp("version", keyword))
00515                 {
00516                         sscanf(valuestr, "%d", &mVersion);
00517                 }
00518                 else
00519                 {
00520                         llwarns << "unknown keyword '" << keyword
00521                                         << "' in inventory import category "  << mUUID << llendl;
00522                 }
00523         }
00524         return true;
00525 }
00526 
00527 bool LLViewerInventoryCategory::exportFileLocal(FILE* fp) const
00528 {
00529         char uuid_str[UUID_STR_LENGTH];         /* Flawfinder: ignore */
00530         fprintf(fp, "\tinv_category\t0\n\t{\n");
00531         mUUID.toString(uuid_str);
00532         fprintf(fp, "\t\tcat_id\t%s\n", uuid_str);
00533         mParentUUID.toString(uuid_str);
00534         fprintf(fp, "\t\tparent_id\t%s\n", uuid_str);
00535         fprintf(fp, "\t\ttype\t%s\n", LLAssetType::lookup(mType));
00536         fprintf(fp, "\t\tpref_type\t%s\n", LLAssetType::lookup(mPreferredType));
00537         fprintf(fp, "\t\tname\t%s|\n", mName.c_str());
00538         mOwnerID.toString(uuid_str);
00539         fprintf(fp, "\t\towner_id\t%s\n", uuid_str);
00540         fprintf(fp, "\t\tversion\t%d\n", mVersion);
00541         fprintf(fp,"\t}\n");
00542         return true;
00543 }
00544 
00548 
00549 /*
00550 void inventory_reliable_callback(void**, S32 status)
00551 {
00552         if(0 != status)
00553         {
00554                 char buffer[MAX_STRING];
00555                 sprintf(buffer, "Reliable packet failure: %d", status);
00556                 llwarns << buffer << llendl;
00557         }
00558 }
00559 */
00560 LLInventoryCallbackManager *LLInventoryCallbackManager::sInstance = NULL;
00561 
00562 LLInventoryCallbackManager::LLInventoryCallbackManager() :
00563         mLastCallback(0)
00564 {
00565         if( sInstance != NULL )
00566         {
00567                 llwarns << "LLInventoryCallbackManager::LLInventoryCallbackManager: unexpected multiple instances" << llendl;
00568                 return;
00569         }
00570         sInstance = this;
00571 }
00572 
00573 LLInventoryCallbackManager::~LLInventoryCallbackManager()
00574 {
00575         if( sInstance != this )
00576         {
00577                 llwarns << "LLInventoryCallbackManager::~LLInventoryCallbackManager: unexpected multiple instances" << llendl;
00578                 return;
00579         }
00580         sInstance = NULL;
00581 }
00582 
00583 U32 LLInventoryCallbackManager::registerCB(LLPointer<LLInventoryCallback> cb)
00584 {
00585         if (cb.isNull())
00586                 return 0;
00587 
00588         mLastCallback++;
00589         if (!mLastCallback)
00590                 mLastCallback++;
00591 
00592         mMap[mLastCallback] = cb;
00593         return mLastCallback;
00594 }
00595 
00596 void LLInventoryCallbackManager::fire(U32 callback_id, const LLUUID& item_id)
00597 {
00598         if (!callback_id || item_id.isNull())
00599                 return;
00600 
00601         std::map<U32, LLPointer<LLInventoryCallback> >::iterator i;
00602 
00603         i = mMap.find(callback_id);
00604         if (i != mMap.end())
00605         {
00606                 (*i).second->fire(item_id);
00607                 mMap.erase(i);
00608         }
00609 }
00610 
00611 void WearOnAvatarCallback::fire(const LLUUID& inv_item)
00612 {
00613         if (inv_item.isNull())
00614                 return;
00615 
00616         LLViewerInventoryItem *item = gInventory.getItem(inv_item);
00617         if (item)
00618         {
00619                 wear_inventory_item_on_avatar(item);
00620         }
00621 }
00622 
00623 RezAttachmentCallback::RezAttachmentCallback(LLViewerJointAttachment *attachmentp)
00624 {
00625         mAttach = attachmentp;
00626 }
00627 RezAttachmentCallback::~RezAttachmentCallback()
00628 {
00629 }
00630 
00631 void RezAttachmentCallback::fire(const LLUUID& inv_item)
00632 {
00633         if (inv_item.isNull())
00634                 return;
00635 
00636         LLViewerInventoryItem *item = gInventory.getItem(inv_item);
00637         if (item)
00638         {
00639                 rez_attachment(item, mAttach);
00640         }
00641 }
00642 
00643 extern LLGestureManager gGestureManager;
00644 void ActivateGestureCallback::fire(const LLUUID& inv_item)
00645 {
00646         if (inv_item.isNull())
00647                 return;
00648 
00649         gGestureManager.activateGesture(inv_item);
00650 }
00651 
00652 LLInventoryCallbackManager gInventoryCallbacks;
00653 
00654 void create_inventory_item(const LLUUID& agent_id, const LLUUID& session_id,
00655                                                    const LLUUID& parent, const LLTransactionID& transaction_id,
00656                                                    const std::string& name,
00657                                                    const std::string& desc, LLAssetType::EType asset_type,
00658                                                    LLInventoryType::EType inv_type, EWearableType wtype,
00659                                                    U32 next_owner_perm,
00660                                                    LLPointer<LLInventoryCallback> cb)
00661 {
00662         LLMessageSystem* msg = gMessageSystem;
00663         msg->newMessageFast(_PREHASH_CreateInventoryItem);
00664         msg->nextBlock(_PREHASH_AgentData);
00665         msg->addUUIDFast(_PREHASH_AgentID, agent_id);
00666         msg->addUUIDFast(_PREHASH_SessionID, session_id);
00667         msg->nextBlock(_PREHASH_InventoryBlock);
00668         msg->addU32Fast(_PREHASH_CallbackID, gInventoryCallbacks.registerCB(cb));
00669         msg->addUUIDFast(_PREHASH_FolderID, parent);
00670         msg->addUUIDFast(_PREHASH_TransactionID, transaction_id);
00671         msg->addU32Fast(_PREHASH_NextOwnerMask, next_owner_perm);
00672         msg->addS8Fast(_PREHASH_Type, (S8)asset_type);
00673         msg->addS8Fast(_PREHASH_InvType, (S8)inv_type);
00674         msg->addU8Fast(_PREHASH_WearableType, (U8)wtype);
00675         msg->addStringFast(_PREHASH_Name, name);
00676         msg->addStringFast(_PREHASH_Description, desc);
00677         
00678         gAgent.sendReliableMessage();
00679 }
00680 
00681 void copy_inventory_item(
00682         const LLUUID& agent_id,
00683         const LLUUID& current_owner,
00684         const LLUUID& item_id,
00685         const LLUUID& parent_id,
00686         const std::string& new_name,
00687         LLPointer<LLInventoryCallback> cb)
00688 {
00689         LLMessageSystem* msg = gMessageSystem;
00690         msg->newMessageFast(_PREHASH_CopyInventoryItem);
00691         msg->nextBlockFast(_PREHASH_AgentData);
00692         msg->addUUIDFast(_PREHASH_AgentID, agent_id);
00693         msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
00694         msg->nextBlockFast(_PREHASH_InventoryData);
00695         msg->addU32Fast(_PREHASH_CallbackID, gInventoryCallbacks.registerCB(cb));
00696         msg->addUUIDFast(_PREHASH_OldAgentID, current_owner);
00697         msg->addUUIDFast(_PREHASH_OldItemID, item_id);
00698         msg->addUUIDFast(_PREHASH_NewFolderID, parent_id);
00699         msg->addStringFast(_PREHASH_NewName, new_name);
00700         gAgent.sendReliableMessage();
00701 }
00702 
00703 void move_inventory_item(
00704         const LLUUID& agent_id,
00705         const LLUUID& session_id,
00706         const LLUUID& item_id,
00707         const LLUUID& parent_id,
00708         const std::string& new_name,
00709         LLPointer<LLInventoryCallback> cb)
00710 {
00711         LLMessageSystem* msg = gMessageSystem;
00712         msg->newMessageFast(_PREHASH_MoveInventoryItem);
00713         msg->nextBlockFast(_PREHASH_AgentData);
00714         msg->addUUIDFast(_PREHASH_AgentID, agent_id);
00715         msg->addUUIDFast(_PREHASH_SessionID, session_id);
00716         msg->addBOOLFast(_PREHASH_Stamp, FALSE);
00717         msg->nextBlockFast(_PREHASH_InventoryData);
00718         msg->addUUIDFast(_PREHASH_ItemID, item_id);
00719         msg->addUUIDFast(_PREHASH_FolderID, parent_id);
00720         msg->addStringFast(_PREHASH_NewName, new_name);
00721         gAgent.sendReliableMessage();
00722 }
00723 
00724 class LLCopyInventoryFromNotecardResponder : public LLHTTPClient::Responder
00725 {
00726 public:
00727         //If we get back a normal response, handle it here
00728         virtual void result(const LLSD& content)
00729         {
00730                 // What do we do here?
00731                 llinfos << "CopyInventoryFromNotecard request successful." << llendl;
00732         }
00733 
00734         //If we get back an error (not found, etc...), handle it here
00735         virtual void error(U32 status, const std::string& reason)
00736         {
00737                 llinfos << "LLCopyInventoryFromNotecardResponder::error "
00738                         << status << ": " << reason << llendl;
00739         }
00740 };
00741 
00742 void copy_inventory_from_notecard(const LLUUID& object_id, const LLUUID& notecard_inv_id, const LLInventoryItem *src, U32 callback_id)
00743 {
00744         LLSD body;
00745         LLViewerRegion* viewer_region = NULL;
00746         if(object_id.notNull())
00747         {
00748                 LLViewerObject* vo = gObjectList.findObject(object_id);
00749                 if(vo)
00750                 {
00751                         viewer_region = vo->getRegion();
00752                 }
00753         }
00754 
00755         // Fallback to the agents region if for some reason the 
00756         // object isn't found in the viewer.
00757         if(!viewer_region)
00758         {
00759                 viewer_region = gAgent.getRegion();
00760         }
00761 
00762         if(viewer_region)
00763         {
00764                 std::string url = viewer_region->getCapability("CopyInventoryFromNotecard");
00765                 if (!url.empty())
00766                 {
00767                         body["notecard-id"] = notecard_inv_id;
00768                         body["object-id"] = object_id;
00769                         body["item-id"] = src->getUUID();
00770                         body["folder-id"] = gInventory.findCategoryUUIDForType(src->getType());
00771                         body["callback-id"] = (LLSD::Integer)callback_id;
00772 
00773                         LLHTTPClient::post(url, body, new LLCopyInventoryFromNotecardResponder());
00774                 }
00775         }
00776 }

Generated on Thu Jul 1 06:09:28 2010 for Second Life Viewer by  doxygen 1.4.7