Publish button in browser (replaces Unpublish button when unpublished saves are selected)
Works using the html page and isn't really the best way until @simtr implements Delete.json&Mode=Publish or something
This commit is contained in:
parent
1a50217acd
commit
b2954a7f0a
@ -1676,6 +1676,36 @@ failure:
|
||||
return RequestFailure;
|
||||
}
|
||||
|
||||
RequestStatus Client::PublishSave(int saveID)
|
||||
{
|
||||
lastError = "";
|
||||
std::stringstream urlStream;
|
||||
int dataStatus;
|
||||
urlStream << "http://" << SERVER << "/Browse/View.html?ID=" << saveID << "&Key=" << authUser.SessionKey;
|
||||
if (authUser.ID)
|
||||
{
|
||||
std::stringstream userIDStream;
|
||||
userIDStream << authUser.ID;
|
||||
const char *const postNames[] = { "ActionPublish", NULL };
|
||||
const char *const postDatas[] = { "" };
|
||||
int postLengths[] = { 1 };
|
||||
char *data = http_multipart_post(urlStream.str().c_str(), postNames, postDatas, postLengths, userIDStream.str().c_str(), NULL, authUser.SessionID.c_str(), &dataStatus, NULL);
|
||||
if (data)
|
||||
free(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
lastError = "Not authenticated";
|
||||
return RequestFailure;
|
||||
}
|
||||
if (dataStatus != 302)
|
||||
{
|
||||
lastError = http_ret_text(dataStatus);
|
||||
return RequestFailure;
|
||||
}
|
||||
return RequestOkay;
|
||||
}
|
||||
|
||||
SaveInfo * Client::GetSave(int saveID, int saveDate)
|
||||
{
|
||||
lastError = "";
|
||||
|
@ -157,6 +157,7 @@ public:
|
||||
RequestStatus DeleteSave(int saveID);
|
||||
RequestStatus ReportSave(int saveID, std::string message);
|
||||
RequestStatus UnpublishSave(int saveID);
|
||||
RequestStatus PublishSave(int saveID);
|
||||
RequestStatus FavouriteSave(int saveID, bool favourite);
|
||||
void SetAuthUser(User user);
|
||||
User GetAuthUser();
|
||||
|
@ -269,6 +269,8 @@ void SearchController::removeSelectedC()
|
||||
std::stringstream saveIDF;
|
||||
saveIDF << "\boFailed to delete [" << saves[i] << "] ...";
|
||||
notifyStatus(saveIDF.str());
|
||||
c->Refresh();
|
||||
return false;
|
||||
}
|
||||
notifyProgress((float(i+1)/float(saves.size())*100));
|
||||
}
|
||||
@ -283,47 +285,73 @@ void SearchController::removeSelectedC()
|
||||
searchModel->UpdateSaveList(searchModel->GetPageNum(), searchModel->GetLastQuery());
|
||||
}
|
||||
|
||||
void SearchController::UnpublishSelected()
|
||||
void SearchController::UnpublishSelected(bool publish)
|
||||
{
|
||||
class UnpublishSelectedConfirmation: public ConfirmDialogueCallback {
|
||||
public:
|
||||
SearchController * c;
|
||||
UnpublishSelectedConfirmation(SearchController * c_) { c = c_; }
|
||||
bool publish;
|
||||
UnpublishSelectedConfirmation(SearchController * c_, bool publish_) { c = c_; publish = publish_; }
|
||||
virtual void ConfirmCallback(ConfirmPrompt::DialogueResult result) {
|
||||
if (result == ConfirmPrompt::ResultOkay)
|
||||
c->unpublishSelectedC();
|
||||
c->unpublishSelectedC(publish);
|
||||
}
|
||||
virtual ~UnpublishSelectedConfirmation() { }
|
||||
};
|
||||
|
||||
std::stringstream desc;
|
||||
desc << "Are you sure you want to hide " << searchModel->GetSelected().size() << " save";
|
||||
desc << "Are you sure you want to " << (publish ? "publish " : "unpublish ") << searchModel->GetSelected().size() << " save";
|
||||
if(searchModel->GetSelected().size()>1)
|
||||
desc << "s";
|
||||
desc << "?";
|
||||
new ConfirmPrompt("Unpublish saves", desc.str(), new UnpublishSelectedConfirmation(this));
|
||||
new ConfirmPrompt((publish ? "Publish Saves" : "Unpublish Saves"), desc.str(), new UnpublishSelectedConfirmation(this, publish));
|
||||
}
|
||||
|
||||
void SearchController::unpublishSelectedC()
|
||||
void SearchController::unpublishSelectedC(bool publish)
|
||||
{
|
||||
class UnpublishSavesTask : public Task
|
||||
{
|
||||
std::vector<int> saves;
|
||||
SearchController *c;
|
||||
bool publish;
|
||||
public:
|
||||
UnpublishSavesTask(std::vector<int> saves_, SearchController *c_) { saves = saves_; c = c_; }
|
||||
UnpublishSavesTask(std::vector<int> saves_, SearchController *c_, bool publish_) { saves = saves_; c = c_; publish = publish_; }
|
||||
|
||||
bool PublishSave(int saveID)
|
||||
{
|
||||
std::stringstream message;
|
||||
message << "Publishing save [" << saveID << "]";
|
||||
notifyStatus(message.str());
|
||||
if (Client::Ref().PublishSave(saveID) != RequestOkay)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnpublishSave(int saveID)
|
||||
{
|
||||
std::stringstream message;
|
||||
message << "Unpublishing save [" << saveID << "]";
|
||||
notifyStatus(message.str());
|
||||
if (Client::Ref().UnpublishSave(saveID) != RequestOkay)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool doWork()
|
||||
{
|
||||
bool ret;
|
||||
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)
|
||||
if (publish)
|
||||
ret = PublishSave(saves[i]);
|
||||
else
|
||||
ret = UnpublishSave(saves[i]);
|
||||
if (!ret)
|
||||
{
|
||||
std::stringstream saveIDF;
|
||||
saveIDF << "\boFailed to hide [" << saves[i] << "], is this save yours?";
|
||||
notifyError(saveIDF.str());
|
||||
std::stringstream error;
|
||||
error << "\boFailed to " << (publish ? "Publish" : "Unpublish") << " [" << saves[i] << "], is this save yours?";
|
||||
notifyError(error.str());
|
||||
c->Refresh();
|
||||
return false;
|
||||
}
|
||||
notifyProgress((float(i+1)/float(saves.size())*100));
|
||||
@ -334,7 +362,7 @@ void SearchController::unpublishSelectedC()
|
||||
};
|
||||
|
||||
std::vector<int> selected = searchModel->GetSelected();
|
||||
new TaskWindow("Unpublishing saves", new UnpublishSavesTask(selected, this));
|
||||
new TaskWindow((publish ? "Publishing Saves" : "Unpublishing Saves"), new UnpublishSavesTask(selected, this, publish));
|
||||
}
|
||||
|
||||
void SearchController::FavouriteSelected()
|
||||
|
@ -24,7 +24,7 @@ private:
|
||||
bool instantOpen;
|
||||
bool doRefresh;
|
||||
void removeSelectedC();
|
||||
void unpublishSelectedC();
|
||||
void unpublishSelectedC(bool publish);
|
||||
public:
|
||||
class OpenCallback;
|
||||
bool HasExited;
|
||||
@ -47,7 +47,7 @@ public:
|
||||
void Update();
|
||||
void ClearSelection();
|
||||
void RemoveSelected();
|
||||
void UnpublishSelected();
|
||||
void UnpublishSelected(bool publish);
|
||||
void FavouriteSelected();
|
||||
void ReleaseLoadedSave();
|
||||
SaveInfo * GetLoadedSave();
|
||||
|
@ -19,7 +19,8 @@ SearchView::SearchView():
|
||||
c(NULL),
|
||||
changed(true),
|
||||
lastChanged(0),
|
||||
pageCount(0)
|
||||
pageCount(0),
|
||||
publishButtonShown(false)
|
||||
{
|
||||
|
||||
Client::Ref().AddListener(this);
|
||||
@ -202,7 +203,7 @@ SearchView::SearchView():
|
||||
UnpublishSelectedAction(SearchView * _v) { v = _v; }
|
||||
void ActionCallback(ui::Button * sender)
|
||||
{
|
||||
v->c->UnpublishSelected();
|
||||
v->c->UnpublishSelected(v->publishButtonShown);
|
||||
}
|
||||
};
|
||||
|
||||
@ -730,13 +731,18 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
|
||||
void SearchView::NotifySelectedChanged(SearchModel * sender)
|
||||
{
|
||||
vector<int> selected = sender->GetSelected();
|
||||
int published = 0;
|
||||
for(int j = 0; j < saveButtons.size(); j++)
|
||||
{
|
||||
saveButtons[j]->SetSelected(false);
|
||||
for(int i = 0; i < selected.size(); i++)
|
||||
{
|
||||
if(saveButtons[j]->GetSave()->GetID()==selected[i])
|
||||
if(saveButtons[j]->GetSave()->GetID() == selected[i])
|
||||
{
|
||||
saveButtons[j]->SetSelected(true);
|
||||
if (saveButtons[j]->GetSave()->GetPublished())
|
||||
published++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -746,13 +752,29 @@ void SearchView::NotifySelectedChanged(SearchModel * sender)
|
||||
unpublishSelected->Visible = true;
|
||||
favouriteSelected->Visible = true;
|
||||
clearSelection->Visible = true;
|
||||
pageTextbox->Visible = false;
|
||||
pageLabel->Visible = false;
|
||||
pageCountLabel->Visible = false;
|
||||
if (published <= selected.size()/2)
|
||||
{
|
||||
unpublishSelected->SetText("Publish");
|
||||
publishButtonShown = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
unpublishSelected->SetText("Unpublish");
|
||||
publishButtonShown = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (removeSelected->Visible)
|
||||
{
|
||||
removeSelected->Visible = false;
|
||||
unpublishSelected->Visible = false;
|
||||
favouriteSelected->Visible = false;
|
||||
clearSelection->Visible = false;
|
||||
pageTextbox->Visible = true;
|
||||
pageLabel->Visible = true;
|
||||
pageCountLabel->Visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,7 @@ private:
|
||||
bool changed;
|
||||
int lastChanged;
|
||||
int pageCount;
|
||||
bool publishButtonShown;
|
||||
public:
|
||||
void NotifyTagListChanged(SearchModel * sender);
|
||||
void NotifySaveListChanged(SearchModel * sender);
|
||||
|
Reference in New Issue
Block a user