serverpasswordsummary.cpp
1 //------------------------------------------------------------------------------
2 // serverpasswordsummary.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) 2014 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "serverpasswordsummary.h"
24 
25 #include "serverapi/serversummary.h"
26 
27 const QString ServerPasswordType::CONNECT = "Connect";
28 const QString ServerPasswordType::INGAME = "InGame";
29 
30 DClass<ServerPasswordSummary>
31 {
32  public:
33  ServerSummary serverSummary;
34  // 'type' is a QString in case if we ever need to expand this
35  // in plugins.
36  // It's easier to keep unique values with this than with enums
37  // considering that this needs to be stored in a config file.
38  QString type;
39 };
40 
41 DPointered(ServerPasswordSummary)
42 
44 {
45 }
46 
47 ServerPasswordSummary::ServerPasswordSummary(const Server *server, const QString &type)
48 {
49  d->serverSummary = ServerSummary(server);
50  d->type = type;
51 }
52 
53 ServerPasswordSummary::~ServerPasswordSummary()
54 {
55 }
56 
57 ServerPasswordSummary ServerPasswordSummary::deserializeQVariant(const QVariant& v)
58 {
59  QVariantMap map = v.toMap();
61  obj.setServerSummary(ServerSummary::deserializeQVariant(v));
62  obj.setType(map["passwordType"].toString());
63  return obj;
64 }
65 
66 const QString& ServerPasswordSummary::address() const
67 {
68  return serverSummary().address();
69 }
70 
71 const QString& ServerPasswordSummary::game() const
72 {
73  return serverSummary().game();
74 }
75 
76 bool ServerPasswordSummary::isValid() const
77 {
78  return serverSummary().isValid();
79 }
80 
81 const QString& ServerPasswordSummary::name() const
82 {
83  return serverSummary().name();
84 }
85 
86 unsigned short ServerPasswordSummary::port() const
87 {
88  return serverSummary().port();
89 }
90 
91 QVariant ServerPasswordSummary::serializeQVariant() const
92 {
93  QVariantMap var = serverSummary().serializeQVariant().toMap();
94  var["passwordType"] = type();
95  return var;
96 }
97 
98 const ServerSummary &ServerPasswordSummary::serverSummary() const
99 {
100  return d->serverSummary;
101 }
102 
103 void ServerPasswordSummary::setServerSummary(const ServerSummary &val)
104 {
105  d->serverSummary = val;
106 }
107 
108 void ServerPasswordSummary::setType(const QString &val)
109 {
110  d->type = val;
111 }
112 
114 {
115  if (!isValid() || !other.isValid())
116  {
117  return 0.0f;
118  }
119 
121  {
122  return 0.0f;
123  }
124 
125  return serverSummary().similarity(other.serverSummary());
126 }
127 
128 QDateTime ServerPasswordSummary::time() const
129 {
130  return serverSummary().time();
131 }
132 
133 const QString &ServerPasswordSummary::type() const
134 {
135  return d->type;
136 }
137 
139 {
140  if (type().isEmpty())
141  {
142  return ServerPasswordType::CONNECT;
143  }
144  return d->type;
145 }
A representation of a server for a given game.
Definition: server.h:93
void setType(const QString &val)
One of ServerPasswordType consts or custom.
float similarity(const ServerPasswordSummary &other) const
Similarity to the &#39;other&#39; server; between 0.0 and 1.0.
const QString & typeWithCompatibility() const
Returns type(), if type() is empty returns ServerPasswordType::CONNECT .
float similarity(const ServerSummary &other) const
Similarity to the &#39;other&#39; server; between 0.0 and 1.0.
const QString & type() const
One of ServerPasswordType consts or custom.