serverpasswordsummary.cpp
1 //------------------------------------------------------------------------------
2 // serverpasswordsummary.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) 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  return 0.0f;
117 
119  return 0.0f;
120 
121  return serverSummary().similarity(other.serverSummary());
122 }
123 
124 QDateTime ServerPasswordSummary::time() const
125 {
126  return serverSummary().time();
127 }
128 
129 const QString &ServerPasswordSummary::type() const
130 {
131  return d->type;
132 }
133 
135 {
136  if (type().isEmpty())
137  return ServerPasswordType::CONNECT;
138  return d->type;
139 }
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.