serverlistfilterinfo.cpp
1 //------------------------------------------------------------------------------
2 // serverlistfilterinfo.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2011 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "serverlistfilterinfo.h"
24 
25 ServerListFilterInfo::ServerListFilterInfo()
26 {
27  bEnabled = true;
28  bShowEmpty = true;
29  bShowFull = true;
30  bShowOnlyValid = false;
31  bShowBannedServers = true;
32  bShowTooSoonServers = true;
33  bShowNotRespondingServers = true;
34  lockedServers = Doomseeker::Indifferent;
35  maxPing = 0;
36  testingServers = Doomseeker::Indifferent;
38 }
39 
40 void ServerListFilterInfo::copy(const ServerListFilterInfo &other)
41 {
42  name = other.name;
43  bEnabled = other.bEnabled;
44  bShowEmpty = other.bShowEmpty;
45  bShowFull = other.bShowFull;
46  bShowOnlyValid = other.bShowOnlyValid;
47  bShowBannedServers = other.bShowBannedServers;
48  bShowTooSoonServers = other.bShowTooSoonServers;
49  bShowNotRespondingServers = other.bShowNotRespondingServers;
50  gameModes = other.gameModes;
51  gameModesExcluded = other.gameModesExcluded;
52  lockedServers = other.lockedServers;
53  maxPing = other.maxPing;
54  serverName = other.serverName.trimmed();
55  testingServers = other.testingServers;
57 
58  copyTrimmed(this->wads, other.wads);
59  copyTrimmed(this->wadsExcluded, other.wadsExcluded);
60 }
61 
62 void ServerListFilterInfo::copyTrimmed(QStringList &target, const QStringList &source) const
63 {
64  target.clear();
65  for (QString element : source)
66  {
67  element = element.trimmed();
68  if (!element.isEmpty())
69  target << element;
70  }
71 }
72 
74 {
75  if (!serverName.isEmpty())
76  return true;
77 
78  if (!bEnabled)
79  return false;
80 
81  if (!bShowEmpty || !bShowFull)
82  return true;
83 
84  if (bShowOnlyValid
85  || !bShowBannedServers
86  || !bShowTooSoonServers
87  || !bShowNotRespondingServers)
88  {
89  return true;
90  }
91 
92  if (maxPing > 0)
93  return true;
94 
95  if (!gameModes.isEmpty()
96  || !gameModesExcluded.isEmpty()
97  || !wads.isEmpty()
98  || !wadsExcluded.isEmpty())
99  {
100  return true;
101  }
102 
103  if (lockedServers != Doomseeker::Indifferent
104  || testingServers != Doomseeker::Indifferent)
105  {
106  return true;
107  }
108 
109  return false;
110 }
111 
113 {
114  return
115  bEnabled == other.bEnabled &&
116  bShowEmpty == other.bShowEmpty &&
117  bShowFull == other.bShowFull &&
118  bShowOnlyValid == other.bShowOnlyValid &&
119  bShowBannedServers == other.bShowBannedServers &&
120  bShowTooSoonServers == other.bShowTooSoonServers &&
121  bShowNotRespondingServers == other.bShowNotRespondingServers &&
122  gameModes == other.gameModes &&
123  gameModesExcluded == other.gameModesExcluded &&
124  lockedServers == other.lockedServers &&
125  maxPing == other.maxPing &&
126  serverName == other.serverName &&
127  wads == other.wads &&
128  wadsExcluded == other.wadsExcluded &&
129  testingServers == other.testingServers &&
131  ;
132 }
133 
134 
135 ServerListFilterInfo ServerListFilterInfo::deserialize(const QVariant &variant)
136 {
138 
139  QVariantMap in = variant.toMap();
140  obj.name = in["name"].toString();
141  obj.bEnabled = in["bEnabled"].toBool();
142  obj.bShowEmpty = in["bShowEmpty"].toBool();
143  obj.bShowFull = in["bShowFull"].toBool();
144  obj.bShowOnlyValid = in["bShowOnlyValid"].toBool();
145  obj.bShowBannedServers = in["bShowBannedServers"].toBool();
146  obj.bShowTooSoonServers = in["bShowTooSoonServers"].toBool();
147  obj.bShowNotRespondingServers = in["bShowNotRespondingServers"].toBool();
148  obj.gameModes = in["GameModes"].toStringList();
149  obj.gameModesExcluded = in["GameModesExcluded"].toStringList();
150  obj.lockedServers = static_cast<Doomseeker::ShowMode>(in["LockedServers"].toInt());
151  obj.maxPing = in["MaxPing"].toUInt();
152  obj.serverName = in["ServerName"].toString();
153  obj.testingServers = static_cast<Doomseeker::ShowMode>(in["TestingServers"].toInt());
154  obj.wads = in["WADs"].toStringList();
155  obj.wadsExcluded = in["WADsExcluded"].toStringList();
156  obj.bPopulatedServersOnTop = in["bPopulatedServersOnTop"].toBool();
157  return obj;
158 }
159 
160 QVariant ServerListFilterInfo::serialize() const
161 {
162  QVariantMap out;
163  out["name"] = this->name;
164  out["bEnabled"] = this->bEnabled;
165  out["bShowEmpty"] = this->bShowEmpty;
166  out["bShowFull"] = this->bShowFull;
167  out["bShowOnlyValid"] = this->bShowOnlyValid;
168  out["bShowBannedServers"] = this->bShowBannedServers;
169  out["bShowTooSoonServers"] = this->bShowTooSoonServers;
170  out["bShowNotRespondingServers"] = this->bShowNotRespondingServers;
171  out["GameModes"] = this->gameModes;
172  out["GameModesExcluded"] = this->gameModesExcluded;
173  out["LockedServers"] = this->lockedServers;
174  out["MaxPing"] = this->maxPing;
175  out["ServerName"] = this->serverName;
176  out["TestingServers"] = this->testingServers;
177  out["WADs"].setValue(this->wads);
178  out["WADsExcluded"].setValue(this->wadsExcluded);
179  out["bPopulatedServersOnTop"] = this->bPopulatedServersOnTop;
180  return out;
181 }
182 
183 QString ServerListFilterInfo::toString() const
184 {
185  QString ret = "";
186 
187  ret += QString("name: %1\n").arg(name);
188  ret += QString("bEnabled: ") + (bEnabled ? "Yes" : "No") + "\n";
189  ret += QString("bShowEmpty: ") + (bShowEmpty ? "Yes" : "No") + "\n";
190  ret += QString("bShowFull: ") + (bShowFull ? "Yes" : "No") + "\n";
191  ret += QString("bShowOnlyValid: ") + (bShowOnlyValid ? "Yes" : "No") + "\n";
192  ret += QString("bShowBannedServers: ") + (bShowBannedServers ? "Yes" : "No") + "\n";
193  ret += QString("bShowTooSoonServers: ") + (bShowTooSoonServers ? "Yes" : "No") + "\n";
194  ret += QString("bShowNotRespondingServers: ") + (bShowNotRespondingServers ? "Yes" : "No") + "\n";
195 
196  ret += QString("GameModes: ") + gameModes.join(",") + "\n";
197  ret += QString("GameModes Excluded: ") + gameModesExcluded.join(",") + "\n";
198  ret += QString("LockedServers: %1\n").arg(lockedServers);
199  ret += QString("MaxPing: ") + QString::number(maxPing) + "\n";
200  ret += QString("ServerName: ") + serverName + "\n";
201  ret += QString("Testing servers: %1\n").arg(testingServers);
202  ret += QString("WADs: ") + wads.join(",") + "\n";
203  ret += QString("WADs Excluded: ") + wadsExcluded.join(",") + "\n";
204  ret += QString("bPopulatedServersOnTop: ") + (bPopulatedServersOnTop ? "Yes" : "No") + "\n";
205 
206  return ret;
207 }