From 618e13a2d6c5bd632892865fc3b88051c13a7658 Mon Sep 17 00:00:00 2001
From: Merov Linden <merov@lindenlab.com>
Date: Fri, 2 Jan 2015 17:35:50 -0800
Subject: [PATCH] DD-297 : Performance on login : Refactored the code so that
 we have a new LLMarketplaceFolderBridge class in the bridge model. Only the
 panels with the use_marketplace_folders param flag will use that one.

---
 indra/llcommon/llassettype.h                  |   3 +
 indra/newview/llinventorybridge.cpp           | 170 +++++++++++-------
 indra/newview/llinventorybridge.h             |  25 ++-
 indra/newview/llinventorypanel.cpp            |   8 +-
 indra/newview/llinventorypanel.h              |   2 +
 .../panel_marketplace_listings_inventory.xml  |   1 +
 .../en/panel_marketplace_listings_listed.xml  |   1 +
 ...anel_marketplace_listings_unassociated.xml |   1 +
 .../panel_marketplace_listings_unlisted.xml   |   1 +
 9 files changed, 139 insertions(+), 73 deletions(-)

diff --git a/indra/llcommon/llassettype.h b/indra/llcommon/llassettype.h
index 5a95a58d93d..3a4b5dad18c 100755
--- a/indra/llcommon/llassettype.h
+++ b/indra/llcommon/llassettype.h
@@ -107,6 +107,9 @@ class LL_COMMON_API LLAssetType
 		AT_LINK_FOLDER = 25,
 			// Inventory folder link
 		
+        AT_MARKETPLACE_FOLDER = 26,
+            // Marketplace folder. Same as an AT_CATEGORY but different display methods.
+        
 		AT_WIDGET = 40,
 			// UI Widget: this is *not* an inventory asset type, only a viewer side asset (e.g. button, other ui items...)
 		
diff --git a/indra/newview/llinventorybridge.cpp b/indra/newview/llinventorybridge.cpp
index 4e3895ea9d4..2dafbccd968 100755
--- a/indra/newview/llinventorybridge.cpp
+++ b/indra/newview/llinventorybridge.cpp
@@ -1274,11 +1274,18 @@ LLInvFVBridge* LLInvFVBridge::createBridge(LLAssetType::EType asset_type,
 		case LLAssetType::AT_CATEGORY:
 			if (actual_asset_type == LLAssetType::AT_LINK_FOLDER)
 			{
-				// Create a link folder handler instead.
+				// Create a link folder handler instead
 				new_listener = new LLLinkFolderBridge(inventory, root, uuid);
-				break;
 			}
-			new_listener = new LLFolderBridge(inventory, root, uuid);
+            else if (actual_asset_type == LLAssetType::AT_MARKETPLACE_FOLDER)
+            {
+				// Create a marketplace folder handler
+				new_listener = new LLMarketplaceFolderBridge(inventory, root, uuid);
+            }
+            else
+            {
+                new_listener = new LLFolderBridge(inventory, root, uuid);
+            }
 			break;
 		case LLAssetType::AT_LINK:
 		case LLAssetType::AT_LINK_FOLDER:
@@ -2090,71 +2097,14 @@ std::string LLFolderBridge::getLabelSuffix() const
         return llformat(" ( %s ) ", LLTrans::getString("LoadingData").c_str());
     }
     
-    if (isMarketplaceListingsFolder())
-    {
-        std::string suffix = "";
-        // Listing folder case
-        if (LLMarketplaceData::instance().isListed(getUUID()))
-        {
-            suffix = llformat("%d",LLMarketplaceData::instance().getListingID(getUUID()));
-            if (suffix.empty())
-            {
-                suffix = LLTrans::getString("MarketplaceNoID");
-            }
-            suffix = " (" +  suffix + ")";
-            if (LLMarketplaceData::instance().getActivationState(getUUID()))
-            {
-                suffix += " (" +  LLTrans::getString("MarketplaceLive") + ")";
-            }
-        }
-        // Version folder case
-        else if (LLMarketplaceData::instance().isVersionFolder(getUUID()))
-        {
-            suffix += " (" +  LLTrans::getString("MarketplaceActive") + ")";
-        }
-        // Add stock amount
-        S32 stock_count = compute_stock_count(getUUID());
-        if (stock_count == 0)
-        {
-            suffix += " (" +  LLTrans::getString("MarketplaceNoStock") + ")";
-        }
-        else if (stock_count != -1)
-        {
-            if (getPreferredType() == LLFolderType::FT_MARKETPLACE_STOCK)
-            {
-                suffix += " (" +  LLTrans::getString("MarketplaceStock") + "=" + llformat("%d", stock_count) + ")";
-            }
-            else
-            {
-                suffix += " (" +  LLTrans::getString("MarketplaceMax") + "=" + llformat("%d", stock_count) + ")";
-            }
-        }
-        // Add updating suffix
-        if (LLMarketplaceData::instance().isUpdating(getUUID()))
-        {
-            suffix += " (" +  LLTrans::getString("MarketplaceUpdating") + ")";
-        }
-        return LLInvFVBridge::getLabelSuffix() + suffix;
-	}
-	else
-	{
-		return LLInvFVBridge::getLabelSuffix();
-	}
+    return LLInvFVBridge::getLabelSuffix();
 }
 
 LLFontGL::StyleFlags LLFolderBridge::getLabelStyle() const
 {
-	if (isMarketplaceListingsFolder() && LLMarketplaceData::instance().getActivationState(getUUID()))
-	{
-		return LLFontGL::BOLD;
-	}
-	else
-	{
-		return LLFontGL::NORMAL;
-	}
+    return LLFontGL::NORMAL;
 }
 
-
 void LLFolderBridge::update()
 {
 	// we know we have children but  haven't  fetched them (doesn't obey filter)
@@ -3283,12 +3233,6 @@ LLUIImagePtr LLFolderBridge::getIconOpen() const
 LLUIImagePtr LLFolderBridge::getFolderIcon(BOOL is_open) const
 {
 	LLFolderType::EType preferred_type = getPreferredType();
-    S32 depth = depth_nesting_in_marketplace(mUUID);
-    if ((preferred_type == LLFolderType::FT_NONE) && (depth == 2))
-    {
-        // We override the type when in the marketplace listings folder and only for version folder
-        preferred_type = LLFolderType::FT_MARKETPLACE_VERSION;
-    }
 	return LLUI::getUIImage(LLViewerFolderType::lookupIconName(preferred_type, is_open));
 }
 
@@ -4184,6 +4128,96 @@ void LLFolderBridge::modifyOutfit(BOOL append)
 	LLAppearanceMgr::instance().wearInventoryCategory( cat, FALSE, append );
 }
 
+// +=================================================+
+// |        LLMarketplaceFolderBridge                |
+// +=================================================+
+
+// LLMarketplaceFolderBridge is a specialized LLFolderBridge for use in Marketplace Inventory panels
+
+LLUIImagePtr LLMarketplaceFolderBridge::getIcon() const
+{
+	return getMarketplaceFolderIcon(FALSE);
+}
+
+LLUIImagePtr LLMarketplaceFolderBridge::getIconOpen() const
+{
+	return getMarketplaceFolderIcon(TRUE);
+}
+
+LLUIImagePtr LLMarketplaceFolderBridge::getMarketplaceFolderIcon(BOOL is_open) const
+{
+	LLFolderType::EType preferred_type = getPreferredType();
+    S32 depth = depth_nesting_in_marketplace(mUUID);
+    if ((preferred_type == LLFolderType::FT_NONE) && (depth == 2))
+    {
+        // We override the type when in the marketplace listings folder and only for version folder
+        preferred_type = LLFolderType::FT_MARKETPLACE_VERSION;
+    }
+	return LLUI::getUIImage(LLViewerFolderType::lookupIconName(preferred_type, is_open));
+}
+
+std::string LLMarketplaceFolderBridge::getLabelSuffix() const
+{
+    static LLCachedControl<F32> folder_loading_message_delay(gSavedSettings, "FolderLoadingMessageWaitTime", 0.5f);
+    
+    if (mIsLoading && mTimeSinceRequestStart.getElapsedTimeF32() >= folder_loading_message_delay())
+    {
+        return llformat(" ( %s ) ", LLTrans::getString("LoadingData").c_str());
+    }
+    
+    std::string suffix = "";
+    // Listing folder case
+    if (LLMarketplaceData::instance().isListed(getUUID()))
+    {
+        suffix = llformat("%d",LLMarketplaceData::instance().getListingID(getUUID()));
+        if (suffix.empty())
+        {
+            suffix = LLTrans::getString("MarketplaceNoID");
+        }
+        suffix = " (" +  suffix + ")";
+        if (LLMarketplaceData::instance().getActivationState(getUUID()))
+        {
+            suffix += " (" +  LLTrans::getString("MarketplaceLive") + ")";
+        }
+    }
+    // Version folder case
+    else if (LLMarketplaceData::instance().isVersionFolder(getUUID()))
+    {
+        suffix += " (" +  LLTrans::getString("MarketplaceActive") + ")";
+    }
+    // Add stock amount
+    S32 stock_count = compute_stock_count(getUUID());
+    if (stock_count == 0)
+    {
+        suffix += " (" +  LLTrans::getString("MarketplaceNoStock") + ")";
+    }
+    else if (stock_count != -1)
+    {
+        if (getPreferredType() == LLFolderType::FT_MARKETPLACE_STOCK)
+        {
+            suffix += " (" +  LLTrans::getString("MarketplaceStock") + "=" + llformat("%d", stock_count) + ")";
+        }
+        else
+        {
+            suffix += " (" +  LLTrans::getString("MarketplaceMax") + "=" + llformat("%d", stock_count) + ")";
+        }
+    }
+    // Add updating suffix
+    if (LLMarketplaceData::instance().isUpdating(getUUID()))
+    {
+        suffix += " (" +  LLTrans::getString("MarketplaceUpdating") + ")";
+    }
+    return LLInvFVBridge::getLabelSuffix() + suffix;
+}
+
+LLFontGL::StyleFlags LLMarketplaceFolderBridge::getLabelStyle() const
+{
+    return (LLMarketplaceData::instance().getActivationState(getUUID()) ? LLFontGL::BOLD : LLFontGL::NORMAL);
+}
+
+
+
+
 // helper stuff
 bool move_task_inventory_callback(const LLSD& notification, const LLSD& response, LLMoveInv* move_inv)
 {
diff --git a/indra/newview/llinventorybridge.h b/indra/newview/llinventorybridge.h
index 2757f5c8846..641d30040b8 100755
--- a/indra/newview/llinventorybridge.h
+++ b/indra/newview/llinventorybridge.h
@@ -362,7 +362,7 @@ class LLFolderBridge : public LLInvFVBridge
 	static LLHandle<LLFolderBridge> sSelf;
 	static void staticFolderOptionsMenu();
 
-private:
+protected:
     void callback_pasteFromClipboard(const LLSD& notification, const LLSD& response);
     void perform_pasteFromClipboard();
     void gatherMessage(std::string& message, LLError::ELevel log_level);
@@ -683,6 +683,29 @@ class LLRecentInventoryBridgeBuilder : public LLInventoryFolderViewModelBuilder
 		U32 flags = 0x00) const;
 };
 
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// Marketplace Inventory Panel related classes
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+class LLMarketplaceFolderBridge : public LLFolderBridge
+{
+public:
+    // Overloads some display related methods specific to folders in a marketplace floater context
+	LLMarketplaceFolderBridge(LLInventoryPanel* inventory,
+							  LLFolderView* root,
+							  const LLUUID& uuid) :
+    LLFolderBridge(inventory, root, uuid) { }
+    
+	virtual LLUIImagePtr getIcon() const;
+	virtual LLUIImagePtr getIconOpen() const;
+	virtual std::string getLabelSuffix() const;
+	virtual LLFontGL::StyleFlags getLabelStyle() const;
+    
+private:
+    LLUIImagePtr getMarketplaceFolderIcon(BOOL is_open) const;
+};
+
+
 void rez_attachment(LLViewerInventoryItem* item, 
 					LLViewerJointAttachment* attachment,
 					bool replace = false);
diff --git a/indra/newview/llinventorypanel.cpp b/indra/newview/llinventorypanel.cpp
index 86ff1aed1bf..a2e5e1e5d81 100755
--- a/indra/newview/llinventorypanel.cpp
+++ b/indra/newview/llinventorypanel.cpp
@@ -839,16 +839,16 @@ LLFolderViewItem* LLInventoryPanel::buildNewViews(const LLUUID& id)
   			if ((objectp->getType() == LLAssetType::AT_CATEGORY) &&
   				(objectp->getActualType() != LLAssetType::AT_LINK_FOLDER))
   			{
-  				LLInvFVBridge* new_listener = mInvFVBridgeBuilder->createBridge(objectp->getType(),
-  																				objectp->getType(),
+  				LLInvFVBridge* new_listener = mInvFVBridgeBuilder->createBridge(LLAssetType::AT_CATEGORY,
+                                            (mParams.use_marketplace_folders ? LLAssetType::AT_MARKETPLACE_FOLDER : LLAssetType::AT_CATEGORY),
   																				LLInventoryType::IT_CATEGORY,
   																				this,
-																			&mInventoryViewModel,
+                                                                                &mInventoryViewModel,
   																				mFolderRoot.get(),
   																				objectp->getUUID());
   				if (new_listener)
   				{
-				folder_view_item = createFolderViewFolder(new_listener,allow_drop);
+                    folder_view_item = createFolderViewFolder(new_listener,allow_drop);
   				}
   			}
   			else
diff --git a/indra/newview/llinventorypanel.h b/indra/newview/llinventorypanel.h
index 822c7c2fe70..5edb244af68 100755
--- a/indra/newview/llinventorypanel.h
+++ b/indra/newview/llinventorypanel.h
@@ -98,6 +98,7 @@ class LLInventoryPanel : public LLPanel
 		Optional<bool>						show_empty_message;
 		Optional<bool>						show_root_folder;
 		Optional<bool>						allow_drop_on_root;
+		Optional<bool>						use_marketplace_folders;
 		Optional<LLScrollContainer::Params>	scroll;
 		Optional<bool>						accepts_drag_and_drop;
 		Optional<LLFolderView::Params>		folder_view;
@@ -115,6 +116,7 @@ class LLInventoryPanel : public LLPanel
             show_empty_message("show_empty_message", true),
             show_root_folder("show_root_folder", false),
             allow_drop_on_root("allow_drop_on_root", true),
+            use_marketplace_folders("use_marketplace_folders", false),
 			scroll("scroll"),
 			accepts_drag_and_drop("accepts_drag_and_drop"),
 			folder_view("folder_view"),
diff --git a/indra/newview/skins/default/xui/en/panel_marketplace_listings_inventory.xml b/indra/newview/skins/default/xui/en/panel_marketplace_listings_inventory.xml
index 67988f31531..567e5e2724c 100755
--- a/indra/newview/skins/default/xui/en/panel_marketplace_listings_inventory.xml
+++ b/indra/newview/skins/default/xui/en/panel_marketplace_listings_inventory.xml
@@ -12,6 +12,7 @@
     start_folder.name="Marketplace listings"
     show_empty_message="true"
     show_root_folder="true"
+    use_marketplace_folders="true"
     start_folder.type="merchant"
     tool_tip="Drag and drop items here to list them"
     bg_opaque_color="DkGray2"
diff --git a/indra/newview/skins/default/xui/en/panel_marketplace_listings_listed.xml b/indra/newview/skins/default/xui/en/panel_marketplace_listings_listed.xml
index 181eee70e27..668be27bdc7 100755
--- a/indra/newview/skins/default/xui/en/panel_marketplace_listings_listed.xml
+++ b/indra/newview/skins/default/xui/en/panel_marketplace_listings_listed.xml
@@ -11,6 +11,7 @@
     start_folder.name="Marketplace listings"
     show_empty_message="true"
     show_root_folder="true"
+    use_marketplace_folders="true"
     allow_drop_on_root="false"
     start_folder.type="merchant"
     bg_opaque_color="DkGray2"
diff --git a/indra/newview/skins/default/xui/en/panel_marketplace_listings_unassociated.xml b/indra/newview/skins/default/xui/en/panel_marketplace_listings_unassociated.xml
index 6ea4784c4c4..0015c85aa20 100755
--- a/indra/newview/skins/default/xui/en/panel_marketplace_listings_unassociated.xml
+++ b/indra/newview/skins/default/xui/en/panel_marketplace_listings_unassociated.xml
@@ -11,6 +11,7 @@
     start_folder.name="Marketplace listings"
     show_empty_message="true"
     show_root_folder="true"
+    use_marketplace_folders="true"
     start_folder.type="merchant"
     bg_opaque_color="DkGray2"
     bg_alpha_color="DkGray2"
diff --git a/indra/newview/skins/default/xui/en/panel_marketplace_listings_unlisted.xml b/indra/newview/skins/default/xui/en/panel_marketplace_listings_unlisted.xml
index 0d19d09918d..ec9c1768119 100755
--- a/indra/newview/skins/default/xui/en/panel_marketplace_listings_unlisted.xml
+++ b/indra/newview/skins/default/xui/en/panel_marketplace_listings_unlisted.xml
@@ -11,6 +11,7 @@
     start_folder.name="Marketplace listings"
     show_empty_message="true"
     show_root_folder="true"
+    use_marketplace_folders="true"
     allow_drop_on_root="false"
     start_folder.type="merchant"
     bg_opaque_color="DkGray2"
-- 
GitLab