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