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  ServerListRowHandler(ServerListModel *parentModel, int rowIndex, const ServerPtr &server);
62 
67  ServerListRowHandler(ServerListModel *parentModel, int rowIndex);
68  ~ServerListRowHandler() override;
69 
73  void clearNonVitalFields();
74 
75  QStandardItem *item(int columnIndex);
76 
77  void redraw();
78 
79  ServerPtr server();
80  void setCountryFlag();
81  void setRefreshing();
82 
83  int updateServer();
84 
85  static ServerPtr serverFromList(const ServerListModel *parentModel, int rowIndex);
86 private:
88 
89  void emptyItem(QStandardItem *);
90 
91  void fillAddressColumn();
92 
93  void fillItem(QStandardItem *, const QString &);
94  void fillItem(QStandardItem *, int, const QString &);
95  void fillItem(QStandardItem *, int);
96  void fillItem(QStandardItem *, const QHostAddress &, const QString &actualDisplay = QString());
97  void fillItem(QStandardItem *, const QString &, const QPixmap &);
98  void fillItem(QStandardItem *, int, const QPixmap &);
99 
100  void fillPlayerColumn();
101  void fillPortIconColumn();
102  void fillServerPointer();
103 
104  void prepareHeaders();
105 
106  void setBackgroundColor();
107 
108  void setBad();
109  void setBanned();
110  void setFirstQuery();
111  void setGood();
112  void setTimeout();
113  void setWait();
114 
115  ServerListModel *model;
116  int row;
117 
118  QStringList extractValidGameCVarNames(const QList<GameCVar> &cvars);
119 };
120 
121 #endif