mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-28 10:20:04 +02:00
Graphics:: Extra icons for Report and Favourite. Client:: Get favourite status in GetSave, FavouriteSave, ReportSave, Preview:: Failure state when loading save
This commit is contained in:
@@ -1190,9 +1190,14 @@ void Graphics::draw_icon(int x, int y, Icon icon)
|
|||||||
case IconPause:
|
case IconPause:
|
||||||
drawchar(x, y, 0x90, 255, 255, 255, 255);
|
drawchar(x, y, 0x90, 255, 255, 255, 255);
|
||||||
break;
|
break;
|
||||||
|
case IconReport:
|
||||||
|
drawchar(x, y, 0xE3, 255, 255, 0, 255);
|
||||||
|
break;
|
||||||
|
case IconFavourite:
|
||||||
|
drawchar(x, y, 0xCC, 192, 160, 64, 255);
|
||||||
|
break;
|
||||||
case IconVoteSort:
|
case IconVoteSort:
|
||||||
case IconDateSort:
|
case IconDateSort:
|
||||||
case IconFavourite:
|
|
||||||
case IconFolder:
|
case IconFolder:
|
||||||
case IconSearch:
|
case IconSearch:
|
||||||
case IconDelete:
|
case IconDelete:
|
||||||
|
@@ -72,7 +72,8 @@ enum Icon
|
|||||||
IconFavourite,
|
IconFavourite,
|
||||||
IconFolder,
|
IconFolder,
|
||||||
IconSearch,
|
IconSearch,
|
||||||
IconDelete
|
IconDelete,
|
||||||
|
IconReport
|
||||||
};
|
};
|
||||||
|
|
||||||
class Graphics
|
class Graphics
|
||||||
|
@@ -57,6 +57,14 @@ Client::Client():
|
|||||||
authUser.SessionID = ((json::String)(configDocument["User"]["SessionID"])).Value();
|
authUser.SessionID = ((json::String)(configDocument["User"]["SessionID"])).Value();
|
||||||
authUser.SessionKey = ((json::String)(configDocument["User"]["SessionKey"])).Value();
|
authUser.SessionKey = ((json::String)(configDocument["User"]["SessionKey"])).Value();
|
||||||
authUser.Username = ((json::String)(configDocument["User"]["Username"])).Value();
|
authUser.Username = ((json::String)(configDocument["User"]["Username"])).Value();
|
||||||
|
|
||||||
|
std::string userElevation = ((json::String)(configDocument["User"]["Elevation"])).Value();
|
||||||
|
if(userElevation == "Admin")
|
||||||
|
authUser.UserElevation = ElevationAdmin;
|
||||||
|
else if(userElevation == "Mod")
|
||||||
|
authUser.UserElevation = ElevationModerator;
|
||||||
|
else
|
||||||
|
authUser.UserElevation= ElevationNone;
|
||||||
}
|
}
|
||||||
catch (json::Exception &e)
|
catch (json::Exception &e)
|
||||||
{
|
{
|
||||||
@@ -117,6 +125,12 @@ Client::~Client()
|
|||||||
configDocument["User"]["SessionID"] = json::String(authUser.SessionID);
|
configDocument["User"]["SessionID"] = json::String(authUser.SessionID);
|
||||||
configDocument["User"]["SessionKey"] = json::String(authUser.SessionKey);
|
configDocument["User"]["SessionKey"] = json::String(authUser.SessionKey);
|
||||||
configDocument["User"]["Username"] = json::String(authUser.Username);
|
configDocument["User"]["Username"] = json::String(authUser.Username);
|
||||||
|
if(authUser.UserElevation == ElevationAdmin)
|
||||||
|
configDocument["User"]["Elevation"] = json::String("Admin");
|
||||||
|
else if(authUser.UserElevation == ElevationModerator)
|
||||||
|
configDocument["User"]["Elevation"] = json::String("Mod");
|
||||||
|
else
|
||||||
|
configDocument["User"]["Elevation"] = json::String("None");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -402,10 +416,18 @@ LoginStatus Client::Login(string username, string password, User & user)
|
|||||||
json::Number userIDTemp = objDocument["UserID"];
|
json::Number userIDTemp = objDocument["UserID"];
|
||||||
json::String sessionIDTemp = objDocument["SessionID"];
|
json::String sessionIDTemp = objDocument["SessionID"];
|
||||||
json::String sessionKeyTemp = objDocument["SessionKey"];
|
json::String sessionKeyTemp = objDocument["SessionKey"];
|
||||||
|
json::String userElevationTemp = objDocument["Elevation"];
|
||||||
user.Username = username;
|
user.Username = username;
|
||||||
user.ID = userIDTemp.Value();
|
user.ID = userIDTemp.Value();
|
||||||
user.SessionID = sessionIDTemp.Value();
|
user.SessionID = sessionIDTemp.Value();
|
||||||
user.SessionKey = sessionKeyTemp.Value();
|
user.SessionKey = sessionKeyTemp.Value();
|
||||||
|
std::string userElevation = userElevationTemp.Value();
|
||||||
|
if(userElevation == "Admin")
|
||||||
|
user.UserElevation = ElevationAdmin;
|
||||||
|
else if(userElevation == "Mod")
|
||||||
|
user.UserElevation = ElevationModerator;
|
||||||
|
else
|
||||||
|
user.UserElevation= ElevationNone;
|
||||||
return LoginOkay;
|
return LoginOkay;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -439,7 +461,175 @@ RequestStatus Client::DeleteSave(int saveID)
|
|||||||
std::stringstream urlStream;
|
std::stringstream urlStream;
|
||||||
char * data = NULL;
|
char * data = NULL;
|
||||||
int dataStatus, dataLength;
|
int dataStatus, dataLength;
|
||||||
urlStream << "http://" << SERVER << "/Browse/Delete.json?ID=" << saveID;
|
urlStream << "http://" << SERVER << "/Browse/Delete.json?ID=" << saveID << "&Mode=Delete&Key=" << authUser.SessionKey;
|
||||||
|
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 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)
|
||||||
|
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 = "";
|
||||||
|
std::vector<string> * tags = NULL;
|
||||||
|
std::stringstream urlStream;
|
||||||
|
char * data = NULL;
|
||||||
|
int dataStatus, dataLength;
|
||||||
|
urlStream << "http://" << SERVER << "/Browse/Favourite.json?ID=" << saveID << "&Key=" << authUser.SessionKey;
|
||||||
|
if(!favourite)
|
||||||
|
urlStream << "&Mode=Remove";
|
||||||
|
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 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::String)objDocument["Error"]).Value();
|
||||||
|
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::ReportSave(int saveID, std::string message)
|
||||||
|
{
|
||||||
|
lastError = "";
|
||||||
|
std::vector<string> * tags = NULL;
|
||||||
|
std::stringstream urlStream;
|
||||||
|
char * data = NULL;
|
||||||
|
int dataStatus, dataLength;
|
||||||
|
urlStream << "http://" << SERVER << "/Browse/Report.json?ID=" << saveID << "&Key=" << authUser.SessionKey;
|
||||||
|
if(authUser.ID)
|
||||||
|
{
|
||||||
|
std::stringstream userIDStream;
|
||||||
|
userIDStream << authUser.ID;
|
||||||
|
|
||||||
|
char * postNames[] = { "Reason", NULL };
|
||||||
|
char * postDatas[] = { (char*)(message.c_str()) };
|
||||||
|
int postLengths[] = { message.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::String)objDocument["Error"]).Value();
|
||||||
|
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::UnpublishSave(int saveID)
|
||||||
|
{
|
||||||
|
lastError = "";
|
||||||
|
std::vector<string> * tags = NULL;
|
||||||
|
std::stringstream urlStream;
|
||||||
|
char * data = NULL;
|
||||||
|
int dataStatus, dataLength;
|
||||||
|
urlStream << "http://" << SERVER << "/Browse/Delete.json?ID=" << saveID << "&Mode=Unpublish&Key=" << authUser.SessionKey;
|
||||||
if(authUser.ID)
|
if(authUser.ID)
|
||||||
{
|
{
|
||||||
std::stringstream userIDStream;
|
std::stringstream userIDStream;
|
||||||
@@ -523,6 +713,7 @@ Save * Client::GetSave(int saveID, int saveDate)
|
|||||||
json::String tempDescription = objDocument["Description"];
|
json::String tempDescription = objDocument["Description"];
|
||||||
json::Number tempDate = objDocument["Date"];
|
json::Number tempDate = objDocument["Date"];
|
||||||
json::Boolean tempPublished = objDocument["Published"];
|
json::Boolean tempPublished = objDocument["Published"];
|
||||||
|
json::Boolean tempFavourite = objDocument["Favourite"];
|
||||||
|
|
||||||
json::Array tagsArray = objDocument["Tags"];
|
json::Array tagsArray = objDocument["Tags"];
|
||||||
vector<string> tempTags;
|
vector<string> tempTags;
|
||||||
@@ -533,7 +724,7 @@ Save * Client::GetSave(int saveID, int saveDate)
|
|||||||
tempTags.push_back(tempTag.Value());
|
tempTags.push_back(tempTag.Value());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Save(
|
Save * tempSave = new Save(
|
||||||
tempID.Value(),
|
tempID.Value(),
|
||||||
tempDate.Value(),
|
tempDate.Value(),
|
||||||
tempScoreUp.Value(),
|
tempScoreUp.Value(),
|
||||||
@@ -545,6 +736,8 @@ Save * Client::GetSave(int saveID, int saveDate)
|
|||||||
tempPublished.Value(),
|
tempPublished.Value(),
|
||||||
tempTags
|
tempTags
|
||||||
);
|
);
|
||||||
|
tempSave->Favourite = tempFavourite.Value();
|
||||||
|
return tempSave;
|
||||||
}
|
}
|
||||||
catch (json::Exception &e)
|
catch (json::Exception &e)
|
||||||
{
|
{
|
||||||
@@ -597,8 +790,8 @@ Thumbnail * Client::GetPreview(int saveID, int saveDate)
|
|||||||
{
|
{
|
||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
return new Thumbnail(saveID, saveDate, (pixel *)malloc((128*128) * PIXELSIZE), ui::Point(128, 128));
|
|
||||||
}
|
}
|
||||||
|
return new Thumbnail(saveID, saveDate, (pixel *)malloc((128*128) * PIXELSIZE), ui::Point(128, 128));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Comment*> * Client::GetComments(int saveID, int start, int count)
|
std::vector<Comment*> * Client::GetComments(int saveID, int start, int count)
|
||||||
@@ -856,7 +1049,7 @@ std::vector<string> * Client::RemoveTag(int saveID, string tag)
|
|||||||
std::stringstream urlStream;
|
std::stringstream urlStream;
|
||||||
char * data = NULL;
|
char * data = NULL;
|
||||||
int dataStatus, dataLength;
|
int dataStatus, dataLength;
|
||||||
urlStream << "http://" << SERVER << "/Browse/EditTag.json?Op=delete&ID=" << saveID << "&Tag=" << tag;
|
urlStream << "http://" << SERVER << "/Browse/EditTag.json?Op=delete&ID=" << saveID << "&Tag=" << tag << "&Key=" << authUser.SessionKey;;
|
||||||
if(authUser.ID)
|
if(authUser.ID)
|
||||||
{
|
{
|
||||||
std::stringstream userIDStream;
|
std::stringstream userIDStream;
|
||||||
@@ -905,7 +1098,7 @@ std::vector<string> * Client::AddTag(int saveID, string tag)
|
|||||||
std::stringstream urlStream;
|
std::stringstream urlStream;
|
||||||
char * data = NULL;
|
char * data = NULL;
|
||||||
int dataStatus, dataLength;
|
int dataStatus, dataLength;
|
||||||
urlStream << "http://" << SERVER << "/Browse/EditTag.json?Op=add&ID=" << saveID << "&Tag=" << tag;
|
urlStream << "http://" << SERVER << "/Browse/EditTag.json?Op=add&ID=" << saveID << "&Tag=" << tag << "&Key=" << authUser.SessionKey;
|
||||||
if(authUser.ID)
|
if(authUser.ID)
|
||||||
{
|
{
|
||||||
std::stringstream userIDStream;
|
std::stringstream userIDStream;
|
||||||
|
@@ -68,6 +68,9 @@ public:
|
|||||||
Thumbnail * GetThumbnail(int saveID, int saveDate);
|
Thumbnail * GetThumbnail(int saveID, int saveDate);
|
||||||
Save * GetSave(int saveID, int saveDate);
|
Save * GetSave(int saveID, int saveDate);
|
||||||
RequestStatus DeleteSave(int saveID);
|
RequestStatus DeleteSave(int saveID);
|
||||||
|
RequestStatus ReportSave(int saveID, std::string message);
|
||||||
|
RequestStatus UnpublishSave(int saveID);
|
||||||
|
RequestStatus FavouriteSave(int saveID, bool favourite);
|
||||||
void SetAuthUser(User user);
|
void SetAuthUser(User user);
|
||||||
User GetAuthUser();
|
User GetAuthUser();
|
||||||
std::vector<string> * RemoveTag(int saveID, string tag); //TODO RequestStatus
|
std::vector<string> * RemoveTag(int saveID, string tag); //TODO RequestStatus
|
||||||
|
@@ -16,7 +16,6 @@ class TextPrompt: public ui::Window {
|
|||||||
protected:
|
protected:
|
||||||
ui::Textbox * textField;
|
ui::Textbox * textField;
|
||||||
public:
|
public:
|
||||||
//class CloseAction;
|
|
||||||
friend class CloseAction;
|
friend class CloseAction;
|
||||||
enum DialogueResult { ResultCancel, ResultOkay };
|
enum DialogueResult { ResultCancel, ResultOkay };
|
||||||
TextPrompt(std::string title, std::string message, bool multiline, TextDialogueCallback * callback_);
|
TextPrompt(std::string title, std::string message, bool multiline, TextDialogueCallback * callback_);
|
||||||
|
@@ -6,13 +6,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include "client/Client.h"
|
||||||
#include "PreviewController.h"
|
#include "PreviewController.h"
|
||||||
#include "PreviewView.h"
|
#include "PreviewView.h"
|
||||||
#include "PreviewModel.h"
|
#include "PreviewModel.h"
|
||||||
|
#include "PreviewModelException.h"
|
||||||
|
#include "dialogues/ErrorMessage.h"
|
||||||
#include "Controller.h"
|
#include "Controller.h"
|
||||||
|
|
||||||
PreviewController::PreviewController(int saveID, ControllerCallback * callback):
|
PreviewController::PreviewController(int saveID, ControllerCallback * callback):
|
||||||
HasExited(false)
|
HasExited(false),
|
||||||
|
saveId(saveID)
|
||||||
{
|
{
|
||||||
previewModel = new PreviewModel();
|
previewModel = new PreviewModel();
|
||||||
previewView = new PreviewView();
|
previewView = new PreviewView();
|
||||||
@@ -26,7 +30,14 @@ PreviewController::PreviewController(int saveID, ControllerCallback * callback):
|
|||||||
|
|
||||||
void PreviewController::Update()
|
void PreviewController::Update()
|
||||||
{
|
{
|
||||||
previewModel->Update();
|
try
|
||||||
|
{
|
||||||
|
previewModel->Update();
|
||||||
|
}
|
||||||
|
catch (PreviewModelException & e)
|
||||||
|
{
|
||||||
|
new ErrorMessage("Error", e.what());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Save * PreviewController::GetSave()
|
Save * PreviewController::GetSave()
|
||||||
@@ -44,6 +55,22 @@ void PreviewController::DoOpen()
|
|||||||
previewModel->SetDoOpen(true);
|
previewModel->SetDoOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PreviewController::Report(std::string message)
|
||||||
|
{
|
||||||
|
if(Client::Ref().ReportSave(saveId, message) == RequestOkay)
|
||||||
|
{
|
||||||
|
Exit();
|
||||||
|
new ErrorMessage("Information", "Report submitted"); //TODO: InfoMessage
|
||||||
|
}
|
||||||
|
else
|
||||||
|
new ErrorMessage("Error", "Unable file report");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewController::FavouriteSave()
|
||||||
|
{
|
||||||
|
previewModel->SetFavourite(true);
|
||||||
|
}
|
||||||
|
|
||||||
void PreviewController::OpenInBrowser()
|
void PreviewController::OpenInBrowser()
|
||||||
{
|
{
|
||||||
if(previewModel->GetSave())
|
if(previewModel->GetSave())
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
class PreviewModel;
|
class PreviewModel;
|
||||||
class PreviewView;
|
class PreviewView;
|
||||||
class PreviewController {
|
class PreviewController {
|
||||||
|
int saveId;
|
||||||
PreviewModel * previewModel;
|
PreviewModel * previewModel;
|
||||||
PreviewView * previewView;
|
PreviewView * previewView;
|
||||||
ControllerCallback * callback;
|
ControllerCallback * callback;
|
||||||
@@ -25,10 +26,12 @@ public:
|
|||||||
void Exit();
|
void Exit();
|
||||||
void DoOpen();
|
void DoOpen();
|
||||||
void OpenInBrowser();
|
void OpenInBrowser();
|
||||||
|
void Report(std::string message);
|
||||||
bool GetDoOpen();
|
bool GetDoOpen();
|
||||||
Save * GetSave();
|
Save * GetSave();
|
||||||
PreviewView * GetView() { return previewView; }
|
PreviewView * GetView() { return previewView; }
|
||||||
void Update();
|
void Update();
|
||||||
|
void FavouriteSave();
|
||||||
virtual ~PreviewController();
|
virtual ~PreviewController();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "PreviewModel.h"
|
#include "PreviewModel.h"
|
||||||
#include "client/Client.h"
|
#include "client/Client.h"
|
||||||
|
#include "PreviewModelException.h"
|
||||||
|
|
||||||
PreviewModel::PreviewModel():
|
PreviewModel::PreviewModel():
|
||||||
save(NULL),
|
save(NULL),
|
||||||
@@ -60,6 +61,16 @@ void * PreviewModel::updateSaveCommentsT()
|
|||||||
return tempComments;
|
return tempComments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PreviewModel::SetFavourite(bool favourite)
|
||||||
|
{
|
||||||
|
//if(save)
|
||||||
|
{
|
||||||
|
Client::Ref().FavouriteSave(save->id, favourite);
|
||||||
|
save->Favourite = favourite;
|
||||||
|
notifySaveChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PreviewModel::UpdateSave(int saveID, int saveDate)
|
void PreviewModel::UpdateSave(int saveID, int saveDate)
|
||||||
{
|
{
|
||||||
this->tSaveID = saveID;
|
this->tSaveID = saveID;
|
||||||
@@ -192,6 +203,8 @@ void PreviewModel::Update()
|
|||||||
updateSaveInfoWorking = false;
|
updateSaveInfoWorking = false;
|
||||||
pthread_join(updateSaveInfoThread, (void**)(&save));
|
pthread_join(updateSaveInfoThread, (void**)(&save));
|
||||||
notifySaveChanged();
|
notifySaveChanged();
|
||||||
|
if(!save)
|
||||||
|
throw PreviewModelException("Unable to load save");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -56,6 +56,7 @@ public:
|
|||||||
std::vector<Comment*> * GetComments();
|
std::vector<Comment*> * GetComments();
|
||||||
void AddObserver(PreviewView * observer);
|
void AddObserver(PreviewView * observer);
|
||||||
void UpdateSave(int saveID, int saveDate);
|
void UpdateSave(int saveID, int saveDate);
|
||||||
|
void SetFavourite(bool favourite);
|
||||||
bool GetDoOpen();
|
bool GetDoOpen();
|
||||||
void SetDoOpen(bool doOpen);
|
void SetDoOpen(bool doOpen);
|
||||||
void Update();
|
void Update();
|
||||||
|
26
src/preview/PreviewModelException.h
Normal file
26
src/preview/PreviewModelException.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* PreviewModelException.h
|
||||||
|
*
|
||||||
|
* Created on: Apr 14, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PREVIEWMODELEXCEPTION_H_
|
||||||
|
#define PREVIEWMODELEXCEPTION_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <exception>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
struct PreviewModelException: public exception {
|
||||||
|
string message;
|
||||||
|
public:
|
||||||
|
PreviewModelException(string message_): message(message_) {}
|
||||||
|
const char * what() const throw()
|
||||||
|
{
|
||||||
|
return message.c_str();
|
||||||
|
}
|
||||||
|
~PreviewModelException() throw() {};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* PREVIEWMODELEXCEPTION_H_ */
|
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "PreviewView.h"
|
#include "PreviewView.h"
|
||||||
|
#include "dialogues/TextPrompt.h"
|
||||||
#include "interface/Point.h"
|
#include "interface/Point.h"
|
||||||
#include "interface/Window.h"
|
#include "interface/Window.h"
|
||||||
#include "search/Thumbnail.h"
|
#include "search/Thumbnail.h"
|
||||||
@@ -32,6 +33,50 @@ PreviewView::PreviewView():
|
|||||||
openButton->SetActionCallback(new OpenAction(this));
|
openButton->SetActionCallback(new OpenAction(this));
|
||||||
AddComponent(openButton);
|
AddComponent(openButton);
|
||||||
|
|
||||||
|
class FavAction: public ui::ButtonAction
|
||||||
|
{
|
||||||
|
PreviewView * v;
|
||||||
|
public:
|
||||||
|
FavAction(PreviewView * v_){ v = v_; }
|
||||||
|
virtual void ActionCallback(ui::Button * sender)
|
||||||
|
{
|
||||||
|
v->c->FavouriteSave();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
favButton = new ui::Button(ui::Point(50, Size.Y-16), ui::Point(50, 16), "Fav.");
|
||||||
|
favButton->SetAlignment(AlignLeft, AlignMiddle);
|
||||||
|
favButton->SetIcon(IconFavourite);
|
||||||
|
favButton->SetActionCallback(new FavAction(this));
|
||||||
|
AddComponent(favButton);
|
||||||
|
|
||||||
|
class ReportPromptCallback: public TextDialogueCallback {
|
||||||
|
public:
|
||||||
|
PreviewView * v;
|
||||||
|
ReportPromptCallback(PreviewView * v_) { v = v_; }
|
||||||
|
virtual void TextCallback(TextPrompt::DialogueResult result, std::string resultText) {
|
||||||
|
if (result == TextPrompt::ResultOkay)
|
||||||
|
v->c->Report(resultText);
|
||||||
|
}
|
||||||
|
virtual ~ReportPromptCallback() { }
|
||||||
|
};
|
||||||
|
|
||||||
|
class ReportAction: public ui::ButtonAction
|
||||||
|
{
|
||||||
|
PreviewView * v;
|
||||||
|
public:
|
||||||
|
ReportAction(PreviewView * v_){ v = v_; }
|
||||||
|
virtual void ActionCallback(ui::Button * sender)
|
||||||
|
{
|
||||||
|
new TextPrompt("Report Save", "Reason for reporting", true, new ReportPromptCallback(v));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
reportButton = new ui::Button(ui::Point(100, Size.Y-16), ui::Point(50, 16), "Report");
|
||||||
|
reportButton->SetAlignment(AlignLeft, AlignMiddle);
|
||||||
|
reportButton->SetIcon(IconReport);
|
||||||
|
reportButton->SetActionCallback(new ReportAction(this));
|
||||||
|
AddComponent(reportButton);
|
||||||
|
|
||||||
class BrowserOpenAction: public ui::ButtonAction
|
class BrowserOpenAction: public ui::ButtonAction
|
||||||
{
|
{
|
||||||
PreviewView * v;
|
PreviewView * v;
|
||||||
@@ -42,7 +87,8 @@ PreviewView::PreviewView():
|
|||||||
v->c->OpenInBrowser();
|
v->c->OpenInBrowser();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
browserOpenButton = new ui::Button(ui::Point((XRES/2)-90, Size.Y-16), ui::Point(90, 16), "Open in browser");
|
|
||||||
|
browserOpenButton = new ui::Button(ui::Point((XRES/2)-110, Size.Y-16), ui::Point(110, 16), "Open in browser");
|
||||||
browserOpenButton->SetAlignment(AlignLeft, AlignMiddle);
|
browserOpenButton->SetAlignment(AlignLeft, AlignMiddle);
|
||||||
browserOpenButton->SetIcon(IconOpen);
|
browserOpenButton->SetIcon(IconOpen);
|
||||||
browserOpenButton->SetActionCallback(new BrowserOpenAction(this));
|
browserOpenButton->SetActionCallback(new BrowserOpenAction(this));
|
||||||
@@ -114,6 +160,10 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender)
|
|||||||
saveNameLabel->SetText(save->name);
|
saveNameLabel->SetText(save->name);
|
||||||
authorDateLabel->SetText("\bgAuthor:\bw " + save->userName + " \bgDate:\bw ");
|
authorDateLabel->SetText("\bgAuthor:\bw " + save->userName + " \bgDate:\bw ");
|
||||||
saveDescriptionTextblock->SetText(save->Description);
|
saveDescriptionTextblock->SetText(save->Description);
|
||||||
|
if(save->Favourite)
|
||||||
|
favButton->Enabled = false;
|
||||||
|
else
|
||||||
|
favButton->Enabled = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -122,6 +172,7 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender)
|
|||||||
saveNameLabel->SetText("");
|
saveNameLabel->SetText("");
|
||||||
authorDateLabel->SetText("");
|
authorDateLabel->SetText("");
|
||||||
saveDescriptionTextblock->SetText("");
|
saveDescriptionTextblock->SetText("");
|
||||||
|
favButton->Enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,6 +24,8 @@ class PreviewView: public ui::Window {
|
|||||||
Thumbnail * savePreview;
|
Thumbnail * savePreview;
|
||||||
ui::Button * openButton;
|
ui::Button * openButton;
|
||||||
ui::Button * browserOpenButton;
|
ui::Button * browserOpenButton;
|
||||||
|
ui::Button * favButton;
|
||||||
|
ui::Button * reportButton;
|
||||||
ui::Label * saveNameLabel;
|
ui::Label * saveNameLabel;
|
||||||
ui::Label * authorDateLabel;
|
ui::Label * authorDateLabel;
|
||||||
ui::Textblock * saveDescriptionTextblock;
|
ui::Textblock * saveDescriptionTextblock;
|
||||||
|
@@ -18,6 +18,7 @@ public:
|
|||||||
int votesUp, votesDown;
|
int votesUp, votesDown;
|
||||||
unsigned char * data;
|
unsigned char * data;
|
||||||
int dataLength;
|
int dataLength;
|
||||||
|
bool Favourite;
|
||||||
|
|
||||||
Save(Save & save);
|
Save(Save & save);
|
||||||
|
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
#include "SearchView.h"
|
#include "SearchView.h"
|
||||||
#include "interface/Panel.h"
|
#include "interface/Panel.h"
|
||||||
#include "dialogues/ConfirmPrompt.h"
|
#include "dialogues/ConfirmPrompt.h"
|
||||||
|
#include "dialogues/ErrorMessage.h"
|
||||||
#include "preview/PreviewController.h"
|
#include "preview/PreviewController.h"
|
||||||
#include "client/Client.h"
|
#include "client/Client.h"
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
@@ -206,15 +207,58 @@ void SearchController::removeSelectedC()
|
|||||||
|
|
||||||
void SearchController::UnpublishSelected()
|
void SearchController::UnpublishSelected()
|
||||||
{
|
{
|
||||||
|
class UnpublishSelectedConfirmation: public ConfirmDialogueCallback {
|
||||||
|
public:
|
||||||
|
SearchController * c;
|
||||||
|
UnpublishSelectedConfirmation(SearchController * c_) { c = c_; }
|
||||||
|
virtual void ConfirmCallback(ConfirmPrompt::DialogueResult result) {
|
||||||
|
if (result == ConfirmPrompt::ResultOkay)
|
||||||
|
c->unpublishSelectedC();
|
||||||
|
}
|
||||||
|
virtual ~UnpublishSelectedConfirmation() { }
|
||||||
|
};
|
||||||
|
|
||||||
|
std::stringstream desc;
|
||||||
|
desc << "Are you sure you want to hide " << searchModel->GetSelected().size() << " save";
|
||||||
|
if(searchModel->GetSelected().size()>1)
|
||||||
|
desc << "s";
|
||||||
|
new ConfirmPrompt("Unpublish saves", desc.str(), new UnpublishSelectedConfirmation(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::unpublishSelectedC()
|
void SearchController::unpublishSelectedC()
|
||||||
{
|
{
|
||||||
|
class UnpublishSavesTask : public Task
|
||||||
|
{
|
||||||
|
std::vector<int> saves;
|
||||||
|
public:
|
||||||
|
UnpublishSavesTask(std::vector<int> saves_) { saves = saves_; }
|
||||||
|
virtual void doWork()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < saves.size(); i++)
|
||||||
|
{
|
||||||
|
std::stringstream saveID;
|
||||||
|
saveID << "Hiding save [" << saves[i] << "] ...";
|
||||||
|
notifyStatus(saveID.str());
|
||||||
|
if(Client::Ref().UnpublishSave(saves[i])!=RequestOkay)
|
||||||
|
{
|
||||||
|
std::stringstream saveIDF;
|
||||||
|
saveIDF << "\boFailed to hide [" << saves[i] << "] ...";
|
||||||
|
notifyStatus(saveIDF.str());
|
||||||
|
usleep(500*1000);
|
||||||
|
}
|
||||||
|
usleep(100*1000);
|
||||||
|
notifyProgress((float(i+1)/float(saves.size())*100));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<int> selected = searchModel->GetSelected();
|
||||||
|
new TaskWindow("Unpublishing saves", new UnpublishSavesTask(selected));
|
||||||
ClearSelection();
|
ClearSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::FavouriteSelected()
|
void SearchController::FavouriteSelected()
|
||||||
{
|
{
|
||||||
|
new ErrorMessage("Not impletemented", "Not ermplermerterd");
|
||||||
ClearSelection();
|
ClearSelection();
|
||||||
}
|
}
|
||||||
|
@@ -163,6 +163,25 @@ SearchView::SearchView():
|
|||||||
clearSelection->Visible = false;
|
clearSelection->Visible = false;
|
||||||
clearSelection->SetActionCallback(new ClearSelectionAction(this));
|
clearSelection->SetActionCallback(new ClearSelectionAction(this));
|
||||||
AddComponent(clearSelection);
|
AddComponent(clearSelection);
|
||||||
|
|
||||||
|
if(Client::Ref().GetAuthUser().ID)
|
||||||
|
{
|
||||||
|
favouriteSelected->Enabled = true;
|
||||||
|
if((Client::Ref().GetAuthUser().UserElevation == ElevationAdmin || Client::Ref().GetAuthUser().UserElevation == ElevationModerator))
|
||||||
|
{
|
||||||
|
unpublishSelected->Enabled = true;
|
||||||
|
removeSelected->Enabled = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unpublishSelected->Enabled = false;
|
||||||
|
removeSelected->Enabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
favouriteSelected->Enabled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchView::doSearch()
|
void SearchView::doSearch()
|
||||||
@@ -182,6 +201,16 @@ void SearchView::NotifySortChanged(SearchModel * sender)
|
|||||||
void SearchView::NotifyShowOwnChanged(SearchModel * sender)
|
void SearchView::NotifyShowOwnChanged(SearchModel * sender)
|
||||||
{
|
{
|
||||||
ownButton->SetToggleState(sender->GetShowOwn());
|
ownButton->SetToggleState(sender->GetShowOwn());
|
||||||
|
if(sender->GetShowOwn() || Client::Ref().GetAuthUser().UserElevation == ElevationAdmin || Client::Ref().GetAuthUser().UserElevation == ElevationModerator)
|
||||||
|
{
|
||||||
|
unpublishSelected->Enabled = true;
|
||||||
|
removeSelected->Enabled = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unpublishSelected->Enabled = false;
|
||||||
|
removeSelected->Enabled = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchView::NotifyPageChanged(SearchModel * sender)
|
void SearchView::NotifyPageChanged(SearchModel * sender)
|
||||||
@@ -233,6 +262,7 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
|
|||||||
}
|
}
|
||||||
if(!saves.size())
|
if(!saves.size())
|
||||||
{
|
{
|
||||||
|
loadingSpinner->Visible = false;
|
||||||
if(!errorLabel)
|
if(!errorLabel)
|
||||||
{
|
{
|
||||||
errorLabel = new ui::Label(ui::Point(((XRES+BARSIZE)/2)-100, ((YRES+MENUSIZE)/2)-6), ui::Point(200, 12), "Error");
|
errorLabel = new ui::Label(ui::Point(((XRES+BARSIZE)/2)-100, ((YRES+MENUSIZE)/2)-6), ui::Point(200, 12), "Error");
|
||||||
|
Reference in New Issue
Block a user