summaryrefslogtreecommitdiff
path: root/indra/newview/llinventorylistener.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llinventorylistener.cpp')
-rw-r--r--indra/newview/llinventorylistener.cpp140
1 files changed, 134 insertions, 6 deletions
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;
+}