summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indra/newview/llinventoryfunctions.h2
-rw-r--r--indra/newview/llinventorylistener.cpp26
-rw-r--r--indra/newview/llinventorylistener.h4
-rw-r--r--indra/newview/llinventorymodel.cpp8
-rw-r--r--indra/newview/scripts/lua/require/LLInventory.lua3
-rw-r--r--indra/newview/scripts/lua/test_LLInventory.lua21
6 files changed, 59 insertions, 5 deletions
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)]))