diff options
| author | build.powdertoy.co.uk <admin@powdertoy.co.uk> | 2012-07-19 17:08:34 (GMT) |
|---|---|---|
| committer | build.powdertoy.co.uk <admin@powdertoy.co.uk> | 2012-07-19 17:08:34 (GMT) |
| commit | d328b84b1330b0e8f3a7f87ce48b9b20ea4b6d01 (patch) | |
| tree | db311c7849270ddd2510cbd65a192b059f8a3c77 /src/client | |
| parent | d71af3706a7a14e8ae65523e1a062417818b8fe2 (diff) | |
| parent | 4d961117bde4398ae4d72f2db96eef381371e2df (diff) | |
| download | powder-d328b84b1330b0e8f3a7f87ce48b9b20ea4b6d01.zip powder-d328b84b1330b0e8f3a7f87ce48b9b20ea4b6d01.tar.gz | |
Merge branch 'master' of github.com:FacialTurd/PowderToypp
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/Client.cpp | 82 | ||||
| -rw-r--r-- | src/client/Client.h | 4 | ||||
| -rw-r--r-- | src/client/ClientListener.h | 1 |
3 files changed, 87 insertions, 0 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 3a46e23..5ecb8ac 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -211,11 +211,31 @@ void Client::notifyUpdateAvailable() } } +void Client::notifyAuthUserChanged() +{ + for (std::vector<ClientListener*>::iterator iterator = listeners.begin(), end = listeners.end(); iterator != end; ++iterator) + { + (*iterator)->NotifyAuthUserChanged(this); + } +} + void Client::AddListener(ClientListener * listener) { listeners.push_back(listener); } +void Client::RemoveListener(ClientListener * listener) +{ + for (std::vector<ClientListener*>::iterator iterator = listeners.begin(), end = listeners.end(); iterator != end; ++iterator) + { + if((*iterator) == listener) + { + listeners.erase(iterator); + return; + } + } +} + void Client::Shutdown() { ClearThumbnailRequests(); @@ -256,6 +276,7 @@ Client::~Client() void Client::SetAuthUser(User user) { authUser = user; + notifyAuthUserChanged(); } User Client::GetAuthUser() @@ -664,6 +685,67 @@ failure: return RequestFailure; } +RequestStatus Client::AddComment(int saveID, std::string comment) +{ + lastError = ""; + std::vector<string> * tags = NULL; + std::stringstream urlStream; + char * data = NULL; + int dataStatus, dataLength; + urlStream << "http://" << SERVER << "/Browse/Comments.json?ID=" << saveID << "&Key=" << authUser.SessionKey; + if(authUser.ID) + { + std::stringstream userIDStream; + userIDStream << authUser.ID; + + char * postNames[] = { "Comment", NULL }; + char * postDatas[] = { (char*)(comment.c_str()) }; + int postLengths[] = { comment.length() }; + data = http_multipart_post((char *)urlStream.str().c_str(), postNames, postDatas, postLengths, (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength); + } + else + { + lastError = "Not authenticated"; + return RequestFailure; + } + if(dataStatus == 200 && data) + { + try + { + std::istringstream dataStream(data); + json::Object objDocument; + json::Reader::Read(objDocument, dataStream); + + int status = ((json::Number)objDocument["Status"]).Value(); + + if(status!=1) + { + lastError = ((json::Number)objDocument["Error"]).Value(); + } + + if(status!=1) + goto failure; + } + catch (json::Exception &e) + { + lastError = "Could not read response"; + goto failure; + } + } + else + { + lastError = http_ret_text(dataStatus); + goto failure; + } + if(data) + free(data); + return RequestOkay; +failure: + if(data) + free(data); + return RequestFailure; +} + RequestStatus Client::FavouriteSave(int saveID, bool favourite) { lastError = ""; diff --git a/src/client/Client.h b/src/client/Client.h index b2822d4..a2d8720 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -67,6 +67,7 @@ private: void updateStamps(); static vector<std::string> explodePropertyString(std::string property); void notifyUpdateAvailable(); + void notifyAuthUserChanged(); //Config file handle json::Object configDocument; @@ -79,6 +80,7 @@ public: ~Client(); void AddListener(ClientListener * listener); + void RemoveListener(ClientListener * listener); RequestStatus ExecVote(int saveID, int direction); RequestStatus UploadSave(SaveInfo * save); @@ -90,6 +92,8 @@ public: int GetStampsCount(); SaveFile * GetFirstStamp(); + RequestStatus AddComment(int saveID, std::string comment); + unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength); LoginStatus Login(string username, string password, User & user); void ClearThumbnailRequests(); diff --git a/src/client/ClientListener.h b/src/client/ClientListener.h index 308721c..4fc2d89 100644 --- a/src/client/ClientListener.h +++ b/src/client/ClientListener.h @@ -16,6 +16,7 @@ public: virtual ~ClientListener() {} virtual void NotifyUpdateAvailable(Client * sender) {} + virtual void NotifyAuthUserChanged(Client * sender) {} }; |
