serverlistrowhandler.h
1 //------------------------------------------------------------------------------
2 // serverlistrowhandler.h
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) 2010 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef __SERVER_LIST_ROW_HANDLER_H_
24 #define __SERVER_LIST_ROW_HANDLER_H_
25 
26 #include "dptr.h"
27 #include "serverapi/serverptr.h"
28 #include <QObject>
29 
30 class GameCVar;
31 class Server;
32 class ServerListModel;
33 class QHostAddress;
34 class QPixmap;
35 class QStandardItem;
36 
37 class ServerListRowHandler : public QObject
38 {
39  Q_OBJECT
40 
41 public:
52  {
53  SGNormal = 200,
54  SGWait = 175,
55  SGBanned = 150,
56  SGTimeout = 125,
57  SGBad = 100,
58  SGFirstQuery = 50,
59  };
60 
61  enum ServerListDataTypes
62  {
63  // Pointer to the server structure is always stored in the first column
64  DTPointerToServerStructure = Qt::UserRole + 1,
65  DTSort = Qt::UserRole + 2
66  };
67 
68  ServerListRowHandler(ServerListModel *parentModel, int rowIndex, const ServerPtr &server);
69 
74  ServerListRowHandler(ServerListModel *parentModel, int rowIndex);
75  ~ServerListRowHandler() override;
76 
80  void clearNonVitalFields();
81 
82  QStandardItem *item(int columnIndex);
83 
84  void redraw();
85 
86  ServerPtr server();
87  void setCountryFlag();
88  void setRefreshing();
89 
90  int updateServer();
91 
92  static ServerPtr serverFromList(const ServerListModel *parentModel, int rowIndex);
93 private:
95 
96  void emptyItem(QStandardItem *);
97 
98  void fillAddressColumn();
99 
100  void fillItem(QStandardItem *, const QString &);
101  void fillItem(QStandardItem *, int, const QString &);
102  void fillItem(QStandardItem *, int);
103  void fillItem(QStandardItem *, const QHostAddress &, const QString &actualDisplay = QString());
104  void fillItem(QStandardItem *, const QString &, const QPixmap &);
105  void fillItem(QStandardItem *, int, const QPixmap &);
106 
107  void fillPlayerColumn();
108  void fillPortIconColumn();
109  void fillServerPointerColumn();
110 
111  void prepareHeaders();
112 
113  void setBackgroundColor();
114 
115  void setBad();
116  void setBanned();
117  void setFirstQuery();
118  void setGood();
119  void setTimeout();
120  void setWait();
121 
122  ServerListModel *model;
123  int row;
124 
125  QStringList extractValidGameCVarNames(const QList<GameCVar> &cvars);
126 };
127 
128 #endif
A representation of a server for a given game.
Definition: server.h:93
A general game setting or variable (like fraglimit).