serverlistmodel.h
1 //------------------------------------------------------------------------------
2 // serverlistmodel.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) 2009 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef __SERVER_LIST_MODEL_H_
24 #define __SERVER_LIST_MODEL_H_
25 
26 #include "serverapi/serverptr.h"
27 #include <QStandardItemModel>
28 
29 class Server;
30 class ServerListSortFilterProxyModel;
31 class ServerListHandler;
32 
33 class ServerListModel : public QStandardItemModel
34 {
35  Q_OBJECT
36 
37  friend class ServerListHandler;
38  friend class ServerListProxyModel;
39 
40  public:
52  {
53  SG_NORMAL = 200,
54  SG_WAIT = 175,
55  SG_BANNED = 150,
56  SG_TIMEOUT = 125,
57  SG_BAD = 100,
58  SG_FIRST_QUERY = 50,
59  };
60 
61  enum ServerListDataTypes
62  {
63  // Pointer to the server structure is always stored in the first column
64  SLDT_POINTER_TO_SERVER_STRUCTURE = Qt::UserRole+1,
65  SLDT_SORT = Qt::UserRole+2
66  };
67 
69 
73  int addServer(ServerPtr server, int response);
74 
75  void destroyRows();
76 
82  int findServerOnTheList(const Server* server);
83 
84  ServerListHandler* handler() { return parentHandler; }
85 
91  void redraw(int row);
92  void redrawAll();
93 
94  void removeCustomServers();
95 
100  void updateFlag(int row, bool force = true);
101 
105  int updateServer(int row, ServerPtr server, int response);
106 
107  ServerPtr serverFromList(int rowIndex);
108  ServerPtr serverFromList(const QModelIndex&);
109 
110  void setRefreshing(ServerPtr server);
111 
112  signals:
113  void allRowsContentChanged();
114  void modelCleared();
115  void rowContentChanged(int row);
116 
117  protected:
118  void prepareHeaders();
119  ServerGroup serverGroup(int row);
120 
121  QVariant columnSortData(int row, int column);
122 
123  ServerListHandler* parentHandler;
124 };
125 
126 #endif
void redraw(int row)
A representation of a server for a given game.
Definition: server.h:93
int updateServer(int row, ServerPtr server, int response)
int addServer(ServerPtr server, int response)
int findServerOnTheList(const Server *server)
Finds index of the row where server is contained.
void updateFlag(int row, bool force=true)