diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-23 22:53:57 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-23 22:53:57 (GMT) |
| commit | df72f2580f68a7d0055fcf20dcd65c0be90c52dd (patch) | |
| tree | ada3c6d3fdc2009f5236ec2a39d661c0bfaaf3e5 /src/client | |
| parent | 2bd571e1598e6baffc717bcb086d89d01929604b (diff) | |
| download | powder-df72f2580f68a7d0055fcf20dcd65c0be90c52dd.zip powder-df72f2580f68a7d0055fcf20dcd65c0be90c52dd.tar.gz | |
Better element buttons, Save preview WIP
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/Client.cpp | 93 | ||||
| -rw-r--r-- | src/client/Client.h | 2 |
2 files changed, 94 insertions, 1 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp index ff6fb97..c2e82ea 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -39,6 +39,97 @@ Client::~Client() http_done(); } +Save * Client::GetSave(int saveID, int saveDate) +{ + lastError = ""; + std::stringstream urlStream; + urlStream << "http://" << SERVER << "/Browse/View.json?ID=" << saveID; + if(saveDate) + { + urlStream << "&Date=" << saveDate; + } + char * data; + int dataStatus, dataLength; + //Save(int _id, int _votesUp, int _votesDown, string _userName, string _name, string description_, string date_, bool published_): + data = http_simple_get((char *)urlStream.str().c_str(), &dataStatus, &dataLength); + if(dataStatus == 200 && data) + { + try + { + std::istringstream dataStream(data); + json::Object objDocument; + json::Reader::Read(objDocument, dataStream); + + json::Number tempID = objDocument["ID"]; + json::Number tempScoreUp = objDocument["ScoreUp"]; + json::Number tempScoreDown = objDocument["ScoreDown"]; + json::String tempUsername = objDocument["Username"]; + json::String tempName = objDocument["Name"]; + json::String tempDescription = objDocument["Description"]; + json::String tempDate = objDocument["Date"]; + json::Boolean tempPublished = objDocument["Published"]; + return new Save( + tempID.Value(), + tempScoreUp.Value(), + tempScoreDown.Value(), + tempUsername.Value(), + tempName.Value(), + tempDescription.Value(), + tempDate.Value(), + tempPublished.Value() + ); + } + catch (json::Exception &e) + { + lastError = "Could not read response"; + return NULL; + } + } + else + { + lastError = http_ret_text(dataStatus); + } + return NULL; +} + +Thumbnail * Client::GetPreview(int saveID, int saveDate) +{ + std::stringstream urlStream; + urlStream << "http://" << SERVER << "/Get.api?Op=thumblarge&ID=" << saveID; + if(saveDate) + { + urlStream << "&Date=" << saveDate; + } + pixel * thumbData; + char * data; + int status, data_size, imgw, imgh; + data = http_simple_get((char *)urlStream.str().c_str(), &status, &data_size); + if (status == 200 && data) + { + thumbData = Graphics::ptif_unpack(data, data_size, &imgw, &imgh); + if(data) + { + free(data); + } + if(thumbData) + { + return new Thumbnail(saveID, saveDate, thumbData, ui::Point(imgw, imgh)); + } + else + { + return new Thumbnail(saveID, saveDate, (pixel *)malloc((128*128) * PIXELSIZE), ui::Point(128, 128)); + } + } + else + { + if(data) + { + free(data); + } + return new Thumbnail(saveID, saveDate, (pixel *)malloc((128*128) * PIXELSIZE), ui::Point(128, 128)); + } +} + std::vector<Save*> * Client::SearchSaves(int start, int count, string query, string sort, int & resultCount) { lastError = ""; @@ -66,7 +157,7 @@ std::vector<Save*> * Client::SearchSaves(int start, int count, string query, str { try { - std::istringstream dataStream(data); // missing comma! + std::istringstream dataStream(data); json::Object objDocument; json::Reader::Read(objDocument, dataStream); diff --git a/src/client/Client.h b/src/client/Client.h index 678b3e7..c974524 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -25,7 +25,9 @@ public: ~Client(); void ClearThumbnailRequests(); std::vector<Save*> * SearchSaves(int start, int count, string query, string sort, int & resultCount); + Thumbnail * GetPreview(int saveID, int saveDate); Thumbnail * GetThumbnail(int saveID, int saveDate); + Save * GetSave(int saveID, int saveDate); std::string GetLastError() { return lastError; } }; |
