diff --git a/src/search/Save.cpp b/src/search/Save.cpp deleted file mode 100644 index 8b2f21566..000000000 --- a/src/search/Save.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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), vote(save.vote), tags(save.tags) { - if (save.data) { - 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), vote(0), tags() { -} - -Save::Save(int _id, int date_, int _votesUp, int _votesDown, int _vote, string _userName, - string _name, string description_, bool published_, vector tags_) : - id(_id), votesUp(_votesUp), votesDown(_votesDown), userName(_userName), name( - _name), Description(description_), date(date_), Published( - published_), data(NULL), vote(_vote), tags(tags_) { -} - -Save::~Save() -{ - if(data) - { - free(data); - } -} - -void Save::SetName(string name) { - this->name = name; -} -string Save::GetName() { - return name; -} - -void Save::SetVote(int vote) -{ - this->vote = vote; -} -int Save::GetVote() -{ - return vote; -} - -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; -} - -void Save::SetTags(vector tags) -{ - this->tags = tags; -} -vector Save::GetTags() -{ - return tags; -} - -unsigned char * Save::GetData() { - if (!data) { - data = Client::Ref().GetSaveData(id, date, dataLength); - } - return data; -} -void Save::SetData(unsigned char * data_, int dataLength) { - if(data) - free(data); - data = data_; - this->dataLength = dataLength; -} - -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 deleted file mode 100644 index 0b213e221..000000000 --- a/src/search/Save.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef SAVE_H -#define SAVE_H - -#include -#include -#include -#include -#include - -using namespace std; - -class Save -{ -private: -public: - int id; - int date; - int votesUp, votesDown; - unsigned char * data; - int dataLength; - bool Favourite; - - 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, int _vote, string _userName, string _name, string description_, bool published_, vector tags); - - ~Save(); - - string userName; - string name; - - string Description; - - vector tags; - - int vote; - - bool Published; - - void SetName(string name); - string GetName(); - - void SetUserName(string userName); - string GetUserName(); - - void SetID(int id); - int GetID(); - - void SetVote(int vote); - int GetVote(); - - void SetVotesUp(int votesUp); - int GetVotesUp(); - - void SetVotesDown(int votesDown); - int GetVotesDown(); - - void SetTags(vector tags); - vector GetTags(); - - unsigned char * GetData(); - void SetData(unsigned char * data_, int dataLength); - - int GetDataLength(); -}; - -#endif // SAVE_H diff --git a/src/stamps/StampsController.cpp b/src/stamps/StampsController.cpp deleted file mode 100644 index fde93a54b..000000000 --- a/src/stamps/StampsController.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * StampsController.cpp - * - * Created on: Mar 29, 2012 - * Author: Simon - */ -#include -#include - -#include "client/Client.h" -#include "StampsController.h" -#include "interface/Engine.h" -#include "dialogues/ConfirmPrompt.h" -#include "tasks/TaskWindow.h" -#include "tasks/Task.h" - -#include "StampsModel.h" -#include "StampsView.h" - -StampsController::StampsController(ControllerCallback * callback): - HasDone(false) -{ - stampsModel = new StampsModel(); - stampsView = new StampsView(); - stampsView->AttachController(this); - stampsModel->AddObserver(stampsView); - - this->callback = callback; - - stampsModel->UpdateStampsList(1); -} - -void StampsController::OpenStamp(Save * stamp) -{ - stampsModel->SetStamp(stamp); -} - -Save * StampsController::GetStamp() -{ - return stampsModel->GetStamp(); -} - -void StampsController::RemoveSelected() -{ - class RemoveSelectedConfirmation: public ConfirmDialogueCallback { - public: - StampsController * c; - RemoveSelectedConfirmation(StampsController * c_) { c = c_; } - virtual void ConfirmCallback(ConfirmPrompt::DialogueResult result) { - if (result == ConfirmPrompt::ResultOkay) - c->removeSelectedC(); - } - virtual ~RemoveSelectedConfirmation() { } - }; - - std::stringstream desc; - desc << "Are you sure you want to delete " << stampsModel->GetSelected().size() << " stamp"; - if(stampsModel->GetSelected().size()>1) - desc << "s"; - new ConfirmPrompt("Delete stamps", desc.str(), new RemoveSelectedConfirmation(this)); -} - -void StampsController::removeSelectedC() -{ - class RemoveSavesTask : public Task - { - std::vector stamps; - public: - RemoveSavesTask(std::vector stamps_) { stamps = stamps_; } - virtual void doWork() - { - for(int i = 0; i < stamps.size(); i++) - { - std::stringstream stampID; - stampID << "Deleting stamp [" << stamps[i] << "] ..."; - notifyStatus(stampID.str()); - Client::Ref().DeleteStamp(stamps[i]); - usleep(100*1000); - notifyProgress((float(i+1)/float(stamps.size())*100)); - } - } - }; - - std::vector selected = stampsModel->GetSelected(); - new TaskWindow("Removing saves", new RemoveSavesTask(selected)); - ClearSelection(); - stampsModel->UpdateStampsList(stampsModel->GetPageNum()); -} - -void StampsController::ClearSelection() -{ - stampsModel->ClearSelected(); -} - -void StampsController::NextPage() -{ - if(stampsModel->GetPageNum()>1) - stampsModel->UpdateStampsList(stampsModel->GetPageNum()-1); -} - -void StampsController::PrevPage() -{ - if(stampsModel->GetPageNum() <= stampsModel->GetPageCount()) - stampsModel->UpdateStampsList(stampsModel->GetPageNum()+1); -} - -void StampsController::Update() -{ - if(stampsModel->GetStamp()) - { - Exit(); - } -} - -void StampsController::Selected(std::string stampID, bool selected) -{ - if(selected) - stampsModel->SelectStamp(stampID); - else - stampsModel->DeselectStamp(stampID); -} - -void StampsController::Exit() -{ - if(ui::Engine::Ref().GetWindow() == stampsView) - ui::Engine::Ref().CloseWindow(); - if(callback) - callback->ControllerExit(); - HasDone = true; -} - -StampsController::~StampsController() { - // TODO Auto-generated destructor stub -} - diff --git a/src/stamps/StampsController.h b/src/stamps/StampsController.h deleted file mode 100644 index 70537142a..000000000 --- a/src/stamps/StampsController.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * StampsController.h - * - * Created on: Mar 29, 2012 - * Author: Simon - */ - -#ifndef STAMPSCONTROLLER_H_ -#define STAMPSCONTROLLER_H_ - -#include "Controller.h" -#include "StampsView.h" -#include "search/Save.h" - -class StampsView; -class StampsModel; -class StampsController { - ControllerCallback * callback; - StampsView * stampsView; - StampsModel * stampsModel; -public: - bool HasDone; - StampsController(ControllerCallback * callback); - StampsView * GetView() {return stampsView;} - Save * GetStamp(); - void RemoveSelected(); - void removeSelectedC(); - void ClearSelection(); - void Selected(std::string stampID, bool selected); - void OpenStamp(Save * stamp); - void SetStamp(); - void NextPage(); - void PrevPage(); - void Update(); - void Exit(); - virtual ~StampsController(); -}; - -#endif /* STAMPSCONTROLLER_H_ */ diff --git a/src/stamps/StampsModel.cpp b/src/stamps/StampsModel.cpp deleted file mode 100644 index cfdc72c4b..000000000 --- a/src/stamps/StampsModel.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* - * StampsModel.cpp - * - * Created on: Mar 29, 2012 - * Author: Simon - */ - -#include "StampsModel.h" -#include "StampsView.h" -#include "client/Client.h" -#include "StampsModelException.h" - -StampsModel::StampsModel(): - stamp(NULL), - currentPage(1) -{ - // TODO Auto-generated constructor stub - stampIDs = Client::Ref().GetStamps(); -} - - -std::vector StampsModel::GetStampsList() -{ - return stampsList; -} - -void StampsModel::AddObserver(StampsView * observer) -{ - observers.push_back(observer); - observer->NotifyStampsListChanged(this); - observer->NotifyPageChanged(this); -} - -void StampsModel::notifyStampsListChanged() -{ - for(int i = 0; i < observers.size(); i++) - { - observers[i]->NotifyStampsListChanged(this); - } -} - -void StampsModel::notifyPageChanged() -{ - for(int i = 0; i < observers.size(); i++) - { - observers[i]->NotifyPageChanged(this); - } -} - -Save * StampsModel::GetStamp() -{ - return stamp; -} - -void StampsModel::SetStamp(Save * newStamp) -{ - if(stamp) - delete stamp; - stamp = new Save(*newStamp); -} - -void StampsModel::UpdateStampsList(int pageNumber) -{ - std::vector tempStampsList = stampsList; - stampsList.clear(); - currentPage = pageNumber; - notifyPageChanged(); - notifyStampsListChanged(); - /*notifyStampsListChanged(); - for(int i = 0; i < tempStampsList.size(); i++) - { - delete tempStampsList[i]; - }*/ - - int stampsEnd = pageNumber*20; - - for(int i = stampsEnd-20; iNotifySelectedChanged(this); - } -} - -StampsModel::~StampsModel() { - if(stamp) - delete stamp; -} - diff --git a/src/stamps/StampsModel.h b/src/stamps/StampsModel.h deleted file mode 100644 index 48d3c38eb..000000000 --- a/src/stamps/StampsModel.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * StampsModel.h - * - * Created on: Mar 29, 2012 - * Author: Simon - */ - -#ifndef STAMPSMODEL_H_ -#define STAMPSMODEL_H_ - -#include -#include -#include -#include "search/Save.h" - -class StampsView; -class StampsModel { - vector selected; - Save * stamp; - std::vector stampIDs; - std::vector stampsList; - std::vector observers; - int currentPage; - void notifyStampsListChanged(); - void notifyPageChanged(); - void notifySelectedChanged(); -public: - StampsModel(); - int GetPageCount() { return max(1, (int)(ceil(stampIDs.size()/16))); } - int GetPageNum() { return currentPage; } - void AddObserver(StampsView * observer); - std::vector GetStampsList(); - void UpdateStampsList(int pageNumber); - Save * GetStamp(); - void SetStamp(Save * newStamp); - vector GetSelected() { return selected; } - void ClearSelected() { selected.clear(); notifySelectedChanged(); } - void SelectStamp(std::string stampID); - void DeselectStamp(std::string stampID); - virtual ~StampsModel(); -}; - -#endif /* STAMPSMODEL_H_ */ diff --git a/src/stamps/StampsModelException.h b/src/stamps/StampsModelException.h deleted file mode 100644 index 7310aa0f4..000000000 --- a/src/stamps/StampsModelException.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * StampsModelException.h - * - * Created on: Mar 29, 2012 - * Author: Simon - */ - -#ifndef STAMPSMODELEXCEPTION_H_ -#define STAMPSMODELEXCEPTION_H_ - -#include -#include -using namespace std; - -class StampsModelException { - string message; -public: - StampsModelException(string message_): message(message_) {}; - const char * what() const throw() { return message.c_str(); }; - ~StampsModelException() throw() {}; -}; - -#endif /* STAMPSMODELEXCEPTION_H_ */ diff --git a/src/stamps/StampsView.cpp b/src/stamps/StampsView.cpp deleted file mode 100644 index 249248e79..000000000 --- a/src/stamps/StampsView.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/* - * StampsView.cpp - * - * Created on: Mar 29, 2012 - * Author: Simon - */ - -#include -#include "client/Client.h" -#include "StampsView.h" - -#include "dialogues/ErrorMessage.h" -#include "StampsController.h" -#include "StampsModel.h" -#include "StampsModelException.h" - -StampsView::StampsView(): - ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)) -{ - 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..."); - AddComponent(infoLabel); - AddComponent(nextButton); - AddComponent(previousButton); - - class NextPageAction : public ui::ButtonAction - { - StampsView * v; - public: - NextPageAction(StampsView * _v) { v = _v; } - void ActionCallback(ui::Button * sender) - { - v->c->NextPage(); - } - }; - nextButton->SetActionCallback(new NextPageAction(this)); - nextButton->Appearance.HorizontalAlign = ui::Appearance::AlignRight; nextButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom; - - class PrevPageAction : public ui::ButtonAction - { - StampsView * v; - public: - PrevPageAction(StampsView * _v) { v = _v; } - void ActionCallback(ui::Button * sender) - { - v->c->PrevPage(); - } - }; - previousButton->SetActionCallback(new PrevPageAction(this)); - previousButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; previousButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom; - - class RemoveSelectedAction : public ui::ButtonAction - { - StampsView * v; - public: - RemoveSelectedAction(StampsView * _v) { v = _v; } - void ActionCallback(ui::Button * sender) - { - v->c->RemoveSelected(); - } - }; - - removeSelected = new ui::Button(ui::Point((((XRES+BARSIZE)-100)/2), YRES+MENUSIZE-18), ui::Point(100, 16), "Delete"); - removeSelected->Visible = false; - removeSelected->SetActionCallback(new RemoveSelectedAction(this)); - AddComponent(removeSelected); -} - -void StampsView::OnTick(float dt) -{ - c->Update(); -} - -void StampsView::NotifyPageChanged(StampsModel * 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 StampsView::NotifyStampsListChanged(StampsModel * sender) -{ - int i = 0; - int buttonWidth, buttonHeight, saveX = 0, saveY = 0, savesX = 5, savesY = 4, buttonPadding = 2; - int buttonAreaWidth, buttonAreaHeight, buttonXOffset, buttonYOffset; - - vector saves = sender->GetStampsList(); - for(i = 0; i < stampButtons.size(); i++) - { - RemoveComponent(stampButtons[i]); - delete stampButtons[i]; - } - stampButtons.clear(); - buttonXOffset = 0; - buttonYOffset = 50; - buttonAreaWidth = Size.X; - buttonAreaHeight = Size.Y - buttonYOffset - 18; - buttonWidth = (buttonAreaWidth/savesX) - buttonPadding*2; - buttonHeight = (buttonAreaHeight/savesY) - buttonPadding*2; - class SaveOpenAction: public ui::SaveButtonAction - { - StampsView * v; - public: - SaveOpenAction(StampsView * _v) { v = _v; } - virtual void ActionCallback(ui::SaveButton * sender) - { - v->c->OpenStamp(sender->GetSave()); - } - virtual void SelectedCallback(ui::SaveButton * sender) - { - v->c->Selected(sender->GetSave()->GetName(), sender->GetSelected()); - } - }; - for(i = 0; i < saves.size(); i++) - { - if(saveX == savesX) - { - if(saveY == savesY-1) - break; - saveX = 0; - saveY++; - } - ui::SaveButton * saveButton; - saveButton = new ui::SaveButton( - ui::Point( - buttonXOffset + buttonPadding + saveX*(buttonWidth+buttonPadding*2), - buttonYOffset + buttonPadding + saveY*(buttonHeight+buttonPadding*2) - ), - ui::Point(buttonWidth, buttonHeight), - saves[i]); - saveButton->SetSelectable(true); - saveButton->SetActionCallback(new SaveOpenAction(this)); - stampButtons.push_back(saveButton); - AddComponent(saveButton); - saveX++; - } -} - -void StampsView::NotifySelectedChanged(StampsModel * sender) -{ - vector selected = sender->GetSelected(); - for(int j = 0; j < stampButtons.size(); j++) - { - stampButtons[j]->SetSelected(false); - for(int i = 0; i < selected.size(); i++) - { - if(stampButtons[j]->GetSave()->GetName()==selected[i]) - stampButtons[j]->SetSelected(true); - } - } - - if(selected.size()) - { - removeSelected->Visible = true; - } - else - removeSelected->Visible = false; -} - -void StampsView::OnMouseWheel(int x, int y, int d) -{ - if(!d) - return; - if(d<0) - c->NextPage(); - else - c->PrevPage(); -} -void StampsView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) -{ - if(key==KEY_ESCAPE) - c->Exit(); -} - -StampsView::~StampsView() { - // TODO Auto-generated destructor stub -} - diff --git a/src/stamps/StampsView.h b/src/stamps/StampsView.h deleted file mode 100644 index 026461196..000000000 --- a/src/stamps/StampsView.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * StampsView.h - * - * Created on: Mar 29, 2012 - * Author: Simon - */ - -#ifndef STAMPSVIEW_H_ -#define STAMPSVIEW_H_ - -#include -#include "interface/Window.h" -#include "interface/Button.h" -#include "interface/Textbox.h" -#include "interface/Label.h" -#include "interface/SaveButton.h" - -class StampsController; -class StampsModel; -class StampsView: public ui::Window { - StampsController * c; - std::vector stampButtons; - ui::Button * previousButton; - ui::Button * nextButton; - ui::Label * infoLabel; - ui::Button * removeSelected; -public: - StampsView(); - //virtual void OnDraw(); - virtual void OnTick(float dt); - void AttachController(StampsController * c_) { c = c_; }; - void NotifyPageChanged(StampsModel * sender); - void NotifyStampsListChanged(StampsModel * sender); - void NotifySelectedChanged(StampsModel * sender); - virtual void OnMouseWheel(int x, int y, int d); - virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - virtual ~StampsView(); -}; - -#endif /* STAMPSVIEW_H_ */