From ab0f7ff14cd80b89524ba95eb5a39e2d6df55b26 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Thu, 15 Aug 2024 23:29:54 +0300 Subject: First batch of Inventory api; raise interrupts limit --- indra/newview/CMakeLists.txt | 2 + indra/newview/llinventorylistener.cpp | 130 ++++++++++++++++++++++ indra/newview/llinventorylistener.h | 45 ++++++++ indra/newview/llviewerinventory.cpp | 3 + indra/newview/scripts/lua/require/LLInventory.lua | 28 +++++ 5 files changed, 208 insertions(+) create mode 100644 indra/newview/llinventorylistener.cpp create mode 100644 indra/newview/llinventorylistener.h create mode 100644 indra/newview/scripts/lua/require/LLInventory.lua (limited to 'indra/newview') diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index 4e7e072289..04eb2c1d6d 100644 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -360,6 +360,7 @@ set(viewer_SOURCE_FILES llinventorygallerymenu.cpp llinventoryicon.cpp llinventoryitemslist.cpp + llinventorylistener.cpp llinventorylistitem.cpp llinventorymodel.cpp llinventorymodelbackgroundfetch.cpp @@ -1027,6 +1028,7 @@ set(viewer_HEADER_FILES llinventorygallerymenu.h llinventoryicon.h llinventoryitemslist.h + llinventorylistener.h llinventorylistitem.h llinventorymodel.h llinventorymodelbackgroundfetch.h diff --git a/indra/newview/llinventorylistener.cpp b/indra/newview/llinventorylistener.cpp new file mode 100644 index 0000000000..a8269bb80d --- /dev/null +++ b/indra/newview/llinventorylistener.cpp @@ -0,0 +1,130 @@ +/** + * @file llinventorylistener.cpp + * + * $LicenseInfo:firstyear=2024&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2024, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "llviewerprecompiledheaders.h" + +#include "llinventorylistener.h" + +#include "llappearancemgr.h" +#include "llinventoryfunctions.h" +#include "lltransutil.h" +#include "llwearableitemslist.h" +#include "stringize.h" + +LLInventoryListener::LLInventoryListener() + : LLEventAPI("LLInventory", + "API for interactions with viewer Inventory items") +{ + add("getItemsInfo", + "Return information about items or folders defined in [\"items_id\"]:\n" + "reply will contain [\"items\"] and [\"categories\"] tables accordingly", + &LLInventoryListener::getItemsInfo, + llsd::map("items_id", LLSD(), "reply", LLSD())); + + add("getFolderTypeNames", + "Return the table of folder type names, contained in [\"type_names\"]\n", + &LLInventoryListener::getFolderTypeNames, + llsd::map("reply", LLSD())); + + add("getBasicFolderID", + "Return the UUID of the folder by specified folder type name, for example:\n" + "\"Textures\", \"My outfits\", \"Sounds\" and other basic folders which have associated type", + &LLInventoryListener::getBasicFolderID, + llsd::map("ft_name", LLSD(), "reply", LLSD())); + + add("getDirectDescendents", + "Return the direct descendents(both items and folders) of the [\"folder_id\"]", + &LLInventoryListener::getDirectDescendents, + llsd::map("folder_id", LLSD(), "reply", LLSD())); + } + + +void add_item_info(LLEventAPI::Response& response, LLViewerInventoryItem* item) +{ + response["items"].insert(item->getUUID().asString(), + llsd::map("name", item->getName(), "parent_id", item->getParentUUID(), "desc", item->getDescription(), + "inv_type", LLInventoryType::lookup(item->getInventoryType()), "creation_date", + (S32) item->getCreationDate(), "asset_id", item->getAssetUUID(), "is_link", item->getIsLinkType(), + "linked_id", item->getLinkedUUID())); +} + +void add_cat_info(LLEventAPI::Response &response, LLViewerInventoryCategory *cat) +{ + response["categories"].insert(cat->getUUID().asString(), + llsd::map("name", cat->getName(), "parent_id", cat->getParentUUID(), "type", + LLFolderType::lookup(cat->getPreferredType()), "creation_date", (S32) cat->getCreationDate(), + "is_link", cat->getIsLinkType(), "linked_id", cat->getLinkedUUID())); +} + +void LLInventoryListener::getItemsInfo(LLSD const &data) +{ + Response response(LLSD(), data); + + uuid_vec_t ids = LLSDParam(data["items_id"]); + for (auto &it : ids) + { + LLViewerInventoryItem* item = gInventory.getItem(it); + if (item) + { + add_item_info(response, item); + } + LLViewerInventoryCategory* cat = gInventory.getCategory(it); + if (cat) + { + add_cat_info(response, cat); + } + } +} + +void LLInventoryListener::getFolderTypeNames(LLSD const &data) +{ + Response response(llsd::map("type_names", LLFolderType::getTypeNames()), data); +} + +void LLInventoryListener::getBasicFolderID(LLSD const &data) +{ + Response response(llsd::map("id", gInventory.findCategoryUUIDForType(LLFolderType::lookup(data["ft_name"].asString()))), data); +} + + +void LLInventoryListener::getDirectDescendents(LLSD const &data) +{ + Response response(LLSD(), data); + LLInventoryModel::cat_array_t* cats; + LLInventoryModel::item_array_t* items; + gInventory.getDirectDescendentsOf(data["folder_id"], cats, items); + + LLInventoryModel::item_array_t items_copy = *items; + for (LLInventoryModel::item_array_t::iterator iter = items_copy.begin(); iter != items_copy.end(); iter++) + { + add_item_info(response, *iter); + } + LLInventoryModel::cat_array_t cats_copy = *cats; + for (LLInventoryModel::cat_array_t::iterator iter = cats_copy.begin(); iter != cats_copy.end(); iter++) + { + add_cat_info(response, *iter); + } +} + diff --git a/indra/newview/llinventorylistener.h b/indra/newview/llinventorylistener.h new file mode 100644 index 0000000000..e148df48fe --- /dev/null +++ b/indra/newview/llinventorylistener.h @@ -0,0 +1,45 @@ +/** + * @file llinventorylistener.h + * + * $LicenseInfo:firstyear=2024&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2024, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + + +#ifndef LL_LLINVENTORYLISTENER_H +#define LL_LLINVENTORYLISTENER_H + +#include "lleventapi.h" + +class LLInventoryListener : public LLEventAPI +{ +public: + LLInventoryListener(); + +private: + void getItemsInfo(LLSD const &data); + void getFolderTypeNames(LLSD const &data); + void getBasicFolderID(LLSD const &data); + void getDirectDescendents(LLSD const &data); +}; + +#endif // LL_LLINVENTORYLISTENER_H + diff --git a/indra/newview/llviewerinventory.cpp b/indra/newview/llviewerinventory.cpp index 16810efa01..7030426e21 100644 --- a/indra/newview/llviewerinventory.cpp +++ b/indra/newview/llviewerinventory.cpp @@ -71,6 +71,9 @@ #include "llclipboard.h" #include "llhttpretrypolicy.h" #include "llsettingsvo.h" +#include "llinventorylistener.h" + +LLInventoryListener sInventoryListener; // do-nothing ops for use in callbacks. void no_op_inventory_func(const LLUUID&) {} diff --git a/indra/newview/scripts/lua/require/LLInventory.lua b/indra/newview/scripts/lua/require/LLInventory.lua new file mode 100644 index 0000000000..880a2516f1 --- /dev/null +++ b/indra/newview/scripts/lua/require/LLInventory.lua @@ -0,0 +1,28 @@ +local leap = require 'leap' +local mapargs = require 'mapargs' + +local LLInventory = {} + +-- Get the items/folders info by provided IDs, +-- reply will contain "items" and "categories" tables accordingly +function LLInventory.getItemsInfo(items_id) + return leap.request('LLInventory', {op = 'getItemsInfo', items_id=items_id}) +end + +-- Get the table of folder type names, which can be later used to get the ID of the basic folders +function LLInventory.getFolderTypeNames() + return leap.request('LLInventory', {op = 'getFolderTypeNames'}).type_names +end + +-- Get the UUID of the basic folder("Textures", "My outfits", "Sounds" etc.) by specified folder type name +function LLInventory.getBasicFolderID(ft_name) + return leap.request('LLInventory', {op = 'getBasicFolderID', ft_name=ft_name}).id +end + +-- Get the direct descendents of the 'folder_id' provided, +-- reply will contain "items" and "categories" tables accordingly +function LLInventory.getDirectDescendents(folder_id) + return leap.request('LLInventory', {op = 'getDirectDescendents', folder_id=folder_id}) +end + +return LLInventory -- cgit v1.2.3 From 3cef79d979f2d21c29d17d123d6c166b9f7e7e0e Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Tue, 20 Aug 2024 23:09:14 +0300 Subject: Add collectDescendentsIf api for Lua --- indra/newview/llinventorylistener.cpp | 140 +++++++++++++++++++++- indra/newview/llinventorylistener.h | 27 +++++ indra/newview/scripts/lua/require/LLInventory.lua | 19 +++ 3 files changed, 180 insertions(+), 6 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/llinventorylistener.cpp b/indra/newview/llinventorylistener.cpp index a8269bb80d..4beb59c58e 100644 --- a/indra/newview/llinventorylistener.cpp +++ b/indra/newview/llinventorylistener.cpp @@ -48,6 +48,11 @@ LLInventoryListener::LLInventoryListener() &LLInventoryListener::getFolderTypeNames, llsd::map("reply", LLSD())); + add("getAssetTypeNames", + "Return the table of asset type names, contained in [\"type_names\"]\n", + &LLInventoryListener::getAssetTypeNames, + llsd::map("reply", LLSD())); + add("getBasicFolderID", "Return the UUID of the folder by specified folder type name, for example:\n" "\"Textures\", \"My outfits\", \"Sounds\" and other basic folders which have associated type", @@ -58,6 +63,15 @@ LLInventoryListener::LLInventoryListener() "Return the direct descendents(both items and folders) of the [\"folder_id\"]", &LLInventoryListener::getDirectDescendents, llsd::map("folder_id", LLSD(), "reply", LLSD())); + + add("collectDescendentsIf", + "Return the descendents(both items and folders) of the [\"folder_id\"], if it passes specified filters:\n" + "[\"name\"] is a substring of object's name,\n" + "[\"desc\"] is a substring of object's description,\n" + "asset [\"type\"] corresponds to the object's asset type\n" + "[\"filter_links\"]: EXCLUDE_LINKS - don't show links, ONLY_LINKS - only show links, INCLUDE_LINKS - show links too (default)", + &LLInventoryListener::collectDescendentsIf, + llsd::map("folder_id", LLSD(), "reply", LLSD())); } @@ -65,17 +79,15 @@ void add_item_info(LLEventAPI::Response& response, LLViewerInventoryItem* item) { response["items"].insert(item->getUUID().asString(), llsd::map("name", item->getName(), "parent_id", item->getParentUUID(), "desc", item->getDescription(), - "inv_type", LLInventoryType::lookup(item->getInventoryType()), "creation_date", - (S32) item->getCreationDate(), "asset_id", item->getAssetUUID(), "is_link", item->getIsLinkType(), - "linked_id", item->getLinkedUUID())); + "inv_type", LLInventoryType::lookup(item->getInventoryType()), "asset_type", LLAssetType::lookup(item->getType()), + "creation_date", (S32) item->getCreationDate(), "asset_id", item->getAssetUUID(), + "is_link", item->getIsLinkType(), "linked_id", item->getLinkedUUID())); } void add_cat_info(LLEventAPI::Response &response, LLViewerInventoryCategory *cat) { response["categories"].insert(cat->getUUID().asString(), - llsd::map("name", cat->getName(), "parent_id", cat->getParentUUID(), "type", - LLFolderType::lookup(cat->getPreferredType()), "creation_date", (S32) cat->getCreationDate(), - "is_link", cat->getIsLinkType(), "linked_id", cat->getLinkedUUID())); + llsd::map("name", cat->getName(), "parent_id", cat->getParentUUID(), "type", LLFolderType::lookup(cat->getPreferredType()))); } void LLInventoryListener::getItemsInfo(LLSD const &data) @@ -103,6 +115,11 @@ void LLInventoryListener::getFolderTypeNames(LLSD const &data) Response response(llsd::map("type_names", LLFolderType::getTypeNames()), data); } +void LLInventoryListener::getAssetTypeNames(LLSD const &data) +{ + Response response(llsd::map("type_names", LLAssetType::getTypeNames()), data); +} + void LLInventoryListener::getBasicFolderID(LLSD const &data) { Response response(llsd::map("id", gInventory.findCategoryUUIDForType(LLFolderType::lookup(data["ft_name"].asString()))), data); @@ -128,3 +145,114 @@ void LLInventoryListener::getDirectDescendents(LLSD const &data) } } +void LLInventoryListener::collectDescendentsIf(LLSD const &data) +{ + Response response(LLSD(), data); + LLUUID folder_id(data["folder_id"].asUUID()); + LLViewerInventoryCategory *cat = gInventory.getCategory(folder_id); + if (!cat) + { + return response.error(stringize("Folder ", std::quoted(data["folder_id"].asString()), " was not found")); + } + LLInventoryModel::cat_array_t cat_array; + LLInventoryModel::item_array_t item_array; + + LLFilteredCollector collector = LLFilteredCollector(data); + + gInventory.collectDescendentsIf(folder_id, cat_array, item_array, LLInventoryModel::EXCLUDE_TRASH, collector); + + for (LLInventoryModel::item_array_t::iterator iter = item_array.begin(); iter != item_array.end(); iter++) + { + add_item_info(response, *iter); + } + for (LLInventoryModel::cat_array_t::iterator iter = cat_array.begin(); iter != cat_array.end(); iter++) + { + add_cat_info(response, *iter); + } +} + +LLFilteredCollector::LLFilteredCollector(LLSD const &data) + : mType(LLAssetType::EType::AT_UNKNOWN), + mLinkFilter(INCLUDE_LINKS) +{ + if (data.has("name")) + { + mName = data["name"]; + } + if (data.has("desc")) + { + mDesc = data["desc"]; + } + if (data.has("type")) + { + mType = LLAssetType::lookup(data["type"]); + } + if (data.has("filter_links")) + { + if (data["filter_links"] == "EXCLUDE_LINKS") + { + mLinkFilter = EXCLUDE_LINKS; + } + else if (data["filter_links"] == "ONLY_LINKS") + { + mLinkFilter = ONLY_LINKS; + } + } +} + +bool LLFilteredCollector::operator()(LLInventoryCategory *cat, LLInventoryItem *item) +{ + bool passed = checkagainstType(cat, item); + passed = passed && checkagainstNameDesc(cat, item); + passed = passed && checkagainstLinks(cat, item); + + return passed; +} + +bool LLFilteredCollector::checkagainstNameDesc(LLInventoryCategory *cat, LLInventoryItem *item) +{ + std::string name, desc; + bool passed(true); + if (cat) + { + if (!mDesc.empty()) return false; + name = cat->getName(); + } + if (item) + { + name = item->getName(); + passed = (mDesc.size() ? item->getDescription().find(mDesc) != std::string::npos : true); + } + + return passed && (mName.size() ? name.find(mName) != std::string::npos : true); +} + +bool LLFilteredCollector::checkagainstType(LLInventoryCategory *cat, LLInventoryItem *item) +{ + if (mType == LLAssetType::AT_UNKNOWN) + { + return true; + } + if (mType == LLAssetType::AT_CATEGORY) + { + if (cat) + { + return true; + } + } + if (item && item->getType() == mType) + { + return true; + } + return false; +} + +bool LLFilteredCollector::checkagainstLinks(LLInventoryCategory *cat, LLInventoryItem *item) +{ + bool is_link = cat ? cat->getIsLinkType() : item->getIsLinkType(); + if (is_link && (mLinkFilter == EXCLUDE_LINKS)) + return false; + if (!is_link && (mLinkFilter == ONLY_LINKS)) + return false; + return true; +} diff --git a/indra/newview/llinventorylistener.h b/indra/newview/llinventorylistener.h index e148df48fe..83e1751e1b 100644 --- a/indra/newview/llinventorylistener.h +++ b/indra/newview/llinventorylistener.h @@ -28,6 +28,7 @@ #define LL_LLINVENTORYLISTENER_H #include "lleventapi.h" +#include "llinventoryfunctions.h" class LLInventoryListener : public LLEventAPI { @@ -37,8 +38,34 @@ public: private: void getItemsInfo(LLSD const &data); void getFolderTypeNames(LLSD const &data); + void getAssetTypeNames(LLSD const &data); void getBasicFolderID(LLSD const &data); void getDirectDescendents(LLSD const &data); + void collectDescendentsIf(LLSD const &data); +}; + +struct LLFilteredCollector : public LLInventoryCollectFunctor +{ + enum EFilterLink + { + INCLUDE_LINKS, // show links too + EXCLUDE_LINKS, // don't show links + ONLY_LINKS // only show links + }; + + LLFilteredCollector(LLSD const &data); + virtual ~LLFilteredCollector() {} + virtual bool operator()(LLInventoryCategory *cat, LLInventoryItem *item); + + protected: + bool checkagainstType(LLInventoryCategory *cat, LLInventoryItem *item); + bool checkagainstNameDesc(LLInventoryCategory *cat, LLInventoryItem *item); + bool checkagainstLinks(LLInventoryCategory *cat, LLInventoryItem *item); + + LLAssetType::EType mType; + std::string mName; + std::string mDesc; + EFilterLink mLinkFilter; }; #endif // LL_LLINVENTORYLISTENER_H diff --git a/indra/newview/scripts/lua/require/LLInventory.lua b/indra/newview/scripts/lua/require/LLInventory.lua index 880a2516f1..e6a347532b 100644 --- a/indra/newview/scripts/lua/require/LLInventory.lua +++ b/indra/newview/scripts/lua/require/LLInventory.lua @@ -19,10 +19,29 @@ function LLInventory.getBasicFolderID(ft_name) return leap.request('LLInventory', {op = 'getBasicFolderID', ft_name=ft_name}).id end +-- Get the table of asset type names, which can be later used to get the specific items via LLInventory.collectDescendentsIf(...) +function LLInventory.getAssetTypeNames() + return leap.request('LLInventory', {op = 'getAssetTypeNames'}).type_names +end + -- Get the direct descendents of the 'folder_id' provided, -- reply will contain "items" and "categories" tables accordingly function LLInventory.getDirectDescendents(folder_id) return leap.request('LLInventory', {op = 'getDirectDescendents', folder_id=folder_id}) end +-- Get the descendents of the 'folder_id' provided, which pass specified filters +-- reply will contain "items" and "categories" tables accordingly +-- LLInventory.collectDescendentsIf{ folder_id -- parent folder ID +-- [, name] -- name (substring) +-- [, desc] -- description (substring) +-- [, type] -- asset type +-- [, filter_links]} -- EXCLUDE_LINKS - don't show links, ONLY_LINKS - only show links, INCLUDE_LINKS - show links too (default) +function LLInventory.collectDescendentsIf(...) + local args = mapargs('folder_id,name,desc,type,filter_links', ...) + args.op = 'collectDescendentsIf' + return leap.request('LLInventory', args) +end + + return LLInventory -- cgit v1.2.3 From 86eec90d97c03ac0f6be8897041185c6b5601968 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Wed, 21 Aug 2024 20:43:38 +0300 Subject: Add item limit for collectDescendentsIf func; add demo script --- indra/newview/llinventoryfunctions.h | 2 ++ indra/newview/llinventorylistener.cpp | 26 +++++++++++++++++++---- indra/newview/llinventorylistener.h | 4 ++++ indra/newview/llinventorymodel.cpp | 8 +++++++ indra/newview/scripts/lua/require/LLInventory.lua | 3 ++- indra/newview/scripts/lua/test_LLInventory.lua | 21 ++++++++++++++++++ 6 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 indra/newview/scripts/lua/test_LLInventory.lua (limited to 'indra/newview') diff --git a/indra/newview/llinventoryfunctions.h b/indra/newview/llinventoryfunctions.h index 78077d2007..f6d910820d 100644 --- a/indra/newview/llinventoryfunctions.h +++ b/indra/newview/llinventoryfunctions.h @@ -189,6 +189,8 @@ public: virtual ~LLInventoryCollectFunctor(){}; virtual bool operator()(LLInventoryCategory* cat, LLInventoryItem* item) = 0; + virtual bool exceedsLimit() { return false; } + static bool itemTransferCommonlyAllowed(const LLInventoryItem* item); }; diff --git a/indra/newview/llinventorylistener.cpp b/indra/newview/llinventorylistener.cpp index 4beb59c58e..4ff25f7f5c 100644 --- a/indra/newview/llinventorylistener.cpp +++ b/indra/newview/llinventorylistener.cpp @@ -33,6 +33,8 @@ #include "llwearableitemslist.h" #include "stringize.h" +static const F32 MAX_ITEM_LIMIT = 100; + LLInventoryListener::LLInventoryListener() : LLEventAPI("LLInventory", "API for interactions with viewer Inventory items") @@ -68,7 +70,8 @@ LLInventoryListener::LLInventoryListener() "Return the descendents(both items and folders) of the [\"folder_id\"], if it passes specified filters:\n" "[\"name\"] is a substring of object's name,\n" "[\"desc\"] is a substring of object's description,\n" - "asset [\"type\"] corresponds to the object's asset type\n" + "asset [\"type\"] corresponds to the object's asset type\n" + "[\"item_limit\"] sets item count limit in reply, maximum and default is 100\n" "[\"filter_links\"]: EXCLUDE_LINKS - don't show links, ONLY_LINKS - only show links, INCLUDE_LINKS - show links too (default)", &LLInventoryListener::collectDescendentsIf, llsd::map("folder_id", LLSD(), "reply", LLSD())); @@ -171,9 +174,11 @@ void LLInventoryListener::collectDescendentsIf(LLSD const &data) } } -LLFilteredCollector::LLFilteredCollector(LLSD const &data) - : mType(LLAssetType::EType::AT_UNKNOWN), - mLinkFilter(INCLUDE_LINKS) +LLFilteredCollector::LLFilteredCollector(LLSD const &data) : + mType(LLAssetType::EType::AT_UNKNOWN), + mLinkFilter(INCLUDE_LINKS), + mItemLimit(MAX_ITEM_LIMIT), + mItemCount(0) { if (data.has("name")) { @@ -198,6 +203,10 @@ LLFilteredCollector::LLFilteredCollector(LLSD const &data) mLinkFilter = ONLY_LINKS; } } + if (data.has("item_limit")) + { + mItemLimit = llclamp(data["item_limit"].asInteger(), 1, MAX_ITEM_LIMIT); + } } bool LLFilteredCollector::operator()(LLInventoryCategory *cat, LLInventoryItem *item) @@ -206,9 +215,18 @@ bool LLFilteredCollector::operator()(LLInventoryCategory *cat, LLInventoryItem * passed = passed && checkagainstNameDesc(cat, item); passed = passed && checkagainstLinks(cat, item); + if (passed) + { + ++mItemCount; + } return passed; } +bool LLFilteredCollector::exceedsLimit() +{ + return (mItemLimit <= mItemCount); +} + bool LLFilteredCollector::checkagainstNameDesc(LLInventoryCategory *cat, LLInventoryItem *item) { std::string name, desc; diff --git a/indra/newview/llinventorylistener.h b/indra/newview/llinventorylistener.h index 83e1751e1b..2c1eb2cb6d 100644 --- a/indra/newview/llinventorylistener.h +++ b/indra/newview/llinventorylistener.h @@ -56,6 +56,7 @@ struct LLFilteredCollector : public LLInventoryCollectFunctor LLFilteredCollector(LLSD const &data); virtual ~LLFilteredCollector() {} virtual bool operator()(LLInventoryCategory *cat, LLInventoryItem *item); + virtual bool exceedsLimit(); protected: bool checkagainstType(LLInventoryCategory *cat, LLInventoryItem *item); @@ -66,6 +67,9 @@ struct LLFilteredCollector : public LLInventoryCollectFunctor std::string mName; std::string mDesc; EFilterLink mLinkFilter; + + S32 mItemLimit; + S32 mItemCount; }; #endif // LL_LLINVENTORYLISTENER_H diff --git a/indra/newview/llinventorymodel.cpp b/indra/newview/llinventorymodel.cpp index 5325c28abf..c98c3482d0 100644 --- a/indra/newview/llinventorymodel.cpp +++ b/indra/newview/llinventorymodel.cpp @@ -1289,6 +1289,10 @@ void LLInventoryModel::collectDescendentsIf(const LLUUID& id, S32 count = cat_array->size(); for(S32 i = 0; i < count; ++i) { + if (add.exceedsLimit()) + { + break; + } LLViewerInventoryCategory* cat = cat_array->at(i); if(add(cat,NULL)) { @@ -1307,6 +1311,10 @@ void LLInventoryModel::collectDescendentsIf(const LLUUID& id, S32 count = item_array->size(); for(S32 i = 0; i < count; ++i) { + if (add.exceedsLimit()) + { + break; + } item = item_array->at(i); if(add(NULL, item)) { diff --git a/indra/newview/scripts/lua/require/LLInventory.lua b/indra/newview/scripts/lua/require/LLInventory.lua index e6a347532b..b3f817da94 100644 --- a/indra/newview/scripts/lua/require/LLInventory.lua +++ b/indra/newview/scripts/lua/require/LLInventory.lua @@ -36,9 +36,10 @@ end -- [, name] -- name (substring) -- [, desc] -- description (substring) -- [, type] -- asset type +-- [, item_limit] -- item count limit in reply, maximum and default is 100 -- [, filter_links]} -- EXCLUDE_LINKS - don't show links, ONLY_LINKS - only show links, INCLUDE_LINKS - show links too (default) function LLInventory.collectDescendentsIf(...) - local args = mapargs('folder_id,name,desc,type,filter_links', ...) + local args = mapargs('folder_id,name,desc,type,filter_links,item_limit', ...) args.op = 'collectDescendentsIf' return leap.request('LLInventory', args) end diff --git a/indra/newview/scripts/lua/test_LLInventory.lua b/indra/newview/scripts/lua/test_LLInventory.lua new file mode 100644 index 0000000000..dc6eb243ad --- /dev/null +++ b/indra/newview/scripts/lua/test_LLInventory.lua @@ -0,0 +1,21 @@ +inspect = require 'inspect' +LLInventory = require 'LLInventory' + +-- Get 'My Landmarks' folder id (you can see all folder types via LLInventory.getFolderTypeNames()) +my_landmarks_id = LLInventory.getBasicFolderID('landmark') +-- Get 3 landmarks from the 'My Landmarks' folder (you can see all folder types via LLInventory.getAssetTypeNames()) +landmarks = LLInventory.collectDescendentsIf{folder_id=my_landmarks_id, type="landmark", item_limit=3} +print(inspect(landmarks)) + +-- Get 'Calling Cards' folder id +calling_cards_id = LLInventory.getBasicFolderID('callcard') +-- Get all items located directly in 'Calling Cards' folder +calling_cards = LLInventory.getDirectDescendents(calling_cards_id).items + +-- Print a random calling card name from 'Calling Cards' folder +local card_names = {} +for _, value in pairs(calling_cards) do + table.insert(card_names, value.name) +end +math.randomseed(os.time()) +print("Random calling card: " .. inspect(card_names[math.random(#card_names)])) -- cgit v1.2.3 From 8887711019f3b37bc830a51609a4940fe10d7cec Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Wed, 21 Aug 2024 23:12:21 +0300 Subject: mac build fix --- indra/newview/llinventorylistener.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/llinventorylistener.cpp b/indra/newview/llinventorylistener.cpp index 4ff25f7f5c..0aa1208d83 100644 --- a/indra/newview/llinventorylistener.cpp +++ b/indra/newview/llinventorylistener.cpp @@ -182,11 +182,11 @@ LLFilteredCollector::LLFilteredCollector(LLSD const &data) : { if (data.has("name")) { - mName = data["name"]; + mName = data["name"].asString(); } if (data.has("desc")) { - mDesc = data["desc"]; + mDesc = data["desc"].asString(); } if (data.has("type")) { -- cgit v1.2.3 From 27ce2a23a286709c90579db31c2551e0c3f292e7 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Tue, 27 Aug 2024 16:27:34 +0300 Subject: code clean up --- indra/newview/llinventorylistener.cpp | 136 +++++++++++++--------- indra/newview/llinventorylistener.h | 28 ----- indra/newview/scripts/lua/require/LLInventory.lua | 12 +- indra/newview/scripts/lua/test_LLInventory.lua | 2 +- 4 files changed, 86 insertions(+), 92 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/llinventorylistener.cpp b/indra/newview/llinventorylistener.cpp index 0aa1208d83..157e04dce3 100644 --- a/indra/newview/llinventorylistener.cpp +++ b/indra/newview/llinventorylistener.cpp @@ -40,18 +40,18 @@ LLInventoryListener::LLInventoryListener() "API for interactions with viewer Inventory items") { add("getItemsInfo", - "Return information about items or folders defined in [\"items_id\"]:\n" + "Return information about items or folders defined in [\"item_ids\"]:\n" "reply will contain [\"items\"] and [\"categories\"] tables accordingly", &LLInventoryListener::getItemsInfo, - llsd::map("items_id", LLSD(), "reply", LLSD())); + llsd::map("item_ids", LLSD(), "reply", LLSD())); add("getFolderTypeNames", - "Return the table of folder type names, contained in [\"type_names\"]\n", + "Return the table of folder type names, contained in [\"names\"]\n", &LLInventoryListener::getFolderTypeNames, llsd::map("reply", LLSD())); add("getAssetTypeNames", - "Return the table of asset type names, contained in [\"type_names\"]\n", + "Return the table of asset type names, contained in [\"names\"]\n", &LLInventoryListener::getAssetTypeNames, llsd::map("reply", LLSD())); @@ -70,8 +70,8 @@ LLInventoryListener::LLInventoryListener() "Return the descendents(both items and folders) of the [\"folder_id\"], if it passes specified filters:\n" "[\"name\"] is a substring of object's name,\n" "[\"desc\"] is a substring of object's description,\n" - "asset [\"type\"] corresponds to the object's asset type\n" - "[\"item_limit\"] sets item count limit in reply, maximum and default is 100\n" + "asset [\"type\"] corresponds to the string name of the object's asset type\n" + "[\"limit\"] sets item count limit in reply, maximum and default is 100\n" "[\"filter_links\"]: EXCLUDE_LINKS - don't show links, ONLY_LINKS - only show links, INCLUDE_LINKS - show links too (default)", &LLInventoryListener::collectDescendentsIf, llsd::map("folder_id", LLSD(), "reply", LLSD())); @@ -81,23 +81,42 @@ LLInventoryListener::LLInventoryListener() void add_item_info(LLEventAPI::Response& response, LLViewerInventoryItem* item) { response["items"].insert(item->getUUID().asString(), - llsd::map("name", item->getName(), "parent_id", item->getParentUUID(), "desc", item->getDescription(), - "inv_type", LLInventoryType::lookup(item->getInventoryType()), "asset_type", LLAssetType::lookup(item->getType()), - "creation_date", (S32) item->getCreationDate(), "asset_id", item->getAssetUUID(), - "is_link", item->getIsLinkType(), "linked_id", item->getLinkedUUID())); + llsd::map("name", item->getName(), + "parent_id", item->getParentUUID(), + "desc", item->getDescription(), + "inv_type", LLInventoryType::lookup(item->getInventoryType()), + "asset_type", LLAssetType::lookup(item->getType()), + "creation_date", (S32) item->getCreationDate(), + "asset_id", item->getAssetUUID(), + "is_link", item->getIsLinkType(), + "linked_id", item->getLinkedUUID())); } void add_cat_info(LLEventAPI::Response &response, LLViewerInventoryCategory *cat) { response["categories"].insert(cat->getUUID().asString(), - llsd::map("name", cat->getName(), "parent_id", cat->getParentUUID(), "type", LLFolderType::lookup(cat->getPreferredType()))); + llsd::map("name", cat->getName(), + "parent_id", cat->getParentUUID(), + "type", LLFolderType::lookup(cat->getPreferredType()))); +} + +void add_objects_info(LLEventAPI::Response& response, LLInventoryModel::cat_array_t cat_array, LLInventoryModel::item_array_t item_array) +{ + for (auto &p : item_array) + { + add_item_info(response, p); + } + for (auto &p : cat_array) + { + add_cat_info(response, p); + } } void LLInventoryListener::getItemsInfo(LLSD const &data) { Response response(LLSD(), data); - uuid_vec_t ids = LLSDParam(data["items_id"]); + uuid_vec_t ids = LLSDParam(data["item_ids"]); for (auto &it : ids) { LLViewerInventoryItem* item = gInventory.getItem(it); @@ -105,22 +124,25 @@ void LLInventoryListener::getItemsInfo(LLSD const &data) { add_item_info(response, item); } - LLViewerInventoryCategory* cat = gInventory.getCategory(it); - if (cat) + else { - add_cat_info(response, cat); + LLViewerInventoryCategory *cat = gInventory.getCategory(it); + if (cat) + { + add_cat_info(response, cat); + } } } } void LLInventoryListener::getFolderTypeNames(LLSD const &data) { - Response response(llsd::map("type_names", LLFolderType::getTypeNames()), data); + Response response(llsd::map("names", LLFolderType::getTypeNames()), data); } void LLInventoryListener::getAssetTypeNames(LLSD const &data) { - Response response(llsd::map("type_names", LLAssetType::getTypeNames()), data); + Response response(llsd::map("names", LLAssetType::getTypeNames()), data); } void LLInventoryListener::getBasicFolderID(LLSD const &data) @@ -136,18 +158,37 @@ void LLInventoryListener::getDirectDescendents(LLSD const &data) LLInventoryModel::item_array_t* items; gInventory.getDirectDescendentsOf(data["folder_id"], cats, items); - LLInventoryModel::item_array_t items_copy = *items; - for (LLInventoryModel::item_array_t::iterator iter = items_copy.begin(); iter != items_copy.end(); iter++) - { - add_item_info(response, *iter); - } - LLInventoryModel::cat_array_t cats_copy = *cats; - for (LLInventoryModel::cat_array_t::iterator iter = cats_copy.begin(); iter != cats_copy.end(); iter++) - { - add_cat_info(response, *iter); - } + add_objects_info(response, *cats, *items); } +struct LLFilteredCollector : public LLInventoryCollectFunctor +{ + enum EFilterLink + { + INCLUDE_LINKS, // show links too + EXCLUDE_LINKS, // don't show links + ONLY_LINKS // only show links + }; + + LLFilteredCollector(LLSD const &data); + virtual ~LLFilteredCollector() {} + virtual bool operator()(LLInventoryCategory *cat, LLInventoryItem *item) override; + virtual bool exceedsLimit() override { return (mItemLimit <= mItemCount); }; + + protected: + bool checkagainstType(LLInventoryCategory *cat, LLInventoryItem *item); + bool checkagainstNameDesc(LLInventoryCategory *cat, LLInventoryItem *item); + bool checkagainstLinks(LLInventoryCategory *cat, LLInventoryItem *item); + + LLAssetType::EType mType; + std::string mName; + std::string mDesc; + EFilterLink mLinkFilter; + + S32 mItemLimit; + S32 mItemCount; +}; + void LLInventoryListener::collectDescendentsIf(LLSD const &data) { Response response(LLSD(), data); @@ -164,14 +205,7 @@ void LLInventoryListener::collectDescendentsIf(LLSD const &data) gInventory.collectDescendentsIf(folder_id, cat_array, item_array, LLInventoryModel::EXCLUDE_TRASH, collector); - for (LLInventoryModel::item_array_t::iterator iter = item_array.begin(); iter != item_array.end(); iter++) - { - add_item_info(response, *iter); - } - for (LLInventoryModel::cat_array_t::iterator iter = cat_array.begin(); iter != cat_array.end(); iter++) - { - add_cat_info(response, *iter); - } + add_objects_info(response, cat_array, item_array); } LLFilteredCollector::LLFilteredCollector(LLSD const &data) : @@ -180,14 +214,10 @@ LLFilteredCollector::LLFilteredCollector(LLSD const &data) : mItemLimit(MAX_ITEM_LIMIT), mItemCount(0) { - if (data.has("name")) - { - mName = data["name"].asString(); - } - if (data.has("desc")) - { - mDesc = data["desc"].asString(); - } + + mName = data["name"].asString(); + mDesc = data["desc"].asString(); + if (data.has("type")) { mType = LLAssetType::lookup(data["type"]); @@ -203,9 +233,9 @@ LLFilteredCollector::LLFilteredCollector(LLSD const &data) : mLinkFilter = ONLY_LINKS; } } - if (data.has("item_limit")) + if (data["limit"].isInteger()) { - mItemLimit = llclamp(data["item_limit"].asInteger(), 1, MAX_ITEM_LIMIT); + mItemLimit = llclamp(data["limit"].asInteger(), 1, MAX_ITEM_LIMIT); } } @@ -222,11 +252,6 @@ bool LLFilteredCollector::operator()(LLInventoryCategory *cat, LLInventoryItem * return passed; } -bool LLFilteredCollector::exceedsLimit() -{ - return (mItemLimit <= mItemCount); -} - bool LLFilteredCollector::checkagainstNameDesc(LLInventoryCategory *cat, LLInventoryItem *item) { std::string name, desc; @@ -239,10 +264,10 @@ bool LLFilteredCollector::checkagainstNameDesc(LLInventoryCategory *cat, LLInven if (item) { name = item->getName(); - passed = (mDesc.size() ? item->getDescription().find(mDesc) != std::string::npos : true); + passed = (mDesc.empty() || (item->getDescription().find(mDesc) != std::string::npos)); } - return passed && (mName.size() ? name.find(mName) != std::string::npos : true); + return passed && (mName.empty() || name.find(mName) != std::string::npos); } bool LLFilteredCollector::checkagainstType(LLInventoryCategory *cat, LLInventoryItem *item) @@ -251,12 +276,9 @@ bool LLFilteredCollector::checkagainstType(LLInventoryCategory *cat, LLInventory { return true; } - if (mType == LLAssetType::AT_CATEGORY) + if (cat && (mType == LLAssetType::AT_CATEGORY)) { - if (cat) - { - return true; - } + return true; } if (item && item->getType() == mType) { diff --git a/indra/newview/llinventorylistener.h b/indra/newview/llinventorylistener.h index 2c1eb2cb6d..5cbac2ca32 100644 --- a/indra/newview/llinventorylistener.h +++ b/indra/newview/llinventorylistener.h @@ -44,33 +44,5 @@ private: void collectDescendentsIf(LLSD const &data); }; -struct LLFilteredCollector : public LLInventoryCollectFunctor -{ - enum EFilterLink - { - INCLUDE_LINKS, // show links too - EXCLUDE_LINKS, // don't show links - ONLY_LINKS // only show links - }; - - LLFilteredCollector(LLSD const &data); - virtual ~LLFilteredCollector() {} - virtual bool operator()(LLInventoryCategory *cat, LLInventoryItem *item); - virtual bool exceedsLimit(); - - protected: - bool checkagainstType(LLInventoryCategory *cat, LLInventoryItem *item); - bool checkagainstNameDesc(LLInventoryCategory *cat, LLInventoryItem *item); - bool checkagainstLinks(LLInventoryCategory *cat, LLInventoryItem *item); - - LLAssetType::EType mType; - std::string mName; - std::string mDesc; - EFilterLink mLinkFilter; - - S32 mItemLimit; - S32 mItemCount; -}; - #endif // LL_LLINVENTORYLISTENER_H diff --git a/indra/newview/scripts/lua/require/LLInventory.lua b/indra/newview/scripts/lua/require/LLInventory.lua index b3f817da94..dd1b910250 100644 --- a/indra/newview/scripts/lua/require/LLInventory.lua +++ b/indra/newview/scripts/lua/require/LLInventory.lua @@ -5,13 +5,13 @@ local LLInventory = {} -- Get the items/folders info by provided IDs, -- reply will contain "items" and "categories" tables accordingly -function LLInventory.getItemsInfo(items_id) - return leap.request('LLInventory', {op = 'getItemsInfo', items_id=items_id}) +function LLInventory.getItemsInfo(item_ids) + return leap.request('LLInventory', {op = 'getItemsInfo', item_ids=item_ids}) end -- Get the table of folder type names, which can be later used to get the ID of the basic folders function LLInventory.getFolderTypeNames() - return leap.request('LLInventory', {op = 'getFolderTypeNames'}).type_names + return leap.request('LLInventory', {op = 'getFolderTypeNames'}).names end -- Get the UUID of the basic folder("Textures", "My outfits", "Sounds" etc.) by specified folder type name @@ -21,7 +21,7 @@ end -- Get the table of asset type names, which can be later used to get the specific items via LLInventory.collectDescendentsIf(...) function LLInventory.getAssetTypeNames() - return leap.request('LLInventory', {op = 'getAssetTypeNames'}).type_names + return leap.request('LLInventory', {op = 'getAssetTypeNames'}).names end -- Get the direct descendents of the 'folder_id' provided, @@ -36,10 +36,10 @@ end -- [, name] -- name (substring) -- [, desc] -- description (substring) -- [, type] -- asset type --- [, item_limit] -- item count limit in reply, maximum and default is 100 +-- [, limit] -- item count limit in reply, maximum and default is 100 -- [, filter_links]} -- EXCLUDE_LINKS - don't show links, ONLY_LINKS - only show links, INCLUDE_LINKS - show links too (default) function LLInventory.collectDescendentsIf(...) - local args = mapargs('folder_id,name,desc,type,filter_links,item_limit', ...) + local args = mapargs('folder_id,name,desc,type,filter_links,limit', ...) args.op = 'collectDescendentsIf' return leap.request('LLInventory', args) end diff --git a/indra/newview/scripts/lua/test_LLInventory.lua b/indra/newview/scripts/lua/test_LLInventory.lua index dc6eb243ad..107b0791d4 100644 --- a/indra/newview/scripts/lua/test_LLInventory.lua +++ b/indra/newview/scripts/lua/test_LLInventory.lua @@ -4,7 +4,7 @@ LLInventory = require 'LLInventory' -- Get 'My Landmarks' folder id (you can see all folder types via LLInventory.getFolderTypeNames()) my_landmarks_id = LLInventory.getBasicFolderID('landmark') -- Get 3 landmarks from the 'My Landmarks' folder (you can see all folder types via LLInventory.getAssetTypeNames()) -landmarks = LLInventory.collectDescendentsIf{folder_id=my_landmarks_id, type="landmark", item_limit=3} +landmarks = LLInventory.collectDescendentsIf{folder_id=my_landmarks_id, type="landmark", limit=3} print(inspect(landmarks)) -- Get 'Calling Cards' folder id -- cgit v1.2.3