summaryrefslogtreecommitdiff
path: root/src/search/SearchView.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-01-21 18:51:28 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-01-21 18:51:28 (GMT)
commit1cee908c165ead0fcecba4519d4584f3935988b5 (patch)
treec03981effdc5543fd9e50f70aab678c9631dbbcd /src/search/SearchView.cpp
parent8ec6aae617525d13697d1c2a612ac37be0f341d5 (diff)
downloadpowder-1cee908c165ead0fcecba4519d4584f3935988b5.zip
powder-1cee908c165ead0fcecba4519d4584f3935988b5.tar.gz
Fix thumbnail crash, turns out SaveButton was storing a Thumbnail pointer, not a Thumbnail as I thought
Diffstat (limited to 'src/search/SearchView.cpp')
-rw-r--r--src/search/SearchView.cpp110
1 files changed, 101 insertions, 9 deletions
diff --git a/src/search/SearchView.cpp b/src/search/SearchView.cpp
index 53ab443..ca848b5 100644
--- a/src/search/SearchView.cpp
+++ b/src/search/SearchView.cpp
@@ -1,4 +1,7 @@
+#include <sstream>
+
#include "SearchView.h"
+#include "client/Client.h"
#include "interface/SaveButton.h"
#include "interface/Label.h"
#include "interface/Textbox.h"
@@ -9,8 +12,10 @@ SearchView::SearchView():
saveButtons(vector<ui::SaveButton*>()),
errorLabel(NULL)
{
+
nextButton = new ui::Button(ui::Point(XRES+BARSIZE-52, YRES+MENUSIZE-18), ui::Point(50, 16), "Next \x95");
previousButton = new ui::Button(ui::Point(1, YRES+MENUSIZE-18), ui::Point(50, 16), "\x96 Prev");
+ infoLabel = new ui::Label(ui::Point(51, YRES+MENUSIZE-18), ui::Point(XRES+BARSIZE-102, 16), "Loading...");
class SearchAction : public ui::TextboxAction
{
@@ -26,11 +31,65 @@ SearchView::SearchView():
searchField->SetAlignment(AlignLeft, AlignBottom);
searchField->SetActionCallback(new SearchAction(this));
+ class SortAction : public ui::ButtonAction
+ {
+ SearchView * v;
+ public:
+ SortAction(SearchView * _v) { v = _v; }
+ void ActionCallback(ui::Button * sender)
+ {
+ v->c->ChangeSort();
+ }
+ };
+ sortButton = new ui::Button(ui::Point(XRES+BARSIZE-50-50-16-10, 10), ui::Point(50, 16), "Sort");
+ sortButton->SetActionCallback(new SortAction(this));
+ sortButton->SetAlignment(AlignLeft, AlignBottom);
+ AddComponent(sortButton);
+
+ class MyOwnAction : public ui::ButtonAction
+ {
+ SearchView * v;
+ public:
+ MyOwnAction(SearchView * _v) { v = _v; }
+ void ActionCallback(ui::Button * sender)
+ {
+ v->c->ShowOwn(sender->GetToggleState());
+ }
+ };
+ ownButton = new ui::Button(ui::Point(XRES+BARSIZE-50-16-10, 10), ui::Point(50, 16), "My Own");
+ ownButton->SetTogglable(true);
+ ownButton->SetActionCallback(new MyOwnAction(this));
+ ownButton->SetAlignment(AlignLeft, AlignBottom);
+ AddComponent(ownButton);
+
+ class NextPageAction : public ui::ButtonAction
+ {
+ SearchView * v;
+ public:
+ NextPageAction(SearchView * _v) { v = _v; }
+ void ActionCallback(ui::Button * sender)
+ {
+ v->c->NextPage();
+ }
+ };
+ nextButton->SetActionCallback(new NextPageAction(this));
nextButton->SetAlignment(AlignRight, AlignBottom);
+ class PrevPageAction : public ui::ButtonAction
+ {
+ SearchView * v;
+ public:
+ PrevPageAction(SearchView * _v) { v = _v; }
+ void ActionCallback(ui::Button * sender)
+ {
+ v->c->PrevPage();
+ }
+ };
+ previousButton->SetActionCallback(new PrevPageAction(this));
previousButton->SetAlignment(AlignLeft, AlignBottom);
AddComponent(nextButton);
AddComponent(previousButton);
AddComponent(searchField);
+ AddComponent(infoLabel);
ui::Label * searchPrompt = new ui::Label(ui::Point(10, 10), ui::Point(50, 16), "Search:");
searchPrompt->SetAlignment(AlignLeft, AlignBottom);
@@ -46,6 +105,39 @@ SearchView::~SearchView()
{
}
+void SearchView::NotifySortChanged(SearchModel * sender)
+{
+ sortButton->SetText("Sort: "+sender->GetSort());
+}
+
+void SearchView::NotifyShowOwnChanged(SearchModel * sender)
+{
+ sortButton->SetToggleState(sender->GetShowOwn());
+}
+
+void SearchView::NotifyPageChanged(SearchModel * sender)
+{
+ std::stringstream pageInfo;
+ pageInfo << "Page " << sender->GetPageNum() << " of " << sender->GetPageCount();
+ infoLabel->SetText(pageInfo.str());
+ if(sender->GetPageNum() == 1)
+ {
+ previousButton->Visible = false;
+ }
+ else
+ {
+ previousButton->Visible = true;
+ }
+ if(sender->GetPageNum() == sender->GetPageCount())
+ {
+ nextButton->Visible = false;
+ }
+ else
+ {
+ nextButton->Visible = true;
+ }
+}
+
void SearchView::NotifySaveListChanged(SearchModel * sender)
{
int i = 0;
@@ -53,6 +145,13 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
int buttonAreaWidth, buttonAreaHeight, buttonXOffset, buttonYOffset;
vector<Save*> saves = sender->GetSaveList();
+ Client::Ref().ClearThumbnailRequests();
+ for(i = 0; i < saveButtons.size(); i++)
+ {
+ RemoveComponent(saveButtons[i]);
+ delete saveButtons[i];
+ }
+ saveButtons.clear();
if(!saves.size())
{
if(!errorLabel)
@@ -61,9 +160,9 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
AddComponent(errorLabel);
}
if(sender->GetLastError().length())
- errorLabel->SetText(sender->GetLastError());
+ errorLabel->SetText("\bo" + sender->GetLastError());
else
- errorLabel->SetText("No saves found");
+ errorLabel->SetText("\boNo saves found");
}
else
{
@@ -79,13 +178,6 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
buttonAreaHeight = Size.Y - buttonYOffset - 18;
buttonWidth = (buttonAreaWidth/savesX) - buttonPadding*2;
buttonHeight = (buttonAreaHeight/savesY) - buttonPadding*2;
- for(i = 0; i < saveButtons.size(); i++)
- {
- RemoveComponent(saveButtons[i]);
-
- delete saveButtons[i];
- }
- saveButtons.clear();
for(i = 0; i < saves.size(); i++)
{
if(saveX == savesX)