1 #include "gamefilterssettings.h"
2
3 #include <QCryptographicHash>
4 #include <QTime>
5
GameFiltersSettings(QString settingPath,QObject * parent)6 GameFiltersSettings::GameFiltersSettings(QString settingPath, QObject *parent)
7 : SettingsManager(settingPath + "gamefilters.ini", parent)
8 {
9 }
10
11 /*
12 * The game type might contain special characters, so to use it in
13 * QSettings we just hash it.
14 */
hashGameType(const QString & gameType) const15 QString GameFiltersSettings::hashGameType(const QString &gameType) const
16 {
17 return QCryptographicHash::hash(gameType.toUtf8(), QCryptographicHash::Md5).toHex();
18 }
19
setShowBuddiesOnlyGames(bool show)20 void GameFiltersSettings::setShowBuddiesOnlyGames(bool show)
21 {
22 setValue(show, "show_buddies_only_games", "filter_games");
23 }
24
isShowBuddiesOnlyGames()25 bool GameFiltersSettings::isShowBuddiesOnlyGames()
26 {
27 QVariant previous = getValue("show_buddies_only_games", "filter_games");
28 return previous == QVariant() ? true : previous.toBool();
29 }
30
setShowFullGames(bool show)31 void GameFiltersSettings::setShowFullGames(bool show)
32 {
33 setValue(show, "show_full_games", "filter_games");
34 }
35
isShowFullGames()36 bool GameFiltersSettings::isShowFullGames()
37 {
38 QVariant previous = getValue("show_full_games", "filter_games");
39 return previous == QVariant() ? false : previous.toBool();
40 }
41
setShowGamesThatStarted(bool show)42 void GameFiltersSettings::setShowGamesThatStarted(bool show)
43 {
44 setValue(show, "show_games_that_started", "filter_games");
45 }
46
isShowGamesThatStarted()47 bool GameFiltersSettings::isShowGamesThatStarted()
48 {
49 QVariant previous = getValue("show_games_that_started", "filter_games");
50 return previous == QVariant() ? false : previous.toBool();
51 }
52
setShowPasswordProtectedGames(bool show)53 void GameFiltersSettings::setShowPasswordProtectedGames(bool show)
54 {
55 setValue(show, "show_password_protected_games", "filter_games");
56 }
57
isShowPasswordProtectedGames()58 bool GameFiltersSettings::isShowPasswordProtectedGames()
59 {
60 QVariant previous = getValue("show_password_protected_games", "filter_games");
61 return previous == QVariant() ? true : previous.toBool();
62 }
63
setHideIgnoredUserGames(bool hide)64 void GameFiltersSettings::setHideIgnoredUserGames(bool hide)
65 {
66 setValue(hide, "hide_ignored_user_games", "filter_games");
67 }
68
isHideIgnoredUserGames()69 bool GameFiltersSettings::isHideIgnoredUserGames()
70 {
71 QVariant previous = getValue("hide_ignored_user_games", "filter_games");
72 return previous == QVariant() ? false : previous.toBool();
73 }
74
setGameNameFilter(QString gameName)75 void GameFiltersSettings::setGameNameFilter(QString gameName)
76 {
77 setValue(gameName, "game_name_filter", "filter_games");
78 }
79
getGameNameFilter()80 QString GameFiltersSettings::getGameNameFilter()
81 {
82 return getValue("game_name_filter", "filter_games").toString();
83 }
84
setCreatorNameFilter(QString creatorName)85 void GameFiltersSettings::setCreatorNameFilter(QString creatorName)
86 {
87 setValue(creatorName, "creator_name_filter", "filter_games");
88 }
89
getCreatorNameFilter()90 QString GameFiltersSettings::getCreatorNameFilter()
91 {
92 return getValue("creator_name_filter", "filter_games").toString();
93 }
94
setMinPlayers(int min)95 void GameFiltersSettings::setMinPlayers(int min)
96 {
97 setValue(min, "min_players", "filter_games");
98 }
99
getMinPlayers()100 int GameFiltersSettings::getMinPlayers()
101 {
102 QVariant previous = getValue("min_players", "filter_games");
103 return previous == QVariant() ? 1 : previous.toInt();
104 }
105
setMaxPlayers(int max)106 void GameFiltersSettings::setMaxPlayers(int max)
107 {
108 setValue(max, "max_players", "filter_games");
109 }
110
getMaxPlayers()111 int GameFiltersSettings::getMaxPlayers()
112 {
113 QVariant previous = getValue("max_players", "filter_games");
114 return previous == QVariant() ? 99 : previous.toInt();
115 }
116
setMaxGameAge(const QTime & maxGameAge)117 void GameFiltersSettings::setMaxGameAge(const QTime &maxGameAge)
118 {
119 setValue(maxGameAge, "max_game_age_time", "filter_games");
120 }
121
getMaxGameAge()122 QTime GameFiltersSettings::getMaxGameAge()
123 {
124 QVariant previous = getValue("max_game_age_time", "filter_games");
125 return previous.toTime();
126 }
127
setGameTypeEnabled(QString gametype,bool enabled)128 void GameFiltersSettings::setGameTypeEnabled(QString gametype, bool enabled)
129 {
130 setValue(enabled, "game_type/" + hashGameType(gametype), "filter_games");
131 }
132
setGameHashedTypeEnabled(QString gametypeHASHED,bool enabled)133 void GameFiltersSettings::setGameHashedTypeEnabled(QString gametypeHASHED, bool enabled)
134 {
135 setValue(enabled, gametypeHASHED, "filter_games");
136 }
137
isGameTypeEnabled(QString gametype)138 bool GameFiltersSettings::isGameTypeEnabled(QString gametype)
139 {
140 QVariant previous = getValue("game_type/" + hashGameType(gametype), "filter_games");
141 return previous == QVariant() ? false : previous.toBool();
142 }
143
setShowOnlyIfSpectatorsCanWatch(bool show)144 void GameFiltersSettings::setShowOnlyIfSpectatorsCanWatch(bool show)
145 {
146 setValue(show, "show_only_if_spectators_can_watch", "filter_games");
147 }
148
isShowOnlyIfSpectatorsCanWatch()149 bool GameFiltersSettings::isShowOnlyIfSpectatorsCanWatch()
150 {
151 QVariant previous = getValue("show_only_if_spectators_can_watch", "filter_games");
152 return previous == QVariant() ? false : previous.toBool();
153 }
154
setShowSpectatorPasswordProtected(bool show)155 void GameFiltersSettings::setShowSpectatorPasswordProtected(bool show)
156 {
157 setValue(show, "show_spectator_password_protected", "filter_games");
158 }
159
isShowSpectatorPasswordProtected()160 bool GameFiltersSettings::isShowSpectatorPasswordProtected()
161 {
162 QVariant previous = getValue("show_spectator_password_protected", "filter_games");
163 return previous == QVariant() ? true : previous.toBool();
164 }
165
setShowOnlyIfSpectatorsCanChat(bool show)166 void GameFiltersSettings::setShowOnlyIfSpectatorsCanChat(bool show)
167 {
168 setValue(show, "show_only_if_spectators_can_chat", "filter_games");
169 }
170
isShowOnlyIfSpectatorsCanChat()171 bool GameFiltersSettings::isShowOnlyIfSpectatorsCanChat()
172 {
173 QVariant previous = getValue("show_only_if_spectators_can_chat", "filter_games");
174 return previous == QVariant() ? true : previous.toBool();
175 }
176
setShowOnlyIfSpectatorsCanSeeHands(bool show)177 void GameFiltersSettings::setShowOnlyIfSpectatorsCanSeeHands(bool show)
178 {
179 setValue(show, "show_only_if_spectators_can_see_hands", "filter_games");
180 }
181
isShowOnlyIfSpectatorsCanSeeHands()182 bool GameFiltersSettings::isShowOnlyIfSpectatorsCanSeeHands()
183 {
184 QVariant previous = getValue("show_only_if_spectators_can_see_hands", "filter_games");
185 return previous == QVariant() ? true : previous.toBool();
186 }