serverpassword.h
1 //------------------------------------------------------------------------------
2 // serverpassword.h
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) 2013 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef id279D1E56_A461_424E_93E3EF155BEFA077
24 #define id279D1E56_A461_424E_93E3EF155BEFA077
25 
26 #include <QDateTime>
27 #include <QString>
28 #include <QVariant>
29 
30 #include "configuration/serverpasswordsummary.h"
31 
33 {
34  public:
35  static ServerPassword deserializeQVariant(const QVariant& map);
36 
42  bool isValid() const
43  {
44  return !d.phrase.isEmpty();
45  }
46 
47  QString lastGame() const;
48  ServerPasswordSummary lastServer() const;
49  QString lastServerName() const;
50  QDateTime lastTime() const;
51 
52  ServerPasswordSummary mostSimilarServer(const ServerPasswordSummary& other, float* outSimilarity = NULL) const;
53 
54  const QList<ServerPasswordSummary>& servers() const
55  {
56  return d.servers;
57  }
58 
59  const QString& phrase() const
60  {
61  return d.phrase;
62  }
63 
64  QVariant serializeQVariant() const;
65 
66  void addServer(const ServerPasswordSummary& v);
67  void removeServer(const QString& game, const QString& address, unsigned short port);
68 
69  void setPhrase(const QString& v)
70  {
71  d.phrase = v;
72  }
73 
74  void setServers(const QList<ServerPasswordSummary>& v)
75  {
76  d.servers = v;
77  }
78 
79  private:
80  class PrivData
81  {
82  public:
83  QList<ServerPasswordSummary> servers;
84  QString phrase;
85  };
86  PrivData d;
87 };
88 
89 #endif
bool isValid() const
Password is valid if its phrase is not an empty string.