diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-04-14 20:11:54 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-04-14 20:11:54 (GMT) |
| commit | 900e23128a16bd49d8929a232ac57fc7e30ad3f9 (patch) | |
| tree | a5d04c86dc0ac5efb887579699e86143f12f20a8 /src/search | |
| parent | 4c6be4ff2cc822d9c1ed36c9c88261771775dc02 (diff) | |
| download | powder-900e23128a16bd49d8929a232ac57fc7e30ad3f9.zip powder-900e23128a16bd49d8929a232ac57fc7e30ad3f9.tar.gz | |
Add ability to get favourites
Diffstat (limited to 'src/search')
| -rw-r--r-- | src/search/SearchController.cpp | 17 | ||||
| -rw-r--r-- | src/search/SearchController.h | 1 | ||||
| -rw-r--r-- | src/search/SearchModel.cpp | 17 | ||||
| -rw-r--r-- | src/search/SearchModel.h | 8 | ||||
| -rw-r--r-- | src/search/SearchView.cpp | 50 | ||||
| -rw-r--r-- | src/search/SearchView.h | 2 |
6 files changed, 89 insertions, 6 deletions
diff --git a/src/search/SearchController.cpp b/src/search/SearchController.cpp index 09fde71..b0936ef 100644 --- a/src/search/SearchController.cpp +++ b/src/search/SearchController.cpp @@ -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) diff --git a/src/search/SearchController.h b/src/search/SearchController.h index 3168419..ae13431 100644 --- a/src/search/SearchController.h +++ b/src/search/SearchController.h @@ -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(); diff --git a/src/search/SearchModel.cpp b/src/search/SearchModel.cpp index e1d9849..76d0bb7 100644 --- a/src/search/SearchModel.cpp +++ b/src/search/SearchModel.cpp @@ -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++) diff --git a/src/search/SearchModel.h b/src/search/SearchModel.h index 8f2ae58..980c06d 100644 --- a/src/search/SearchModel.h +++ b/src/search/SearchModel.h @@ -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; } diff --git a/src/search/SearchView.cpp b/src/search/SearchView.cpp index 5a1c6c7..ffaa471 100644 --- a/src/search/SearchView.cpp +++ b/src/search/SearchView.cpp @@ -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; diff --git a/src/search/SearchView.h b/src/search/SearchView.h index ed4b06e..6e27f06 100644 --- a/src/search/SearchView.h +++ b/src/search/SearchView.h @@ -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; } |
