Add ability to get favourites
This commit is contained in:
parent
4c6be4ff2c
commit
900e23128a
@ -840,7 +840,7 @@ std::vector<Comment*> * Client::GetComments(int saveID, int start, int count)
|
||||
return commentArray;
|
||||
}
|
||||
|
||||
std::vector<Save*> * Client::SearchSaves(int start, int count, string query, string sort, bool showOwn, int & resultCount)
|
||||
std::vector<Save*> * Client::SearchSaves(int start, int count, string query, string sort, std::string category, int & resultCount)
|
||||
{
|
||||
lastError = "";
|
||||
resultCount = 0;
|
||||
@ -860,15 +860,21 @@ std::vector<Save*> * Client::SearchSaves(int start, int count, string query, str
|
||||
urlStream << URLEscape(" ");
|
||||
urlStream << URLEscape("sort:") << URLEscape(sort);
|
||||
}
|
||||
if(showOwn && authUser.ID)
|
||||
{
|
||||
if(query.length())
|
||||
urlStream << URLEscape(" ");
|
||||
urlStream << URLEscape("user:") << URLEscape(authUser.Username);
|
||||
}
|
||||
|
||||
}
|
||||
data = http_simple_get((char *)urlStream.str().c_str(), &dataStatus, &dataLength);
|
||||
if(category.length())
|
||||
{
|
||||
urlStream << "&Category=" << URLEscape(category);
|
||||
}
|
||||
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
|
||||
{
|
||||
data = http_simple_get((char *)urlStream.str().c_str(), &dataStatus, &dataLength);
|
||||
}
|
||||
if(dataStatus == 200 && data)
|
||||
{
|
||||
try
|
||||
|
@ -62,7 +62,7 @@ public:
|
||||
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
|
||||
LoginStatus Login(string username, string password, User & user);
|
||||
void ClearThumbnailRequests();
|
||||
std::vector<Save*> * SearchSaves(int start, int count, string query, string sort, bool showOwn, int & resultCount);
|
||||
std::vector<Save*> * SearchSaves(int start, int count, string query, string sort, string category, int & resultCount);
|
||||
std::vector<Comment*> * GetComments(int saveID, int start, int count);
|
||||
Thumbnail * GetPreview(int saveID, int saveDate);
|
||||
Thumbnail * GetThumbnail(int saveID, int saveDate);
|
||||
|
18
src/options/OptionsController.cpp
Normal file
18
src/options/OptionsController.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* OptionsController.cpp
|
||||
*
|
||||
* Created on: Apr 14, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#include "OptionsController.h"
|
||||
|
||||
OptionsController::OptionsController() {
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
OptionsController::~OptionsController() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
17
src/options/OptionsController.h
Normal file
17
src/options/OptionsController.h
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* OptionsController.h
|
||||
*
|
||||
* Created on: Apr 14, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#ifndef OPTIONSCONTROLLER_H_
|
||||
#define OPTIONSCONTROLLER_H_
|
||||
|
||||
class OptionsController {
|
||||
public:
|
||||
OptionsController();
|
||||
virtual ~OptionsController();
|
||||
};
|
||||
|
||||
#endif /* OPTIONSCONTROLLER_H_ */
|
18
src/options/OptionsModel.cpp
Normal file
18
src/options/OptionsModel.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* OptionsModel.cpp
|
||||
*
|
||||
* Created on: Apr 14, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#include "OptionsModel.h"
|
||||
|
||||
OptionsModel::OptionsModel() {
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
OptionsModel::~OptionsModel() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
17
src/options/OptionsModel.h
Normal file
17
src/options/OptionsModel.h
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* OptionsModel.h
|
||||
*
|
||||
* Created on: Apr 14, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#ifndef OPTIONSMODEL_H_
|
||||
#define OPTIONSMODEL_H_
|
||||
|
||||
class OptionsModel {
|
||||
public:
|
||||
OptionsModel();
|
||||
virtual ~OptionsModel();
|
||||
};
|
||||
|
||||
#endif /* OPTIONSMODEL_H_ */
|
19
src/options/OptionsView.cpp
Normal file
19
src/options/OptionsView.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* OptionsView.cpp
|
||||
*
|
||||
* Created on: Apr 14, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#include "OptionsView.h"
|
||||
|
||||
OptionsView::OptionsView():
|
||||
ui::Window(ui::Point(-1, -1), ui::Point(300, 300)){
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
OptionsView::~OptionsView() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
19
src/options/OptionsView.h
Normal file
19
src/options/OptionsView.h
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* OptionsView.h
|
||||
*
|
||||
* Created on: Apr 14, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#ifndef OPTIONSVIEW_H_
|
||||
#define OPTIONSVIEW_H_
|
||||
|
||||
#include "interface/Window.h"
|
||||
|
||||
class OptionsView: public ui::Window {
|
||||
public:
|
||||
OptionsView();
|
||||
virtual ~OptionsView();
|
||||
};
|
||||
|
||||
#endif /* OPTIONSVIEW_H_ */
|
@ -121,14 +121,31 @@ void SearchController::ChangeSort()
|
||||
{
|
||||
searchModel->SetSort("new");
|
||||
}
|
||||
searchModel->UpdateSaveList(1, searchModel->GetLastQuery());
|
||||
}
|
||||
|
||||
void SearchController::ShowOwn(bool show)
|
||||
{
|
||||
if(Client::Ref().GetAuthUser().ID)
|
||||
{
|
||||
searchModel->SetShowFavourite(false);
|
||||
searchModel->SetShowOwn(show);
|
||||
}
|
||||
else
|
||||
searchModel->SetShowOwn(false);
|
||||
searchModel->UpdateSaveList(1, searchModel->GetLastQuery());
|
||||
}
|
||||
|
||||
void SearchController::ShowFavourite(bool show)
|
||||
{
|
||||
if(Client::Ref().GetAuthUser().ID)
|
||||
{
|
||||
searchModel->SetShowOwn(false);
|
||||
searchModel->SetShowFavourite(show);
|
||||
}
|
||||
else
|
||||
searchModel->SetShowFavourite(false);
|
||||
searchModel->UpdateSaveList(1, searchModel->GetLastQuery());
|
||||
}
|
||||
|
||||
void SearchController::Selected(int saveID, bool selected)
|
||||
|
@ -35,6 +35,7 @@ public:
|
||||
void PrevPage();
|
||||
void ChangeSort();
|
||||
void ShowOwn(bool show);
|
||||
void ShowFavourite(bool show);
|
||||
void Selected(int saveID, bool selected);
|
||||
void OpenSave(int saveID);
|
||||
void Update();
|
||||
|
@ -6,6 +6,7 @@
|
||||
SearchModel::SearchModel():
|
||||
currentSort("best"),
|
||||
showOwn(false),
|
||||
showFavourite(false),
|
||||
loadedSave(NULL),
|
||||
updateSaveListWorking(false),
|
||||
updateSaveListFinished(false),
|
||||
@ -22,7 +23,12 @@ void * SearchModel::updateSaveListTHelper(void * obj)
|
||||
|
||||
void * SearchModel::updateSaveListT()
|
||||
{
|
||||
vector<Save*> * tempSaveList = Client::Ref().SearchSaves((currentPage-1)*20, 20, lastQuery, currentSort=="new"?"date":"votes", showOwn, resultCount);
|
||||
std::string category = "";
|
||||
if(showFavourite)
|
||||
category = "Favourites";
|
||||
if(showOwn && Client::Ref().GetAuthUser().ID)
|
||||
category = "by:"+Client::Ref().GetAuthUser().Username;
|
||||
vector<Save*> * tempSaveList = Client::Ref().SearchSaves((currentPage-1)*20, 20, lastQuery, currentSort=="new"?"date":"votes", category, resultCount);
|
||||
updateSaveListFinished = true;
|
||||
return tempSaveList;
|
||||
}
|
||||
@ -162,6 +168,15 @@ void SearchModel::notifyShowOwnChanged()
|
||||
}
|
||||
}
|
||||
|
||||
void SearchModel::notifyShowFavouriteChanged()
|
||||
{
|
||||
for(int i = 0; i < observers.size(); i++)
|
||||
{
|
||||
SearchView* cObserver = observers[i];
|
||||
cObserver->NotifyShowOwnChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
void SearchModel::notifySelectedChanged()
|
||||
{
|
||||
for(int i = 0; i < observers.size(); i++)
|
||||
|
@ -24,11 +24,13 @@ private:
|
||||
int currentPage;
|
||||
int resultCount;
|
||||
bool showOwn;
|
||||
bool showFavourite;
|
||||
void notifySaveListChanged();
|
||||
void notifySelectedChanged();
|
||||
void notifyPageChanged();
|
||||
void notifySortChanged();
|
||||
void notifyShowOwnChanged();
|
||||
void notifyShowFavouriteChanged();
|
||||
|
||||
//Variables and methods for backgroun save request
|
||||
bool saveListLoaded;
|
||||
@ -48,10 +50,12 @@ public:
|
||||
int GetPageCount() { return max(1, (int)(ceil(resultCount/16))); }
|
||||
int GetPageNum() { return currentPage; }
|
||||
std::string GetLastQuery() { return lastQuery; }
|
||||
void SetSort(string sort) { currentSort = sort; UpdateSaveList(1, lastQuery); notifySortChanged(); }
|
||||
void SetSort(string sort) { currentSort = sort; notifySortChanged(); }
|
||||
string GetSort() { return currentSort; }
|
||||
void SetShowOwn(bool show) { if(show!=showOwn) { showOwn = show; UpdateSaveList(1, lastQuery); } notifyShowOwnChanged(); }
|
||||
void SetShowOwn(bool show) { if(show!=showOwn) { showOwn = show; } notifyShowOwnChanged(); }
|
||||
bool GetShowOwn() { return showOwn; }
|
||||
void SetShowFavourite(bool show) { if(show!=showFavourite) { showFavourite = show; } notifyShowFavouriteChanged(); }
|
||||
bool GetShowFavourite() { return showFavourite; }
|
||||
void SetLoadedSave(Save * save);
|
||||
Save * GetLoadedSave();
|
||||
bool GetSavesLoaded() { return saveListLoaded; }
|
||||
|
@ -27,7 +27,7 @@ SearchView::SearchView():
|
||||
v->doSearch();
|
||||
}
|
||||
};
|
||||
searchField = new ui::Textbox(ui::Point(60, 10), ui::Point((XRES+BARSIZE)-((60*2)+16+10+50+10), 16), "");
|
||||
searchField = new ui::Textbox(ui::Point(60, 10), ui::Point((XRES+BARSIZE)-226, 16), "");
|
||||
searchField->SetAlignment(AlignLeft, AlignBottom);
|
||||
searchField->SetActionCallback(new SearchAction(this));
|
||||
|
||||
@ -41,7 +41,7 @@ SearchView::SearchView():
|
||||
v->c->ChangeSort();
|
||||
}
|
||||
};
|
||||
sortButton = new ui::Button(ui::Point(XRES+BARSIZE-60-60-16-10+5, 10), ui::Point(60, 16), "Sort");
|
||||
sortButton = new ui::Button(ui::Point(XRES+BARSIZE-140, 10), ui::Point(60, 16), "Sort");
|
||||
sortButton->SetActionCallback(new SortAction(this));
|
||||
sortButton->SetAlignment(AlignCentre, AlignBottom);
|
||||
AddComponent(sortButton);
|
||||
@ -56,7 +56,7 @@ SearchView::SearchView():
|
||||
v->c->ShowOwn(sender->GetToggleState());
|
||||
}
|
||||
};
|
||||
ownButton = new ui::Button(ui::Point(XRES+BARSIZE-60-16-10+10, 10), ui::Point(60, 16), "My Own");
|
||||
ownButton = new ui::Button(ui::Point(XRES+BARSIZE-70, 10), ui::Point(60, 16), "My Own");
|
||||
ownButton->SetTogglable(true);
|
||||
ownButton->SetActionCallback(new MyOwnAction(this));
|
||||
if(!Client::Ref().GetAuthUser().ID)
|
||||
@ -64,6 +64,25 @@ SearchView::SearchView():
|
||||
ownButton->SetAlignment(AlignCentre, AlignBottom);
|
||||
AddComponent(ownButton);
|
||||
|
||||
class FavAction : public ui::ButtonAction
|
||||
{
|
||||
SearchView * v;
|
||||
public:
|
||||
FavAction(SearchView * _v) { v = _v; }
|
||||
void ActionCallback(ui::Button * sender)
|
||||
{
|
||||
v->c->ShowFavourite(sender->GetToggleState());
|
||||
}
|
||||
};
|
||||
favButton = new ui::Button(searchField->Position+ui::Point(searchField->Size.X, 0), ui::Point(16, 16), "");
|
||||
favButton->SetIcon(IconFavourite);
|
||||
favButton->SetTogglable(true);
|
||||
favButton->SetActionCallback(new FavAction(this));
|
||||
if(!Client::Ref().GetAuthUser().ID)
|
||||
favButton->Enabled = false;
|
||||
favButton->SetAlignment(AlignCentre, AlignBottom);
|
||||
AddComponent(favButton);
|
||||
|
||||
class NextPageAction : public ui::ButtonAction
|
||||
{
|
||||
SearchView * v;
|
||||
@ -206,6 +225,31 @@ void SearchView::NotifyShowOwnChanged(SearchModel * sender)
|
||||
unpublishSelected->Enabled = true;
|
||||
removeSelected->Enabled = true;
|
||||
}
|
||||
else if(sender->GetShowFavourite())
|
||||
{
|
||||
unpublishSelected->Enabled = false;
|
||||
removeSelected->Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
unpublishSelected->Enabled = false;
|
||||
removeSelected->Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
void SearchView::NotifyShowFavouriteChanged(SearchModel * sender)
|
||||
{
|
||||
favButton->SetToggleState(sender->GetShowFavourite());
|
||||
if(sender->GetShowFavourite())
|
||||
{
|
||||
unpublishSelected->Enabled = false;
|
||||
removeSelected->Enabled = true;
|
||||
}
|
||||
else if(sender->GetShowOwn() || Client::Ref().GetAuthUser().UserElevation == ElevationAdmin || Client::Ref().GetAuthUser().UserElevation == ElevationModerator)
|
||||
{
|
||||
unpublishSelected->Enabled = true;
|
||||
removeSelected->Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
unpublishSelected->Enabled = false;
|
||||
|
@ -19,6 +19,7 @@ class SearchView: public ui::Window
|
||||
private:
|
||||
SearchController * c;
|
||||
vector<ui::SaveButton*> saveButtons;
|
||||
ui::Button * favButton;
|
||||
ui::Button * nextButton;
|
||||
ui::Button * previousButton;
|
||||
ui::Label * errorLabel;
|
||||
@ -39,6 +40,7 @@ public:
|
||||
void NotifyPageChanged(SearchModel * sender);
|
||||
void NotifySortChanged(SearchModel * sender);
|
||||
void NotifyShowOwnChanged(SearchModel * sender);
|
||||
void NotifyShowFavouriteChanged(SearchModel * sender);
|
||||
SearchView();
|
||||
virtual ~SearchView();
|
||||
void AttachController(SearchController * _c) { c = _c; }
|
||||
|
Loading…
Reference in New Issue
Block a user