From f15442a82a2bfee00694b0097abdf6aeae083e14 Mon Sep 17 00:00:00 2001
From: Merov Linden <merov@lindenlab.com>
Date: Mon, 28 Apr 2014 15:53:54 -0700
Subject: [PATCH] DD-22 : WIP : Implements getSLMListings(). Does no parsing
 for the moment

---
 .../newview/llfloatermarketplacelistings.cpp  |  2 +
 indra/newview/llmarketplacefunctions.cpp      | 84 +++++++++++++------
 indra/newview/llmarketplacefunctions.h        |  6 ++
 3 files changed, 68 insertions(+), 24 deletions(-)

diff --git a/indra/newview/llfloatermarketplacelistings.cpp b/indra/newview/llfloatermarketplacelistings.cpp
index ccfca71df91..e2bf9f0206b 100755
--- a/indra/newview/llfloatermarketplacelistings.cpp
+++ b/indra/newview/llfloatermarketplacelistings.cpp
@@ -264,6 +264,8 @@ void LLFloaterMarketplaceListings::fetchContents()
 	if (mRootFolderId.notNull())
 	{
 		LLInventoryModelBackgroundFetch::instance().start(mRootFolderId);
+        // Get all the SLM Listings
+        LLMarketplaceData::instance().getSLMListings();
 	}
 }
 
diff --git a/indra/newview/llmarketplacefunctions.cpp b/indra/newview/llmarketplacefunctions.cpp
index c3aaf660718..b85828ddfd1 100755
--- a/indra/newview/llmarketplacefunctions.cpp
+++ b/indra/newview/llmarketplacefunctions.cpp
@@ -96,7 +96,7 @@ LLSD getMarketplaceStringSubstitutions()
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-// SLM Responder
+// SLM Responders
 class LLSLMMerchantResponder : public LLHTTPClient::Responder
 {
 	LOG_CLASS(LLSLMMerchantResponder);
@@ -132,7 +132,41 @@ class LLSLMMerchantResponder : public LLHTTPClient::Responder
 		}
     }
 };
-// SLM Responder End
+
+class LLSLMListingsResponder : public LLHTTPClient::Responder
+{
+	LOG_CLASS(LLSLMListingsResponder);
+public:
+	
+    LLSLMListingsResponder() {}
+    
+	virtual void completed(U32 status, const std::string& reason, const LLSD& content)
+	{
+		if (isGoodStatus(status))
+		{
+            llinfos << "Merov : completed successful, status = " << status << ", reason = " << reason << ", content = " << content << llendl;
+            // *TODO : Parse the Json body
+            //LLMarketplaceData::instance().parseListings(content);
+		}
+		else
+		{
+            llinfos << "Merov : completed with error, status = " << status << ", reason = " << reason << ", content = " << content << llendl;
+		}
+	}
+    
+    void completedHeader(U32 status, const std::string& reason, const LLSD& content)
+    {
+		if (isGoodStatus(status))
+		{
+            llinfos << "Merov : completed header successful, status = " << status << ", reason = " << reason << ", content = " << content << llendl;
+		}
+		else
+		{
+            llinfos << "Merov : completed header with error, status = " << status << ", reason = " << reason << ", content = " << content << llendl;
+		}
+    }
+};
+// SLM Responders End
 ///////////////////////////////////////////////////////////////////////////////
 
 namespace LLMarketplaceImport
@@ -621,34 +655,36 @@ void LLMarketplaceData::initializeSLM(const status_updated_signal_t::slot_type&
 		mStatusUpdatedSignal = new status_updated_signal_t();
 	}
 	mStatusUpdatedSignal->connect(cb);
-    
-    // Get DirectDelivery cap
-    std::string url = "";
-	LLViewerRegion* region = gAgent.getRegion();
-	if (region)
-    {
-        url = region->getCapability("DirectDelivery");
-        llinfos << "Merov : Test DirectDelivery cap : url = " << url << llendl;
-    }
-    else
-    {
-        llinfos << "Merov : Test DirectDelivery cap : no region accessible" << llendl;
-    }
-    // *TODO : Take this DirectDelivery cap coping hack out
-    if (url == "")
+	LLHTTPClient::get(getSLMConnectURL("/merchant"), new LLSLMMerchantResponder(), LLSD());
+}
+
+void LLMarketplaceData::getSLMListings()
+{
+	LLHTTPClient::get(getSLMConnectURL("/listings"), new LLSLMListingsResponder(), LLSD());
+}
+
+std::string LLMarketplaceData::getSLMConnectURL(const std::string& route)
+{
+    std::string url("");
+    LLViewerRegion *regionp = gAgent.getRegion();
+    if (regionp)
     {
-        url = "https://marketplace.secondlife-staging.com/api/1/viewer/" + gAgentID.asString() + "/merchant";
+        // Get DirectDelivery cap
+        url = regionp->getCapability("DirectDelivery");
+        // *TODO : Take this DirectDelivery cap coping mechanism hack out
+        if (url == "")
+        {
+            url = "https://marketplace.secondlife-staging.com/api/1/viewer/" + gAgentID.asString();
+        }
+        url += route;
     }
-    llinfos << "Merov : Testing get : " << url << llendl;
-    
-	LLHTTPClient::get(url, new LLSLMMerchantResponder(), LLSD());
+    llinfos << "Merov : Testing getSLMConnectURL : " << url << llendl;
+	return url;
 }
 
 void LLMarketplaceData::setSLMStatus(U32 status)
 {
-    mMarketPlaceStatus = status; /* call cb if status is "done" */
-
-    // Make sure we trigger the status change with the current state
+    mMarketPlaceStatus = status;
     if (mStatusUpdatedSignal)
     {
         (*mStatusUpdatedSignal)();
diff --git a/indra/newview/llmarketplacefunctions.h b/indra/newview/llmarketplacefunctions.h
index 237432068c8..d5869d3025f 100755
--- a/indra/newview/llmarketplacefunctions.h
+++ b/indra/newview/llmarketplacefunctions.h
@@ -150,6 +150,12 @@ class LLMarketplaceData
 	U32  getSLMStatus() const { return mMarketPlaceStatus; }
 	void setSLMStatus(U32 status);
     void initializeSLM(const status_updated_signal_t::slot_type& cb);
+    void getSLMListings();
+    //void getSLMListing();
+    //void postSLMListing();
+    //void modifySLMListing();
+    //void associateSLMListing();
+    std::string getSLMConnectURL(const std::string& route);
     
     bool isEmpty() { return (mMarketplaceItems.size() == 0); }
     
-- 
GitLab