summaryrefslogtreecommitdiff
path: root/indra/newview/llinventoryfunctions.cpp
diff options
context:
space:
mode:
authorAndrey Kleshchev <117672381+akleshchev@users.noreply.github.com>2024-06-27 18:57:02 +0300
committerGitHub <noreply@github.com>2024-06-27 18:57:02 +0300
commitac0f56668b42bbd01396633bbfd6dbda7ea434a5 (patch)
treedbb724773d49b1397e192e38770543fff4cf85f2 /indra/newview/llinventoryfunctions.cpp
parentfcffbad09007185becf53f2a259701c7e07444f5 (diff)
parent6ee6d19f600bb7fee99f96e8476e2c57088dad17 (diff)
Merge pull request #1840 from secondlife/inventory_favorites
viewer#1300 viewer#1301 viewer#1424 viewer#1425 viewer#1619 viewer#1005
Diffstat (limited to 'indra/newview/llinventoryfunctions.cpp')
-rw-r--r--indra/newview/llinventoryfunctions.cpp145
1 files changed, 145 insertions, 0 deletions
diff --git a/indra/newview/llinventoryfunctions.cpp b/indra/newview/llinventoryfunctions.cpp
index 909dea050e..ca27ea8b3f 100644
--- a/indra/newview/llinventoryfunctions.cpp
+++ b/indra/newview/llinventoryfunctions.cpp
@@ -2423,6 +2423,123 @@ void ungroup_folder_items(const LLUUID& folder_id)
gInventory.notifyObservers();
}
+class LLUpdateFavorite : public LLInventoryCallback
+{
+public:
+ LLUpdateFavorite(const LLUUID& inv_item_id)
+ : mInvItemID(inv_item_id)
+ {}
+ /* virtual */ void fire(const LLUUID& inv_item_id) override
+ {
+ gInventory.addChangedMask(LLInventoryObserver::UPDATE_FAVORITE, mInvItemID);
+
+ LLInventoryModel::item_array_t items;
+ LLInventoryModel::cat_array_t cat_array;
+ LLLinkedItemIDMatches matches(mInvItemID);
+ gInventory.collectDescendentsIf(gInventory.getRootFolderID(),
+ cat_array,
+ items,
+ LLInventoryModel::INCLUDE_TRASH,
+ matches);
+
+ std::set<LLUUID> link_ids;
+ for (LLInventoryModel::item_array_t::iterator it = items.begin(); it != items.end(); ++it)
+ {
+ LLPointer<LLViewerInventoryItem> item = *it;
+
+ gInventory.addChangedMask(LLInventoryObserver::UPDATE_FAVORITE, item->getUUID());
+ }
+
+ gInventory.notifyObservers();
+ }
+private:
+ LLUUID mInvItemID;
+};
+
+void favorite_send(LLInventoryObject* obj, const LLUUID& obj_id, bool favorite)
+{
+ LLSD val;
+ if (favorite)
+ {
+ val = true;
+ } // else leave undefined to remove unneeded metadata field
+
+ LLSD updates;
+ if (favorite)
+ {
+ updates["favorite"] = LLSD().with("toggled", true);
+ }
+ else
+ {
+ updates["favorite"] = LLSD();
+ }
+
+ LLPointer<LLInventoryCallback> cb = new LLUpdateFavorite(obj_id);
+
+ LLViewerInventoryCategory* view_folder = dynamic_cast<LLViewerInventoryCategory*>(obj);
+ if (view_folder)
+ {
+ update_inventory_category(obj_id, updates, cb);
+ }
+ LLViewerInventoryItem* view_item = dynamic_cast<LLViewerInventoryItem*>(obj);
+ if (view_item)
+ {
+ update_inventory_item(obj_id, updates, cb);
+ }
+}
+
+bool get_is_favorite(const LLInventoryObject* object)
+{
+ if (object->getIsLinkType())
+ {
+ LLInventoryObject* obj = gInventory.getObject(object->getLinkedUUID());
+ return obj && obj->getIsFavorite();
+ }
+
+ return object->getIsFavorite();
+}
+
+bool get_is_favorite(const LLUUID& obj_id)
+{
+ LLInventoryObject* object = gInventory.getObject(obj_id);
+ if (object && object->getIsLinkType())
+ {
+ LLInventoryObject* obj = gInventory.getObject(object->getLinkedUUID());
+ return obj && obj->getIsFavorite();
+ }
+
+ return object->getIsFavorite();
+}
+
+void set_favorite(const LLUUID& obj_id, bool favorite)
+{
+ LLInventoryObject* obj = gInventory.getObject(obj_id);
+
+ if (obj && obj->getIsLinkType())
+ {
+ obj = gInventory.getObject(obj->getLinkedUUID());
+ }
+
+ if (obj && obj->getIsFavorite() != favorite)
+ {
+ favorite_send(obj, obj->getUUID(), favorite);
+ }
+}
+
+void toggle_favorite(const LLUUID& obj_id)
+{
+ LLInventoryObject* obj = gInventory.getObject(obj_id);
+ if (obj && obj->getIsLinkType())
+ {
+ obj = gInventory.getObject(obj->getLinkedUUID());
+ }
+
+ if (obj)
+ {
+ favorite_send(obj, obj->getUUID(), !obj->getIsFavorite());
+ }
+}
+
std::string get_searchable_description(LLInventoryModel* model, const LLUUID& item_id)
{
if (model)
@@ -2704,6 +2821,20 @@ bool LLIsTypeWithPermissions::operator()(LLInventoryCategory* cat, LLInventoryIt
return FALSE;
}
+bool LLFavoritesCollector::operator()(LLInventoryCategory* cat,
+ LLInventoryItem* item)
+{
+ if (item && item->getIsFavorite())
+ {
+ return true;
+ }
+ if (cat && cat->getIsFavorite())
+ {
+ return true;
+ }
+ return false;
+}
+
bool LLBuddyCollector::operator()(LLInventoryCategory* cat,
LLInventoryItem* item)
{
@@ -3458,6 +3589,20 @@ void LLInventoryAction::doToSelected(LLInventoryModel* model, LLFolderView* root
ungroup_folder_items(*ids.begin());
}
}
+ else if ("add_to_favorites" == action)
+ {
+ for (const LLUUID& id : ids)
+ {
+ set_favorite(id, true);
+ }
+ }
+ else if ("remove_from_favorites" == action)
+ {
+ for (const LLUUID& id : ids)
+ {
+ set_favorite(id, false);
+ }
+ }
else
{
std::set<LLFolderViewItem*>::iterator set_iter;