summaryrefslogtreecommitdiff
path: root/src/search
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-01-20 22:07:49 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-01-20 22:07:49 (GMT)
commitc8073657fcbfd1bfa72538d7babe4964857e7101 (patch)
treef3488e993c9828121b2f89ed2f639d2ebbe54dc9 /src/search
parentc5e8b345219cd7d8ca4b0aa638f59a1fed2cd83b (diff)
downloadpowder-c8073657fcbfd1bfa72538d7babe4964857e7101.zip
powder-c8073657fcbfd1bfa72538d7babe4964857e7101.tar.gz
More stuff, need to fix memory leak
Diffstat (limited to 'src/search')
-rw-r--r--src/search/SearchController.cpp8
-rw-r--r--src/search/SearchController.h1
-rw-r--r--src/search/SearchModel.cpp4
-rw-r--r--src/search/SearchModel.h2
-rw-r--r--src/search/SearchView.cpp29
-rw-r--r--src/search/SearchView.h3
6 files changed, 41 insertions, 6 deletions
diff --git a/src/search/SearchController.cpp b/src/search/SearchController.cpp
index 90750e0..11871fd 100644
--- a/src/search/SearchController.cpp
+++ b/src/search/SearchController.cpp
@@ -1,3 +1,4 @@
+#include <string>
#include "SearchController.h"
#include "SearchModel.h"
#include "SearchView.h"
@@ -10,8 +11,13 @@ SearchController::SearchController()
searchModel->AddObserver(searchView);
searchView->AttachController(this);
- searchModel->UpdateSaveList();
+ searchModel->UpdateSaveList("");
//Set up interface
//windowPanel.AddChild();
}
+
+void SearchController::DoSearch(std::string query)
+{
+ searchModel->UpdateSaveList(query);
+}
diff --git a/src/search/SearchController.h b/src/search/SearchController.h
index 10dd9bd..8676145 100644
--- a/src/search/SearchController.h
+++ b/src/search/SearchController.h
@@ -14,6 +14,7 @@ private:
public:
SearchController();
SearchView * GetView() { return searchView; }
+ void DoSearch(std::string query);
};
#endif // SEARCHCONTROLLER_H
diff --git a/src/search/SearchModel.cpp b/src/search/SearchModel.cpp
index 16a99d4..96d340a 100644
--- a/src/search/SearchModel.cpp
+++ b/src/search/SearchModel.cpp
@@ -7,12 +7,12 @@ SearchModel::SearchModel()
{
}
-void SearchModel::UpdateSaveList()
+void SearchModel::UpdateSaveList(std::string query)
{
lastError = "";
saveList.clear();
notifySaveListChanged();
- saveList = Client::Ref().SearchSaves(0, 12, "", "");
+ saveList = Client::Ref().SearchSaves(0, 12, query, "");
if(!saveList.size())
{
lastError = Client::Ref().GetLastError();
diff --git a/src/search/SearchModel.h b/src/search/SearchModel.h
index e65c15e..ca6a293 100644
--- a/src/search/SearchModel.h
+++ b/src/search/SearchModel.h
@@ -19,7 +19,7 @@ private:
public:
SearchModel();
void AddObserver(SearchView * observer);
- void UpdateSaveList();
+ void UpdateSaveList(std::string query);
vector<Save> GetSaveList();
string GetLastError() { return lastError; }
};
diff --git a/src/search/SearchView.cpp b/src/search/SearchView.cpp
index 63a579e..2ddd76c 100644
--- a/src/search/SearchView.cpp
+++ b/src/search/SearchView.cpp
@@ -1,6 +1,7 @@
#include "SearchView.h"
#include "interface/SaveButton.h"
#include "interface/Label.h"
+#include "interface/Textbox.h"
#include "Misc.h"
SearchView::SearchView():
@@ -11,10 +12,34 @@ SearchView::SearchView():
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");
+ class SearchAction : public ui::TextboxAction
+ {
+ SearchView * v;
+ public:
+ SearchAction(SearchView * _v) { v = _v; }
+ void TextChangedCallback(ui::Textbox * sender)
+ {
+ v->doSearch();
+ }
+ };
+ searchField = new ui::Textbox(ui::Point(60, 10), ui::Point((XRES+BARSIZE)-((50*2)+16+10+50+10), 16), "");
+ searchField->SetAlignment(AlignLeft, AlignBottom);
+ searchField->SetActionCallback(new SearchAction(this));
+
nextButton->SetAlignment(AlignRight, AlignBottom);
previousButton->SetAlignment(AlignLeft, AlignBottom);
AddComponent(nextButton);
AddComponent(previousButton);
+ AddComponent(searchField);
+
+ ui::Label * searchPrompt = new ui::Label(ui::Point(10, 10), ui::Point(50, 16), "Search:");
+ searchPrompt->SetAlignment(AlignLeft, AlignBottom);
+ AddComponent(searchPrompt);
+}
+
+void SearchView::doSearch()
+{
+ c->DoSearch(searchField->GetText());
}
SearchView::~SearchView()
@@ -36,9 +61,9 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
AddComponent(errorLabel);
}
if(sender->GetLastError().length())
- errorLabel->LabelText = sender->GetLastError();
+ errorLabel->SetText(sender->GetLastError());
else
- errorLabel->LabelText = "No saves found";
+ errorLabel->SetText("No saves found");
}
else
{
diff --git a/src/search/SearchView.h b/src/search/SearchView.h
index 795fb74..8777c30 100644
--- a/src/search/SearchView.h
+++ b/src/search/SearchView.h
@@ -6,6 +6,7 @@
#include "interface/SaveButton.h"
#include "interface/Button.h"
#include "interface/Label.h"
+#include "interface/Textbox.h"
using namespace std;
@@ -20,6 +21,8 @@ private:
ui::Button * nextButton;
ui::Button * previousButton;
ui::Label * errorLabel;
+ ui::Textbox * searchField;
+ void doSearch();
public:
void NotifySaveListChanged(SearchModel * sender);
SearchView();