From eb6e64ec401382fd2fbbbb27830e828035a6e5af Mon Sep 17 00:00:00 2001
From: "Brad Payne (Vir Linden)" <vir@lindenlab.com>
Date: Tue, 19 Nov 2019 16:15:19 +0000
Subject: [PATCH] SL-10499 - Fixes for benefits info and upload, especially
 bulk upload

---
 indra/newview/llfloaternamedesc.cpp           | 31 ++++++++++++++-----
 indra/newview/llfloaternamedesc.h             |  3 ++
 indra/newview/llpanelmaininventory.cpp        | 10 ------
 indra/newview/llstartup.cpp                   |  2 +-
 indra/newview/llviewerassetupload.cpp         |  6 ++++
 indra/newview/llviewerassetupload.h           |  1 +
 indra/newview/llviewermenu.cpp                | 10 +++---
 .../skins/default/xui/en/menu_viewer.xml      |  2 +-
 .../skins/default/xui/en/notifications.xml    |  8 +++++
 9 files changed, 49 insertions(+), 24 deletions(-)

diff --git a/indra/newview/llfloaternamedesc.cpp b/indra/newview/llfloaternamedesc.cpp
index fa1ed57d1ff..937dd60f0f4 100644
--- a/indra/newview/llfloaternamedesc.cpp
+++ b/indra/newview/llfloaternamedesc.cpp
@@ -63,7 +63,7 @@ const S32 PREVIEW_HPAD = PREVIEW_RESIZE_HANDLE_SIZE;
 //-----------------------------------------------------------------------------
 LLFloaterNameDesc::LLFloaterNameDesc(const LLSD& filename )
 	: LLFloater(filename),
-	  mIsAudio(FALSE)	  
+	  mIsAudio(FALSE)
 {
 	mFilenameAndPath = filename.asString();
 	mFilename = gDirUtilp->getBaseFileName(mFilenameAndPath, false);
@@ -123,14 +123,33 @@ BOOL LLFloaterNameDesc::postBuild()
 	// Cancel button
 	getChild<LLUICtrl>("cancel_btn")->setCommitCallback(boost::bind(&LLFloaterNameDesc::onBtnCancel, this));
 
-	// FIXME PREMIUM - depends - what are we uploading here?
-	getChild<LLUICtrl>("ok_btn")->setLabelArg("[AMOUNT]", llformat("%d", LLAgentBenefits::instance().getTextureUploadCost()));
+	S32 expected_upload_cost = getExpectedUploadCost();
+	getChild<LLUICtrl>("ok_btn")->setLabelArg("[AMOUNT]", llformat("%d", expected_upload_cost));
 	
 	setDefaultBtn("ok_btn");
 	
 	return TRUE;
 }
 
+S32 LLFloaterNameDesc::getExpectedUploadCost() const
+{
+    std::string exten = gDirUtilp->getExtension(mFilename);
+	LLAssetType::EType asset_type;
+	S32 upload_cost = -1;
+	if (LLResourceUploadInfo::findAssetTypeOfExtension(exten, asset_type))
+	{
+		if (!LLAgentBenefits::instance().findUploadCost(asset_type, upload_cost))
+		{
+			LL_WARNS() << "Unable to find upload cost for asset type " << asset_type << LL_ENDL;
+		}
+	}
+	else
+	{
+		LL_WARNS() << "Unable to find upload cost for " << mFilename << LL_ENDL;
+	}
+	return upload_cost;
+}
+
 //-----------------------------------------------------------------------------
 // LLFloaterNameDesc()
 //-----------------------------------------------------------------------------
@@ -162,10 +181,8 @@ void LLFloaterNameDesc::onBtnOK( )
 {
 	getChildView("ok_btn")->setEnabled(FALSE); // don't allow inadvertent extra uploads
 	
-	// FIXME PREMIUM - upload cost. Need to know which asset type this is, use agent benefits.
 	LLAssetStorage::LLStoreAssetCallback callback = NULL;
-	S32 expected_upload_cost = LLAgentBenefits::instance().getTextureUploadCost(); // kinda hack - assumes that unsubclassed LLFloaterNameDesc is only used for uploading chargeable assets, which it is right now (it's only used unsubclassed for the sound upload dialog, and THAT should be a subclass).
-
+	S32 expected_upload_cost = getExpectedUploadCost();
     if (can_afford_transaction(expected_upload_cost))
     {
         void *nruserdata = NULL;
@@ -187,7 +204,7 @@ void LLFloaterNameDesc::onBtnOK( )
     {
         LLSD args;
         args["COST"] = llformat("%d", expected_upload_cost);
-        LLNotificationsUtil::add("ErrorTextureCannotAfford", args);
+        LLNotificationsUtil::add("ErrorCannotAffordUpload", args);
     }
 
 	closeFloater(false);
diff --git a/indra/newview/llfloaternamedesc.h b/indra/newview/llfloaternamedesc.h
index 41643681ac0..589f470e827 100644
--- a/indra/newview/llfloaternamedesc.h
+++ b/indra/newview/llfloaternamedesc.h
@@ -30,6 +30,7 @@
 #include "llfloater.h"
 #include "llresizehandle.h"
 #include "llstring.h"
+#include "llassettype.h"
 
 class LLLineEditor;
 class LLButton;
@@ -45,6 +46,8 @@ class LLFloaterNameDesc : public LLFloater
 	void		onBtnOK();
 	void		onBtnCancel();
 	void		doCommit();
+
+	S32			getExpectedUploadCost() const;
 	
 protected:
 	virtual void		onCommit();
diff --git a/indra/newview/llpanelmaininventory.cpp b/indra/newview/llpanelmaininventory.cpp
index b81dce4e318..a57ee832855 100644
--- a/indra/newview/llpanelmaininventory.cpp
+++ b/indra/newview/llpanelmaininventory.cpp
@@ -237,11 +237,6 @@ BOOL LLPanelMainInventory::postBuild()
 		menu->getChild<LLMenuItemGL>("Upload Image")->setLabelArg("[COST]", texture_upload_cost_str);
 		menu->getChild<LLMenuItemGL>("Upload Sound")->setLabelArg("[COST]", sound_upload_cost_str);
 		menu->getChild<LLMenuItemGL>("Upload Animation")->setLabelArg("[COST]", animation_upload_cost_str);
-
-		// FIXME PREMIUM - bulk upload of what? This doesn't work with
-		// mixed items if costs aren't all the same. For now treating
-		// as textures.
-		menu->getChild<LLMenuItemGL>("Bulk Upload")->setLabelArg("[COST]", texture_upload_cost_str);
 	}
 
 	// Trigger callback for focus received so we can deselect items in inbox/outbox
@@ -1519,11 +1514,6 @@ void LLPanelMainInventory::setUploadCostIfNeeded()
 		menu->getChild<LLView>("Upload Image")->setLabelArg("[COST]", texture_upload_cost_str);
 		menu->getChild<LLView>("Upload Sound")->setLabelArg("[COST]", sound_upload_cost_str);
 		menu->getChild<LLView>("Upload Animation")->setLabelArg("[COST]", animation_upload_cost_str);
-
-		// FIXME PREMIUM - bulk upload of what? This doesn't work with
-		// mixed items if costs aren't all the same. For now treating
-		// as textures.
-		menu->getChild<LLView>("Bulk Upload")->setLabelArg("[COST]", texture_upload_cost_str);
 	}
 }
 
diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp
index 2f9bc786ca5..c144ea2f8e6 100644
--- a/indra/newview/llstartup.cpp
+++ b/indra/newview/llstartup.cpp
@@ -3254,7 +3254,7 @@ bool process_login_success_response()
 {
 	LLSD response = LLLoginInstance::getInstance()->getResponse();
 
-	//LL_INFOS() << "login success response:" << ll_pretty_print_sd(response) << LL_ENDL;
+	LL_DEBUGS("Benefits") << "login success response:" << response << LL_ENDL;
 	if (!LLAgentBenefits::instance().init(response["account_level_benefits"]))
 	{
 		LL_ERRS() << "Benefits error" << LL_ENDL;
diff --git a/indra/newview/llviewerassetupload.cpp b/indra/newview/llviewerassetupload.cpp
index de35f9911c0..4cbb88d4f17 100644
--- a/indra/newview/llviewerassetupload.cpp
+++ b/indra/newview/llviewerassetupload.cpp
@@ -306,6 +306,12 @@ std::string LLResourceUploadInfo::getDisplayName() const
     return (mName.empty()) ? mAssetId.asString() : mName;
 };
 
+bool LLResourceUploadInfo::findAssetTypeOfExtension(const std::string& exten, LLAssetType::EType& asset_type)
+{
+	U32 codec;
+	return findAssetTypeAndCodecOfExtension(exten, asset_type, codec);
+}
+
 // static
 bool LLResourceUploadInfo::findAssetTypeAndCodecOfExtension(const std::string& exten, LLAssetType::EType& asset_type, U32& codec)
 {
diff --git a/indra/newview/llviewerassetupload.h b/indra/newview/llviewerassetupload.h
index 8ef25ad6fd4..6301359021b 100644
--- a/indra/newview/llviewerassetupload.h
+++ b/indra/newview/llviewerassetupload.h
@@ -87,6 +87,7 @@ class LLResourceUploadInfo
     LLUUID              getItemId() const { return mItemId; }
     LLAssetID           getAssetId() const { return mAssetId; }
 
+	static bool			findAssetTypeOfExtension(const std::string& exten, LLAssetType::EType& asset_type);
 	static bool			findAssetTypeAndCodecOfExtension(const std::string& exten, LLAssetType::EType& asset_type, U32& codec);
 
 protected:
diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp
index c1de2751743..e88acc2ac42 100644
--- a/indra/newview/llviewermenu.cpp
+++ b/indra/newview/llviewermenu.cpp
@@ -516,8 +516,6 @@ void init_menus()
 	gMenuHolder->childSetLabelArg("Upload Image", "[COST]", texture_upload_cost_str);
 	gMenuHolder->childSetLabelArg("Upload Sound", "[COST]", sound_upload_cost_str);
 	gMenuHolder->childSetLabelArg("Upload Animation", "[COST]", animation_upload_cost_str);
-	// FIXME PREMIUM - do we need to handle non-texture bulk uploads?
-	gMenuHolder->childSetLabelArg("Bulk Upload", "[COST]", texture_upload_cost_str);
 	
 	gAttachSubMenu = gMenuBarView->findChildMenuByName("Attach Object", TRUE);
 	gDetachSubMenu = gMenuBarView->findChildMenuByName("Detach Object", TRUE);
@@ -8720,8 +8718,7 @@ class LLToggleUIHints : public view_listener_t
 
 void LLUploadCostCalculator::calculateCost(const std::string& asset_type_str)
 {
-	// FIXME PREMIUM reasonable default?
-	S32 upload_cost = LLAgentBenefits::instance().getTextureUploadCost();
+	S32 upload_cost = -1;
 
 	if (asset_type_str == "texture")
 	{
@@ -8735,6 +8732,10 @@ void LLUploadCostCalculator::calculateCost(const std::string& asset_type_str)
 	{
 		upload_cost = LLAgentBenefits::instance().getSoundUploadCost();
 	}
+	if (upload_cost < 0)
+	{
+		LL_WARNS() << "Unable to find upload cost for asset_type_str " << asset_type_str << LL_ENDL;
+	}
 	mCostStr = std::to_string(upload_cost);
 }
 
@@ -8840,7 +8841,6 @@ void initialize_menus()
 
 	enable.add("displayViewerEventRecorderMenuItems",boost::bind(&LLViewerEventRecorder::displayViewerEventRecorderMenuItems,&LLViewerEventRecorder::instance()));
 
-	// FIXME PREMIUM these need to be distinguished by asset type - see menu_viewer.xml
 	view_listener_t::addEnable(new LLUploadCostCalculator(), "Upload.CalculateCosts");
 
 	enable.add("Conversation.IsConversationLoggingAllowed", boost::bind(&LLFloaterIMContainer::isConversationLoggingAllowed));
diff --git a/indra/newview/skins/default/xui/en/menu_viewer.xml b/indra/newview/skins/default/xui/en/menu_viewer.xml
index 9b27e8b03dc..362ddfd27ac 100644
--- a/indra/newview/skins/default/xui/en/menu_viewer.xml
+++ b/indra/newview/skins/default/xui/en/menu_viewer.xml
@@ -1347,7 +1347,7 @@
             function="File.VisibleUploadModel"/>
             </menu_item_call>
 	   <menu_item_call
-             label="Bulk..."
+             labe="Bulk..."
              layout="topleft"
              name="Bulk Upload">
                 <menu_item_call.on_visible
diff --git a/indra/newview/skins/default/xui/en/notifications.xml b/indra/newview/skins/default/xui/en/notifications.xml
index 2df0b1cbf4f..f93113ebd01 100644
--- a/indra/newview/skins/default/xui/en/notifications.xml
+++ b/indra/newview/skins/default/xui/en/notifications.xml
@@ -1289,6 +1289,14 @@ Error encoding snapshot.
     <tag>fail</tag>
   </notification>
   
+  <notification
+   icon="alertmodal.tga"
+   name="ErrorCannotAffordUpload"
+   type="alertmodal">
+    You need L$[COST] to upload this item.
+    <tag>fail</tag>
+  </notification>
+  
   <notification
    icon="alertmodal.tga"
    name="ErrorTextureCannotAfford"
-- 
GitLab