/
SearchModel.h
89 lines (82 loc) · 2.75 KB
/
SearchModel.h
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
82
83
84
85
86
87
88
89
#ifndef SEARCHMODEL_H
#define SEARCHMODEL_H
#include <vector>
#include <string>
#include <pthread.h>
#undef GetUserName //God dammit microsoft!
#include <cmath>
#include "client/SaveInfo.h"
#include "SearchView.h"
using namespace std;
class SearchView;
class SearchModel
{
private:
SaveInfo * loadedSave;
string currentSort;
string lastQuery;
string lastError;
vector<int> selected;
vector<SearchView*> observers;
vector<SaveInfo*> saveList;
vector<pair<string, int> > tagList;
int currentPage;
int resultCount;
int thResultCount;
bool showOwn;
bool showFavourite;
bool showTags;
void notifySaveListChanged();
void notifyTagListChanged();
void notifySelectedChanged();
void notifyPageChanged();
void notifySortChanged();
void notifyShowOwnChanged();
void notifyShowFavouriteChanged();
//Variables and methods for background save request
bool saveListLoaded;
bool updateSaveListWorking;
volatile bool updateSaveListFinished;
pthread_t updateSaveListThread;
TH_ENTRY_POINT static void * updateSaveListTHelper(void * obj);
void * updateSaveListT();
bool updateTagListWorking;
volatile bool updateTagListFinished;
pthread_t updateTagListThread;
TH_ENTRY_POINT static void * updateTagListTHelper(void * obj);
void * updateTagListT();
public:
SearchModel();
virtual ~SearchModel();
void SetShowTags(bool show);
bool GetShowTags();
void AddObserver(SearchView * observer);
void UpdateSaveList(int pageNumber, std::string query);
vector<SaveInfo*> GetSaveList();
vector<pair<string, int> > GetTagList();
string GetLastError() { return lastError; }
int GetPageCount()
{
if (!showOwn && !showFavourite && currentSort == "best" && lastQuery == "")
return max(1, (int)(ceil(resultCount/20.0f))+1); //add one for front page (front page saves are repeated twice)
else
return max(1, (int)(ceil(resultCount/20.0f)));
}
int GetPageNum() { return currentPage; }
std::string GetLastQuery() { return lastQuery; }
void SetSort(string sort) { if(!updateSaveListWorking) { currentSort = sort; } notifySortChanged(); }
string GetSort() { return currentSort; }
void SetShowOwn(bool show) { if(!updateSaveListWorking) { if(show!=showOwn) { showOwn = show; } } notifyShowOwnChanged(); }
bool GetShowOwn() { return showOwn; }
void SetShowFavourite(bool show) { if(show!=showFavourite && !updateSaveListWorking) { showFavourite = show; } notifyShowFavouriteChanged(); }
bool GetShowFavourite() { return showFavourite; }
void SetLoadedSave(SaveInfo * save);
SaveInfo * GetLoadedSave();
bool GetSavesLoaded() { return saveListLoaded; }
vector<int> GetSelected() { return selected; }
void ClearSelected() { selected.clear(); notifySelectedChanged(); }
void SelectSave(int saveID);
void DeselectSave(int saveID);
void Update();
};
#endif // SEARCHMODEL_H