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  maxPing = 0;
32  testingServers = Doomseeker::Indifferent;
33 }
34 
35 void ServerListFilterInfo::copy(const ServerListFilterInfo& other)
36 {
37  bEnabled = other.bEnabled;
38  bShowEmpty = other.bShowEmpty;
39  bShowFull = other.bShowFull;
40  bShowOnlyValid = other.bShowOnlyValid;
41  gameModes = other.gameModes;
42  gameModesExcluded = other.gameModesExcluded;
43  maxPing = other.maxPing;
44  serverName = other.serverName.trimmed();
45  testingServers = other.testingServers;
46 
47  copyTrimmed(this->wads, other.wads);
48  copyTrimmed(this->wadsExcluded, other.wadsExcluded);
49 }
50 
51 void ServerListFilterInfo::copyTrimmed(QStringList& target, const QStringList& source) const
52 {
53  target.clear();
54  foreach (QString element, source)
55  {
56  element = element.trimmed();
57  if (!element.isEmpty())
58  {
59  target << element;
60  }
61  }
62 }
63 
65 {
66  if (!serverName.isEmpty())
67  {
68  return true;
69  }
70 
71  if (!bEnabled)
72  {
73  return false;
74  }
75 
76  if (!bShowEmpty || !bShowFull)
77  {
78  return true;
79  }
80 
81  if (bShowOnlyValid || maxPing > 0)
82  {
83  return true;
84  }
85 
86  if (!gameModes.isEmpty()
87  || !gameModesExcluded.isEmpty()
88  || !wads.isEmpty()
89  || !wadsExcluded.isEmpty())
90  {
91  return true;
92  }
93 
94  if (testingServers != Doomseeker::Indifferent)
95  {
96  return true;
97  }
98 
99  return false;
100 }
101 
102 QString ServerListFilterInfo::toString() const
103 {
104  QString ret = "";
105 
106  ret += QString("bEnabled: ") + (bEnabled ? "Yes" : "No") + "\n";
107  ret += QString("bShowEmpty: ") + (bShowEmpty ? "Yes" : "No") + "\n";
108  ret += QString("bShowFull: ") + (bShowFull ? "Yes" : "No") + "\n";
109  ret += QString("bShowOnlyValid: ") + (bShowOnlyValid ? "Yes" : "No") + "\n";
110  ret += QString("GameModes: ") + gameModes.join(",") + "\n";
111  ret += QString("GameModes Excluded: ") + gameModesExcluded.join(",") + "\n";
112  ret += QString("MaxPing: ") + QString::number(maxPing) + "\n";
113  ret += QString("ServerName: ") + serverName + "\n";
114  ret += QString("Testing servers: %1\n").arg(testingServers);
115  ret += QString("WADs: ") + wads.join(",") + "\n";
116  ret += QString("WADs Excluded: ") + wadsExcluded.join(",") + "\n";
117 
118  return ret;
119 }
Structure describing server filter.
unsigned maxPing
Maximum allowed ping.
bool isFilteringAnything() const
Informs if filter will apply to any server.