serverlistfilterinfo.cpp
1 //------------------------------------------------------------------------------
2 // serverlistfilterinfo.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program 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
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; 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  maxPing = 0;
32 }
33 
34 void ServerListFilterInfo::copy(const ServerListFilterInfo& other)
35 {
36  bEnabled = other.bEnabled;
37  bShowEmpty = other.bShowEmpty;
38  bShowFull = other.bShowFull;
39  bShowOnlyValid = other.bShowOnlyValid;
40  gameModes = other.gameModes;
41  gameModesExcluded = other.gameModesExcluded;
42  maxPing = other.maxPing;
43  serverName = other.serverName.trimmed();
44 
45  copyTrimmed(this->wads, other.wads);
46  copyTrimmed(this->wadsExcluded, other.wadsExcluded);
47 }
48 
49 void ServerListFilterInfo::copyTrimmed(QStringList& target, const QStringList& source) const
50 {
51  target.clear();
52  foreach (QString element, source)
53  {
54  element = element.trimmed();
55  if (!element.isEmpty())
56  {
57  target << element;
58  }
59  }
60 }
61 
63 {
64  if (!bEnabled)
65  {
66  return false;
67  }
68 
69  if (!bShowEmpty || !bShowFull)
70  {
71  return true;
72  }
73 
74  if (bShowOnlyValid || maxPing > 0)
75  {
76  return true;
77  }
78 
79  if (!gameModes.isEmpty()
80  || !gameModesExcluded.isEmpty()
81  || !serverName.isEmpty()
82  || !wads.isEmpty()
83  || !wadsExcluded.isEmpty())
84  {
85  return true;
86  }
87 
88  return false;
89 }
90 
91 QString ServerListFilterInfo::toString() const
92 {
93  QString ret = "";
94 
95  ret += QString("bEnabled: ") + (bEnabled ? "Yes" : "No") + "\n";
96  ret += QString("bShowEmpty: ") + (bShowEmpty ? "Yes" : "No") + "\n";
97  ret += QString("bShowFull: ") + (bShowFull ? "Yes" : "No") + "\n";
98  ret += QString("bShowOnlyValid: ") + (bShowOnlyValid ? "Yes" : "No") + "\n";
99  ret += QString("GameModes: ") + gameModes.join(",") + "\n";
100  ret += QString("GameModes Excluded: ") + gameModesExcluded.join(",") + "\n";
101  ret += QString("MaxPing: ") + QString::number(maxPing) + "\n";
102  ret += QString("ServerName: ") + serverName + "\n";
103  ret += QString("WADs: ") + wads.join(",") + "\n";
104  ret += QString("WADs Excluded: ") + wadsExcluded.join(",") + "\n";
105 
106  return ret;
107 }
108 
Structure describing server filter.
unsigned maxPing
Maximum allowed ping.
bool isFilteringAnything() const
Informs if filter will apply to any server.