summaryrefslogtreecommitdiff
path: root/src/search
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-02-12 16:47:01 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-02-12 16:47:01 (GMT)
commitafe9e061e1d173731d8a5122c397a2caf4fe61ab (patch)
treef045221d8718c44b8af516cb58bdb45c3c74114b /src/search
parentd25384c36c427d4afd71f87f8282b1a981c4b563 (diff)
downloadpowder-afe9e061e1d173731d8a5122c397a2caf4fe61ab.zip
powder-afe9e061e1d173731d8a5122c397a2caf4fe61ab.tar.gz
Better names for sort, allow showing own saves
Diffstat (limited to 'src/search')
-rw-r--r--src/search/SearchController.cpp12
-rw-r--r--src/search/SearchModel.cpp8
-rw-r--r--src/search/SearchModel.h2
-rw-r--r--src/search/SearchView.cpp16
4 files changed, 23 insertions, 15 deletions
diff --git a/src/search/SearchController.cpp b/src/search/SearchController.cpp
index 6fa9748..1449f9a 100644
--- a/src/search/SearchController.cpp
+++ b/src/search/SearchController.cpp
@@ -4,6 +4,7 @@
#include "SearchView.h"
#include "interface/Panel.h"
#include "preview/PreviewController.h"
+#include "client/Client.h"
class SearchController::OpenCallback: public ControllerCallback
{
@@ -106,19 +107,22 @@ void SearchController::NextPage()
void SearchController::ChangeSort()
{
- if(searchModel->GetSort() == "date")
+ if(searchModel->GetSort() == "new")
{
- searchModel->SetSort("votes");
+ searchModel->SetSort("best");
}
else
{
- searchModel->SetSort("date");
+ searchModel->SetSort("new");
}
}
void SearchController::ShowOwn(bool show)
{
- //TODO: Implement
+ if(Client::Ref().GetAuthUser().ID)
+ searchModel->SetShowOwn(show);
+ else
+ searchModel->SetShowOwn(false);
}
void SearchController::OpenSave(int saveID)
diff --git a/src/search/SearchModel.cpp b/src/search/SearchModel.cpp
index e40c4b0..4a410c3 100644
--- a/src/search/SearchModel.cpp
+++ b/src/search/SearchModel.cpp
@@ -4,12 +4,14 @@
#include "client/Client.h"
SearchModel::SearchModel():
- currentSort("votes"),
+ currentSort("best"),
showOwn(false),
loadedSave(NULL),
updateSaveListWorking(false),
updateSaveListFinished(false),
- saveListLoaded(false)
+ saveListLoaded(false),
+ currentPage(1),
+ resultCount(0)
{
}
@@ -20,7 +22,7 @@ void * SearchModel::updateSaveListTHelper(void * obj)
void * SearchModel::updateSaveListT()
{
- vector<Save*> * tempSaveList = Client::Ref().SearchSaves((currentPage-1)*20, 20, lastQuery, currentSort, resultCount);
+ vector<Save*> * tempSaveList = Client::Ref().SearchSaves((currentPage-1)*20, 20, lastQuery, currentSort=="new"?"date":"votes", showOwn, resultCount);
updateSaveListFinished = true;
return tempSaveList;
}
diff --git a/src/search/SearchModel.h b/src/search/SearchModel.h
index d52529d..2587c03 100644
--- a/src/search/SearchModel.h
+++ b/src/search/SearchModel.h
@@ -47,7 +47,7 @@ public:
std::string GetLastQuery() { return lastQuery; }
void SetSort(string sort) { currentSort = sort; UpdateSaveList(1, lastQuery); notifySortChanged(); }
string GetSort() { return currentSort; }
- void SetShowOwn(bool show) { showOwn = show; UpdateSaveList(1, lastQuery); notifyShowOwnChanged(); }
+ void SetShowOwn(bool show) { if(show!=showOwn) { showOwn = show; UpdateSaveList(1, lastQuery); } notifyShowOwnChanged(); }
bool GetShowOwn() { return showOwn; }
void SetLoadedSave(Save * save);
Save * GetLoadedSave();
diff --git a/src/search/SearchView.cpp b/src/search/SearchView.cpp
index 584b7e3..5bcbe06 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)-((50*2)+16+10+50+10), 16), "");
+ searchField = new ui::Textbox(ui::Point(60, 10), ui::Point((XRES+BARSIZE)-((60*2)+16+10+50+10), 16), "");
searchField->SetAlignment(AlignLeft, AlignBottom);
searchField->SetActionCallback(new SearchAction(this));
@@ -41,9 +41,9 @@ SearchView::SearchView():
v->c->ChangeSort();
}
};
- sortButton = new ui::Button(ui::Point(XRES+BARSIZE-50-50-16-10, 10), ui::Point(50, 16), "Sort");
+ sortButton = new ui::Button(ui::Point(XRES+BARSIZE-60-60-16-10+5, 10), ui::Point(60, 16), "Sort");
sortButton->SetActionCallback(new SortAction(this));
- sortButton->SetAlignment(AlignLeft, AlignBottom);
+ sortButton->SetAlignment(AlignCentre, AlignBottom);
AddComponent(sortButton);
class MyOwnAction : public ui::ButtonAction
@@ -56,10 +56,12 @@ SearchView::SearchView():
v->c->ShowOwn(sender->GetToggleState());
}
};
- ownButton = new ui::Button(ui::Point(XRES+BARSIZE-50-16-10, 10), ui::Point(50, 16), "My Own");
+ ownButton = new ui::Button(ui::Point(XRES+BARSIZE-60-16-10+10, 10), ui::Point(60, 16), "My Own");
ownButton->SetTogglable(true);
ownButton->SetActionCallback(new MyOwnAction(this));
- ownButton->SetAlignment(AlignLeft, AlignBottom);
+ if(!Client::Ref().GetAuthUser().ID)
+ ownButton->Enabled = false;
+ ownButton->SetAlignment(AlignCentre, AlignBottom);
AddComponent(ownButton);
class NextPageAction : public ui::ButtonAction
@@ -110,12 +112,12 @@ SearchView::~SearchView()
void SearchView::NotifySortChanged(SearchModel * sender)
{
- sortButton->SetText("Sort: "+sender->GetSort());
+ sortButton->SetText("Show "+sender->GetSort());
}
void SearchView::NotifyShowOwnChanged(SearchModel * sender)
{
- sortButton->SetToggleState(sender->GetShowOwn());
+ ownButton->SetToggleState(sender->GetShowOwn());
}
void SearchView::NotifyPageChanged(SearchModel * sender)