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  for (QString element : source)
55  {
56  element = element.trimmed();
57  if (!element.isEmpty())
58  target << element;
59  }
60 }
61 
63 {
64  if (!serverName.isEmpty())
65  return true;
66 
67  if (!bEnabled)
68  return false;
69 
70  if (!bShowEmpty || !bShowFull)
71  return true;
72 
73  if (bShowOnlyValid || maxPing > 0)
74  return true;
75 
76  if (!gameModes.isEmpty()
77  || !gameModesExcluded.isEmpty()
78  || !wads.isEmpty()
79  || !wadsExcluded.isEmpty())
80  {
81  return true;
82  }
83 
84  if (testingServers != Doomseeker::Indifferent)
85  return true;
86 
87  return false;
88 }
89 
90 QString ServerListFilterInfo::toString() const
91 {
92  QString ret = "";
93 
94  ret += QString("bEnabled: ") + (bEnabled ? "Yes" : "No") + "\n";
95  ret += QString("bShowEmpty: ") + (bShowEmpty ? "Yes" : "No") + "\n";
96  ret += QString("bShowFull: ") + (bShowFull ? "Yes" : "No") + "\n";
97  ret += QString("bShowOnlyValid: ") + (bShowOnlyValid ? "Yes" : "No") + "\n";
98  ret += QString("GameModes: ") + gameModes.join(",") + "\n";
99  ret += QString("GameModes Excluded: ") + gameModesExcluded.join(",") + "\n";
100  ret += QString("MaxPing: ") + QString::number(maxPing) + "\n";
101  ret += QString("ServerName: ") + serverName + "\n";
102  ret += QString("Testing servers: %1\n").arg(testingServers);
103  ret += QString("WADs: ") + wads.join(",") + "\n";
104  ret += QString("WADs Excluded: ") + wadsExcluded.join(",") + "\n";
105 
106  return ret;
107 }