summaryrefslogtreecommitdiff
path: root/src/search/SearchModel.cpp
blob: 3b2d0e08557e3275bfc847d57d3ca489b2f4385c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "SearchModel.h"
#include "Save.h"

#include "client/Client.h"

SearchModel::SearchModel()
{
}

void SearchModel::UpdateSaveList(std::string query)
{
	lastError = "";
	saveList.clear();
	notifySaveListChanged();
	vector<Save*> * tempSaveList = Client::Ref().SearchSaves(0, 12, query, "");
	saveList = *tempSaveList;
	delete tempSaveList;
	if(!saveList.size())
	{
		lastError = Client::Ref().GetLastError();
	}
	/*for(int i = 0; i < 16; i++)
	{
		saveList.push_back(Save(2198, 2333, 315, "dima-gord", "Destroyable city 5 (wth metro)"));
	}*/
	notifySaveListChanged();
}

vector<Save*> SearchModel::GetSaveList()
{
	return saveList;
}

void SearchModel::AddObserver(SearchView * observer)
{
	observers.push_back(observer);
	observer->NotifySaveListChanged(this);
}

void SearchModel::notifySaveListChanged()
{
	for(int i = 0; i < observers.size(); i++)
	{
		SearchView* cObserver = observers[i];
		cObserver->NotifySaveListChanged(this);
	}
}