diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-26 01:13:33 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-26 01:13:33 (GMT) |
| commit | 9e1be78bc21d1fb76a19ce12ef36193aea6e2b93 (patch) | |
| tree | 081b67d551bb44fecbf6deb99b6c44ea9789614c /src/search | |
| parent | b2d3257ae944a3ea3b57dc8ee4171b1b2f85483e (diff) | |
| download | powder-9e1be78bc21d1fb76a19ce12ef36193aea6e2b93.zip powder-9e1be78bc21d1fb76a19ce12ef36193aea6e2b93.tar.gz | |
I've got to a point where I can no longer be bothered to think of a proper commit comment
Diffstat (limited to 'src/search')
| -rw-r--r-- | src/search/Save.cpp | 87 | ||||
| -rw-r--r-- | src/search/Save.h | 59 | ||||
| -rw-r--r-- | src/search/SearchController.cpp | 53 | ||||
| -rw-r--r-- | src/search/SearchController.h | 11 | ||||
| -rw-r--r-- | src/search/SearchModel.cpp | 18 | ||||
| -rw-r--r-- | src/search/SearchModel.h | 4 | ||||
| -rw-r--r-- | src/search/SearchView.cpp | 5 | ||||
| -rw-r--r-- | src/search/SearchView.h | 1 |
8 files changed, 194 insertions, 44 deletions
diff --git a/src/search/Save.cpp b/src/search/Save.cpp new file mode 100644 index 0000000..6a5925d --- /dev/null +++ b/src/search/Save.cpp @@ -0,0 +1,87 @@ +/* + * Save.cpp + * + * Created on: Jan 26, 2012 + * Author: Simon + */ + +#include "Save.h" +#include "client/Client.h" + +Save::Save(Save & save) : + userName(save.userName), name(save.name), Description(save.Description), date( + save.date), Published(save.Published), id(save.id), votesUp( + save.votesUp), votesDown(save.votesDown), data(NULL) { + if (save.data) { + std::cout << data << " " << save.data << std::endl; + data = (unsigned char *) malloc(save.dataLength); + memcpy(data, save.data, save.dataLength); + dataLength = save.dataLength; + } +} + +Save::Save(int _id, int _date, int _votesUp, int _votesDown, string _userName, + string _name) : + id(_id), votesUp(_votesUp), votesDown(_votesDown), userName(_userName), name( + _name), Description("No description provided"), date(_date), Published( + true), data(NULL) { +} + +Save::Save(int _id, int date_, int _votesUp, int _votesDown, string _userName, + string _name, string description_, bool published_) : + id(_id), votesUp(_votesUp), votesDown(_votesDown), userName(_userName), name( + _name), Description(description_), date(date_), Published( + published_), data(NULL) { +} + +void Save::SetName(string name) { + this->name = name; +} +string Save::GetName() { + return name; +} + +void Save::SetUserName(string userName) { + this->userName = userName; +} +string Save::GetUserName() { + return userName; +} + +void Save::SetID(int id) { + this->id = id; +} +int Save::GetID() { + return id; +} + +void Save::SetVotesUp(int votesUp) { + this->votesUp = votesUp; +} +int Save::GetVotesUp() { + return votesUp; +} + +void Save::SetVotesDown(int votesDown) { + this->votesDown = votesDown; +} +int Save::GetVotesDown() { + return votesDown; +} + +unsigned char * Save::GetData() { + if (!data) { + data = Client::Ref().GetSaveData(id, date, dataLength); + } + return data; +} +void Save::SetData(unsigned char * data_) { + data = data_; +} + +int Save::GetDataLength() { + if (!data) { + data = Client::Ref().GetSaveData(id, date, dataLength); + } + return dataLength; +} diff --git a/src/search/Save.h b/src/search/Save.h index 0a011ab..3186e2a 100644 --- a/src/search/Save.h +++ b/src/search/Save.h @@ -2,6 +2,9 @@ #define SAVE_H #include <string> +#include <stdlib.h> +#include <iostream> +#include <string.h> using namespace std; @@ -9,57 +12,43 @@ class Save { private: int id; + int date; int votesUp, votesDown; unsigned char * data; + int dataLength; public: - Save(int _id, int _votesUp, int _votesDown, string _userName, string _name): - id(_id), - votesUp(_votesUp), - votesDown(_votesDown), - userName(_userName), - name(_name), - Description("No description provided"), - Date("0/0/0"), - Published(true) - { - } - - Save(int _id, int _votesUp, int _votesDown, string _userName, string _name, string description_, string date_, bool published_): - id(_id), - votesUp(_votesUp), - votesDown(_votesDown), - userName(_userName), - name(_name), - Description(description_), - Date(date_), - Published(published_) - { - } + Save(Save & save); + + Save(int _id, int _date, int _votesUp, int _votesDown, string _userName, string _name); + + Save(int _id, int date_, int _votesUp, int _votesDown, string _userName, string _name, string description_, bool published_); string userName; string name; string Description; - string Date; bool Published; - void SetName(string name){ this->name = name; } - string GetName(){ return name; } + void SetName(string name); + string GetName(); + + void SetUserName(string userName); + string GetUserName(); - void SetUserName(string userName){ this->userName = userName; } - string GetUserName(){ return userName; } + void SetID(int id); + int GetID(); - void SetID(int id){ this->id = id; } - int GetID(){ return id; } + void SetVotesUp(int votesUp); + int GetVotesUp(); - void SetVotesUp(int votesUp){ this->votesUp = votesUp; } - int GetVotesUp(){ return votesUp; } + void SetVotesDown(int votesDown); + int GetVotesDown(); - void SetVotesDown(int votesDown){ this->votesDown = votesDown; } - int GetVotesDown(){ return votesDown; } + unsigned char * GetData(); + void SetData(unsigned char * data_); - unsigned char * GetData() { return data; } + int GetDataLength(); }; #endif // SAVE_H diff --git a/src/search/SearchController.cpp b/src/search/SearchController.cpp index 46a353c..96f759e 100644 --- a/src/search/SearchController.cpp +++ b/src/search/SearchController.cpp @@ -5,8 +5,24 @@ #include "interface/Panel.h" #include "preview/PreviewController.h" -SearchController::SearchController(): - activePreview(NULL) +class SearchController::OpenCallback: public ControllerCallback +{ + SearchController * cc; +public: + OpenCallback(SearchController * cc_) { cc = cc_; } + virtual void ControllerExit() + { + if(cc->activePreview->GetDoOpen()) + { + cc->searchModel->SetLoadedSave(new Save(*(cc->activePreview->GetSave()))); + cc->Exit(); + } + } +}; + +SearchController::SearchController(ControllerCallback * callback): + activePreview(NULL), + HasExited(false) { searchModel = new SearchModel(); searchView = new SearchView(); @@ -15,19 +31,42 @@ SearchController::SearchController(): searchModel->UpdateSaveList(1, ""); + this->callback = callback; + //Set up interface //windowPanel.AddChild(); } -SearchController::~SearchController() +Save * SearchController::GetLoadedSave() { - if(activePreview) + return searchModel->GetLoadedSave(); +} + +void SearchController::Update() +{ + if(activePreview && activePreview->HasExited) { - ui::Engine::Ref().CloseWindow(); delete activePreview; + activePreview = NULL; } +} + +void SearchController::Exit() +{ + if(ui::Engine::Ref().GetWindow() == searchView) + { + ui::Engine::Ref().CloseWindow(); + } + if(callback) + callback->ControllerExit(); + HasExited = true; +} + +SearchController::~SearchController() +{ delete searchModel; - delete searchView; + if(searchView) + delete searchView; } void SearchController::DoSearch(std::string query) @@ -66,6 +105,6 @@ void SearchController::ShowOwn(bool show) void SearchController::OpenSave(int saveID) { - activePreview = new PreviewController(saveID); + activePreview = new PreviewController(saveID, new OpenCallback(this)); ui::Engine::Ref().ShowWindow(activePreview->GetView()); } diff --git a/src/search/SearchController.h b/src/search/SearchController.h index d67743e..e015648 100644 --- a/src/search/SearchController.h +++ b/src/search/SearchController.h @@ -5,6 +5,9 @@ #include "SearchModel.h" #include "SearchView.h" #include "preview/PreviewController.h" +#include "Controller.h" +#include "Save.h" + class SearchView; class SearchModel; class SearchController @@ -13,16 +16,22 @@ private: SearchModel * searchModel; SearchView * searchView; PreviewController * activePreview; + ControllerCallback * callback; public: - SearchController(); + class OpenCallback; + bool HasExited; + SearchController(ControllerCallback * callback = NULL); ~SearchController(); SearchView * GetView() { return searchView; } + void Exit(); void DoSearch(std::string query); void NextPage(); void PrevPage(); void ChangeSort(); void ShowOwn(bool show); void OpenSave(int saveID); + void Update(); + Save * GetLoadedSave(); }; #endif // SEARCHCONTROLLER_H diff --git a/src/search/SearchModel.cpp b/src/search/SearchModel.cpp index adb8cad..d9a4a1e 100644 --- a/src/search/SearchModel.cpp +++ b/src/search/SearchModel.cpp @@ -5,7 +5,8 @@ SearchModel::SearchModel(): currentSort("votes"), - showOwn(false) + showOwn(false), + loadedSave(NULL) { } @@ -30,6 +31,15 @@ void SearchModel::UpdateSaveList(int pageNumber, std::string query) notifySaveListChanged(); } +void SearchModel::SetLoadedSave(Save * save) +{ + loadedSave = save; +} + +Save * SearchModel::GetLoadedSave(){ + return loadedSave; +} + vector<Save*> SearchModel::GetSaveList() { return saveList; @@ -79,3 +89,9 @@ void SearchModel::notifyShowOwnChanged() cObserver->NotifyShowOwnChanged(this); } } + +SearchModel::~SearchModel() +{ + if(loadedSave) + delete loadedSave; +} diff --git a/src/search/SearchModel.h b/src/search/SearchModel.h index 0ed7d86..e99e4ca 100644 --- a/src/search/SearchModel.h +++ b/src/search/SearchModel.h @@ -13,6 +13,7 @@ class SearchView; class SearchModel { private: + Save * loadedSave; string currentSort; string lastQuery; string lastError; @@ -27,6 +28,7 @@ private: void notifyShowOwnChanged(); public: SearchModel(); + virtual ~SearchModel(); void AddObserver(SearchView * observer); void UpdateSaveList(int pageNumber, std::string query); vector<Save*> GetSaveList(); @@ -38,6 +40,8 @@ public: string GetSort() { return currentSort; } void SetShowOwn(bool show) { showOwn = show; UpdateSaveList(1, lastQuery); notifyShowOwnChanged(); } bool GetShowOwn() { return showOwn; } + void SetLoadedSave(Save * save); + Save * GetLoadedSave(); }; #endif // SEARCHMODEL_H diff --git a/src/search/SearchView.cpp b/src/search/SearchView.cpp index e589d20..8e5360f 100644 --- a/src/search/SearchView.cpp +++ b/src/search/SearchView.cpp @@ -212,3 +212,8 @@ void SearchView::NotifySaveListChanged(SearchModel * sender) } } } + +void SearchView::OnTick(float dt) +{ + c->Update(); +} diff --git a/src/search/SearchView.h b/src/search/SearchView.h index 370877e..a2a5297 100644 --- a/src/search/SearchView.h +++ b/src/search/SearchView.h @@ -34,6 +34,7 @@ public: SearchView(); virtual ~SearchView(); void AttachController(SearchController * _c) { c = _c; } + virtual void OnTick(float dt); }; #endif // SEARCHVIEW_H |
