summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Nikolenko <maximnproductengine@lindenlab.com>2023-04-04 20:18:08 +0300
committerMaxim Nikolenko <maximnproductengine@lindenlab.com>2023-04-04 20:18:08 +0300
commitf5809ad862c0a9b1004a2c9a779df99ff4555a1f (patch)
treed873fc3253d10f4574b9aff1c9e2488366259cad
parent58092382269eb8dc48fb30734ee3738f7385f8da (diff)
SL-19379 Observe thumbnail changes and update it in Gallery
-rw-r--r--indra/newview/llinventorygallery.cpp76
-rw-r--r--indra/newview/llinventorygallery.h37
2 files changed, 102 insertions, 11 deletions
diff --git a/indra/newview/llinventorygallery.cpp b/indra/newview/llinventorygallery.cpp
index c4da11a570..8c2f4c2214 100644
--- a/indra/newview/llinventorygallery.cpp
+++ b/indra/newview/llinventorygallery.cpp
@@ -89,6 +89,8 @@ LLInventoryGallery::LLInventoryGallery(const LLInventoryGallery::Params& p)
updateGalleryWidth();
mFilter = new LLInventoryFilter();
mCategoriesObserver = new LLInventoryCategoriesObserver();
+ mThumbnailsObserver = new LLThumbnailsObserver();
+ gInventory.addObserver(mThumbnailsObserver);
mUsername = gAgentUsername;
LLStringUtil::toUpper(mUsername);
@@ -146,6 +148,12 @@ LLInventoryGallery::~LLInventoryGallery()
gInventory.removeObserver(mCategoriesObserver);
}
delete mCategoriesObserver;
+
+ if (gInventory.containsObserver(mThumbnailsObserver))
+ {
+ gInventory.removeObserver(mThumbnailsObserver);
+ }
+ delete mThumbnailsObserver;
}
void LLInventoryGallery::setRootFolder(const LLUUID cat_id)
@@ -702,13 +710,8 @@ void LLInventoryGallery::updateAddedItem(LLUUID item_id)
addToGallery(item);
}
- if (mCategoriesObserver == NULL)
- {
- mCategoriesObserver = new LLInventoryCategoriesObserver();
- gInventory.addObserver(mCategoriesObserver);
- }
- mCategoriesObserver->addCategory(item_id,
- boost::bind(&LLInventoryGallery::updateItemThumbnail, this, item_id), true);
+ mThumbnailsObserver->addItem(item_id,
+ boost::bind(&LLInventoryGallery::updateItemThumbnail, this, item_id));
}
void LLInventoryGallery::updateRemovedItem(LLUUID item_id)
@@ -716,7 +719,7 @@ void LLInventoryGallery::updateRemovedItem(LLUUID item_id)
gallery_item_map_t::iterator item_iter = mItemMap.find(item_id);
if (item_iter != mItemMap.end())
{
- mCategoriesObserver->removeCategory(item_id);
+ mThumbnailsObserver->removeItem(item_id);
LLInventoryGalleryItem* item = item_iter->second;
@@ -978,7 +981,7 @@ LLUUID LLInventoryGallery::getOutfitImageID(LLUUID outfit_id)
return thumbnail_id;
}
-boost::signals2::connection LLInventoryGallery::setRootChangedCallback(root_changed_callback_t cb)
+boost::signals2::connection LLInventoryGallery::setRootChangedCallback(callback_t cb)
{
return mRootChangedSignal.connect(cb);
}
@@ -1341,6 +1344,61 @@ LLFontGL* LLInventoryGalleryItem::getTextFont()
}
//-----------------------------
+// LLThumbnailsObserver
+//-----------------------------
+
+void LLThumbnailsObserver::changed(U32 mask)
+{
+ if (!mItemMap.size())
+ return;
+ std::vector<LLUUID> deleted_ids;
+
+ for (item_map_t::iterator iter = mItemMap.begin();
+ iter != mItemMap.end();
+ ++iter)
+ {
+ const LLUUID& obj_id = (*iter).first;
+ LLItemData& data = (*iter).second;
+
+ LLInventoryObject* obj = gInventory.getObject(obj_id);
+ if (!obj)
+ {
+ deleted_ids.push_back(obj_id);
+ continue;
+ }
+
+ const LLUUID thumbnail_id = obj->getThumbnailUUID();
+ if (data.mThumbnailID != thumbnail_id)
+ {
+ data.mThumbnailID = thumbnail_id;
+ data.mCallback();
+ }
+ }
+
+ // Remove deleted items from the list
+ for (std::vector<LLUUID>::iterator deleted_id = deleted_ids.begin(); deleted_id != deleted_ids.end(); ++deleted_id)
+ {
+ removeItem(*deleted_id);
+ }
+}
+
+bool LLThumbnailsObserver::addItem(const LLUUID& obj_id, callback_t cb)
+{
+ LLInventoryObject* obj = gInventory.getObject(obj_id);
+ if (obj)
+ {
+ mItemMap.insert(item_map_value_t(obj_id, LLItemData(obj_id, obj->getThumbnailUUID(), cb)));
+ return true;
+ }
+ return false;
+}
+
+void LLThumbnailsObserver::removeItem(const LLUUID& obj_id)
+{
+ mItemMap.erase(obj_id);
+}
+
+//-----------------------------
// Helper drag&drop functions
//-----------------------------
diff --git a/indra/newview/llinventorygallery.h b/indra/newview/llinventorygallery.h
index 7284c92c96..98ed91df19 100644
--- a/indra/newview/llinventorygallery.h
+++ b/indra/newview/llinventorygallery.h
@@ -30,15 +30,19 @@
#include "lllistcontextmenu.h"
#include "llpanel.h"
#include "llinventoryfilter.h"
+#include "llinventoryobserver.h"
#include "llinventorymodel.h"
class LLInventoryCategoriesObserver;
class LLInventoryGalleryItem;
class LLScrollContainer;
class LLTextBox;
+class LLThumbnailsObserver;
class LLInventoryGalleryContextMenu;
+typedef boost::function<void()> callback_t;
+
class LLInventoryGallery : public LLPanel
{
public:
@@ -90,8 +94,7 @@ public:
void setRootFolder(const LLUUID cat_id);
void updateRootFolder();
LLUUID getRootFolder() { return mFolderID; }
- typedef boost::function<void()> root_changed_callback_t;
- boost::signals2::connection setRootChangedCallback(root_changed_callback_t cb);
+ boost::signals2::connection setRootChangedCallback(callback_t cb);
void onForwardFolder();
void onBackwardFolder();
void clearNavigationHistory();
@@ -127,6 +130,7 @@ protected:
void applyFilter(LLInventoryGalleryItem* item, const std::string& filter_substring);
LLInventoryCategoriesObserver* mCategoriesObserver;
+ LLThumbnailsObserver* mThumbnailsObserver;
LLUUID mSelectedItemID;
bool mIsInitialized;
@@ -279,4 +283,33 @@ private:
LLInventoryGallery* mGallery;
};
+class LLThumbnailsObserver : public LLInventoryObserver
+{
+public:
+ LLThumbnailsObserver(){};
+
+ virtual void changed(U32 mask);
+ bool addItem(const LLUUID& obj_id, callback_t cb);
+ void removeItem(const LLUUID& obj_id);
+
+protected:
+
+ struct LLItemData
+ {
+ LLItemData(const LLUUID& obj_id, const LLUUID& thumbnail_id, callback_t cb)
+ : mItemID(obj_id)
+ , mCallback(cb)
+ , mThumbnailID(thumbnail_id)
+ {}
+
+ callback_t mCallback;
+ LLUUID mItemID;
+ LLUUID mThumbnailID;
+ };
+
+ typedef std::map<LLUUID, LLItemData> item_map_t;
+ typedef item_map_t::value_type item_map_value_t;
+ item_map_t mItemMap;
+};
+
#endif