blob: adb8cad1d038b46e0a1a7dbb1faa4c83456dd2bd (
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#include "SearchModel.h"
#include "Save.h"
#include "client/Client.h"
SearchModel::SearchModel():
currentSort("votes"),
showOwn(false)
{
}
void SearchModel::UpdateSaveList(int pageNumber, std::string query)
{
lastQuery = query;
lastError = "";
saveList.clear();
currentPage = 1;
resultCount = 0;
notifySaveListChanged();
notifyPageChanged();
vector<Save*> * tempSaveList = Client::Ref().SearchSaves((pageNumber-1)*12, 12, query, currentSort, resultCount);
saveList = *tempSaveList;
delete tempSaveList;
if(!saveList.size())
{
lastError = Client::Ref().GetLastError();
}
currentPage = pageNumber;
notifyPageChanged();
notifySaveListChanged();
}
vector<Save*> SearchModel::GetSaveList()
{
return saveList;
}
void SearchModel::AddObserver(SearchView * observer)
{
observers.push_back(observer);
observer->NotifySaveListChanged(this);
observer->NotifyPageChanged(this);
observer->NotifySortChanged(this);
observer->NotifyShowOwnChanged(this);
}
void SearchModel::notifySaveListChanged()
{
for(int i = 0; i < observers.size(); i++)
{
SearchView* cObserver = observers[i];
cObserver->NotifySaveListChanged(this);
}
}
void SearchModel::notifyPageChanged()
{
for(int i = 0; i < observers.size(); i++)
{
SearchView* cObserver = observers[i];
cObserver->NotifyPageChanged(this);
}
}
void SearchModel::notifySortChanged()
{
for(int i = 0; i < observers.size(); i++)
{
SearchView* cObserver = observers[i];
cObserver->NotifySortChanged(this);
}
}
void SearchModel::notifyShowOwnChanged()
{
for(int i = 0; i < observers.size(); i++)
{
SearchView* cObserver = observers[i];
cObserver->NotifyShowOwnChanged(this);
}
}
|