diff options
Diffstat (limited to 'linden/indra/newview/llinventorymodel.cpp')
-rw-r--r-- | linden/indra/newview/llinventorymodel.cpp | 135 |
1 files changed, 84 insertions, 51 deletions
diff --git a/linden/indra/newview/llinventorymodel.cpp b/linden/indra/newview/llinventorymodel.cpp index 15f5398..0e6056f 100644 --- a/linden/indra/newview/llinventorymodel.cpp +++ b/linden/indra/newview/llinventorymodel.cpp | |||
@@ -56,6 +56,7 @@ | |||
56 | #include "llcallbacklist.h" | 56 | #include "llcallbacklist.h" |
57 | #include "llpreview.h" | 57 | #include "llpreview.h" |
58 | #include "llviewercontrol.h" | 58 | #include "llviewercontrol.h" |
59 | #include "llvoavatar.h" | ||
59 | #include "llsdutil.h" | 60 | #include "llsdutil.h" |
60 | #include <deque> | 61 | #include <deque> |
61 | 62 | ||
@@ -304,7 +305,7 @@ LLUUID LLInventoryModel::findCategoryUUIDForType(LLAssetType::EType t, bool crea | |||
304 | LLUUID root_id = gAgent.getInventoryRootID(); | 305 | LLUUID root_id = gAgent.getInventoryRootID(); |
305 | if(root_id.notNull()) | 306 | if(root_id.notNull()) |
306 | { | 307 | { |
307 | rv = createNewCategory(root_id, t, NULL); | 308 | rv = createNewCategory(root_id, t, LLStringUtil::null); |
308 | } | 309 | } |
309 | } | 310 | } |
310 | return rv; | 311 | return rv; |
@@ -344,7 +345,7 @@ LLUUID LLInventoryModel::findCatUUID(LLAssetType::EType preferred_type) | |||
344 | // based on preferred type. Returns the UUID of the new category. | 345 | // based on preferred type. Returns the UUID of the new category. |
345 | LLUUID LLInventoryModel::createNewCategory(const LLUUID& parent_id, | 346 | LLUUID LLInventoryModel::createNewCategory(const LLUUID& parent_id, |
346 | LLAssetType::EType preferred_type, | 347 | LLAssetType::EType preferred_type, |
347 | const LLString& pname) | 348 | const std::string& pname) |
348 | { | 349 | { |
349 | LLUUID id; | 350 | LLUUID id; |
350 | if(!isInventoryUsable()) | 351 | if(!isInventoryUsable()) |
@@ -360,7 +361,7 @@ LLUUID LLInventoryModel::createNewCategory(const LLUUID& parent_id, | |||
360 | } | 361 | } |
361 | 362 | ||
362 | id.generate(); | 363 | id.generate(); |
363 | LLString name = pname; | 364 | std::string name = pname; |
364 | if(!pname.empty()) | 365 | if(!pname.empty()) |
365 | { | 366 | { |
366 | name.assign(pname); | 367 | name.assign(pname); |
@@ -473,13 +474,13 @@ void LLInventoryModel::collectDescendentsIf(const LLUUID& id, | |||
473 | 474 | ||
474 | // Generates a string containing the path to the item specified by | 475 | // Generates a string containing the path to the item specified by |
475 | // item_id. | 476 | // item_id. |
476 | void LLInventoryModel::appendPath(const LLUUID& id, LLString& path) | 477 | void LLInventoryModel::appendPath(const LLUUID& id, std::string& path) |
477 | { | 478 | { |
478 | LLString temp; | 479 | std::string temp; |
479 | LLInventoryObject* obj = getObject(id); | 480 | LLInventoryObject* obj = getObject(id); |
480 | LLUUID parent_id; | 481 | LLUUID parent_id; |
481 | if(obj) parent_id = obj->getParentUUID(); | 482 | if(obj) parent_id = obj->getParentUUID(); |
482 | LLString forward_slash("/"); | 483 | std::string forward_slash("/"); |
483 | while(obj) | 484 | while(obj) |
484 | { | 485 | { |
485 | obj = getCategory(parent_id); | 486 | obj = getCategory(parent_id); |
@@ -1516,19 +1517,15 @@ void LLInventoryModel::cache( | |||
1516 | items, | 1517 | items, |
1517 | INCLUDE_TRASH, | 1518 | INCLUDE_TRASH, |
1518 | can_cache); | 1519 | can_cache); |
1519 | char agent_id_str[UUID_STR_LENGTH]; /*Flawfinder: ignore*/ | 1520 | std::string agent_id_str; |
1520 | char inventory_filename[LL_MAX_PATH]; /*Flawfinder: ignore*/ | 1521 | std::string inventory_filename; |
1521 | agent_id.toString(agent_id_str); | 1522 | agent_id.toString(agent_id_str); |
1522 | std::string path(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, agent_id_str)); | 1523 | std::string path(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, agent_id_str)); |
1523 | snprintf( /* Flawfinder: ignore */ | 1524 | inventory_filename = llformat(CACHE_FORMAT_STRING, path.c_str()); |
1524 | inventory_filename, | ||
1525 | LL_MAX_PATH, | ||
1526 | CACHE_FORMAT_STRING, | ||
1527 | path.c_str()); | ||
1528 | saveToFile(inventory_filename, categories, items); | 1525 | saveToFile(inventory_filename, categories, items); |
1529 | std::string gzip_filename(inventory_filename); | 1526 | std::string gzip_filename(inventory_filename); |
1530 | gzip_filename.append(".gz"); | 1527 | gzip_filename.append(".gz"); |
1531 | if(gzip_file(inventory_filename, gzip_filename.c_str())) | 1528 | if(gzip_file(inventory_filename, gzip_filename)) |
1532 | { | 1529 | { |
1533 | lldebugs << "Successfully compressed " << inventory_filename << llendl; | 1530 | lldebugs << "Successfully compressed " << inventory_filename << llendl; |
1534 | LLFile::remove(inventory_filename); | 1531 | LLFile::remove(inventory_filename); |
@@ -1766,16 +1763,16 @@ bool LLInventoryModel::loadSkeleton( | |||
1766 | response_t::const_iterator skel; | 1763 | response_t::const_iterator skel; |
1767 | skel = (*it).find("name"); | 1764 | skel = (*it).find("name"); |
1768 | if(skel == no_response) goto clean_cat; | 1765 | if(skel == no_response) goto clean_cat; |
1769 | cat->rename(LLString((*skel).second.c_str())); | 1766 | cat->rename(std::string((*skel).second)); |
1770 | skel = (*it).find("folder_id"); | 1767 | skel = (*it).find("folder_id"); |
1771 | if(skel == no_response) goto clean_cat; | 1768 | if(skel == no_response) goto clean_cat; |
1772 | id.set((*skel).second.c_str()); | 1769 | id.set((*skel).second); |
1773 | // if an id is null, it locks the viewer. | 1770 | // if an id is null, it locks the viewer. |
1774 | if(id.isNull()) goto clean_cat; | 1771 | if(id.isNull()) goto clean_cat; |
1775 | cat->setUUID(id); | 1772 | cat->setUUID(id); |
1776 | skel = (*it).find("parent_id"); | 1773 | skel = (*it).find("parent_id"); |
1777 | if(skel == no_response) goto clean_cat; | 1774 | if(skel == no_response) goto clean_cat; |
1778 | id.set((*skel).second.c_str()); | 1775 | id.set((*skel).second); |
1779 | cat->setParent(id); | 1776 | cat->setParent(id); |
1780 | skel = (*it).find("type_default"); | 1777 | skel = (*it).find("type_default"); |
1781 | if(skel == no_response) | 1778 | if(skel == no_response) |
@@ -1805,25 +1802,21 @@ bool LLInventoryModel::loadSkeleton( | |||
1805 | { | 1802 | { |
1806 | cat_array_t categories; | 1803 | cat_array_t categories; |
1807 | item_array_t items; | 1804 | item_array_t items; |
1808 | char owner_id_str[UUID_STR_LENGTH]; /*Flawfinder: ignore*/ | 1805 | std::string owner_id_str; |
1809 | owner_id.toString(owner_id_str); | 1806 | owner_id.toString(owner_id_str); |
1810 | std::string path(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, owner_id_str)); | 1807 | std::string path(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, owner_id_str)); |
1811 | char inventory_filename[LL_MAX_PATH]; /*Flawfinder: ignore*/ | 1808 | std::string inventory_filename; |
1812 | snprintf( /* Flawfinder: ignore */ | 1809 | inventory_filename = llformat(CACHE_FORMAT_STRING, path.c_str()); |
1813 | inventory_filename, | ||
1814 | LL_MAX_PATH, | ||
1815 | CACHE_FORMAT_STRING, | ||
1816 | path.c_str()); | ||
1817 | const S32 NO_VERSION = LLViewerInventoryCategory::VERSION_UNKNOWN; | 1810 | const S32 NO_VERSION = LLViewerInventoryCategory::VERSION_UNKNOWN; |
1818 | std::string gzip_filename(inventory_filename); | 1811 | std::string gzip_filename(inventory_filename); |
1819 | gzip_filename.append(".gz"); | 1812 | gzip_filename.append(".gz"); |
1820 | LLFILE* fp = LLFile::fopen(gzip_filename.c_str(), "rb"); /*Flawfinder: ignore*/ | 1813 | LLFILE* fp = LLFile::fopen(gzip_filename, "rb"); |
1821 | bool remove_inventory_file = false; | 1814 | bool remove_inventory_file = false; |
1822 | if(fp) | 1815 | if(fp) |
1823 | { | 1816 | { |
1824 | fclose(fp); | 1817 | fclose(fp); |
1825 | fp = NULL; | 1818 | fp = NULL; |
1826 | if(gunzip_file(gzip_filename.c_str(), inventory_filename)) | 1819 | if(gunzip_file(gzip_filename, inventory_filename)) |
1827 | { | 1820 | { |
1828 | // we only want to remove the inventory file if it was | 1821 | // we only want to remove the inventory file if it was |
1829 | // gzipped before we loaded, and we successfully | 1822 | // gzipped before we loaded, and we successfully |
@@ -1977,14 +1970,14 @@ bool LLInventoryModel::loadMeat( | |||
1977 | response_t::const_iterator meat; | 1970 | response_t::const_iterator meat; |
1978 | meat = (*it).find("name"); | 1971 | meat = (*it).find("name"); |
1979 | if(meat == no_response) goto clean_item; | 1972 | if(meat == no_response) goto clean_item; |
1980 | item->rename(LLString((*meat).second.c_str())); | 1973 | item->rename(std::string((*meat).second)); |
1981 | meat = (*it).find("item_id"); | 1974 | meat = (*it).find("item_id"); |
1982 | if(meat == no_response) goto clean_item; | 1975 | if(meat == no_response) goto clean_item; |
1983 | id.set((*meat).second.c_str()); | 1976 | id.set((*meat).second); |
1984 | item->setUUID(id); | 1977 | item->setUUID(id); |
1985 | meat = (*it).find("parent_id"); | 1978 | meat = (*it).find("parent_id"); |
1986 | if(meat == no_response) goto clean_item; | 1979 | if(meat == no_response) goto clean_item; |
1987 | id.set((*meat).second.c_str()); | 1980 | id.set((*meat).second); |
1988 | item->setParent(id); | 1981 | item->setParent(id); |
1989 | meat = (*it).find("type"); | 1982 | meat = (*it).find("type"); |
1990 | if(meat == no_response) goto clean_item; | 1983 | if(meat == no_response) goto clean_item; |
@@ -1998,7 +1991,7 @@ bool LLInventoryModel::loadMeat( | |||
1998 | } | 1991 | } |
1999 | meat = (*it).find("data_id"); | 1992 | meat = (*it).find("data_id"); |
2000 | if(meat == no_response) goto clean_item; | 1993 | if(meat == no_response) goto clean_item; |
2001 | id.set((*meat).second.c_str()); | 1994 | id.set((*meat).second); |
2002 | if(LLAssetType::AT_CALLINGCARD == type) | 1995 | if(LLAssetType::AT_CALLINGCARD == type) |
2003 | { | 1996 | { |
2004 | LLPermissions perm; | 1997 | LLPermissions perm; |
@@ -2243,16 +2236,16 @@ void LLInventoryModel::buildParentChildMap() | |||
2243 | struct LLUUIDAndName | 2236 | struct LLUUIDAndName |
2244 | { | 2237 | { |
2245 | LLUUIDAndName() {} | 2238 | LLUUIDAndName() {} |
2246 | LLUUIDAndName(const LLUUID& id, const LLString& name); | 2239 | LLUUIDAndName(const LLUUID& id, const std::string& name); |
2247 | bool operator==(const LLUUIDAndName& rhs) const; | 2240 | bool operator==(const LLUUIDAndName& rhs) const; |
2248 | bool operator<(const LLUUIDAndName& rhs) const; | 2241 | bool operator<(const LLUUIDAndName& rhs) const; |
2249 | bool operator>(const LLUUIDAndName& rhs) const; | 2242 | bool operator>(const LLUUIDAndName& rhs) const; |
2250 | 2243 | ||
2251 | LLUUID mID; | 2244 | LLUUID mID; |
2252 | LLString mName; | 2245 | std::string mName; |
2253 | }; | 2246 | }; |
2254 | 2247 | ||
2255 | LLUUIDAndName::LLUUIDAndName(const LLUUID& id, const LLString& name) : | 2248 | LLUUIDAndName::LLUUIDAndName(const LLUUID& id, const std::string& name) : |
2256 | mID(id), mName(name) | 2249 | mID(id), mName(name) |
2257 | { | 2250 | { |
2258 | } | 2251 | } |
@@ -2340,12 +2333,11 @@ bool LLUUIDAndName::operator>(const LLUUIDAndName& rhs) const | |||
2340 | //} | 2333 | //} |
2341 | 2334 | ||
2342 | // static | 2335 | // static |
2343 | bool LLInventoryModel::loadFromFile( | 2336 | bool LLInventoryModel::loadFromFile(const std::string& filename, |
2344 | const char* filename, | 2337 | LLInventoryModel::cat_array_t& categories, |
2345 | LLInventoryModel::cat_array_t& categories, | 2338 | LLInventoryModel::item_array_t& items) |
2346 | LLInventoryModel::item_array_t& items) | ||
2347 | { | 2339 | { |
2348 | if(!filename) | 2340 | if(filename.empty()) |
2349 | { | 2341 | { |
2350 | llerrs << "Filename is Null!" << llendl; | 2342 | llerrs << "Filename is Null!" << llendl; |
2351 | return false; | 2343 | return false; |
@@ -2413,12 +2405,11 @@ bool LLInventoryModel::loadFromFile( | |||
2413 | } | 2405 | } |
2414 | 2406 | ||
2415 | // static | 2407 | // static |
2416 | bool LLInventoryModel::saveToFile( | 2408 | bool LLInventoryModel::saveToFile(const std::string& filename, |
2417 | const char* filename, | 2409 | const cat_array_t& categories, |
2418 | const cat_array_t& categories, | 2410 | const item_array_t& items) |
2419 | const item_array_t& items) | ||
2420 | { | 2411 | { |
2421 | if(!filename) | 2412 | if(filename.empty()) |
2422 | { | 2413 | { |
2423 | llerrs << "Filename is Null!" << llendl; | 2414 | llerrs << "Filename is Null!" << llendl; |
2424 | return false; | 2415 | return false; |
@@ -2993,7 +2984,7 @@ void LLInventoryModel::processMoveInventoryItem(LLMessageSystem* msg, void**) | |||
2993 | 2984 | ||
2994 | LLUUID item_id; | 2985 | LLUUID item_id; |
2995 | LLUUID folder_id; | 2986 | LLUUID folder_id; |
2996 | char new_name[MAX_STRING]; /*Flawfinder: ignore*/ | 2987 | std::string new_name; |
2997 | bool anything_changed = false; | 2988 | bool anything_changed = false; |
2998 | S32 count = msg->getNumberOfBlocksFast(_PREHASH_InventoryData); | 2989 | S32 count = msg->getNumberOfBlocksFast(_PREHASH_InventoryData); |
2999 | for(S32 i = 0; i < count; ++i) | 2990 | for(S32 i = 0; i < count; ++i) |
@@ -3004,7 +2995,7 @@ void LLInventoryModel::processMoveInventoryItem(LLMessageSystem* msg, void**) | |||
3004 | { | 2995 | { |
3005 | LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item); | 2996 | LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item); |
3006 | msg->getUUIDFast(_PREHASH_InventoryData, _PREHASH_FolderID, folder_id, i); | 2997 | msg->getUUIDFast(_PREHASH_InventoryData, _PREHASH_FolderID, folder_id, i); |
3007 | msg->getString("InventoryData", "NewName", MAX_STRING, new_name, i); | 2998 | msg->getString("InventoryData", "NewName", new_name, i); |
3008 | 2999 | ||
3009 | lldebugs << "moving item " << item_id << " to folder " | 3000 | lldebugs << "moving item " << item_id << " to folder " |
3010 | << folder_id << llendl; | 3001 | << folder_id << llendl; |
@@ -3016,7 +3007,7 @@ void LLInventoryModel::processMoveInventoryItem(LLMessageSystem* msg, void**) | |||
3016 | gInventory.accountForUpdate(update); | 3007 | gInventory.accountForUpdate(update); |
3017 | 3008 | ||
3018 | new_item->setParent(folder_id); | 3009 | new_item->setParent(folder_id); |
3019 | if(strlen(new_name) > 0) /*Flawfinder: ignore*/ | 3010 | if (new_name.length() > 0) |
3020 | { | 3011 | { |
3021 | new_item->rename(new_name); | 3012 | new_item->rename(new_name); |
3022 | } | 3013 | } |
@@ -3074,6 +3065,45 @@ void LLInventoryModel::dumpInventory() | |||
3074 | /// LLInventoryCollectFunctor implementations | 3065 | /// LLInventoryCollectFunctor implementations |
3075 | ///---------------------------------------------------------------------------- | 3066 | ///---------------------------------------------------------------------------- |
3076 | 3067 | ||
3068 | // static | ||
3069 | bool LLInventoryCollectFunctor::itemTransferCommonlyAllowed(LLInventoryItem* item) | ||
3070 | { | ||
3071 | if (!item) | ||
3072 | return false; | ||
3073 | |||
3074 | bool allowed = false; | ||
3075 | LLVOAvatar* my_avatar = NULL; | ||
3076 | |||
3077 | switch(item->getType()) | ||
3078 | { | ||
3079 | case LLAssetType::AT_CALLINGCARD: | ||
3080 | // not allowed | ||
3081 | break; | ||
3082 | |||
3083 | case LLAssetType::AT_OBJECT: | ||
3084 | my_avatar = gAgent.getAvatarObject(); | ||
3085 | if(my_avatar && !my_avatar->isWearingAttachment(item->getUUID())) | ||
3086 | { | ||
3087 | allowed = true; | ||
3088 | } | ||
3089 | break; | ||
3090 | |||
3091 | case LLAssetType::AT_BODYPART: | ||
3092 | case LLAssetType::AT_CLOTHING: | ||
3093 | if(!gAgent.isWearingItem(item->getUUID())) | ||
3094 | { | ||
3095 | allowed = true; | ||
3096 | } | ||
3097 | break; | ||
3098 | |||
3099 | default: | ||
3100 | allowed = true; | ||
3101 | break; | ||
3102 | } | ||
3103 | |||
3104 | return allowed; | ||
3105 | } | ||
3106 | |||
3077 | bool LLIsType::operator()(LLInventoryCategory* cat, LLInventoryItem* item) | 3107 | bool LLIsType::operator()(LLInventoryCategory* cat, LLInventoryItem* item) |
3078 | { | 3108 | { |
3079 | if(mType == LLAssetType::AT_CATEGORY) | 3109 | if(mType == LLAssetType::AT_CATEGORY) |
@@ -3206,7 +3236,7 @@ bool LLNameCategoryCollector::operator()( | |||
3206 | { | 3236 | { |
3207 | if(cat) | 3237 | if(cat) |
3208 | { | 3238 | { |
3209 | if (!LLString::compareInsensitive(mName.c_str(), cat->getName().c_str())) | 3239 | if (!LLStringUtil::compareInsensitive(mName, cat->getName())) |
3210 | { | 3240 | { |
3211 | return true; | 3241 | return true; |
3212 | } | 3242 | } |
@@ -3600,11 +3630,14 @@ void LLInventoryAddedObserver::changed(U32 mask) | |||
3600 | // the network, figure out which item was updated. | 3630 | // the network, figure out which item was updated. |
3601 | // Code from Gigs Taggert, sin allowed by JC. | 3631 | // Code from Gigs Taggert, sin allowed by JC. |
3602 | LLMessageSystem* msg = gMessageSystem; | 3632 | LLMessageSystem* msg = gMessageSystem; |
3603 | const char* msg_name = msg->getMessageName(); | 3633 | std::string msg_name = msg->getMessageName(); |
3604 | if (!msg_name) return; | 3634 | if (msg_name.empty()) |
3605 | 3635 | { | |
3636 | return; | ||
3637 | } | ||
3638 | |||
3606 | // We only want newly created inventory items. JC | 3639 | // We only want newly created inventory items. JC |
3607 | if ( strcmp(msg_name, "UpdateCreateInventoryItem") ) | 3640 | if ( msg_name != "UpdateCreateInventoryItem") |
3608 | { | 3641 | { |
3609 | return; | 3642 | return; |
3610 | } | 3643 | } |