From 2d39f05cc1403da307be05edc972d2ebcec6cfc7 Mon Sep 17 00:00:00 2001 From: Callum Prentice Date: Fri, 11 Aug 2023 18:07:13 -0700 Subject: SL-20109: Now that it seems that the tool might be useful, make a new version with a proper name and start worknig on it. Prototype bulky thumbs one will be removed after new version is working --- .../newview/llfloaterinventorythumbnailshelper.cpp | 390 +++++++++++++++++++++ 1 file changed, 390 insertions(+) create mode 100644 indra/newview/llfloaterinventorythumbnailshelper.cpp (limited to 'indra/newview/llfloaterinventorythumbnailshelper.cpp') diff --git a/indra/newview/llfloaterinventorythumbnailshelper.cpp b/indra/newview/llfloaterinventorythumbnailshelper.cpp new file mode 100644 index 0000000000..31ec144615 --- /dev/null +++ b/indra/newview/llfloaterinventorythumbnailshelper.cpp @@ -0,0 +1,390 @@ +/** + * @file llfloaterinventorythumbnailshelper.cpp + * @author Callum Prentice + * @brief LLFloaterInventoryThumbnailsHelper class implementation + * + * $LicenseInfo:firstyear=2008&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, 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$ + */ + +/** + * Floater that appears when buying an object, giving a preview + * of its contents and their permissions. + */ + +#include "llviewerprecompiledheaders.h" + +#include "llfloaterinventorythumbnailshelper.h" +#include "lluictrlfactory.h" +#include "llclipboard.h" +#include "llinventorymodel.h" +#include "llinventoryfunctions.h" +#include "lltexteditor.h" +#include "llmediactrl.h" +#include "lluuid.h" +#include "llaisapi.h" + +LLFloaterInventoryThumbnailsHelper::LLFloaterInventoryThumbnailsHelper(const LLSD& key) + : LLFloater("floater_inventory_thumbnails_helper") +{ +} + +LLFloaterInventoryThumbnailsHelper::~LLFloaterInventoryThumbnailsHelper() +{ +} + +BOOL LLFloaterInventoryThumbnailsHelper::postBuild() +{ + mPasteItemsBtn = getChild("paste_items_btn"); + mPasteItemsBtn->setCommitCallback(boost::bind(&LLFloaterInventoryThumbnailsHelper::onPasteItems, this)); + + mPasteTexturesBtn = getChild("paste_textures_btn"); + mPasteTexturesBtn->setCommitCallback(boost::bind(&LLFloaterInventoryThumbnailsHelper::onPasteTextures, this)); + + mOutputLog = getChild("output_log"); + mOutputLog->setMaxTextLength(0xffff * 0x10); + + mMergeItemsTexturesBtn = getChild("merge_items_textures"); + mMergeItemsTexturesBtn->setCommitCallback(boost::bind(&LLFloaterInventoryThumbnailsHelper::onMergeItemsTextures, this)); + mMergeItemsTexturesBtn->setEnabled(false); + + mWriteThumbnailsBtn = getChild("write_items_thumbnails"); + mWriteThumbnailsBtn->setCommitCallback(boost::bind(&LLFloaterInventoryThumbnailsHelper::onWriteThumbnails, this)); + mWriteThumbnailsBtn->setEnabled(false); + + return true; +} + +void LLFloaterInventoryThumbnailsHelper::recordInventoryItemEntry(LLViewerInventoryItem* item) +{ + const std::string name = item->getName(); + + std::map::iterator iter = mItemNamesIDs.find(name); + if (iter == mItemNamesIDs.end()) + { + LLUUID id = item->getUUID(); + mItemNamesIDs.insert({name, id}); + + mOutputLog->appendText( + STRINGIZE( + "ITEM " << mItemNamesIDs.size() << "> " << + name << + //" | " << + //id.asString() << + std::endl + ), false); + } + else + { + // dupe - do not save + } +} + +void LLFloaterInventoryThumbnailsHelper::onPasteItems() +{ + if (!LLClipboard::instance().hasContents()) + { + return; + } + + mOutputLog->appendText( + STRINGIZE( + "\n==== Pasting items from inventory ====" << + std::endl + ), false); + + std::vector objects; + LLClipboard::instance().pasteFromClipboard(objects); + size_t count = objects.size(); + + for (size_t i = 0; i < count; i++) + { + const LLUUID& entry = objects.at(i); + + const LLInventoryCategory* cat = gInventory.getCategory(entry); + if (cat) + { + LLInventoryModel::cat_array_t cat_array; + LLInventoryModel::item_array_t item_array; + + LLIsType is_object(LLAssetType::AT_OBJECT); + gInventory.collectDescendentsIf(cat->getUUID(), + cat_array, + item_array, + LLInventoryModel::EXCLUDE_TRASH, + is_object); + + LLIsType is_bodypart(LLAssetType::AT_BODYPART); + gInventory.collectDescendentsIf(cat->getUUID(), + cat_array, + item_array, + LLInventoryModel::EXCLUDE_TRASH, + is_bodypart); + + for (size_t i = 0; i < item_array.size(); i++) + { + LLViewerInventoryItem* item = item_array.at(i); + recordInventoryItemEntry(item); + } + } + + LLViewerInventoryItem* item = gInventory.getItem(entry); + if (item) + { + const LLAssetType::EType item_type = item->getType(); + if (item_type == LLAssetType::AT_OBJECT || item_type == LLAssetType::AT_BODYPART) + { + recordInventoryItemEntry(item); + } + } + } + + mOutputLog->setCursorAndScrollToEnd(); + + mMergeItemsTexturesBtn->setEnabled(true); +} + +void LLFloaterInventoryThumbnailsHelper::recordTextureItemEntry(LLViewerInventoryItem* item) +{ + const std::string name = item->getName(); + + std::map::iterator iter = mTextureNamesIDs.find(name); + if (iter == mTextureNamesIDs.end()) + { + LLUUID id = item->getAssetUUID(); + mTextureNamesIDs.insert({name, id}); + + mOutputLog->appendText( + STRINGIZE( + "TEXTURE " << mTextureNamesIDs.size() << "> " << + name << + //" | " << + //id.asString() << + std::endl + ), false); + } + else + { + // dupe - do not save + } +} + +void LLFloaterInventoryThumbnailsHelper::onPasteTextures() +{ + if (!LLClipboard::instance().hasContents()) + { + return; + } + + mOutputLog->appendText( + STRINGIZE( + "\n==== Pasting textures from inventory ====" << + std::endl + ), false); + + std::vector objects; + LLClipboard::instance().pasteFromClipboard(objects); + size_t count = objects.size(); + + for (size_t i = 0; i < count; i++) + { + const LLUUID& entry = objects.at(i); + + const LLInventoryCategory* cat = gInventory.getCategory(entry); + if (cat) + { + LLInventoryModel::cat_array_t cat_array; + LLInventoryModel::item_array_t item_array; + + LLIsType is_object(LLAssetType::AT_TEXTURE); + gInventory.collectDescendentsIf(cat->getUUID(), + cat_array, + item_array, + LLInventoryModel::EXCLUDE_TRASH, + is_object); + + for (size_t i = 0; i < item_array.size(); i++) + { + LLViewerInventoryItem* item = item_array.at(i); + recordTextureItemEntry(item); + } + } + + LLViewerInventoryItem* item = gInventory.getItem(entry); + if (item) + { + const LLAssetType::EType item_type = item->getType(); + if (item_type == LLAssetType::AT_TEXTURE) + { + recordTextureItemEntry(item); + } + } + } + + mOutputLog->setCursorAndScrollToEnd(); + + mMergeItemsTexturesBtn->setEnabled(true); +} + +void LLFloaterInventoryThumbnailsHelper::onMergeItemsTextures() +{ + mOutputLog->appendText( + STRINGIZE( + "\n==== Matching items and textures for " << + mItemNamesIDs.size() << + " entries ====" << + std::endl + ), false); + + std::map::iterator item_iter = mItemNamesIDs.begin(); + size_t index = 1; + + while (item_iter != mItemNamesIDs.end()) + { + std::string item_name = (*item_iter).first; + + mOutputLog->appendText( + STRINGIZE( + "MATCHING ITEM (" << index++ << "/" << mItemNamesIDs.size() << ") " << item_name << "> " + ), false); + + std::map::iterator texture_iter = mTextureNamesIDs.find(item_name); + if (texture_iter != mTextureNamesIDs.end()) + { + mOutputLog->appendText( + STRINGIZE( + "MATCHED" << + std::endl + ), false); + + mNameItemIDTextureId.insert({item_name, {(*item_iter).second, (*texture_iter).second}}); + } + else + { + mOutputLog->appendText( + STRINGIZE( + "NO MATCH FOUND" << + std::endl + ), false); + } + + ++item_iter; + } + + mOutputLog->appendText( + STRINGIZE( + "==== Matched list of items and textures has " << + mNameItemIDTextureId.size() << + " entries ====" << + std::endl + ), true); + + //std::map>::iterator iter = mNameItemIDTextureId.begin(); + //while (iter != mNameItemIDTextureId.end()) + //{ + // std::string output_line = (*iter).first; + // output_line += "\n"; + // output_line += "item ID: "; + // output_line += ((*iter).second).first.asString(); + // output_line += "\n"; + // output_line += "thumbnail texture ID: "; + // output_line += ((*iter).second).second.asString(); + // output_line += "\n"; + // mOutputLog->appendText(output_line, true); + + // ++iter; + //} + mOutputLog->setCursorAndScrollToEnd(); + + mWriteThumbnailsBtn->setEnabled(true); +} + +#if 1 +// *TODO$: LLInventoryCallback should be deprecated to conform to the new boost::bind/coroutine model. +// temp code in transition +void bulkyInventoryCb(LLPointer cb, LLUUID id) +{ + if (cb.notNull()) + { + cb->fire(id); + } +} +#endif + +bool writeThumbnailID(LLUUID item_id, LLUUID thumbnail_asset_id) +{ + if (AISAPI::isAvailable()) + { + + LLSD updates; + updates["thumbnail"] = LLSD().with("asset_id", thumbnail_asset_id.asString()); + + LLPointer cb; + + AISAPI::completion_t cr = boost::bind(&bulkyInventoryCb, cb, _1); + AISAPI::UpdateItem(item_id, updates, cr); + + return true; + } + else + { + LL_WARNS() << "Unable to write inventory thumbnail because the AIS API is not available" << LL_ENDL; + return false; + } +} + +void LLFloaterInventoryThumbnailsHelper::onWriteThumbnails() +{ + mOutputLog->appendText( + STRINGIZE( + "\n==== Writing thumbnails for " << + mNameItemIDTextureId.size() << + " entries ====" << + std::endl + ), false); + + std::map>::iterator iter = mNameItemIDTextureId.begin(); + size_t index = 1; + + while (iter != mNameItemIDTextureId.end()) + { + mOutputLog->appendText( + STRINGIZE( + "WRITING THUMB (" << index++ << "/" << mNameItemIDTextureId.size() << ")> " << + (*iter).first << + "\n" << + "item ID: " << + ((*iter).second).first.asString() << + "\n" << + "thumbnail texture ID: " << + ((*iter).second).second.asString() << + "\n" + ), true); + + LLUUID item_id = ((*iter).second).first; + LLUUID thumbnail_asset_id = ((*iter).second).second; + + writeThumbnailID(item_id, thumbnail_asset_id); + + ++iter; + } + mOutputLog->setCursorAndScrollToEnd(); +} -- cgit v1.3 From abb8d0402c8498dc5ce8dfec1438f2fedbaecce9 Mon Sep 17 00:00:00 2001 From: Callum Prentice Date: Fri, 11 Aug 2023 18:31:21 -0700 Subject: SL-20109: Some small UI tweaks before moving onto the meat of the functionality --- .../newview/llfloaterinventorythumbnailshelper.cpp | 22 +++++++++------------- indra/newview/llfloaterinventorythumbnailshelper.h | 3 +-- .../xui/en/floater_inventory_thumbnails_helper.xml | 7 +++++-- 3 files changed, 15 insertions(+), 17 deletions(-) (limited to 'indra/newview/llfloaterinventorythumbnailshelper.cpp') diff --git a/indra/newview/llfloaterinventorythumbnailshelper.cpp b/indra/newview/llfloaterinventorythumbnailshelper.cpp index 31ec144615..abd5e01e5d 100644 --- a/indra/newview/llfloaterinventorythumbnailshelper.cpp +++ b/indra/newview/llfloaterinventorythumbnailshelper.cpp @@ -62,11 +62,11 @@ BOOL LLFloaterInventoryThumbnailsHelper::postBuild() mOutputLog = getChild("output_log"); mOutputLog->setMaxTextLength(0xffff * 0x10); - mMergeItemsTexturesBtn = getChild("merge_items_textures"); - mMergeItemsTexturesBtn->setCommitCallback(boost::bind(&LLFloaterInventoryThumbnailsHelper::onMergeItemsTextures, this)); - mMergeItemsTexturesBtn->setEnabled(false); + //mMergeItemsTexturesBtn = getChild("merge_items_textures"); + //mMergeItemsTexturesBtn->setCommitCallback(boost::bind(&LLFloaterInventoryThumbnailsHelper::onMergeItemsTextures, this)); + //mMergeItemsTexturesBtn->setEnabled(false); - mWriteThumbnailsBtn = getChild("write_items_thumbnails"); + mWriteThumbnailsBtn = getChild("write_thumbnails_btn"); mWriteThumbnailsBtn->setCommitCallback(boost::bind(&LLFloaterInventoryThumbnailsHelper::onWriteThumbnails, this)); mWriteThumbnailsBtn->setEnabled(false); @@ -158,8 +158,6 @@ void LLFloaterInventoryThumbnailsHelper::onPasteItems() } mOutputLog->setCursorAndScrollToEnd(); - - mMergeItemsTexturesBtn->setEnabled(true); } void LLFloaterInventoryThumbnailsHelper::recordTextureItemEntry(LLViewerInventoryItem* item) @@ -240,11 +238,9 @@ void LLFloaterInventoryThumbnailsHelper::onPasteTextures() } mOutputLog->setCursorAndScrollToEnd(); - - mMergeItemsTexturesBtn->setEnabled(true); } -void LLFloaterInventoryThumbnailsHelper::onMergeItemsTextures() +void LLFloaterInventoryThumbnailsHelper::mergeItemsTextures() { mOutputLog->appendText( STRINGIZE( @@ -320,7 +316,7 @@ void LLFloaterInventoryThumbnailsHelper::onMergeItemsTextures() #if 1 // *TODO$: LLInventoryCallback should be deprecated to conform to the new boost::bind/coroutine model. // temp code in transition -void bulkyInventoryCb(LLPointer cb, LLUUID id) +void inventoryThumbnailsHelperCb(LLPointer cb, LLUUID id) { if (cb.notNull()) { @@ -329,7 +325,7 @@ void bulkyInventoryCb(LLPointer cb, LLUUID id) } #endif -bool writeThumbnailID(LLUUID item_id, LLUUID thumbnail_asset_id) +bool writeInventoryThumbnailID(LLUUID item_id, LLUUID thumbnail_asset_id) { if (AISAPI::isAvailable()) { @@ -339,7 +335,7 @@ bool writeThumbnailID(LLUUID item_id, LLUUID thumbnail_asset_id) LLPointer cb; - AISAPI::completion_t cr = boost::bind(&bulkyInventoryCb, cb, _1); + AISAPI::completion_t cr = boost::bind(&inventoryThumbnailsHelperCb, cb, _1); AISAPI::UpdateItem(item_id, updates, cr); return true; @@ -382,7 +378,7 @@ void LLFloaterInventoryThumbnailsHelper::onWriteThumbnails() LLUUID item_id = ((*iter).second).first; LLUUID thumbnail_asset_id = ((*iter).second).second; - writeThumbnailID(item_id, thumbnail_asset_id); + writeInventoryThumbnailID(item_id, thumbnail_asset_id); ++iter; } diff --git a/indra/newview/llfloaterinventorythumbnailshelper.h b/indra/newview/llfloaterinventorythumbnailshelper.h index 69ce3e1fec..3942214fe1 100644 --- a/indra/newview/llfloaterinventorythumbnailshelper.h +++ b/indra/newview/llfloaterinventorythumbnailshelper.h @@ -51,8 +51,7 @@ class LLFloaterInventoryThumbnailsHelper: LLTextEditor* mOutputLog; - LLUICtrl* mMergeItemsTexturesBtn; - void onMergeItemsTextures(); + void mergeItemsTextures(); LLUICtrl* mWriteThumbnailsBtn; void onWriteThumbnails(); diff --git a/indra/newview/skins/default/xui/en/floater_inventory_thumbnails_helper.xml b/indra/newview/skins/default/xui/en/floater_inventory_thumbnails_helper.xml index 79e0ef2b9f..62d0417f9e 100644 --- a/indra/newview/skins/default/xui/en/floater_inventory_thumbnails_helper.xml +++ b/indra/newview/skins/default/xui/en/floater_inventory_thumbnails_helper.xml @@ -38,7 +38,10 @@ left="8" right="-8" name="output_log" - width="480"> + font="Monospace" + text_color="0.1 0.5 0.1 1.0" + width="480"> +