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 EnginePlugin;
30 class Server;
31 class ServerListSortFilterProxyModel;
32 class ServerList;
33 
34 class ServerListModel : public QStandardItemModel
35 {
36  Q_OBJECT
37 
38  friend class ServerList;
39  friend class ServerListProxyModel;
40 
41  public:
53  {
54  SG_NORMAL = 200,
55  SG_WAIT = 175,
56  SG_BANNED = 150,
57  SG_TIMEOUT = 125,
58  SG_BAD = 100,
59  SG_FIRST_QUERY = 50,
60  };
61 
62  enum ServerListDataTypes
63  {
64  // Pointer to the server structure is always stored in the first column
65  SLDT_POINTER_TO_SERVER_STRUCTURE = Qt::UserRole+1,
66  SLDT_SORT = Qt::UserRole+2
67  };
68 
69  ServerListModel(ServerList* parent);
70 
74  int addServer(ServerPtr server);
75  QList<ServerPtr> customServers() const;
76 
82  int findServerOnTheList(const Server* server);
83 
84  ServerList* handler() { return parentHandler; }
85 
86  QList<ServerPtr> nonSpecialServers() const;
87  QList<ServerPtr> servers() const;
88  QList<ServerPtr> serversForPlugin(const EnginePlugin *plugin) const;
89 
95  void redraw(int row);
96  void redrawAll();
97 
98  void removeServer(const ServerPtr &server);
99 
104  void updateFlag(int row, bool force = true);
105 
109  int updateServer(int row, ServerPtr server);
110 
111  ServerPtr serverFromList(int rowIndex) const;
112  ServerPtr serverFromList(const QModelIndex&) const;
113 
114  void setRefreshing(ServerPtr server);
115 
116  signals:
117  void allRowsContentChanged();
118  void rowContentChanged(int row);
119 
120  private:
121  void prepareHeaders();
122  ServerGroup serverGroup(int row);
123 
124  QVariant columnSortData(int row, int column);
125 
126  ServerList* parentHandler;
127 };
128 
129 #endif
int addServer(ServerPtr server)
void redraw(int row)
A representation of a server for a given game.
Definition: server.h:93
int updateServer(int row, ServerPtr server)
int findServerOnTheList(const Server *server)
Finds index of the row where server is contained.
void updateFlag(int row, bool force=true)