summaryrefslogtreecommitdiff
path: root/src/client/Client.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-03-22 22:12:16 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-03-22 22:12:16 (GMT)
commit63af6abd29a161f6d1aa257aeb76f6891f512f74 (patch)
tree841fc401ae8670ccd20131b2cf95ac2090662c25 /src/client/Client.cpp
parent23873eae719a1c0a1227a4e108a158a9ec625462 (diff)
downloadpowder-63af6abd29a161f6d1aa257aeb76f6891f512f74.zip
powder-63af6abd29a161f6d1aa257aeb76f6891f512f74.tar.gz
Add and remove tags.\nBrings to light an interesting issue with adding or removing UI components within component Event handlers
Diffstat (limited to 'src/client/Client.cpp')
-rw-r--r--src/client/Client.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp
index f6c2ecb..e85d3e6 100644
--- a/src/client/Client.cpp
+++ b/src/client/Client.cpp
@@ -676,3 +676,101 @@ Thumbnail * Client::GetThumbnail(int saveID, int saveDate)
//http_async_req_start(http, urlStream.str().c_str(), NULL, 0, 1);
return NULL;
}
+
+std::vector<string> * Client::RemoveTag(int saveID, string tag)
+{
+ lastError = "";
+ std::vector<string> * tags = NULL;
+ std::stringstream urlStream;
+ char * data = NULL;
+ int dataStatus, dataLength;
+ urlStream << "http://" << SERVER << "/Browse/EditTag.json?Op=delete&ID=" << saveID << "&Tag=" << tag;
+ if(authUser.ID)
+ {
+ std::stringstream userIDStream;
+ userIDStream << authUser.ID;
+ data = http_auth_get((char *)urlStream.str().c_str(), (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength);
+ }
+ else
+ {
+ lastError = "Not authenticated";
+ return NULL;
+ }
+ if(dataStatus == 200 && data)
+ {
+ try
+ {
+ std::istringstream dataStream(data);
+ json::Array tagsArray;
+ json::Reader::Read(tagsArray, dataStream);
+
+ tags = new std::vector<string>();
+
+ for(int j = 0; j < tagsArray.Size(); j++)
+ {
+ json::String tempTag = tagsArray[j];
+ tags->push_back(tempTag.Value());
+ }
+ }
+ catch (json::Exception &e)
+ {
+ lastError = "Could not read response";
+ }
+ }
+ else
+ {
+ lastError = http_ret_text(dataStatus);
+ }
+ if(data)
+ free(data);
+ return tags;
+}
+
+std::vector<string> * Client::AddTag(int saveID, string tag)
+{
+ lastError = "";
+ std::vector<string> * tags = NULL;
+ std::stringstream urlStream;
+ char * data = NULL;
+ int dataStatus, dataLength;
+ urlStream << "http://" << SERVER << "/Browse/EditTag.json?Op=add&ID=" << saveID << "&Tag=" << tag;
+ if(authUser.ID)
+ {
+ std::stringstream userIDStream;
+ userIDStream << authUser.ID;
+ data = http_auth_get((char *)urlStream.str().c_str(), (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength);
+ }
+ else
+ {
+ lastError = "Not authenticated";
+ return NULL;
+ }
+ if(dataStatus == 200 && data)
+ {
+ try
+ {
+ std::istringstream dataStream(data);
+ json::Array tagsArray;
+ json::Reader::Read(tagsArray, dataStream);
+
+ tags = new std::vector<string>();
+
+ for(int j = 0; j < tagsArray.Size(); j++)
+ {
+ json::String tempTag = tagsArray[j];
+ tags->push_back(tempTag.Value());
+ }
+ }
+ catch (json::Exception &e)
+ {
+ lastError = "Could not read response";
+ }
+ }
+ else
+ {
+ lastError = http_ret_text(dataStatus);
+ }
+ if(data)
+ free(data);
+ return tags;
+}