Remove unneeded files

This commit is contained in:
Simon Robertshaw 2012-06-07 16:16:54 +01:00
parent 61ed6e0276
commit 1dadb11fc2
9 changed files with 0 additions and 790 deletions

View File

@ -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<string> 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<string> tags)
{
this->tags = tags;
}
vector<string> 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;
}

View File

@ -1,69 +0,0 @@
#ifndef SAVE_H
#define SAVE_H
#include <vector>
#include <string>
#include <stdlib.h>
#include <iostream>
#include <string.h>
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<string> tags);
~Save();
string userName;
string name;
string Description;
vector<string> 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<string> tags);
vector<string> GetTags();
unsigned char * GetData();
void SetData(unsigned char * data_, int dataLength);
int GetDataLength();
};
#endif // SAVE_H

View File

@ -1,135 +0,0 @@
/*
* StampsController.cpp
*
* Created on: Mar 29, 2012
* Author: Simon
*/
#include <sstream>
#include <unistd.h>
#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<std::string> stamps;
public:
RemoveSavesTask(std::vector<std::string> 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<std::string> 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
}

View File

@ -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_ */

View File

@ -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<Save *> 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<Save*> 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; i<stampIDs.size() && i<stampsEnd; i++)
{
Save * tempSave = Client::Ref().GetStamp(stampIDs[i]);
if(tempSave)
{
stampsList.push_back(tempSave);
}
}
notifyStampsListChanged();
}
void StampsModel::SelectStamp(std::string stampID)
{
for(int i = 0; i < selected.size(); i++)
{
if(selected[i]==stampID)
{
return;
}
}
selected.push_back(stampID);
notifySelectedChanged();
}
void StampsModel::DeselectStamp(std::string stampID)
{
bool changed = false;
restart:
for(int i = 0; i < selected.size(); i++)
{
if(selected[i]==stampID)
{
selected.erase(selected.begin()+i);
changed = true;
goto restart; //Just ensure all cases are removed.
}
}
if(changed)
notifySelectedChanged();
}
void StampsModel::notifySelectedChanged()
{
for(int i = 0; i < observers.size(); i++)
{
StampsView* cObserver = observers[i];
cObserver->NotifySelectedChanged(this);
}
}
StampsModel::~StampsModel() {
if(stamp)
delete stamp;
}

View File

@ -1,43 +0,0 @@
/*
* StampsModel.h
*
* Created on: Mar 29, 2012
* Author: Simon
*/
#ifndef STAMPSMODEL_H_
#define STAMPSMODEL_H_
#include <vector>
#include <string>
#include <cmath>
#include "search/Save.h"
class StampsView;
class StampsModel {
vector<std::string> selected;
Save * stamp;
std::vector<std::string> stampIDs;
std::vector<Save*> stampsList;
std::vector<StampsView*> 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<Save *> GetStampsList();
void UpdateStampsList(int pageNumber);
Save * GetStamp();
void SetStamp(Save * newStamp);
vector<std::string> GetSelected() { return selected; }
void ClearSelected() { selected.clear(); notifySelectedChanged(); }
void SelectStamp(std::string stampID);
void DeselectStamp(std::string stampID);
virtual ~StampsModel();
};
#endif /* STAMPSMODEL_H_ */

View File

@ -1,23 +0,0 @@
/*
* StampsModelException.h
*
* Created on: Mar 29, 2012
* Author: Simon
*/
#ifndef STAMPSMODELEXCEPTION_H_
#define STAMPSMODELEXCEPTION_H_
#include <string>
#include <exception>
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_ */

View File

@ -1,195 +0,0 @@
/*
* StampsView.cpp
*
* Created on: Mar 29, 2012
* Author: Simon
*/
#include <sstream>
#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<Save*> 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<std::string> 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
}

View File

@ -1,40 +0,0 @@
/*
* StampsView.h
*
* Created on: Mar 29, 2012
* Author: Simon
*/
#ifndef STAMPSVIEW_H_
#define STAMPSVIEW_H_
#include <vector>
#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<ui::SaveButton*> 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_ */